From: Paolo Bonzini <pbonzini@redhat.com>
To: Maxim Levitsky <mlevitsk@redhat.com>, kvm@vger.kernel.org
Cc: Sean Christopherson <seanjc@google.com>,
"open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<linux-kernel@vger.kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<x86@kernel.org>, Jim Mattson <jmattson@google.com>,
Borislav Petkov <bp@alien8.de>,
Wanpeng Li <wanpengli@tencent.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Joerg Roedel <joro@8bytes.org>,
Vitaly Kuznetsov <vkuznets@redhat.com>
Subject: Re: [PATCH] KVM: nSVM: call nested_svm_load_cr3 on nested state load
Date: Wed, 10 Feb 2021 18:38:36 +0100 [thread overview]
Message-ID: <9314afe0-7808-7877-0270-87f29a5f1191@redhat.com> (raw)
In-Reply-To: <20210210155937.141569-1-mlevitsk@redhat.com>
On 10/02/21 16:59, Maxim Levitsky wrote:
> While KVM's MMU should be fully reset by loading of nested CR0/CR3/CR4
> by KVM_SET_SREGS, we are not in nested mode yet when we do it and therefore
> only root_mmu is reset.
>
> On regular nested entries we call nested_svm_load_cr3 which both updates the
> guest's CR3 in the MMU when it is needed, and it also initializes
> the mmu again which makes it initialize the walk_mmu as well when nested
> paging is enabled in both host and guest.
>
> Since we don't call nested_svm_load_cr3 on nested state load,
> the walk_mmu can be left uninitialized, which can lead to a NULL pointer
> dereference while accessing it if we happen to get a nested page fault
> right after entering the nested guest first time after the migration and
> we decide to emulate it, which leads to emulator trying to access
> walk_mmu->gva_to_gpa which is NULL.
>
> Therefore we should call this function on nested state load as well.
>
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
> arch/x86/kvm/svm/nested.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index 519fe84f2100..c209f1232928 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -1282,6 +1282,14 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
>
> nested_vmcb02_prepare_control(svm);
>
> + ret = nested_svm_load_cr3(&svm->vcpu, vcpu->arch.cr3,
> + nested_npt_enabled(svm));
> +
> + if (ret) {
> + svm_leave_nested(svm);
> + goto out_free;
> + }
> +
> kvm_make_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
> ret = 0;
> out_free:
>
I think you have to delay this to KVM_REQ_GET_NESTED_STATE_PAGES,
because the !nested_npt case can be accessing memory before the VM is
started (PDPTRs!).
In fact the same is true for VMX: this code
/* Shadow page tables on either EPT or shadow page tables. */
if (nested_vmx_load_cr3(vcpu, vmcs12->guest_cr3,
nested_cpu_has_ept(vmcs12),
entry_failure_code))
return -EINVAL;
must be moved from prepare_vmcs02 to both nested_vmx_enter_non_root_mode
and nested_get_vmcs12_pages.
Thanks,
Paolo
prev parent reply other threads:[~2021-02-10 17:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-10 15:59 Maxim Levitsky
2021-02-10 17:38 ` Paolo Bonzini [this message]
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=9314afe0-7808-7877-0270-87f29a5f1191@redhat.com \
--to=pbonzini@redhat.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mlevitsk@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
/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
all inboxes | Powered by JetHome®