From: Sean Christopherson <seanjc@google.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
jpoimboe@redhat.com, mark.rutland@arm.com, dvyukov@google.com,
pbonzini@redhat.com, mbenes@suse.cz
Subject: Re: [PATCH v2 16/23] x86,vmx: Provide asm-goto-output vmread
Date: Tue, 14 Dec 2021 18:44:48 +0000 [thread overview]
Message-ID: <YbjmIPWtd6ke66CU@google.com> (raw)
In-Reply-To: <YbcbbGW2GcMx6KpD@hirez.programming.kicks-ass.net>
On Mon, Dec 13, 2021, Peter Zijlstra wrote:
>
> Here's a version that doesn't make clang ICE..
>
> Paolo, since this doesn't really depend on the .fixup removal series,
> feel free to collect it in the kvm tree or somesuch.
>
> ---
> Subject: x86/vmx: Provide asm-goto-output vmread
> From: Peter Zijlstra <peterz@infradead.org>
> Date: Wed, 10 Nov 2021 11:01:18 +0100
>
> Use asm-goto-output for smaller fast path code.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
> arch/x86/kvm/vmx/vmx_ops.h | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> --- a/arch/x86/kvm/vmx/vmx_ops.h
> +++ b/arch/x86/kvm/vmx/vmx_ops.h
> @@ -71,6 +71,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])
> +
> + : [output] "=r" (value)
> + : [field] "r" (field)
> + : "cc"
> + : do_fail, do_exception);
> +
> + return value;
> +
> +do_fail:
> + WARN_ONCE(1, "kvm: vmread failed: field=%lx\n", field);
> + pr_warn_ratelimited("kvm: vmread failed: field=%lx\n", field);
This needs to route through a noinline vmread_error(), the intent is that KVM only
does WARN once for all VMREAD failures, whereas having this inline will WARN once
on each unique vmcs_read*(). And at that point, we might as well hide the asm
trampoline too. The amount of ifdeffery gets a bit gross, but in for a penny in
for a pound?
And like the other VMX instruction, I assume it's safe to annotate the failure
path as instrumentation safe.
So this?
---
arch/x86/kvm/vmx/vmenter.S | 2 ++
arch/x86/kvm/vmx/vmx.c | 7 +++++++
arch/x86/kvm/vmx/vmx_ops.h | 31 +++++++++++++++++++++++++++++++
3 files changed, 40 insertions(+)
diff --git a/arch/x86/kvm/vmx/vmenter.S b/arch/x86/kvm/vmx/vmenter.S
index 3a6461694fc2..d8a7a0a69ec1 100644
--- a/arch/x86/kvm/vmx/vmenter.S
+++ b/arch/x86/kvm/vmx/vmenter.S
@@ -238,6 +238,7 @@ SYM_FUNC_END(__vmx_vcpu_run)
.section .text, "ax"
+#ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT
/**
* vmread_error_trampoline - Trampoline from inline asm to vmread_error()
* @field: VMCS field encoding that failed
@@ -295,6 +296,7 @@ SYM_FUNC_START(vmread_error_trampoline)
ret
SYM_FUNC_END(vmread_error_trampoline)
+#endif
SYM_FUNC_START(vmx_do_interrupt_nmi_irqoff)
/*
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 640f4719612c..746c0952ddac 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -373,6 +373,12 @@ do { \
pr_warn_ratelimited(fmt); \
} while (0)
+#ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT
+noinline void vmread_error(unsigned long field)
+{
+ vmx_insn_failed("kvm: vmread failed: field=%lx\n", field);
+}
+#else
asmlinkage void vmread_error(unsigned long field, bool fault)
{
if (fault)
@@ -380,6 +386,7 @@ asmlinkage void vmread_error(unsigned long field, bool fault)
else
vmx_insn_failed("kvm: vmread failed: field=%lx\n", field);
}
+#endif
noinline void vmwrite_error(unsigned long field, unsigned long value)
{
diff --git a/arch/x86/kvm/vmx/vmx_ops.h b/arch/x86/kvm/vmx/vmx_ops.h
index 9e9ef47e988c..6cdc4ff4335f 100644
--- a/arch/x86/kvm/vmx/vmx_ops.h
+++ b/arch/x86/kvm/vmx/vmx_ops.h
@@ -10,9 +10,13 @@
#include "vmcs.h"
#include "x86.h"
+#ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT
+noinline void vmread_error(unsigned long field);
+#else
asmlinkage void vmread_error(unsigned long field, bool fault);
__attribute__((regparm(0))) void vmread_error_trampoline(unsigned long field,
bool fault);
+#endif
void vmwrite_error(unsigned long field, unsigned long value);
void vmclear_error(struct vmcs *vmcs, u64 phys_addr);
void vmptrld_error(struct vmcs *vmcs, u64 phys_addr);
@@ -71,6 +75,31 @@ static __always_inline unsigned long __vmcs_readl(unsigned long field)
{
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])
+
+ : [output] "=r" (value)
+ : [field] "r" (field)
+ : "cc"
+ : do_fail, do_exception);
+
+ return value;
+
+do_fail:
+ instrumentation_begin();
+ vmread_error(field);
+ instrumentation_end();
+ return 0;
+
+do_exception:
+ 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"
@@ -101,6 +130,8 @@ static __always_inline unsigned long __vmcs_readl(unsigned long field)
_ASM_EXTABLE(1b, 4b)
: 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)
--
next prev parent reply other threads:[~2021-12-14 18:44 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-10 10:01 [PATCH v2 00/23] x86: Remove anonymous out-of-line fixups Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 01/23] bitfield.h: Fix "type of reg too small for mask" test Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 02/23] x86,mmx_32: Remove .fixup usage Peter Zijlstra
2021-11-15 16:54 ` [PATCH v2.1 02/23] x86/mmx_32: Remove X86_USE_3DNOW Peter Zijlstra
2021-11-16 18:25 ` Borislav Petkov
2021-12-13 9:50 ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 03/23] x86,copy_user_64: Remove .fixup usage Peter Zijlstra
2021-11-16 19:04 ` Borislav Petkov
2021-12-13 9:50 ` [tip: x86/core] x86/copy_user_64: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 04/23] x86,copy_mc_64: " Peter Zijlstra
2021-11-17 16:28 ` Borislav Petkov
2021-12-13 9:50 ` [tip: x86/core] x86/copy_mc_64: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 05/23] x86,entry_64: " Peter Zijlstra
2021-11-17 16:29 ` Borislav Petkov
2021-11-19 8:00 ` Lai Jiangshan
2021-12-13 9:50 ` [tip: x86/core] x86/entry_64: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 06/23] x86,entry_32: " Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/entry_32: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 07/23] x86,extable: Extend extable functionality Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/extable: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 08/23] x86,msr: Remove .fixup usage Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/msr: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 09/23] x86,futex: " Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/futex: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 10/23] x86,uaccess: " Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/uaccess: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 11/23] x86,xen: " Peter Zijlstra
2021-11-10 10:35 ` Juergen Gross
2021-11-10 11:00 ` Peter Zijlstra
2021-11-10 12:46 ` Peter Zijlstra
2021-11-10 12:52 ` Juergen Gross
2021-11-10 16:17 ` Peter Zijlstra
2021-11-11 7:20 ` Juergen Gross
2021-11-10 12:45 ` [PATCH v2.1 " Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/xen: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 12/23] x86,fpu: " Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/fpu: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 13/23] x86,segment: " Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/segment: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 14/23] x86,kvm: " Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/kvm: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 15/23] x86,vmx: " Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/vmx: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 16/23] x86,vmx: Provide asm-goto-output vmread Peter Zijlstra
2021-12-13 10:07 ` Peter Zijlstra
2021-12-14 18:44 ` Sean Christopherson [this message]
2021-12-14 22:46 ` Peter Zijlstra
2021-12-14 23:07 ` Sean Christopherson
2021-11-10 10:01 ` [PATCH v2 17/23] x86,checksum_32: Remove .fixup usage Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/checksum_32: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 18/23] x86,sgx: " Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/sgx: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 19/23] x86,usercopy_32: Simplify __copy_user_intel_nocache() Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/usercopy_32: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 20/23] x86,usercopy: Remove .fixup usage Peter Zijlstra
2021-11-11 7:51 ` Josh Poimboeuf
2021-11-11 8:28 ` Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/usercopy: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 21/23] x86,word-at-a-time: " Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] x86/word-at-a-time: " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 22/23] x86: Remove .fixup section Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2021-11-10 10:01 ` [PATCH v2 23/23] objtool: Remove .fixup handling Peter Zijlstra
2021-12-13 9:50 ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2021-11-11 7:55 ` [PATCH v2 00/23] x86: Remove anonymous out-of-line fixups Josh Poimboeuf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YbjmIPWtd6ke66CU@google.com \
--to=seanjc@google.com \
--cc=dvyukov@google.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mbenes@suse.cz \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox