From patchwork Wed Nov 30 14:14:33 2022 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: 27837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp951461wrr; Wed, 30 Nov 2022 06:20:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf6oNO82BaF7ljQa2e5w8AzB/9bHA1WwN8zgpfjycbSade5m6whbZc9kPkvFKBSNH2MMsEN2 X-Received: by 2002:a17:906:a050:b0:78d:47c8:e80f with SMTP id bg16-20020a170906a05000b0078d47c8e80fmr52597978ejb.700.1669818035231; Wed, 30 Nov 2022 06:20:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669818035; cv=none; d=google.com; s=arc-20160816; b=Fn3cnMgClSi/Lcuwr0GpRwEXl+PGgdjeZ5meILP4xa+/EmPOBURtswq3kJlkLMWl1H +Y9J8fDFN5uLbIQljJpvP4BSUXTqeQforWkUkn0ev5cILHRACkXpsOFwlSH9AABWnIUx MfGFyeteyIxu+Adn5M8OLWVG9c8NHGjl8h53psx6GHvrmAtlOZ4/N6q6pZSsYiTNIWhs V+dZ2uGCn3w5Dr1r2Nkryn80yevDCwmRSEwAhVpnntHJi/fpzkoU5reA6VwCAeHrjjvM ARDmphp5kfYgnBWSoIkCjIa5FC0JM9edSYlgL7WZorFCxEboh/e8yiwSsPRsJHUbXshI zh9Q== 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=FVO6zWidXe6Zg/00vyTjYgijpJdIvLIKWg8mwZB6WUk=; b=LN3jIDZNYz4S4kG/VnAoHfA/hQBZ4aaWtSKRMzEcZVupDX58oJ8+S9EoC08G+Hznya QfRDce0qk7UnlKY1bmGKw/Qw8NX4oykqpD+174U3BOvZf+sipjfcatTseL9mHOBPuKri Fhin1ZvMpcEeO2LOMQRp2iSQXgUw4ipVeNvIKO48j5T8HCeeLQwEUhnQXYeIGW116Lyh ow55TKZljcvfP1naOxGwtAP3JGCgMMxgpYaad4ppI8MG4qTp+eFiFb/aC3Lgp5HPq6vn Bur5/ntB1WRIUlfQeaDn2bGx8DGYpDl3HWi6cJx3MuzrGsdjQ1e7xrjxgJu1lpkzuz+u C0UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jJr6lvwE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 ty12-20020a170907c70c00b007ae377adb6asi1276794ejc.628.2022.11.30.06.20.10; Wed, 30 Nov 2022 06:20:35 -0800 (PST) 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=jJr6lvwE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S229528AbiK3OPA (ORCPT + 99 others); Wed, 30 Nov 2022 09:15:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbiK3OOt (ORCPT ); Wed, 30 Nov 2022 09:14:49 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14F3D7CA8D; Wed, 30 Nov 2022 06:14:37 -0800 (PST) Date: Wed, 30 Nov 2022 14:14:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669817675; 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=FVO6zWidXe6Zg/00vyTjYgijpJdIvLIKWg8mwZB6WUk=; b=jJr6lvwE5HoKZQ3iwBpA72pDmyP3fzGq2uChpeVtnJAA5sKmEMfDjGtob0EtNYY3QS4Zqj AtxedjVzosKK/C2+SpoDtjTCPNpSikL8up/sO0Fm8akKVJwuAkoerP6jDhg+ptRp7PU9ES Ios+SgGVeyeJk3dCxIebZymao7qahpmU6uftk4FTmwqBBaJJWHRlhCzbW308olJh2lqXRQ nt3iHiS3KzfS6JFED+0AXQ5t5JQyVpirGrUQU6d2J8pm8s8G0cPaxlFNWUvLn6EisGS8Xo Qk44zO3fPoh0wVVF1iPII3gKQBh7y8qipbpZ/K7u6sYPEjG57kZK3AyC9QJA6Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669817675; 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=FVO6zWidXe6Zg/00vyTjYgijpJdIvLIKWg8mwZB6WUk=; b=v3r7yglRuFcMRjgVjbNVSQOPNp4epMuUebQWMxga/8zZwizx0ggqZczYEF2t/1n84TdpU/ y7BJL+KlQBLGmtAA== From: "tip-bot2 for Yang Yingliang" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/core] genirq/irqdesc: Don't try to remove non-existing sysfs files Cc: Yang Yingliang , Thomas Gleixner , "Greg Kroah-Hartman" , x86@kernel.org, linux-kernel@vger.kernel.org, maz@kernel.org In-Reply-To: <20221128151612.1786122-1-yangyingliang@huawei.com> References: <20221128151612.1786122-1-yangyingliang@huawei.com> MIME-Version: 1.0 Message-ID: <166981767350.4906.13064198854331518868.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750931116385967958?= X-GMAIL-MSGID: =?utf-8?q?1750931116385967958?= The following commit has been merged into the irq/core branch of tip: Commit-ID: 9049e1ca41983ab773d7ea244bee86d7835ec9f5 Gitweb: https://git.kernel.org/tip/9049e1ca41983ab773d7ea244bee86d7835ec9f5 Author: Yang Yingliang AuthorDate: Mon, 28 Nov 2022 23:16:12 +08:00 Committer: Thomas Gleixner CommitterDate: Wed, 30 Nov 2022 14:52:11 +01:00 genirq/irqdesc: Don't try to remove non-existing sysfs files Fault injection tests trigger warnings like this: kernfs: can not remove 'chip_name', no directory WARNING: CPU: 0 PID: 253 at fs/kernfs/dir.c:1616 kernfs_remove_by_name_ns+0xce/0xe0 RIP: 0010:kernfs_remove_by_name_ns+0xce/0xe0 Call Trace: remove_files.isra.1+0x3f/0xb0 sysfs_remove_group+0x68/0xe0 sysfs_remove_groups+0x41/0x70 __kobject_del+0x45/0xc0 kobject_del+0x29/0x40 free_desc+0x42/0x70 irq_free_descs+0x5e/0x90 The reason is that the interrupt descriptor sysfs handling does not roll back on a failing kobject_add() during allocation. If the descriptor is freed later on, kobject_del() is invoked with a not added kobject resulting in the above warnings. A proper rollback in case of a kobject_add() failure would be the straight forward solution. But this is not possible due to the way how interrupt descriptor sysfs handling works. Interrupt descriptors are allocated before sysfs becomes available. So the sysfs files for the early allocated descriptors are added later in the boot process. At this point there can be nothing useful done about a failing kobject_add(). For consistency the interrupt descriptor allocation always treats kobject_add() failures as non-critical and just emits a warning. To solve this problem, keep track in the interrupt descriptor whether kobject_add() was successful or not and make the invocation of kobject_del() conditional on that. [ tglx: Massage changelog, comments and use a state bit. ] Fixes: ecb3f394c5db ("genirq: Expose interrupt information through sysfs") Signed-off-by: Yang Yingliang Signed-off-by: Thomas Gleixner Reviewed-by: Greg Kroah-Hartman Link: https://lore.kernel.org/r/20221128151612.1786122-1-yangyingliang@huawei.com --- kernel/irq/internals.h | 2 ++ kernel/irq/irqdesc.c | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index f09c603..5fdc0b5 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -52,6 +52,7 @@ enum { * IRQS_PENDING - irq is pending and replayed later * IRQS_SUSPENDED - irq is suspended * IRQS_NMI - irq line is used to deliver NMIs + * IRQS_SYSFS - descriptor has been added to sysfs */ enum { IRQS_AUTODETECT = 0x00000001, @@ -64,6 +65,7 @@ enum { IRQS_SUSPENDED = 0x00000800, IRQS_TIMINGS = 0x00001000, IRQS_NMI = 0x00002000, + IRQS_SYSFS = 0x00004000, }; #include "debug.h" diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index a91f900..fd09962 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -288,22 +288,25 @@ static void irq_sysfs_add(int irq, struct irq_desc *desc) if (irq_kobj_base) { /* * Continue even in case of failure as this is nothing - * crucial. + * crucial and failures in the late irq_sysfs_init() + * cannot be rolled back. */ if (kobject_add(&desc->kobj, irq_kobj_base, "%d", irq)) pr_warn("Failed to add kobject for irq %d\n", irq); + else + desc->istate |= IRQS_SYSFS; } } static void irq_sysfs_del(struct irq_desc *desc) { /* - * If irq_sysfs_init() has not yet been invoked (early boot), then - * irq_kobj_base is NULL and the descriptor was never added. - * kobject_del() complains about a object with no parent, so make - * it conditional. + * Only invoke kobject_del() when kobject_add() was successfully + * invoked for the descriptor. This covers both early boot, where + * sysfs is not initialized yet, and the case of a failed + * kobject_add() invocation. */ - if (irq_kobj_base) + if (desc->istate & IRQS_SYSFS) kobject_del(&desc->kobj); }