Re: [PATCH v11 44/46] KVM: selftests: evmcs_test: Introduce L2 TLB flush test
From: Sean Christopherson
Date: Wed Oct 19 2022 - 18:19:34 EST
On Tue, Oct 04, 2022, Vitaly Kuznetsov wrote:
> @@ -64,15 +67,33 @@ void l2_guest_code(void)
> vmcall();
> rdmsr_gs_base(); /* intercepted */
>
> + /* L2 TLB flush tests */
> + hyperv_hypercall(HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE | HV_HYPERCALL_FAST_BIT, 0x0,
> + HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES | HV_FLUSH_ALL_PROCESSORS);
Alignment is funky.
> + rdmsr_fs_base();
> + /*
> + * Note: hypercall status (RAX) is not preserved correctly by L1 after
> + * synthetic vmexit, use unchecked version.
Nice...
> + */
> + __hyperv_hypercall(HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE | HV_HYPERCALL_FAST_BIT, 0x0,
> + HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES | HV_FLUSH_ALL_PROCESSORS,
> + &unused);
> + /* Make sure we're no issuing Hyper-V TLB flush call again */
> + __asm__ __volatile__ ("mov $0xdeadbeef, %rcx");
> +
> /* Done, exit to L1 and never come back. */
> vmcall();
> }
>
> -void guest_code(struct vmx_pages *vmx_pages, struct hyperv_test_pages *hv_pages)
> +void guest_code(struct vmx_pages *vmx_pages, struct hyperv_test_pages *hv_pages,
> + vm_vaddr_t hv_hcall_page_gpa)
> {
> #define L2_GUEST_STACK_SIZE 64
> unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE];
>
> + wrmsr(HV_X64_MSR_GUEST_OS_ID, HYPERV_LINUX_OS_ID);
> + wrmsr(HV_X64_MSR_HYPERCALL, hv_hcall_page_gpa);
> +
> x2apic_enable();
>
> GUEST_SYNC(1);
> @@ -102,6 +123,14 @@ void guest_code(struct vmx_pages *vmx_pages, struct hyperv_test_pages *hv_pages)
> vmwrite(PIN_BASED_VM_EXEC_CONTROL, vmreadz(PIN_BASED_VM_EXEC_CONTROL) |
> PIN_BASED_NMI_EXITING);
>
> + /* L2 TLB flush setup */
> + current_evmcs->partition_assist_page = hv_pages->partition_assist_gpa;
> + current_evmcs->hv_enlightenments_control.nested_flush_hypercall = 1;
> + current_evmcs->hv_vm_id = 1;
> + current_evmcs->hv_vp_id = 1;
> + current_vp_assist->nested_control.features.directhypercall = 1;
> + *(u32 *)(hv_pages->partition_assist) = 0;
> +
> GUEST_ASSERT(!vmlaunch());
Pre-existing code, but would it make sense to add an assert here to verify L2
exited due to an NMI? Feel free to ignore this for now if it's not straightforward,
this series is plenty big :-)