[RFC][PATCH 02/24] kernel/fork: Use sizeof() union instead of TASK_SIZE

From: Dave Hansen

Date: Wed Oct 21 2026 - 15:51:38 EST



thread_union is sized with TASK_SIZE. Instead of needing the definition
and this code to match, just use the thread_union size. This way, if the
thread union size changes, this code will still be correct.

Foreshadowing: shadow stack support will change the size of thread_union.

---

b/kernel/fork.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff -puN kernel/fork.c~alloc_thread_stack_node-2 kernel/fork.c
--- a/kernel/fork.c~alloc_thread_stack_node-2 2026-10-21 12:36:33.082871786 -0700
+++ b/kernel/fork.c 2026-10-21 12:36:33.085871792 -0700
@@ -315,7 +315,7 @@ static int memcg_charge_kernel_stack(str
int ret;
int nr_charged = 0;

- BUG_ON(vm_area->nr_pages != THREAD_SIZE / PAGE_SIZE);
+ BUG_ON(vm_area->nr_pages != sizeof(union thread_union) / PAGE_SIZE);

for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) {
ret = memcg_kmem_charge_page(vm_area->pages[i], GFP_KERNEL, 0);
@@ -332,7 +332,7 @@ err:

static void *__vmalloc_thread_stack_node(int node)
{
- return __vmalloc_node(THREAD_SIZE, THREAD_ALIGN,
+ return __vmalloc_node(sizeof(union thread_union), THREAD_ALIGN,
GFP_VMAP_STACK,
node, __builtin_return_address(0));
}
_