[RFC PATCH v2 1/3] KVM: x86: add DSM IRQ forwarding ABI and state

From: muliang.shou

Date: Fri Jun 05 2026 - 06:01:08 EST


Add the Kconfig knob, request id, per-vCPU state, and userspace ABI
needed to report DSM IRQ forwarding events to userspace.

Signed-off-by: muliang.shou <muliang.shou@xxxxxxxxxxx>
---
arch/x86/include/asm/kvm_host.h | 17 +++++++++++++++++
arch/x86/kvm/Kconfig | 12 ++++++++++++
include/uapi/linux/kvm.h | 33 ++++++++++++++++++++++++++++++++-
3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index f14009f25a3b6..7dccfeaee432d 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -131,6 +131,11 @@
#define KVM_REQ_UPDATE_PROTECTED_GUEST_STATE \
KVM_ARCH_REQ_FLAGS(34, KVM_REQUEST_WAIT)

+#ifdef CONFIG_KVM_DSM_IRQ_FORWARD
+#define KVM_REQ_DSM_IRQ_FORWARD \
+ KVM_ARCH_REQ(33)
+#endif
+
#define CR0_RESERVED_BITS \
(~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \
| X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM \
@@ -1074,6 +1079,14 @@ struct kvm_vcpu_arch {
/* AMD MSRC001_0015 Hardware Configuration */
u64 msr_hwcr;

+#ifdef CONFIG_KVM_DSM_IRQ_FORWARD
+ /* DSM interrupt forwarding */
+ bool dsm_irq_forward_pending;
+ u32 dsm_irq_forward_reg;
+ u32 dsm_irq_forward_val;
+ u32 dsm_irq_forward_dest_id;
+#endif
+
/* pv related cpuid info */
struct {
/*
@@ -1667,6 +1680,10 @@ struct kvm_arch {
* current VM.
*/
int cpu_dirty_log_size;
+
+#ifdef CONFIG_KVM_DSM_IRQ_FORWARD
+ int dsm_id;
+#endif
};

struct kvm_vm_stat {
diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index 801bf9e520db3..bd3a97f115284 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -240,4 +240,16 @@ config KVM_MAX_NR_VCPUS
the memory footprint of each KVM guest, regardless of how many vCPUs are
created for a given VM.

+config KVM_DSM_IRQ_FORWARD
+ bool "KVM DSM interrupt forwarding support"
+ depends on KVM && KVM_INTEL
+ default n
+ help
+ Provide support for interrupt forwarding in distributed KVM.
+ When enabled, guest ICR/ICR2 writes are intercepted and
+ forwarded to userspace via KVM_EXIT_DSM_SEND_IRQ exit,
+ allowing cross-node IPI delivery in a distributed KVM setup.
+ This feature can be used independently of the full DSM memory
+ coherence framework.
+
endif # VIRTUALIZATION
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 6c8afa2047bf3..75a11e72e232e 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -194,6 +194,17 @@ struct kvm_exit_snp_req_certs {
#define KVM_EXIT_ARM_LDST64B 42
#define KVM_EXIT_SNP_REQ_CERTS 43

+#ifdef CONFIG_KVM_DSM_IRQ_FORWARD
+/* DSM exit reason: distributed APIC region access */
+#define KVM_EXIT_DAPIC 44
+/* DSM exit reason: IPI forwarding to userspace */
+#define KVM_EXIT_DSM_SEND_IRQ 45
+/* DSM exit reason: X2APIC ICR write forwarding to userspace */
+#define KVM_EXIT_DSM_X2_ICR 46
+/* DSM exit reason: APIC base MSR write forwarding to userspace */
+#define KVM_EXIT_DSM_APIC_BASE 47
+#endif
+
/* For KVM_EXIT_INTERNAL_ERROR */
/* Emulate instruction failed. */
#define KVM_INTERNAL_ERROR_EMULATION 1
@@ -243,7 +254,27 @@ struct kvm_run {
__u64 psw_addr; /* psw lower half */
#endif
union {
- /* KVM_EXIT_UNKNOWN */
+#ifdef CONFIG_KVM_DSM_IRQ_FORWARD
+ /* DSM IPI forwarding data (KVM_EXIT_DSM_SEND_IRQ) */
+ struct {
+ __u32 id;
+ __u32 val;
+ __u32 val2;
+ __u32 dest_id;
+ } lapic_irq;
+ /* DSM X2APIC write data (KVM_EXIT_DSM_X2APIC) */
+ struct {
+ __u32 id;
+ __u64 data;
+ } x2apic;
+ /* DSM APIC base write data (KVM_EXIT_DSM_APIC_BASE) */
+ struct {
+ __u32 id;
+ bool host;
+ __u32 index;
+ __u64 data;
+ } x2msr_base;
+#endif
struct {
__u64 hardware_exit_reason;
} hw;
--
2.43.0