Skip to contentSkip to conversation

x86/apic: SVM AVIC tests and some cleanups

RFC PATCH In review Naveen N Rao (AMD) 2 participants 7 messages Feb 25, 2025 – Jun 3, 2025 KVM

lore
Share & tools
lore
#0 lore raw

cover x86/apic: SVM AVIC tests and some cleanups

The first patch is a small cleanup. The next two patches update tests to disable PIT so that SVM AVIC can be exercized. The last patch adds a test for x1apic-split.

The last patch causes aliased apic_id ipi test to fail with older qemu versions. Qemu v6.2 and before used to enable KVM_X2APIC_API_USE_32BIT_IDS KVM quirk in some scenarios, and this was changed in commit dc89f32d92bb ("target/i386: Fix sanity check on max APIC ID / X2APIC enablement") to be enabled only if there are > 255 vcpus. The KUT test does talk about this assumption in a comment:
/*
* By default, KVM doesn't follow the x86 APIC architecture for aliased
* APIC IDs if userspace has enabled KVM_X2APIC_API_USE_32BIT_IDS.
* If x2APIC is supported, assume the userspace VMM has enabled 32-bit
* IDs and thus activated KVM's quirk. Delete this code to run the
* aliasing test on x2APIC CPUs, e.g. to run it on bare metal. */

That looks to suggest that this is an expected failure, but it would be good to get confirmation on the same.

Thanks,
Naveen

Naveen N Rao (AMD) (4):
x86/apic: Move ioapic tests together and add them to apic test group x86/apic: Disable PIT for x2apic test to allow SVM AVIC to be tested x86/apic: Disable PIT for ioapic test to allow SVM AVIC to be tested x86/apic: Add test for xapic-split

 x86/unittests.cfg | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

base-commit: 699264f5ef8129c60e9db7c281e572016ad41a45

Signature · 1 line
2.48.1
#2 lore raw

RFC PATCH 2/4 x86/apic: Disable PIT for x2apic test to allow SVM AVIC to be tested

SVM AVIC is inhibited if kvm-pit is enabled in the default "reinject" mode. Commit f5cfdd33cb21 ("x86/apic: Add test config to allow running apic tests against SVM's AVIC") disabled PIT in xapic test to allow AVIC to be tested. However, since then, AVIC has been enabled to work in x2apic mode, but still requires PIT to either be disabled or set to "discard".

Update x2apic test to disable PIT so that AVIC can be exercized with x2apic.

---
 x86/unittests.cfg | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
x86/unittests.cfg +2 -1
index 8d046e6d7356..35fb88c3cb79 100644
@@ -14,10 +14,11 @@ extra_params = -cpu qemu64,+x2apic,+tsc-deadline -machine kernel_irqchip=split
 arch = x86_64
 groups = apic
 
+# Don't create a Programmable Interval Timer (PIT, a.k.a 8254) to allow testing SVM's AVIC
 [x2apic]
 file = apic.flat
 smp = 2
-extra_params = -cpu qemu64,+x2apic,+tsc-deadline
+extra_params = -cpu qemu64,+x2apic,+tsc-deadline -machine pit=off
 arch = x86_64
 timeout = 30
 groups = apic
Signature · 1 line
2.48.1
#4 lore raw

RFC PATCH 3/4 x86/apic: Disable PIT for ioapic test to allow SVM AVIC to be tested

In reply to Naveen N Rao (AMD)

SVM AVIC is inhibited if kvm-pit is present in the default reinject mode. Disable PIT so that AVIC is exercized with the ioapic test.

---
 x86/unittests.cfg | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
x86/unittests.cfg +1 -1
index 35fb88c3cb79..b057b59b1e30 100644
@@ -42,7 +42,7 @@ groups = apic
 [ioapic]
 file = ioapic.flat
 smp = 4
-extra_params = -cpu qemu64,+x2apic
+extra_params = -cpu qemu64,+x2apic -machine pit=off
 arch = x86_64
 groups = apic
 
Signature · 1 line
2.48.1
#5 lore raw

RFC PATCH 4/4 x86/apic: Add test for xapic-split

In reply to Naveen N Rao (AMD)

The current apic-split test actually uses x2apic. Rename the same, and add a separate test for xapic in split irqchip mode.

---
 x86/unittests.cfg | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
x86/unittests.cfg +8 -1
index b057b59b1e30..35646e320620 100644
@@ -7,7 +7,7 @@
 # arch = i386|x86_64
 ##############################################################################
 
-[apic-split]
+[x2apic-split]
 file = apic.flat
 smp = 2
 extra_params = -cpu qemu64,+x2apic,+tsc-deadline -machine kernel_irqchip=split
@@ -23,6 +23,13 @@ arch = x86_64
 timeout = 30
 groups = apic
 
+[xapic-split]
+file = apic.flat
+smp = 2
+extra_params = -cpu qemu64,-x2apic,+tsc-deadline -machine kernel_irqchip=split
+arch = x86_64
+groups = apic
+
 # Hide x2APIC and don't create a Programmable Interval Timer (PIT, a.k.a 8254)
 # to allow testing SVM's AVIC, which is disabled if either is exposed to the guest.
 [xapic]
Signature · 1 line
2.48.1
#1 lore raw

RFC PATCH 1/4 x86/apic: Move ioapic tests together and add them to apic test group

In reply to Naveen N Rao (AMD)

Commit f5cfdd33cb21 ("x86/apic: Add test config to allow running apic tests against SVM's AVIC") added most of the APIC tests to the "apic" test group, but missed adding ioapic test. Add it.

Also move ioapic-split test next to the regular ioapic test to keep the two together.

---
 x86/unittests.cfg | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
x86/unittests.cfg +7 -6
index 6e69c50b9b0d..8d046e6d7356 100644
@@ -14,12 +14,6 @@ extra_params = -cpu qemu64,+x2apic,+tsc-deadline -machine kernel_irqchip=split
 arch = x86_64
 groups = apic
 
-[ioapic-split]
-file = ioapic.flat
-extra_params = -cpu qemu64 -machine kernel_irqchip=split
-arch = x86_64
-groups = apic
-
 [x2apic]
 file = apic.flat
 smp = 2
@@ -38,11 +32,18 @@ arch = x86_64
 timeout = 60
 groups = apic
 
+[ioapic-split]
+file = ioapic.flat
+extra_params = -cpu qemu64 -machine kernel_irqchip=split
+arch = x86_64
+groups = apic
+
 [ioapic]
 file = ioapic.flat
 smp = 4
 extra_params = -cpu qemu64,+x2apic
 arch = x86_64
+groups = apic
 
 [cmpxchg8b]
 file = cmpxchg8b.flat
Signature · 1 line
2.48.1
#6 lore raw

Re: [RFC kvm-unit-tests PATCH 4/4] x86/apic: Add test for xapic-split

In reply to Naveen N Rao (AMD)
Quoted 2 lines · Naveen N Rao (AMD)

The current apic-split test actually uses x2apic. Rename the same, and add a separate test for xapic in split irqchip mode.

I would actually prefer we go in the opposite direction and rip out the testcases that explicitly specify kernel_irqchip=split, not add more. And instead either defer to the user via ACCEL=, or make it a top-level switch.

While it would be nice for unittests.cfg to cover more scenarios by "default", the flip side of doing so is that makes it annoying for an end user to do more, and gives the false impression that the configurations in unittests.cfg are the only ones that are worth testing.

E.g. svm_npt fails with kernel_irqchip=split on x2AVIC hardware due to test bugs (patches incoming), hyperv_connections fails due to what is effectively a QEMU bug that also got hoisted into KVM[1], and vmx_apic_passthrough_tpr_threshold_test also fails with kernel_irqchip=split due to a KVM bug that happened to be masked by another KVM bug with the in-kernel PIT emulation.

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

#3 lore raw

Re: [RFC kvm-unit-tests PATCH 2/4] x86/apic: Disable PIT for x2apic test to allow SVM AVIC to be tested

In reply to Naveen N Rao (AMD)
Quoted 20 lines · Naveen N Rao (AMD)

SVM AVIC is inhibited if kvm-pit is enabled in the default "reinject" mode. Commit f5cfdd33cb21 ("x86/apic: Add test config to allow running apic tests against SVM's AVIC") disabled PIT in xapic test to allow AVIC to be tested. However, since then, AVIC has been enabled to work in x2apic mode, but still requires PIT to either be disabled or set to "discard".

Update x2apic test to disable PIT so that AVIC can be exercized with x2apic.

---
 x86/unittests.cfg | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
x86/unittests.cfg +0 -0
index 8d046e6d7356..35fb88c3cb79 100644

x86/unittests.cfg extra_params = -cpu qemu64,+x2apic,+tsc-deadline -machine kernel_irqchip=split · line 21

Quoted 9 lines
x86/unittests.cfg +2 -1
@@ -14,10 +14,11 @@ extra_params = -cpu qemu64,+x2apic,+tsc-deadline -machine kernel_irqchip=split
 arch = x86_64
 groups = apic
 
+# Don't create a Programmable Interval Timer (PIT, a.k.a 8254) to allow testing SVM's AVIC
 [x2apic]
 file = apic.flat
 smp = 2
-extra_params = -cpu qemu64,+x2apic,+tsc-deadline
+extra_params = -cpu qemu64,+x2apic,+tsc-deadline -machine pit=off

Similar to the split IRQ chip, playing whack-a-mole to disable the PIT in every test where (x2)AVIC might be interesting is rather silly. The realmode test uses the PIT, but AFAICT it doesn't need re-injection, i.e. we can simply disable re-injection mode to get the same effect, e.g.

    qemu-429929  [233] ...1. 16531.028284: kvm_apicv_inhibit_changed: set reason=9, inhibits=0x200 PIT_REINJ
    qemu-429929  [233] ...1. 16531.028311: kvm_apicv_inhibit_changed: cleared reason=9, inhibits=0x0

I'll send a patch.

Quoted 6 lines
x86/unittests.cfg +0 -0
 arch = x86_64
 timeout = 30
 groups = apic
Signature · 1 line
2.48.1