diff mbox

[05/47] KVM: VMX: Optimize vmx_get_cpl()

Message ID 4A95437C.2060707@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roel Kluin Aug. 26, 2009, 2:15 p.m. UTC
Op 26-08-09 12:29, Avi Kivity schreef:
> Instead of calling vmx_get_segment() (which reads a whole bunch of
> vmcs fields), read only the cs selector which contains the cpl.
> 
> Signed-off-by: Avi Kivity <avi@redhat.com>

Can't we also optimise cs_ss_rpl_check()? (Please review, untested.)

------------- >8 ---------------------- 8< --------------------
Instead of calling vmx_get_segment() (which reads a whole bunch of
vmcs fields), read only the cs/ss selectors which contains the rpls.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Avi Kivity Aug. 26, 2009, 2:33 p.m. UTC | #1
On 08/26/2009 05:15 PM, Roel Kluin wrote:
> Op 26-08-09 12:29, Avi Kivity schreef:
>    
>> Instead of calling vmx_get_segment() (which reads a whole bunch of
>> vmcs fields), read only the cs selector which contains the cpl.
>>
>> Signed-off-by: Avi Kivity<avi@redhat.com>
>>      
> Can't we also optimise cs_ss_rpl_check()? (Please review, untested.)
>
> ------------->8 ---------------------- 8<  --------------------
> Instead of calling vmx_get_segment() (which reads a whole bunch of
> vmcs fields), read only the cs/ss selectors which contains the rpls.
>
>    

It's really a slowpath, so I prefer not to touch it.  We're likely to 
start caching guest segment fields soon, so the less code that reads 
them directly, the better.

> Signed-off-by: Roel Kluin<roel.kluin@gmail.com>
> ---
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 29f9129..5d8512a 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -1932,13 +1932,8 @@ static bool ldtr_valid(struct kvm_vcpu *vcpu)
>
>   static bool cs_ss_rpl_check(struct kvm_vcpu *vcpu)
>   {
> -	struct kvm_segment cs, ss;
> -
> -	vmx_get_segment(vcpu,&cs, VCPU_SREG_CS);
> -	vmx_get_segment(vcpu,&ss, VCPU_SREG_SS);
> -
> -	return ((cs.selector&  SELECTOR_RPL_MASK) ==
> -		 (ss.selector&  SELECTOR_RPL_MASK));
> +	return ((vmcs_read16(GUEST_CS_SELECTOR)&  SELECTOR_RPL_MASK) ==
> +		 (vmcs_read16(GUEST_SS_SELECTOR)&  SELECTOR_RPL_MASK));
>   }
>
>   /*
>
diff mbox

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 29f9129..5d8512a 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1932,13 +1932,8 @@  static bool ldtr_valid(struct kvm_vcpu *vcpu)
 
 static bool cs_ss_rpl_check(struct kvm_vcpu *vcpu)
 {
-	struct kvm_segment cs, ss;
-
-	vmx_get_segment(vcpu, &cs, VCPU_SREG_CS);
-	vmx_get_segment(vcpu, &ss, VCPU_SREG_SS);
-
-	return ((cs.selector & SELECTOR_RPL_MASK) ==
-		 (ss.selector & SELECTOR_RPL_MASK));
+	return ((vmcs_read16(GUEST_CS_SELECTOR) & SELECTOR_RPL_MASK) ==
+		 (vmcs_read16(GUEST_SS_SELECTOR) & SELECTOR_RPL_MASK));
 }
 
 /*