Skip to contentSkip to conversation

KVM: selftests: fix ucall on x86

PATCH Applied Vitaly Kuznetsov 2 participants 2 messages Sep 25, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: selftests: fix ucall on x86

After commit e8bb4755eea2("KVM: selftests: Split ucall.c into architecture specific files") selftests which use ucall on x86 started segfaulting and apparently it's gcc to blame: it "optimizes" ucall() function throwing away va_start/va_end part because it thinks the structure is not being used. Previously, it couldn't do that because the there was also MMIO version and the decision which particular implementation to use was done at runtime.

With older gccs it's possible to solve the problem by adding 'volatile' to 'struct ucall' but at least with gcc-8.3 this trick doesn't work.

'memory' clobber seems to do the job.

---
s390 should, in theory, have the same problem. Thomas, Cornelia, could you please take a look? Thanks!

---
 tools/testing/selftests/kvm/lib/x86_64/ucall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/lib/x86_64/ucall.c +1 -1
index 4bfc9a90b1de..da4d89ad5419 100644
@@ -32,7 +32,7 @@ void ucall(uint64_t cmd, int nargs, ...)
 	va_end(va);
 
 	asm volatile("in %[port], %%al"
-		: : [port] "d" (UCALL_PIO_PORT), "D" (&uc) : "rax");
+		: : [port] "d" (UCALL_PIO_PORT), "D" (&uc) : "rax", "memory");
 }
 
 uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
Signature · 1 line
2.20.1
maintainer Applied
#1 lore raw
Quoted 26 lines · Vitaly Kuznetsov

After commit e8bb4755eea2("KVM: selftests: Split ucall.c into architecture specific files") selftests which use ucall on x86 started segfaulting and apparently it's gcc to blame: it "optimizes" ucall() function throwing away va_start/va_end part because it thinks the structure is not being used. Previously, it couldn't do that because the there was also MMIO version and the decision which particular implementation to use was done at runtime.

With older gccs it's possible to solve the problem by adding 'volatile' to 'struct ucall' but at least with gcc-8.3 this trick doesn't work.

'memory' clobber seems to do the job.

---
s390 should, in theory, have the same problem. Thomas, Cornelia, could you please take a look? Thanks!

---
 tools/testing/selftests/kvm/lib/x86_64/ucall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/lib/x86_64/ucall.c +0 -0
index 4bfc9a90b1de..da4d89ad5419 100644

tools/testing/selftests/kvm/lib/x86_64/ucall.c void ucall(uint64_t cmd, int nargs, ...) · line 38

Quoted 8 lines
tools/testing/selftests/kvm/lib/x86_64/ucall.c +1 -1
@@ -32,7 +32,7 @@ void ucall(uint64_t cmd, int nargs, ...)
 	va_end(va);
 
 	asm volatile("in %[port], %%al"
-		: : [port] "d" (UCALL_PIO_PORT), "D" (&uc) : "rax");
+		: : [port] "d" (UCALL_PIO_PORT), "D" (&uc) : "rax", "memory");
 }
 
 uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)

Queued, thanks. s390 already clobbers memory.

Paolo