Skip to content

Commit 20d49bf

Browse files
committed
Merge tag 'core-debugobjects-2020-10-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull debugobjects updates from Thomas Gleixner: "A small set of updates for debug objects: - Make all debug object descriptors constant. There is no reason to have them writeable. - Free the per CPU object pool after CPU unplug to avoid memory waste" * tag 'core-debugobjects-2020-10-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: debugobjects: Free per CPU pool after CPU unplug treewide: Make all debug_obj_descriptors const debugobjects: Allow debug_obj_descr to be const
2 parents 1e6d1d9 + 88451f2 commit 20d49bf

11 files changed

Lines changed: 69 additions & 43 deletions

File tree

drivers/gpu/drm/i915/i915_active.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void *active_debug_hint(void *addr)
8181
return (void *)ref->active ?: (void *)ref->retire ?: (void *)ref;
8282
}
8383

84-
static struct debug_obj_descr active_debug_desc = {
84+
static const struct debug_obj_descr active_debug_desc = {
8585
.name = "i915_active",
8686
.debug_hint = active_debug_hint,
8787
};

drivers/gpu/drm/i915/i915_sw_fence.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static void *i915_sw_fence_debug_hint(void *addr)
3434

3535
#ifdef CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS
3636

37-
static struct debug_obj_descr i915_sw_fence_debug_descr = {
37+
static const struct debug_obj_descr i915_sw_fence_debug_descr = {
3838
.name = "i915_sw_fence",
3939
.debug_hint = i915_sw_fence_debug_hint,
4040
};

include/linux/cpuhotplug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum cpuhp_state {
3636
CPUHP_X86_MCE_DEAD,
3737
CPUHP_VIRT_NET_DEAD,
3838
CPUHP_SLUB_DEAD,
39+
CPUHP_DEBUG_OBJ_DEAD,
3940
CPUHP_MM_WRITEBACK_DEAD,
4041
CPUHP_MM_VMSTAT_DEAD,
4142
CPUHP_SOFTIRQ_DEAD,

include/linux/debugobjects.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct debug_obj {
3030
enum debug_obj_state state;
3131
unsigned int astate;
3232
void *object;
33-
struct debug_obj_descr *descr;
33+
const struct debug_obj_descr *descr;
3434
};
3535

3636
/**
@@ -64,41 +64,41 @@ struct debug_obj_descr {
6464
};
6565

6666
#ifdef CONFIG_DEBUG_OBJECTS
67-
extern void debug_object_init (void *addr, struct debug_obj_descr *descr);
67+
extern void debug_object_init (void *addr, const struct debug_obj_descr *descr);
6868
extern void
69-
debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr);
70-
extern int debug_object_activate (void *addr, struct debug_obj_descr *descr);
71-
extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr);
72-
extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr);
73-
extern void debug_object_free (void *addr, struct debug_obj_descr *descr);
74-
extern void debug_object_assert_init(void *addr, struct debug_obj_descr *descr);
69+
debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr);
70+
extern int debug_object_activate (void *addr, const struct debug_obj_descr *descr);
71+
extern void debug_object_deactivate(void *addr, const struct debug_obj_descr *descr);
72+
extern void debug_object_destroy (void *addr, const struct debug_obj_descr *descr);
73+
extern void debug_object_free (void *addr, const struct debug_obj_descr *descr);
74+
extern void debug_object_assert_init(void *addr, const struct debug_obj_descr *descr);
7575

7676
/*
7777
* Active state:
7878
* - Set at 0 upon initialization.
7979
* - Must return to 0 before deactivation.
8080
*/
8181
extern void
82-
debug_object_active_state(void *addr, struct debug_obj_descr *descr,
82+
debug_object_active_state(void *addr, const struct debug_obj_descr *descr,
8383
unsigned int expect, unsigned int next);
8484

8585
extern void debug_objects_early_init(void);
8686
extern void debug_objects_mem_init(void);
8787
#else
8888
static inline void
89-
debug_object_init (void *addr, struct debug_obj_descr *descr) { }
89+
debug_object_init (void *addr, const struct debug_obj_descr *descr) { }
9090
static inline void
91-
debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr) { }
91+
debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr) { }
9292
static inline int
93-
debug_object_activate (void *addr, struct debug_obj_descr *descr) { return 0; }
93+
debug_object_activate (void *addr, const struct debug_obj_descr *descr) { return 0; }
9494
static inline void
95-
debug_object_deactivate(void *addr, struct debug_obj_descr *descr) { }
95+
debug_object_deactivate(void *addr, const struct debug_obj_descr *descr) { }
9696
static inline void
97-
debug_object_destroy (void *addr, struct debug_obj_descr *descr) { }
97+
debug_object_destroy (void *addr, const struct debug_obj_descr *descr) { }
9898
static inline void
99-
debug_object_free (void *addr, struct debug_obj_descr *descr) { }
99+
debug_object_free (void *addr, const struct debug_obj_descr *descr) { }
100100
static inline void
101-
debug_object_assert_init(void *addr, struct debug_obj_descr *descr) { }
101+
debug_object_assert_init(void *addr, const struct debug_obj_descr *descr) { }
102102

103103
static inline void debug_objects_early_init(void) { }
104104
static inline void debug_objects_mem_init(void) { }

kernel/rcu/rcu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static inline unsigned long rcu_seq_diff(unsigned long new, unsigned long old)
167167
# define STATE_RCU_HEAD_READY 0
168168
# define STATE_RCU_HEAD_QUEUED 1
169169

170-
extern struct debug_obj_descr rcuhead_debug_descr;
170+
extern const struct debug_obj_descr rcuhead_debug_descr;
171171

172172
static inline int debug_rcu_head_queue(struct rcu_head *head)
173173
{

kernel/rcu/update.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void destroy_rcu_head_on_stack(struct rcu_head *head)
469469
}
470470
EXPORT_SYMBOL_GPL(destroy_rcu_head_on_stack);
471471

472-
struct debug_obj_descr rcuhead_debug_descr = {
472+
const struct debug_obj_descr rcuhead_debug_descr = {
473473
.name = "rcu_head",
474474
.is_static_object = rcuhead_is_static_object,
475475
};

kernel/time/hrtimer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ EXPORT_SYMBOL_GPL(ktime_add_safe);
342342

343343
#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
344344

345-
static struct debug_obj_descr hrtimer_debug_descr;
345+
static const struct debug_obj_descr hrtimer_debug_descr;
346346

347347
static void *hrtimer_debug_hint(void *addr)
348348
{
@@ -401,7 +401,7 @@ static bool hrtimer_fixup_free(void *addr, enum debug_obj_state state)
401401
}
402402
}
403403

404-
static struct debug_obj_descr hrtimer_debug_descr = {
404+
static const struct debug_obj_descr hrtimer_debug_descr = {
405405
.name = "hrtimer",
406406
.debug_hint = hrtimer_debug_hint,
407407
.fixup_init = hrtimer_fixup_init,

kernel/time/timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ static void internal_add_timer(struct timer_base *base, struct timer_list *timer
611611

612612
#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
613613

614-
static struct debug_obj_descr timer_debug_descr;
614+
static const struct debug_obj_descr timer_debug_descr;
615615

616616
static void *timer_debug_hint(void *addr)
617617
{
@@ -707,7 +707,7 @@ static bool timer_fixup_assert_init(void *addr, enum debug_obj_state state)
707707
}
708708
}
709709

710-
static struct debug_obj_descr timer_debug_descr = {
710+
static const struct debug_obj_descr timer_debug_descr = {
711711
.name = "timer_list",
712712
.debug_hint = timer_debug_hint,
713713
.is_static_object = timer_is_static_object,

kernel/workqueue.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static void show_pwq(struct pool_workqueue *pwq);
427427

428428
#ifdef CONFIG_DEBUG_OBJECTS_WORK
429429

430-
static struct debug_obj_descr work_debug_descr;
430+
static const struct debug_obj_descr work_debug_descr;
431431

432432
static void *work_debug_hint(void *addr)
433433
{
@@ -477,7 +477,7 @@ static bool work_fixup_free(void *addr, enum debug_obj_state state)
477477
}
478478
}
479479

480-
static struct debug_obj_descr work_debug_descr = {
480+
static const struct debug_obj_descr work_debug_descr = {
481481
.name = "work_struct",
482482
.debug_hint = work_debug_hint,
483483
.is_static_object = work_is_static_object,

lib/debugobjects.c

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/slab.h>
2020
#include <linux/hash.h>
2121
#include <linux/kmemleak.h>
22+
#include <linux/cpu.h>
2223

2324
#define ODEBUG_HASH_BITS 14
2425
#define ODEBUG_HASH_SIZE (1 << ODEBUG_HASH_BITS)
@@ -90,7 +91,7 @@ static int debug_objects_pool_size __read_mostly
9091
= ODEBUG_POOL_SIZE;
9192
static int debug_objects_pool_min_level __read_mostly
9293
= ODEBUG_POOL_MIN_LEVEL;
93-
static struct debug_obj_descr *descr_test __read_mostly;
94+
static const struct debug_obj_descr *descr_test __read_mostly;
9495
static struct kmem_cache *obj_cache __read_mostly;
9596

9697
/*
@@ -223,7 +224,7 @@ static struct debug_obj *__alloc_object(struct hlist_head *list)
223224
* Must be called with interrupts disabled.
224225
*/
225226
static struct debug_obj *
226-
alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr)
227+
alloc_object(void *addr, struct debug_bucket *b, const struct debug_obj_descr *descr)
227228
{
228229
struct debug_percpu_free *percpu_pool = this_cpu_ptr(&percpu_obj_pool);
229230
struct debug_obj *obj;
@@ -433,6 +434,25 @@ static void free_object(struct debug_obj *obj)
433434
}
434435
}
435436

437+
#ifdef CONFIG_HOTPLUG_CPU
438+
static int object_cpu_offline(unsigned int cpu)
439+
{
440+
struct debug_percpu_free *percpu_pool;
441+
struct hlist_node *tmp;
442+
struct debug_obj *obj;
443+
444+
/* Remote access is safe as the CPU is dead already */
445+
percpu_pool = per_cpu_ptr(&percpu_obj_pool, cpu);
446+
hlist_for_each_entry_safe(obj, tmp, &percpu_pool->free_objs, node) {
447+
hlist_del(&obj->node);
448+
kmem_cache_free(obj_cache, obj);
449+
}
450+
percpu_pool->obj_free = 0;
451+
452+
return 0;
453+
}
454+
#endif
455+
436456
/*
437457
* We run out of memory. That means we probably have tons of objects
438458
* allocated.
@@ -475,7 +495,7 @@ static struct debug_bucket *get_bucket(unsigned long addr)
475495

476496
static void debug_print_object(struct debug_obj *obj, char *msg)
477497
{
478-
struct debug_obj_descr *descr = obj->descr;
498+
const struct debug_obj_descr *descr = obj->descr;
479499
static int limit;
480500

481501
if (limit < 5 && descr != descr_test) {
@@ -529,7 +549,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
529549
}
530550

531551
static void
532-
__debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
552+
__debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstack)
533553
{
534554
enum debug_obj_state state;
535555
bool check_stack = false;
@@ -587,7 +607,7 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
587607
* @addr: address of the object
588608
* @descr: pointer to an object specific debug description structure
589609
*/
590-
void debug_object_init(void *addr, struct debug_obj_descr *descr)
610+
void debug_object_init(void *addr, const struct debug_obj_descr *descr)
591611
{
592612
if (!debug_objects_enabled)
593613
return;
@@ -602,7 +622,7 @@ EXPORT_SYMBOL_GPL(debug_object_init);
602622
* @addr: address of the object
603623
* @descr: pointer to an object specific debug description structure
604624
*/
605-
void debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr)
625+
void debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr)
606626
{
607627
if (!debug_objects_enabled)
608628
return;
@@ -617,7 +637,7 @@ EXPORT_SYMBOL_GPL(debug_object_init_on_stack);
617637
* @descr: pointer to an object specific debug description structure
618638
* Returns 0 for success, -EINVAL for check failed.
619639
*/
620-
int debug_object_activate(void *addr, struct debug_obj_descr *descr)
640+
int debug_object_activate(void *addr, const struct debug_obj_descr *descr)
621641
{
622642
enum debug_obj_state state;
623643
struct debug_bucket *db;
@@ -695,7 +715,7 @@ EXPORT_SYMBOL_GPL(debug_object_activate);
695715
* @addr: address of the object
696716
* @descr: pointer to an object specific debug description structure
697717
*/
698-
void debug_object_deactivate(void *addr, struct debug_obj_descr *descr)
718+
void debug_object_deactivate(void *addr, const struct debug_obj_descr *descr)
699719
{
700720
struct debug_bucket *db;
701721
struct debug_obj *obj;
@@ -747,7 +767,7 @@ EXPORT_SYMBOL_GPL(debug_object_deactivate);
747767
* @addr: address of the object
748768
* @descr: pointer to an object specific debug description structure
749769
*/
750-
void debug_object_destroy(void *addr, struct debug_obj_descr *descr)
770+
void debug_object_destroy(void *addr, const struct debug_obj_descr *descr)
751771
{
752772
enum debug_obj_state state;
753773
struct debug_bucket *db;
@@ -797,7 +817,7 @@ EXPORT_SYMBOL_GPL(debug_object_destroy);
797817
* @addr: address of the object
798818
* @descr: pointer to an object specific debug description structure
799819
*/
800-
void debug_object_free(void *addr, struct debug_obj_descr *descr)
820+
void debug_object_free(void *addr, const struct debug_obj_descr *descr)
801821
{
802822
enum debug_obj_state state;
803823
struct debug_bucket *db;
@@ -838,7 +858,7 @@ EXPORT_SYMBOL_GPL(debug_object_free);
838858
* @addr: address of the object
839859
* @descr: pointer to an object specific debug description structure
840860
*/
841-
void debug_object_assert_init(void *addr, struct debug_obj_descr *descr)
861+
void debug_object_assert_init(void *addr, const struct debug_obj_descr *descr)
842862
{
843863
struct debug_bucket *db;
844864
struct debug_obj *obj;
@@ -886,7 +906,7 @@ EXPORT_SYMBOL_GPL(debug_object_assert_init);
886906
* @next: state to move to if expected state is found
887907
*/
888908
void
889-
debug_object_active_state(void *addr, struct debug_obj_descr *descr,
909+
debug_object_active_state(void *addr, const struct debug_obj_descr *descr,
890910
unsigned int expect, unsigned int next)
891911
{
892912
struct debug_bucket *db;
@@ -934,7 +954,7 @@ EXPORT_SYMBOL_GPL(debug_object_active_state);
934954
static void __debug_check_no_obj_freed(const void *address, unsigned long size)
935955
{
936956
unsigned long flags, oaddr, saddr, eaddr, paddr, chunks;
937-
struct debug_obj_descr *descr;
957+
const struct debug_obj_descr *descr;
938958
enum debug_obj_state state;
939959
struct debug_bucket *db;
940960
struct hlist_node *tmp;
@@ -1052,7 +1072,7 @@ struct self_test {
10521072
unsigned long dummy2[3];
10531073
};
10541074

1055-
static __initdata struct debug_obj_descr descr_type_test;
1075+
static __initconst const struct debug_obj_descr descr_type_test;
10561076

10571077
static bool __init is_static_object(void *addr)
10581078
{
@@ -1177,7 +1197,7 @@ check_results(void *addr, enum debug_obj_state state, int fixups, int warnings)
11771197
return res;
11781198
}
11791199

1180-
static __initdata struct debug_obj_descr descr_type_test = {
1200+
static __initconst const struct debug_obj_descr descr_type_test = {
11811201
.name = "selftest",
11821202
.is_static_object = is_static_object,
11831203
.fixup_init = fixup_init,
@@ -1367,6 +1387,11 @@ void __init debug_objects_mem_init(void)
13671387
} else
13681388
debug_objects_selftest();
13691389

1390+
#ifdef CONFIG_HOTPLUG_CPU
1391+
cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL,
1392+
object_cpu_offline);
1393+
#endif
1394+
13701395
/*
13711396
* Increase the thresholds for allocating and freeing objects
13721397
* according to the number of possible CPUs available in the system.

0 commit comments

Comments
 (0)