From patchwork Sat Jul 22 16:03:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 124348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp911864vqg; Sat, 22 Jul 2023 10:30:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlF8Ba0t1ijb3yK2t4M6SrqLAy93gnjt6yUcqTF61UHT079uaINeu6bciAaSbvTWm3CqBz0a X-Received: by 2002:a17:906:77c8:b0:977:e310:1ce7 with SMTP id m8-20020a17090677c800b00977e3101ce7mr5039003ejn.38.1690047058990; Sat, 22 Jul 2023 10:30:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690047058; cv=none; d=google.com; s=arc-20160816; b=jiyYQChNwJUpxcIvq8LSWp4viOpwGA8NfGeanArE0MoSq1ZkyvQZiFPCAF1qsbO0fr u8FyzOUG2YcKXcSknuYi21jR8hAhsmVZF1jSRxA+Q0ViohGCjpJvgF8xJzgu0gOjDl0f 3aCXYnR8N3sbUO/VeOGaezMnQCD8JFvAdhjSrFVX4NsvEgIFvPR6P9tEPLqnXatEO7gi 3cKDXiFuPmzA4RhaP8GzvWnU89XvUqp8LgQBb1SYColQfARa8ZAs5vSGkwPx84/k6vlR m1zFCiKQJ4RdD5rrTpxI+4aMBoeRtyLWxKDj9tDK3+OCSVqNALVVp8ROo9h7V2qqmxoz 3hIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=dIlUKNOZbqeMD94L3neoznK1YkPZS74c2BtITe69l/k=; fh=c0g4l7espqOX0TY66SRkGGj8lL7Qx8WSTpMH2fDUamw=; b=firqAAVvJler0OD75jMOZnL+qINTzz7saiB7qpkRt11I9qjFgq0cGTaPgykZKc/hij q0yNXFkgARa4PVGnjwV8bs6orDW1VqvK9LjOevMGcSvy+kmi5ZkWGyKjLtf8IhrI7V// UUVylp8w4BYjot2KNr278KBGzX8N6+crxye9klnFJY19xqv7GJNvyKCWIgwgdmAlKj5M 8juQMM6c3/w7jOyHCp0LBt7EK7rmnOJC7jII0qetPQcwBV9m/9sNgdOj2CxvfXgN6ZeN Pa/M6us5lpokvi1x0tkAJXW/bFd4CLOXagsfMUiHQLAF8YTLHgKDcjp1fqn0uwtXY8bB BGfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GGLv4iM6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=iz75Bid9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a056402055100b0051dd2d2cfb8si1583048edx.644.2023.07.22.10.30.35; Sat, 22 Jul 2023 10:30:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GGLv4iM6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=iz75Bid9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230173AbjGVQDd (ORCPT + 99 others); Sat, 22 Jul 2023 12:03:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbjGVQDc (ORCPT ); Sat, 22 Jul 2023 12:03:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D44A1FDF; Sat, 22 Jul 2023 09:03:31 -0700 (PDT) Date: Sat, 22 Jul 2023 16:03:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690041808; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dIlUKNOZbqeMD94L3neoznK1YkPZS74c2BtITe69l/k=; b=GGLv4iM6WnZDW78RJ5+CuAvj80uZMdsF5isE4nKovuV+++ySEwVRCRwRWhwoc8f8isH6+n 7B1es3eD35+kc6RQ2hWSoru+0jmIJouVw7EV1D0EuI/jNH2r6cF/Zk+uQiOM9neAQ2WFMr rjt90USSL+l9mZesrd25Tmk+NYTauYOzxii+cQ5HaYguOM1tsUOia8sLhiXVXHTSFh4fdG CaUS+8wpG/0c1/KCIokzSTCaE4f8t5v/AOjhs2oUoRhIAqNIiYlad0Ot0IZu/sjpx+gWIA VWqV+/TZilJQd9QK59KPEwJpBEAuVB/a9YnAzRF95FVqaQtp5qyql1Bi9/yX4Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690041808; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dIlUKNOZbqeMD94L3neoznK1YkPZS74c2BtITe69l/k=; b=iz75Bid9Qiui3nrBFlzThsbpB+ZeyI752O9Sc9AbsfayQZYbO5VcIy/KsrpvBz3ztfT/QM BZRiVJNnENZn1LCg== From: "tip-bot2 for Yazen Ghannam" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/MCE/AMD: Decrement threshold_bank refcount when removing threshold blocks Cc: Mikulas Patocka , Yazen Ghannam , "Borislav Petkov (AMD)" , , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?b?PGFscGluZS5MUkguMi4wMi4yMjA1MzAxMTQ1NTQwLjI1ODQwQGZp?= =?utf-8?b?bGUwMS5pbnRyYW5ldC5wcm9kLmludC5yZHUyLnJlZGhhdC5jb20+?= References: =?utf-8?b?PGFscGluZS5MUkguMi4wMi4yMjA1MzAxMTQ1NTQwLjI1ODQwQGZp?= =?utf-8?b?bGUwMS5pbnRyYW5ldC5wcm9kLmludC5yZHUyLnJlZGhhdC5jb20+?= MIME-Version: 1.0 Message-ID: <169004180799.28540.1304114763325215952.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772142784886519845 X-GMAIL-MSGID: 1772142784886519845 The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 3ba2e83334bed2b1980b59734e6e84dfaf96026c Gitweb: https://git.kernel.org/tip/3ba2e83334bed2b1980b59734e6e84dfaf96026c Author: Yazen Ghannam AuthorDate: Mon, 06 Jun 2022 19:45:56 Committer: Borislav Petkov (AMD) CommitterDate: Sat, 22 Jul 2023 17:35:16 +02:00 x86/MCE/AMD: Decrement threshold_bank refcount when removing threshold blocks AMD systems from Family 10h to 16h share MCA bank 4 across multiple CPUs. Therefore, the threshold_bank structure for bank 4, and its threshold_block structures, will be initialized once at boot time. And the kobject for the shared bank will be added to each of the CPUs that share it. Furthermore, the threshold_blocks for the shared bank will be added again to the bank's kobject. These additions will increase the refcount for the bank's kobject. For example, a shared bank with two blocks and shared across two CPUs will be set up like this: CPU0 init bank create and add; bank refcount = 1; threshold_create_bank() block 0 init and add; bank refcount = 2; allocate_threshold_blocks() block 1 init and add; bank refcount = 3; allocate_threshold_blocks() CPU1 init bank add; bank refcount = 3; threshold_create_bank() block 0 add; bank refcount = 4; __threshold_add_blocks() block 1 add; bank refcount = 5; __threshold_add_blocks() Currently in threshold_remove_bank(), if the bank is shared then __threshold_remove_blocks() is called. Here the shared bank's kobject and the bank's blocks' kobjects are deleted. This is done on the first call even while the structures are still shared. Subsequent calls from other CPUs that share the structures will attempt to delete the kobjects. During kobject_del(), kobject->sd is removed. If the kobject is not part of a kset with default_groups, then subsequent kobject_del() calls seem safe even with kobject->sd == NULL. Originally, the AMD MCA thresholding structures did not use default_groups. And so the above behavior was not apparent. However, a recent change implemented default_groups for the thresholding structures. Therefore, kobject_del() will go down the sysfs_remove_groups() code path. In this case, the first kobject_del() may succeed and remove kobject->sd. But subsequent kobject_del() calls will give a WARNing in kernfs_remove_by_name_ns() since kobject->sd == NULL. Use kobject_put() on the shared bank's kobject when "removing" blocks. This decrements the bank's refcount while keeping kobjects enabled until the bank is no longer shared. At that point, kobject_put() will be called on the blocks which drives their refcount to 0 and deletes them and also decrementing the bank's refcount. And finally kobject_put() will be called on the bank driving its refcount to 0 and deleting it. The same example above: CPU1 shutdown bank is shared; bank refcount = 5; threshold_remove_bank() block 0 put parent bank; bank refcount = 4; __threshold_remove_blocks() block 1 put parent bank; bank refcount = 3; __threshold_remove_blocks() CPU0 shutdown bank is no longer shared; bank refcount = 3; threshold_remove_bank() block 0 put block; bank refcount = 2; deallocate_threshold_blocks() block 1 put block; bank refcount = 1; deallocate_threshold_blocks() put bank; bank refcount = 0; threshold_remove_bank() Fixes: 7f99cb5e6039 ("x86/CPU/AMD: Use default_groups in kobj_type") Reported-by: Mikulas Patocka Signed-off-by: Yazen Ghannam Signed-off-by: Borislav Petkov (AMD) Tested-by: Mikulas Patocka Cc: Link: https://lore.kernel.org/r/alpine.LRH.2.02.2205301145540.25840@file01.intranet.prod.int.rdu2.redhat.com --- arch/x86/kernel/cpu/mce/amd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/amd.c b/arch/x86/kernel/cpu/mce/amd.c index 5e74610..c4ec4ca 100644 --- a/arch/x86/kernel/cpu/mce/amd.c +++ b/arch/x86/kernel/cpu/mce/amd.c @@ -1261,10 +1261,10 @@ static void __threshold_remove_blocks(struct threshold_bank *b) struct threshold_block *pos = NULL; struct threshold_block *tmp = NULL; - kobject_del(b->kobj); + kobject_put(b->kobj); list_for_each_entry_safe(pos, tmp, &b->blocks->miscj, miscj) - kobject_del(&pos->kobj); + kobject_put(b->kobj); } static void threshold_remove_bank(struct threshold_bank *bank)