Skip to contentSkip to conversation

KVM: arm64: Set/unset vGIC v4 forwarding if direct IRQs are supported

PATCH In review Raghavendra Rao Ananta 2 participants 4 messages Jul 28, 2025 – Jul 29, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: arm64: Set/unset vGIC v4 forwarding if direct IRQs are supported

Commit <c652887a9288> ("KVM: arm64: vgic-v3: Allow userspace to write GICD_TYPER2.nASSGIcap") bundles the vLPIs and vSGIs behind the GICD_TYPER2.nASSGIcap field. While the vGIC v4 initialization and teardown is handled correctly, it erroneously left out the cases when KVM sets/unset vGIC v4 forwarding, which leads to a kernel panic of the following nature:

 Unable to handle kernel NULL pointer dereference at virtual address 00000000000000a8
 Mem abort info:
   ESR = 0x0000000096000044
   EC = 0x25: DABT (current EL), IL = 32 bits
   SET = 0, FnV = 0
   EA = 0, S1PTW = 0
   FSC = 0x04: level 0 translation fault
 Data abort info:
   ISV = 0, ISS = 0x00000044, ISS2 = 0x00000000
   CM = 0, WnR = 1, TnD = 0, TagAccess = 0
   GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
 user pgtable: 4k pages, 48-bit VAs, pgdp=00000073a453b000
 [00000000000000a8] pgd=0000000000000000, p4d=0000000000000000
 Internal error: Oops: 0000000096000044 [#1] SMP
 pstate: 23400009 (nzCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
 pc : its_irq_set_vcpu_affinity+0x58c/0x95c
 lr : its_irq_set_vcpu_affinity+0x1e0/0x95c
 sp : ffff8001029bb9e0
 pmr_save: 00000060
 x29: ffff8001029bba20 x28: ffff0001ca5e28c0 x27: 0000000000000000
 x26: 0000000000000000 x25: ffff00019eee9f80 x24: ffff0001992b3f00
 x23: ffff8001029bbab8 x22: ffff00001159fb80 x21: 00000000000024a7
 x20: 00000000000024a7 x19: ffff00019eee9fb4 x18: 0000000000000494
 x17: 000000000000000e x16: 0000000000000494 x15: 0000000000000002
 x14: ffff0001a7f34600 x13: ffffccaad1203000 x12: 0000000000000018
 x11: ffff000011991000 x10: 0000000000000000 x9 : 00000000000000a2
 x8 : 00000000000020a8 x7 : 0000000000000000 x6 : 000000000000003f
 x5 : 0000000000000040 x4 : 0000000000000000 x3 : 0000000000000004
 x2 : 0000000000000000 x1 : ffff8001029bbab8 x0 : 00000000000000a8
 Call trace:
  its_irq_set_vcpu_affinity+0x58c/0x95c
  irq_set_vcpu_affinity+0x74/0xc8
  its_map_vlpi+0x4c/0x94
  kvm_vgic_v4_set_forwarding+0x134/0x298
  kvm_arch_irq_bypass_add_producer+0x28/0x34
  irq_bypass_register_producer+0xf8/0x1d8
  vfio_msi_set_vector_signal+0x2c8/0x308
  vfio_pci_set_msi_trigger+0x198/0x2d4
  vfio_pci_set_irqs_ioctl+0xf0/0x104
  vfio_pci_core_ioctl+0x6ac/0xc5c
  vfio_device_fops_unl_ioctl+0x128/0x370
  __arm64_sys_ioctl+0x98/0xd0
  el0_svc_common+0xd8/0x1d8
  do_el0_svc+0x28/0x34
  el0_svc+0x40/0xb8
  el0t_64_sync_handler+0x70/0xbc
  el0t_64_sync+0x1a8/0x1ac
 Code: 321f0129 f940094a 8b080148 d1400900 (39000009)
 ---[ end trace 0000000000000000 ]---

Fix this by checking if vgic_supports_direct_irqs() while setting/unsetting vGIC v4 forwarding as well.

Fixes c652887a9288 ("KVM: arm64: vgic-v3: Allow userspace to write GICD_TYPER2.nASSGIcap")
---
 arch/arm64/kvm/vgic/vgic-v4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kvm/vgic/vgic-v4.c +2 -2
index e7e284d47a77..873a190bcff7 100644
@@ -433,7 +433,7 @@ int kvm_vgic_v4_set_forwarding(struct kvm *kvm, int virq,
 	unsigned long flags;
 	int ret = 0;
 
-	if (!vgic_supports_direct_msis(kvm))
+	if (!vgic_supports_direct_irqs(kvm))
 		return 0;
 
 	/*
@@ -533,7 +533,7 @@ int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int host_irq)
 	unsigned long flags;
 	int ret = 0;
 
-	if (!vgic_supports_direct_msis(kvm))
+	if (!vgic_supports_direct_irqs(kvm))
 		return 0;
 
 	irq = __vgic_host_irq_get_vlpi(kvm, host_irq);

base-commit: 18ec25dd0e97653cdb576bb1750c31acf2513ea7

Signature · 1 line
2.50.1.487.gc89ff58d15-goog
#1 lore raw

Hi Raghu,

Thanks for reporting this so quickly :)

Quoted 14 lines · Raghavendra Rao Ananta
arch/arm64/kvm/vgic/vgic-v4.c +1 -1
index e7e284d47a77..873a190bcff7 100644
@@ -433,7 +433,7 @@ int kvm_vgic_v4_set_forwarding(struct kvm *kvm, int virq,
 	unsigned long flags;
 	int ret = 0;
 
-	if (!vgic_supports_direct_msis(kvm))
+	if (!vgic_supports_direct_irqs(kvm))
 		return 0;
 
 	/*

arch/arm64/kvm/vgic/vgic-v4.c int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int host_irq) · line 537

Quoted 6 lines
arch/arm64/kvm/vgic/vgic-v4.c +1 -1
@@ -533,7 +533,7 @@ int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int host_irq)
 	unsigned long flags;
 	int ret = 0;
 
-	if (!vgic_supports_direct_msis(kvm))
+	if (!vgic_supports_direct_irqs(kvm))
 		return 0;

I'm not sure this is what we want, since a precondition of actually doing vLPI injection is the guest having an ITS. Could you try the following?

Thanks,
Oliver

arch/arm64/kvm/vgic/vgic-mmio-v3.c +8 -0
index a3ef185209e9..70d50c77e5dc 100644
@@ -50,6 +50,14 @@ bool vgic_has_its(struct kvm *kvm)
 
 bool vgic_supports_direct_msis(struct kvm *kvm)
 {
+	/*
+	 * Deliberately conflate vLPI and vSGI support on GICv4.1 hardware,
+	 * indirectly allowing userspace to control whether or not vPEs are
+	 * allocated for the VM.
+	 */
+	if (system_supports_direct_sgis() && !vgic_supports_direct_sgis(kvm))
+		return false;
+
 	return kvm_vgic_global_state.has_gicv4 && vgic_has_its(kvm);
 }
 
arch/arm64/kvm/vgic/vgic.h +1 -9
index 1384a04c0784..de1c1d3261c3 100644
@@ -396,15 +396,7 @@ bool vgic_supports_direct_sgis(struct kvm *kvm);
 
 static inline bool vgic_supports_direct_irqs(struct kvm *kvm)
 {
-	/*
-	 * Deliberately conflate vLPI and vSGI support on GICv4.1 hardware,
-	 * indirectly allowing userspace to control whether or not vPEs are
-	 * allocated for the VM.
-	 */
-	if (system_supports_direct_sgis())
-		return vgic_supports_direct_sgis(kvm);
-
-	return vgic_supports_direct_msis(kvm);
+	return vgic_supports_direct_msis(kvm) || vgic_supports_direct_sgis(kvm);
 }
 
 int vgic_v4_init(struct kvm *kvm);
#2 lore raw
Quoted 64 lines · Oliver Upton

Hi Raghu,

Thanks for reporting this so quickly :)

Quoted 14 lines · Raghavendra Rao Ananta
arch/arm64/kvm/vgic/vgic-v4.c +1 -1
index e7e284d47a77..873a190bcff7 100644
@@ -433,7 +433,7 @@ int kvm_vgic_v4_set_forwarding(struct kvm *kvm, int virq,
      unsigned long flags;
      int ret = 0;
 
-     if (!vgic_supports_direct_msis(kvm))
+     if (!vgic_supports_direct_irqs(kvm))
              return 0;
 
      /*

arch/arm64/kvm/vgic/vgic-v4.c int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int host_irq) · line 537

Quoted 6 lines
arch/arm64/kvm/vgic/vgic-v4.c +1 -1
@@ -533,7 +533,7 @@ int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int host_irq)
      unsigned long flags;
      int ret = 0;
 
-     if (!vgic_supports_direct_msis(kvm))
+     if (!vgic_supports_direct_irqs(kvm))
              return 0;

I'm not sure this is what we want, since a precondition of actually doing vLPI injection is the guest having an ITS. Could you try the following?

Thanks,
Oliver

arch/arm64/kvm/vgic/vgic-mmio-v3.c +8 -0
index a3ef185209e9..70d50c77e5dc 100644
@@ -50,6 +50,14 @@ bool vgic_has_its(struct kvm *kvm)
 
 bool vgic_supports_direct_msis(struct kvm *kvm)
 {
+       /*
+        * Deliberately conflate vLPI and vSGI support on GICv4.1 hardware,
+        * indirectly allowing userspace to control whether or not vPEs are
+        * allocated for the VM.
+        */
+       if (system_supports_direct_sgis() && !vgic_supports_direct_sgis(kvm))
+               return false;
+
        return kvm_vgic_global_state.has_gicv4 && vgic_has_its(kvm);
 }
 
arch/arm64/kvm/vgic/vgic.h +0 -3
index 1384a04c0784..de1c1d3261c3 100644
@@ -396,15 +396,7 @@ bool vgic_supports_direct_sgis(struct kvm *kvm);
 
 static inline bool vgic_supports_direct_irqs(struct kvm *kvm)
 {
-       /*
-        * Deliberately conflate vLPI and vSGI support on GICv4.1 hardware,
-        * indirectly allowing userspace to control whether or not vPEs are

arch/arm64/kvm/vgic/vgic.h bool vgic_supports_direct_sgis(struct kvm *kvm); · line 402

Quoted 10 lines
arch/arm64/kvm/vgic/vgic.h +1 -6
-        * allocated for the VM.
-        */
-       if (system_supports_direct_sgis())
-               return vgic_supports_direct_sgis(kvm);
-
-       return vgic_supports_direct_msis(kvm);
+       return vgic_supports_direct_msis(kvm) || vgic_supports_direct_sgis(kvm);
 }
 
 int vgic_v4_init(struct kvm *kvm);

Yes, the diff seems fine (tested as well). Would you be pushing a v2 or do you want me to (on your behalf)?

Thank you.
Raghavendra

#3 lore raw
Quoted 74 lines · Raghavendra Rao Ananta
Quoted 73 lines · Oliver Upton

Hi Raghu,

Thanks for reporting this so quickly :)

Quoted 14 lines · Raghavendra Rao Ananta
arch/arm64/kvm/vgic/vgic-v4.c +1 -1
index e7e284d47a77..873a190bcff7 100644
@@ -433,7 +433,7 @@ int kvm_vgic_v4_set_forwarding(struct kvm *kvm, int virq,
      unsigned long flags;
      int ret = 0;
 
-     if (!vgic_supports_direct_msis(kvm))
+     if (!vgic_supports_direct_irqs(kvm))
              return 0;
 
      /*

arch/arm64/kvm/vgic/vgic-v4.c int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int host_irq) · line 537

Quoted 6 lines
arch/arm64/kvm/vgic/vgic-v4.c +1 -1
@@ -533,7 +533,7 @@ int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int host_irq)
      unsigned long flags;
      int ret = 0;
 
-     if (!vgic_supports_direct_msis(kvm))
+     if (!vgic_supports_direct_irqs(kvm))
              return 0;

I'm not sure this is what we want, since a precondition of actually doing vLPI injection is the guest having an ITS. Could you try the following?

Thanks,
Oliver

arch/arm64/kvm/vgic/vgic-mmio-v3.c +8 -0
index a3ef185209e9..70d50c77e5dc 100644
@@ -50,6 +50,14 @@ bool vgic_has_its(struct kvm *kvm)
 
 bool vgic_supports_direct_msis(struct kvm *kvm)
 {
+       /*
+        * Deliberately conflate vLPI and vSGI support on GICv4.1 hardware,
+        * indirectly allowing userspace to control whether or not vPEs are
+        * allocated for the VM.
+        */
+       if (system_supports_direct_sgis() && !vgic_supports_direct_sgis(kvm))
+               return false;
+
        return kvm_vgic_global_state.has_gicv4 && vgic_has_its(kvm);
 }
 
arch/arm64/kvm/vgic/vgic.h +1 -9
index 1384a04c0784..de1c1d3261c3 100644
@@ -396,15 +396,7 @@ bool vgic_supports_direct_sgis(struct kvm *kvm);
 
 static inline bool vgic_supports_direct_irqs(struct kvm *kvm)
 {
-       /*
-        * Deliberately conflate vLPI and vSGI support on GICv4.1 hardware,
-        * indirectly allowing userspace to control whether or not vPEs are
-        * allocated for the VM.
-        */
-       if (system_supports_direct_sgis())
-               return vgic_supports_direct_sgis(kvm);
-
-       return vgic_supports_direct_msis(kvm);
+       return vgic_supports_direct_msis(kvm) || vgic_supports_direct_sgis(kvm);
 }
 
Quoted 4 lines

arch/arm64/kvm/vgic/vgic.h bool vgic_supports_direct_sgis(struct kvm *kvm); · line 402

Quoted 1 line
arch/arm64/kvm/vgic/vgic.h +0 -0
 int vgic_v4_init(struct kvm *kvm);

Yes, the diff seems fine (tested as well). Would you be pushing a v2 or do you want me to (on your behalf)?

Go ahead and respin this diff, thanks!

Oliver