Re: [RFC][PATCH 15/22] x86,vmx: Remove .fixup usage

From: Peter Zijlstra
Date: Sat Nov 06 2021 - 04:30:39 EST


On Fri, Nov 05, 2021 at 06:17:53PM +0000, Sean Christopherson wrote:

> And hopefully this entire mess will
> go away before that happens, as the trampoline shenanigans are needed
> only because the minimum compiler version doesn't guarantee support for
> asm goto with outputs.

We can at least have those who use sane compilers get sane code..

Something like this, right?

--- a/arch/x86/kvm/vmx/vmx_ops.h
+++ b/arch/x86/kvm/vmx/vmx_ops.h
@@ -70,6 +70,31 @@ static __always_inline unsigned long __v
{
unsigned long value;

+#ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT
+
+ asm_volatile_goto("1: vmread %[field], %[output]\n\t"
+ "jna %l[do_fail]\n\t"
+
+ _ASM_EXTABLE(1b, %l[do_exception])
+
+ : ASM_CALL_CONSTRAINT, [output] "=r" (value)
+ : [field] "r" (field)
+ : "cc"
+ : do_fail, do_exception);
+
+ return value;
+
+do_fail: __cold;
+ WARN_ONCE(1, "kvm: vmread failed: field=%lx\n", field);
+ pr_warn_ratelimited("kvm: vmread failed: field=%lx\n", field);
+ return 0;
+
+do_exception: __cold;
+ kvm_spurious_fault();
+ return 0;
+
+#else /* !CONFIG_CC_HAS_ASM_GOTO_OUTPUT */
+
asm volatile("1: vmread %2, %1\n\t"
".byte 0x3e\n\t" /* branch taken hint */
"ja 3f\n\t"
@@ -94,7 +119,10 @@ static __always_inline unsigned long __v
_ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_EFAULT_REG, %1)

: ASM_CALL_CONSTRAINT, "=r"(value) : "r"(field) : "cc");
+
return value;
+
+#endif /* CONFIG_CC_HAS_ASM_GOTO_OUTPUT */
}

static __always_inline u16 vmcs_read16(unsigned long field)