From patchwork Thu Oct 20 14:16:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 6223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp145552wrr; Thu, 20 Oct 2022 07:34:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ETH4PU6tJETgLSmX+0DYJEdiHUo7mChihdTes6TshbWOiicQSsA3pUA/BrccKnKny8Oe7 X-Received: by 2002:a17:907:320c:b0:77b:6f08:9870 with SMTP id xg12-20020a170907320c00b0077b6f089870mr11385857ejb.249.1666276492708; Thu, 20 Oct 2022 07:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666276492; cv=none; d=google.com; s=arc-20160816; b=uQUERgV2JvVbFprvL1aIgq7QtLxiZfTo5IIchyBfBa2NzrdvuSkLv5sLUeie0Zcocr jYIH1nqiFGA0I8wLU6ZoDT2v26VMrGJkhReSs7kID2LABcC8xC5kAQQ7OLsAHrfi5iQo AjFleg75+uynqR3Qz93L3aVgxj3MXD2NNTr+tuiXBnUVeHXnSk25nog6jKKuCMeKIF1q SJN+bKxDR15bR5ITILXV26gW4aSHXuGELlxwoE+zwIdgXalzEXMcAvm8gjggi8omRxaD qcVIvYArKnBhYaBronHwjbgyTub52xkfY6B61OMPKbivVfjesK2MG7hsIVWlrgxQhHpp OERg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GJJGOz6GTslLFaQ8JQP/ybuMSeO/eT0XffDJlkLxdOM=; b=nE5sILSvShhZAI/j2xBsOnbSb0fMucXXv8d8886dRlCXE2Z1RlaanWKvBEDt0FW5bc QV0SWiLZoF3BnFSCrk4rE1HMlWA2EyC5pXdpXkUP6/Qaym7GSBgBisTmUNWlAhFVLWLi 22GzLcRpI11HcFEOIItVHk2wypXX6+jq/FKm9OeQ3y2R8xG5/MoCt2KfD/SKgj2H3Svw refbETAgzEaNLf55odQN3bBQPUipRFiVnKA/vadGMzn8Y+3UdObobnwGDE9dyM8cgNrO eNeN4uHop6QssOnigY0+eOI6UBi+coggF+bcons+ZbQLXNGIpLd5xANOu9aeFkO6nwco X0AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U3LlyRqH; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr8-20020a170907720800b0077945c44b7fsi18624233ejc.856.2022.10.20.07.34.26; Thu, 20 Oct 2022 07:34:52 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=U3LlyRqH; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230128AbiJTOQx (ORCPT + 99 others); Thu, 20 Oct 2022 10:16:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbiJTOQv (ORCPT ); Thu, 20 Oct 2022 10:16:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E102F186789; Thu, 20 Oct 2022 07:16:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4A0BBB82770; Thu, 20 Oct 2022 14:16:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23492C433B5; Thu, 20 Oct 2022 14:16:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666275406; bh=xstK3zkOHtc6QOgvpFphVjtbdDCoP5sViwZUf0BdeYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U3LlyRqHOBjAVnIEBN9khBKKuhSpAf8SRXM5yZ8+Koj4z/6g7noNLkFtpt+9p/Zj+ pzdPqmZQNMO4HZOhMN/5wEHiEes7Kjtd4nbmtft8bL+Oh2GdsRm4H9pKZS1blUMSMP 8ZKk4UKKY9N3j+pQPT7jeksTeOdx9omaRUOBSGaXDRVMoNomD5u5A8v0GEvQXJm7k3 EUM7mWCg9KadWJ1W6HTdwOmCBfu+45gLb8YkIy0JWgQjJEgLO+OCgkrckACL9RKFmM 2AY9yQhPb8/RJF3y3MwageHC1XTLfBMEUStZmx34vhQMtm89he0h1kC2t6GUIDpz2O kIOGQ2kpMUXeg== From: guoren@kernel.org To: guoren@kernel.org, xianting.tian@linux.alibaba.com, palmer@dabbelt.com, palmer@rivosinc.com, heiko@sntech.de, arnd@arndb.de, lijiang@redhat.com, bagasdotme@gmail.com, bhe@redhat.com, yixun.lan@gmail.com, goyal@redhat.com, dyoung@redhat.com, corbet@lwn.net, Conor.Dooley@microchip.com Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, crash-utility@redhat.com, Guo Ren , Nick Kossifidis Subject: [PATCH V5 1/2] riscv: kexec: Fixup irq controller broken in kexec crash path Date: Thu, 20 Oct 2022 10:16:02 -0400 Message-Id: <20221020141603.2856206-2-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221020141603.2856206-1-guoren@kernel.org> References: <20221020141603.2856206-1-guoren@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1747217539605239814?= X-GMAIL-MSGID: =?utf-8?q?1747217539605239814?= From: Guo Ren If a crash happens on cpu3 and all interrupts are binding on cpu0, the bad irq routing will cause a crash kernel which can't receive any irq. Because crash kernel won't clean up all harts' PLIC enable bits in enable registers. This patch is similar to 9141a003a491 ("ARM: 7316/1: kexec: EOI active and mask all interrupts in kexec crash path") and 78fd584cdec0 ("arm64: kdump: implement machine_crash_shutdown()"), and PowerPC also has the same mechanism. Fixes: fba8a8674f68 ("RISC-V: Add kexec support") Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Xianting Tian Cc: Nick Kossifidis Cc: Palmer Dabbelt --- arch/riscv/kernel/machine_kexec.c | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/riscv/kernel/machine_kexec.c b/arch/riscv/kernel/machine_kexec.c index ee79e6839b86..db41c676e5a2 100644 --- a/arch/riscv/kernel/machine_kexec.c +++ b/arch/riscv/kernel/machine_kexec.c @@ -15,6 +15,8 @@ #include /* For unreachable() */ #include /* For cpu_down() */ #include +#include +#include /* * kexec_image_info - Print received image details @@ -154,6 +156,37 @@ void crash_smp_send_stop(void) cpus_stopped = 1; } +static void machine_kexec_mask_interrupts(void) +{ + unsigned int i; + struct irq_desc *desc; + + 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) + 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); + } +} + /* * machine_crash_shutdown - Prepare to kexec after a kernel crash * @@ -169,6 +202,8 @@ machine_crash_shutdown(struct pt_regs *regs) crash_smp_send_stop(); crash_save_cpu(regs, smp_processor_id()); + machine_kexec_mask_interrupts(); + pr_info("Starting crashdump kernel...\n"); }