Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-31 Thread Gleb Natapov
On Mon, Jan 30, 2012 at 04:26:06PM +0100, Kevin Wolf wrote: Would that be enough or would we have to avoid clearing it in all other places as well? Where would it be initialised if it's not enough? Maybe vmx_vcpu_reset(). Do all CPL changes go through set_cr0/segment/rflags/cpl? I

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-31 Thread Avi Kivity
On 01/31/2012 11:37 AM, Gleb Natapov wrote: On Mon, Jan 30, 2012 at 04:26:06PM +0100, Kevin Wolf wrote: Would that be enough or would we have to avoid clearing it in all other places as well? Where would it be initialised if it's not enough? Maybe vmx_vcpu_reset(). Do all CPL

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Avi Kivity
On 01/27/2012 09:23 PM, Kevin Wolf wrote: Task switches can switch between Protected Mode and VM86. The current mode must be updated during the task switch emulation so that the new segment selectors are interpreted correctly and privilege checks succeed. VMX code calculates the CPL from the

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Gleb Natapov
On Mon, Jan 30, 2012 at 12:24:11PM +0200, Avi Kivity wrote: + ctxt-ops-set_segment(ctxt, selector, desc, base3, seg); } @@ -2273,6 +2281,24 @@ static int load_state_from_tss32(struct x86_emulate_ctxt *ctxt, return emulate_gp(ctxt, 0); ctxt-_eip = tss-eip;

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Kevin Wolf
Am 30.01.2012 11:24, schrieb Avi Kivity: On 01/27/2012 09:23 PM, Kevin Wolf wrote: Task switches can switch between Protected Mode and VM86. The current mode must be updated during the task switch emulation so that the new segment selectors are interpreted correctly and privilege checks

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Gleb Natapov
On Mon, Jan 30, 2012 at 12:05:37PM +0100, Kevin Wolf wrote: + + /* + * If we're switching between Protected Mode and VM86, we need to make + * sure to update the mode before loading the segment descriptors so + * that the selectors are interpreted correctly. + * + * Need

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Avi Kivity
On 01/30/2012 12:56 PM, Gleb Natapov wrote: On Mon, Jan 30, 2012 at 12:24:11PM +0200, Avi Kivity wrote: + ctxt-ops-set_segment(ctxt, selector, desc, base3, seg); } @@ -2273,6 +2281,24 @@ static int load_state_from_tss32(struct x86_emulate_ctxt *ctxt, return

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Gleb Natapov
On Mon, Jan 30, 2012 at 02:02:14PM +0200, Avi Kivity wrote: On 01/30/2012 12:56 PM, Gleb Natapov wrote: On Mon, Jan 30, 2012 at 12:24:11PM +0200, Avi Kivity wrote: + ctxt-ops-set_segment(ctxt, selector, desc, base3, seg); } @@ -2273,6 +2281,24 @@ static int

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Avi Kivity
On 01/30/2012 01:05 PM, Kevin Wolf wrote: Am 30.01.2012 11:24, schrieb Avi Kivity: On 01/27/2012 09:23 PM, Kevin Wolf wrote: Task switches can switch between Protected Mode and VM86. The current mode must be updated during the task switch emulation so that the new segment selectors are

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Avi Kivity
On 01/30/2012 02:04 PM, Gleb Natapov wrote: On Mon, Jan 30, 2012 at 02:02:14PM +0200, Avi Kivity wrote: On 01/30/2012 12:56 PM, Gleb Natapov wrote: On Mon, Jan 30, 2012 at 12:24:11PM +0200, Avi Kivity wrote: + ctxt-ops-set_segment(ctxt, selector, desc, base3, seg); }

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Kevin Wolf
Am 30.01.2012 14:23, schrieb Avi Kivity: On 01/30/2012 01:05 PM, Kevin Wolf wrote: Am 30.01.2012 11:24, schrieb Avi Kivity: On 01/27/2012 09:23 PM, Kevin Wolf wrote: Task switches can switch between Protected Mode and VM86. The current mode must be updated during the task switch emulation so

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Avi Kivity
On 01/30/2012 04:01 PM, Kevin Wolf wrote: Am 30.01.2012 14:23, schrieb Avi Kivity: On 01/30/2012 01:05 PM, Kevin Wolf wrote: Am 30.01.2012 11:24, schrieb Avi Kivity: On 01/27/2012 09:23 PM, Kevin Wolf wrote: Task switches can switch between Protected Mode and VM86. The current mode must

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Kevin Wolf
Am 30.01.2012 15:32, schrieb Avi Kivity: On 01/30/2012 04:01 PM, Kevin Wolf wrote: Am 30.01.2012 14:23, schrieb Avi Kivity: On 01/30/2012 01:05 PM, Kevin Wolf wrote: Am 30.01.2012 11:24, schrieb Avi Kivity: On 01/27/2012 09:23 PM, Kevin Wolf wrote: Task switches can switch between Protected

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Avi Kivity
On 01/30/2012 05:26 PM, Kevin Wolf wrote: My bet is that it will be 3 if eflags.vm=1 and unchanged otherwise -- the cpl update happens when the segment cache is updated. But that's just a guess. Does even anyone see the new CPL in error cases? An exception is thrown immediately, so cs

Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-30 Thread Takuya Yoshikawa
On Mon, 30 Jan 2012 16:26:06 +0100 Kevin Wolf kw...@redhat.com wrote: The other case is what we're looking at, task switch. To actually update cpl, set_segment() needs to look at cr0.pe and eflags, but these might not have been committed yet. It's all solvable but the solution involves

[PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch

2012-01-27 Thread Kevin Wolf
Task switches can switch between Protected Mode and VM86. The current mode must be updated during the task switch emulation so that the new segment selectors are interpreted correctly and privilege checks succeed. VMX code calculates the CPL from the code segment selector and rflags, so it needs