linux-kernelorg-stable/include/trace/events
Lorenzo Stoakes 5dba5cc2e0 mm: introduce VM_MAYBE_GUARD and make visible in /proc/$pid/smaps
Patch series "introduce VM_MAYBE_GUARD and make it sticky", v4.

Currently, guard regions are not visible to users except through
/proc/$pid/pagemap, with no explicit visibility at the VMA level.

This makes the feature less useful, as it isn't entirely apparent which
VMAs may have these entries present, especially when performing actions
which walk through memory regions such as those performed by CRIU.

This series addresses this issue by introducing the VM_MAYBE_GUARD flag
which fulfils this role, updating the smaps logic to display an entry for
these.

The semantics of this flag are that a guard region MAY be present if set
(we cannot be sure, as we can't efficiently track whether an
MADV_GUARD_REMOVE finally removes all the guard regions in a VMA) - but if
not set the VMA definitely does NOT have any guard regions present.

It's problematic to establish this flag without further action, because
that means that VMAs with guard regions in them become non-mergeable with
adjacent VMAs for no especially good reason.

To work around this, this series also introduces the concept of 'sticky'
VMA flags - that is flags which:

a. if set in one VMA and not in another still permit those VMAs to be
   merged (if otherwise compatible).

b. When they are merged, the resultant VMA must have the flag set.

The VMA logic is updated to propagate these flags correctly.

Additionally, VM_MAYBE_GUARD being an explicit VMA flag allows us to solve
an issue with file-backed guard regions - previously these established an
anon_vma object for file-backed mappings solely to have vma_needs_copy()
correctly propagate guard region mappings to child processes.

We introduce a new flag alias VM_COPY_ON_FORK (which currently only
specifies VM_MAYBE_GUARD) and update vma_needs_copy() to check explicitly
for this flag and to copy page tables if it is present, which resolves
this issue.

Additionally, we add the ability for allow-listed VMA flags to be
atomically writable with only mmap/VMA read locks held.

The only flag we allow so far is VM_MAYBE_GUARD, which we carefully ensure
does not cause any races by being allowed to do so.

This allows us to maintain guard region installation as a read-locked
operation and not endure the overhead of obtaining a write lock here.

Finally we introduce extensive VMA userland tests to assert that the
sticky VMA logic behaves correctly as well as guard region self tests to
assert that smaps visibility is correctly implemented.


This patch (of 9):

Currently, if a user needs to determine if guard regions are present in a
range, they have to scan all VMAs (or have knowledge of which ones might
have guard regions).

Since commit 8e2f2aeb8b ("fs/proc/task_mmu: add guard region bit to
pagemap") and the related commit a516403787 ("fs/proc: extend the
PAGEMAP_SCAN ioctl to report guard regions"), users can use either
/proc/$pid/pagemap or the PAGEMAP_SCAN functionality to perform this
operation at a virtual address level.

This is not ideal, and it gives no visibility at a /proc/$pid/smaps level
that guard regions exist in ranges.

This patch remedies the situation by establishing a new VMA flag,
VM_MAYBE_GUARD, to indicate that a VMA may contain guard regions (it is
uncertain because we cannot reasonably determine whether a
MADV_GUARD_REMOVE call has removed all of the guard regions in a VMA, and
additionally VMAs may change across merge/split).

We utilise 0x800 for this flag which makes it available to 32-bit
architectures also, a flag that was previously used by VM_DENYWRITE, which
was removed in commit 8d0920bde5 ("mm: remove VM_DENYWRITE") and hasn't
bee reused yet.

We also update the smaps logic and documentation to identify these VMAs.

Another major use of this functionality is that we can use it to identify
that we ought to copy page tables on fork.

We do not actually implement usage of this flag in mm/madvise.c yet as we
need to allow some VMA flags to be applied atomically under mmap/VMA read
lock in order to avoid the need to acquire a write lock for this purpose.

Link: https://lkml.kernel.org/r/cover.1763460113.git.lorenzo.stoakes@oracle.com
Link: https://lkml.kernel.org/r/cf8ef821eba29b6c5b5e138fffe95d6dcabdedb9.1763460113.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>
Reviewed-by: Lance Yang <lance.yang@linux.dev>
Cc: Andrei Vagin <avagin@gmail.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nico Pache <npache@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2025-11-20 13:43:58 -08:00
..
9p.h
afs.h afs: Add support for RENAME_NOREPLACE and RENAME_EXCHANGE 2025-09-25 09:19:07 +02:00
alarmtimer.h alarmtimer: Hide alarmtimer_suspend event when RTC_CLASS is not configured 2025-07-21 16:40:56 -04:00
amdxdna.h
asoc.h
avc.h
bcache.h
block.h block: fix blk_zone_append_update_request_bio() kernel-doc 2025-07-16 10:02:18 -06:00
bpf_test_run.h
bridge.h
btrfs.h Summary of significant series in this pull request: 2025-07-31 14:57:54 -07:00
cachefiles.h
capability.h
cgroup.h cgroup: remove per-cpu per-subsystem locks 2025-06-17 10:01:18 -10:00
clk.h
cma.h mm/cma: add 'available count' and 'total count' to trace_cma_alloc_start 2025-09-13 16:55:15 -07:00
compaction.h
context_tracking.h
cpuhp.h
csd.h
damon.h mm/damon: add trace event for effective size quota 2025-07-13 16:38:33 -07:00
devfreq.h
devlink.h
dlm.h
dma.h dma-mapping: fix direction in dma_alloc direction traces 2025-10-03 08:45:09 +02:00
dma_fence.h dma-fence: Add safe access helpers and document the rules 2025-06-13 08:26:49 +01:00
erofs.h erofs: remove unused trace event erofs_destroy_inode 2025-06-18 13:41:16 +08:00
error_report.h
exceptions.h x86/tracing, x86/mm: Move page fault tracepoints to generic 2025-05-16 10:13:59 +02:00
ext4.h Major ext4 changes for 6.17: 2025-07-31 10:02:44 -07:00
f2fs.h f2fs: remove wbc->for_reclaim handling 2025-05-08 15:22:45 +00:00
fib.h ipv4: Convert ->flowi4_tos to dscp_t. 2025-08-26 17:34:31 -07:00
fib6.h
filelock.h vfs-6.18-rc1.inode 2025-09-29 09:42:30 -07:00
filemap.h
firewire.h
firewire_ohci.h
fs_dax.h mm: update core kernel code to use vm_flags_t consistently 2025-07-09 22:42:13 -07:00
fscache.h
fsi.h
fsi_master_aspeed.h
fsi_master_ast_cf.h
fsi_master_gpio.h
fsi_master_i2cr.h
gpio.h
gpu_mem.h
habanalabs.h accel/habanalabs: fix typo in trace output (cms -> cmd) 2025-09-25 09:09:28 +03:00
handshake.h
host1x.h
huge_memory.h mm: drop all references of writable and SCAN_PAGE_RO 2025-09-21 14:22:40 -07:00
hugetlbfs.h
hw_pressure.h
hwmon.h hwmon: Introduce 64-bit energy attribute support 2025-09-07 16:33:48 -07:00
i2c.h
i2c_slave.h
ib_mad.h
ib_umad.h
icmp.h
initcall.h
intel-sst.h
intel_ifs.h
intel_ish.h
io_uring.h io_uring/trace: support completion tracing of mixed 32b CQEs 2025-08-24 11:41:13 -06:00
iocost.h
iommu.h
ipi.h tracing: arm: arm64: Hide trace events ipi_raise, ipi_entry and ipi_exit 2025-07-23 14:58:55 -04:00
irq.h
irq_matrix.h genirq/matrix: Remove unused irq_matrix_alloc_reserved tracepoint 2025-06-02 13:12:26 -04:00
iscsi.h
jbd2.h
kmem.h kmem/tracing: add kmem name to kmem_cache_alloc tracepoint 2025-09-13 16:55:18 -07:00
ksm.h
kvm.h LoongArch: KVM: Move kvm_iocsr tracepoint out of generic code 2025-09-23 23:37:26 +08:00
kyber.h
libata.h
lock.h
maple_tree.h
mce.h
mctp.h
mdio.h
memcg.h
migrate.h
mlxsw.h
mmap.h mm: remove unused mmap tracepoints 2025-07-09 22:41:55 -07:00
mmap_lock.h
mmc.h
mmflags.h mm: introduce VM_MAYBE_GUARD and make visible in /proc/$pid/smaps 2025-11-20 13:43:58 -08:00
module.h
mptcp.h
napi.h
nbd.h
neigh.h
net.h
net_probe_common.h
netfs.h netfs: Fix race between cache write completion and ALL_QUEUED being set 2025-07-14 11:05:02 +02:00
netlink.h
nilfs2.h
nmi.h
notifier.h
objagg.h
oom.h
osnoise.h
page_isolation.h
page_pool.h
page_ref.h mm: introduce memdesc_flags_t 2025-09-13 16:55:07 -07:00
pagemap.h
percpu.h
power.h PM: tracing: Hide power_domain_target event under ARCH_OMAP2PLUS 2025-07-21 16:40:57 -04:00
power_cpu_migrate.h
preemptirq.h
printk.h
pwc.h
pwm.h
qdisc.h
qla.h
qrtr.h
rcu.h
rdma_core.h
readahead.h readahead: add trace points 2025-09-21 14:22:28 -07:00
regulator.h
rpcgss.h sunrpc: implement rfc2203 rpcsec_gss seqnum cache 2025-05-19 10:14:29 -04:00
rpcrdma.h
rpm.h
rseq.h
rtc.h
rust_sample.h
rwmmio.h
rxrpc.h rxrpc: Fix notification vs call-release vs recvmsg 2025-07-17 07:50:48 -07:00
sched.h tracing changes for 6.17 2025-08-01 10:29:36 -07:00
sched_ext.h
scmi.h include: trace: Add tracepoint support for inflight xfer count 2025-07-03 16:18:09 +01:00
scsi.h scsi: trace: Show rtn in string for scsi_dispatch_cmd_error() 2025-06-09 21:59:07 -04:00
sctp.h
signal.h
siox.h
skb.h
smbus.h
sock.h
sof.h
sof_intel.h
spi.h
spmi.h
sunrpc.h sunrpc: remove SVC_SYSERR 2025-07-14 12:46:48 -04:00
sunvnet.h
swiotlb.h
syscalls.h
target.h
task.h copy_process: pass clone_flags as u64 across calltree 2025-09-01 15:31:34 +02:00
tcp.h trace: tcp: add three metrics to trace_tcp_rcvbuf_grow() 2025-10-29 17:30:18 -07:00
tegra_apb_dma.h
thp.h powerpc/thp: tracing: Hide hugepage events under CONFIG_PPC_BOOK3S_64 2025-07-25 08:58:07 -04:00
timer.h
timer_migration.h
timestamp.h
tlb.h
tsm_mr.h tsm-mr: Add TVM Measurement Register support 2025-05-08 19:17:33 -07:00
udp.h
v4l2.h
vb2.h
vmalloc.h
vmscan.h
vsock_virtio_transport_common.h
watchdog.h
wbt.h
workqueue.h
writeback.h writeback: Add tracepoint to track pending inode switches 2025-09-19 13:11:06 +02:00
xdp.h xdp: tracing: Hide some xdp events under CONFIG_BPF_SYSCALL 2025-06-12 19:36:53 -07:00
xen.h