Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH 0/2] Inline vmcs_readl()
@ 2011-05-15 14:13 Avi Kivity
  2011-05-15 14:13 ` [PATCH 1/2] KVM: VMX: Move VMREAD cleanup to exception handler Avi Kivity
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Avi Kivity @ 2011-05-15 14:13 UTC (permalink / raw)
  To: Marcelo Tosatti, kvm

The following two patches optimize vmcs_readl() to a single VMREAD instruction,
instead of a call to a 7-instruction function.

Avi Kivity (2):
  KVM: VMX: Move VMREAD cleanup to exception handler
  KVM: VMX: always_inline VMREADs

 arch/x86/include/asm/kvm_host.h |    6 +++++-
 arch/x86/kvm/vmx.c              |   16 +++++++++-------
 2 files changed, 14 insertions(+), 8 deletions(-)

-- 
1.7.4.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] KVM: VMX: Move VMREAD cleanup to exception handler
  2011-05-15 14:13 [PATCH 0/2] Inline vmcs_readl() Avi Kivity
@ 2011-05-15 14:13 ` Avi Kivity
  2011-05-15 14:13 ` [PATCH 2/2] KVM: VMX: always_inline VMREADs Avi Kivity
  2011-05-18 13:02 ` [PATCH 0/2] Inline vmcs_readl() Marcelo Tosatti
  2 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2011-05-15 14:13 UTC (permalink / raw)
  To: Marcelo Tosatti, kvm

We clean up a failed VMREAD by clearing the output register.  Do
it in the exception handler instead of unconditionally.  This is
worthwhile since there are more than a hundred call sites.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 arch/x86/include/asm/kvm_host.h |    6 +++++-
 arch/x86/kvm/vmx.c              |    8 +++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index d2ac8e2..db4b654 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -830,11 +830,12 @@ enum {
 asmlinkage void kvm_spurious_fault(void);
 extern bool kvm_rebooting;
 
-#define __kvm_handle_fault_on_reboot(insn) \
+#define ____kvm_handle_fault_on_reboot(insn, cleanup_insn)	\
 	"666: " insn "\n\t" \
 	"668: \n\t"                           \
 	".pushsection .fixup, \"ax\" \n" \
 	"667: \n\t" \
+	cleanup_insn "\n\t"		      \
 	"cmpb $0, kvm_rebooting \n\t"	      \
 	"jne 668b \n\t"      		      \
 	__ASM_SIZE(push) " $666b \n\t"	      \
@@ -844,6 +845,9 @@ extern bool kvm_rebooting;
 	_ASM_PTR " 666b, 667b \n\t" \
 	".popsection"
 
+#define __kvm_handle_fault_on_reboot(insn)		\
+	____kvm_handle_fault_on_reboot(insn, "")
+
 #define KVM_ARCH_WANT_MMU_NOTIFIER
 int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
 int kvm_age_hva(struct kvm *kvm, unsigned long hva);
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 4c3fa0f..3df6b2c 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -43,6 +43,8 @@
 #include "trace.h"
 
 #define __ex(x) __kvm_handle_fault_on_reboot(x)
+#define __ex_clear(x, reg) \
+	____kvm_handle_fault_on_reboot(x, "xor " reg " , " reg)
 
 MODULE_AUTHOR("Qumranet");
 MODULE_LICENSE("GPL");
@@ -587,10 +589,10 @@ static inline void ept_sync_individual_addr(u64 eptp, gpa_t gpa)
 
 static unsigned long vmcs_readl(unsigned long field)
 {
-	unsigned long value = 0;
+	unsigned long value;
 
-	asm volatile (__ex(ASM_VMX_VMREAD_RDX_RAX)
-		      : "+a"(value) : "d"(field) : "cc");
+	asm volatile (__ex_clear(ASM_VMX_VMREAD_RDX_RAX, "%0")
+		      : "=a"(value) : "d"(field) : "cc");
 	return value;
 }
 
-- 
1.7.4.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] KVM: VMX: always_inline VMREADs
  2011-05-15 14:13 [PATCH 0/2] Inline vmcs_readl() Avi Kivity
  2011-05-15 14:13 ` [PATCH 1/2] KVM: VMX: Move VMREAD cleanup to exception handler Avi Kivity
@ 2011-05-15 14:13 ` Avi Kivity
  2011-05-18 13:02 ` [PATCH 0/2] Inline vmcs_readl() Marcelo Tosatti
  2 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2011-05-15 14:13 UTC (permalink / raw)
  To: Marcelo Tosatti, kvm

vmcs_readl() and friends are really short, but gcc thinks they are long because of
the out-of-line exception handlers.  Mark them always_inline to clear the
misunderstanding.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 arch/x86/kvm/vmx.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 3df6b2c..750b0ff 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -587,7 +587,7 @@ static inline void ept_sync_individual_addr(u64 eptp, gpa_t gpa)
 	}
 }
 
-static unsigned long vmcs_readl(unsigned long field)
+static __always_inline unsigned long vmcs_readl(unsigned long field)
 {
 	unsigned long value;
 
@@ -596,17 +596,17 @@ static unsigned long vmcs_readl(unsigned long field)
 	return value;
 }
 
-static u16 vmcs_read16(unsigned long field)
+static __always_inline u16 vmcs_read16(unsigned long field)
 {
 	return vmcs_readl(field);
 }
 
-static u32 vmcs_read32(unsigned long field)
+static __always_inline u32 vmcs_read32(unsigned long field)
 {
 	return vmcs_readl(field);
 }
 
-static u64 vmcs_read64(unsigned long field)
+static __always_inline u64 vmcs_read64(unsigned long field)
 {
 #ifdef CONFIG_X86_64
 	return vmcs_readl(field);
-- 
1.7.4.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Inline vmcs_readl()
  2011-05-15 14:13 [PATCH 0/2] Inline vmcs_readl() Avi Kivity
  2011-05-15 14:13 ` [PATCH 1/2] KVM: VMX: Move VMREAD cleanup to exception handler Avi Kivity
  2011-05-15 14:13 ` [PATCH 2/2] KVM: VMX: always_inline VMREADs Avi Kivity
@ 2011-05-18 13:02 ` Marcelo Tosatti
  2 siblings, 0 replies; 4+ messages in thread
From: Marcelo Tosatti @ 2011-05-18 13:02 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm

On Sun, May 15, 2011 at 10:13:11AM -0400, Avi Kivity wrote:
> The following two patches optimize vmcs_readl() to a single VMREAD instruction,
> instead of a call to a 7-instruction function.
> 
> Avi Kivity (2):
>   KVM: VMX: Move VMREAD cleanup to exception handler
>   KVM: VMX: always_inline VMREADs

Applied, thanks.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-05-18 13:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-15 14:13 [PATCH 0/2] Inline vmcs_readl() Avi Kivity
2011-05-15 14:13 ` [PATCH 1/2] KVM: VMX: Move VMREAD cleanup to exception handler Avi Kivity
2011-05-15 14:13 ` [PATCH 2/2] KVM: VMX: always_inline VMREADs Avi Kivity
2011-05-18 13:02 ` [PATCH 0/2] Inline vmcs_readl() Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox