OSDN Git Service

KVM: x86/xen: Fix SRCU/RCU usage in readers of evtchn_ports
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 26 Dec 2022 12:03:17 +0000 (12:03 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 27 Dec 2022 11:01:49 +0000 (06:01 -0500)
commit70eae03087a3101493d9a1cf60c86c5f65600822
treea980cfdcdcb5f4ac71a99f9a932a1fad80117f3c
parent92c58965e9656dc6e682a8ffe520fac0fb256d13
KVM: x86/xen: Fix SRCU/RCU usage in readers of evtchn_ports

The evtchnfd structure itself must be protected by either kvm->lock or
SRCU. Use the former in kvm_xen_eventfd_update(), since the lock is
being taken anyway; kvm_xen_hcall_evtchn_send() instead is a reader and
does not need kvm->lock, and is called in SRCU critical section from the
kvm_x86_handle_exit function.

It is also important to use rcu_read_{lock,unlock}() in
kvm_xen_hcall_evtchn_send(), because idr_remove() will *not*
use synchronize_srcu() to wait for readers to complete.

Remove a superfluous if (kvm) check before calling synchronize_srcu()
in kvm_xen_eventfd_deassign() where kvm has been dereferenced already.

Co-developed-by: Michal Luczaj <mhal@rbox.co>
Signed-off-by: Michal Luczaj <mhal@rbox.co>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Message-Id: <20221226120320.1125390-3-dwmw2@infradead.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/xen.c