Skip to content

Commit 6b839b3

Browse files
diandersakpm00
authored andcommitted
regset: use kvzalloc() for regset_get_alloc()
While browsing through ChromeOS crash reports, I found one with an allocation failure that looked like this: chrome: page allocation failure: order:7, mode:0x40dc0(GFP_KERNEL|__GFP_COMP|__GFP_ZERO), nodemask=(null),cpuset=urgent,mems_allowed=0 CPU: 7 PID: 3295 Comm: chrome Not tainted 5.15.133-20574-g8044615ac35c #1 (HASH:1162 1) Hardware name: Google Lazor (rev3 - 8) with KB Backlight (DT) Call trace: ... warn_alloc+0x104/0x174 __alloc_pages+0x5f0/0x6e4 kmalloc_order+0x44/0x98 kmalloc_order_trace+0x34/0x124 __kmalloc+0x228/0x36c __regset_get+0x68/0xcc regset_get_alloc+0x1c/0x28 elf_core_dump+0x3d8/0xd8c do_coredump+0xeb8/0x1378 get_signal+0x14c/0x804 ... An order 7 allocation is (1 << 7) contiguous pages, or 512K. It's not a surprise that this allocation failed on a system that's been running for a while. More digging showed that it was fairly easy to see the order 7 allocation by just sending a SIGQUIT to chrome (or other processes) to generate a core dump. The actual amount being allocated was 279,584 bytes and it was for "core_note_type" NT_ARM_SVE. There was quite a bit of discussion [1] on the mailing lists in response to my v1 patch attempting to switch to vmalloc. The overall conclusion was that we could likely reduce the 279,584 byte allocation by quite a bit and Mark Brown has sent a patch to that effect [2]. However even with the 279,584 byte allocation gone there are still 65,552 byte allocations. These are just barely more than the 65,536 bytes and thus would require an order 5 allocation. An order 5 allocation is still something to avoid unless necessary and nothing needs the memory here to be contiguous. Change the allocation to kvzalloc() which should still be efficient for small allocations but doesn't force the memory subsystem to work hard (and maybe fail) at getting a large contiguous chunk. [1] https://lore.kernel.org/r/20240201171159.1.Id9ad163b60d21c9e56c2d686b0cc9083a8ba7924@changeid [2] https://lore.kernel.org/r/20240203-arm64-sve-ptrace-regset-size-v1-1-2c3ba1386b9e@kernel.org Link: https://lkml.kernel.org/r/20240205092626.v2.1.Id9ad163b60d21c9e56c2d686b0cc9083a8ba7924@changeid Signed-off-by: Douglas Anderson <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Cc: Al Viro <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Dave Martin <[email protected]> Cc: Eric Biederman <[email protected]> Cc: Jan Kara <[email protected]> Cc: Kees Cook <[email protected]> Cc: Mark Brown <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent f9899c0 commit 6b839b3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

fs/binfmt_elf.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ static void free_note_info(struct elf_note_info *info)
19281928
threads = t->next;
19291929
WARN_ON(t->notes[0].data && t->notes[0].data != &t->prstatus);
19301930
for (i = 1; i < info->thread_notes; ++i)
1931-
kfree(t->notes[i].data);
1931+
kvfree(t->notes[i].data);
19321932
kfree(t);
19331933
}
19341934
kfree(info->psinfo.data);

kernel/regset.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ static int __regset_get(struct task_struct *target,
1616
if (size > regset->n * regset->size)
1717
size = regset->n * regset->size;
1818
if (!p) {
19-
to_free = p = kzalloc(size, GFP_KERNEL);
19+
to_free = p = kvzalloc(size, GFP_KERNEL);
2020
if (!p)
2121
return -ENOMEM;
2222
}
2323
res = regset->regset_get(target, regset,
2424
(struct membuf){.p = p, .left = size});
2525
if (res < 0) {
26-
kfree(to_free);
26+
kvfree(to_free);
2727
return res;
2828
}
2929
*data = p;
@@ -71,6 +71,6 @@ int copy_regset_to_user(struct task_struct *target,
7171
ret = regset_get_alloc(target, regset, size, &buf);
7272
if (ret > 0)
7373
ret = copy_to_user(data, buf, ret) ? -EFAULT : 0;
74-
kfree(buf);
74+
kvfree(buf);
7575
return ret;
7676
}

0 commit comments

Comments
 (0)