Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: selftests: SYNC after guest ITS setup in vgic_lpi_stress

vgic_lpi_stress sends MAPTI and MAPC commands during guest GIC setup to
map interrupt events to ITT entries and collection IDs to
redistributors, respectively.

We have no guarantee that the ITS will finish handling these mapping
commands before the selftest calls KVM_SIGNAL_MSI to inject LPIs to the
guest. If LPIs are injected before ITS mapping completes, the ITS cannot
properly pass the interrupt on to the redistributor.

Fix by adding a SYNC command to the selftests ITS library, then calling
SYNC after ITS mapping to ensure mapping completes before signal_lpi()
writes to GITS_TRANSLATER.

Signed-off-by: Maximilian Dittgen <mdittgen@amazon.de>
Link: https://msgid.link/20251119135744.68552-2-mdittgen@amazon.de
Signed-off-by: Oliver Upton <oupton@kernel.org>

authored by

Maximilian Dittgen and committed by
Oliver Upton
85f329df 31df012d

+15
+4
tools/testing/selftests/kvm/arm64/vgic_lpi_stress.c
··· 118 118 119 119 guest_setup_its_mappings(); 120 120 guest_invalidate_all_rdists(); 121 + 122 + /* SYNC to ensure ITS setup is complete */ 123 + for (cpuid = 0; cpuid < test_data.nr_cpus; cpuid++) 124 + its_send_sync_cmd(test_data.cmdq_base_va, cpuid); 121 125 } 122 126 123 127 static void guest_code(size_t nr_lpis)
+1
tools/testing/selftests/kvm/include/arm64/gic_v3_its.h
··· 15 15 void its_send_mapti_cmd(void *cmdq_base, u32 device_id, u32 event_id, 16 16 u32 collection_id, u32 intid); 17 17 void its_send_invall_cmd(void *cmdq_base, u32 collection_id); 18 + void its_send_sync_cmd(void *cmdq_base, u32 vcpu_id); 18 19 19 20 #endif // __SELFTESTS_GIC_V3_ITS_H__
+10
tools/testing/selftests/kvm/lib/arm64/gic_v3_its.c
··· 246 246 247 247 its_send_cmd(cmdq_base, &cmd); 248 248 } 249 + 250 + void its_send_sync_cmd(void *cmdq_base, u32 vcpu_id) 251 + { 252 + struct its_cmd_block cmd = {}; 253 + 254 + its_encode_cmd(&cmd, GITS_CMD_SYNC); 255 + its_encode_target(&cmd, procnum_to_rdbase(vcpu_id)); 256 + 257 + its_send_cmd(cmdq_base, &cmd); 258 + }