From: "Jan Beulich" Subject: [PATCH] x86: further adjustments to arch_set_info_guest() after c/s 23142:f5e8d152a565 Date: Tue, 17 May 2011 10:26:37 +0100 Message-ID: <4DD25B6D0200007800041944@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part95B9075D.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" Cc: Shriram Rajagopalan List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part95B9075D.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The adjustments to v->arch.user_regs.eflags and the initialization of the int80 direct trap must be done earlier (namely before the function may bail because of inconsistencies between input and stored state on an already initialised vCPU) so that stored state is consistent, and for arch_get_info_guest() to not have its eflags related BUG_ON() triggered. Further, v->arch.pv_vcpu.ctrlreg[] indices 3 and 1 aren't being kept up to date while the domain is running, so consistency checks must instead be done against v->arch.guest_table{,_user}. Additionally, for 64-bit pv domains, CR1 must also be checked to be consistent with the kernel mode setting for the vCPU, and the whole CR1 checking should not be done for 32-bit pv domains. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -843,6 +843,15 @@ int arch_set_info_guest( goto out; } =20 + init_int80_direct_trap(v); + + /* IOPL privileges are virtualised. */ + v->arch.pv_vcpu.iopl =3D (v->arch.user_regs.eflags >> 12) & 3; + v->arch.user_regs.eflags &=3D ~X86_EFLAGS_IOPL; + + /* Ensure real hardware interrupts are enabled. */ + v->arch.user_regs.eflags |=3D X86_EFLAGS_IF; + if ( !v->is_initialised ) { v->arch.pv_vcpu.ldt_base =3D c(ldt_base); @@ -850,11 +859,27 @@ int arch_set_info_guest( } else { - bool_t fail =3D v->arch.pv_vcpu.ctrlreg[3] !=3D c(ctrlreg[3]); + unsigned long pfn =3D pagetable_get_pfn(v->arch.guest_table); + bool_t fail; =20 + if ( !compat ) + { + fail =3D xen_pfn_to_cr3(pfn) !=3D c.nat->ctrlreg[3]; #ifdef CONFIG_X86_64 - fail |=3D v->arch.pv_vcpu.ctrlreg[1] !=3D c(ctrlreg[1]); + if ( pagetable_is_null(v->arch.guest_table_user) ) + fail |=3D c.nat->ctrlreg[1] || !(flags & VGCF_in_kernel); + else + { + pfn =3D pagetable_get_pfn(v->arch.guest_table_user); + fail |=3D xen_pfn_to_cr3(pfn) !=3D c.nat->ctrlreg[1]; + } + } else { + l4_pgentry_t *l4tab =3D __va(pfn_to_paddr(pfn)); + + pfn =3D l4e_get_pfn(*l4tab); + fail =3D compat_pfn_to_cr3(pfn) !=3D c.cmp->ctrlreg[3]; #endif + } =20 for ( i =3D 0; i < ARRAY_SIZE(v->arch.pv_vcpu.gdt_frames); ++i ) fail |=3D v->arch.pv_vcpu.gdt_frames[i] !=3D c(gdt_frames[i]);= @@ -894,15 +919,6 @@ int arch_set_info_guest( v->arch.pv_vcpu.ctrlreg[0] &=3D X86_CR0_TS; v->arch.pv_vcpu.ctrlreg[0] |=3D read_cr0() & ~X86_CR0_TS; =20 - init_int80_direct_trap(v); - - /* IOPL privileges are virtualised. */ - v->arch.pv_vcpu.iopl =3D (v->arch.user_regs.eflags >> 12) & 3; - v->arch.user_regs.eflags &=3D ~X86_EFLAGS_IOPL; - - /* Ensure real hardware interrupts are enabled. */ - v->arch.user_regs.eflags |=3D X86_EFLAGS_IF; - cr4 =3D v->arch.pv_vcpu.ctrlreg[4]; v->arch.pv_vcpu.ctrlreg[4] =3D cr4 ? pv_guest_cr4_fixup(v, cr4) : real_cr4_to_pv_guest_cr4(mmu_cr4_features); --=__Part95B9075D.1__= Content-Type: text/plain; name="x86-set-info-guest-fix-23142.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-set-info-guest-fix-23142.patch" The adjustments to v->arch.user_regs.eflags and the initialization = of=0Athe int80 direct trap must be done earlier (namely before the = function=0Amay bail because of inconsistencies between input and stored = state on=0Aan already initialised vCPU) so that stored state is consistent,= and=0Afor arch_get_info_guest() to not have its eflags related BUG_ON()=0A= triggered.=0A=0AFurther, v->arch.pv_vcpu.ctrlreg[] indices 3 and 1 aren't = being kept=0Aup to date while the domain is running, so consistency checks = must=0Ainstead be done against v->arch.guest_table{,_user}.=0A=0AAdditional= ly, for 64-bit pv domains, CR1 must also be checked to be=0Aconsistent = with the kernel mode setting for the vCPU, and the whole=0ACR1 checking = should not be done for 32-bit pv domains.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/domain.c=0A+++ b/xen/arch/x86= /domain.c=0A@@ -843,6 +843,15 @@ int arch_set_info_guest(=0A goto = out;=0A }=0A =0A+ init_int80_direct_trap(v);=0A+=0A+ /* IOPL = privileges are virtualised. */=0A+ v->arch.pv_vcpu.iopl =3D (v->arch.use= r_regs.eflags >> 12) & 3;=0A+ v->arch.user_regs.eflags &=3D ~X86_EFLAGS_= IOPL;=0A+=0A+ /* Ensure real hardware interrupts are enabled. */=0A+ = v->arch.user_regs.eflags |=3D X86_EFLAGS_IF;=0A+=0A if ( !v->is_initial= ised )=0A {=0A v->arch.pv_vcpu.ldt_base =3D c(ldt_base);=0A@@ = -850,11 +859,27 @@ int arch_set_info_guest(=0A }=0A else=0A = {=0A- bool_t fail =3D v->arch.pv_vcpu.ctrlreg[3] !=3D c(ctrlreg[3]);= =0A+ unsigned long pfn =3D pagetable_get_pfn(v->arch.guest_table);= =0A+ bool_t fail;=0A =0A+ if ( !compat )=0A+ {=0A+ = fail =3D xen_pfn_to_cr3(pfn) !=3D c.nat->ctrlreg[3];=0A #ifdef = CONFIG_X86_64=0A- fail |=3D v->arch.pv_vcpu.ctrlreg[1] !=3D = c(ctrlreg[1]);=0A+ if ( pagetable_is_null(v->arch.guest_table_us= er) )=0A+ fail |=3D c.nat->ctrlreg[1] || !(flags & = VGCF_in_kernel);=0A+ else=0A+ {=0A+ = pfn =3D pagetable_get_pfn(v->arch.guest_table_user);=0A+ = fail |=3D xen_pfn_to_cr3(pfn) !=3D c.nat->ctrlreg[1];=0A+ }=0A+ = } else {=0A+ l4_pgentry_t *l4tab =3D __va(pfn_to_paddr(pf= n));=0A+=0A+ pfn =3D l4e_get_pfn(*l4tab);=0A+ fail = =3D compat_pfn_to_cr3(pfn) !=3D c.cmp->ctrlreg[3];=0A #endif=0A+ = }=0A =0A for ( i =3D 0; i < ARRAY_SIZE(v->arch.pv_vcpu.gdt_frames);= ++i )=0A fail |=3D v->arch.pv_vcpu.gdt_frames[i] !=3D = c(gdt_frames[i]);=0A@@ -894,15 +919,6 @@ int arch_set_info_guest(=0A = v->arch.pv_vcpu.ctrlreg[0] &=3D X86_CR0_TS;=0A v->arch.pv_vcpu.ctrlreg[= 0] |=3D read_cr0() & ~X86_CR0_TS;=0A =0A- init_int80_direct_trap(v);=0A-= =0A- /* IOPL privileges are virtualised. */=0A- v->arch.pv_vcpu.iopl = =3D (v->arch.user_regs.eflags >> 12) & 3;=0A- v->arch.user_regs.eflags = &=3D ~X86_EFLAGS_IOPL;=0A-=0A- /* Ensure real hardware interrupts are = enabled. */=0A- v->arch.user_regs.eflags |=3D X86_EFLAGS_IF;=0A-=0A = cr4 =3D v->arch.pv_vcpu.ctrlreg[4];=0A v->arch.pv_vcpu.ctrlreg[4] =3D = cr4 ? pv_guest_cr4_fixup(v, cr4) :=0A real_cr4_to_pv_guest_cr4(mmu_= cr4_features);=0A --=__Part95B9075D.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part95B9075D.1__=--