From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: "Harry Yoo (Meta)" <harry@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Alexei Starovoitov <ast@kernel.org>, Hao Li <hao.li@linux.dev>,
Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>
Cc: kernel-team@meta.com, cgroups@vger.kernel.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-rt-devel@lists.linux.dev, Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH for-next v3 0/7] memcg,slab: kmalloc_nolock() fixes
Date: Thu, 19 Nov 2026 15:45:34 +0100 [thread overview]
Message-ID: <f64021c9-21c2-43c9-a847-c44129d8ca75@kernel.org> (raw)
In-Reply-To: <20261115-kmalloc-nolock-fixes-v3-0-9034dd4ecaab@kernel.org>
On 11/15/26 16:09, Harry Yoo (Meta) wrote:
> This patchset fixes three kmalloc_nolock() bugs.
>
> 1. obj_cgroup_put() takes spinlocks in the release path when it drops
> the last reference, but it can be called from any context.
>
> 2. A spinlock may be taken in the following path and may lead
> to deadlock:
>
> kmalloc_nolock()
> -> slab_post_alloc_hook()
> -> memcg_slab_post_alloc_hook()
> -> memcg_alloc_abort_single().
>
> 3. irq_work_sync() is called without synchronization for rcuwait
> (on PREEMPT_RT or some architectures), potentially causing a
> hang.
>
> Bug 1 was reported by lockdep, and bugs 2 [1] and 3 [2] were
> reported by Sashiko.
>
> This series fixes the bugs by:
> - 1. Deferring obj_cgroup_release() to an irq work.
> - 2. Making slab_free_hook() and memcg_alloc_abort_single() respect
> SLAB_*_NOLOCK
> - 3. Serializing irq_work_sync() with a mutex
>
> Patch 1, 4, 5 are bugfixes and others are refactoring and cleanup
> patches.
>
> Changes in v3
> =============
>
> - Rebased onto the latest slab/for-next.
>
> - New patches and changes to existing patches were written and
> verified with AI assistance and carefully reviewed by Harry Yoo.
>
> - Patch 1: added Vlastimil's Reviewed-by (thanks!).
>
> - Patch 2 (new): pass free_flags to slab_free_hook() instead of adding
> a third bool, as suggested by Vlastimil.
>
> - Patch 3 (patch 2 in v2):
> - Now handles SLAB_FREE_NOLOCK in free_flags, so callers no longer
> need the allow_spin local variables.
> - Updated the subject accordingly.
> - Addressed v2 review comments from Vlastimil (thanks!):
> - dropped the memcg_alloc_abort_single() functional change from
> the changelog, as it does not change until patch 4.
>
> - Patch 4 (patch 4 in v2):
> - Try freeing the object to the percpu sheaves first in both
> contexts, as suggested by Alexei and Vlastimil. Dropped Vlastimil's
> Reviewed-by accordingly.
> - memcg_alloc_abort_single() now takes alloc_flags instead of a bool
> allow_spin, and converts them with a new to_free_flags() helper.
>
> - Patch 5 (patch 5 in v2): added Vlastimil's Acked-by.
>
> - Patch 6 (new): Make free_to_pcs() call can_free_to_pcs() and take
> free_flags instead of allow_spin.
>
> - Patch 7 (patch 3 in v2): moved to the end of the series, after the
> fixes. Reworded the comment.
>
> - Link to v2: https://lore.kernel.org/20261103-kmalloc-nolock-fixes-v2-0-19167cfe4779@kernel.org
>
> [1] https://sashiko.dev/#/patchset/20260610-slab_alloc_flags-v2-0-7190909db118%40kernel.org?part=9
> [2] https://sashiko.dev/#/patchset/20260615-kfree_rcu_nolock-v3-0-70a54f3775bb%40kernel.org?part=5
>
> ---
> Harry Yoo (Meta) (7):
> mm/memcontrol: defer obj_cgroup_release() to irq_work
> mm/slab: pass free_flags to slab_free_hook()
> mm/slab: handle SLAB_FREE_NOLOCK in slab_free_hook() instead of open coding
> mm/slab: fix a deadlock in memcg_alloc_abort_single()
> mm/slab: serialize deferred_work_barrier()
> mm/slab: refactor free_to_pcs()
> mm/slab: call debug_locks and KCSAN checks in kfree_nolock()
>
> include/linux/memcontrol.h | 2 +
> mm/memcontrol.c | 27 ++++-
> mm/slab.h | 14 ++-
> mm/slub.c | 247 ++++++++++++++++++++++++++-------------------
> 4 files changed, 180 insertions(+), 110 deletions(-)
Merged as slab/for-7.5/kmalloc-nolock
Rebased to
d866d5bafc5e ("Merge tag 'mm-hotfixes-stable-2026-11-17-19-55' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm")
to avoid conflicts with mainline
Nit for 6/7 resolved locally
> ---
> base-commit: a7cdd0af963a420fc0e6f20b7c8bc8d4784098db
> change-id: 20260624-kmalloc-nolock-fixes-c97675328773
>
> Best regards,
> --
> Cheers,
> Harry / Hyeonggon
>
prev parent reply other threads:[~2026-11-19 14:45 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 15:09 Harry Yoo (Meta)
2026-11-15 15:09 ` [PATCH for-next v3 1/7] mm/memcontrol: defer obj_cgroup_release() to irq_work Harry Yoo (Meta)
2026-11-15 15:09 ` [PATCH for-next v3 2/7] mm/slab: pass free_flags to slab_free_hook() Harry Yoo (Meta)
2026-11-18 15:21 ` Vlastimil Babka (SUSE)
2026-11-15 15:09 ` [PATCH for-next v3 3/7] mm/slab: handle SLAB_FREE_NOLOCK in slab_free_hook() instead of open coding Harry Yoo (Meta)
2026-11-16 8:26 ` sashiko-bot
2026-11-18 15:54 ` Vlastimil Babka (SUSE)
2026-11-15 15:09 ` [PATCH for-next v3 4/7] mm/slab: fix a deadlock in memcg_alloc_abort_single() Harry Yoo (Meta)
2026-11-18 16:24 ` Vlastimil Babka (SUSE)
2026-11-15 15:09 ` [PATCH for-next v3 5/7] mm/slab: serialize deferred_work_barrier() Harry Yoo (Meta)
2026-11-15 15:09 ` [PATCH for-next v3 6/7] mm/slab: refactor free_to_pcs() Harry Yoo (Meta)
2026-11-18 16:32 ` Vlastimil Babka (SUSE)
2026-11-15 15:09 ` [PATCH for-next v3 7/7] mm/slab: call debug_locks and KCSAN checks in kfree_nolock() Harry Yoo (Meta)
2026-11-18 16:58 ` Vlastimil Babka (SUSE)
2026-11-19 14:45 ` Vlastimil Babka (SUSE) [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f64021c9-21c2-43c9-a847-c44129d8ca75@kernel.org \
--to=vbabka@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=cgroups@vger.kernel.org \
--cc=cl@gentwo.org \
--cc=clrkwllms@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=rostedt@goodmis.org \
--cc=sashiko-bot@kernel.org \
--cc=shakeel.butt@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®