]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
selftests/perf_events: Add a mmap() correctness test
authorLorenzo Stoakes <lorenzo.stoakes@oracle.com>
Sat, 2 Aug 2025 20:55:35 +0000 (22:55 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Aug 2025 10:05:11 +0000 (12:05 +0200)
commit546cebccfe41de2710874fd7b430ed27136db5e9
tree1df657bb9f0ab577f8df02ecd413c6d043173ce6
parent7b84cb58d1f0aa07656802eae24689566e5f5b1b
selftests/perf_events: Add a mmap() correctness test

commit 084d2ac4030c5919e85bba1f4af26e33491469cb upstream.

Exercise various mmap(), munmap() and mremap() invocations, which might
cause a perf buffer mapping to be split or truncated.

To avoid hard coding the perf event and having dependencies on
architectures and configuration options, scan through event types in sysfs
and try to open them. On success, try to mmap() and if that succeeds try to
mmap() the AUX buffer.

In case that no AUX buffer supporting event is found, only test the base
buffer mapping. If no mappable event is found or permissions are not
sufficient, skip the tests.

Reserve a PROT_NONE region for both rb and aux tests to allow testing the
case where mremap unmaps beyond the end of a mapped VMA to prevent it from
unmapping unrelated mappings.

Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Co-developed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/testing/selftests/perf_events/.gitignore
tools/testing/selftests/perf_events/Makefile
tools/testing/selftests/perf_events/mmap.c [new file with mode: 0644]