Re: [PATCH v3 09/12] KVM: selftests: Port VMware backdoor coverage
From: Jim Mattson
Date: Thu Nov 12 2026 - 14:03:45 EST
On Tue, Nov 10, 2026 at 10:08 PM Zack Rusin <zack.rusin@xxxxxxxxxxxx> wrote:
>
> Add vmware_backdoor_test, adapted from KVM-unit-tests' vmware_backdoors
> test. From CPL3, with CR4.PCE clear and no I/O permission bitmap in
> the TSS, read the VMware pseudo-PMCs with RDPMC and issue backdoor
> commands on the backdoor port with IN. Verify that the pseudo-PMC
> reads succeed and the port accesses exit to userspace only when the
> backdoor is enabled and raise #GP otherwise, and that other PMC indices
> and ports always raise #GP. Repeat the pseudo-PMC checks at CPL3 with
> CR4.PCE set and at CPL0, where RDPMC doesn't fault before KVM handles
> it. Skip the pseudo-PMC checks if KVM doesn't virtualize a PMU, as KVM
> then injects #GP for every RDPMC.
>
> Run the checks for a VM that relies on the enable_vmware_backdoor
> default and for a VM that enables KVM_VMWARE_ENABLE_BACKDOOR, and
> verify that KVM_CAP_X86_VMWARE rejects every flag it doesn't report.
> KVM-unit-tests can only cover the module parameter, which applies to
> every VM, while the selftest also covers the per-VM capability.
>
> Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> Link: https://lore.kernel.org/r/aIEoNpe-LFoH6LBm@xxxxxxxxxx
> Signed-off-by: Zack Rusin <zack.rusin@xxxxxxxxxxxx>
> ---
[ ... ]
> +static struct insn_result guest_inl(u16 port, u32 command)
> +{
> + struct insn_result result;
> + unsigned long rax = VMPORT_DEFAULT_RETVAL;
Shouldn't %rax be VMWARE_MAGIC?
> + unsigned long rbx = VMPORT_DEFAULT_RETVAL;
> + unsigned long rcx = command;
> + unsigned long rdx = port;
> + u64 error_code;
> +
> + asm volatile(KVM_ASM_SAFE("inl %%dx, %%eax")
> + : "+a"(rax), "+b"(rbx), "+c"(rcx), "+d"(rdx),
> + KVM_ASM_SAFE_OUTPUTS(result.vector, error_code)
> + :
> + : KVM_ASM_SAFE_CLOBBERS);
> + result.value = rbx;
> + return result;
> +}
> +