[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250401113616.204203-10-Neeraj.Upadhyay@amd.com>
Date: Tue, 1 Apr 2025 17:06:08 +0530
From: Neeraj Upadhyay <Neeraj.Upadhyay@....com>
To: <linux-kernel@...r.kernel.org>
CC: <bp@...en8.de>, <tglx@...utronix.de>, <mingo@...hat.com>,
<dave.hansen@...ux.intel.com>, <Thomas.Lendacky@....com>, <nikunj@....com>,
<Santosh.Shukla@....com>, <Vasant.Hegde@....com>,
<Suravee.Suthikulpanit@....com>, <David.Kaplan@....com>, <x86@...nel.org>,
<hpa@...or.com>, <peterz@...radead.org>, <seanjc@...gle.com>,
<pbonzini@...hat.com>, <kvm@...r.kernel.org>,
<kirill.shutemov@...ux.intel.com>, <huibo.wang@....com>,
<naveen.rao@....com>, <francescolavra.fl@...il.com>
Subject: [PATCH v3 09/17] x86/apic: Add support to send NMI IPI for Secure AVIC
Secure AVIC has introduced a new field in the APIC backing page
"NmiReq" that has to be set by the guest to request a NMI IPI
through APIC_ICR write.
Add support to set NmiReq appropriately to send NMI IPI.
This also requires Virtual NMI feature to be enabled in VINTRL_CTRL
field in the VMSA. However this would be added by a later commit
after adding support for injecting NMI from the hypervisor.
Co-developed-by: Kishon Vijay Abraham I <kvijayab@....com>
Signed-off-by: Kishon Vijay Abraham I <kvijayab@....com>
Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@....com>
---
Changes since v2:
- Updates to use per_cpu_ptr() on apic_page struct.
arch/x86/kernel/apic/x2apic_savic.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kernel/apic/x2apic_savic.c b/arch/x86/kernel/apic/x2apic_savic.c
index 1088d82e3adb..f2310d90443d 100644
--- a/arch/x86/kernel/apic/x2apic_savic.c
+++ b/arch/x86/kernel/apic/x2apic_savic.c
@@ -180,12 +180,19 @@ static void x2apic_savic_write(u32 reg, u32 data)
}
}
-static inline void send_ipi_dest(unsigned int cpu, unsigned int vector)
+static void send_ipi_dest(unsigned int cpu, unsigned int vector, bool nmi)
{
+ if (nmi) {
+ struct apic_page *ap = per_cpu_ptr(apic_page, cpu);
+
+ WRITE_ONCE(ap->regs[SAVIC_NMI_REQ >> 2], 1);
+ return;
+ }
+
update_vector(cpu, APIC_IRR, vector, true);
}
-static void send_ipi_allbut(unsigned int vector)
+static void send_ipi_allbut(unsigned int vector, bool nmi)
{
unsigned int cpu, src_cpu;
unsigned long flags;
@@ -197,16 +204,19 @@ static void send_ipi_allbut(unsigned int vector)
for_each_cpu(cpu, cpu_online_mask) {
if (cpu == src_cpu)
continue;
- send_ipi_dest(cpu, vector);
+ send_ipi_dest(cpu, vector, nmi);
}
local_irq_restore(flags);
}
-static inline void self_ipi(unsigned int vector)
+static inline void self_ipi(unsigned int vector, bool nmi)
{
u32 icr_low = APIC_SELF_IPI | vector;
+ if (nmi)
+ icr_low |= APIC_DM_NMI;
+
native_x2apic_icr_write(icr_low, 0);
}
@@ -214,22 +224,24 @@ static void x2apic_savic_icr_write(u32 icr_low, u32 icr_high)
{
unsigned int dsh, vector;
u64 icr_data;
+ bool nmi;
dsh = icr_low & APIC_DEST_ALLBUT;
vector = icr_low & APIC_VECTOR_MASK;
+ nmi = ((icr_low & APIC_DM_FIXED_MASK) == APIC_DM_NMI);
switch (dsh) {
case APIC_DEST_SELF:
- self_ipi(vector);
+ self_ipi(vector, nmi);
break;
case APIC_DEST_ALLINC:
- self_ipi(vector);
+ self_ipi(vector, nmi);
fallthrough;
case APIC_DEST_ALLBUT:
- send_ipi_allbut(vector);
+ send_ipi_allbut(vector, nmi);
break;
default:
- send_ipi_dest(icr_high, vector);
+ send_ipi_dest(icr_high, vector, nmi);
break;
}
--
2.34.1
Powered by blists - more mailing lists