All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: correctly initialize the CS base on reset
@ 2013-03-19 15:30 Paolo Bonzini
  2013-03-19 15:43 ` Gleb Natapov
  2013-03-20 20:35 ` Marcelo Tosatti
  0 siblings, 2 replies; 5+ messages in thread
From: Paolo Bonzini @ 2013-03-19 15:30 UTC (permalink / raw)
  To: linux-kernel; +Cc: kvm

The CS base was initialized to 0 on VMX (wrong, but usually overridden
by userspace before starting) or 0xf0000 on SVM.  The correct value is
0xffff0000, and VMX is able to emulate it now, so use it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/svm.c | 8 +-------
 arch/x86/kvm/vmx.c | 1 +
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 7219a40..7a46c1f 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1131,17 +1131,11 @@ static void init_vmcb(struct vcpu_svm *svm)
 	init_seg(&save->gs);
 
 	save->cs.selector = 0xf000;
+	save->cs.base = 0xffff0000;
 	/* Executable/Readable Code Segment */
 	save->cs.attrib = SVM_SELECTOR_READ_MASK | SVM_SELECTOR_P_MASK |
 		SVM_SELECTOR_S_MASK | SVM_SELECTOR_CODE_MASK;
 	save->cs.limit = 0xffff;
-	/*
-	 * cs.base should really be 0xffff0000, but vmx can't handle that, so
-	 * be consistent with it.
-	 *
-	 * Replace when we have real mode working for vmx.
-	 */
-	save->cs.base = 0xf0000;
 
 	save->gdtr.limit = 0xffff;
 	save->idtr.limit = 0xffff;
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 4a0bafe..c75c25d 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -4133,6 +4133,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu)
 
 	seg_setup(VCPU_SREG_CS);
 	vmcs_write16(GUEST_CS_SELECTOR, 0xf000);
+	vmcs_write32(GUEST_CS_BASE, 0xffff0000);
 
 	seg_setup(VCPU_SREG_DS);
 	seg_setup(VCPU_SREG_ES);
-- 
1.8.1.4


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

* Re: [PATCH] x86: correctly initialize the CS base on reset
  2013-03-19 15:30 [PATCH] x86: correctly initialize the CS base on reset Paolo Bonzini
@ 2013-03-19 15:43 ` Gleb Natapov
  2013-03-19 16:41   ` Jan Kiszka
  2013-03-20 20:35 ` Marcelo Tosatti
  1 sibling, 1 reply; 5+ messages in thread
From: Gleb Natapov @ 2013-03-19 15:43 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm

On Tue, Mar 19, 2013 at 04:30:26PM +0100, Paolo Bonzini wrote:
> The CS base was initialized to 0 on VMX (wrong, but usually overridden
> by userspace before starting) or 0xf0000 on SVM.  The correct value is
> 0xffff0000, and VMX is able to emulate it now, so use it.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Gleb Natapov <gleb@redhat.com>

> ---
>  arch/x86/kvm/svm.c | 8 +-------
>  arch/x86/kvm/vmx.c | 1 +
>  2 files changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 7219a40..7a46c1f 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -1131,17 +1131,11 @@ static void init_vmcb(struct vcpu_svm *svm)
>  	init_seg(&save->gs);
>  
>  	save->cs.selector = 0xf000;
> +	save->cs.base = 0xffff0000;
>  	/* Executable/Readable Code Segment */
>  	save->cs.attrib = SVM_SELECTOR_READ_MASK | SVM_SELECTOR_P_MASK |
>  		SVM_SELECTOR_S_MASK | SVM_SELECTOR_CODE_MASK;
>  	save->cs.limit = 0xffff;
> -	/*
> -	 * cs.base should really be 0xffff0000, but vmx can't handle that, so
> -	 * be consistent with it.
> -	 *
> -	 * Replace when we have real mode working for vmx.
> -	 */
> -	save->cs.base = 0xf0000;
>  
>  	save->gdtr.limit = 0xffff;
>  	save->idtr.limit = 0xffff;
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 4a0bafe..c75c25d 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -4133,6 +4133,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu)
>  
>  	seg_setup(VCPU_SREG_CS);
>  	vmcs_write16(GUEST_CS_SELECTOR, 0xf000);
> +	vmcs_write32(GUEST_CS_BASE, 0xffff0000);
>  
>  	seg_setup(VCPU_SREG_DS);
>  	seg_setup(VCPU_SREG_ES);
> -- 
> 1.8.1.4
> 
> --
> 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

--
			Gleb.

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

* Re: [PATCH] x86: correctly initialize the CS base on reset
  2013-03-19 15:43 ` Gleb Natapov
@ 2013-03-19 16:41   ` Jan Kiszka
  2013-03-19 17:07     ` Gleb Natapov
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kiszka @ 2013-03-19 16:41 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: Paolo Bonzini, linux-kernel, kvm

On 2013-03-19 16:43, Gleb Natapov wrote:
> On Tue, Mar 19, 2013 at 04:30:26PM +0100, Paolo Bonzini wrote:
>> The CS base was initialized to 0 on VMX (wrong, but usually overridden
>> by userspace before starting) or 0xf0000 on SVM.  The correct value is
>> 0xffff0000, and VMX is able to emulate it now, so use it.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Reviewed-by: Gleb Natapov <gleb@redhat.com>

Just for the history (as I was wondering where this came from): CS base
used to be set to 0xf0000 on VMX as well, but that was changed by
b246dd5d to only affect guests when unrestricted mode is missing. That
change actually left the base uninitialized.

Jan

> 
>> ---
>>  arch/x86/kvm/svm.c | 8 +-------
>>  arch/x86/kvm/vmx.c | 1 +
>>  2 files changed, 2 insertions(+), 7 deletions(-)
>>
>> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
>> index 7219a40..7a46c1f 100644
>> --- a/arch/x86/kvm/svm.c
>> +++ b/arch/x86/kvm/svm.c
>> @@ -1131,17 +1131,11 @@ static void init_vmcb(struct vcpu_svm *svm)
>>  	init_seg(&save->gs);
>>  
>>  	save->cs.selector = 0xf000;
>> +	save->cs.base = 0xffff0000;
>>  	/* Executable/Readable Code Segment */
>>  	save->cs.attrib = SVM_SELECTOR_READ_MASK | SVM_SELECTOR_P_MASK |
>>  		SVM_SELECTOR_S_MASK | SVM_SELECTOR_CODE_MASK;
>>  	save->cs.limit = 0xffff;
>> -	/*
>> -	 * cs.base should really be 0xffff0000, but vmx can't handle that, so
>> -	 * be consistent with it.
>> -	 *
>> -	 * Replace when we have real mode working for vmx.
>> -	 */
>> -	save->cs.base = 0xf0000;
>>  
>>  	save->gdtr.limit = 0xffff;
>>  	save->idtr.limit = 0xffff;
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index 4a0bafe..c75c25d 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -4133,6 +4133,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu)
>>  
>>  	seg_setup(VCPU_SREG_CS);
>>  	vmcs_write16(GUEST_CS_SELECTOR, 0xf000);
>> +	vmcs_write32(GUEST_CS_BASE, 0xffff0000);
>>  
>>  	seg_setup(VCPU_SREG_DS);
>>  	seg_setup(VCPU_SREG_ES);
>> -- 
>> 1.8.1.4
>>
>> --
>> 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
> 
> --
> 			Gleb.
> 
-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux


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

* Re: [PATCH] x86: correctly initialize the CS base on reset
  2013-03-19 16:41   ` Jan Kiszka
@ 2013-03-19 17:07     ` Gleb Natapov
  0 siblings, 0 replies; 5+ messages in thread
From: Gleb Natapov @ 2013-03-19 17:07 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: Paolo Bonzini, linux-kernel, kvm

On Tue, Mar 19, 2013 at 05:41:45PM +0100, Jan Kiszka wrote:
> On 2013-03-19 16:43, Gleb Natapov wrote:
> > On Tue, Mar 19, 2013 at 04:30:26PM +0100, Paolo Bonzini wrote:
> >> The CS base was initialized to 0 on VMX (wrong, but usually overridden
> >> by userspace before starting) or 0xf0000 on SVM.  The correct value is
> >> 0xffff0000, and VMX is able to emulate it now, so use it.
> >>
> >> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > Reviewed-by: Gleb Natapov <gleb@redhat.com>
> 
> Just for the history (as I was wondering where this came from): CS base
> used to be set to 0xf0000 on VMX as well, but that was changed by
> b246dd5d to only affect guests when unrestricted mode is missing. That
> change actually left the base uninitialized.
> 
Looking at the code before b246dd5d it sets CS base to 0xf0000 only if it was
0xffff0000. This is the same as with current code: fix_rmode_seg() does
it.

--
			Gleb.

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

* Re: [PATCH] x86: correctly initialize the CS base on reset
  2013-03-19 15:30 [PATCH] x86: correctly initialize the CS base on reset Paolo Bonzini
  2013-03-19 15:43 ` Gleb Natapov
@ 2013-03-20 20:35 ` Marcelo Tosatti
  1 sibling, 0 replies; 5+ messages in thread
From: Marcelo Tosatti @ 2013-03-20 20:35 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm

On Tue, Mar 19, 2013 at 04:30:26PM +0100, Paolo Bonzini wrote:
> The CS base was initialized to 0 on VMX (wrong, but usually overridden
> by userspace before starting) or 0xf0000 on SVM.  The correct value is
> 0xffff0000, and VMX is able to emulate it now, so use it.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/svm.c | 8 +-------
>  arch/x86/kvm/vmx.c | 1 +
>  2 files changed, 2 insertions(+), 7 deletions(-)

Applied, thanks.


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

end of thread, other threads:[~2013-03-20 23:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-19 15:30 [PATCH] x86: correctly initialize the CS base on reset Paolo Bonzini
2013-03-19 15:43 ` Gleb Natapov
2013-03-19 16:41   ` Jan Kiszka
2013-03-19 17:07     ` Gleb Natapov
2013-03-20 20:35 ` Marcelo Tosatti

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.