Skip to content

Commit

Permalink
lockdep: Fix per-cpu static objects
Browse files Browse the repository at this point in the history
Since commit 383776f ("locking/lockdep: Handle statically initialized
PER_CPU locks properly") we try to collapse per-cpu locks into a single
class by giving them all the same key. For this key we choose the canonical
address of the per-cpu object, which would be the offset into the per-cpu
area.

This has two problems:

 - there is a case where we run !0 lock->key through static_obj() and
   expect this to pass; it doesn't for canonical pointers.

 - 0 is a valid canonical address.

Cure both issues by redefining the canonical address as the address of the
per-cpu variable on the boot CPU.

Since I didn't want to rely on CPU0 being the boot-cpu, or even existing at
all, track the boot CPU in a variable.

Fixes: 383776f ("locking/lockdep: Handle statically initialized PER_CPU locks properly")
Reported-by: kernel test robot <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Tested-by: Borislav Petkov <[email protected]>
Cc: Sebastian Andrzej Siewior <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: kernel test robot <[email protected]>
Cc: LKP <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Thomas Gleixner <[email protected]>
  • Loading branch information
Peter Zijlstra authored and KAGA-KOKO committed Mar 26, 2017
1 parent 56222b2 commit 8ce371f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
12 changes: 12 additions & 0 deletions include/linux/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ extern unsigned int setup_max_cpus;
extern void __init setup_nr_cpu_ids(void);
extern void __init smp_init(void);

extern int __boot_cpu_id;

static inline int get_boot_cpu_id(void)
{
return __boot_cpu_id;
}

#else /* !SMP */

static inline void smp_send_stop(void) { }
Expand Down Expand Up @@ -158,6 +165,11 @@ static inline void smp_init(void) { up_late_init(); }
static inline void smp_init(void) { }
#endif

static inline int get_boot_cpu_id(void)
{
return 0;
}

#endif /* !SMP */

/*
Expand Down
6 changes: 6 additions & 0 deletions kernel/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,8 @@ core_initcall(cpu_hotplug_pm_sync_init);

#endif /* CONFIG_PM_SLEEP_SMP */

int __boot_cpu_id;

#endif /* CONFIG_SMP */

/* Boot processor state steps */
Expand Down Expand Up @@ -1815,6 +1817,10 @@ void __init boot_cpu_init(void)
set_cpu_active(cpu, true);
set_cpu_present(cpu, true);
set_cpu_possible(cpu, true);

#ifdef CONFIG_SMP
__boot_cpu_id = cpu;
#endif
}

/*
Expand Down
6 changes: 5 additions & 1 deletion kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,12 @@ bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
void *va = (void *)addr;

if (va >= start && va < start + mod->percpu_size) {
if (can_addr)
if (can_addr) {
*can_addr = (unsigned long) (va - start);
*can_addr += (unsigned long)
per_cpu_ptr(mod->percpu,
get_boot_cpu_id());
}
preempt_enable();
return true;
}
Expand Down
5 changes: 4 additions & 1 deletion mm/percpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1293,8 +1293,11 @@ bool __is_kernel_percpu_address(unsigned long addr, unsigned long *can_addr)
void *va = (void *)addr;

if (va >= start && va < start + static_size) {
if (can_addr)
if (can_addr) {
*can_addr = (unsigned long) (va - start);
*can_addr += (unsigned long)
per_cpu_ptr(base, get_boot_cpu_id());
}
return true;
}
}
Expand Down

0 comments on commit 8ce371f

Please sign in to comment.