lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20200321145551.GA12329@linux.intel.com>
Date:   Sat, 21 Mar 2020 07:55:51 -0700
From:   Sean Christopherson <sean.j.christopherson@...el.com>
To:     Paolo Bonzini <pbonzini@...hat.com>
Cc:     Vitaly Kuznetsov <vkuznets@...hat.com>,
        Wanpeng Li <wanpengli@...cent.com>,
        Jim Mattson <jmattson@...gle.com>,
        Joerg Roedel <joro@...tes.org>, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/3] KVM: VMX: Always VMCLEAR in-use VMCSes during crash
 with kexec support

On Fri, Feb 28, 2020 at 06:59:43AM -0800, Sean Christopherson wrote:
> On Fri, Feb 28, 2020 at 11:16:10AM +0100, Paolo Bonzini wrote:
> > On 27/02/20 23:30, Sean Christopherson wrote:
> > > -void loaded_vmcs_init(struct loaded_vmcs *loaded_vmcs)
> > > +void loaded_vmcs_init(struct loaded_vmcs *loaded_vmcs, bool in_use)
> > >  {
> > >  	vmcs_clear(loaded_vmcs->vmcs);
> > >  	if (loaded_vmcs->shadow_vmcs && loaded_vmcs->launched)
> > >  		vmcs_clear(loaded_vmcs->shadow_vmcs);
> > > +
> > > +	if (in_use) {
> > > +		list_del(&loaded_vmcs->loaded_vmcss_on_cpu_link);
> > > +
> > > +		/*
> > > +		 * Ensure deleting loaded_vmcs from its current percpu list
> > > +		 * completes before setting loaded_vmcs->vcpu to -1, otherwise
> > > +		 * a different cpu can see vcpu == -1 first and add loaded_vmcs
> > > +		 * to its percpu list before it's deleted from this cpu's list.
> > > +		 * Pairs with the smp_rmb() in vmx_vcpu_load_vmcs().
> > > +		 */
> > > +		smp_wmb();
> > > +	}
> > > +
> > 
> > I'd like to avoid the new in_use argument and, also, I think it's a
> > little bit nicer to always invoke the memory barrier.  Even though we 
> > use "asm volatile" for vmclear and therefore the compiler is already 
> > taken care of, in principle it's more correct to order the ->cpu write 
> > against vmclear's.
> 
> Completely agree on all points.  I wanted to avoid in_use as well, but it
> didn't occur to me to use list_empty()...
> 
> > This gives the following patch on top:
> 
> Looks good.
> 
> > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> > index c9d6152e7a4d..77a64110577b 100644
> > --- a/arch/x86/kvm/vmx/vmx.c
> > +++ b/arch/x86/kvm/vmx/vmx.c
> > @@ -656,25 +656,24 @@ static int vmx_set_guest_msr(struct vcpu_vmx *vmx, struct shared_msr_entry *msr,
> >  	return ret;
> >  }
> >  
> > -void loaded_vmcs_init(struct loaded_vmcs *loaded_vmcs, bool in_use)
> > +void loaded_vmcs_init(struct loaded_vmcs *loaded_vmcs)
> >  {
> >  	vmcs_clear(loaded_vmcs->vmcs);
> >  	if (loaded_vmcs->shadow_vmcs && loaded_vmcs->launched)
> >  		vmcs_clear(loaded_vmcs->shadow_vmcs);
> >  
> > -	if (in_use) {
> > +	if (!list_empty(&loaded_vmcs->loaded_vmcss_on_cpu_link))

Circling back to this, an even better option is to drop loaded_vmcs_init()
and open code the required pieces in __loaded_vmcs_clear() and
alloc_loaded_vmcs().  Those are the only two callers, and the latter
doesn't need to VMCLEAR the shadow VMCS (guaranteed to be NULL) and
obviously doesn't need the list manipulation of smp_wmb().

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ