Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] KVM: selftests: missing volatile and XMM constraints in guest_code() --
commit e7e0d35b7ca4b9fc386b6fe7a75c6cc9bf38431a Author: David Woodhouse <[email protected]> KVM: selftests: Add Hyper-V hypercall forwarding test This commit adds a KVM selftest covering KVM_CAP_HYPERV_FORWARD_HCALL for memory-based and fast hypercall exits as well as hypercall completion cancellation via KVM_SET_VCPU_EVENTS. > diff --git a/tools/testing/selftests/kvm/x86/hyperv_forward_hcall.c > b/tools/testing/selftests/kvm/x86/hyperv_forward_hcall.c > new file mode 100644 > index 0000000000000..4c290b6a10122 > --- /dev/null > +++ b/tools/testing/selftests/kvm/x86/hyperv_forward_hcall.c > @@ -0,0 +1,337 @@ [ ... ] > +static void guest_code(gpa_t pgs_gpa) > +{ > + __sse128_u in, out; > + u64 status; > + u8 vector; [ ... ] > + /* > + * Fast form: the register parameters and XMM0 reach userspace, and > + * the XMM1 value userspace writes reaches the guest. > + */ > + in.as_u64[0] = XMM_IN_MARKER; > + in.as_u64[1] = XMM_IN_MARKER + 1; > + out.as_u64[0] = 0; > + out.as_u64[1] = 0; > + write_sse_reg(0, &in.vec); > + write_sse_reg(1, &out.vec); > + vector = __hyperv_hypercall(HVCALL_TEST_CODE | HV_HYPERCALL_FAST_BIT, > + FAST_PARAM0, FAST_PARAM1, &status); > + read_sse_reg(1, &out.vec); > + GUEST_ASSERT(!vector); > + GUEST_ASSERT_EQ(status, USERSPACE_STATUS); > + GUEST_ASSERT_EQ(out.as_u64[0], XMM_OUT_MARKER); > + GUEST_ASSERT_EQ(out.as_u64[1], XMM_OUT_MARKER + 1); > + GUEST_SYNC(STAGE_FAST); [Severity: Low] Can the compiler reorder read_sse_reg() across __hyperv_hypercall(), or clobber xmm0 before the hypercall runs? In tools/testing/selftests/kvm/include/x86/processor.h, read_sse_reg() uses a non-volatile asm statement with an output operand and no input operands, and neither write_sse_reg() nor __hyperv_hypercall() declares xmm register constraints or clobbers: tools/testing/selftests/kvm/include/x86/processor.h:read_sse_reg() { switch (reg) { ... case 1: asm("movdqa %%xmm1, %0" : "=m"(*data)); break; } tools/testing/selftests/kvm/include/x86/processor.h:write_sse_reg() { switch (reg) { case 0: asm("movdqa %0, %%xmm0" : : "m"(*data)); break; } Because x86 selftests are compiled with -O2 -march=x86-64-v2 (with SSE enabled), the compiler can schedule a vectorized zeroing of out via xmm0 after write_sse_reg(0, &in.vec) or move read_sse_reg(1, &out.vec) ahead of __hyperv_hypercall(), causing spurious assertion failures in handle_fast_hcall() or guest_code(). -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=4
