• Sean Christopherson's avatar
    KVM: selftests: Add a test for coalesced MMIO (and PIO on x86) · 215b3cb7
    Sean Christopherson authored
    Add a test to verify that KVM correctly exits (or not) when a vCPU's
    coalesced I/O ring is full (or isn't).  Iterate over all legal starting
    points in the ring (with an empty ring), and verify that KVM doesn't exit
    until the ring is full.
    
    Opportunistically verify that KVM exits immediately on non-coalesced I/O,
    either because the MMIO/PIO region was never registered, or because a
    previous region was unregistered.
    
    This is a regression test for a KVM bug where KVM would prematurely exit
    due to bad math resulting in a false positive if the first entry in the
    ring was before the halfway mark.  See commit 92f6d413 ("KVM: Fix
    coalesced_mmio_has_room() to avoid premature userspace exit").
    
    Enable the test for x86, arm64, and risc-v, i.e. all architectures except
    s390, which doesn't have MMIO.
    
    On x86, which has both MMIO and PIO, interleave MMIO and PIO into the same
    ring, as KVM shouldn't exit until a non-coalesced I/O is encountered,
    regardless of whether the ring is filled with MMIO, PIO, or both.
    
    Lastly, wrap the coalesced I/O ring in a structure to prepare for a
    potential future where KVM supports multiple ring buffers beyond KVM's
    "default" built-in buffer.
    
    Link: https://lore.kernel.org/all/20240820133333.1724191-1-ilstam@amazon.com
    Cc: Ilias Stamatis <ilstam@amazon.com>
    Cc: Marc Zyngier <maz@kernel.org>
    Cc: Oliver Upton <oliver.upton@linux.dev>
    Cc: Anup Patel <anup@brainfault.org>
    Link: https://lore.kernel.org/r/20240828181446.652474-2-seanjc@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
    215b3cb7
kvm_util.h 31.5 KB