Skip to content

Commit 645f224

Browse files
committed
kprobes: Tell lockdep about kprobe nesting
Since the kprobe handlers have protection that prohibits other handlers from executing in other contexts (like if an NMI comes in while processing a kprobe, and executes the same kprobe, it will get fail with a "busy" return). Lockdep is unaware of this protection. Use lockdep's nesting api to differentiate between locks taken in INT3 context and other context to suppress the false warnings. Link: https://lore.kernel.org/r/[email protected] Cc: Peter Zijlstra <[email protected]> Acked-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 561ca66 commit 645f224

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

kernel/kprobes.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,13 @@ __acquires(hlist_lock)
12491249

12501250
*head = &kretprobe_inst_table[hash];
12511251
hlist_lock = kretprobe_table_lock_ptr(hash);
1252-
raw_spin_lock_irqsave(hlist_lock, *flags);
1252+
/*
1253+
* Nested is a workaround that will soon not be needed.
1254+
* There's other protections that make sure the same lock
1255+
* is not taken on the same CPU that lockdep is unaware of.
1256+
* Differentiate when it is taken in NMI context.
1257+
*/
1258+
raw_spin_lock_irqsave_nested(hlist_lock, *flags, !!in_nmi());
12531259
}
12541260
NOKPROBE_SYMBOL(kretprobe_hash_lock);
12551261

@@ -1258,7 +1264,13 @@ static void kretprobe_table_lock(unsigned long hash,
12581264
__acquires(hlist_lock)
12591265
{
12601266
raw_spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash);
1261-
raw_spin_lock_irqsave(hlist_lock, *flags);
1267+
/*
1268+
* Nested is a workaround that will soon not be needed.
1269+
* There's other protections that make sure the same lock
1270+
* is not taken on the same CPU that lockdep is unaware of.
1271+
* Differentiate when it is taken in NMI context.
1272+
*/
1273+
raw_spin_lock_irqsave_nested(hlist_lock, *flags, !!in_nmi());
12621274
}
12631275
NOKPROBE_SYMBOL(kretprobe_table_lock);
12641276

@@ -2028,7 +2040,12 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
20282040

20292041
/* TODO: consider to only swap the RA after the last pre_handler fired */
20302042
hash = hash_ptr(current, KPROBE_HASH_BITS);
2031-
raw_spin_lock_irqsave(&rp->lock, flags);
2043+
/*
2044+
* Nested is a workaround that will soon not be needed.
2045+
* There's other protections that make sure the same lock
2046+
* is not taken on the same CPU that lockdep is unaware of.
2047+
*/
2048+
raw_spin_lock_irqsave_nested(&rp->lock, flags, 1);
20322049
if (!hlist_empty(&rp->free_instances)) {
20332050
ri = hlist_entry(rp->free_instances.first,
20342051
struct kretprobe_instance, hlist);
@@ -2039,7 +2056,7 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
20392056
ri->task = current;
20402057

20412058
if (rp->entry_handler && rp->entry_handler(ri, regs)) {
2042-
raw_spin_lock_irqsave(&rp->lock, flags);
2059+
raw_spin_lock_irqsave_nested(&rp->lock, flags, 1);
20432060
hlist_add_head(&ri->hlist, &rp->free_instances);
20442061
raw_spin_unlock_irqrestore(&rp->lock, flags);
20452062
return 0;

0 commit comments

Comments
 (0)