* [PATCH v1] perf_event_open.2: clarify and expand memory barrier requirements
@ 2021-09-19 17:36 Avi Kivity
2021-10-10 11:04 ` Avi Kivity
0 siblings, 1 reply; 2+ messages in thread
From: Avi Kivity @ 2021-09-19 17:36 UTC (permalink / raw)
To: linux-man; +Cc: mingo
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] perf_event_open.2: clarify and expand memory barrier requirements
2021-09-19 17:36 [PATCH v1] perf_event_open.2: clarify and expand memory barrier requirements Avi Kivity
@ 2021-10-10 11:04 ` Avi Kivity
0 siblings, 0 replies; 2+ messages in thread
From: Avi Kivity @ 2021-10-10 11:04 UTC (permalink / raw)
To: linux-man; +Cc: mingo
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@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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-10 11:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-19 17:36 [PATCH v1] perf_event_open.2: clarify and expand memory barrier requirements Avi Kivity
2021-10-10 11:04 ` Avi Kivity
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.