Skip to content

Commit 9e2f649

Browse files
rananta468bonzini
authored andcommitted
selftests: KVM: Handle compiler optimizations in ucall
The selftests, when built with newer versions of clang, is found to have over optimized guests' ucall() function, and eliminating the stores for uc.cmd (perhaps due to no immediate readers). This resulted in the userspace side always reading a value of '0', and causing multiple test failures. As a result, prevent the compiler from optimizing the stores in ucall() with WRITE_ONCE(). Suggested-by: Ricardo Koller <[email protected]> Suggested-by: Reiji Watanabe <[email protected]> Signed-off-by: Raghavendra Rao Ananta <[email protected]> Message-Id: <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 933b5f9 commit 9e2f649

File tree

1 file changed

+4
-5
lines changed
  • tools/testing/selftests/kvm/lib/aarch64

1 file changed

+4
-5
lines changed

tools/testing/selftests/kvm/lib/aarch64/ucall.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,19 @@ void ucall_uninit(struct kvm_vm *vm)
7373

7474
void ucall(uint64_t cmd, int nargs, ...)
7575
{
76-
struct ucall uc = {
77-
.cmd = cmd,
78-
};
76+
struct ucall uc = {};
7977
va_list va;
8078
int i;
8179

80+
WRITE_ONCE(uc.cmd, cmd);
8281
nargs = nargs <= UCALL_MAX_ARGS ? nargs : UCALL_MAX_ARGS;
8382

8483
va_start(va, nargs);
8584
for (i = 0; i < nargs; ++i)
86-
uc.args[i] = va_arg(va, uint64_t);
85+
WRITE_ONCE(uc.args[i], va_arg(va, uint64_t));
8786
va_end(va);
8887

89-
*ucall_exit_mmio_addr = (vm_vaddr_t)&uc;
88+
WRITE_ONCE(*ucall_exit_mmio_addr, (vm_vaddr_t)&uc);
9089
}
9190

9291
uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)

0 commit comments

Comments
 (0)