Linux Documentation
 help / color / mirror / Atom feed
* Re: [RFC PATCH] mm/oom_kill: optionally log victim command-line arguments on OOM kill
       [not found] <20261124205043.1010247-1-atomlin@atomlin.com>
@ 2026-11-25 15:33 ` Lorenzo Stoakes (ARM)
  2026-11-25 16:20   ` Aaron Tomlin
  0 siblings, 1 reply; 2+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-25 15:33 UTC (permalink / raw)
  To: Aaron Tomlin
  Cc: david, corbet, akpm, liam, vbabka, rppt, surenb, mhocko, skhan,
	rdunlap, rientjes, shakeel.butt, sean, neelx, linux-mm, linux-doc

Nackity nackity NACK NACK NACK!

This is terribly, horribly broken both in concept and implementation.

On Tue, Nov 24, 2026 at 03:50:43PM -0500, Aaron Tomlin wrote:
> When the OOM killer terminates a task in __oom_kill_process(), the
> kernel log records only victim->comm alongside its PID and memory
> counters. Because comm[] is truncated to TASK_COMM_LEN and typically
> reflects the interpreter binary rather than the executed programme or
> script (e.g. "python3" instead of /usr/bin/python3 -sP
> /usr/bin/firewalld --nofork --nopid), identifying which service or
> worker instance was killed during post-mortem analysis is often
> difficult once the process has exited and /proc/[pid]/cmdline is gone.
>
> The standard get_cmdline() helper cannot be called from
> __oom_kill_process(). OOM kill paths run whilst holding oom_lock, so
> blocking on mmap_read_lock_killable() risks deadlocking against a
> thread holding mmap_write_lock() whilst waiting for memory allocation
> on oom_lock. Furthermore, get_cmdline() walks user pages via
> access_process_vm(), which triggers page faults, memory allocations,
> and swap-in I/O during an active OOM condition, and drops an mm_users
> reference via mmput() that could run synchronous exit_mmap() teardown
> under oom_lock.

Also, fiddling with the memory of a soon-to-die process under extreme
memory pressure is insane, additionally _holding that lock_ under memory
pressure is insane.

>
> Introduce an opt-in vm.oom_dump_cmdline sysctl (documented in
> Documentation/admin-guide/sysctl/vm.rst), disabled by default to

'Have mm people support my code literally forever'... and make it an ABI
requirement too!

> preserve existing behaviour and avoid exposing potentially sensitive
> command-line arguments unless explicitly requested by the
> administrator. When enabled on CONFIG_MMU builds, __oom_kill_process()
> attempts a best-effort, non-blocking read of the victim's resident
> argument vector (including setproctitle(3) updates inspected via
> arg_end - 1) after releasing task_lock(victim). It snapshots the
> argument and environment bounds under mm->arg_lock, acquires mmap_lock
> via mmap_read_trylock(), bails out if MMF_OOM_SKIP or MMF_UNSTABLE is
> set, and walks only present, non-PageHWPoison() anonymous page table
> entries via folio_walk_start() without faulting or allocating memory.
> After dropping the page table lock, each pinned subpage is flushed via
> flush_anon_page() and copied across kmap_local_page() and
> copy_from_user_page(), and mmap_lock is released prior to calling
> printk.

Ah the giant slabs of impenetrable text that reviewers are supposed to read in
detail now... LLMs really have a lot to answer for.

You (or far more likely your LLM) is just describing the (horribly broken)
code in English here.

I hate how often I have to read this stuff...

>
> To preserve backwards compatibility with monitoring tools that parse
> the existing "Killed process %d (%s) ..." message, leave that line
> untouched and emit a separate rate-limited companion line sanitised
> with %*pE when resident argument bytes are recovered. For example:
>
>     [  124.819203] Out of memory: Killed process 1482 (python3) total-vm:184320kB, anon-rss:42100kB, ...
>     [  124.819215] Out of memory: Process 1482 (python3) cmdline: /usr/bin/python3 -sP /usr/bin/firewalld --nofork --nopid
>

Doubling the output in a way that is super confusing, great! :)

> Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>

This patch is broken in a million different ways.

The process gets sent SIGKILL and _then_ you race it to take the mmap read
lock, which prevents the reaper from running?

You do a lock inversion between oom_lock and the mmap_lock, and hope it'll
be OK?

You take a heavy rwsem lock while the system is under extreme memory
pressure? Which, again, prevents the reaper getting to it?

You do heavy operations during one of the most sensitive, dangerous times
for a kernel for a nice-to-have annotation?

And dump_oom_victim() already outputs memcg information, which systemd
uses, your example mentions firewalld so likely that'd _already_ give you
the kind of information you are interested in (except for mutliple
workers).

You're adding a ton of totally broken complexity then, insanely, making it
a global sysctl flag that we have to support forever as an ABI too.

You intentionally abuse folio_walk_start() to do _what its kdoc tells you
not to_:

 * This function must *not* be used as a naive replacement for
 * get_user_pages() / pin_user_pages(), especially not to perform DMA or
 * to carelessly modify page content. This function may *only* be used to grab
 * short-term folio references, never to grab long-term folio references.

You're (or more likely your LLM) is literally copy/pasting code from
__access_remote_vm() combined with this mad abuse of folio_walk_*() as a
proto-GUP to... get more info about a killed process.

You also copy/pasted wrong so this is even more subtly broken.

You are also potentially exposing sensitive information. Your ratelimiting
is broken.

Oh and of course, you add 256 bytes to the VERY limited kernel stack at the
point of an OOMK.

I mean I could go on. Even the concept here is fundamentally broken, so
please don't waste our time with respins.

Thanks.

> ---
>  Documentation/admin-guide/sysctl/vm.rst |  30 ++++
>  mm/oom_kill.c                           | 206 ++++++++++++++++++++++++
>  2 files changed, 236 insertions(+)

Of course it's also a massive patch...

--
Cheers, Lorenzo

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [RFC PATCH] mm/oom_kill: optionally log victim command-line arguments on OOM kill
  2026-11-25 15:33 ` [RFC PATCH] mm/oom_kill: optionally log victim command-line arguments on OOM kill Lorenzo Stoakes (ARM)
@ 2026-11-25 16:20   ` Aaron Tomlin
  0 siblings, 0 replies; 2+ messages in thread
From: Aaron Tomlin @ 2026-11-25 16:20 UTC (permalink / raw)
  To: Lorenzo Stoakes (ARM)
  Cc: david, corbet, akpm, liam, vbabka, rppt, surenb, mhocko, skhan,
	rdunlap, rientjes, shakeel.butt, sean, neelx, linux-mm, linux-doc

On Wed, Nov 25, 2026 at 03:33:28PM +0000, Lorenzo Stoakes (ARM) wrote:
> Nackity nackity NACK NACK NACK!
> 
> This is terribly, horribly broken both in concept and implementation.

Hi Lorenzo,

Fair enough.

For context, using mmap_read_trylock() before queue_oom_reaper() was
intentional to avoid blocking under oom_lock, which is why I sent it as an
RFC. That said, I take your point: touching mmap_lock and walking page
tables via folio_walk_start() in __oom_kill_process(), along with the stack
footprint and adding a new vm sysctl ABI, is the wrong trade-off at OOM
time when dump_oom_victim() provides memcg context.

Thanks for taking a look.

Kind regards,
-- 
Aaron Tomlin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-25 16:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261124205043.1010247-1-atomlin@atomlin.com>
2026-11-25 15:33 ` [RFC PATCH] mm/oom_kill: optionally log victim command-line arguments on OOM kill Lorenzo Stoakes (ARM)
2026-11-25 16:20   ` Aaron Tomlin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox