From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 DBA4DD7360A for ; Sat, 30 Nov 2024 20:12:59 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y11SV14tgz2xQC; Sun, 1 Dec 2024 07:12:58 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=72.21.196.25 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1732997578; cv=none; b=kFspjMss5tj/tE8AYyiJWtMcV8Dym+oIutddvu+SyL2Eb7lvPGUOYT8LocG/UAAhJBy2E4kTkhrI6Eq63HQThREPV09E+grCrsOeMmnCJMuOSluujcCSyIHD4nYq/OeOUnLRDp+U1d2eq4Rw9n1M+Pxv383FqbEocfRsJRqXcYd7ho1UlNYDlvgm/QWaP19ouSTS7/ntZKBskytxVGAetTtMMU2HrHOthvi9Qp0FhU07IgpL3In5/jQCmAzGO30vYnvRYFyD8vXlkkm9RDIS9AyuvFBeef59GV3XxkD9v9jpJxqQo7D0FeThkTSHiZoNSfFgjTVQaWx+uIf5LRefzA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1732997578; c=relaxed/relaxed; bh=zoZ/+qDc221WdsVhvoxlHSC6W9U8KUsHn4lZh61HM1Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GNKb+tqcrytgM2dPQYOvHJkamgkWpf5VOjx++1L+ZLx2LQGD11l7UTwc1AxDStvqpqL1KuDMBITY205sgoJOfkiVaHkxTYhHQPj5pGhS4w6E51U/Ds/BHKU/pa+VhslmxsML4bvUCJ8eiV5xd0SglfztXpm0rc8/ua6lfuGmAg59qcVs+Hpi6lGTNaqHcoXxgRSE1vdSSSRoD5B2miS1qUQX2/iAusTJduClLgwA9DP/qJVJmD+eJgAgns0OckBcbcxyvVDDZfxT0G/w8726ITJ/nhdYJJhrJD3DGX+2dfv2nUnJjTJfdCTxqR+PrcMN4e2ku+ew64WGSU3BDk1Q4A== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; dkim=pass (1024-bit key; unprotected) header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazon201209 header.b=P7EHIFlo; dkim-atps=neutral; spf=pass (client-ip=72.21.196.25; helo=smtp-fw-2101.amazon.com; envelope-from=prvs=057a1cabc=farbere@amazon.com; receiver=lists.ozlabs.org) smtp.mailfrom=amazon.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazon201209 header.b=P7EHIFlo; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=amazon.com (client-ip=72.21.196.25; helo=smtp-fw-2101.amazon.com; envelope-from=prvs=057a1cabc=farbere@amazon.com; receiver=lists.ozlabs.org) Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y11SS501rz2xH8 for ; Sun, 1 Dec 2024 07:12:56 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1732997578; x=1764533578; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zoZ/+qDc221WdsVhvoxlHSC6W9U8KUsHn4lZh61HM1Y=; b=P7EHIFlocVddm2t0vgXtQNbCfIGPyfx53dOwAajdQZjz+aUTPTur8qeA D8T8hLUtbu6N+JlZfSeJNJR7un82Jgh+YE+peyVAm1lsOyglBVn8+PKTT Gno6B2em6hQ7vkZ5retPQ5oaUTkSNYN8fRsR8cuxv7p5/FSJEublI6cG3 4=; X-IronPort-AV: E=Sophos;i="6.12,199,1728950400"; d="scan'208";a="447165625" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.124.125.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2024 20:11:50 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.21.151:19230] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.32.230:2525] with esmtp (Farcaster) id a6a52d1b-8c83-4dfa-ade4-e0f66ee20537; Sat, 30 Nov 2024 20:11:48 +0000 (UTC) X-Farcaster-Flow-ID: a6a52d1b-8c83-4dfa-ade4-e0f66ee20537 Received: from EX19D013UWB003.ant.amazon.com (10.13.138.111) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Sat, 30 Nov 2024 20:11:44 +0000 Received: from EX19MTAUWB001.ant.amazon.com (10.250.64.248) by EX19D013UWB003.ant.amazon.com (10.13.138.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Sat, 30 Nov 2024 20:11:44 +0000 Received: from email-imr-corp-prod-iad-all-1a-47ca2651.us-east-1.amazon.com (10.25.36.214) by mail-relay.amazon.com (10.250.64.254) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34 via Frontend Transport; Sat, 30 Nov 2024 20:11:44 +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-iad-all-1a-47ca2651.us-east-1.amazon.com (Postfix) with ESMTP id D7D6F404CE; Sat, 30 Nov 2024 20:11:43 +0000 (UTC) Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 96751719D; Sat, 30 Nov 2024 20:11:43 +0000 (UTC) From: Eliav Farber To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v5 2/2] kexec: Prevent redundant IRQ masking by checking state before shutdown Date: Sat, 30 Nov 2024 20:11:43 +0000 Message-ID: <20241130201143.48808-3-farbere@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20241130201143.48808-1-farbere@amazon.com> References: <20241130201143.48808-1-farbere@amazon.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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. Replace calls to irq_mask() and irq_disable() hooks with a simplified call to irq_shutdown(), and check if the interrupt is started (irqd_is_started) before calling the shutdown. Signed-off-by: Eliav Farber --- V4 -> V5: - The phrase 'This patch' has been removed from the commit message. kernel/irq/kexec.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/kernel/irq/kexec.c b/kernel/irq/kexec.c index 0f9548c1708d..1a3deffe6b5b 100644 --- a/kernel/irq/kexec.c +++ b/kernel/irq/kexec.c @@ -17,7 +17,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_GENERIC_IRQ_KEXEC_CLEAR_VM_FORWARD)) { @@ -31,10 +31,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); } } -- 2.40.1