Skip to content

Commit b4c5c57

Browse files
committed
Merge tag 'locking-urgent-2025-03-28' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull misc locking fixes and updates from Ingo Molnar: - Fix a locking self-test FAIL on PREEMPT_RT kernels - Fix nr_unused_locks accounting bug - Simplify the split-lock debugging feature's fast-path * tag 'locking-urgent-2025-03-28' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: locking/lockdep: Decrease nr_unused_locks if lock unused in zap_class() lockdep: Fix wait context check on softirq for PREEMPT_RT x86/split_lock: Simplify reenabling
2 parents aa918db + 495f53d commit b4c5c57

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

arch/x86/kernel/cpu/bus_lock.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,26 @@ static void __split_lock_reenable(struct work_struct *work)
200200
*/
201201
static DEFINE_PER_CPU(struct delayed_work, sl_reenable);
202202

203+
/*
204+
* Per-CPU delayed_work can't be statically initialized properly because
205+
* the struct address is unknown. Thus per-CPU delayed_work structures
206+
* have to be initialized during kernel initialization and after calling
207+
* setup_per_cpu_areas().
208+
*/
209+
static int __init setup_split_lock_delayed_work(void)
210+
{
211+
unsigned int cpu;
212+
213+
for_each_possible_cpu(cpu) {
214+
struct delayed_work *work = per_cpu_ptr(&sl_reenable, cpu);
215+
216+
INIT_DELAYED_WORK(work, __split_lock_reenable);
217+
}
218+
219+
return 0;
220+
}
221+
pure_initcall(setup_split_lock_delayed_work);
222+
203223
/*
204224
* If a CPU goes offline with pending delayed work to re-enable split lock
205225
* detection then the delayed work will be executed on some other CPU. That
@@ -219,15 +239,16 @@ static int splitlock_cpu_offline(unsigned int cpu)
219239

220240
static void split_lock_warn(unsigned long ip)
221241
{
222-
struct delayed_work *work = NULL;
242+
struct delayed_work *work;
223243
int cpu;
244+
unsigned int saved_sld_mitigate = READ_ONCE(sysctl_sld_mitigate);
224245

225246
if (!current->reported_split_lock)
226247
pr_warn_ratelimited("#AC: %s/%d took a split_lock trap at address: 0x%lx\n",
227248
current->comm, current->pid, ip);
228249
current->reported_split_lock = 1;
229250

230-
if (sysctl_sld_mitigate) {
251+
if (saved_sld_mitigate) {
231252
/*
232253
* misery factor #1:
233254
* sleep 10ms before trying to execute split lock.
@@ -240,18 +261,10 @@ static void split_lock_warn(unsigned long ip)
240261
*/
241262
if (down_interruptible(&buslock_sem) == -EINTR)
242263
return;
243-
work = &sl_reenable_unlock;
244264
}
245265

246266
cpu = get_cpu();
247-
248-
if (!work) {
249-
work = this_cpu_ptr(&sl_reenable);
250-
/* Deferred initialization of per-CPU struct */
251-
if (!work->work.func)
252-
INIT_DELAYED_WORK(work, __split_lock_reenable);
253-
}
254-
267+
work = saved_sld_mitigate ? &sl_reenable_unlock : per_cpu_ptr(&sl_reenable, cpu);
255268
schedule_delayed_work_on(cpu, work, 2);
256269

257270
/* Disable split lock detection on this CPU to make progress */

kernel/locking/lockdep.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6264,6 +6264,9 @@ static void zap_class(struct pending_free *pf, struct lock_class *class)
62646264
hlist_del_rcu(&class->hash_entry);
62656265
WRITE_ONCE(class->key, NULL);
62666266
WRITE_ONCE(class->name, NULL);
6267+
/* Class allocated but not used, -1 in nr_unused_locks */
6268+
if (class->usage_mask == 0)
6269+
debug_atomic_dec(nr_unused_locks);
62676270
nr_lock_classes--;
62686271
__clear_bit(class - lock_classes, lock_classes_in_use);
62696272
if (class - lock_classes == max_lock_class_idx)

kernel/softirq.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ static DEFINE_PER_CPU(struct softirq_ctrl, softirq_ctrl) = {
126126
.lock = INIT_LOCAL_LOCK(softirq_ctrl.lock),
127127
};
128128

129+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
130+
static struct lock_class_key bh_lock_key;
131+
struct lockdep_map bh_lock_map = {
132+
.name = "local_bh",
133+
.key = &bh_lock_key,
134+
.wait_type_outer = LD_WAIT_FREE,
135+
.wait_type_inner = LD_WAIT_CONFIG, /* PREEMPT_RT makes BH preemptible. */
136+
.lock_type = LD_LOCK_PERCPU,
137+
};
138+
EXPORT_SYMBOL_GPL(bh_lock_map);
139+
#endif
140+
129141
/**
130142
* local_bh_blocked() - Check for idle whether BH processing is blocked
131143
*
@@ -148,6 +160,8 @@ void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
148160

149161
WARN_ON_ONCE(in_hardirq());
150162

163+
lock_map_acquire_read(&bh_lock_map);
164+
151165
/* First entry of a task into a BH disabled section? */
152166
if (!current->softirq_disable_cnt) {
153167
if (preemptible()) {
@@ -211,6 +225,8 @@ void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)
211225
WARN_ON_ONCE(in_hardirq());
212226
lockdep_assert_irqs_enabled();
213227

228+
lock_map_release(&bh_lock_map);
229+
214230
local_irq_save(flags);
215231
curcnt = __this_cpu_read(softirq_ctrl.cnt);
216232

@@ -261,6 +277,8 @@ static inline void ksoftirqd_run_begin(void)
261277
/* Counterpart to ksoftirqd_run_begin() */
262278
static inline void ksoftirqd_run_end(void)
263279
{
280+
/* pairs with the lock_map_acquire_read() in ksoftirqd_run_begin() */
281+
lock_map_release(&bh_lock_map);
264282
__local_bh_enable(SOFTIRQ_OFFSET, true);
265283
WARN_ON_ONCE(in_interrupt());
266284
local_irq_enable();

0 commit comments

Comments
 (0)