mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Leizhen (ThunderTown)" <thunder.leizhen@huawei.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>
Cc: Waiman Long <longman@redhat.com>
Subject: Re: [patch 03/25] debugobjects: Dont destroy kmem cache in init()
Date: Thu, 10 Oct 2024 10:14:05 +0800	[thread overview]
Message-ID: <c118dad2-4e39-78f2-c09b-0fe771feb86a@huawei.com> (raw)
In-Reply-To: <20241007164913.137021337@linutronix.de>



On 2024/10/8 0:49, Thomas Gleixner wrote:
> debug_objects_mem_init() is invoked from mm_core_init() before work queues
> are available. If debug_objects_mem_init() destroys the kmem cache in the
> error path it causes an Oops in __queue_work():
> 
>  Oops: Oops: 0000 [#1] PREEMPT SMP PTI
>  RIP: 0010:__queue_work+0x35/0x6a0
>   queue_work_on+0x66/0x70
>   flush_all_cpus_locked+0xdf/0x1a0
>   __kmem_cache_shutdown+0x2f/0x340
>   kmem_cache_destroy+0x4e/0x150
>   mm_core_init+0x9e/0x120
>   start_kernel+0x298/0x800
>   x86_64_start_reservations+0x18/0x30
>   x86_64_start_kernel+0xc5/0xe0
>   common_startup_64+0x12c/0x138
> 
> Further the object cache pointer is used in various places to check for
> early boot operation. It is exposed before the replacments for the static
> boot time objects are allocated and the self test operates on it.
> 
> This can be avoided by:
> 
>      1) Running the self test with the static boot objects
> 
>      2) Exposing it only after the replacement objects have been added to
>      	the pool.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  lib/debugobjects.c |   68 +++++++++++++++++++++++++++--------------------------
>  1 file changed, 35 insertions(+), 33 deletions(-)
> 
> --- a/lib/debugobjects.c
> +++ b/lib/debugobjects.c
> @@ -1211,7 +1211,7 @@ static __initconst const struct debug_ob
>  
>  static __initdata struct self_test obj = { .static_init = 0 };
>  
> -static void __init debug_objects_selftest(void)
> +static bool __init debug_objects_selftest(void)
>  {
>  	int fixups, oldfixups, warnings, oldwarnings;
>  	unsigned long flags;
> @@ -1280,9 +1280,10 @@ static void __init debug_objects_selftes
>  	descr_test = NULL;
>  
>  	local_irq_restore(flags);
> +	return !!debug_objects_enabled;
>  }
>  #else
> -static inline void debug_objects_selftest(void) { }
> +static inline bool debug_objects_selftest(void) { return true; }
>  #endif
>  
>  /*
> @@ -1302,18 +1303,21 @@ void __init debug_objects_early_init(voi
>  }
>  
>  /*
> - * Convert the statically allocated objects to dynamic ones:
> + * Convert the statically allocated objects to dynamic ones.
> + * debug_objects_mem_init() is called early so only one CPU is up and
> + * interrupts are disabled, which means it is safe to replace the active
> + * object references.
>   */
> -static int __init debug_objects_replace_static_objects(void)
> +static bool __init debug_objects_replace_static_objects(struct kmem_cache *cache)
>  {
>  	struct debug_bucket *db = obj_hash;
> -	struct hlist_node *tmp;
>  	struct debug_obj *obj, *new;
> +	struct hlist_node *tmp;
>  	HLIST_HEAD(objects);
>  	int i, cnt = 0;
>  
>  	for (i = 0; i < ODEBUG_POOL_SIZE; i++) {
> -		obj = kmem_cache_zalloc(obj_cache, GFP_KERNEL);
> +		obj = kmem_cache_zalloc(cache, GFP_KERNEL);
>  		if (!obj)
>  			goto free;
>  		hlist_add_head(&obj->node, &objects);
> @@ -1322,12 +1326,6 @@ static int __init debug_objects_replace_
>  	debug_objects_allocated += i;
>  
>  	/*
> -	 * debug_objects_mem_init() is now called early that only one CPU is up
> -	 * and interrupts have been disabled, so it is safe to replace the
> -	 * active object references.
> -	 */
> -
> -	/*
>  	 * Replace the statically allocated objects list with the allocated
>  	 * objects list.
>  	 */
> @@ -1347,15 +1345,14 @@ static int __init debug_objects_replace_
>  		}
>  	}
>  
> -	pr_debug("%d of %d active objects replaced\n",
> -		 cnt, obj_pool_used);
> -	return 0;
> +	pr_debug("%d of %d active objects replaced\n", cnt, obj_pool_used);
> +	return true;
>  free:
>  	hlist_for_each_entry_safe(obj, tmp, &objects, node) {
>  		hlist_del(&obj->node);
> -		kmem_cache_free(obj_cache, obj);
> +		kmem_cache_free(cache, obj);
>  	}
> -	return -ENOMEM;
> +	return false;
>  }
>  
>  /*
> @@ -1366,6 +1363,7 @@ static int __init debug_objects_replace_
>   */
>  void __init debug_objects_mem_init(void)
>  {
> +	struct kmem_cache *cache;
>  	int cpu, extras;
>  
>  	if (!debug_objects_enabled)
> @@ -1380,29 +1378,33 @@ void __init debug_objects_mem_init(void)
>  	for_each_possible_cpu(cpu)
>  		INIT_HLIST_HEAD(&per_cpu(percpu_obj_pool.free_objs, cpu));
>  
> -	obj_cache = kmem_cache_create("debug_objects_cache",
> -				      sizeof (struct debug_obj), 0,
> -				      SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE,
> -				      NULL);
> +	if (!debug_objects_selftest())
> +		return;
> +
> +	cache = kmem_cache_create("debug_objects_cache", sizeof (struct debug_obj), 0,
> +				  SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE, NULL);
>  
> -	if (!obj_cache || debug_objects_replace_static_objects()) {
> +	if (!cache || !debug_objects_replace_static_objects(cache)) {
>  		debug_objects_enabled = 0;
> -		kmem_cache_destroy(obj_cache);

kmem_cache_destroy(cache) should be kept, or move it into debug_objects_replace_static_objects()
and place it above 'return false'.

> -		pr_warn("out of memory.\n");
> +		pr_warn("Out of memory.\n");
>  		return;
> -	} else
> -		debug_objects_selftest();
> -
> -#ifdef CONFIG_HOTPLUG_CPU
> -	cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL,
> -					object_cpu_offline);
> -#endif
> +	}
>  
>  	/*
> -	 * Increase the thresholds for allocating and freeing objects
> -	 * according to the number of possible CPUs available in the system.
> +	 * Adjust the thresholds for allocating and freeing objects
> +	 * according to the number of possible CPUs available in the
> +	 * system.
>  	 */
>  	extras = num_possible_cpus() * ODEBUG_BATCH_SIZE;
>  	debug_objects_pool_size += extras;
>  	debug_objects_pool_min_level += extras;
> +
> +	/* Everything worked. Expose the cache */
> +	obj_cache = cache;
> +
> +#ifdef CONFIG_HOTPLUG_CPU
> +	cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL,
> +				  object_cpu_offline);
> +#endif
> +	return;
>  }
> 
> .
> 

-- 
Regards,
  Zhen Lei

  reply	other threads:[~2024-10-10  2:14 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-07 16:49 [patch 00/25] debugobjects: Rework object handling Thomas Gleixner
2024-10-07 16:49 ` [patch 01/25] debugobjects: Delete a piece of redundant code Thomas Gleixner
2024-10-07 16:49 ` [patch 02/25] debugobjects: Collect newly allocated objects in a list to reduce lock contention Thomas Gleixner
2024-10-07 16:49 ` [patch 03/25] debugobjects: Dont destroy kmem cache in init() Thomas Gleixner
2024-10-10  2:14   ` Leizhen (ThunderTown) [this message]
2024-10-10 11:46     ` Thomas Gleixner
2024-10-10 13:31       ` Leizhen (ThunderTown)
2024-10-11 20:37         ` Thomas Gleixner
2024-10-12  1:50           ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:49 ` [patch 04/25] debugobjects: Remove pointless hlist initialization Thomas Gleixner
2024-10-10  2:19   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:49 ` [patch 05/25] debugobjects: Dont free objects directly on CPU hotplug Thomas Gleixner
2024-10-10  2:33   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:49 ` [patch 06/25] debugobjects: Reuse put_objects() on OOM Thomas Gleixner
2024-10-10  2:38   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:49 ` [patch 07/25] debugobjects: Remove pointless debug printk Thomas Gleixner
2024-10-10  2:44   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 08/25] debugobjects: Provide and use free_object_list() Thomas Gleixner
2024-10-10  2:54   ` Leizhen (ThunderTown)
2024-10-11 20:40     ` Thomas Gleixner
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 09/25] debugobjects: Make debug_objects_enabled bool Thomas Gleixner
2024-10-10  3:00   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 10/25] debugobjects: Reduce parallel pool fill attempts Thomas Gleixner
2024-10-07 16:50 ` [patch 11/25] debugobjects: Move pools into a datastructure Thomas Gleixner
2024-10-10  3:47   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 12/25] debugobjects: Use separate list head for boot pool Thomas Gleixner
2024-10-10  4:04   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 13/25] debugobjects: Rename and tidy up per CPU pools Thomas Gleixner
2024-10-10  6:23   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 14/25] debugobjects: Move min/max count into pool struct Thomas Gleixner
2024-10-10  6:26   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 15/25] debugobjects: Rework object allocation Thomas Gleixner
2024-10-10  6:39   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 16/25] debugobjects: Rework object freeing Thomas Gleixner
2024-10-10  7:39   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 17/25] debugobjects: Rework free_object_work() Thomas Gleixner
2024-10-10  8:10   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 18/25] debugobjects: Use static key for boot pool selection Thomas Gleixner
2024-10-10  8:12   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 19/25] debugobjects: Prepare for batching Thomas Gleixner
2024-10-10  8:15   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 20/25] debugobjects: Prepare kmem_cache allocations " Thomas Gleixner
2024-10-10  8:40   ` Leizhen (ThunderTown)
2024-10-11 20:47     ` Thomas Gleixner
2024-10-12  2:02       ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 21/25] debugobjects: Implement batch processing Thomas Gleixner
2024-10-10  9:39   ` Leizhen (ThunderTown)
2024-10-11 20:48     ` Thomas Gleixner
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 22/25] debugobjects: Move pool statistics into global_pool struct Thomas Gleixner
2024-10-10  9:50   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 23/25] debugobjects: Double the per CPU slots Thomas Gleixner
2024-10-10  9:51   ` Leizhen (ThunderTown)
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 24/25] debugobjects: Refill per CPU pool more agressively Thomas Gleixner
2024-10-10 10:02   ` Leizhen (ThunderTown)
2024-10-11 20:49     ` Thomas Gleixner
2024-10-15 15:36   ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 25/25] debugobjects: Track object usage to avoid premature freeing of objects Thomas Gleixner
2024-10-10 13:13   ` Leizhen (ThunderTown)
2024-10-13 18:45     ` Thomas Gleixner
2024-10-14  1:46       ` Leizhen (ThunderTown)
2024-10-15 15:36       ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c118dad2-4e39-78f2-c09b-0fe771feb86a@huawei.com \
    --to=thunder.leizhen@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®