Skip to content

Commit af5eeab

Browse files
committed
signal: Factor force_sig_perf out of perf_sigtrap
Separate filling in siginfo for TRAP_PERF from deciding that siginal needs to be sent. There are enough little details that need to be correct when properly filling in siginfo_t that it is easy to make mistakes if filling in the siginfo_t is in the same function with other logic. So factor out force_sig_perf to reduce the cognative load of on reviewers, maintainers and implementors. v1: https://lkml.kernel.org/r/m17dkjqqxz.fsf_-_@fess.ebiederm.org v2: https://lkml.kernel.org/r/20210505141101.11519-10-ebiederm@xmission.com Link: https://lkml.kernel.org/r/20210517195748.8880-3-ebiederm@xmission.com Reviewed-by: Marco Elver <elver@google.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 9abcabe commit af5eeab

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

include/linux/sched/signal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);
326326

327327
int force_sig_bnderr(void __user *addr, void __user *lower, void __user *upper);
328328
int force_sig_pkuerr(void __user *addr, u32 pkey);
329+
int force_sig_perf(void __user *addr, u32 type, u64 sig_data);
329330

330331
int force_sig_ptrace_errno_trap(int errno, void __user *addr);
331332

kernel/events/core.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6394,8 +6394,6 @@ void perf_event_wakeup(struct perf_event *event)
63946394

63956395
static void perf_sigtrap(struct perf_event *event)
63966396
{
6397-
struct kernel_siginfo info;
6398-
63996397
/*
64006398
* We'd expect this to only occur if the irq_work is delayed and either
64016399
* ctx->task or current has changed in the meantime. This can be the
@@ -6410,13 +6408,8 @@ static void perf_sigtrap(struct perf_event *event)
64106408
if (current->flags & PF_EXITING)
64116409
return;
64126410

6413-
clear_siginfo(&info);
6414-
info.si_signo = SIGTRAP;
6415-
info.si_code = TRAP_PERF;
6416-
info.si_errno = event->attr.type;
6417-
info.si_perf = event->attr.sig_data;
6418-
info.si_addr = (void __user *)event->pending_addr;
6419-
force_sig_info(&info);
6411+
force_sig_perf((void __user *)event->pending_addr,
6412+
event->attr.type, event->attr.sig_data);
64206413
}
64216414

64226415
static void perf_pending_event_disable(struct perf_event *event)

kernel/signal.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,19 @@ int force_sig_pkuerr(void __user *addr, u32 pkey)
17631763
}
17641764
#endif
17651765

1766+
int force_sig_perf(void __user *addr, u32 type, u64 sig_data)
1767+
{
1768+
struct kernel_siginfo info;
1769+
1770+
clear_siginfo(&info);
1771+
info.si_signo = SIGTRAP;
1772+
info.si_errno = type;
1773+
info.si_code = TRAP_PERF;
1774+
info.si_addr = addr;
1775+
info.si_perf = sig_data;
1776+
return force_sig_info(&info);
1777+
}
1778+
17661779
/* For the crazy architectures that include trap information in
17671780
* the errno field, instead of an actual errno value.
17681781
*/

0 commit comments

Comments
 (0)