public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Let gcc to choose which registers to save
@ 2007-10-25 12:18 Laurent Vivier
       [not found] ` <11933147352304-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Laurent Vivier @ 2007-10-25 12:18 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f; +Cc: Laurent Vivier

This patch lets GCC to determine which registers to save when we
switch to/from a VCPU.

[PATCH 1/4] Let gcc to choose which registers to save (vmx-x86_64)

    drivers/kvm/vmx.c |   21 +++++++++------------
    1 files changed, 9 insertions(+), 12 deletions(-)

    This patch lets GCC to determine which registers to save when we
    switch to/from a VCPU in the case of intel x86_64.

[PATCH 2/4] Let gcc to choose which registers to save (svm-x86_64)

    drivers/kvm/svm.c |   17 ++++++++---------
    1 files changed, 8 insertions(+), 9 deletions(-)

    This patch lets GCC to determine which registers to save when we
    switch to/from a VCPU in the case of AMD x86_64.

[PATCH 3/4] Let gcc to choose which registers to save (svm-i386)

    drivers/kvm/svm.c |    8 ++++----
    1 files changed, 4 insertions(+), 4 deletions(-)

    This patch lets GCC to determine which registers to save when we
    switch to/from a VCPU in the case of AMD i386

[PATCH 4/4] Let gcc to choose which registers to save (vmx-i386)

    drivers/kvm/vmx.c |    8 +++++---
    1 files changed, 5 insertions(+), 3 deletions(-)

    This patch lets GCC to determine which registers to save when we
    switch to/from a VCPU in the case of intel i386.

Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

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

* [PATCH 1/4] Let gcc to choose which registers to save (vmx-x86_64)
       [not found] ` <11933147352304-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
@ 2007-10-25 12:18   ` Laurent Vivier
       [not found]     ` <11933147352093-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
  2007-10-26 13:49   ` [PATCH 0/4] Let gcc to choose which registers to save Avi Kivity
  1 sibling, 1 reply; 7+ messages in thread
From: Laurent Vivier @ 2007-10-25 12:18 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f; +Cc: Laurent Vivier

This patch lets GCC to determine which registers to save when we
switch to/from a VCPU in the case of intel x86_64.

* Original code saves following registers:

    rax, rbx, rcx, rdx, rsi, rdi, rbp,
    r8, r9, r10, r11, r12, r13, r14, r15

* Patched code:

  - informs GCC that we modify following registers 
    using the clobber description:

    rbx, rdi, rsi,
    r8, r9, r10, r11, r12, r13, r14, r15

  - doesn't save rax because it is an output operand (vmx->fail)

  - cannot put rcx in clobber description because it is an input operand, 
    but as we modify it and we want to keep its value (vcpu), we must 
    save it (pop/push)

  - rbp is saved (pop/push) because GCC seems to ignore its use in the clobber
    description.

  - rdx is saved (pop/push) because it is reserved by GCC (REGPARM) and
    cannot be put in the clobber description.

  - line "mov (%%rsp), %3 \n\t" has been removed because %3
    is rcx and rcx is restored just after.

  - line ASM_VMX_VMWRITE_RSP_RDX() is moved out of the ifdef/else/endif

Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
---
 drivers/kvm/vmx.c |   21 +++++++++------------
 1 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 97814e4..ec81ebc 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -2242,16 +2242,12 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 	asm(
 		/* Store host registers */
 #ifdef CONFIG_X86_64
-		"push %%rax; push %%rbx; push %%rdx;"
-		"push %%rsi; push %%rdi; push %%rbp;"
-		"push %%r8;  push %%r9;  push %%r10; push %%r11;"
-		"push %%r12; push %%r13; push %%r14; push %%r15;"
+		"push %%rdx; push %%rbp;"
 		"push %%rcx \n\t"
-		ASM_VMX_VMWRITE_RSP_RDX "\n\t"
 #else
 		"pusha; push %%ecx \n\t"
-		ASM_VMX_VMWRITE_RSP_RDX "\n\t"
 #endif
+		ASM_VMX_VMWRITE_RSP_RDX "\n\t"
 		/* Check if vmlaunch of vmresume is needed */
 		"cmp $0, %1 \n\t"
 		/* Load guest registers.  Don't clobber flags. */
@@ -2310,12 +2306,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		"mov %%r15, %c[r15](%3) \n\t"
 		"mov %%cr2, %%rax   \n\t"
 		"mov %%rax, %c[cr2](%3) \n\t"
-		"mov (%%rsp), %3 \n\t"
 
-		"pop  %%rcx; pop  %%r15; pop  %%r14; pop  %%r13; pop  %%r12;"
-		"pop  %%r11; pop  %%r10; pop  %%r9;  pop  %%r8;"
-		"pop  %%rbp; pop  %%rdi; pop  %%rsi;"
-		"pop  %%rdx; pop  %%rbx; pop  %%rax \n\t"
+		"pop  %%rcx; pop  %%rbp; pop  %%rdx \n\t"
 #else
 		"xchg %3, (%%esp) \n\t"
 		"mov %%eax, %c[rax](%3) \n\t"
@@ -2353,7 +2345,12 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		[r15]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R15])),
 #endif
 		[cr2]"i"(offsetof(struct kvm_vcpu, cr2))
-	      : "cc", "memory");
+	      : "cc", "memory"
+#ifdef CONFIG_X86_64
+		, "rbx", "rdi", "rsi"
+		, "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
+#endif
+	      );
 
 	vcpu->interrupt_window_open =
 		(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0;
-- 
1.5.2.4


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

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

* [PATCH 2/4] Let gcc to choose which registers to save (svm-x86_64)
       [not found]     ` <11933147352093-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
@ 2007-10-25 12:18       ` Laurent Vivier
       [not found]         ` <1193314735566-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Laurent Vivier @ 2007-10-25 12:18 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f; +Cc: Laurent Vivier

This patch lets GCC to determine which registers to save when we
switch to/from a VCPU in the case of AMD x86_64.

* Original code saves following registers:

    rbx, rcx, rdx, rsi, rdi, rbp,
    r8, r9, r10, r11, r12, r13, r14, r15

* Patched code:

  - informs GCC that we modify following registers
    using the clobber description:

    rbx, rcx, rdx, rsi, rdi
    r8, r9, r10, r11, r12, r13, r14, r15

  - rbp is saved (pop/push) because GCC seems to ignore its use in the clobber
    description.

Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
---
 drivers/kvm/svm.c |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 3cc324a..c69d6b6 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -1483,10 +1483,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 
 	asm volatile (
 #ifdef CONFIG_X86_64
-		"push %%rbx; push %%rcx; push %%rdx;"
-		"push %%rsi; push %%rdi; push %%rbp;"
-		"push %%r8;  push %%r9;  push %%r10; push %%r11;"
-		"push %%r12; push %%r13; push %%r14; push %%r15;"
+		"push %%rbp; \n\t"
 #else
 		"push %%ebx; push %%ecx; push %%edx;"
 		"push %%esi; push %%edi; push %%ebp;"
@@ -1551,10 +1548,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		"mov %%r14, %c[r14](%[svm]) \n\t"
 		"mov %%r15, %c[r15](%[svm]) \n\t"
 
-		"pop  %%r15; pop  %%r14; pop  %%r13; pop  %%r12;"
-		"pop  %%r11; pop  %%r10; pop  %%r9;  pop  %%r8;"
-		"pop  %%rbp; pop  %%rdi; pop  %%rsi;"
-		"pop  %%rdx; pop  %%rcx; pop  %%rbx; \n\t"
+		"pop  %%rbp; \n\t"
 #else
 		"mov %%ebx, %c[rbx](%[svm]) \n\t"
 		"mov %%ecx, %c[rcx](%[svm]) \n\t"
@@ -1585,7 +1579,12 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		  [r14]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R14])),
 		  [r15]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R15]))
 #endif
-		: "cc", "memory");
+		: "cc", "memory"
+#ifdef CONFIG_X86_64
+		, "rbx", "rcx", "rdx", "rsi", "rdi"
+		, "r8", "r9", "r10", "r11" , "r12", "r13", "r14", "r15"
+#endif
+		);
 
 	local_irq_disable();
 
-- 
1.5.2.4


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

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

* [PATCH 3/4] Let gcc to choose which registers to save (svm-i386)
       [not found]         ` <1193314735566-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
@ 2007-10-25 12:18           ` Laurent Vivier
       [not found]             ` <1193314735642-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Laurent Vivier @ 2007-10-25 12:18 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f; +Cc: Laurent Vivier

This patch lets GCC to determine which registers to save when we
switch to/from a VCPU in the case of AMD i386

* Original code saves following registers:

    ebx, ecx, edx, esi, edi, ebp

* Patched code:

  - informs GCC that we modify following registers
    using the clobber description:

    ebx, ecx, edx, esi, edi

  - rbp is saved (pop/push) because GCC seems to ignore its use in the clobber
    description.

Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
---
 drivers/kvm/svm.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index c69d6b6..7852d97 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -1485,8 +1485,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 #ifdef CONFIG_X86_64
 		"push %%rbp; \n\t"
 #else
-		"push %%ebx; push %%ecx; push %%edx;"
-		"push %%esi; push %%edi; push %%ebp;"
+		"push %%ebp; \n\t"
 #endif
 
 #ifdef CONFIG_X86_64
@@ -1557,8 +1556,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		"mov %%edi, %c[rdi](%[svm]) \n\t"
 		"mov %%ebp, %c[rbp](%[svm]) \n\t"
 
-		"pop  %%ebp; pop  %%edi; pop  %%esi;"
-		"pop  %%edx; pop  %%ecx; pop  %%ebx; \n\t"
+		"pop  %%ebp; \n\t"
 #endif
 		:
 		: [svm]"a"(svm),
@@ -1583,6 +1581,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 #ifdef CONFIG_X86_64
 		, "rbx", "rcx", "rdx", "rsi", "rdi"
 		, "r8", "r9", "r10", "r11" , "r12", "r13", "r14", "r15"
+#else
+		, "ebx", "ecx", "edx" , "esi", "edi"
 #endif
 		);
 
-- 
1.5.2.4


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

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

* [PATCH 4/4] Let gcc to choose which registers to save (vmx-i386)
       [not found]             ` <1193314735642-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
@ 2007-10-25 12:18               ` Laurent Vivier
       [not found]                 ` <11933147351206-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Laurent Vivier @ 2007-10-25 12:18 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f; +Cc: Laurent Vivier

This patch lets GCC to determine which registers to save when we
switch to/from a VCPU in the case of intel i386.

>>> I don't know if its patch is really usefull as it replaces <<<
>>> a popa/pusha by several pop/push.                          <<<

* Original code saves following registers:
    
    eax, ebx, ecx, edx, edi, esi, ebp (using popa)

* Patched code:

  - informs GCC that we modify following registers
    using the clobber description:

    ebx, edi, rsi

  - doesn't save eax because it is an output operand (vmx->fail)

  - cannot put ecx in clobber description because it is an input operand,
    but as we modify it and we want to keep its value (vcpu), we must
    save it (pop/push)

  - ebp is saved (pop/push) because GCC seems to ignore its use the clobber
    description.

  - edx is saved (pop/push) because it is reserved by GCC (REGPARM) and
    cannot be put in the clobber description.

  - line "mov (%%esp), %3 \n\t" has been removed because %3
    is ecx and ecx is restored just after.
    
Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
---
 drivers/kvm/vmx.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index ec81ebc..890419a 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -2245,7 +2245,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		"push %%rdx; push %%rbp;"
 		"push %%rcx \n\t"
 #else
-		"pusha; push %%ecx \n\t"
+		"push %%edx; push %%ebp;"
+		"push %%ecx \n\t"
 #endif
 		ASM_VMX_VMWRITE_RSP_RDX "\n\t"
 		/* Check if vmlaunch of vmresume is needed */
@@ -2319,9 +2320,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		"mov %%ebp, %c[rbp](%3) \n\t"
 		"mov %%cr2, %%eax  \n\t"
 		"mov %%eax, %c[cr2](%3) \n\t"
-		"mov (%%esp), %3 \n\t"
 
-		"pop %%ecx; popa \n\t"
+		"pop %%ecx; pop %%ebp; pop %%edx \n\t"
 #endif
 		"setbe %0 \n\t"
 	      : "=q" (vmx->fail)
@@ -2349,6 +2349,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 #ifdef CONFIG_X86_64
 		, "rbx", "rdi", "rsi"
 		, "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
+#else
+		, "ebx", "edi", "rsi"
 #endif
 	      );
 
-- 
1.5.2.4


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

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

* Re: [PATCH 0/4] Let gcc to choose which registers to save
       [not found] ` <11933147352304-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
  2007-10-25 12:18   ` [PATCH 1/4] Let gcc to choose which registers to save (vmx-x86_64) Laurent Vivier
@ 2007-10-26 13:49   ` Avi Kivity
  1 sibling, 0 replies; 7+ messages in thread
From: Avi Kivity @ 2007-10-26 13:49 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Laurent Vivier wrote:
> This patch lets GCC to determine which registers to save when we
> switch to/from a VCPU.
>   

Applied all, thanks.  Hopefully all the gccs out there will like it.

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

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

* Re: [PATCH 4/4] Let gcc to choose which registers to save (vmx-i386)
       [not found]                 ` <11933147351206-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
@ 2007-10-26 13:50                   ` Avi Kivity
  0 siblings, 0 replies; 7+ messages in thread
From: Avi Kivity @ 2007-10-26 13:50 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Laurent Vivier wrote:
> This patch lets GCC to determine which registers to save when we
> switch to/from a VCPU in the case of intel i386.
>
>   
>>>> I don't know if its patch is really usefull as it replaces <<<
>>>> a popa/pusha by several pop/push.                          <<<
>>>>         

In general this is useful.  pusha/popa are not heavily used and are thus 
less optimized than push/pop.

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

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

end of thread, other threads:[~2007-10-26 13:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-25 12:18 [PATCH 0/4] Let gcc to choose which registers to save Laurent Vivier
     [not found] ` <11933147352304-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
2007-10-25 12:18   ` [PATCH 1/4] Let gcc to choose which registers to save (vmx-x86_64) Laurent Vivier
     [not found]     ` <11933147352093-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
2007-10-25 12:18       ` [PATCH 2/4] Let gcc to choose which registers to save (svm-x86_64) Laurent Vivier
     [not found]         ` <1193314735566-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
2007-10-25 12:18           ` [PATCH 3/4] Let gcc to choose which registers to save (svm-i386) Laurent Vivier
     [not found]             ` <1193314735642-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
2007-10-25 12:18               ` [PATCH 4/4] Let gcc to choose which registers to save (vmx-i386) Laurent Vivier
     [not found]                 ` <11933147351206-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
2007-10-26 13:50                   ` Avi Kivity
2007-10-26 13:49   ` [PATCH 0/4] Let gcc to choose which registers to save Avi Kivity

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