Skip to content

Commit ba62a53

Browse files
committed
Merge tag 'arc-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vgupta/arc
Pull ARC updates from Vineet Gupta: - Basic eBPF support (Sergey) * tag 'arc-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vgupta/arc: ARC: bpf: define uapi for BPF_PROG_TYPE_PERF_EVENT program type ARC: disasm: handle ARCv2 case in kprobe get/set functions ARC: implement syscall tracepoints ARC: enable HAVE_REGS_AND_STACK_ACCESS_API feature
2 parents ef98f9c + 6aa98f6 commit ba62a53

File tree

9 files changed

+253
-12
lines changed

9 files changed

+253
-12
lines changed

arch/arc/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ config ARC
3636
select HAVE_KERNEL_LZMA
3737
select HAVE_KPROBES
3838
select HAVE_KRETPROBES
39+
select HAVE_REGS_AND_STACK_ACCESS_API
3940
select HAVE_MOD_ARCH_SPECIFIC
4041
select HAVE_PERF_EVENTS
42+
select HAVE_SYSCALL_TRACEPOINTS
4143
select IRQ_DOMAIN
4244
select MODULES_USE_ELF_RELA
4345
select OF

arch/arc/include/asm/perf_event.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ struct arc_reg_cc_build {
6363

6464
#define PERF_COUNT_ARC_HW_MAX (PERF_COUNT_HW_MAX + 8)
6565

66+
#ifdef CONFIG_PERF_EVENTS
67+
#define perf_arch_bpf_user_pt_regs(regs) (struct user_regs_struct *)regs
68+
#endif
69+
6670
#endif /* __ASM_PERF_EVENT_H */

arch/arc/include/asm/ptrace.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define __ASM_ARC_PTRACE_H
99

1010
#include <uapi/asm/ptrace.h>
11+
#include <linux/compiler.h>
1112

1213
#ifndef __ASSEMBLY__
1314

@@ -54,6 +55,9 @@ struct pt_regs {
5455

5556
unsigned long user_r25;
5657
};
58+
59+
#define MAX_REG_OFFSET offsetof(struct pt_regs, user_r25)
60+
5761
#else
5862

5963
struct pt_regs {
@@ -102,6 +106,8 @@ struct pt_regs {
102106
unsigned long status32;
103107
};
104108

109+
#define MAX_REG_OFFSET offsetof(struct pt_regs, status32)
110+
105111
#endif
106112

107113
/* Callee saved registers - need to be saved only when you are scheduled out */
@@ -154,6 +160,27 @@ static inline void instruction_pointer_set(struct pt_regs *regs,
154160
{
155161
instruction_pointer(regs) = val;
156162
}
163+
164+
static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
165+
{
166+
return regs->sp;
167+
}
168+
169+
extern int regs_query_register_offset(const char *name);
170+
extern const char *regs_query_register_name(unsigned int offset);
171+
extern bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr);
172+
extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
173+
unsigned int n);
174+
175+
static inline unsigned long regs_get_register(struct pt_regs *regs,
176+
unsigned int offset)
177+
{
178+
if (unlikely(offset > MAX_REG_OFFSET))
179+
return 0;
180+
181+
return *(unsigned long *)((unsigned long)regs + offset);
182+
}
183+
157184
#endif /* !__ASSEMBLY__ */
158185

159186
#endif /* __ASM_PTRACE_H */

arch/arc/include/asm/syscall.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <asm/unistd.h>
1313
#include <asm/ptrace.h> /* in_syscall() */
1414

15+
extern void *sys_call_table[];
16+
1517
static inline long
1618
syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
1719
{

arch/arc/include/asm/thread_info.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ static inline __attribute_const__ struct thread_info *current_thread_info(void)
7878
#define TIF_SYSCALL_AUDIT 4 /* syscall auditing active */
7979
#define TIF_NOTIFY_SIGNAL 5 /* signal notifications exist */
8080
#define TIF_SYSCALL_TRACE 15 /* syscall trace active */
81-
8281
/* true if poll_idle() is polling TIF_NEED_RESCHED */
8382
#define TIF_MEMDIE 16
83+
#define TIF_SYSCALL_TRACEPOINT 17 /* syscall tracepoint instrumentation */
8484

8585
#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8686
#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
@@ -89,11 +89,14 @@ static inline __attribute_const__ struct thread_info *current_thread_info(void)
8989
#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9090
#define _TIF_NOTIFY_SIGNAL (1<<TIF_NOTIFY_SIGNAL)
9191
#define _TIF_MEMDIE (1<<TIF_MEMDIE)
92+
#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9293

9394
/* work to do on interrupt/exception return */
9495
#define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
9596
_TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL)
9697

98+
#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT)
99+
97100
/*
98101
* _TIF_ALLWORK_MASK includes SYSCALL_TRACE, but we don't need it.
99102
* SYSCALL_TRACE is anyway separately/unconditionally tested right after a
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
#ifndef _UAPI__ASM_BPF_PERF_EVENT_H__
3+
#define _UAPI__ASM_BPF_PERF_EVENT_H__
4+
5+
#include <asm/ptrace.h>
6+
7+
typedef struct user_regs_struct bpf_user_pt_regs_t;
8+
9+
#endif /* _UAPI__ASM_BPF_PERF_EVENT_H__ */

arch/arc/kernel/disasm.c

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,31 @@ long __kprobes get_reg(int reg, struct pt_regs *regs,
434434
{
435435
long *p;
436436

437+
#if defined(CONFIG_ISA_ARCOMPACT)
437438
if (reg <= 12) {
438439
p = &regs->r0;
439440
return p[-reg];
440441
}
442+
#else /* CONFIG_ISA_ARCV2 */
443+
if (reg <= 11) {
444+
p = &regs->r0;
445+
return p[reg];
446+
}
441447

448+
if (reg == 12)
449+
return regs->r12;
450+
if (reg == 30)
451+
return regs->r30;
452+
#ifdef CONFIG_ARC_HAS_ACCL_REGS
453+
if (reg == 58)
454+
return regs->r58;
455+
if (reg == 59)
456+
return regs->r59;
457+
#endif
458+
#endif
442459
if (cregs && (reg <= 25)) {
443460
p = &cregs->r13;
444-
return p[13-reg];
461+
return p[13 - reg];
445462
}
446463

447464
if (reg == 26)
@@ -461,6 +478,7 @@ void __kprobes set_reg(int reg, long val, struct pt_regs *regs,
461478
{
462479
long *p;
463480

481+
#if defined(CONFIG_ISA_ARCOMPACT)
464482
switch (reg) {
465483
case 0 ... 12:
466484
p = &regs->r0;
@@ -469,7 +487,7 @@ void __kprobes set_reg(int reg, long val, struct pt_regs *regs,
469487
case 13 ... 25:
470488
if (cregs) {
471489
p = &cregs->r13;
472-
p[13-reg] = val;
490+
p[13 - reg] = val;
473491
}
474492
break;
475493
case 26:
@@ -487,6 +505,48 @@ void __kprobes set_reg(int reg, long val, struct pt_regs *regs,
487505
default:
488506
break;
489507
}
508+
#else /* CONFIG_ISA_ARCV2 */
509+
switch (reg) {
510+
case 0 ... 11:
511+
p = &regs->r0;
512+
p[reg] = val;
513+
break;
514+
case 12:
515+
regs->r12 = val;
516+
break;
517+
case 13 ... 25:
518+
if (cregs) {
519+
p = &cregs->r13;
520+
p[13 - reg] = val;
521+
}
522+
break;
523+
case 26:
524+
regs->r26 = val;
525+
break;
526+
case 27:
527+
regs->fp = val;
528+
break;
529+
case 28:
530+
regs->sp = val;
531+
break;
532+
case 30:
533+
regs->r30 = val;
534+
break;
535+
case 31:
536+
regs->blink = val;
537+
break;
538+
#ifdef CONFIG_ARC_HAS_ACCL_REGS
539+
case 58:
540+
regs->r58 = val;
541+
break;
542+
case 59:
543+
regs->r59 = val;
544+
break;
545+
#endif
546+
default:
547+
break;
548+
}
549+
#endif
490550
}
491551

492552
/*

arch/arc/kernel/entry.S

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ ENTRY(sys_clone_wrapper)
2929
DISCARD_CALLEE_SAVED_USER
3030

3131
GET_CURR_THR_INFO_FLAGS r10
32-
btst r10, TIF_SYSCALL_TRACE
33-
bnz tracesys_exit
32+
and.f 0, r10, _TIF_SYSCALL_WORK
33+
bnz tracesys_exit
3434

3535
b .Lret_from_system_call
3636
END(sys_clone_wrapper)
@@ -41,8 +41,8 @@ ENTRY(sys_clone3_wrapper)
4141
DISCARD_CALLEE_SAVED_USER
4242

4343
GET_CURR_THR_INFO_FLAGS r10
44-
btst r10, TIF_SYSCALL_TRACE
45-
bnz tracesys_exit
44+
and.f 0, r10, _TIF_SYSCALL_WORK
45+
bnz tracesys_exit
4646

4747
b .Lret_from_system_call
4848
END(sys_clone3_wrapper)
@@ -247,8 +247,8 @@ ENTRY(EV_Trap)
247247

248248
; If syscall tracing ongoing, invoke pre-post-hooks
249249
GET_CURR_THR_INFO_FLAGS r10
250-
btst r10, TIF_SYSCALL_TRACE
251-
bnz tracesys ; this never comes back
250+
and.f 0, r10, _TIF_SYSCALL_WORK
251+
bnz tracesys ; this never comes back
252252

253253
;============ Normal syscall case
254254

0 commit comments

Comments
 (0)