Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2260895rdb; Fri, 8 Dec 2023 03:11:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoTRHcw9fnXnQtLY/dnwVQdGtB6tOJ8U8Hu51wzsinr2E/uZwCLxHMXSAwNZ+J1TsWjJsh X-Received: by 2002:a17:90b:4a4f:b0:285:ada5:956 with SMTP id lb15-20020a17090b4a4f00b00285ada50956mr4228388pjb.42.1702033884320; Fri, 08 Dec 2023 03:11:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702033884; cv=none; d=google.com; s=arc-20160816; b=FSgg89IwjF+Og0lJ0Rr47d7j/B0fVRGlY3JbMsKVpDh3yjIcz9cDo2OO0Hjmw+eDZq Yqm/CISQfVVkSwNU7L+syQyJA1mmdCHupWL74mqHjiPx0NtIWgsBMKsdh0K3AHgmeuQL fQ5w4iuUsEVAivAqyTWLj8ubkRgAPNKlh7JL82nCf/TssMLjW3y20ez2FSlDScAWbinu Gx9N034p+MkaxtQGImEYYmlZHGoLH7VbxG6nVM/Pj6dFJdhIsXeplvIvspEf8HQd8ukv yN4xx+zFxfQlf5kAe6ftmJdJNf4jpVN7QgFI+rT/hI1MPPkY/ZKacp+YYnvmgF75Ke0U VhQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=gzFHY2K6D4Xb2bH7rsxD+6acZzW8Ga9lJhcwRi3Mzb4=; fh=MfxqOGEYVxd/Djn65Hcby1Zw7xVBPPldt2t3kmR37lU=; b=q/mL2LnBwbbA0btNSLCb5i1MNQ2d9W/MNU7WNluW+RVL4OpraQd/SHtfJmO6GsBwxm C3U6IsbvK/vphTwukavZfEI85tig6wtf0Ji5db/zyquS97MRENvHQwgFl5QiREkloPXu yp9pc164IHni/3t/rGacJiMIAQo7Icz9YxFxbibuZCvqsP+vSXEr3HXNdgvRgU44H9VN iz6PNfnVVGffXliA+eU3PpjzVWQ0FHVH+C4lB5AtaG1MYONwrrwAszdP/hhuuKmtLftj 0MuzbuwtwYXEHz4D0id8PArGvQnroKRFTtRUQEiPAG1ef35jnyxx8i8+7l3245g0dn9U j6eA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id gx6-20020a17090b124600b0028a1ee84596si1596172pjb.186.2023.12.08.03.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 03:11:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id F1CB3824630F; Fri, 8 Dec 2023 03:11:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231656AbjLHLKu (ORCPT + 99 others); Fri, 8 Dec 2023 06:10:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231828AbjLHLKi (ORCPT ); Fri, 8 Dec 2023 06:10:38 -0500 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 673FBF1 for ; Fri, 8 Dec 2023 03:10:43 -0800 (PST) X-QQ-mid: bizesmtp69t1702033819tx63b91w Received: from localhost.localdomain ( [58.240.82.166]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 08 Dec 2023 19:10:17 +0800 (CST) X-QQ-SSF: 01200000000000B0B000000A0000000 X-QQ-FEAT: HIVLo4mOhq54yA4OLFoMe1EM5ffJGUYpbwtVwR0aVb2Wr/FKPBIXiLzDRcTWG OIph7+eMji4nK3Bm9+9R2C56dYXezaz0dIipH1Gcf/bRcDAGtVQheFhchN7bubTU4OhuI5Z F9DyUzj+gU2wtpheFi8tSfxkzKHyEyzQpyRktOVkIwzlftynytYwscEnrCaNM0IS7pCA4WQ I4ct+DAQZOgxysVdVDF8TCrGF9UW6Z4brCHDydwtKfDdeNcqxbFBpRvZU9vwpo/NzqgPCV6 u029vpL1XAKL1FUKjLY5W28Oo/7BZ1QEUayacnzx48XU3bQfGIv87wBWFNZX2sd7n3/n7om wLEiSEYqo9vobF70ORgvS+0j7mOUg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 3233006858392869652 From: Song Shuai To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, guoren@kernel.org, xianting.tian@linux.alibaba.com, takahiro.akashi@linaro.org Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Song Shuai Subject: [PATCH -fixes] riscv: kexec: Avoid deadlock in kexec crash path Date: Fri, 8 Dec 2023 19:10:15 +0800 Message-Id: <20231208111015.173237-1-songshuaishuai@tinylab.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz4a-0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 08 Dec 2023 03:11:11 -0800 (PST) If the kexec crash code is called in the interrupt context, the machine_kexec_mask_interrupts() function will trigger a deadlock while trying to acquire the irqdesc spinlock and then deacitive irqchip. To avoid the deadlock, this patch directly EOI the irq regardless of the active status of irqchip. Fixes: b17d19a5314a ("riscv: kexec: Fixup irq controller broken in kexec crash path") Signed-off-by: Song Shuai --- Note that: 1. this deadlock can reproduced via echo EXCEPTION to lkdtm INT_HW_IRQ_EN point 2. RISC-V HLIC and PLIC irqchips don't have the irq_set_irqchip_state handler and I don't know is it ok to deactive irqchip without the spinlock in this code context, so I simply removed that snippet as arm and powerpc do. I would like to listen to your advice. --- arch/riscv/kernel/machine_kexec.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/arch/riscv/kernel/machine_kexec.c b/arch/riscv/kernel/machine_kexec.c index f6c7135b00d7..d7ddf4d2b243 100644 --- a/arch/riscv/kernel/machine_kexec.c +++ b/arch/riscv/kernel/machine_kexec.c @@ -149,20 +149,12 @@ static void machine_kexec_mask_interrupts(void) for_each_irq_desc(i, desc) { struct irq_chip *chip; - int ret; chip = irq_desc_get_chip(desc); if (!chip) continue; - /* - * First try to remove the active state. If this - * fails, try to EOI the interrupt. - */ - ret = irq_set_irqchip_state(i, IRQCHIP_STATE_ACTIVE, false); - - if (ret && irqd_irq_inprogress(&desc->irq_data) && - chip->irq_eoi) + if (chip->irq_eoi && irqd_irq_inprogress(&desc->irq_data)) chip->irq_eoi(&desc->irq_data); if (chip->irq_mask) -- 2.20.1