All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] KVM: SVM: ignore type when setting segment registers
@ 2017-05-29 13:24 Gioh Kim
  2017-05-30 12:54 ` Radim Krčmář
  0 siblings, 1 reply; 5+ messages in thread
From: Gioh Kim @ 2017-05-29 13:24 UTC (permalink / raw)
  To: andre.przywara, kvm; +Cc: linux-kernel, Gioh Kim

Current code sets unusable as 1 if present is 1 and type is 0.
In Long mode, type value in segment descriptor is ignored.
So I think type should be ignored when setting the segment registers,
if type means the descriptor type in the segment descriptor.

Is the type field of struct kvm_segment the descriptor type?
If so, why type is checked when setting segment registers?

If the type field is not the descriptor type,
is it ok to set unusable when present is 1?

I'm copying a code as following to show what code I'm asking.

----------------------------- 8< ---------------------------------
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 5f48f62..0133f6f 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1803,7 +1803,7 @@ static void svm_get_segment(struct kvm_vcpu *vcpu,
 	 * AMD's VMCB does not have an explicit unusable field, so emulate it
 	 * for cross vendor migration purposes by "not present"
 	 */
-	var->unusable = !var->present || (var->type == 0);
+	var->unusable = !var->present;
 
 	switch (seg) {
 	case VCPU_SREG_TR:
-- 
2.5.0

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

* Re: [RFC] KVM: SVM: ignore type when setting segment registers
  2017-05-29 13:24 [RFC] KVM: SVM: ignore type when setting segment registers Gioh Kim
@ 2017-05-30 12:54 ` Radim Krčmář
  2017-05-30 13:37   ` Gioh Kim
  2017-05-30 18:03   ` Matt Mullins
  0 siblings, 2 replies; 5+ messages in thread
From: Radim Krčmář @ 2017-05-30 12:54 UTC (permalink / raw)
  To: Gioh Kim; +Cc: andre.przywara, kvm, linux-kernel

2017-05-29 15:24+0200, Gioh Kim:
> Current code sets unusable as 1 if present is 1 and type is 0.
> In Long mode, type value in segment descriptor is ignored.
> So I think type should be ignored when setting the segment registers,
> if type means the descriptor type in the segment descriptor.
> 
> Is the type field of struct kvm_segment the descriptor type?

Yes.

> If so, why type is checked when setting segment registers?

No idea.  19bca6ab75d8 ("KVM: SVM: Fix cross vendor migration issue with
unusable bit") also moved the assigment up to initialize it before use
and I think that is enough.

> If the type field is not the descriptor type,
> is it ok to set unusable when present is 1?

Looks like a bug.  type = 0 can be a usable read-only data segment.

> I'm copying a code as following to show what code I'm asking.

Please send it as a patch,

thanks.

> ----------------------------- 8< ---------------------------------
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 5f48f62..0133f6f 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -1803,7 +1803,7 @@ static void svm_get_segment(struct kvm_vcpu *vcpu,
>  	 * AMD's VMCB does not have an explicit unusable field, so emulate it
>  	 * for cross vendor migration purposes by "not present"
>  	 */
> -	var->unusable = !var->present || (var->type == 0);
> +	var->unusable = !var->present;
>  
>  	switch (seg) {
>  	case VCPU_SREG_TR:
> -- 
> 2.5.0
> 

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

* Re: [RFC] KVM: SVM: ignore type when setting segment registers
  2017-05-30 12:54 ` Radim Krčmář
@ 2017-05-30 13:37   ` Gioh Kim
  2017-05-30 18:03   ` Matt Mullins
  1 sibling, 0 replies; 5+ messages in thread
From: Gioh Kim @ 2017-05-30 13:37 UTC (permalink / raw)
  To: Radim Krčmář; +Cc: andre.przywara, kvm, linux-kernel

On Tue, May 30, 2017 at 02:54:21PM +0200, Radim Krčmář wrote:
> 2017-05-29 15:24+0200, Gioh Kim:
> > Current code sets unusable as 1 if present is 1 and type is 0.
> > In Long mode, type value in segment descriptor is ignored.
> > So I think type should be ignored when setting the segment registers,
> > if type means the descriptor type in the segment descriptor.
> > 
> > Is the type field of struct kvm_segment the descriptor type?
> 
> Yes.
> 
> > If so, why type is checked when setting segment registers?
> 
> No idea.  19bca6ab75d8 ("KVM: SVM: Fix cross vendor migration issue with
> unusable bit") also moved the assigment up to initialize it before use
> and I think that is enough.
> 
> > If the type field is not the descriptor type,
> > is it ok to set unusable when present is 1?
> 
> Looks like a bug.  type = 0 can be a usable read-only data segment.
> 
> > I'm copying a code as following to show what code I'm asking.
> 
> Please send it as a patch,

Hi Radim,

Thank you for reply.
I sent a patch: https://lkml.org/lkml/2017/5/30/459
I'd appreciate if if you could review it.

-- 
Best regards,
Gi-Oh Kim
TEL: 0176 2697 8962

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

* Re: [RFC] KVM: SVM: ignore type when setting segment registers
  2017-05-30 12:54 ` Radim Krčmář
  2017-05-30 13:37   ` Gioh Kim
@ 2017-05-30 18:03   ` Matt Mullins
  2017-05-31  6:42     ` Gi-Oh Kim
  1 sibling, 1 reply; 5+ messages in thread
From: Matt Mullins @ 2017-05-30 18:03 UTC (permalink / raw)
  To: Radim Krčmář, Gioh Kim; +Cc: andre.przywara, kvm, linux-kernel

On Tue, May 30, 2017 at 02:54:21PM +0200, Radim Krčmář wrote:
> 2017-05-29 15:24+0200, Gioh Kim:
> > If so, why type is checked when setting segment registers?
> 
> No idea.  19bca6ab75d8 ("KVM: SVM: Fix cross vendor migration issue with
> unusable bit") also moved the assigment up to initialize it before use
> and I think that is enough.

Was this perhaps intended to instead check for a zero selector, which is also
an unusable segment?

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

* Re: [RFC] KVM: SVM: ignore type when setting segment registers
  2017-05-30 18:03   ` Matt Mullins
@ 2017-05-31  6:42     ` Gi-Oh Kim
  0 siblings, 0 replies; 5+ messages in thread
From: Gi-Oh Kim @ 2017-05-31  6:42 UTC (permalink / raw)
  To: Radim Krčmář, Gioh Kim, andre.przywara, kvm, linux-kernel

On Tue, May 30, 2017 at 8:03 PM, Matt Mullins <mmullins@mmlx.us> wrote:
> On Tue, May 30, 2017 at 02:54:21PM +0200, Radim Krčmář wrote:
>> 2017-05-29 15:24+0200, Gioh Kim:
>> > If so, why type is checked when setting segment registers?
>>
>> No idea.  19bca6ab75d8 ("KVM: SVM: Fix cross vendor migration issue with
>> unusable bit") also moved the assigment up to initialize it before use
>> and I think that is enough.
>
> Was this perhaps intended to instead check for a zero selector, which is also
> an unusable segment?

I think that is what present value is for.


-- 
Best regards,
Gi-Oh Kim
TEL: 0176 2697 8962

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

end of thread, other threads:[~2017-05-31  6:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-29 13:24 [RFC] KVM: SVM: ignore type when setting segment registers Gioh Kim
2017-05-30 12:54 ` Radim Krčmář
2017-05-30 13:37   ` Gioh Kim
2017-05-30 18:03   ` Matt Mullins
2017-05-31  6:42     ` Gi-Oh Kim

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.