READ_ONCE() usage in perf_mmap_read_self()

From: Vince Weaver
Date: Fri Jun 17 2022 - 16:13:32 EST


Hello

Is the perf_mmap__read_self() interface as found in tools/lib/perf/mmap.c
the "official" interface for accessing the perf mmap info from
userspace?

Are the READ_ONCE() calls required? If they are left out, will accessing
the mmap interface potentially fail? Has this ever been seen in practice?

Part of why I am asking is both
tools/lib/perf/mmap.c
and
tools/linux/compiler.h (which defines READ_ONCE)
have SPDX headers indicating they are GPL-2.0 licensed, which means it
seems like it would not be possible to easily use the perf mmap interface
from BSD-licensed code. Would it be possible to get those two files
re-licensed?

The (BSD-licensed) PAPI is currently using a mmap reading interface
based on early documentation for the feature, but it isn't 100% the same
as the version from libperf (and isn't using READ_ONCE). Life would be
easier if we could use the perf version of the code because then we would
have one less variable to deal with when trying to track down issues.

Vince Weaver
vincent.weaver@xxxxxxxxx