Skip to contentSkip to conversation

KVM: TDX: Force split irqchip for TDX at irqchip creation time

PATCH Applied Sagi Shahar 4 participants 6 messages Aug 27, 2025 – Sep 16, 2025

Subsystems (4)

v2 of 4 Applied Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 KVM: TDX: Force split irqchip for TDX at irqchip creation time

TDX module protects the EOI-bitmap which prevents the use of in-kernel I/O APIC. See more details in the original patch [1]

The current implementation already enforces the use of split irqchip for TDX but it does so at the vCPU creation time which is generally to late to fallback to split irqchip.

This patch follows Sean's recomendation from [2] and move the check if I/O APIC is supported for the VM at irqchip creation time.

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/

---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/vmx/tdx.c          | 6 ++++++
 arch/x86/kvm/x86.c              | 9 +++++++++
 3 files changed, 16 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
index f19a76d3ca0e..6a4019d3a184 100644
@@ -1357,6 +1357,7 @@ struct kvm_arch {
 	u8 vm_type;
 	bool has_private_mem;
 	bool has_protected_state;
+	bool has_protected_eoi;
 	bool pre_fault_allowed;
 	struct hlist_head *mmu_page_hash;
 	struct list_head active_mmu_pages;
arch/x86/kvm/vmx/tdx.c +6 -0
index 66744f5768c8..9637d9da1af1 100644
@@ -658,6 +658,12 @@ int tdx_vm_init(struct kvm *kvm)
 	 */
 	kvm->max_vcpus = min_t(int, kvm->max_vcpus, num_present_cpus());
 
+	/*
+	 * TDX Module doesn't allow the hypervisor to modify the EOI-bitmap,
+	 * i.e. all EOIs are accelerated and never trigger exits.
+	 */
+	kvm->arch.has_protected_eoi = true;
+
 	kvm_tdx->state = TD_STATE_UNINITIALIZED;
 
 	return 0;
arch/x86/kvm/x86.c +9 -0
index a1c49bc681c4..57b4d5ba2568 100644
@@ -6966,6 +6966,15 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
 		if (irqchip_in_kernel(kvm))
 			goto create_irqchip_unlock;
 
+		/*
+		 * Disallow an in-kernel I/O APIC if the VM has protected EOIs,
+		 * i.e. if KVM can't intercept EOIs and thus can't properly
+		 * emulate level-triggered interrupts.
+		 */
+		r = -ENOTTY;
+		if (kvm->arch.has_protected_eoi)
+			goto create_irqchip_unlock;
+
 		r = -EINVAL;
 		if (kvm->created_vcpus)
 			goto create_irqchip_unlock;
Signature · 1 line
2.51.0.261.g7ce5a0a67e-goog
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Sagi Shahar

TDX module protects the EOI-bitmap which prevents the use of in-kernel I/O APIC. See more details in the original patch [1]

The current implementation already enforces the use of split irqchip for TDX but it does so at the vCPU creation time which is generally to late

to late -> too late

Quoted 3 lines

to fallback to split irqchip.

This patch follows Sean's recomendation from [2] and move the check if

recomendation -> recommendation

Also "move the check ..." needs to be updated, since the check during vCPU creation is still there.

Quoted 1 line

I/O APIC is supported for the VM at irqchip creation time.

Some nits above.

Otherwise,

Quoted 61 lines

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/

---
  arch/x86/include/asm/kvm_host.h | 1 +
  arch/x86/kvm/vmx/tdx.c          | 6 ++++++
  arch/x86/kvm/x86.c              | 9 +++++++++
  3 files changed, 16 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
index f19a76d3ca0e..6a4019d3a184 100644
@@ -1357,6 +1357,7 @@ struct kvm_arch {
  	u8 vm_type;
  	bool has_private_mem;
  	bool has_protected_state;
+	bool has_protected_eoi;
  	bool pre_fault_allowed;
  	struct hlist_head *mmu_page_hash;
  	struct list_head active_mmu_pages;
arch/x86/kvm/vmx/tdx.c +6 -0
index 66744f5768c8..9637d9da1af1 100644
@@ -658,6 +658,12 @@ int tdx_vm_init(struct kvm *kvm)
  	 */
  	kvm->max_vcpus = min_t(int, kvm->max_vcpus, num_present_cpus());
 
+	/*
+	 * TDX Module doesn't allow the hypervisor to modify the EOI-bitmap,
+	 * i.e. all EOIs are accelerated and never trigger exits.
+	 */
+	kvm->arch.has_protected_eoi = true;
+
  	kvm_tdx->state = TD_STATE_UNINITIALIZED;
 
  	return 0;
arch/x86/kvm/x86.c +9 -0
index a1c49bc681c4..57b4d5ba2568 100644
@@ -6966,6 +6966,15 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
  		if (irqchip_in_kernel(kvm))
  			goto create_irqchip_unlock;
 
+		/*
+		 * Disallow an in-kernel I/O APIC if the VM has protected EOIs,
+		 * i.e. if KVM can't intercept EOIs and thus can't properly
+		 * emulate level-triggered interrupts.
+		 */
+		r = -ENOTTY;
+		if (kvm->arch.has_protected_eoi)
+			goto create_irqchip_unlock;
+
  		r = -EINVAL;
  		if (kvm->created_vcpus)
  			goto create_irqchip_unlock;
Reviewed-by on v2 1/1
#2 lore raw
In reply to Sagi Shahar
Quoted 38 lines · Sagi Shahar

TDX module protects the EOI-bitmap which prevents the use of in-kernel I/O APIC. See more details in the original patch [1]

The current implementation already enforces the use of split irqchip for TDX but it does so at the vCPU creation time which is generally to late to fallback to split irqchip.

This patch follows Sean's recomendation from [2] and move the check if I/O APIC is supported for the VM at irqchip creation time.

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/

---
  arch/x86/include/asm/kvm_host.h | 1 +
  arch/x86/kvm/vmx/tdx.c          | 6 ++++++
  arch/x86/kvm/x86.c              | 9 +++++++++
  3 files changed, 16 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
index f19a76d3ca0e..6a4019d3a184 100644
@@ -1357,6 +1357,7 @@ struct kvm_arch {
  	u8 vm_type;
  	bool has_private_mem;
  	bool has_protected_state;
+	bool has_protected_eoi;
  	bool pre_fault_allowed;
  	struct hlist_head *mmu_page_hash;
  	struct list_head active_mmu_pages;
arch/x86/kvm/vmx/tdx.c +0 -0
index 66744f5768c8..9637d9da1af1 100644

arch/x86/kvm/vmx/tdx.c int tdx_vm_init(struct kvm *kvm) · line 665

Quoted 8 lines
arch/x86/kvm/vmx/tdx.c +5 -0
@@ -658,6 +658,12 @@ int tdx_vm_init(struct kvm *kvm)
  	 */
  	kvm->max_vcpus = min_t(int, kvm->max_vcpus, num_present_cpus());
 
+	/*
+	 * TDX Module doesn't allow the hypervisor to modify the EOI-bitmap,
+	 * i.e. all EOIs are accelerated and never trigger exits.
+	 */
+	kvm->arch.has_protected_eoi = true;

I prefer putting it along with the lines

	kvm->arch.has_protected_state = true;
	kvm->arch.has_private_mem = true;

Otherwise,

Quoted 23 lines
arch/x86/kvm/vmx/tdx.c +0 -0
  	kvm_tdx->state = TD_STATE_UNINITIALIZED;
 
  	return 0;
arch/x86/kvm/x86.c +9 -0
index a1c49bc681c4..57b4d5ba2568 100644
@@ -6966,6 +6966,15 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
  		if (irqchip_in_kernel(kvm))
  			goto create_irqchip_unlock;
 
+		/*
+		 * Disallow an in-kernel I/O APIC if the VM has protected EOIs,
+		 * i.e. if KVM can't intercept EOIs and thus can't properly
+		 * emulate level-triggered interrupts.
+		 */
+		r = -ENOTTY;
+		if (kvm->arch.has_protected_eoi)
+			goto create_irqchip_unlock;
+
  		r = -EINVAL;
  		if (kvm->created_vcpus)
  			goto create_irqchip_unlock;
maintainer Applied
#3 lore raw
In reply to Sagi Shahar
Quoted 8 lines · Sagi Shahar

TDX module protects the EOI-bitmap which prevents the use of in-kernel I/O APIC. See more details in the original patch [1]

The current implementation already enforces the use of split irqchip for TDX but it does so at the vCPU creation time which is generally to late to fallback to split irqchip.

[...]

Applied to kvm-x86 misc, thanks!

[1/1] KVM: TDX: Force split irqchip for TDX at irqchip creation time

      https://github.com/kvm-x86/linux/commit/2569c8c5767b

--
https://github.com/kvm-x86/linux/tree/next

#4 lore raw
Quoted 11 lines · Sean Christopherson
Quoted 8 lines · Sagi Shahar

TDX module protects the EOI-bitmap which prevents the use of in-kernel I/O APIC. See more details in the original patch [1]

The current implementation already enforces the use of split irqchip for TDX but it does so at the vCPU creation time which is generally to late to fallback to split irqchip.

[...]

Applied to kvm-x86 misc, thanks!

The latest one of this patch is v4:

https://lore.kernel.org/all/[email protected]/

Quoted 2 lines

[1/1] KVM: TDX: Force split irqchip for TDX at irqchip creation time

       https://github.com/kvm-x86/linux/commit/2569c8c5767b

What got queued, added a superfluous new line in tdx_vm_init()

Quoted 3 lines

--
https://github.com/kvm-x86/linux/tree/next

#5 lore raw
Quoted 9 lines · Xiaoyao Li
Quoted 8 lines · Sean Christopherson
Quoted 7 lines · Sagi Shahar

TDX module protects the EOI-bitmap which prevents the use of in-kernel I/O APIC. See more details in the original patch [1]

The current implementation already enforces the use of split irqchip for TDX but it does so at the vCPU creation time which is generally to late to fallback to split irqchip.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

[...]

Applied to kvm-x86 misc, thanks!

The latest one of this patch is v4:

https://lore.kernel.org/all/[email protected]/

Yeah, I had applied v2 quite some time ago, just took me a while to do final testing and send the "thank you".

Quoted 4 lines
Quoted 2 lines

[1/1] KVM: TDX: Force split irqchip for TDX at irqchip creation time

       https://github.com/kvm-x86/linux/commit/2569c8c5767b

What got queued, added a superfluous new line in tdx_vm_init()

Drat. I force pushed to fix that goof, and added Kai's Acked-by in the process.

[1/1] KVM: TDX: Reject fully in-kernel irqchip if EOIs are protected, i.e. for TDX VMs

      https://github.com/kvm-x86/linux/commit/b3a37bff8daf