From patchwork Fri Dec 9 07:55:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 31680 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp636556wrr; Thu, 8 Dec 2022 23:57:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ixsrK013gYI+9EHpHPlerWqfLHLb6sZTJQ13478xJfE2i2anAq+8vJn1kI5g4szP93YDb X-Received: by 2002:a17:906:39d7:b0:7ad:c8d7:4fd9 with SMTP id i23-20020a17090639d700b007adc8d74fd9mr3768936eje.36.1670572654289; Thu, 08 Dec 2022 23:57:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670572654; cv=none; d=google.com; s=arc-20160816; b=DRRXLHTzuq2q6hAsnZFTFFv7RgvIkTVm9pEW7W0lXwFoS9g8tjm8etpnUl3wIhxvoK MnzdAUtZZi09JDCWKSv5GffBoWYuuDf2kHDv7vw+cMpw6GD0fnzZ0xOdVWTE+9c/0GXD vCSV5+/RI0B3+/Dqinp7xxhy6Az1B+EwLxfM8GjtHNDvklwovr2i9wh/kDJ7yCZRIIW7 ppY6PJV6xiyEVrxji0A1R8EDh5mp42CN1vSOIrE+oM7DYiB4tjnpBhYA34XAhqjnHnFO XHlzKZreTAbjbNzODuWaIDaAQX99DMB5Eht6FJ0lU3LH8QW54WjaaRTA3FnwLckR3f/W chGQ== 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=Kz/g6x1NoNmuFc9X6gqur7i0ZfSGYEfhrcbnYbh16qs=; b=vUOPfW/7G+JrkgdZcCQHHqYRfLE+I/+b7tgXS2FJawYcvYZeyrNgd20+wSpx8FHTIf +3+kGBW3Mux0X/FQ2LTVArf/2jJhcxeH5rqtPG4s4bB00lTSGxv7SBTtpfuyLGFqzOH+ t1jTYRSkQU3BT0k3tbbI1B0hnSuxeIwLONOZZhkWu5/I+hcqjJzlKYrU8c8cmHI/Mz/E rAb9L6V/W2F/XjWKsIAH7OgevwiuxQ8KAb21wttERBPbmmbqChuus5KYX8bcO8/bAR7P 85O1Obv9HR4o5wYYqBgH8AlYqAQONAnXTFWO6HU3oX+kSXLoJCrqmQBnr8vQhnJ9WkPX xCDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="pYTmQ/UO"; 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 l14-20020a170906794e00b0078de83a052csi766041ejo.483.2022.12.08.23.57.10; Thu, 08 Dec 2022 23:57:34 -0800 (PST) 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="pYTmQ/UO"; 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 S229798AbiLIHz3 (ORCPT + 99 others); Fri, 9 Dec 2022 02:55:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbiLIHz1 (ORCPT ); Fri, 9 Dec 2022 02:55:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4423E51C12 for ; Thu, 8 Dec 2022 23:55:26 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id D443961DC9 for ; Fri, 9 Dec 2022 07:55:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00FF0C433F1; Fri, 9 Dec 2022 07:55:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670572525; bh=4nLQBcd8V0pueofOhtHaEJKIhLpE2Gc7g50/8xor77o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pYTmQ/UOCCIBGrz5axni9cWPzMzpbmxGbLgghkZ1AnkMeTt/u/+1KFk9GLkRtIYnM oWMbzf3VfSjmHklp1Z0DYJok4+g7+IGg5y/vGWO+U/jKh4QrDIXXwQnHuR/1i8wc+D Es686IkaYTg0dC175moF6PsbxZvkp7L5zTe/ljvXC7IycbLRN5iMI0ZKYFGC9SCtjm 886HZLA/szfVvQHGKg3+VzwI2IZ5fGUeFyGJhmZgJ3CanxkKyjxtxs6dzsobz3ZxLq 5kxACdUNSCzRVvwGI587We/8+fPSAHlrXwPEKNduqLxngqUjnCuHA87kYlseW8qxS3 c5wG9ZRPo8csw== From: guoren@kernel.org To: palmer@rivosinc.com, conor.Dooley@microchip.com, guoren@kernel.org, heiko@sntech.de Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, crash-utility@redhat.com, Guo Ren , Xianting Tian , Nick Kossifidis Subject: [PATCH -next V6 1/2] riscv: kexec: EOI active and mask all interrupts in kexec crash path Date: Fri, 9 Dec 2022 02:55:12 -0500 Message-Id: <20221209075513.532249-2-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221209075513.532249-1-guoren@kernel.org> References: <20221209075513.532249-1-guoren@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 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?1751722391373467822?= X-GMAIL-MSGID: =?utf-8?q?1751722391373467822?= From: Guo Ren If a crash happens on cpu3 and all interrupts are binding on cpu0, the bad irq routing will cause the crash kernel can't receive any irq. Because the crash kernel won't clean up PLIC harts' enable register. This patch is similar to 'commit 9141a003a491 ("ARM: 7316/1: kexec: EOI active and mask all interrupts in kexec crash path")'; arm64 and PowerPC also have a similar mechanism. 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"); }