Skip to content

Commit 2762487

Browse files
authored
Replace mutex with spinlock for tracepoint registration (#2882)
1 parent 51dbc67 commit 2762487

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

kernel/sucompat.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/types.h>
1414
#include <linux/uaccess.h>
1515
#include <linux/version.h>
16+
#include <linux/spinlock.h>
1617
#include <linux/sched/task_stack.h>
1718
#include <asm/syscall.h>
1819
#include <trace/events/syscalls.h>
@@ -335,11 +336,12 @@ static struct kprobe *pts_kp = NULL;
335336
#ifdef CONFIG_KRETPROBES
336337

337338
static int tracepoint_reg_count = 0;
338-
static DEFINE_MUTEX(tracepoint_reg_mutex);
339+
static DEFINE_SPINLOCK(tracepoint_reg_lock);
339340

340341
static int syscall_regfunc_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
341342
{
342-
mutex_lock(&tracepoint_reg_mutex);
343+
unsigned long flags;
344+
spin_lock_irqsave(&tracepoint_reg_lock, flags);
343345
if (tracepoint_reg_count < 1) {
344346
// while install our tracepoint, mark our processes
345347
unmark_all_process();
@@ -349,13 +351,14 @@ static int syscall_regfunc_handler(struct kretprobe_instance *ri, struct pt_regs
349351
mark_all_process();
350352
}
351353
tracepoint_reg_count++;
352-
mutex_unlock(&tracepoint_reg_mutex);
354+
spin_unlock_irqrestore(&tracepoint_reg_lock, flags);
353355
return 0;
354356
}
355357

356358
static int syscall_unregfunc_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
357359
{
358-
mutex_lock(&tracepoint_reg_mutex);
360+
unsigned long flags;
361+
spin_lock_irqsave(&tracepoint_reg_lock, flags);
359362
if (tracepoint_reg_count <= 1) {
360363
// while uninstall our tracepoint, unmark all processes
361364
unmark_all_process();
@@ -365,7 +368,7 @@ static int syscall_unregfunc_handler(struct kretprobe_instance *ri, struct pt_re
365368
ksu_mark_running_process();
366369
}
367370
tracepoint_reg_count--;
368-
mutex_unlock(&tracepoint_reg_mutex);
371+
spin_unlock_irqrestore(&tracepoint_reg_lock, flags);
369372
return 0;
370373
}
371374

0 commit comments

Comments
 (0)