Re: [PATCH v1] perf_event_open.2: clarify and expand memory barrier requirements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bump

On 19/09/2021 20.36, Avi Kivity wrote:
perf_event_open(2) instructs the user to issue an rmb() after reading
data_head to ensure that user-space sees all writes to the memory
it reads. rmb() is a kernel-internal term that might not mean much
to the reader; and further it is too strict. It's enough to require
the weaker load-acquire fence. This is an industry standard term
that does not require the user to understand kernel terminology.

In addition, require a store-release fence before writing data_tail.
This prevents the user's reads from being reordered with the kernel's
writes to the just-freed space. The documentation in <linux/perf_event.h>
also suggests doing this.

Signed-off-by: Avi Kivity <avi@xxxxxxxxxxxx>
---
  man2/perf_event_open.2 | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/man2/perf_event_open.2 b/man2/perf_event_open.2
index 81c1b10f2..db5ce746b 100644
--- a/man2/perf_event_open.2
+++ b/man2/perf_event_open.2
@@ -1837,18 +1837,19 @@ The value needs to be manually wrapped by the size of the mmap buffer
  before accessing the samples.
  .IP
  On SMP-capable platforms, after reading the
  .I data_head
  value,
-user space should issue an rmb().
+user space should issue a load-acquire fence.
  .TP
  .I data_tail
  When the mapping is
  .BR PROT_WRITE ,
  the
  .I data_tail
  value should be written by user space to reflect the last read data.
+Before writing, issue a store-release fence.
  In this case, the kernel will not overwrite unread data.
  .TP
  .IR data_offset " (since Linux 4.1)"
  .\" commit e8c6deac69629c0cb97c3d3272f8631ef17f8f0f
  Contains the offset of the location in the mmap buffer



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux