2007-06-06 19:28:37

by Jeff Dike

[permalink] [raw]
Subject: [PATCH] KVM - Fix rmode_tss_base declaration

The long return value of rmode_tss_base is truncated by its declared
return type of int.

Signed-off-by: Jeff Dike <[email protected]>
--
drivers/kvm/vmx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Index: kvm/drivers/kvm/vmx.c
===================================================================
--- kvm.orig/drivers/kvm/vmx.c
+++ kvm/drivers/kvm/vmx.c
@@ -884,7 +884,7 @@ static void enter_pmode(struct kvm_vcpu
vmcs_write32(GUEST_CS_AR_BYTES, 0x9b);
}

-static int rmode_tss_base(struct kvm* kvm)
+static unsigned long rmode_tss_base(struct kvm* kvm)
{
gfn_t base_gfn = kvm->memslots[0].base_gfn + kvm->memslots[0].npages - 3;
return base_gfn << PAGE_SHIFT;


2007-06-07 02:14:19

by Li, Xin B

[permalink] [raw]
Subject: RE: [kvm-devel] [PATCH] KVM - Fix rmode_tss_base declaration

>
>The long return value of rmode_tss_base is truncated by its declared
>return type of int.
>
>Signed-off-by: Jeff Dike <[email protected]>
>--
> drivers/kvm/vmx.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>Index: kvm/drivers/kvm/vmx.c
>===================================================================
>--- kvm.orig/drivers/kvm/vmx.c
>+++ kvm/drivers/kvm/vmx.c
>@@ -884,7 +884,7 @@ static void enter_pmode(struct kvm_vcpu
> vmcs_write32(GUEST_CS_AR_BYTES, 0x9b);
> }
>
>-static int rmode_tss_base(struct kvm* kvm)
>+static unsigned long rmode_tss_base(struct kvm* kvm)

Should use gpa_t instead.
-Xin

2007-06-07 03:20:13

by Jeff Dike

[permalink] [raw]
Subject: Re: [kvm-devel] [PATCH] KVM - Fix rmode_tss_base declaration

On Thu, Jun 07, 2007 at 10:13:42AM +0800, Li, Xin B wrote:
> >-static int rmode_tss_base(struct kvm* kvm)
> >+static unsigned long rmode_tss_base(struct kvm* kvm)
>
> Should use gpa_t instead.

Right you are, I didn't notice that type.

Will fix.

Jeff

--
Work email - jdike at linux dot intel dot com

2007-06-07 05:10:00

by Avi Kivity

[permalink] [raw]
Subject: Re: [kvm-devel] [PATCH] KVM - Fix rmode_tss_base declaration

Jeff Dike wrote:
> On Thu, Jun 07, 2007 at 10:13:42AM +0800, Li, Xin B wrote:
>
>>> -static int rmode_tss_base(struct kvm* kvm)
>>> +static unsigned long rmode_tss_base(struct kvm* kvm)
>>>
>> Should use gpa_t instead.
>>
>
> Right you are, I didn't notice that type.
>
>

Some extra logic is needed on i386 with >= 4GB. Current code will
wraparound since gfn_t is 32-bits long, but casting it to 64-bits is not
the answer since the processor will truncate it back to 32 bits (the
return value is eventually used as a long in enter_rmode()).


--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.

2007-06-08 19:45:55

by Jeff Dike

[permalink] [raw]
Subject: Re: [kvm-devel] [PATCH] KVM - Fix rmode_tss_base declaration

On Thu, Jun 07, 2007 at 08:09:48AM +0300, Avi Kivity wrote:
> Some extra logic is needed on i386 with >= 4GB. Current code will
> wraparound since gfn_t is 32-bits long, but casting it to 64-bits is not
> the answer since the processor will truncate it back to 32 bits (the
> return value is eventually used as a long in enter_rmode()).

Is it necessary to initialize TR in enter_rmode? I can't see anything
that says it has any meaning in real mode.

And if not, would not the guest be responsible for finding room for the
TSS?

Jeff

--
Work email - jdike at linux dot intel dot com

2007-06-10 07:36:27

by Avi Kivity

[permalink] [raw]
Subject: Re: [kvm-devel] [PATCH] KVM - Fix rmode_tss_base declaration

Jeff Dike wrote:
> On Thu, Jun 07, 2007 at 08:09:48AM +0300, Avi Kivity wrote:
>
>> Some extra logic is needed on i386 with >= 4GB. Current code will
>> wraparound since gfn_t is 32-bits long, but casting it to 64-bits is not
>> the answer since the processor will truncate it back to 32 bits (the
>> return value is eventually used as a long in enter_rmode()).
>>
>
> Is it necessary to initialize TR in enter_rmode? I can't see anything
> that says it has any meaning in real mode.
>
>

VT doesn't support real mode. kvm uses virtual-8086 mode to virtualize
real mode. Virtual 8086 mode does require a task state segment.

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