linux/include/trace/events
Kalesh Singh 079c24d569 mm/tracing: rss_stat: ensure curr is false from kthread context
The rss_stat trace event allows userspace tools, like Perfetto [1], to
inspect per-process RSS metric changes over time.

The curr field was introduced to rss_stat in commit e4dcad204d
("rss_stat: add support to detect RSS updates of external mm").  Its
intent is to indicate whether the RSS update is for the mm_struct of the
current execution context; and is set to false when operating on a remote
mm_struct (e.g., via kswapd or a direct reclaimer).

However, an issue arises when a kernel thread temporarily adopts a user
process's mm_struct.  Kernel threads do not have their own mm_struct and
normally have current->mm set to NULL.  To operate on user memory, they
can "borrow" a memory context using kthread_use_mm(), which sets
current->mm to the user process's mm.

This can be observed, for example, in the USB Function Filesystem (FFS)
driver.  The ffs_user_copy_worker() handles AIO completions and uses
kthread_use_mm() to copy data to a user-space buffer.  If a page fault
occurs during this copy, the fault handler executes in the kthread's
context.

At this point, current is the kthread, but current->mm points to the user
process's mm.  Since the rss_stat event (from the page fault) is for that
same mm, the condition current->mm == mm becomes true, causing curr to be
incorrectly set to true when the trace event is emitted.

This is misleading because it suggests the mm belongs to the kthread,
confusing userspace tools that track per-process RSS changes and
corrupting their mm_id-to-process association.

Fix this by ensuring curr is always false when the trace event is emitted
from a kthread context by checking for the PF_KTHREAD flag.

Link: https://lkml.kernel.org/r/20260219233708.1971199-1-kaleshsingh@google.com
Link: https://perfetto.dev/ [1]
Fixes: e4dcad204d ("rss_stat: add support to detect RSS updates of external mm")
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
Acked-by: Zi Yan <ziy@nvidia.com>
Acked-by: SeongJae Park <sj@kernel.org>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Cc: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: <stable@vger.kernel.org>	[5.10+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2026-02-24 11:13:27 -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 ASoC: asoc.h: convert to snd_soc_dapm_xxx() 2025-11-17 00:14:25 +00:00
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 btrfs: fix NULL dereference on root when tracing inode eviction 2025-12-16 22:53:14 +01:00
cachefiles.h
capability.h
ceph.h ceph: add trace points to the MDS client 2025-12-10 11:50:54 +01:00
cgroup.h cgroup: increase maximum subsystem count from 16 to 32 2026-02-01 06:34:15 -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/core: add trace point for damos stat per apply interval 2026-01-20 19:24:46 -08:00
devfreq.h
devlink.h
dlm.h
dma.h tracing/dma: Cap dma_map_sg tracepoint arrays to prevent buffer overflow 2026-02-02 08:41:17 +01:00
dma_buf.h dma-buf: add some tracepoints to debug. 2026-01-21 13:27:54 +01: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: pass inode to trace_erofs_read_folio 2026-01-23 20:02:09 +08:00
error_report.h
exceptions.h
ext4.h ext4: mark move extents fast-commit ineligible 2026-01-19 19:26:35 -05:00
f2fs.h f2fs: introduce trace_f2fs_priority_update 2026-01-31 03:24:55 +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
fsverity.h fsverity: add tracepoints 2026-01-29 16:00:57 +01:00
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/khugepaged: map dirty/writeback pages failures to EAGAIN 2026-01-26 20:02:12 -08: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: rename io_uring_queue_async_work event "rw" field 2025-12-04 07:18:02 -07: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 mm/tracing: rss_stat: ensure curr is false from kthread context 2026-02-24 11:13:27 -08: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
memory-failure.h mm/memory-failure: remove the selection of RAS 2025-11-24 15:08:55 -08:00
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 trace: mptcp: add mptcp_rcvbuf_grow tracepoint 2026-02-04 18:45:09 -08:00
napi.h
nbd.h
neigh.h
net.h net: add net cookie for net device trace events 2025-11-04 09:59:19 +01:00
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
pci.h PCI: trace: Add RAS tracepoint to monitor link speed changes 2025-12-23 16:06:00 -06:00
percpu.h
power.h PM: Introduce new PMSG_POWEROFF event 2025-11-14 17:05:53 +01: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
rpcrdma.h
rpm.h
rseq.h rseq: Cache CPU ID and MM CID values 2025-11-04 08:32:14 +01:00
rtc.h
rust_sample.h
rwmmio.h
rxrpc.h rxrpc: Fix recvmsg() unconditional requeue 2026-01-19 10:07:06 -08:00
sched.h tracing changes for 6.17 2025-08-01 10:29:36 -07:00
sched_ext.h sched_ext: Implement load balancer for bypass mode 2025-11-12 06:43:44 -10:00
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-mem.h spi: spi-mem: Trace exec_op 2025-10-27 11:10:50 +00:00
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 tcp: preserve const qualifier in tcp_rsk() and inet_rsk() 2026-01-21 19:20:04 -08: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 timers/migration: Rename 'online' bit to 'available' 2025-11-20 20:17:31 +01:00
timestamp.h
tlb.h x86/mm/tlb/trace: Export the TLB_REMOTE_WRONG_CPU enum in <trace/events/tlb.h> 2025-12-13 11:01:16 +01:00
tsm_mr.h
udp.h
v4l2.h
vb2.h
vmalloc.h
vmscan.h mm/vmscan: add tracepoint and reason for kswapd_failures reset 2026-01-31 14:22:38 -08:00
vsock_virtio_transport_common.h
watchdog.h
wbt.h
workqueue.h
writeback.h mm.git review status for linus..mm-stable 2026-02-12 11:32:37 -08:00
xdp.h xdp: tracing: Hide some xdp events under CONFIG_BPF_SYSCALL 2025-06-12 19:36:53 -07:00
xen.h