linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Pingfan Liu <kernelfans@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Mark Rutland <mark.rutland@arm.com>,
	Julien Thierry <julien.thierry@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Pingfan Liu <kernelfans@gmail.com>, Marc Zyngier <maz@kernel.org>,
	Will Deacon <will@kernel.org>
Subject: [PATCH] arm64/irq: use NMI to send stop IPI
Date: Tue,  8 Dec 2020 21:14:30 +0800	[thread overview]
Message-ID: <1607433270-9807-1-git-send-email-kernelfans@gmail.com> (raw)

Like other arches, both 'kexec -l' and 'kexec -p' expect to use NMI to
interrupt other cpus in order to capture cpus tightly to a known state.

So for both of the cases, try to use NMI IPI if irqchip supports NMI.

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Julien Thierry <julien.thierry@arm.com>
To: linux-arm-kernel@lists.infradead.org
---
 arch/arm64/kernel/smp.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index 18e9727..ff61e2c 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -884,6 +884,31 @@ static void ipi_cpu_crash_stop(unsigned int cpu, struct pt_regs *regs)
 }
 
 /*
+ * Overlapped with the counterpart in do_handle_IPI(), only just for nmi purpose
+ */
+static irqreturn_t nmi_ipi_handler(int irq, void *data)
+{
+	unsigned int cpu = smp_processor_id();
+	int ipinr = irq - ipi_irq_base;
+
+	switch (ipinr) {
+	case IPI_CPU_STOP:
+		local_cpu_stop();
+		unreachable();
+		break;
+
+	case IPI_CPU_CRASH_STOP:
+		if (IS_ENABLED(CONFIG_KEXEC_CORE)) {
+			ipi_cpu_crash_stop(cpu, get_irq_regs());
+
+			unreachable();
+		}
+		break;
+	}
+	return IRQ_NONE;
+}
+
+/*
  * Main handler for inter-processor interrupts
  */
 static void do_handle_IPI(int ipinr)
@@ -902,10 +927,12 @@ static void do_handle_IPI(int ipinr)
 		generic_smp_call_function_interrupt();
 		break;
 
+	/* If NMI IPI is not supported */
 	case IPI_CPU_STOP:
 		local_cpu_stop();
 		break;
 
+	/* If NMI IPI is not supported */
 	case IPI_CPU_CRASH_STOP:
 		if (IS_ENABLED(CONFIG_KEXEC_CORE)) {
 			ipi_cpu_crash_stop(cpu, get_irq_regs());
@@ -989,6 +1016,14 @@ void __init set_smp_ipi_range(int ipi_base, int n)
 	for (i = 0; i < nr_ipi; i++) {
 		int err;
 
+		if (i == IPI_CPU_CRASH_STOP || i == IPI_CPU_STOP) {
+			err = request_percpu_nmi(ipi_base + i, nmi_ipi_handler,
+				"NMI-IPI", &cpu_number);
+			if (!err)
+				continue;
+
+			pr_warn("Fail to request nmi for NMI-IPI\n");
+		}
 		err = request_percpu_irq(ipi_base + i, ipi_handler,
 					 "IPI", &cpu_number);
 		WARN_ON(err);
@@ -1038,6 +1073,7 @@ void smp_send_stop(void)
 
 		if (system_state <= SYSTEM_RUNNING)
 			pr_crit("SMP: stopping secondary CPUs\n");
+		/* NMI is expected, but it is subject to the irq line's ability */
 		smp_cross_call(&mask, IPI_CPU_STOP);
 	}
 
@@ -1084,6 +1120,7 @@ void crash_smp_send_stop(void)
 	atomic_set(&waiting_for_crash_ipi, num_other_online_cpus());
 
 	pr_crit("SMP: stopping secondary CPUs\n");
+	/* NMI is expected, but it is subject to the irq line's ability */
 	smp_cross_call(&mask, IPI_CPU_CRASH_STOP);
 
 	/* Wait up to one second for other CPUs to stop */
-- 
2.7.5


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2020-12-08 13:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-08 13:14 Pingfan Liu [this message]
2020-12-08 14:04 ` [PATCH] arm64/irq: use NMI to send stop IPI Marc Zyngier
2020-12-14  2:20   ` Pingfan Liu
2020-12-14  2:25     ` [PATCH 1/3] kernel/irq: __handle_domain_irq() makes irq_enter/exit arch optional Pingfan Liu
2020-12-14  2:25       ` [PATCH 2/3] arm64/irq-gic-v3: make gic_handle_irq() cope with enter_from_kernel_mode() Pingfan Liu
2020-12-14  2:25       ` [PATCH 3/3] arm64/irq-gic-v3: make reschedule-ipi light weight Pingfan Liu
2020-12-14  9:46     ` [PATCH] arm64/irq: use NMI to send stop IPI Marc Zyngier
2020-12-14 13:04       ` Pingfan Liu
2020-12-14 13:24         ` Marc Zyngier
2020-12-15  5:40           ` Pingfan Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1607433270-9807-1-git-send-email-kernelfans@gmail.com \
    --to=kernelfans@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=julien.thierry@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).