From: Sean Christopherson <seanjc@google.com>
To: Michal Luczaj <mhal@rbox.co>
Cc: pbonzini@redhat.com, dwmw2@infradead.org, kvm@vger.kernel.org,
paul@xen.org
Subject: Re: [PATCH 1/2] KVM: x86: Fix deadlock in kvm_vm_ioctl_set_msr_filter()
Date: Thu, 5 Jan 2023 22:46:46 +0000 [thread overview]
Message-ID: <Y7dTVgz4chEVL2IS@google.com> (raw)
In-Reply-To: <20221229211737.138861-2-mhal@rbox.co>
On Thu, Dec 29, 2022, Michal Luczaj wrote:
> Move synchronize_srcu(&kvm->srcu) out of kvm->lock critical section.
>
> Signed-off-by: Michal Luczaj <mhal@rbox.co>
> ---
> arch/x86/kvm/x86.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index da4bbd043a7b..16c89f7e98c3 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6460,7 +6460,7 @@ static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm,
> struct kvm_x86_msr_filter *new_filter, *old_filter;
> bool default_allow;
> bool empty = true;
> - int r = 0;
> + int r;
Separate change that should be its own patch (even though it's trivial).
> u32 i;
>
> if (filter->flags & ~KVM_MSR_FILTER_VALID_MASK)
> @@ -6488,16 +6488,14 @@ static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm,
> mutex_lock(&kvm->lock);
>
> /* The per-VM filter is protected by kvm->lock... */
> - old_filter = srcu_dereference_check(kvm->arch.msr_filter, &kvm->srcu, 1);
> + old_filter = rcu_replace_pointer(kvm->arch.msr_filter, new_filter, 1);
Same here. Can you also add a patch to replace the '1' with "mutex_is_locked(&kvm->lock)"?
> + kvm_make_all_cpus_request(kvm, KVM_REQ_MSR_FILTER_CHANGED);
I think the request can actually be moved outside of kvm->lock too (in yet another
patch). Iterating over vCPUs without kvm->lock is safe; kvm_make_all_cpus_request()
might race with adding a new vCPU, i.e. send an unnecessary request, but
kvm->online_vcpus is never decremented.
> - rcu_assign_pointer(kvm->arch.msr_filter, new_filter);
> - synchronize_srcu(&kvm->srcu);
> + mutex_unlock(&kvm->lock);
>
> + synchronize_srcu(&kvm->srcu);
> kvm_free_msr_filter(old_filter);
>
> - kvm_make_all_cpus_request(kvm, KVM_REQ_MSR_FILTER_CHANGED);
> - mutex_unlock(&kvm->lock);
> -
> return 0;
> }
>
> --
> 2.39.0
>
next prev parent reply other threads:[~2023-01-05 22:46 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-22 20:30 [RFC PATCH 0/2] Use-after-free in kvm_xen_eventfd_update() Michal Luczaj
2022-12-22 20:30 ` [RFC PATCH 1/2] KVM: x86/xen: Fix use-after-free " Michal Luczaj
2022-12-24 8:52 ` Paolo Bonzini
2022-12-24 11:14 ` Michal Luczaj
2022-12-27 11:11 ` Paolo Bonzini
2022-12-28 0:21 ` Michal Luczaj
2022-12-28 9:32 ` David Woodhouse
2022-12-28 9:39 ` Paolo Bonzini
2022-12-28 9:54 ` David Woodhouse
2022-12-28 11:58 ` Paolo Bonzini
2022-12-28 12:35 ` David Woodhouse
2022-12-28 13:14 ` Paolo Bonzini
2022-12-29 2:12 ` Michal Luczaj
2022-12-29 21:03 ` Paolo Bonzini
2022-12-29 21:17 ` [PATCH 0/2] Fix deadlocks in kvm_vm_ioctl_set_msr_filter() and Michal Luczaj
2022-12-29 21:17 ` [PATCH 1/2] KVM: x86: Fix deadlock in kvm_vm_ioctl_set_msr_filter() Michal Luczaj
2023-01-03 17:17 ` Sean Christopherson
2023-01-03 17:28 ` Sean Christopherson
2023-01-05 19:32 ` Michal Luczaj
2023-01-05 22:23 ` Sean Christopherson
2023-01-05 23:02 ` Paolo Bonzini
2023-01-05 23:07 ` Sean Christopherson
2023-01-10 12:55 ` David Woodhouse
2023-01-10 14:10 ` Paolo Bonzini
2023-01-10 15:27 ` David Woodhouse
2023-01-10 19:17 ` David Woodhouse
2023-01-10 19:37 ` Sean Christopherson
2023-01-10 19:46 ` David Woodhouse
2023-01-11 8:49 ` David Woodhouse
2023-01-11 22:49 ` Paolo Bonzini
2023-01-06 10:06 ` David Woodhouse
2023-01-07 0:06 ` Michal Luczaj
2023-01-05 22:46 ` Sean Christopherson [this message]
2022-12-29 21:17 ` [PATCH 2/2] KVM: x86: Fix deadlock in kvm_vm_ioctl_set_pmu_event_filter() Michal Luczaj
2022-12-22 20:30 ` [RFC PATCH 2/2] KVM: x86/xen: Simplify eventfd IOCTLs Michal Luczaj
2022-12-24 8:54 ` Paolo Bonzini
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=Y7dTVgz4chEVL2IS@google.com \
--to=seanjc@google.com \
--cc=dwmw2@infradead.org \
--cc=kvm@vger.kernel.org \
--cc=mhal@rbox.co \
--cc=paul@xen.org \
--cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.