Thread (29 messages) 29 messages, 4 authors, 2021-09-21

Re: [PATCH v2 01/13] perf: Ensure perf_guest_cbs aren't reloaded between !NULL check and deref

From: Sean Christopherson <seanjc@google.com>
Date: 2021-09-16 21:41:10
Also in: kvm, kvmarm, linux-arm-kernel, linux-riscv, lkml, xen-devel

On Sat, Aug 28, 2021, Peter Zijlstra wrote:
On Fri, Aug 27, 2021 at 05:35:46PM -0700, Sean Christopherson wrote:
quoted
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 464917096e73..2126f6327321 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6491,14 +6491,19 @@ struct perf_guest_info_callbacks *perf_guest_cbs;
 
 int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
 {
-	perf_guest_cbs = cbs;
+	if (WARN_ON_ONCE(perf_guest_cbs))
+		return -EBUSY;
+
+	WRITE_ONCE(perf_guest_cbs, cbs);
+	synchronize_rcu();
You're waiting for all NULL users to go away? :-) IOW, we can do without
this synchronize_rcu() call.
Doh, right.  I was thinking KVM needed to wait for in-progress NMI to exit to
ensure guest PT interrupts are handled correctly, but obviously the NMI handler
needs to exit for that CPU to get into a guest...
quoted
 	return 0;
 }
 EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks);
 
 int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
 {
-	perf_guest_cbs = NULL;
	if (WARN_ON_ONCE(perf_guest_cbs != cbs))
		return -EBUSY;

?
Works for me.  I guess I'm more optimistic about people not being morons :-)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help