From nobody Mon Dec 1 22:07:35 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43105315D25 for ; Thu, 27 Nov 2025 12:53:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248010; cv=none; b=QqK/zgtocwRx4nj+AHV3T6EKupnfZcmR1z0Wp2gEDxMCpoGLll6YXxQ+KzWm6TNHHaZut3CVmYmfT9t9r/+oCdRBWZ6l8RT6lXwfhgVRE8e+UTs20VzNUCossv5AoqDzNcFLZTCKtK2h4x62G1JhNc7UOT/f6/sXfJQDXGAhb7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248010; c=relaxed/simple; bh=RLe+Or8mCxHbUOYdLD2jDO4rk+jmTrHQdKdIXJHJbRI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kTUB9lk3CdvI/euApHWiVNvZl0qU7rCAF1UqN7ba08JyWmaTyMomx9/Oy1TEnV/Sy5JWOsE/qQP7lvvqT9R7BYTKFD2Ojqa+fUDo116dSCN5O6uNoAIjkNmQThzyi2jM0J6/mLtCKoNsctHtDmbY/ZguOT8WOqm00sD0qONRe70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=irw5g992; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="irw5g992" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-29806bd47b5so5019545ad.3 for ; Thu, 27 Nov 2025 04:53:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1764248007; x=1764852807; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=6gRHgAms/qw186HwaqxgpMtPx5WpCFvQohfxW5cnU8g=; b=irw5g992nUnplRbEAqkMSvv6HHQnf6CQKnq4LX9D/X9glbhfwvjmm8tSeIDuV6FgCI lrYnl8ms3slYRY9XF2x7iRq4V0fH+MNLjZdWl6qHKEtcbif3oq/5cZ5IgTvikzZAO7DC wbnM3aa+LlOL3TIzS0VmKQujnEhPUHIfFa6QqI2QEzXdmmGzDizY5dRiGS/siqnlT94g UBUZpGqF3iahvYfvGyt3yPrVs5cN1Zcwrd7TKv2fpS4jp/2YCwn5R5QUqdz8zfNTNVMv 37skf4RPGbpgcqThlUv+GMd/g/sfX4ua0F5A4t8dL/qsdHSaAKA9rt6+wn8R4uq836l8 cRJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764248007; x=1764852807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=6gRHgAms/qw186HwaqxgpMtPx5WpCFvQohfxW5cnU8g=; b=UJmjPTzmULYEFHPZp/vuwoK0KfswpZcRia/5exNdRxAu9AlrQE+Mn6ygSckdnwNYrv Di2HM8NCZ1lccVmfF5xLqd86McIG/R3sD/whQ67vIOAWkMMrxOCqPDCfsQEw08o4N7h4 0d1rKglbpk3LH4AnmL8/W1+PFk9mw7TsMSKRCr4kLI9SfNwM/osHz1AjNS59mT7EHxff v24YGdxpFIQR+YWu9l6ntzDfKzew/ks9MehWfLU01wb4O8KI+0BH4XfHszFp6+Crrdgr qF3JM6V/KHoy3VdYW9sL8WBz/VYKBdx8Z1CEU4qBkW8CPacdM12Lk3UJ+MJyRpMGVFhO n+EQ== X-Forwarded-Encrypted: i=1; AJvYcCWigZLhjFubHMBx5pybqe5Hc2wdI2Il3qRrU0Hmg0oIu3sj/KXhOX/smLEdskwduxuJPrXLimDwhj+kbhY=@vger.kernel.org X-Gm-Message-State: AOJu0YyeGWvlQpnywvdxyRcxGKvZbVg2o7JKwWalJNABYqWuErpBHTX2 ATFsDvTLVuflzjwkLn6qiPJcUgKegf4RV2OY4kE82ykdruvoDhpbPF7jR2h9VcN07as= X-Gm-Gg: ASbGncstPsEenSQmWNijjFG7MV7++BRczOODYHg0PfqCLG/3HYH0BAgjFu1RzZuE/x0 qjQHbkTK4QYQFmUBFjdBD2w/U79pzMu/5YDfwzjhT6XeHgjfUZee9S2eft84kV+aSlY/M++TL/2 8f46WnPweXm1hz0A5Pbw6KOZvnl6fafCFN1OLoaUp7QNGAI+cwLn+CVl3YcorkbQCJGLL6Uv38d p67Symrt1lOqf55Lf1FMKxWvTmdYrYfz7ZZ9IV4rowVgJh48g2ALwCoiVkCJBmdHRccDaQu1wp6 UetVJIKX6r2NsOB2suTEDBvXEUMyQOkCzcSChuQwb1wdTHY0UJeldL7UEf7zprmfu7HgCmo4nvx R5Fvf5C4Jk99N6jWfoT3GFH0NEm/RAZsp3es0Dtf1BocbHQ7GV7bL5U7PS2/XMy3ZMM0flTElPN UH7dZZjNbsRACXK4jQiQXGwHu2dhIH+NLbXJ2hL2EyuSwb X-Google-Smtp-Source: AGHT+IElrZeX9ue0soNAe3UvXw/hxq6Df/QcKBQE4mLLMStE8fECsay5d0GzZrwvfFYo76l7k0B4dQ== X-Received: by 2002:a17:903:3c68:b0:295:7806:1d64 with SMTP id d9443c01a7336-29b6c50afa1mr268547755ad.25.1764248007302; Thu, 27 Nov 2025 04:53:27 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bce470347sm17771255ad.41.2025.11.27.04.53.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Nov 2025 04:53:26 -0800 (PST) From: Yunhui Cui To: conor@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, cuiyunhui@bytedance.com, luxu.kernel@bytedance.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, jassisinghbrar@gmail.com, conor.dooley@microchip.com, valentina.fernandezalanis@microchip.com, catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, timothy.hayes@arm.com, lpieralisi@kernel.org, arnd@arndb.de, kees@kernel.org, tglx@linutronix.de, viresh.kumar@linaro.org, boqun.feng@gmail.com, linux-arm-kernel@lists.infradead.org, cleger@rivosinc.com, atishp@rivosinc.com, ajones@ventanamicro.com Subject: [PATCH v3 1/8] drivers: firmware: riscv: add SSE NMI support Date: Thu, 27 Nov 2025 20:52:58 +0800 Message-Id: <20251127125305.89961-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251127125305.89961-1-cuiyunhui@bytedance.com> References: <20251127125305.89961-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for handling Non-Maskable Interrupts (NMIs) through the RISC-V Supervisor Software Events (SSE) framework. Add basic NMI functionality via SBI_SSE_EVENT_LOCAL_SOFTWARE_INJECTED registration and enabling. Signed-off-by: Yunhui Cui --- MAINTAINERS | 8 +++ drivers/firmware/riscv/Kconfig | 10 +++ drivers/firmware/riscv/Makefile | 1 + drivers/firmware/riscv/riscv_sse_nmi.c | 90 ++++++++++++++++++++++++++ include/linux/riscv_sse_nmi.h | 26 ++++++++ 5 files changed, 135 insertions(+) create mode 100644 drivers/firmware/riscv/riscv_sse_nmi.c create mode 100644 include/linux/riscv_sse_nmi.h diff --git a/MAINTAINERS b/MAINTAINERS index 8bf5416953f45..c06658da8af96 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22057,6 +22057,14 @@ S: Maintained F: drivers/firmware/riscv/riscv_sse.c F: include/linux/riscv_sse.h =20 +RISC-V SSE NMI SUPPORT +M: Yunhui Cui +R: Xu Lu +L: linux-riscv@lists.infradead.org +S: Maintained +F: drivers/firmware/riscv/riscv_sse_nmi.c +F: include/linux/riscv_sse_nmi.h + RISC-V THEAD SoC SUPPORT M: Drew Fustini M: Guo Ren diff --git a/drivers/firmware/riscv/Kconfig b/drivers/firmware/riscv/Kconfig index ed5b663ac5f91..6c77c7823571a 100644 --- a/drivers/firmware/riscv/Kconfig +++ b/drivers/firmware/riscv/Kconfig @@ -12,4 +12,14 @@ config RISCV_SBI_SSE this option provides support to register callbacks on specific SSE events. =20 +config RISCV_SSE_NMI + bool "Enable SBI Supervisor Software Events NMI support" + depends on RISCV_SBI_SSE && SMP + default y + help + This option enables support for delivering Non-Maskable Interrupt + (NMI) notifications through the Supervisor Software Events (SSE) + framework. When enabled, the system can deliver local, unknown and + other types of NMIs. + endmenu diff --git a/drivers/firmware/riscv/Makefile b/drivers/firmware/riscv/Makef= ile index c8795d4bbb2ea..fbc182b53ae53 100644 --- a/drivers/firmware/riscv/Makefile +++ b/drivers/firmware/riscv/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 =20 obj-$(CONFIG_RISCV_SBI_SSE) +=3D riscv_sbi_sse.o +obj-$(CONFIG_RISCV_SSE_NMI) +=3D riscv_sse_nmi.o diff --git a/drivers/firmware/riscv/riscv_sse_nmi.c b/drivers/firmware/risc= v/riscv_sse_nmi.c new file mode 100644 index 0000000000000..752ee88b230da --- /dev/null +++ b/drivers/firmware/riscv/riscv_sse_nmi.c @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#define pr_fmt(fmt) "SSE NMI: " fmt + +#include +#include +#include + +#include +#include +#include + +static bool nmi_available; +static struct sse_event *local_nmi_evt; +static DEFINE_PER_CPU(atomic_t, local_nmi) =3D ATOMIC_INIT(LOCAL_NMI_NONE); + +bool nmi_support(void) +{ + return READ_ONCE(nmi_available); +} + +static inline struct sbiret sbi_sse_ecall(int fid, unsigned long arg0, + unsigned long arg1) +{ + return sbi_ecall(SBI_EXT_SSE, fid, arg0, arg1, 0, 0, 0, 0); +} + +void send_nmi_single(unsigned int cpu, enum local_nmi_type type) +{ + unsigned int hart_id =3D cpuid_to_hartid_map(cpu); + u32 evt =3D SBI_SSE_EVENT_LOCAL_SOFTWARE_INJECTED; + struct sbiret ret; + + atomic_or(type, per_cpu_ptr(&local_nmi, cpu)); + + ret =3D sbi_sse_ecall(SBI_SSE_EVENT_INJECT, evt, hart_id); + if (ret.error) + pr_err("Failed to signal event %x to hartid %d, error %ld\n", + evt, hart_id, ret.error); +} + +void send_nmi_mask(cpumask_t *mask, enum local_nmi_type type) +{ + unsigned int cpu; + + for_each_cpu(cpu, mask) + send_nmi_single(cpu, type); +} + +static int local_nmi_handler(u32 evt, void *arg, struct pt_regs *regs) +{ + return 0; +} + +static int __init local_nmi_init(void) +{ + int ret; + + local_nmi_evt =3D sse_event_register(SBI_SSE_EVENT_LOCAL_SOFTWARE_INJECTE= D, 0, + local_nmi_handler, NULL); + if (IS_ERR(local_nmi_evt)) + return PTR_ERR(local_nmi_evt); + + ret =3D sse_event_enable(local_nmi_evt); + if (ret) { + sse_event_unregister(local_nmi_evt); + return ret; + } + + pr_info("Using SSE for Local NMI event delivery\n"); + + return 0; +} + +static int __init sse_nmi_init(void) +{ + int ret; + + ret =3D local_nmi_init(); + if (ret) { + pr_err("Local_nmi_init failed with error %d\n", ret); + return ret; + } + + WRITE_ONCE(nmi_available, true); + + return 0; +} + +late_initcall(sse_nmi_init); diff --git a/include/linux/riscv_sse_nmi.h b/include/linux/riscv_sse_nmi.h new file mode 100644 index 0000000000000..16db85c5162f5 --- /dev/null +++ b/include/linux/riscv_sse_nmi.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __LINUX_RISCV_SSE_NMI_H +#define __LINUX_RISCV_SSE_NMI_H + +#include + +enum local_nmi_type { + LOCAL_NMI_NONE =3D 0U, + LOCAL_NMI_STOP =3D BIT(0), + LOCAL_NMI_CRASH =3D BIT(1), + LOCAL_NMI_BACKTRACE =3D BIT(2), + LOCAL_NMI_KGDB =3D BIT(3), +}; + +#ifdef CONFIG_RISCV_SSE_NMI +bool nmi_support(void); +void send_nmi_mask(cpumask_t *mask, enum local_nmi_type type); +void send_nmi_single(unsigned int cpu, enum local_nmi_type type); +#else +static inline bool nmi_support(void) { return false; } +static inline void send_nmi_mask(cpumask_t *mask) { }; +static inline void send_nmi_single(unsigned int cpu) { }; +#endif + +#endif --=20 2.39.5 From nobody Mon Dec 1 22:07:35 2025 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8A6C330B1F for ; Thu, 27 Nov 2025 12:53:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248018; cv=none; b=l84pLzWtvNaAnX6pjpdUcBpfUefaKwfTJjID+u3cPd2xm5LJT3axzzRvsYoyfAYyOFbfSmPr3r/yDZWvC2MRkCPNMZYgD7AZNoTwwXrzxAK4RajD80xW/64phPJ9byQx45aiITjCkFU99fnLr9gxxIAKuwbMs1/4hRPiEDfOkZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248018; c=relaxed/simple; bh=TRyEBRIpgT7BYzdRENjXaC7C9gx2hEXpB/ykhPrxgFM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X6jBm0+NgNDLnM7Hy20MMAi0/EkFVuNcJmMGiCtmITINwIGe5KhyzUhfRxAOmR6uCNJDEISCj/8Jb0tHKz2GzcrpVgxCiTqK4ZIrkAA+sG8GrmaTm3gDE16Ac4T0hEvSYMAG6B+9ngboXDLHtNIKJ6jVu4DEaC2VCLywXFcMoQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=iagV1Z/j; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="iagV1Z/j" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-bcfd82f55ebso903355a12.1 for ; Thu, 27 Nov 2025 04:53:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1764248016; x=1764852816; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=kWEVz8RQkOVIjQiYoeWau+DA1cwiHSk9Obrie6fKLfw=; b=iagV1Z/jyHtaoaU7lRqjxik7p6OXr8tLOEWYaDPWYfCQ5MdS2s3keg0GQuk7qLe4ct rZXxajwBwbMWy3WYa5jbAMBAsojbYSelSb6aRlty1DU2eW8Zq/Mv1OjsnhulsxY+Jlt7 JcQI+4YZANrzMy+zWwzTVuQDa4a78W5tNUQOM8GFU2qKN2xT/BmlSIyzgb8+5BdBakTz S2HtrzIhGAIocu4/P5ZBhgRzcjfmNVbpcy6vCMwchKtjL7S1wMtZ8BnAJWJl6lk+rHAM GQo6BdHNKZaCc/mLlauFPJm8vbRpSUP4EykalkiiekMEcvv61KoYNupUTeI1FGnxk/91 IRyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764248016; x=1764852816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=kWEVz8RQkOVIjQiYoeWau+DA1cwiHSk9Obrie6fKLfw=; b=hBRLn23J5GiS/birHrRGEztvgoMgV8Rjd9VVi1T7+gky7TdFFRUtosDGjuXZ9Fqi7h BX71lpMZOcr/GSjXWi0WaojoCUcU78shatxn/VZpkexH6yg+vAjBlpfcnzBpUB+IyebE VDdDpuXkfoiQXAZlsQFMSWaew3REnMnxm7SiWwY9BK6CErcV2MSTIi01YuWSc1uJfx3f QpTPzBoQDlCsPaVPILx8t3BNWzb0HSCnOF/HzDmVd6g3UT1sBvA9rA639Wsx0oupE6Ut W/gsaxTVk0Wc1svbInJ1uAWKHxWhL7MCHrd9B8cqnc5LcYIDjyFqBVza0Ekd7X92ifjN x6ug== X-Forwarded-Encrypted: i=1; AJvYcCUFCFtM8cfU86+vggkjbnGs2Va1CH9lc0/Gh0dUW5seZXxI/Cz+UyYya2191yfdXMtFwfpJ1Z5rHcJJ2Sc=@vger.kernel.org X-Gm-Message-State: AOJu0YxTv4jmD9e0pRSya5Vqsp75S4pexOM9AzPgOXP6cswxxJ43KNXe WMsDz5JJIhy34jW8twm79XuPr+Qec2iVknXeTjMk/LQ+aRdoCGlYfg2yT9NsSa5G1mE= X-Gm-Gg: ASbGncudZZ4oGTruV56/wCw0GQKj5nYk3jyWWa4apSP7X00LgQarJA2dBdIUQf702hA NrTqRPNbZljTj5jUIVrb8mtByEC/Grm1f+BAW06iKdYWxkWtKIC71vgoIjCDGkms3+hr8UKIL9i dBc9ulPSxCjubRB262s4em+sjNn3mw7Kkh2ntXzKUWOXut7798FTk5bTUDsYDBqG+DtutU0eT6U Q0KNFSeOyK/05CXurJPZ4yu0hKwlKmdEycgA5mCbVnIKr6durkvz+l3bnbVkJweOfgabkDv2rCG GM+6ufOoG9xK7Ke/I23LvzKnpTUL43qheKrdcBVxexjqLNslYBI6lbO3esVfd+CxVg/FZJypzXk aFaipg0qnfGP3RvoiZNPhJagIih5S4yZkhsLSEPHy1OV3JilqbLblYPjUyo1sGr8PhBgC/WNSNz lIvC+N0bwhlvQfgKE+AWUbDdRxLVtc++jx3sjiLBa/D2Nd X-Google-Smtp-Source: AGHT+IFo3oRBJLdJi4pyyDpZGbMQhtVuztEKKK6FGAEfrCPL8DYRN7thK8HfinjkzsY3+0il8FhHiQ== X-Received: by 2002:a17:903:384f:b0:29a:4a5:d688 with SMTP id d9443c01a7336-29b5e38c2efmr326573335ad.15.1764248015652; Thu, 27 Nov 2025 04:53:35 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bce470347sm17771255ad.41.2025.11.27.04.53.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Nov 2025 04:53:35 -0800 (PST) From: Yunhui Cui To: conor@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, cuiyunhui@bytedance.com, luxu.kernel@bytedance.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, jassisinghbrar@gmail.com, conor.dooley@microchip.com, valentina.fernandezalanis@microchip.com, catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, timothy.hayes@arm.com, lpieralisi@kernel.org, arnd@arndb.de, kees@kernel.org, tglx@linutronix.de, viresh.kumar@linaro.org, boqun.feng@gmail.com, linux-arm-kernel@lists.infradead.org, cleger@rivosinc.com, atishp@rivosinc.com, ajones@ventanamicro.com Subject: [PATCH v3 2/8] riscv: smp: move ipi_cpu_crash_stop() declaration to smp.h Date: Thu, 27 Nov 2025 20:52:59 +0800 Message-Id: <20251127125305.89961-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251127125305.89961-1-cuiyunhui@bytedance.com> References: <20251127125305.89961-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move ipi_cpu_crash_stop() declaration from smp.c to smp.h to enable external reference, and rename it to cpu_crash_stop(). Signed-off-by: Yunhui Cui --- arch/riscv/include/asm/smp.h | 9 +++++++++ arch/riscv/kernel/smp.c | 9 ++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h index 7ac80e9f22889..f53f1f0e7aa9e 100644 --- a/arch/riscv/include/asm/smp.h +++ b/arch/riscv/include/asm/smp.h @@ -54,6 +54,15 @@ void riscv_ipi_set_virq_range(int virq, int nr); /* Check other CPUs stop or not */ bool smp_crash_stop_failed(void); =20 +#ifdef CONFIG_KEXEC_CORE +void cpu_crash_stop(unsigned int cpu, struct pt_regs *regs); +#else +static inline void cpu_crash_stop(unsigned int cpu, struct pt_regs *regs) +{ + unreachable(); +} +#endif + /* Secondary hart entry */ asmlinkage void smp_callin(void); =20 diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index e650dec448176..9dbcb9a06a96d 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -78,7 +78,7 @@ static void ipi_stop(void) #ifdef CONFIG_KEXEC_CORE static atomic_t waiting_for_crash_ipi =3D ATOMIC_INIT(0); =20 -static inline void ipi_cpu_crash_stop(unsigned int cpu, struct pt_regs *re= gs) +void cpu_crash_stop(unsigned int cpu, struct pt_regs *regs) { crash_save_cpu(regs, cpu); =20 @@ -94,11 +94,6 @@ static inline void ipi_cpu_crash_stop(unsigned int cpu, = struct pt_regs *regs) for(;;) wait_for_interrupt(); } -#else -static inline void ipi_cpu_crash_stop(unsigned int cpu, struct pt_regs *re= gs) -{ - unreachable(); -} #endif =20 static void send_ipi_mask(const struct cpumask *mask, enum ipi_message_typ= e op) @@ -134,7 +129,7 @@ static irqreturn_t handle_IPI(int irq, void *data) ipi_stop(); break; case IPI_CPU_CRASH_STOP: - ipi_cpu_crash_stop(cpu, get_irq_regs()); + cpu_crash_stop(cpu, get_irq_regs()); break; case IPI_IRQ_WORK: irq_work_run(); --=20 2.39.5 From nobody Mon Dec 1 22:07:35 2025 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 265371DF261 for ; Thu, 27 Nov 2025 12:53:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248030; cv=none; b=NxUoAguLS3hvdUSmAS+GJn8ag4pbPuoFCk4nUss9GLnV+myX2Zyt/GW19ts5IsrWii4FLK0KyAdtWkycSxzzIxHTif+4MjZBoDyyjGxWudbJcCpb+15nN0NLmy72gK0KvKRm1r4r2bgMamGGqzJvAZx+3CabvHaCoD5/lp0J51E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248030; c=relaxed/simple; bh=2ZrRnf7stY83G4Y0lqiUHbFDbs2NG+SjOJBTsZJMl/s=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KoSx7DYaajmaApqEteZ3kZvH0PzJM2v99Ley9jIS3qCvQyHWD6z76EtHp8j9K4curCh3W2MmPfrquPIX0ZnxwtPPA7TB1Lql9qFfyLEeK/VZXRE3UZlziRV5EbWAF8Lveq1bGW4Iwum5ObouPErYla0Z7PRgX8hAUAUUNbxQE90= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=QtnFyBv4; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="QtnFyBv4" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-29558061c68so11649445ad.0 for ; Thu, 27 Nov 2025 04:53:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1764248024; x=1764852824; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=yk19cubzYI59vS2m7ARmuI6dwPXbjagJNzaP0UWxsjY=; b=QtnFyBv4iWZF/IZR4PYPheT5IrDGUlc43sQUAAMyI3b0+BHS7keXUM32KzCeiF1xyb qqC1l/fZZnQNqzrwqRtq55DIcmo7VzczY2goaEpxs2qF/7xuq6VSMAEX4ar3OFbxWOq2 +G+OQLTTKxMUWqnMY/t8gazEOPwEfOg1EUQe+o7579S1AONPDq9j8Weuw8JS6+6xDWZr zKyXl6bYl6mPf7eTGVbKgjHkN7nFGFFLJHTZWE9/b9EReUBApUzYY7rtxwgcMFZ9bMbB 4yJ/4iDCRgxtPe2J97LW0lriYjK3YWfPYCOyBWUJ4566SWCBl2JuTP0H4FzBFdghWP5n TjRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764248024; x=1764852824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=yk19cubzYI59vS2m7ARmuI6dwPXbjagJNzaP0UWxsjY=; b=mwTRixTr4STt1l7XkvSyPeThl1HwbKbaGpDLhPov/HzTFRmJPHMqc+pun+kK+rhMyt t49lJHd5H6HGNgCoLG2T2QmKPd2vU8U8udAouFr6za+s/ipFx7Oc/UR3GV/pp2hmcTH6 uNUP6LHx8hQTCaLGg+528mQyWXh1tE44zbHC7Grznf0MGuK9A1DOl+LlyyK9a6my87qZ 4znOLiWX5u321mJlhNQA4pwrDnKPzoVlWfR9jSmMEGowoRv51AnK/B0FzaqX6nFPT50U iSOsHEw3By3etKbVGNyubebFIYuQ7CnSMoQQ6b1/lOGh8Gb0mrtPGyKZVPSqM1EZTQRm Inxw== X-Forwarded-Encrypted: i=1; AJvYcCW1fkVDCE0Oqb/4NKadlEIhXRJAqmRIcg+GExhF6/UkqCZ13haoKW+la/uS3/+qYyEtdRU+ABY3ttdljiY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4DokD8lHs+3pZAgGeknxN56KzvmGG1A2h2ds3RUXrSjWpS7oz dCd6QAo3reg46ekDC67beoly9YMFN8imLmnPCbsnPjr4H1d8K/uxw8rAJiBcwhkQdto= X-Gm-Gg: ASbGncvdHOur53iOITijTyxbHprtJes+cngQFbKiEMEn+YVPXh7VIJriWZK9XmliIEL N0rWwBbimQ9BLZZ0tbRhPpUdYaB9gpqmQXx4sSDx7LHHXCAHHFludJcASoGb4HpkF7ZSTcZl5UR u6JVVrNkFeJz7JCoxNQawmozq3HH+0hfYpgmHdlSkfbhnXZ0c/c8VVqHi8ustDqYTwAHiaW6KDO nAUWSHVjFHPpbaPqujx1XK7TnKuIa8HO5QAxWrl6Sbn65qD9ejUlhpnFb4KNJbRK/nbdZtyQALL HZjxHb7J6QqOj9uV/COC9OJrDijeWwcOba4YccvRaVZ+oT/ubzAD1bvAoQUrWSNep6N8uKX48D7 gU5So4M9h6S06fa50nKyEPABrvZWMQ9lGYjZtPiA4+jRlSJnswwTnVLRhr/x2zY0X0siLmpkFQ6 8M/Y827n50Dbf/iaRE5B6FRtUHrMeItMhZk1VPKqiGbks5b6s5Co/qSQI= X-Google-Smtp-Source: AGHT+IFWj/Ge/LlTmUk4BGvK2jv7sYmbYypwkakcaLNVvSYRcxAzMelD2Tv37gWsl3Gu0g8hT2LecA== X-Received: by 2002:a17:903:98d:b0:297:fec4:1557 with SMTP id d9443c01a7336-29b6bfaf6c0mr239034795ad.60.1764248023704; Thu, 27 Nov 2025 04:53:43 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bce470347sm17771255ad.41.2025.11.27.04.53.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Nov 2025 04:53:43 -0800 (PST) From: Yunhui Cui To: conor@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, cuiyunhui@bytedance.com, luxu.kernel@bytedance.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, jassisinghbrar@gmail.com, conor.dooley@microchip.com, valentina.fernandezalanis@microchip.com, catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, timothy.hayes@arm.com, lpieralisi@kernel.org, arnd@arndb.de, kees@kernel.org, tglx@linutronix.de, viresh.kumar@linaro.org, boqun.feng@gmail.com, linux-arm-kernel@lists.infradead.org, cleger@rivosinc.com, atishp@rivosinc.com, ajones@ventanamicro.com Subject: [PATCH v3 3/8] smp: move num_other_online_cpus() into smp.h Date: Thu, 27 Nov 2025 20:53:00 +0800 Message-Id: <20251127125305.89961-4-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251127125305.89961-1-cuiyunhui@bytedance.com> References: <20251127125305.89961-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove duplicate definitions from arm64/riscv, add unified implementation in smp.h. Signed-off-by: Yunhui Cui --- arch/arm64/kernel/smp.c | 11 ----------- arch/riscv/kernel/smp.c | 11 ----------- include/linux/smp.h | 11 +++++++++++ 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 68cea3a4a35ca..2d1e7839dc9b0 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -1171,17 +1171,6 @@ void tick_broadcast(const struct cpumask *mask) } #endif =20 -/* - * The number of CPUs online, not counting this CPU (which may not be - * fully online and so not counted in num_online_cpus()). - */ -static inline unsigned int num_other_online_cpus(void) -{ - unsigned int this_cpu_online =3D cpu_online(smp_processor_id()); - - return num_online_cpus() - this_cpu_online; -} - void smp_send_stop(void) { static unsigned long stop_in_progress; diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index 9dbcb9a06a96d..669325e68a21a 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -272,17 +272,6 @@ void smp_send_stop(void) } =20 #ifdef CONFIG_KEXEC_CORE -/* - * The number of CPUs online, not counting this CPU (which may not be - * fully online and so not counted in num_online_cpus()). - */ -static inline unsigned int num_other_online_cpus(void) -{ - unsigned int this_cpu_online =3D cpu_online(smp_processor_id()); - - return num_online_cpus() - this_cpu_online; -} - void crash_smp_send_stop(void) { static int cpus_stopped; diff --git a/include/linux/smp.h b/include/linux/smp.h index 18e9c918325e5..5300c5c14232b 100644 --- a/include/linux/smp.h +++ b/include/linux/smp.h @@ -275,6 +275,17 @@ static inline int get_boot_cpu_id(void) #define get_cpu() ({ preempt_disable(); __smp_processor_id(); }) #define put_cpu() preempt_enable() =20 +/* + * The number of CPUs online, not counting this CPU (which may not be + * fully online and so not counted in num_online_cpus()). + */ +static inline unsigned int num_other_online_cpus(void) +{ + unsigned int this_cpu_online =3D cpu_online(smp_processor_id()); + + return num_online_cpus() - this_cpu_online; +} + /* * Callback to arch code if there's nosmp or maxcpus=3D0 on the * boot command line: --=20 2.39.5 From nobody Mon Dec 1 22:07:35 2025 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20FA0331A5F for ; Thu, 27 Nov 2025 12:53:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248034; cv=none; b=QFC2Kb5u1CwE9b2btyaVQVVoNU/YI0vM0l1HK055FlMRfdac4P2ekqBRCF+7CJH8Pw9+i927HKspWi9ck5jX6Y6ndFToq3OHlEog3ddEPeEwPCaPsBcbeApTeNrX50mWbJ6UT/IsNOh/Fi+Ba11lPw59qzG/ULqisC4zwBil1VY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248034; c=relaxed/simple; bh=JK2ZqWIIEMvEMggTQEZx4lZeLQ4MLvkRVnT3Nub+wEQ=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=I68dxvZVf/PAV+F7+4MU1AlrsM9paqZvfU1LoQFWHwxZb81Skuq5lBnxHQ3dos3qEsgvHWqA6DomHxDmXJ6KpEzDNS2ioMGWAoIR/+a5VehCbn0oQUaOt/zaT3fduPHpNFDgqPJ/oBSkNXo7S3kiNa9Z3rcW7Nmt4MQW0f2XiIw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=Vql80FR8; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="Vql80FR8" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2953e415b27so9509105ad.2 for ; Thu, 27 Nov 2025 04:53:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1764248032; x=1764852832; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ekEUQQGglKUm+pQmuNFUFd1vkJX+rIRh1mBD2DC3QW8=; b=Vql80FR82vBBXRpASkzcsjL0Ms2nibMACpolRdk9qaTS9bWy+dBeecNYVZ4hjmkvJW tYdHKpPx2WJJpmFH+9J9EMZqhBvtgGMj/bt4iH0qgwOwTWwb1sZJ7IBYu7wPLRTIm4p+ FQ1byO5mtiU0HpH3qXU5+AeoZRh4naEGxWmay/ex7md5rjC0akj8CDNaoSMdEYsSmC4m ac6vK9XLp1NwQmnALDuFXkiv1TSwUF2HCEabpIx0i/rhmB+GIFMZuovJw7VqhCom+W5a 3zF/pqi4pa3OOAlVdyvLElqujDN43ssrcDgUSWH5kTuNg3SB94uNBcI9U9PvITS4IYvF NIUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764248032; x=1764852832; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ekEUQQGglKUm+pQmuNFUFd1vkJX+rIRh1mBD2DC3QW8=; b=GpguHhe3v9do8NxUiPcD6yGY8VOw9r9jM4vQZYxvAMwWNuFrWhNpEwBjwu0WUa3HeR 3OhfZqdO8nEt4UQwC3H+qIiwS9Os5I7DWXU/al7X4EuwN9TeieYtz9/i4cnMDwTeOSdi XT0wZXXdw7thvoUklLGVyE54m7IZe1CUIQlj9Sgqn8JukZPsGpZkHF7ewlnj8F9u8KLN xmyE5THvwnOHmyTZW/mORGPAQ5qP7hrM1pI3qRaCX3m/SNu/XJODIif43lHHO+rqZLft LRGn0t0ke3HY5RfvAXeOA1x5FrmHridkCycHPqxSUyXA/9btc3oG84bYMQF0hchsk+OE cZeQ== X-Forwarded-Encrypted: i=1; AJvYcCV7nOVA3UprJfuAQ7B5+1nHPYbNPgAA4QJFhGSOOGgAmTI1X92ylEig2wzB4o7rzNegwAaK04W2meGSkUc=@vger.kernel.org X-Gm-Message-State: AOJu0YxrXgJv7ug7ajTp+z+CVgyz/k5obbpZa/9cWB6m4OpF1CDL+qRl NUVEh4itZ/RN6RN4XZzEmyQcjE/vS/2CPDwJJ5FUleeoQFvt19VXBdvAD/VYRQu8lC8= X-Gm-Gg: ASbGnct7L50NFWXz9uTfDolfYvP1toY5b+RIc3iFxt7wJLUHzuFmiCHurxerl7eVgH7 Uzqyc5x0D8Z3DukWjQHNlMBD8NC/qGbxY30P5OaSHagIeiigSrx9cx8puJ5K+v9H7QtRT57A1Rv 6O2qBIS5N9gBuCqYFR3/Gv0DlgAWDDyj1+ZjV1nk5dfxTgidKyV0oG38mpjwErIA0x+xH+Vg3Ch ovDx71K0Wgi9prF0uu479IURWOEWhCNC0/1YWZEfQPmdC3hw5ZGG0pYxlSsRTUOs/eCkVhbOTlD hm2QajUEUDz9NBq05I5KEclFo8FbKlw96YIa5fj1USh9OyJNPeWEW2s/ZTxp+qgN7Cylnb8+t49 asxGD9T+L+Sm9mi050KPq+rlbYlxnDzSFldyVZk0KSs83LiGyCONcge3mOPtPoVeHb99MxeLGtH WnyHKZH8OqyhkJey1H9e3/78WyssXFKntoD7TKtXqYgrig X-Google-Smtp-Source: AGHT+IGkFjWMbmIGHNf6UcjgbW4i6Qoh9WFvC99RcWljyWTEaWXbPXGfrJnhhVQpJadpguwolGNYMg== X-Received: by 2002:a17:902:c44a:b0:295:34ba:7afa with SMTP id d9443c01a7336-29bab19b21emr77811615ad.43.1764248031954; Thu, 27 Nov 2025 04:53:51 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bce470347sm17771255ad.41.2025.11.27.04.53.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Nov 2025 04:53:51 -0800 (PST) From: Yunhui Cui To: conor@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, cuiyunhui@bytedance.com, luxu.kernel@bytedance.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, jassisinghbrar@gmail.com, conor.dooley@microchip.com, valentina.fernandezalanis@microchip.com, catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, timothy.hayes@arm.com, lpieralisi@kernel.org, arnd@arndb.de, kees@kernel.org, tglx@linutronix.de, viresh.kumar@linaro.org, boqun.feng@gmail.com, linux-arm-kernel@lists.infradead.org, cleger@rivosinc.com, atishp@rivosinc.com, ajones@ventanamicro.com Subject: [PATCH v3 4/8] riscv: smp: use NMI for crash stop Date: Thu, 27 Nov 2025 20:53:01 +0800 Message-Id: <20251127125305.89961-5-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251127125305.89961-1-cuiyunhui@bytedance.com> References: <20251127125305.89961-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use NMI instead of IPI for crash stop if RISC-V SSE NMI is supported. Signed-off-by: Yunhui Cui --- arch/riscv/kernel/smp.c | 11 ++++++++++- drivers/firmware/riscv/riscv_sse_nmi.c | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index 669325e68a21a..1b8cf986abbd0 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -300,7 +301,15 @@ void crash_smp_send_stop(void) atomic_set(&waiting_for_crash_ipi, num_other_online_cpus()); =20 pr_crit("SMP: stopping secondary CPUs\n"); - send_ipi_mask(&mask, IPI_CPU_CRASH_STOP); + + /* + * Not a high frequency operation and is in final state, directly use + * NMI instead of IPI to ensure reliability. + */ + if (!nmi_support()) + send_ipi_mask(&mask, IPI_CPU_CRASH_STOP); + else + send_nmi_mask(&mask, LOCAL_NMI_CRASH); =20 /* Wait up to one second for other CPUs to stop */ timeout =3D USEC_PER_SEC; diff --git a/drivers/firmware/riscv/riscv_sse_nmi.c b/drivers/firmware/risc= v/riscv_sse_nmi.c index 752ee88b230da..add028efd25a0 100644 --- a/drivers/firmware/riscv/riscv_sse_nmi.c +++ b/drivers/firmware/riscv/riscv_sse_nmi.c @@ -10,6 +10,9 @@ #include #include =20 +#define NMI_HANDLE(mask, func, ...) \ + do { if (type & (mask)) func(__VA_ARGS__); } while (0) + static bool nmi_available; static struct sse_event *local_nmi_evt; static DEFINE_PER_CPU(atomic_t, local_nmi) =3D ATOMIC_INIT(LOCAL_NMI_NONE); @@ -49,6 +52,15 @@ void send_nmi_mask(cpumask_t *mask, enum local_nmi_type = type) =20 static int local_nmi_handler(u32 evt, void *arg, struct pt_regs *regs) { + enum local_nmi_type type; + unsigned int cpu =3D smp_processor_id(); + + type =3D atomic_read(this_cpu_ptr(&local_nmi)); + + NMI_HANDLE(LOCAL_NMI_CRASH, cpu_crash_stop, cpu, regs); + + atomic_andnot(type, this_cpu_ptr(&local_nmi)); + return 0; } =20 --=20 2.39.5 From nobody Mon Dec 1 22:07:35 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4D0932F76C for ; Thu, 27 Nov 2025 12:54:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248043; cv=none; b=JaaBN6g+pRtm3DXrcIZqrxJbu5dtBcDGjEFSyniDB+RXMDhR32ebzBgVTGSTNY8ofeAX5/umRjeCE/k7EHe5RAbWPvd6b1adsa+33bAQLqkcMKJ6bzTvMxqOUqo3LAHFehJ/173Qm3g7MIzHRq0e3FF/IpfjH0c6WCZbU7EQqLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248043; c=relaxed/simple; bh=FSXcMcG9gy2R/XAkB5iJJq0f5SCVT3E7zyE+xw/VIiE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WM03aPqi+B95lTgMvn8C2g46/ESVGqWqBJVwmWs+RPwyO9sfGMVK9OkJisXitHXc32aP8ydG1oZ2EBeYgfIrA/7yqfyZtl751GI61CmlmcA9LhM01ZHR8VP2PSAvorSA7+ZBwaZ06hboqlt5cwtwFEZlQpNnAXhADqEp3h9jksk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=iObTcefb; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="iObTcefb" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-297e264528aso9512895ad.2 for ; Thu, 27 Nov 2025 04:54:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1764248040; x=1764852840; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Ks2N7WiKrF1vmFIuqsgCKEVR33GasRQqyUpzFrSGTVc=; b=iObTcefbHgMyBs4TImgJMcE98TP4d/rpyYPhtscNjyWhH1uymmX33gQRCJB4YqLaya 4NNolklrzFVCcRfrcJNkpJb7lTCvFj8kHG4TEcsHQAQiezzkDtYyiivdba+HnhBYMLf8 AukkTlS0bCK0SitBPTIVEDxmbM/T1+EtC5LgAbYxwClR+4GsBNSSLQ2QhSfuVqfABmdK 9bZ8GJzY8eqqB31vgdWsSHKzsGY2CEA5+wSdkTGDUyIV0D91XH4PsWzSYUelvV8ChgUK L3cacHu+z2mZEQd6YnBtwQ8wmEsAea9LjLTd9kV2T9HPHF/2mWElvPWL1VOGUDRoBRN4 fEOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764248040; x=1764852840; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Ks2N7WiKrF1vmFIuqsgCKEVR33GasRQqyUpzFrSGTVc=; b=Ks0p9MaHHUQzgKp3ayvKZ6iBAO5lT2EXr2vmJLc3+FWiuEex3Q2NzlpVXGfXqZPq0A hXSb/bB69FJkZXwb9v/9Y7ePsPKQ5inR+uL669ANvoK/7ej6DBfC4GSVDdEsRzOGtWlQ F761hpXF9SSOiAr0pTKxopOnkq5+AKW1mw4kVQck4IekqMajuvfRQMwuAyFG/60XXgXM RuEJsobLWWu+kQAdd71VYacoggbvpokLXA2sr4OvxHoUHrjojbsYmZs+QQlge1J5tDxF PM3OJg244O8iqJks+dNzdPOTkwq7BLAYTlQV3dZeJUmIozWHoTunXkEhDwyw/Vb4GEBW omvw== X-Forwarded-Encrypted: i=1; AJvYcCVMA+xIEcyRMjE4ESuaI3xtnSksClC+3so4HcZl40nvCHAdVM9p/XaVvEWiptnGfyilyKYFl6uY8A208+k=@vger.kernel.org X-Gm-Message-State: AOJu0YwwJKDKY/2pHP7I7WMJUzqSKI/KANZwBGgP9W274ze7GWDshSLu bHlduIRZWNRysc9S22EARcY4A6g9CeWUWINFjnPZT0bgwszkhh1oheaDqlUjrYhF7tg= X-Gm-Gg: ASbGncvsnkLFBkPM76uUZc5Owa1WTOLLo64Co/y9vHiEV3QQQUCMEanovgcSeL0VtWR /F9+O1oApu1vcrVp9ffeSfICxiZ3ib9s49VGcUQRrw7vX+//UOg7PAOyd35b923rTh62jf5LBJG WPC4GZv5UPjdpJ+uhbi0LKgBCOlo+sD9CE36/eTQOIikJGa2l5OU7Qtg/0/nmDxNRBxTFe9+hv/ WaYct4DSCIjm0xoGsweWoqTZh6j0QlnEiq0DCUhAIK9MOG8n7vxjiZAvhNrZ86oVQchqkY2d3tD BPQ/qDfY0MsrMxnvpLcXHhhmZlikPtOv+QnDS2V4UDugppLh57JG7ESjGTfamsFRXzkhNenueaO bSb+5oOi6iPGgtNvY40n55FiVqm0fKLRDNmtTXi4zPTUXDtZWYQQJrUmx/SBPW8fG/3ajSpXeAD XY/aWPi/X5cs6AHjrn+epf7j31ayldH8y+u9D1m2CcsT9B X-Google-Smtp-Source: AGHT+IGDuGibd7LowW1oyCK8TgeUaL+QE7qRAlkmjqYkFnpqp1CfVc1mAg7S481yXF2w5bN4beqelg== X-Received: by 2002:a17:903:1acf:b0:295:3e80:9aa4 with SMTP id d9443c01a7336-29baafa939fmr114147395ad.22.1764248040026; Thu, 27 Nov 2025 04:54:00 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bce470347sm17771255ad.41.2025.11.27.04.53.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Nov 2025 04:53:59 -0800 (PST) From: Yunhui Cui To: conor@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, cuiyunhui@bytedance.com, luxu.kernel@bytedance.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, jassisinghbrar@gmail.com, conor.dooley@microchip.com, valentina.fernandezalanis@microchip.com, catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, timothy.hayes@arm.com, lpieralisi@kernel.org, arnd@arndb.de, kees@kernel.org, tglx@linutronix.de, viresh.kumar@linaro.org, boqun.feng@gmail.com, linux-arm-kernel@lists.infradead.org, cleger@rivosinc.com, atishp@rivosinc.com, ajones@ventanamicro.com Subject: [PATCH v3 5/8] riscv: smp: use NMI for CPU stop Date: Thu, 27 Nov 2025 20:53:02 +0800 Message-Id: <20251127125305.89961-6-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251127125305.89961-1-cuiyunhui@bytedance.com> References: <20251127125305.89961-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use NMI instead of IPI for CPU stop if RISC-V SSE NMI is supported. Signed-off-by: Yunhui Cui --- arch/riscv/include/asm/smp.h | 2 ++ arch/riscv/kernel/smp.c | 10 +++++++--- drivers/firmware/riscv/riscv_sse_nmi.c | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h index f53f1f0e7aa9e..e01ea962adfc4 100644 --- a/arch/riscv/include/asm/smp.h +++ b/arch/riscv/include/asm/smp.h @@ -63,6 +63,8 @@ static inline void cpu_crash_stop(unsigned int cpu, struc= t pt_regs *regs) } #endif =20 +void cpu_stop(void); + /* Secondary hart entry */ asmlinkage void smp_callin(void); =20 diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index 1b8cf986abbd0..bca95ec0b0f74 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -69,7 +69,7 @@ int riscv_hartid_to_cpuid(unsigned long hartid) return -ENOENT; } =20 -static void ipi_stop(void) +void cpu_stop(void) { set_cpu_online(smp_processor_id(), false); while (1) @@ -127,7 +127,7 @@ static irqreturn_t handle_IPI(int irq, void *data) generic_smp_call_function_interrupt(); break; case IPI_CPU_STOP: - ipi_stop(); + cpu_stop(); break; case IPI_CPU_CRASH_STOP: cpu_crash_stop(cpu, get_irq_regs()); @@ -259,7 +259,11 @@ void smp_send_stop(void) =20 if (system_state <=3D SYSTEM_RUNNING) pr_crit("SMP: stopping secondary CPUs\n"); - send_ipi_mask(&mask, IPI_CPU_STOP); + + if (!nmi_support()) + send_ipi_mask(&mask, IPI_CPU_STOP); + else + send_nmi_mask(&mask, LOCAL_NMI_CRASH); } =20 /* Wait up to one second for other CPUs to stop */ diff --git a/drivers/firmware/riscv/riscv_sse_nmi.c b/drivers/firmware/risc= v/riscv_sse_nmi.c index add028efd25a0..02e2de2bb70f7 100644 --- a/drivers/firmware/riscv/riscv_sse_nmi.c +++ b/drivers/firmware/riscv/riscv_sse_nmi.c @@ -58,6 +58,7 @@ static int local_nmi_handler(u32 evt, void *arg, struct p= t_regs *regs) type =3D atomic_read(this_cpu_ptr(&local_nmi)); =20 NMI_HANDLE(LOCAL_NMI_CRASH, cpu_crash_stop, cpu, regs); + NMI_HANDLE(LOCAL_NMI_STOP, cpu_stop); =20 atomic_andnot(type, this_cpu_ptr(&local_nmi)); =20 --=20 2.39.5 From nobody Mon Dec 1 22:07:35 2025 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1735119CD1D for ; Thu, 27 Nov 2025 12:54:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248051; cv=none; b=AJMO3hUmymQiY+08WuBgsTGTF5US+kxoKUGeF4REVTdQF8ggSuMIRCBBc7dNzkRuYPVbSDI7X5CjUpfi/KjvNndOtvlUUS4TD5ofts/0UZY+dfMzOHy+u0u1FBMhdO13Ebzfv45ZuQXC/n4n+fgZ6OJxeKiq6mmCqz8Yj233Vi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248051; c=relaxed/simple; bh=I30O9jNqCgja6Z3pO1gfj/LBNi5h52jPGJZMV4ihSEM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L6XcqdAgtNMAJzE6Q0rpSOHNOjzCRuzf89ptrGp4X3L28f3Jc1TEmKnrtOU4HYIE7ESkR51IkTyl5hcy1XePJP4kTj3wylUjJzjc9ccdXe0YRWOhfI27JIOPc6Xro5//H9VeIY7MSzButcvgK5Uz7j2rMlZyUPWXo4vsAVZplAU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=MfKnKfG1; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="MfKnKfG1" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-298144fb9bcso8621215ad.0 for ; Thu, 27 Nov 2025 04:54:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1764248048; x=1764852848; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=M+jTpL/HthRsBGxB3Q2ZvpHSHqmwjwHrkZeOIM2209Q=; b=MfKnKfG1BqtoSu/EX+3e3EdQuFOD7dsuE4gL/MRn4s3fiVAKOeKofezLAa7pSs8+R/ eXqLBnT1tssTdR0PbNDdwQBZeaTynwLEKfuJ2s4SyitdJvXy18EIabt+5xgoUHNNeF89 HO6xvZP4w5/toAteqjL092cl0LYE/uHYMDkTIr0V95pbb8T2/qBLO+GHscyX11B4v1PQ IWIGowVJgVY5lDw4geMxzzl1gWSHp2wc+f8TQ1CvJHYb4ih8XfhEL1q9uYeKXUw/OFlp hZRyoYeRALJZtti9JebHMV2kuBFlrclp8HT5mVwpLdFeCW+nJ2+aTgRyaZUaKu/+T66+ SB+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764248048; x=1764852848; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=M+jTpL/HthRsBGxB3Q2ZvpHSHqmwjwHrkZeOIM2209Q=; b=eUFOi34pLygIcGHPKM7IXodv73YuqXvJqkwrJV66Rkw/YjcA2D8Bcvx5ji/Q/wrUQB aOHq3senZMfJkaju2hWtRBc5ptstkli8eCrhaznHE2ibgyY449OJj7Hw7far8WBFUAAO +N4+qqC8z+V1Aty6Ryta84qyarFiJciQW51n5wosZ66AFDfvrxq9N/7Pak/PVYTxqyRh YmB2RRBH/ryiQ/cTxurf3vgstMUSDEDFudGphWmTI+yE7pAAfgTUHiD+0gRWGw0qCJM1 vsy7zcnHL268ZnHEukDMPMHDO4YELkN78vIvibm73spcKP3hJzQCdniLrnGwHUG3G7UF 0Dcw== X-Forwarded-Encrypted: i=1; AJvYcCXX0rHzwnJxYcybnLV8SfGPLNDJEI0BV+QcxSa4v+g4pwekhn6+klvUWkbU1eGrP33bE1hryPOpA4FwqmQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxqjMND0Pl4xbntcmcN3D3dZu8r3octSsCeBfa/SQhvaUP555+y NlAhOGxgDK8EvVeCXnDoRH6xRVNqGIHS5bUr4Qxi+mhW8utqah3D0pChGC0JiakuY4U= X-Gm-Gg: ASbGnct4qMB8H5LWxGuW/z7tyOwmBbx66oM9DKAyffP8hlwlM4yB5jwwb+419j46N45 QHDv3fOVduO/E8nYPO9/O7mEYTMSQddUFDRaB92SJMkh9dnwJ7PXKKQPrSY/spLhUBzGRyt09XT 8oNQhN5jBdqKiPL4wPDEPL4sB2Dsx+btJ1jZDreJ/OHa8HCF4CTiNLLMUcjjY7NFUkj+njhQDwf NvqCk26woaOv3NxIg4MeWDT2u6sW7AFvZSDBCM1NVZnRQEQwmiPftcNJ61OcQvXWovWEIyoo8S/ HKwtO2Mzpl6vQM3RXMajfvFMqBop4tCaHl2Vt8Qxpz/k+W2A9K+/GRm0A8eln5JeCwpAJ6+moDn 3KrPfcpgPdVLQK6rjExvCQZggybT9qlsZV5L7YTUhgP6E78XCGdqWEpW3Rqzs/bYpkp+2BUT42P XRNsWGKhAUrCsfxKYtde66M34uBNOnWGS+SH394M1LiWnU X-Google-Smtp-Source: AGHT+IG7drzon1SEfVMmYQlVlllrpZTrqpn/kBxmqkQQMT6P+x5y8+0dsVV7yCSCC0f84pvUbVhN3A== X-Received: by 2002:a17:903:2412:b0:297:f0a8:e84c with SMTP id d9443c01a7336-29bab1d73ebmr115182445ad.52.1764248048104; Thu, 27 Nov 2025 04:54:08 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bce470347sm17771255ad.41.2025.11.27.04.54.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Nov 2025 04:54:07 -0800 (PST) From: Yunhui Cui To: conor@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, cuiyunhui@bytedance.com, luxu.kernel@bytedance.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, jassisinghbrar@gmail.com, conor.dooley@microchip.com, valentina.fernandezalanis@microchip.com, catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, timothy.hayes@arm.com, lpieralisi@kernel.org, arnd@arndb.de, kees@kernel.org, tglx@linutronix.de, viresh.kumar@linaro.org, boqun.feng@gmail.com, linux-arm-kernel@lists.infradead.org, cleger@rivosinc.com, atishp@rivosinc.com, ajones@ventanamicro.com Subject: [PATCH v3 6/8] riscv: smp: use NMI for backtrace Date: Thu, 27 Nov 2025 20:53:03 +0800 Message-Id: <20251127125305.89961-7-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251127125305.89961-1-cuiyunhui@bytedance.com> References: <20251127125305.89961-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use NMI instead of IPI for backtrace if RISC-V SSE NMI is supported. Signed-off-by: Yunhui Cui --- arch/riscv/kernel/smp.c | 12 +++++++++++- drivers/firmware/riscv/riscv_sse_nmi.c | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index bca95ec0b0f74..6d9a67c2c2a6e 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -342,9 +342,19 @@ static void riscv_backtrace_ipi(cpumask_t *mask) send_ipi_mask(mask, IPI_CPU_BACKTRACE); } =20 +static void riscv_backtrace_nmi(cpumask_t *mask) +{ + send_nmi_mask(mask, LOCAL_NMI_BACKTRACE); +} + void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu) { - nmi_trigger_cpumask_backtrace(mask, exclude_cpu, riscv_backtrace_ipi); + if (!nmi_support()) + nmi_trigger_cpumask_backtrace(mask, exclude_cpu, + riscv_backtrace_ipi); + else + nmi_trigger_cpumask_backtrace(mask, exclude_cpu, + riscv_backtrace_nmi); } =20 #ifdef CONFIG_KGDB diff --git a/drivers/firmware/riscv/riscv_sse_nmi.c b/drivers/firmware/risc= v/riscv_sse_nmi.c index 02e2de2bb70f7..a138d6bdbc0d1 100644 --- a/drivers/firmware/riscv/riscv_sse_nmi.c +++ b/drivers/firmware/riscv/riscv_sse_nmi.c @@ -3,6 +3,7 @@ #define pr_fmt(fmt) "SSE NMI: " fmt =20 #include +#include #include #include =20 @@ -59,6 +60,7 @@ static int local_nmi_handler(u32 evt, void *arg, struct p= t_regs *regs) =20 NMI_HANDLE(LOCAL_NMI_CRASH, cpu_crash_stop, cpu, regs); NMI_HANDLE(LOCAL_NMI_STOP, cpu_stop); + NMI_HANDLE(LOCAL_NMI_BACKTRACE, nmi_cpu_backtrace, regs); =20 atomic_andnot(type, this_cpu_ptr(&local_nmi)); =20 --=20 2.39.5 From nobody Mon Dec 1 22:07:35 2025 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7647A1DF994 for ; Thu, 27 Nov 2025 12:54:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248059; cv=none; b=oA/pXdgtkL2cEUrLuRAHS0b7UOAqTvMXfwQGvFhfGTBkE+DNNKW8WLpOh6BimQTPcUcoVC3kuAlwSHp/JfiULucLE7Y8A7dB3jbBgz1ilLkHuJkUrhzklkjLSTxZgIPw+SrzBiOc3lsd6U9YzL8MN8HZn8V+TvpQXvokOSc23Ro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248059; c=relaxed/simple; bh=rnSX7Ak0EAA/CBkbrD4UJp9biUdZzKvWUFu+k0xkG3g=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bwgDIvMadlo0BUvST5CX7yhqMQ2m7YS3WM+Or7518ef4AS69bbtLYfSfJS0a1Uu6wy3IL5WObsSrPabzTC4bZ+OBJV0ZGnihgyMLPd81Mkf0momFtHtzdqmyg59+/BthUxToG5T2KAuEvpy5Cf3T6qbSZwA4bCpH+HOwlGn7svU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=H3r73jI2; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="H3r73jI2" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-298250d7769so6055565ad.0 for ; Thu, 27 Nov 2025 04:54:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1764248057; x=1764852857; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=fWkOyJ5AcV33EEWNye1AG75lZoiCez1+DCGpMn2n8h0=; b=H3r73jI2vffpf9PRZ5H33xhs/eRIXuk5LeIVi8EDKhI8t0Ul5BmzLEm6FObPVNc2j+ jOkeDVlLpyiJSdjlpivEBHECuhxhgNEIbHRQfF1N/AmnNAugDybkkE7bl4kzHhuXQU1d 7ebx1dKzeFf2IKhBMZwOsN1r4w6wmltnzBPcV0thfAxpERzmooyc488EVvsgvG0K9hte 4kDKT16LN+jq5LF4RdELVsRGuAx8GdW4wKET4I4DCUzg9olpS15Ax9Rr8qlfvHfsGrx9 tGow7BoUD91PND7bBB43R0uGKEASjLSIXAYp+zuV4AhpPUESYw6VWrIjsPdSf/7mo95n 381Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764248057; x=1764852857; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=fWkOyJ5AcV33EEWNye1AG75lZoiCez1+DCGpMn2n8h0=; b=fbm+3KBLqgm40uUo7iYXYOYscv/+qUzWFmLna4D7Hu/nYfkEOkuPswM0W4K0ZJdj45 P4pfO59lNDAYLy1QXMPsNHe1XYA+Xwcj+kHzqi5QwPJKDSxqvi3hSTeuCt/Y/OCD9Ah7 tdd66ZGhWD551IxrdZw7Ie1UgJvP9r12rRc9LqvLVacap0e9Ti7vqZ4M18SusTshtcu6 zFemWPxGj36YwGWs93cL1fSfXTOEoJBdjw5ZdYvH8knQDIBuaqQhQKAwEGJeQXmPIXb+ 5G3Eq4WqK+oDOcfhL36cN52fmAeUAgVDodujYQd1BitiQF1auWG6evAc5MgrbvQobFy2 48lw== X-Forwarded-Encrypted: i=1; AJvYcCU4bD4P9V/s8RXgxKQyYWcFuJ2lUCeVCbgJtj2aq2vGZ23NknqMyn38V08HJgYr77kLhK7JQm2BDIE7Rc8=@vger.kernel.org X-Gm-Message-State: AOJu0YxMhtbtWEjTPeBCeAiU6xYB7i9DJPkQu4EsE9d5qqknr0Io2fc3 UwMRt6zOcCGNKIYeP/63GlXzaIfEONGBGP5oJLaIWe5+dVzMOz2eKv4WjNVkFVLXHvg= X-Gm-Gg: ASbGncslfQEk1+H8fo75XBIsftCj2TobD6KYxHkBN4XuOial9yhhPyNC/Pa2cV1oNxX pwlEfQ71rjhk9NSPmnT8A6FLOEFPIM/ShDl0pQT4TU/E2WTXmzjdBiTXyA2mw8zzTh2tdrwiOQH zXhlh7e2dDp8VOgakoLoTkQkx9K4naCgDQ4bsPHuLOG2wGgbdm+gLeRpHdcenu3tsSIMPpiYYUj VrmUWmCzgTR572e9XA5LGFezR6weEIqlHdb7SNMLppGt/gFiY9/DveSIZZdmtsjC6z/Rr9tgLpA go9BOcUreQjZrV2TpdUSz+BGYKAaLzglFZ8kPe68O+Q0kZMxMKcZ44EFYwNmiko6LklcmNOteDh EYeys1S39gnroAyIm5XROrDAYGbjzv2pAOmKOTaLH+OYrLeqOwn0jENN5FMO5+lfOh3Klq2JWDG pxgyIElc3DaLOlcmjv8ath5xedbc7wEq3ngBG1rYHz5FTF X-Google-Smtp-Source: AGHT+IHfDsQKz8tAmdnpj9oG+MYaFIwY7KvVCZ53LvFxGr4u9uSgj1+YFJnBx9PPYOIc/+SZwAFzqw== X-Received: by 2002:a17:903:292:b0:298:43f4:cc4b with SMTP id d9443c01a7336-29b6c50c632mr250127435ad.26.1764248056650; Thu, 27 Nov 2025 04:54:16 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bce470347sm17771255ad.41.2025.11.27.04.54.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Nov 2025 04:54:16 -0800 (PST) From: Yunhui Cui To: conor@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, cuiyunhui@bytedance.com, luxu.kernel@bytedance.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, jassisinghbrar@gmail.com, conor.dooley@microchip.com, valentina.fernandezalanis@microchip.com, catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, timothy.hayes@arm.com, lpieralisi@kernel.org, arnd@arndb.de, kees@kernel.org, tglx@linutronix.de, viresh.kumar@linaro.org, boqun.feng@gmail.com, linux-arm-kernel@lists.infradead.org, cleger@rivosinc.com, atishp@rivosinc.com, ajones@ventanamicro.com Subject: [PATCH v3 7/8] riscv: smp: kgdb: use NMI for CPU roundup Date: Thu, 27 Nov 2025 20:53:04 +0800 Message-Id: <20251127125305.89961-8-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251127125305.89961-1-cuiyunhui@bytedance.com> References: <20251127125305.89961-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use NMI for kgdb CPU roundup if RISC-V SSE NMI is available. Signed-off-by: Yunhui Cui --- arch/riscv/kernel/smp.c | 5 ++++- drivers/firmware/riscv/riscv_sse_nmi.c | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index 6d9a67c2c2a6e..84436e348b6ea 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -368,7 +368,10 @@ void kgdb_roundup_cpus(void) if (cpu =3D=3D this_cpu) continue; =20 - send_ipi_single(cpu, IPI_KGDB_ROUNDUP); + if (!nmi_support()) + send_ipi_single(cpu, IPI_KGDB_ROUNDUP); + else + send_nmi_single(cpu, LOCAL_NMI_KGDB); } } #endif diff --git a/drivers/firmware/riscv/riscv_sse_nmi.c b/drivers/firmware/risc= v/riscv_sse_nmi.c index a138d6bdbc0d1..85aa65f31943b 100644 --- a/drivers/firmware/riscv/riscv_sse_nmi.c +++ b/drivers/firmware/riscv/riscv_sse_nmi.c @@ -3,6 +3,7 @@ #define pr_fmt(fmt) "SSE NMI: " fmt =20 #include +#include #include #include #include @@ -61,6 +62,7 @@ static int local_nmi_handler(u32 evt, void *arg, struct p= t_regs *regs) NMI_HANDLE(LOCAL_NMI_CRASH, cpu_crash_stop, cpu, regs); NMI_HANDLE(LOCAL_NMI_STOP, cpu_stop); NMI_HANDLE(LOCAL_NMI_BACKTRACE, nmi_cpu_backtrace, regs); + NMI_HANDLE(LOCAL_NMI_KGDB, kgdb_nmicallback, cpu, regs); =20 atomic_andnot(type, this_cpu_ptr(&local_nmi)); =20 --=20 2.39.5 From nobody Mon Dec 1 22:07:35 2025 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FAD81DF994 for ; Thu, 27 Nov 2025 12:54:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248067; cv=none; b=BE8mp0P4LMjl4wsaOjm3f/dbg15O0j1eBQbYwCbkojI6mxyJ3FsECZ1C11Et/H7dgXdKMv1+S2g6bQA+/b1cpHRjAsvBBBtuo1gmaiPtDTDXb0u6WkDW8RWWZMOeg9/S6VfCbRXSMo/Q7Ho2SYl4WlntAhzqV/HbAQAw7CiTPTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764248067; c=relaxed/simple; bh=d/kl4UdVPgcHeGEXPdIBpKOIWrBIZrxIu9iOCmCrdOc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W3a1Q01Wl/UpoURLH8Otk0fDTq93nJhlEGQSsDjCctU1gH7n+c7ROKY4d2ryQr5Qe2BXyDa2SK3IzwaaExPH7qRceE/hnCnkyXlrNNHgSnUGa1KWr+aQ/iUAOsIUGm4cR69ZxCF78ZfUgHBGOFXkwod/qT2MEKy3WvIBbJatAG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=QAOxTFYF; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="QAOxTFYF" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-29845b06dd2so11247645ad.2 for ; Thu, 27 Nov 2025 04:54:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1764248065; x=1764852865; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Cn2qLDcM5Q0Hk7ii9P/KQYaMCaCobwGUqniWS6mOX/s=; b=QAOxTFYFYbmgxHjI2ZViGa7NaeMAXCgk0whsWjLEj8qZuu47YMG9gAXf1ujHnQukUq gHQ36TeyuqZ3TN6usJVL3YB8NTdAJWap3OpAaafYk0NefL/1XtTiOmXcUJdKd3ax01PW NSDSCQ3stnUEzT3MozCi/auLemq7QthFwUsB+y7ZSoU6BHErgnfuwzzfv0xDQ1Xr+pVn LjsqMBhpYLrV4a+0ITb3/hfbWh944kPLloEPiSqlf2KO51Rct0A72c0a/8Zm9Al6jsIR cXC7IsRSwUWcO7UaGDo4J6F+w0WKCkH5+9a3hGbFh8PO+K8Jm7cr+LHMKxGZKsEG6f7T EKYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764248065; x=1764852865; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Cn2qLDcM5Q0Hk7ii9P/KQYaMCaCobwGUqniWS6mOX/s=; b=A7micVHtwNPiVdSVKdt4Jzd3iWCUY4v2LWfdJOm9r9l+c34R+GNTH43ET/JzIu273E 9N/r7oMmTkvDlmWwtPw4z/wZWu4i08dg2847JoImVMJf6NRvw8t9kJE5FurgQ9UXxCGC FuTJ4bSeb36LpT/Gsfs0n0pwUUCbud40UMxRTWFrx5a1M6TBRUfY1Mj3Hoy0GHbcEYev +xqqz4MCIbsbFrc5l8RqR/HgjXLDJI1K/s1JFG9sLja+pJinVijKPzUu0XWpE9dvzL75 hakb9F2/yVLJW7sr3ENw2tEkL9NfUal1B49+qCg6mNDFzDdP5HXWEF1n4/+V2xWQ2bm5 Iq5w== X-Forwarded-Encrypted: i=1; AJvYcCXboPKZq/5xhd9ffzROsuFWL+A8usAFsxq7NQ4Gmbk9UlNtTU88NaMRiBrz6V9+9ngaxIKRIwLpCftQ1gE=@vger.kernel.org X-Gm-Message-State: AOJu0YyNlClyf5cEZqL3DF56Xqp69FYRsh131k7mPeelc0kWSkzXUU6O RjzNg72BVlKc1cucp++3Hs96+yRE6QffBaF7e0EF+dn2QtRE+srHpfE+IkREz+1nLK4= X-Gm-Gg: ASbGncvMsH4v/X7Pvy7K98rqautRr8xBumIyTVpTSATIYGrulPVCKZ2G6L2g+p2CluV yCNYNEQlbvf83e07u+uZHPU6b/bksqF3b4AZZNwCC82td3Duozip6F/HO4CY+9jsCdFFHWA5F9V 1NshzbLvJ6knee2iDf7NlaTNWoEj98PKgPcdFHKQa4MEjB/LuCukPWOfr2QLB3H/XTJ8WE4CBqg ytlY5v7se7vySAao+nD56wlpXDWkTKJdEq+LjGDNh94HHHmnZ+zexwBPrywjF8+19O5GCGnOUvp Dyo+bsk571KQFMsCnExSxjiI2a1S8/bj4tpJCZ9TG+ONnXde1dnPF9pW0ozZqKTvJS/7uiibUYD cEEjPjzrHMURmrOcsVzU3iJlKzyGwjXDuFe6pL4+T4jzfcmcDeYjbxj5+ugdygjVGIeAfkKPzSi 0pvd+WWm2zzDsphxR1W9u+rZ2UPSPEhwZMr0FLq737e4I5 X-Google-Smtp-Source: AGHT+IEAZqTGZJVNP2wrNdlYDnUqTCKW3NgeNK+bqQtAShTypNyKnPlwOxZ/5vWOPg+U1HVeecPksQ== X-Received: by 2002:a17:902:e890:b0:295:9cb5:ae07 with SMTP id d9443c01a7336-29b6c574f95mr278040245ad.38.1764248065275; Thu, 27 Nov 2025 04:54:25 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bce470347sm17771255ad.41.2025.11.27.04.54.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Nov 2025 04:54:24 -0800 (PST) From: Yunhui Cui To: conor@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, cuiyunhui@bytedance.com, luxu.kernel@bytedance.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, jassisinghbrar@gmail.com, conor.dooley@microchip.com, valentina.fernandezalanis@microchip.com, catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, timothy.hayes@arm.com, lpieralisi@kernel.org, arnd@arndb.de, kees@kernel.org, tglx@linutronix.de, viresh.kumar@linaro.org, boqun.feng@gmail.com, linux-arm-kernel@lists.infradead.org, cleger@rivosinc.com, atishp@rivosinc.com, ajones@ventanamicro.com Subject: [PATCH v3 8/8] drivers: firmware: riscv: add unknown nmi support Date: Thu, 27 Nov 2025 20:53:05 +0800 Message-Id: <20251127125305.89961-9-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251127125305.89961-1-cuiyunhui@bytedance.com> References: <20251127125305.89961-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Register unknown_nmi_handler() as the handler for the UNKNOWN_NMI event. When the system becomes unresponsive, unknown_nmi_handler() can be manually triggered, which in turn invokes nmi_panic() to collect vmcore for root cause analysis. Signed-off-by: Yunhui Cui --- arch/riscv/include/asm/sbi.h | 1 + drivers/firmware/riscv/riscv_sse_nmi.c | 68 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 874cc1d7603a5..52d3fdf2d4cc1 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -486,6 +486,7 @@ enum sbi_sse_attr_id { #define SBI_SSE_EVENT_LOCAL_LOW_PRIO_RAS 0x00100000 #define SBI_SSE_EVENT_GLOBAL_LOW_PRIO_RAS 0x00108000 #define SBI_SSE_EVENT_LOCAL_SOFTWARE_INJECTED 0xffff0000 +#define SBI_SSE_EVENT_LOCAL_UNKNOWN_NMI 0xffff0001 #define SBI_SSE_EVENT_GLOBAL_SOFTWARE_INJECTED 0xffff8000 =20 #define SBI_SSE_EVENT_PLATFORM BIT(14) diff --git a/drivers/firmware/riscv/riscv_sse_nmi.c b/drivers/firmware/risc= v/riscv_sse_nmi.c index 85aa65f31943b..d98015d1cb893 100644 --- a/drivers/firmware/riscv/riscv_sse_nmi.c +++ b/drivers/firmware/riscv/riscv_sse_nmi.c @@ -7,6 +7,7 @@ #include #include #include +#include =20 #include #include @@ -16,7 +17,10 @@ do { if (type & (mask)) func(__VA_ARGS__); } while (0) =20 static bool nmi_available; +static int unknown_nmi_panic; static struct sse_event *local_nmi_evt; +static struct sse_event *unknown_nmi_evt; +static struct ctl_table_header *unknown_nmi_sysctl_header; static DEFINE_PER_CPU(atomic_t, local_nmi) =3D ATOMIC_INIT(LOCAL_NMI_NONE); =20 bool nmi_support(void) @@ -52,6 +56,35 @@ void send_nmi_mask(cpumask_t *mask, enum local_nmi_type = type) send_nmi_single(cpu, type); } =20 +static int __init setup_unknown_nmi_panic(char *str) +{ + unknown_nmi_panic =3D 1; + return 1; +} +__setup("unknown_nmi_panic", setup_unknown_nmi_panic); + +static const struct ctl_table unknown_nmi_table[] =3D { + { + .procname =3D "unknown_nmi_panic", + .data =3D &unknown_nmi_panic, + .maxlen =3D sizeof(bool), + .mode =3D 0644, + .proc_handler =3D proc_dobool, + }, +}; + +static int unknown_nmi_handler(u32 evt, void *arg, struct pt_regs *regs) +{ + pr_emerg("NMI received for unknown on CPU %d.\n", smp_processor_id()); + + if (unknown_nmi_panic) + nmi_panic(regs, "NMI: Not continuing"); + + pr_emerg("Dazed and confused, but trying to continue\n"); + + return 0; +} + static int local_nmi_handler(u32 evt, void *arg, struct pt_regs *regs) { enum local_nmi_type type; @@ -69,6 +102,35 @@ static int local_nmi_handler(u32 evt, void *arg, struct= pt_regs *regs) return 0; } =20 +static int unknown_nmi_init(void) +{ + int ret; + + unknown_nmi_evt =3D sse_event_register(SBI_SSE_EVENT_LOCAL_UNKNOWN_NMI, 0, + unknown_nmi_handler, NULL); + if (IS_ERR(unknown_nmi_evt)) + return PTR_ERR(unknown_nmi_evt); + + ret =3D sse_event_enable(unknown_nmi_evt); + if (ret) + goto err_unregister; + + unknown_nmi_sysctl_header =3D register_sysctl("kernel", unknown_nmi_table= ); + if (!unknown_nmi_sysctl_header) { + ret =3D -ENOMEM; + goto err_disable; + } + + pr_info("Using SSE for unknown NMI event delivery\n"); + return 0; + +err_disable: + sse_event_disable(unknown_nmi_evt); +err_unregister: + sse_event_unregister(unknown_nmi_evt); + return ret; +} + static int __init local_nmi_init(void) { int ret; @@ -101,6 +163,12 @@ static int __init sse_nmi_init(void) =20 WRITE_ONCE(nmi_available, true); =20 + ret =3D unknown_nmi_init(); + if (ret) { + pr_err("Unknown_nmi_init failed with error %d\n", ret); + return ret; + } + return 0; } =20 --=20 2.39.5