* [PATCH RESEND] KVM: when entering real mode align segment base to 16 bytes
@ 2010-12-27 13:01 Gleb Natapov
2010-12-27 14:21 ` Avi Kivity
0 siblings, 1 reply; 6+ messages in thread
From: Gleb Natapov @ 2010-12-27 13:01 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm
VMX checks that base is equal segment shifted 4 bites left. Otherwise
guest entry fails.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
--
Same as previous one but with correct (I hope) To: header.
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 2260783..45014ba 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1736,7 +1736,7 @@ static void fix_rmode_seg(int seg, struct kvm_save_segment *save)
save->limit = vmcs_read32(sf->limit);
save->ar = vmcs_read32(sf->ar_bytes);
vmcs_write16(sf->selector, save->base >> 4);
- vmcs_write32(sf->base, save->base & 0xfffff);
+ vmcs_write32(sf->base, save->base & 0xffff0);
vmcs_write32(sf->limit, 0xffff);
vmcs_write32(sf->ar_bytes, 0xf3);
}
--
Gleb.
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH RESEND] KVM: when entering real mode align segment base to 16 bytes
2010-12-27 13:01 [PATCH RESEND] KVM: when entering real mode align segment base to 16 bytes Gleb Natapov
@ 2010-12-27 14:21 ` Avi Kivity
2010-12-27 14:37 ` Gleb Natapov
0 siblings, 1 reply; 6+ messages in thread
From: Avi Kivity @ 2010-12-27 14:21 UTC (permalink / raw)
To: Gleb Natapov; +Cc: mtosatti, kvm
On 12/27/2010 03:01 PM, Gleb Natapov wrote:
> VMX checks that base is equal segment shifted 4 bites left. Otherwise
> guest entry fails.
>
> Signed-off-by: Gleb Natapov<gleb@redhat.com>
> --
> Same as previous one but with correct (I hope) To: header.
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 2260783..45014ba 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -1736,7 +1736,7 @@ static void fix_rmode_seg(int seg, struct kvm_save_segment *save)
> save->limit = vmcs_read32(sf->limit);
> save->ar = vmcs_read32(sf->ar_bytes);
> vmcs_write16(sf->selector, save->base>> 4);
> - vmcs_write32(sf->base, save->base& 0xfffff);
> + vmcs_write32(sf->base, save->base& 0xffff0);
> vmcs_write32(sf->limit, 0xffff);
> vmcs_write32(sf->ar_bytes, 0xf3);
> }
This looks okay, but I'm curious what happened here. If the guest will
use the segment it will fail on an incorrect address.
What's the scenario here? And what segment is involved? if it's fs or
gs, or maybe ss, I can see it working out, but hardly otherwise.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RESEND] KVM: when entering real mode align segment base to 16 bytes
2010-12-27 14:21 ` Avi Kivity
@ 2010-12-27 14:37 ` Gleb Natapov
2010-12-27 14:55 ` Avi Kivity
0 siblings, 1 reply; 6+ messages in thread
From: Gleb Natapov @ 2010-12-27 14:37 UTC (permalink / raw)
To: Avi Kivity; +Cc: mtosatti, kvm
On Mon, Dec 27, 2010 at 04:21:53PM +0200, Avi Kivity wrote:
> On 12/27/2010 03:01 PM, Gleb Natapov wrote:
> >VMX checks that base is equal segment shifted 4 bites left. Otherwise
> >guest entry fails.
> >
> >Signed-off-by: Gleb Natapov<gleb@redhat.com>
> >--
> >Same as previous one but with correct (I hope) To: header.
> >
> >diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> >index 2260783..45014ba 100644
> >--- a/arch/x86/kvm/vmx.c
> >+++ b/arch/x86/kvm/vmx.c
> >@@ -1736,7 +1736,7 @@ static void fix_rmode_seg(int seg, struct kvm_save_segment *save)
> > save->limit = vmcs_read32(sf->limit);
> > save->ar = vmcs_read32(sf->ar_bytes);
> > vmcs_write16(sf->selector, save->base>> 4);
> >- vmcs_write32(sf->base, save->base& 0xfffff);
> >+ vmcs_write32(sf->base, save->base& 0xffff0);
> > vmcs_write32(sf->limit, 0xffff);
> > vmcs_write32(sf->ar_bytes, 0xf3);
> > }
>
> This looks okay, but I'm curious what happened here. If the guest
> will use the segment it will fail on an incorrect address.
>
Not much we can do about it. Either do what patch does, or exit to
userspace with more meaningful message then:
kvm: unhandled exit 80000021
kvm_run returned -22
> What's the scenario here? And what segment is involved? if it's fs
> or gs, or maybe ss, I can see it working out, but hardly otherwise.
>
The scenario is older Seabios that lefts DS segment unaligned during
switch to real mode in int1587 function (copy extended memory).
--
Gleb.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RESEND] KVM: when entering real mode align segment base to 16 bytes
2010-12-27 14:37 ` Gleb Natapov
@ 2010-12-27 14:55 ` Avi Kivity
2010-12-27 14:58 ` Gleb Natapov
0 siblings, 1 reply; 6+ messages in thread
From: Avi Kivity @ 2010-12-27 14:55 UTC (permalink / raw)
To: Gleb Natapov; +Cc: mtosatti, kvm
On 12/27/2010 04:37 PM, Gleb Natapov wrote:
> > What's the scenario here? And what segment is involved? if it's fs
> > or gs, or maybe ss, I can see it working out, but hardly otherwise.
> >
> The scenario is older Seabios that lefts DS segment unaligned during
> switch to real mode in int1587 function (copy extended memory).
>
Did it not use %ds then?
What about switching back to protected mode? I see we do restore the
base, so it can continue to use the segment. I guess this isn't an
issue for 1587.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RESEND] KVM: when entering real mode align segment base to 16 bytes
2010-12-27 14:55 ` Avi Kivity
@ 2010-12-27 14:58 ` Gleb Natapov
2010-12-27 15:15 ` Avi Kivity
0 siblings, 1 reply; 6+ messages in thread
From: Gleb Natapov @ 2010-12-27 14:58 UTC (permalink / raw)
To: Avi Kivity; +Cc: mtosatti, kvm
On Mon, Dec 27, 2010 at 04:55:08PM +0200, Avi Kivity wrote:
> On 12/27/2010 04:37 PM, Gleb Natapov wrote:
> >> What's the scenario here? And what segment is involved? if it's fs
> >> or gs, or maybe ss, I can see it working out, but hardly otherwise.
> >>
> >The scenario is older Seabios that lefts DS segment unaligned during
> >switch to real mode in int1587 function (copy extended memory).
> >
>
> Did it not use %ds then?
>
It restores %ds before first use. There can be other guests of course
that try to use %ds in protected mode. We can distinguish one from the
other.
> What about switching back to protected mode? I see we do restore the
> base, so it can continue to use the segment. I guess this isn't an
> issue for 1587.
>
Correct. 1587 does not return to protected mode again.
--
Gleb.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RESEND] KVM: when entering real mode align segment base to 16 bytes
2010-12-27 14:58 ` Gleb Natapov
@ 2010-12-27 15:15 ` Avi Kivity
0 siblings, 0 replies; 6+ messages in thread
From: Avi Kivity @ 2010-12-27 15:15 UTC (permalink / raw)
To: Gleb Natapov; +Cc: mtosatti, kvm
On 12/27/2010 04:58 PM, Gleb Natapov wrote:
> On Mon, Dec 27, 2010 at 04:55:08PM +0200, Avi Kivity wrote:
> > On 12/27/2010 04:37 PM, Gleb Natapov wrote:
> > >> What's the scenario here? And what segment is involved? if it's fs
> > >> or gs, or maybe ss, I can see it working out, but hardly otherwise.
> > >>
> > >The scenario is older Seabios that lefts DS segment unaligned during
> > >switch to real mode in int1587 function (copy extended memory).
> > >
> >
> > Did it not use %ds then?
> >
> It restores %ds before first use. There can be other guests of course
> that try to use %ds in protected mode. We can distinguish one from the
> other.
Okay. Please add a printk_once() if we lose some bits here, so we know
something bad happened.
In theory we should do this for the other cases too, but they have been
there long enough.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-12-27 15:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-27 13:01 [PATCH RESEND] KVM: when entering real mode align segment base to 16 bytes Gleb Natapov
2010-12-27 14:21 ` Avi Kivity
2010-12-27 14:37 ` Gleb Natapov
2010-12-27 14:55 ` Avi Kivity
2010-12-27 14:58 ` Gleb Natapov
2010-12-27 15:15 ` Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox