Re: [PATCH v2 3/3] KVM: selftests: Add test for race in kvm_recalculate_apic_map()

From: Sean Christopherson
Date: Thu Jun 01 2023 - 19:11:52 EST


On Fri, May 26, 2023, Sean Christopherson wrote:
> From: Michal Luczaj <mhal@xxxxxxx>
>
> Keep switching between LAPIC_MODE_X2APIC and LAPIC_MODE_DISABLED during
> APIC map construction to hunt for TOCTOU bugs in KVM. KVM's optimized map
> recalc makes multiple passes over the list of vCPUs, and the calculations
> ignore vCPU's whose APIC is hardware-disabled, i.e. there's a window where
> toggling LAPIC_MODE_DISABLED is quite interesting.
>
> Signed-off-by: Michal Luczaj <mhal@xxxxxxx>
> Co-developed-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> ---
> tools/testing/selftests/kvm/Makefile | 1 +
> .../kvm/x86_64/recalc_apic_map_race.c | 76 +++++++++++++++++++
> 2 files changed, 77 insertions(+)
> create mode 100644 tools/testing/selftests/kvm/x86_64/recalc_apic_map_race.c

Since there's another bug+test related to kvm_recalculate_apic_map()[*], I think
it makes sense to name this recalc_apic_map_test, and then fold the LDR test into
this one. The LDR test is tiny enough that I don't think it's worth a separate
binary, even though I generally prefer to keep the selftests small.