From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796454575; b=Bo81CWERPAEu8IC28ue/j2I2wkJDWqfhc6vACRiAW9Pl+o26d/RAI1e5TTSHZp79UR4r BRniDnQn+PFfbKl1W8B9nnBE9Ub1meuLyUVZOAHnLQwJ3RZMf1ydEn5FwuUSQtuJYFg8X 7RvLIIk97hKAkoy01NYx+UVzp2rZ7lmeaenaQo9cNoiCB8PXoXCCRIio0/jz4Md1s2UBt NwvHK5TD+L9BBeapvNWaMBBW44zAyWoT8aUWHGrVhU7KGuHj2ptsGOsbtqwagsGup/fO5 WJKh+xoyuNI65gBZ41E1svSBeZLEDf8WmqfyEInNJ0vvSHT7QDUnf+Fode+Y2+wee9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796454575; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=P8XGtR3SqmHkByHJfZJ6XOOGOlX/uqMXkEnq51Pnejk=; b=rL0bLSVviYZTA73Ptd9qFLUno3CiQoZu1G6BHoFcKWjWHDXgwTmnMURDSwEFNfZ67AHZ pIhjS8LiVFe53aWteTYSDF3tgk4H41ndosGsvgIG2r4np2zyUp2YI5FdCtaxV2EFFUyhw CAHoD12QYbJ9W5FTDX1rdUvLTbTledsEvQgwdD65m+qNhArZsKNwpZkBNYNvI7VTjpMyT Z160lSxhDG9zR1MRKI+xtwtd7ieDBo7nASSNxOG0CAT6gPQB5Xei/BcB2C7HudJ4OWElg cwwT/qISIuIMFVoEH6Wl79GR6fux9jQ4UIJfXkr4CthvBseJSlMgI5NvchQaJwsVbaA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=SIGZpl6s; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 790B1606A322 for ; Sat, 5 Dec 2026 07:09:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=SIGZpl6s Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDDB21F0092B; Sat, 5 Dec 2026 07:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796454575; bh=P8XGtR3SqmHkByHJfZJ6XOOGOlX/uqMXkEnq51Pnejk=; h=Date:To:From:In-Reply-To:References:Subject; b=SIGZpl6sX4lHxs6MnF3rCMTDA1Qo8YOdko8Hy2TgHCcrKc0i0AXZyzfHV+8+/6ku2 TcNepxNmiuG/c6YOUFdfPMShDgYa4Tt8ZUri5ZU5zVlsRigbD0zevmi5gB4wmQg9X7 RELkZPf1YzrISdSh64IupzDLeLW5Gh8EJrFVeOMk= Date: Fri, 04 Dec 2026 23:09:34 -0800 To: mm-commits@vger.kernel.org,vbabka@kernel.org,tj@kernel.org, roman.gushchin@linux.dev,muchun.song@linux.dev,mhocko@kernel.org, harry@kernel.org,hannes@cmpxchg.org,ast@kernel.org,shakeel.butt@linux.dev, akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261204215709.4129739-3-shakeel.butt@linux.dev> References: <20261204215709.4129739-3-shakeel.butt@linux.dev> Subject: + memcg-make-memcg_uncharge_kmem-nmi-safe.patch added to mm-new branch Message-Id: <20261205070934.EDDB21F0092B@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: memcg: make memcg_uncharge_kmem() NMI safe has been added to the -mm mm-new branch. Its filename is memcg-make-memcg_uncharge_kmem-nmi-safe.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/memcg-make-memcg_uncharge_kmem-nmi-safe.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Shakeel Butt Subject: memcg: make memcg_uncharge_kmem() NMI safe Date: Fri, 04 Dec 2026 13:57:09 -0800 On architectures where this_cpu operations are not NMI safe but atomics are (CONFIG_MEMCG_NMI_SAFETY_REQUIRES_ATOMIC), MEMCG_KMEM updates that can run in NMI must go through account_kmem_nmi_safe(). The objcg charge and uncharge paths do, but memcg_uncharge_kmem() still calls mod_memcg_state() directly. memcg_uncharge_kmem() runs in NMI when kmalloc_nolock() or kfree_nolock() has to evict an object stock slot that holds at least a page of charged bytes: __refill_obj_stock() drain_obj_stock_slot() memcg_uncharge_kmem() mod_memcg_state() If the NMI interrupted mod_memcg_state() on the same CPU, the nested read-modify-write of the per-CPU MEMCG_KMEM counter, or of the rstat update counter, loses one of the two updates. Use account_kmem_nmi_safe() in memcg_uncharge_kmem(). Outside NMI it still calls mod_memcg_state(), so nothing changes there. Hitting this needs slub_debug, because on these architectures kmalloc_nolock() only works on slab debug caches. It also needs a base page size below 64K, because an object stock slot holds at most U16_MAX bytes, and a kernel without PREEMPT_RT, where local_trylock() always fails in NMI. Kernels without commit afe9ae3fda96 ("mm: memcontrol: factor out memcg kmem uncharge sequence") have the same mod_memcg_state() call open-coded in drain_obj_stock_slot(), or in drain_obj_stock() in older ones. Backports to them need the change there. Link: https://patch.msgid.link/20261204215709.4129739-3-shakeel.butt@linux.dev Fixes: af92793e52c3 ("slab: Introduce kmalloc_nolock() and kfree_nolock().") Signed-off-by: Shakeel Butt Signed-off-by: Andrew Morton Cc: Johannes Weiner Cc: Michal Hocko Cc: Roman Gushchin Cc: Muchun Song Cc: Alexei Starovoitov Cc: Vlastimil Babka Cc: Harry Yoo Cc: Tejun Heo mm/memcontrol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/mm/memcontrol.c~memcg-make-memcg_uncharge_kmem-nmi-safe +++ a/mm/memcontrol.c @@ -136,10 +136,11 @@ bool mem_cgroup_kmem_disabled(void) } static void memcg_uncharge(struct mem_cgroup *memcg, unsigned int nr_pages); +static inline void account_kmem_nmi_safe(struct mem_cgroup *memcg, int val); static void memcg_uncharge_kmem(struct mem_cgroup *memcg, unsigned int nr_pages) { - mod_memcg_state(memcg, MEMCG_KMEM, -nr_pages); + account_kmem_nmi_safe(memcg, -nr_pages); memcg1_account_kmem(memcg, -nr_pages); if (!mem_cgroup_is_root(memcg)) memcg_uncharge(memcg, nr_pages); _ Patches currently in -mm which might be from shakeel.butt@linux.dev are memcg-move-memoryhigh-enforcement-out-of-try_charge_memcg.patch memcg-force-charges-from-reclaim-before-trying-the-limits.patch memcg-use-high_work-for-kernel-threads.patch memcg-use-high_work-for-remote-charges.patch memcg-simplify-high-limit-handling-after-a-charge.patch memcg-warn-when-memory-cgroup-ids-run-out.patch memcg-add-nmi-stat-deltas-before-marking-the-css-updated.patch memcg-make-memcg_uncharge_kmem-nmi-safe.patch kernfs-report-times-and-link-count-from-the-node-in-getattr.patch kernfs-dont-copy-times-and-link-count-into-the-inode-on-refresh.patch kernfs-dont-take-kernfs_iattr_rwsem-for-the-directory-counters.patch kernfs-dont-take-kernfs_iattr_rwsem-to-publish-kernfs_removing.patch kernfs-update-a-directorys-times-without-kernfs_iattr_rwsem.patch kernfs-dont-take-kernfs_iattr_rwsem-in-__kernfs_remove.patch cgroup-dont-lose-a-task-in-css_task_iter-when-a-migration-fails.patch cgroup-kill-a-child-forked-while-cgroupkill-runs.patch cgroup-refuse-cgroupkill-below-a-threaded-cgroup.patch cgroup-freezer-check-own-tasks-and-descendants-for-the-frozen-state.patch cgroup-freezer-dont-update-the-frozen-state-of-removed-cgroups.patch cgroup-freezer-test-the-freeze-trap-bit-under-siglock.patch selftests-cgroup-test-cgroupprocs-reads-across-a-failed-migration.patch selftests-cgroup-test-the-frozen-state-of-a-cgroup-with-tasks-and-children.patch selftests-cgroup-test-cgroupkill-in-and-below-a-threaded-cgroup.patch cgroup-factor-out-cgroup_kn_break_active-and-cgroup_kn_unbreak_active.patch cgroup-dont-hold-cgroup_mutex-for-cgroupkill.patch cgroup-freezer-dont-hold-cgroup_mutex-for-cgroupfreeze.patch kernfs-dont-look-for-open-files-of-directories-when-draining.patch kernfs-add-a-sequence-count-to-directories.patch kernfs-list-directories-without-kernfs_rwsem.patch percpu_ref-make-get-and-put-nmi-safe-where-this_cpu-ops-are-not.patch percpu_ref-defer-the-release-function-when-the-last-put-is-in-nmi.patch