Commit 4101b2fe authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Aichun Shi
Browse files

mm: Move mm_cachep initialization to mm_init()

stable inclusion
from stable-v5.10.189
commit 1ff14defdfc9180bfcfd76a70463a5feb188a5db
category: bugfix
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I8LVBS
CVE: N/A
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=1ff14defdfc9180bfcfd76a70463a5feb188a5db



-------------------------------------

Intel-SIG: commit 1ff14defdfc9 ("mm: Move mm_cachep initialization to mm_init()")
Backport x86 related patches from 5.10.189 upstream

-------------------------------------

commit af806027 upstream.

In order to allow using mm_alloc() much earlier, move initializing
mm_cachep into mm_init().

Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20221025201057.751153381@infradead.org


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarAichun Shi <aichun.shi@intel.com>
parent 1f90a7fd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ extern void sched_dead(struct task_struct *p);

void __noreturn do_task_dead(void);

extern void mm_cache_init(void);
extern void proc_caches_init(void);

extern void fork_init(void);
+1 −0
Original line number Diff line number Diff line
@@ -841,6 +841,7 @@ static void __init mm_init(void)
	init_espfix_bsp();
	/* Should be run after espfix64 is set up. */
	pti_init();
	mm_cache_init();
}

#ifdef CONFIG_RANDOMIZE_KSTACK_OFFSET
+18 −14
Original line number Diff line number Diff line
@@ -2934,10 +2934,27 @@ static void sighand_ctor(void *data)
	init_waitqueue_head(&sighand->signalfd_wqh);
}

void __init proc_caches_init(void)
void __init mm_cache_init(void)
{
	unsigned int mm_size;

	/*
	 * The mm_cpumask is located at the end of mm_struct, and is
	 * dynamically sized based on the maximum CPU number this system
	 * can have, taking hotplug into account (nr_cpu_ids).
	 */
	mm_size = MM_STRUCT_SIZE;

	mm_cachep = kmem_cache_create_usercopy("mm_struct",
			mm_size, ARCH_MIN_MMSTRUCT_ALIGN,
			SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT,
			OFFSET_OF_MM_SAVED_AUXV,
			SIZE_OF_MM_SAVED_AUXV,
			NULL);
}

void __init proc_caches_init(void)
{
	sighand_cachep = kmem_cache_create("sighand_cache",
			sizeof(struct sighand_struct), 0,
			SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU|
@@ -2955,19 +2972,6 @@ void __init proc_caches_init(void)
			SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT,
			NULL);

	/*
	 * The mm_cpumask is located at the end of mm_struct, and is
	 * dynamically sized based on the maximum CPU number this system
	 * can have, taking hotplug into account (nr_cpu_ids).
	 */
	mm_size = MM_STRUCT_SIZE;

	mm_cachep = kmem_cache_create_usercopy("mm_struct",
			mm_size, ARCH_MIN_MMSTRUCT_ALIGN,
			SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT,
			OFFSET_OF_MM_SAVED_AUXV,
			SIZE_OF_MM_SAVED_AUXV,
			NULL);
	vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC|SLAB_ACCOUNT);
	mmap_init();
	nsproxy_cache_init();