linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@scylladb.com>
To: linux-man@vger.kernel.org
Cc: mingo@redhat.com
Subject: [PATCH v1] perf_event_open.2: clarify and expand memory barrier requirements
Date: Sun, 19 Sep 2021 20:36:39 +0300	[thread overview]
Message-ID: <20210919173639.2100661-1-avi@scylladb.com> (raw)

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@scylladb.com>
---
 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
-- 
2.31.1


             reply	other threads:[~2021-09-19 17:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-19 17:36 Avi Kivity [this message]
2021-10-10 11:04 ` [PATCH v1] perf_event_open.2: clarify and expand memory barrier requirements Avi Kivity

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=20210919173639.2100661-1-avi@scylladb.com \
    --to=avi@scylladb.com \
    --cc=linux-man@vger.kernel.org \
    --cc=mingo@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).