* [PATCH RESEND] KVM: X86: Grab KVM's srcu lock when accessing hv assist page
@ 2020-02-14 8:51 Wanpeng Li
2020-02-14 8:58 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Wanpeng Li @ 2020-02-14 8:51 UTC (permalink / raw)
To: LKML, kvm
Cc: Paolo Bonzini, Sean Christopherson, Wanpeng Li, Vitaly Kuznetsov,
Jim Mattson, Joerg Roedel
From: Wanpeng Li <wanpengli@tencent.com>
Acquire kvm->srcu for the duration of mapping eVMCS to fix a bug where accessing
hv assist page derefences ->memslots without holding ->srcu or ->slots_lock.
It can be reproduced by running KVM's evmcs_test selftest.
=============================
WARNING: suspicious RCU usage
5.6.0-rc1+ #53 Tainted: G W IOE
-----------------------------
./include/linux/kvm_host.h:623 suspicious rcu_dereference_check() usage!
other info that might help us debug this:
rcu_scheduler_active = 2, debug_locks = 1
1 lock held by evmcs_test/8507:
#0: ffff9ddd156d00d0 (&vcpu->mutex){+.+.}, at:
kvm_vcpu_ioctl+0x85/0x680 [kvm]
stack backtrace:
CPU: 6 PID: 8507 Comm: evmcs_test Tainted: G W IOE 5.6.0-rc1+ #53
Hardware name: Dell Inc. OptiPlex 7040/0JCTF8, BIOS 1.4.9 09/12/2016
Call Trace:
dump_stack+0x68/0x9b
kvm_read_guest_cached+0x11d/0x150 [kvm]
kvm_hv_get_assist_page+0x33/0x40 [kvm]
nested_enlightened_vmentry+0x2c/0x60 [kvm_intel]
nested_vmx_handle_enlightened_vmptrld.part.52+0x32/0x1c0 [kvm_intel]
nested_sync_vmcs12_to_shadow+0x439/0x680 [kvm_intel]
vmx_vcpu_run+0x67a/0xe60 [kvm_intel]
vcpu_enter_guest+0x35e/0x1bc0 [kvm]
kvm_arch_vcpu_ioctl_run+0x40b/0x670 [kvm]
kvm_vcpu_ioctl+0x370/0x680 [kvm]
ksys_ioctl+0x235/0x850
__x64_sys_ioctl+0x16/0x20
do_syscall_64+0x77/0x780
entry_SYSCALL_64_after_hwframe+0x49/0xbe
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
arch/x86/kvm/vmx/nested.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 657c2ed..a68a69d 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -1994,14 +1994,18 @@ static int
nested_vmx_handle_enlightened_vmptrld(struct kvm_vcpu *vcpu,
void nested_sync_vmcs12_to_shadow(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
+ int idx;
/*
* hv_evmcs may end up being not mapped after migration (when
* L2 was running), map it here to make sure vmcs12 changes are
* properly reflected.
*/
- if (vmx->nested.enlightened_vmcs_enabled && !vmx->nested.hv_evmcs)
+ if (vmx->nested.enlightened_vmcs_enabled && !vmx->nested.hv_evmcs) {
+ idx = srcu_read_lock(&vcpu->kvm->srcu);
nested_vmx_handle_enlightened_vmptrld(vcpu, false);
+ srcu_read_unlock(&vcpu->kvm->srcu, idx);
+ }
if (vmx->nested.hv_evmcs) {
copy_vmcs12_to_enlightened(vmx);
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND] KVM: X86: Grab KVM's srcu lock when accessing hv assist page
2020-02-14 8:51 [PATCH RESEND] KVM: X86: Grab KVM's srcu lock when accessing hv assist page Wanpeng Li
@ 2020-02-14 8:58 ` Paolo Bonzini
2020-02-14 8:59 ` Wanpeng Li
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2020-02-14 8:58 UTC (permalink / raw)
To: Wanpeng Li, LKML, kvm
Cc: Sean Christopherson, Wanpeng Li, Vitaly Kuznetsov, Jim Mattson,
Joerg Roedel
On 14/02/20 09:51, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
>
> Acquire kvm->srcu for the duration of mapping eVMCS to fix a bug where accessing
> hv assist page derefences ->memslots without holding ->srcu or ->slots_lock.
Perhaps nested_sync_vmcs12_to_shadow should be moved to
prepare_guest_switch, where the SRCU is already taken.
Paolo
> It can be reproduced by running KVM's evmcs_test selftest.
>
> =============================
> WARNING: suspicious RCU usage
> 5.6.0-rc1+ #53 Tainted: G W IOE
> -----------------------------
> ./include/linux/kvm_host.h:623 suspicious rcu_dereference_check() usage!
>
> other info that might help us debug this:
>
> rcu_scheduler_active = 2, debug_locks = 1
> 1 lock held by evmcs_test/8507:
> #0: ffff9ddd156d00d0 (&vcpu->mutex){+.+.}, at:
> kvm_vcpu_ioctl+0x85/0x680 [kvm]
>
> stack backtrace:
> CPU: 6 PID: 8507 Comm: evmcs_test Tainted: G W IOE 5.6.0-rc1+ #53
> Hardware name: Dell Inc. OptiPlex 7040/0JCTF8, BIOS 1.4.9 09/12/2016
> Call Trace:
> dump_stack+0x68/0x9b
> kvm_read_guest_cached+0x11d/0x150 [kvm]
> kvm_hv_get_assist_page+0x33/0x40 [kvm]
> nested_enlightened_vmentry+0x2c/0x60 [kvm_intel]
> nested_vmx_handle_enlightened_vmptrld.part.52+0x32/0x1c0 [kvm_intel]
> nested_sync_vmcs12_to_shadow+0x439/0x680 [kvm_intel]
> vmx_vcpu_run+0x67a/0xe60 [kvm_intel]
> vcpu_enter_guest+0x35e/0x1bc0 [kvm]
> kvm_arch_vcpu_ioctl_run+0x40b/0x670 [kvm]
> kvm_vcpu_ioctl+0x370/0x680 [kvm]
> ksys_ioctl+0x235/0x850
> __x64_sys_ioctl+0x16/0x20
> do_syscall_64+0x77/0x780
> entry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> arch/x86/kvm/vmx/nested.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 657c2ed..a68a69d 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -1994,14 +1994,18 @@ static int
> nested_vmx_handle_enlightened_vmptrld(struct kvm_vcpu *vcpu,
> void nested_sync_vmcs12_to_shadow(struct kvm_vcpu *vcpu)
> {
> struct vcpu_vmx *vmx = to_vmx(vcpu);
> + int idx;
>
> /*
> * hv_evmcs may end up being not mapped after migration (when
> * L2 was running), map it here to make sure vmcs12 changes are
> * properly reflected.
> */
> - if (vmx->nested.enlightened_vmcs_enabled && !vmx->nested.hv_evmcs)
> + if (vmx->nested.enlightened_vmcs_enabled && !vmx->nested.hv_evmcs) {
> + idx = srcu_read_lock(&vcpu->kvm->srcu);
> nested_vmx_handle_enlightened_vmptrld(vcpu, false);
> + srcu_read_unlock(&vcpu->kvm->srcu, idx);
> + }
>
> if (vmx->nested.hv_evmcs) {
> copy_vmcs12_to_enlightened(vmx);
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND] KVM: X86: Grab KVM's srcu lock when accessing hv assist page
2020-02-14 8:58 ` Paolo Bonzini
@ 2020-02-14 8:59 ` Wanpeng Li
0 siblings, 0 replies; 3+ messages in thread
From: Wanpeng Li @ 2020-02-14 8:59 UTC (permalink / raw)
To: Paolo Bonzini
Cc: LKML, kvm, Sean Christopherson, Wanpeng Li, Vitaly Kuznetsov,
Jim Mattson, Joerg Roedel
On Fri, 14 Feb 2020 at 16:58, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 14/02/20 09:51, Wanpeng Li wrote:
> > From: Wanpeng Li <wanpengli@tencent.com>
> >
> > Acquire kvm->srcu for the duration of mapping eVMCS to fix a bug where accessing
> > hv assist page derefences ->memslots without holding ->srcu or ->slots_lock.
>
> Perhaps nested_sync_vmcs12_to_shadow should be moved to
> prepare_guest_switch, where the SRCU is already taken.
Will do.
Wanpeng
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-02-14 8:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-14 8:51 [PATCH RESEND] KVM: X86: Grab KVM's srcu lock when accessing hv assist page Wanpeng Li
2020-02-14 8:58 ` Paolo Bonzini
2020-02-14 8:59 ` Wanpeng Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).