From patchwork Thu Nov 28 20:10:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eliav Farber X-Patchwork-Id: 13888322 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C362BD70DEB for ; Thu, 28 Nov 2024 20:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pAFdRwFKfNDF1JqGR+n1qcumP19pBTl1wsynLPrMwbI=; b=2287gXismUBXJnHeoMPr9n7vp5 zzm42dmgU6SY6f11lIiJJSvQNahc15/W7qN4nj0h+Ukl+N1iVKs1uB7U45FJEqTxBbbtdS0c8Zw49 uNxex15N9BjS+mPbh3gLH7R3DG+e8TvngZlpLjdB5Znot70VkaoQgu3nVtJOyHQQTtpFXE7aK3OHa Em4zl1+s7fHUKXcoGM6tPLWqlCUS6vV4hKO04ooSPs5Gm69Q7gW99Dd/HiwtkfMrs3Op9GHbXMUzv Gu6yv4TzF4NHE434gE+btuaKTV8ZcFPd/BIH61pWO+TUeNX3d7qhpsMzt0o/0zOEi4+o/obw7hTj0 8rH5j1ig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tGktU-0000000GLAx-0UPR; Thu, 28 Nov 2024 20:13:44 +0000 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tGkqZ-0000000GKV4-2uQL; Thu, 28 Nov 2024 20:10:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1732824643; x=1764360643; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pAFdRwFKfNDF1JqGR+n1qcumP19pBTl1wsynLPrMwbI=; b=rDqURn7tY6AeL1b8tT+BmCEW+5dqgNOrxb1mJPN09Igkff+eBt88Ydml TOfH5MO/DNL3NjIdnpjhW+kTwjKSO+KPXy1SVuMXxcEteho9mjW5D7FfA 4UrepzCgNgDHhFKAuTl3jjKhFzBLKdFhv7EfT7VZthEWfUU6X99nPY0re o=; X-IronPort-AV: E=Sophos;i="6.12,193,1728950400"; d="scan'208";a="389147585" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2024 20:10:33 +0000 Received: from EX19MTAEUB001.ant.amazon.com [10.0.17.79:6662] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.32.206:2525] with esmtp (Farcaster) id 535754cd-d852-4ac9-99b0-bacfdd30cbc2; Thu, 28 Nov 2024 20:10:32 +0000 (UTC) X-Farcaster-Flow-ID: 535754cd-d852-4ac9-99b0-bacfdd30cbc2 Received: from EX19D018EUC003.ant.amazon.com (10.252.51.231) by EX19MTAEUB001.ant.amazon.com (10.252.51.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Thu, 28 Nov 2024 20:10:29 +0000 Received: from EX19MTAUEC001.ant.amazon.com (10.252.135.222) by EX19D018EUC003.ant.amazon.com (10.252.51.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Thu, 28 Nov 2024 20:10:28 +0000 Received: from email-imr-corp-prod-pdx-all-2b-22fa938e.us-west-2.amazon.com (10.124.125.6) by mail-relay.amazon.com (10.252.135.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34 via Frontend Transport; Thu, 28 Nov 2024 20:10:28 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com [172.19.116.181]) by email-imr-corp-prod-pdx-all-2b-22fa938e.us-west-2.amazon.com (Postfix) with ESMTP id ADDF8C01D2; Thu, 28 Nov 2024 20:10:27 +0000 (UTC) Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 46D0F78EA; Thu, 28 Nov 2024 20:10:27 +0000 (UTC) From: Eliav Farber To: , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v3 2/2] kexec: Prevent redundant IRQ masking by checking state before shutdown Date: Thu, 28 Nov 2024 20:10:27 +0000 Message-ID: <20241128201027.10396-3-farbere@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20241128201027.10396-1-farbere@amazon.com> References: <20241128201027.10396-1-farbere@amazon.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241128_121043_779269_2F3F886B X-CRM114-Status: GOOD ( 16.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org During machine kexec, the function machine_kexec_mask_interrupts() is responsible for disabling or masking all interrupts. While the irq_disable hook ensures that an already-disabled IRQ is not disabled again, the current implementation unconditionally invokes the irq_mask() function for every interrupt descriptor, even when the interrupt is already masked. A specific issue was observed in the crash kernel flow after unbinding a device (prior to kexec) that used a GPIO as an IRQ source. The warning was triggered by the gpiochip_disable_irq() function, which attempted to clear the FLAG_IRQ_IS_ENABLED flag when FLAG_USED_AS_IRQ was not set: ``` void gpiochip_disable_irq(struct gpio_chip *gc, unsigned int offset) { struct gpio_desc *desc = gpiochip_get_desc(gc, offset); if (!IS_ERR(desc) && !WARN_ON(!test_bit(FLAG_USED_AS_IRQ, &desc->flags))) clear_bit(FLAG_IRQ_IS_ENABLED, &desc->flags); } ``` This issue surfaced after commit a8173820f441 ("gpio: gpiolib: Allow GPIO IRQs to lazy disable") introduced lazy disablement for GPIO IRQs. It replaced disable/enable hooks with mask/unmask hooks. Unlike the disable hook, the mask hook doesn't handle already-masked IRQs. When a GPIO-IRQ driver is unbound, the IRQ is released, triggering __irq_disable() and irq_state_set_masked(). A subsequent call to machine_kexec_mask_interrupts() re-invokes chip->irq_mask(). This results in a call chain, including gpiochip_irq_mask() and gpiochip_disable_irq(). Since FLAG_USED_AS_IRQ was cleared earlier, a warning occurs. This patch addresses the issue by: - Replacing the calls to irq_mask() and irq_disable() hooks with a simplified call to irq_shutdown(). - Checking if the interrupt is started (irqd_is_started) before calling the shutdown. As part of this change, the irq_shutdown() declaration was moved from kernel/irq/internals.h to include/linux/irq.h to make it accessible outside the kernel/irq/ directory, as the former can only be included within that directory. Signed-off-by: Eliav Farber --- V2 -> V3: - Check if IRQ is started using irqd_is_started(). - Use irq_shutdown() instead of irq_disable(). include/linux/irq.h | 3 +++ kernel/irq/internals.h | 1 - kernel/kexec_core.c | 8 ++------ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/linux/irq.h b/include/linux/irq.h index fa711f80957b..48a3df728c47 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -694,6 +694,9 @@ extern int irq_chip_request_resources_parent(struct irq_data *data); extern void irq_chip_release_resources_parent(struct irq_data *data); #endif +/* Shut down the interrupt */ +extern void irq_shutdown(struct irq_desc *desc); + /* Handling of unhandled and spurious interrupts: */ extern void note_interrupt(struct irq_desc *desc, irqreturn_t action_ret); diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index fe0272cd84a5..1f9287b1ccb7 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -88,7 +88,6 @@ extern int irq_activate(struct irq_desc *desc); extern int irq_activate_and_startup(struct irq_desc *desc, bool resend); extern int irq_startup(struct irq_desc *desc, bool resend, bool force); -extern void irq_shutdown(struct irq_desc *desc); extern void irq_shutdown_and_deactivate(struct irq_desc *desc); extern void irq_enable(struct irq_desc *desc); extern void irq_disable(struct irq_desc *desc); diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 6e1e420946e0..928b4387502b 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -1083,7 +1083,7 @@ void machine_kexec_mask_interrupts(void) int check_eoi = 1; chip = irq_desc_get_chip(desc); - if (!chip) + if (!chip || !irqd_is_started(&desc->irq_data)) continue; if (IS_ENABLED(CONFIG_ARM64)) { @@ -1097,10 +1097,6 @@ void machine_kexec_mask_interrupts(void) if (check_eoi && chip->irq_eoi && irqd_irq_inprogress(&desc->irq_data)) chip->irq_eoi(&desc->irq_data); - if (chip->irq_mask) - chip->irq_mask(&desc->irq_data); - - if (chip->irq_disable && !irqd_irq_disabled(&desc->irq_data)) - chip->irq_disable(&desc->irq_data); + irq_shutdown(desc); } }