mm/slab, ipc: kmem_buckets kernel-doc and msg_msg accounting fixes
Subsystems (4)
v7 cover mm/slab, ipc: kmem_buckets kernel-doc and msg_msg accounting fixes
Hi!
As Vlastimil suggested[1], these are the first two patches of v6, split out for 7.4. The rest of the skb buckets series will come back for 7.5.
2/2 now keeps SLAB_ACCOUNT on the msg_msg bucket caches and allocates with GFP_KERNEL_ACCOUNT as well, so a msg_msg is charged with CONFIG_SLAB_BUCKETS either way.
Thanks!
-Kees
v7:
- split v6's 1/8 and 2/8 out for 7.4; 3/8 to 8/8 will return for 7.5 (Vlastimil)
- 2/2: keep SLAB_ACCOUNT in kmem_buckets_create(), and add Cc: stable (Vlastimil, Andrew, Harry)
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/
Kees Cook (2):
mm/slab: Mark the kmem_buckets_create() context as a Context: section ipc, msg: Account msg_msg allocations with GFP_KERNEL_ACCOUNT again
ipc/msgutil.c | 3 ++- mm/slab_common.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.55.0
PATCH v7 1/2 mm/slab: Mark the kmem_buckets_create() context as a Context: section
kmem_buckets_create() had the same sentence about calling context as kmem_cache_create(), but lacked the "Context:" prefix, so kernel-doc rendered in the body instead of as a "context" section.
Give it the missing prefix. Additionally fix the "a interrupt" typo __kmem_cache_create_args() had.
--- mm/slab_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/slab_common.c +2 -2
@@ -311,7 +311,7 @@ __kmem_cache_alias(const char *name, unsigned int size, slab_flags_t flags,* &SLAB_TYPESAFE_BY_RCU - Slab page (not individual objects) freeing delayed * by a grace period - see the full description before using. * -* Context: Cannot be called within a interrupt, but can be interrupted. +* Context: Cannot be called within an interrupt, but can be interrupted. * * Return: a pointer to the cache on success, NULL on failure. */
@@ -422,7 +422,7 @@ static struct kmem_cache *kmem_buckets_cache __ro_after_init;* to/from userspace. * @ctor: A constructor for the objects, run when new allocations are made. * -* Cannot be called within an interrupt, but can be interrupted. +* Context: Cannot be called within an interrupt, but can be interrupted. * * Return: a pointer to the cache on success, NULL on failure. When * CONFIG_SLAB_BUCKETS is not enabled, ZERO_SIZE_PTR is returned, and
Signature · 1 line
2.55.0
PATCH v7 2/2 ipc, msg: Account msg_msg allocations with GFP_KERNEL_ACCOUNT again
In reply to Kees CookSince commit 734bbc1c97ea7 ("ipc, msg: Use dedicated slab buckets for alloc_msg()"), alloc_msg() allocates with GFP_KERNEL, and a msg_msg is accounted only through SLAB_ACCOUNT on its bucket caches. With CONFIG_SLAB_BUCKETS=n, kmem_buckets_create() creates no caches and kmem_buckets_alloc() is a GFP_KERNEL kmalloc() from the general caches, which do not account it; the same happens when kmem_buckets_create() fails. Either way, the allocation is not charged to the sender's memory cgroup.
Allocate with GFP_KERNEL_ACCOUNT again, as before that commit, so the allocation is charged whichever cache serves it.
Build tested ARCH=x86_64 defconfig with GCC 16.2.0, with CONFIG_SLAB_BUCKETS as y and n.
--- ipc/msgutil.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
ipc/msgutil.c +2 -1
@@ -58,7 +58,8 @@ static struct msg_msg *alloc_msg(size_t len)size_t alen; alen =min (len,DATALEN_MSG ); - msg =kmem_buckets_alloc (msg_buckets,sizeof (*msg) + alen,GFP_KERNEL ); + msg =kmem_buckets_alloc (msg_buckets,sizeof (*msg) + alen, +GFP_KERNEL_ACCOUNT );if (msg ==NULL )return NULL ;
Signature · 1 line
2.55.0
Re: [PATCH v7 2/2] ipc, msg: Account msg_msg allocations with GFP_KERNEL_ACCOUNT again
Quoted 12 lines · Kees Cook
Since commit
734bbc1c97ea7("ipc, msg: Use dedicated slab buckets foralloc_msg()"),alloc_msg()allocates withGFP_KERNEL, and amsg_msgis accounted only throughSLAB_ACCOUNTon its bucket caches. WithCONFIG_SLAB_BUCKETS=n,kmem_buckets_create()creates no caches andkmem_buckets_alloc()is aGFP_KERNELkmalloc()from the general caches, which do not account it; the same happens whenkmem_buckets_create()fails. Either way, the allocation is not charged to the sender's memory cgroup.Allocate with
GFP_KERNEL_ACCOUNTagain, as before that commit, so the allocation is charged whichever cache serves it.
Quoted 6 lines
Build tested ARCH=x86_64 defconfig with GCC 16.2.0, with
CONFIG_SLAB_BUCKETSas y and n.Fixes 734bbc1c97ea7 ("ipc, msg: Use dedicated slab buckets for alloc_msg()")Signed-off-by Kees Cook <[email protected]>
Looks good to me,
Thanks!
Re: [PATCH v7 2/2] ipc, msg: Account msg_msg allocations with GFP_KERNEL_ACCOUNT again
In reply to Kees CookQuoted 12 lines · Kees Cook
Since commit
734bbc1c97ea7("ipc, msg: Use dedicated slab buckets foralloc_msg()"),alloc_msg()allocates withGFP_KERNEL, and amsg_msgis accounted only throughSLAB_ACCOUNTon its bucket caches. WithCONFIG_SLAB_BUCKETS=n,kmem_buckets_create()creates no caches andkmem_buckets_alloc()is aGFP_KERNELkmalloc()from the general caches, which do not account it; the same happens whenkmem_buckets_create()fails. Either way, the allocation is not charged to the sender's memory cgroup.Allocate with
GFP_KERNEL_ACCOUNTagain, as before that commit, so the allocation is charged whichever cache serves it.
Quoted 6 lines
Build tested ARCH=x86_64 defconfig with GCC 16.2.0, with
CONFIG_SLAB_BUCKETSas y and n.Fixes 734bbc1c97ea7 ("ipc, msg: Use dedicated slab buckets for alloc_msg()")Signed-off-by Kees Cook <[email protected]>
Signature · 1 line
Pedro
Quoted 8 lines · Kees Cook
As Vlastimil suggested[1], these are the first two patches of v6, split out for 7.4. The rest of the skb buckets series will come back for 7.5.
2/2 now keeps
SLAB_ACCOUNTon themsg_msgbucket caches and allocates withGFP_KERNEL_ACCOUNTas well, so amsg_msgis charged withCONFIG_SLAB_BUCKETSeither way.[...]
Applied to mm/slab.git slab/for-7.4/misc, thanks!
[1/2] mm/slab: Mark the kmem_buckets_create() context as a Context: section
commit: 655668f0caf32a42fef10aaf31137e52f46a0260
[2/2] ipc, msg: Account msg_msg allocations with GFP_KERNEL_ACCOUNT again
commit: 49c0b3dedf7c8c64e432e63dd7b24f00909916d8Best regards,
Signature · 1 line
Vlastimil Babka (SUSE) <[email protected]>