From: David Woodhouse <[email protected]> read_sse_reg() and write_sse_reg() were borrowed from KVM's _kvm_read_sse_reg() and _kvm_write_sse_reg(). The kernel is built without SSE, so the compiler never uses the XMM registers itself and a plain asm() is enough there. Selftest guest code is built with SSE, and there the asm statements have to tell the compiler what they do.
read_sse_reg() has an output and is not volatile, so the compiler may treat it as a pure computation and move it, for example ahead of the hypercall whose XMM output it is meant to read. write_sse_reg() has no outputs and is therefore implicitly volatile, but it doesn't declare the register it overwrites, so a value the compiler was keeping there does not survive. Mark both volatile, and declare the register each write_sse_reg() case writes as clobbered. A read_sse_reg() after __hyperv_hypercall() now stays after it. That still leaves the compiler free to use an XMM register for its own code between a write_sse_reg() and the asm which consumes it. hyperv_write_xmm_input() in the hyperv_ipi and hyperv_tlb_flush tests relies on that not happening; GCC 11.5 at -O2 emits nothing there. Closing that window entirely would mean passing the XMM values as operands of the hypercall asm itself. Reported-by: Sashiko <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: David Woodhouse <[email protected]> --- .../selftests/kvm/include/x86/processor.h | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/testing/selftests/kvm/include/x86/processor.h index 3e4351ccb359..28571ac697c8 100644 --- a/tools/testing/selftests/kvm/include/x86/processor.h +++ b/tools/testing/selftests/kvm/include/x86/processor.h @@ -888,28 +888,28 @@ static inline void read_sse_reg(int reg, sse128_t *data) { switch (reg) { case 0: - asm("movdqa %%xmm0, %0" : "=m"(*data)); + asm volatile("movdqa %%xmm0, %0" : "=m"(*data)); break; case 1: - asm("movdqa %%xmm1, %0" : "=m"(*data)); + asm volatile("movdqa %%xmm1, %0" : "=m"(*data)); break; case 2: - asm("movdqa %%xmm2, %0" : "=m"(*data)); + asm volatile("movdqa %%xmm2, %0" : "=m"(*data)); break; case 3: - asm("movdqa %%xmm3, %0" : "=m"(*data)); + asm volatile("movdqa %%xmm3, %0" : "=m"(*data)); break; case 4: - asm("movdqa %%xmm4, %0" : "=m"(*data)); + asm volatile("movdqa %%xmm4, %0" : "=m"(*data)); break; case 5: - asm("movdqa %%xmm5, %0" : "=m"(*data)); + asm volatile("movdqa %%xmm5, %0" : "=m"(*data)); break; case 6: - asm("movdqa %%xmm6, %0" : "=m"(*data)); + asm volatile("movdqa %%xmm6, %0" : "=m"(*data)); break; case 7: - asm("movdqa %%xmm7, %0" : "=m"(*data)); + asm volatile("movdqa %%xmm7, %0" : "=m"(*data)); break; default: BUG(); @@ -920,28 +920,28 @@ static inline void write_sse_reg(int reg, const sse128_t *data) { switch (reg) { case 0: - asm("movdqa %0, %%xmm0" : : "m"(*data)); + asm volatile("movdqa %0, %%xmm0" : : "m"(*data) : "xmm0"); break; case 1: - asm("movdqa %0, %%xmm1" : : "m"(*data)); + asm volatile("movdqa %0, %%xmm1" : : "m"(*data) : "xmm1"); break; case 2: - asm("movdqa %0, %%xmm2" : : "m"(*data)); + asm volatile("movdqa %0, %%xmm2" : : "m"(*data) : "xmm2"); break; case 3: - asm("movdqa %0, %%xmm3" : : "m"(*data)); + asm volatile("movdqa %0, %%xmm3" : : "m"(*data) : "xmm3"); break; case 4: - asm("movdqa %0, %%xmm4" : : "m"(*data)); + asm volatile("movdqa %0, %%xmm4" : : "m"(*data) : "xmm4"); break; case 5: - asm("movdqa %0, %%xmm5" : : "m"(*data)); + asm volatile("movdqa %0, %%xmm5" : : "m"(*data) : "xmm5"); break; case 6: - asm("movdqa %0, %%xmm6" : : "m"(*data)); + asm volatile("movdqa %0, %%xmm6" : : "m"(*data) : "xmm6"); break; case 7: - asm("movdqa %0, %%xmm7" : : "m"(*data)); + asm volatile("movdqa %0, %%xmm7" : : "m"(*data) : "xmm7"); break; default: BUG(); base-commit: cbe54fc3462b3949ab27b9ae81fb9ddb509040c7 -- 2.50.1
