public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jim Mattson <jmattson@google.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	kvm list <kvm@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] KVM: VMX: fix crash cleanup when KVM wasn't used
Date: Fri, 21 Aug 2020 20:40:46 -0700	[thread overview]
Message-ID: <20200822034046.GE4769@sjchrist-ice> (raw)
In-Reply-To: <CALMp9eROXAOg_g=R8JRVfywY7uQXzBtVxKJYXq0dUcob-BfR-g@mail.gmail.com>

On Thu, Aug 20, 2020 at 01:08:22PM -0700, Jim Mattson wrote:
> On Wed, Apr 1, 2020 at 1:13 AM Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
> > ---
> >  arch/x86/kvm/vmx/vmx.c | 12 +++++++-----
> >  1 file changed, 7 insertions(+), 5 deletions(-)
> >
> > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> > index 3aba51d782e2..39a5dde12b79 100644
> > --- a/arch/x86/kvm/vmx/vmx.c
> > +++ b/arch/x86/kvm/vmx/vmx.c
> > @@ -2257,10 +2257,6 @@ static int hardware_enable(void)
> >             !hv_get_vp_assist_page(cpu))
> >                 return -EFAULT;
> >
> > -       INIT_LIST_HEAD(&per_cpu(loaded_vmcss_on_cpu, cpu));
> > -       INIT_LIST_HEAD(&per_cpu(blocked_vcpu_on_cpu, cpu));
> > -       spin_lock_init(&per_cpu(blocked_vcpu_on_cpu_lock, cpu));
> > -
> >         r = kvm_cpu_vmxon(phys_addr);
> >         if (r)
> >                 return r;
> > @@ -8006,7 +8002,7 @@ module_exit(vmx_exit);
> >
> >  static int __init vmx_init(void)
> >  {
> > -       int r;
> > +       int r, cpu;
> >
> >  #if IS_ENABLED(CONFIG_HYPERV)
> >         /*
> > @@ -8060,6 +8056,12 @@ static int __init vmx_init(void)
> >                 return r;
> >         }
> >
> > +       for_each_possible_cpu(cpu) {
> > +               INIT_LIST_HEAD(&per_cpu(loaded_vmcss_on_cpu, cpu));
> > +               INIT_LIST_HEAD(&per_cpu(blocked_vcpu_on_cpu, cpu));
> > +               spin_lock_init(&per_cpu(blocked_vcpu_on_cpu_lock, cpu));
> > +       }
> 
> Just above this chunk, we have:
> 
> r = vmx_setup_l1d_flush(vmentry_l1d_flush_param);
> if (r) {
>         vmx_exit();
> ...
> 
> If we take that early exit, because vmx_setup_l1d_flush() fails, we
> won't initialize loaded_vmcss_on_cpu. However, vmx_exit() calls
> kvm_exit(), which calls on_each_cpu(hardware_disable_nolock, NULL, 1).
> Hardware_disable_nolock() then calls kvm_arch_hardware_disable(),
> which calls kvm_x86_ops.hardware_disable() [the vmx.c
> hardware_disable()], which calls vmclear_local_loaded_vmcss().
> 
> I believe that vmclear_local_loaded_vmcss() will then try to
> dereference a NULL pointer, since per_cpu(loaded_vmcss_on_cpu, cpu) is
> uninitialzed.

I agree the code is a mess (kvm_init() and kvm_exit() included), but I'm
pretty sure hardware_disable_nolock() is guaranteed to be a nop as it's
impossible for kvm_usage_count to be non-zero if vmx_init() hasn't
finished.

> >  #ifdef CONFIG_KEXEC_CORE
> >         rcu_assign_pointer(crash_vmclear_loaded_vmcss,
> >                            crash_vmclear_local_loaded_vmcss);
> > --
> > 2.25.1
> >

  reply	other threads:[~2020-08-22  3:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-01  8:13 [PATCH] KVM: VMX: fix crash cleanup when KVM wasn't used Vitaly Kuznetsov
2020-04-01 15:18 ` Sean Christopherson
2020-04-07 12:35 ` Paolo Bonzini
2020-04-09  1:22 ` Baoquan He
2020-08-20 20:08 ` Jim Mattson
2020-08-22  3:40   ` Sean Christopherson [this message]
2020-08-24 18:57     ` Jim Mattson
2020-08-24 22:45       ` Jim Mattson
2020-08-25  0:09         ` Sean Christopherson
2020-09-01 10:36           ` Vitaly Kuznetsov
2020-09-02 15:18             ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200822034046.GE4769@sjchrist-ice \
    --to=sean.j.christopherson@intel.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox