Skip to content

Commit fb6cc12

Browse files
melverPeter Zijlstra
authored andcommitted
signal: Introduce TRAP_PERF si_code and si_perf to siginfo
Introduces the TRAP_PERF si_code, and associated siginfo_t field si_perf. These will be used by the perf event subsystem to send signals (if requested) to the task where an event occurred. Signed-off-by: Marco Elver <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Geert Uytterhoeven <[email protected]> # m68k Acked-by: Arnd Bergmann <[email protected]> # asm-generic Link: https://lkml.kernel.org/r/[email protected]
1 parent 2e498d0 commit fb6cc12

File tree

8 files changed

+33
-3
lines changed

8 files changed

+33
-3
lines changed

arch/m68k/kernel/signal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,9 @@ static inline void siginfo_build_tests(void)
622622
/* _sigfault._addr_pkey */
623623
BUILD_BUG_ON(offsetof(siginfo_t, si_pkey) != 0x12);
624624

625+
/* _sigfault._perf */
626+
BUILD_BUG_ON(offsetof(siginfo_t, si_perf) != 0x10);
627+
625628
/* _sigpoll */
626629
BUILD_BUG_ON(offsetof(siginfo_t, si_band) != 0x0c);
627630
BUILD_BUG_ON(offsetof(siginfo_t, si_fd) != 0x10);

arch/x86/kernel/signal_compat.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static inline void signal_compat_build_tests(void)
2929
BUILD_BUG_ON(NSIGFPE != 15);
3030
BUILD_BUG_ON(NSIGSEGV != 9);
3131
BUILD_BUG_ON(NSIGBUS != 5);
32-
BUILD_BUG_ON(NSIGTRAP != 5);
32+
BUILD_BUG_ON(NSIGTRAP != 6);
3333
BUILD_BUG_ON(NSIGCHLD != 6);
3434
BUILD_BUG_ON(NSIGSYS != 2);
3535

@@ -138,6 +138,9 @@ static inline void signal_compat_build_tests(void)
138138
BUILD_BUG_ON(offsetof(siginfo_t, si_pkey) != 0x20);
139139
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pkey) != 0x14);
140140

141+
BUILD_BUG_ON(offsetof(siginfo_t, si_perf) != 0x18);
142+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_perf) != 0x10);
143+
141144
CHECK_CSI_OFFSET(_sigpoll);
142145
CHECK_CSI_SIZE (_sigpoll, 2*sizeof(int));
143146
CHECK_SI_SIZE (_sigpoll, 4*sizeof(int));

fs/signalfd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
134134
#endif
135135
new.ssi_addr_lsb = (short) kinfo->si_addr_lsb;
136136
break;
137+
case SIL_PERF_EVENT:
138+
new.ssi_addr = (long) kinfo->si_addr;
139+
new.ssi_perf = kinfo->si_perf;
140+
break;
137141
case SIL_CHLD:
138142
new.ssi_pid = kinfo->si_pid;
139143
new.ssi_uid = kinfo->si_uid;

include/linux/compat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ typedef struct compat_siginfo {
236236
char _dummy_pkey[__COMPAT_ADDR_BND_PKEY_PAD];
237237
u32 _pkey;
238238
} _addr_pkey;
239+
/* used when si_code=TRAP_PERF */
240+
compat_u64 _perf;
239241
};
240242
} _sigfault;
241243

include/linux/signal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum siginfo_layout {
4343
SIL_FAULT_MCEERR,
4444
SIL_FAULT_BNDERR,
4545
SIL_FAULT_PKUERR,
46+
SIL_PERF_EVENT,
4647
SIL_CHLD,
4748
SIL_RT,
4849
SIL_SYS,

include/uapi/asm-generic/siginfo.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ union __sifields {
9191
char _dummy_pkey[__ADDR_BND_PKEY_PAD];
9292
__u32 _pkey;
9393
} _addr_pkey;
94+
/* used when si_code=TRAP_PERF */
95+
__u64 _perf;
9496
};
9597
} _sigfault;
9698

@@ -155,6 +157,7 @@ typedef struct siginfo {
155157
#define si_lower _sifields._sigfault._addr_bnd._lower
156158
#define si_upper _sifields._sigfault._addr_bnd._upper
157159
#define si_pkey _sifields._sigfault._addr_pkey._pkey
160+
#define si_perf _sifields._sigfault._perf
158161
#define si_band _sifields._sigpoll._band
159162
#define si_fd _sifields._sigpoll._fd
160163
#define si_call_addr _sifields._sigsys._call_addr
@@ -253,7 +256,8 @@ typedef struct siginfo {
253256
#define TRAP_BRANCH 3 /* process taken branch trap */
254257
#define TRAP_HWBKPT 4 /* hardware breakpoint/watchpoint */
255258
#define TRAP_UNK 5 /* undiagnosed trap */
256-
#define NSIGTRAP 5
259+
#define TRAP_PERF 6 /* perf event with sigtrap=1 */
260+
#define NSIGTRAP 6
257261

258262
/*
259263
* There is an additional set of SIGTRAP si_codes used by ptrace

include/uapi/linux/signalfd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ struct signalfd_siginfo {
3939
__s32 ssi_syscall;
4040
__u64 ssi_call_addr;
4141
__u32 ssi_arch;
42+
__u32 __pad3;
43+
__u64 ssi_perf;
4244

4345
/*
4446
* Pad strcture to 128 bytes. Remember to update the
@@ -49,7 +51,7 @@ struct signalfd_siginfo {
4951
* comes out of a read(2) and we really don't want to have
5052
* a compat on read(2).
5153
*/
52-
__u8 __pad[28];
54+
__u8 __pad[16];
5355
};
5456

5557

kernel/signal.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
11991199
case SIL_FAULT_MCEERR:
12001200
case SIL_FAULT_BNDERR:
12011201
case SIL_FAULT_PKUERR:
1202+
case SIL_PERF_EVENT:
12021203
case SIL_SYS:
12031204
ret = false;
12041205
break;
@@ -2531,6 +2532,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig)
25312532
case SIL_FAULT_MCEERR:
25322533
case SIL_FAULT_BNDERR:
25332534
case SIL_FAULT_PKUERR:
2535+
case SIL_PERF_EVENT:
25342536
ksig->info.si_addr = arch_untagged_si_addr(
25352537
ksig->info.si_addr, ksig->sig, ksig->info.si_code);
25362538
break;
@@ -3333,6 +3335,10 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,
33333335
#endif
33343336
to->si_pkey = from->si_pkey;
33353337
break;
3338+
case SIL_PERF_EVENT:
3339+
to->si_addr = ptr_to_compat(from->si_addr);
3340+
to->si_perf = from->si_perf;
3341+
break;
33363342
case SIL_CHLD:
33373343
to->si_pid = from->si_pid;
33383344
to->si_uid = from->si_uid;
@@ -3413,6 +3419,10 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,
34133419
#endif
34143420
to->si_pkey = from->si_pkey;
34153421
break;
3422+
case SIL_PERF_EVENT:
3423+
to->si_addr = compat_ptr(from->si_addr);
3424+
to->si_perf = from->si_perf;
3425+
break;
34163426
case SIL_CHLD:
34173427
to->si_pid = from->si_pid;
34183428
to->si_uid = from->si_uid;
@@ -4593,6 +4603,7 @@ static inline void siginfo_buildtime_checks(void)
45934603
CHECK_OFFSET(si_lower);
45944604
CHECK_OFFSET(si_upper);
45954605
CHECK_OFFSET(si_pkey);
4606+
CHECK_OFFSET(si_perf);
45964607

45974608
/* sigpoll */
45984609
CHECK_OFFSET(si_band);

0 commit comments

Comments
 (0)