Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4071bd88 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'bpf-MIPS-infra'



David Daney says:

====================
bpf: Changes needed (or desired) for MIPS support

This is a grab bag of changes to the bpf testing infrastructure I
developed working on MIPS eBPF JIT support.  The change to
bpf_jit_disasm is probably universally beneficial, the others are more
MIPS specific.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 2fae5d0e 4b7190e8
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -435,6 +435,30 @@ static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test *self)
	return 0;
}

static int bpf_fill_jump_around_ld_abs(struct bpf_test *self)
{
	unsigned int len = BPF_MAXINSNS;
	struct bpf_insn *insn;
	int i = 0;

	insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
	if (!insn)
		return -ENOMEM;

	insn[i++] = BPF_MOV64_REG(R6, R1);
	insn[i++] = BPF_LD_ABS(BPF_B, 0);
	insn[i] = BPF_JMP_IMM(BPF_JEQ, R0, 10, len - i - 2);
	i++;
	while (i < len - 1)
		insn[i++] = BPF_LD_ABS(BPF_B, 1);
	insn[i] = BPF_EXIT_INSN();

	self->u.ptr.insns = insn;
	self->u.ptr.len = len;

	return 0;
}

static int __bpf_fill_stxdw(struct bpf_test *self, int size)
{
	unsigned int len = BPF_MAXINSNS;
@@ -5044,6 +5068,14 @@ static struct bpf_test tests[] = {
		{ { ETH_HLEN, 0xbef } },
		.fill_helper = bpf_fill_ld_abs_vlan_push_pop,
	},
	{
		"BPF_MAXINSNS: jump around ld_abs",
		{ },
		INTERNAL,
		{ 10, 11 },
		{ { 2, 10 } },
		.fill_helper = bpf_fill_jump_around_ld_abs,
	},
	/*
	 * LD_IND / LD_ABS on fragmented SKBs
	 */
+13 −0
Original line number Diff line number Diff line
@@ -160,6 +160,17 @@ clean:
	$(MAKE) -C ../../ M=$(CURDIR) clean
	@rm -f *~

$(obj)/syscall_nrs.s:	$(src)/syscall_nrs.c
	$(call if_changed_dep,cc_s_c)

$(obj)/syscall_nrs.h:	$(obj)/syscall_nrs.s FORCE
	$(call filechk,offsets,__SYSCALL_NRS_H__)

clean-files += syscall_nrs.h

FORCE:


# Verify LLVM compiler tools are available and bpf target is supported by llc
.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)

@@ -180,6 +191,8 @@ verify_target_bpf: verify_cmds

$(src)/*.c: verify_target_bpf

$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h

# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
# But, there is no easy way to fix it, so just exclude it since it is
# useless for BPF samples.
+13 −0
Original line number Diff line number Diff line
@@ -136,6 +136,19 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
#define PT_REGS_SP(x) ((x)->sp)
#define PT_REGS_IP(x) ((x)->pc)

#elif defined(__mips__)

#define PT_REGS_PARM1(x) ((x)->regs[4])
#define PT_REGS_PARM2(x) ((x)->regs[5])
#define PT_REGS_PARM3(x) ((x)->regs[6])
#define PT_REGS_PARM4(x) ((x)->regs[7])
#define PT_REGS_PARM5(x) ((x)->regs[8])
#define PT_REGS_RET(x) ((x)->regs[31])
#define PT_REGS_FP(x) ((x)->regs[30]) /* Works only with CONFIG_FRAME_POINTER */
#define PT_REGS_RC(x) ((x)->regs[1])
#define PT_REGS_SP(x) ((x)->regs[29])
#define PT_REGS_IP(x) ((x)->cp0_epc)

#elif defined(__powerpc__)

#define PT_REGS_PARM1(x) ((x)->gpr[3])
+12 −0
Original line number Diff line number Diff line
#include <uapi/linux/unistd.h>
#include <linux/kbuild.h>

#define SYSNR(_NR) DEFINE(SYS ## _NR, _NR)

void syscall_defines(void)
{
	COMMENT("Linux system call numbers.");
	SYSNR(__NR_write);
	SYSNR(__NR_read);
	SYSNR(__NR_mmap);
}
+8 −3
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include <uapi/linux/bpf.h>
#include <uapi/linux/seccomp.h>
#include <uapi/linux/unistd.h>
#include "syscall_nrs.h"
#include "bpf_helpers.h"

#define PROG(F) SEC("kprobe/"__stringify(F)) int bpf_func_##F
@@ -17,7 +18,11 @@ struct bpf_map_def SEC("maps") progs = {
	.type = BPF_MAP_TYPE_PROG_ARRAY,
	.key_size = sizeof(u32),
	.value_size = sizeof(u32),
#ifdef __mips__
	.max_entries = 6000, /* MIPS n64 syscalls start at 5000 */
#else
	.max_entries = 1024,
#endif
};

SEC("kprobe/__seccomp_filter")
@@ -37,7 +42,7 @@ int bpf_prog1(struct pt_regs *ctx)
}

/* we jump here when syscall number == __NR_write */
PROG(__NR_write)(struct pt_regs *ctx)
PROG(SYS__NR_write)(struct pt_regs *ctx)
{
	struct seccomp_data sd;

@@ -50,7 +55,7 @@ PROG(__NR_write)(struct pt_regs *ctx)
	return 0;
}

PROG(__NR_read)(struct pt_regs *ctx)
PROG(SYS__NR_read)(struct pt_regs *ctx)
{
	struct seccomp_data sd;

@@ -63,7 +68,7 @@ PROG(__NR_read)(struct pt_regs *ctx)
	return 0;
}

PROG(__NR_mmap)(struct pt_regs *ctx)
PROG(SYS__NR_mmap)(struct pt_regs *ctx)
{
	char fmt[] = "mmap\n";
	bpf_trace_printk(fmt, sizeof(fmt));
Loading