From: "Jan Beulich" Subject: [PATCH] x86/vmx: don't call __vmxoff() blindly Date: Fri, 16 Sep 2011 11:22:51 +0100 Message-ID: <4E733F9B020000780005679C@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part1D322D6B.0__=" 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" 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. --=__Part1D322D6B.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline If vmx_vcpu_up() failed, __vmxon() would generally not have got (successfully) executed, and in that case __vmxoff() will #UD. Additionally, any panic() during early resume (namely the tboot related one) would cause vmx_cpu_down() to get executed without vmx_cpu_up() having run before. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -71,6 +71,7 @@ bool_t cpu_has_vmx_ins_outs_instr_info _ static DEFINE_PER_CPU_READ_MOSTLY(struct vmcs_struct *, vmxon_region); static DEFINE_PER_CPU(struct vmcs_struct *, current_vmcs); static DEFINE_PER_CPU(struct list_head, active_vmcs_list); +static DEFINE_PER_CPU(bool_t, vmxon); =20 static u32 vmcs_revision_id __read_mostly; =20 @@ -519,6 +520,7 @@ int vmx_cpu_up(void) printk("CPU%d: unexpected VMXON failure\n", cpu); return -EINVAL; case 0: /* success */ + this_cpu(vmxon) =3D 1; break; default: BUG(); @@ -540,6 +542,9 @@ void vmx_cpu_down(void) struct list_head *active_vmcs_list =3D &this_cpu(active_vmcs_list); unsigned long flags; =20 + if ( !this_cpu(vmxon) ) + return; + local_irq_save(flags); =20 while ( !list_empty(active_vmcs_list) ) @@ -547,6 +552,7 @@ void vmx_cpu_down(void) struct vcpu, arch.hvm_vmx.active_list)= ); =20 BUG_ON(!(read_cr4() & X86_CR4_VMXE)); + this_cpu(vmxon) =3D 0; __vmxoff(); =20 local_irq_restore(flags); --=__Part1D322D6B.0__= Content-Type: text/plain; name="vmx-conditional-vmxoff.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="vmx-conditional-vmxoff.patch" If vmx_vcpu_up() failed, __vmxon() would generally not have got=0A(successf= ully) executed, and in that case __vmxoff() will #UD.=0A=0AAdditionally, = any panic() during early resume (namely the tboot related=0Aone) would = cause vmx_cpu_down() to get executed without vmx_cpu_up()=0Ahaving run = before.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/hvm/vmx/vmcs.c=0A+++ b/xen/arch/x86/hvm/vmx/vmcs.c=0A@@ = -71,6 +71,7 @@ bool_t cpu_has_vmx_ins_outs_instr_info _=0A static = DEFINE_PER_CPU_READ_MOSTLY(struct vmcs_struct *, vmxon_region);=0A static = DEFINE_PER_CPU(struct vmcs_struct *, current_vmcs);=0A static DEFINE_PER_CP= U(struct list_head, active_vmcs_list);=0A+static DEFINE_PER_CPU(bool_t, = vmxon);=0A =0A static u32 vmcs_revision_id __read_mostly;=0A =0A@@ -519,6 = +520,7 @@ int vmx_cpu_up(void)=0A printk("CPU%d: unexpected VMXON = failure\n", cpu);=0A return -EINVAL;=0A case 0: /* success = */=0A+ this_cpu(vmxon) =3D 1;=0A break;=0A default:=0A = BUG();=0A@@ -540,6 +542,9 @@ void vmx_cpu_down(void)=0A struct = list_head *active_vmcs_list =3D &this_cpu(active_vmcs_list);=0A = unsigned long flags;=0A =0A+ if ( !this_cpu(vmxon) )=0A+ = return;=0A+=0A local_irq_save(flags);=0A =0A while ( !list_empty(ac= tive_vmcs_list) )=0A@@ -547,6 +552,7 @@ void vmx_cpu_down(void)=0A = struct vcpu, arch.hvm_vmx.active_list));=0A = =0A BUG_ON(!(read_cr4() & X86_CR4_VMXE));=0A+ this_cpu(vmxon) =3D = 0;=0A __vmxoff();=0A =0A local_irq_restore(flags);=0A --=__Part1D322D6B.0__= 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 --=__Part1D322D6B.0__=--