Re: [PATCH v3 1/3] perf: Allow using AUX data in perf samples
From: Peter Zijlstra
Date:  Mon Oct 28 2019 - 12:28:47 EST
On Mon, Oct 28, 2019 at 05:27:12PM +0100, Peter Zijlstra wrote:
> And while I get why we need recursion protection for pmu::snapshot_aux,
> I'm a little puzzled on why it is over the padding, that is, why isn't
> the whole of aux_in_sampling inside (the newly minted)
> perf_pmu_snapshot_aux() ?
That is, given the previous delta, the below.
---
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6292,9 +6292,17 @@ long perf_pmu_snapshot_aux(struct perf_e
 	 * IRQs need to be disabled to prevent IPIs from racing with us.
 	 */
 	local_irq_save(flags);
+	/*
+	 * Guard against NMI hits inside the critical section;
+	 * see also perf_prepare_sample_aux().
+	 */
+	WRITE_ONCE(rb->aux_in_sampling, 1);
+	barrier();
 
 	ret = event->pmu->snapshot_aux(event, handle, size);
 
+	barrier();
+	WRITE_ONCE(rb->aux_in_sampling, 0);
 	local_irq_restore(flags);
 
 	return ret;
@@ -6316,13 +6324,6 @@ static void perf_aux_sample_output(struc
 	if (!rb)
 		return;
 
-	/*
-	 * Guard against NMI hits inside the critical section;
-	 * see also perf_prepare_sample_aux().
-	 */
-	WRITE_ONCE(rb->aux_in_sampling, 1);
-	barrier();
-
 	size = perf_pmu_snapshot_aux(sampler, handle, data->aux_size);
 
 	/*
@@ -6348,9 +6349,6 @@ static void perf_aux_sample_output(struc
 	}
 
 out_clear:
-	barrier();
-	WRITE_ONCE(rb->aux_in_sampling, 0);
-
 	ring_buffer_put(rb);
 }