From patchwork Fri Dec 8 11:10:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 175783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5380830vqy; Fri, 8 Dec 2023 03:11:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFl0qZmiZNMXq66Ha6HqJe17JiP7NC2ywCNKOnIqw0ANDtkB2ofOVpY6tlE7IcxDyyKT47B X-Received: by 2002:a05:6a00:400e:b0:6ce:2732:586 with SMTP id by14-20020a056a00400e00b006ce27320586mr4445519pfb.55.1702033883558; Fri, 08 Dec 2023 03:11:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702033883; cv=none; d=google.com; s=arc-20160816; b=MiR4CeltYzf8B8kC0ylPCxSplSPUc9asNFqlHXisANeIXja+reMWPQVmlpoKHZrcQs hBbc5LX6XBCpOVKwUtl389Yl1fxg7SMjjxXd2+mMoAEVv0g8eaHeuHJaxcSdn8dTL5pf Oli3VznUVdqCOVQFjvYSDvwWjVu7XXiKoVvA4EWd1pMvAAhSSWbFBgjXlcue101aJ/Sb +TrQ4H+BQLWEjC5D6J8GYSZY6irmVg19ZyrRrt0ZKm3HSw8GhtOudDEMcO/XMedQOddP jqLsvkLZaS25q9h14rWZLXeJIZEfvGVX34gI4PpBkY77L2pei1nsdZGsVCe0nY31FbfW 51AA== 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 Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id e6-20020a654786000000b005c663eae379si1335698pgs.269.2023.12.08.03.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 03:11:23 -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 BC30D824630C; Fri, 8 Dec 2023 03:10:59 -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 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:00 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784711881543177709 X-GMAIL-MSGID: 1784711881543177709 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)