* [PATCH net 2/2] bpf: fix checking xdp_adjust_head on tail calls
From: Daniel Borkmann @ 2017-04-17 1:12 UTC (permalink / raw)
To: davem
Cc: alexei.starovoitov, kubakici, netdev, Daniel Borkmann,
Martin KaFai Lau
In-Reply-To: <cover.1492390940.git.daniel@iogearbox.net>
Commit 17bedab27231 ("bpf: xdp: Allow head adjustment in XDP prog")
added the xdp_adjust_head bit to the BPF prog in order to tell drivers
that the program that is to be attached requires support for the XDP
bpf_xdp_adjust_head() helper such that drivers not supporting this
helper can reject the program. There are also drivers that do support
the helper, but need to check for xdp_adjust_head bit in order to move
packet metadata prepended by the firmware away for making headroom.
For these cases, the current check for xdp_adjust_head bit is insufficient
since there can be cases where the program itself does not use the
bpf_xdp_adjust_head() helper, but tail calls into another program that
uses bpf_xdp_adjust_head(). As such, the xdp_adjust_head bit is still
set to 0. Since the first program has no control over which program it
calls into, we need to assume that bpf_xdp_adjust_head() helper is used
upon tail calls. Thus, for the very same reasons in cb_access, set the
xdp_adjust_head bit to 1 when the main program uses tail calls.
Fixes: 17bedab27231 ("bpf: xdp: Allow head adjustment in XDP prog")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Cc: Martin KaFai Lau <kafai@fb.com>
---
kernel/bpf/syscall.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index ee5c969..821f9e8 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -623,6 +623,7 @@ static void fixup_bpf_calls(struct bpf_prog *prog)
* in the program array.
*/
prog->cb_access = 1;
+ prog->xdp_adjust_head = 1;
/* mark bpf_tail_call as different opcode
* to avoid conditional branch in
--
1.9.3
^ permalink raw reply related
* [PATCH net 0/2] Two BPF fixes
From: Daniel Borkmann @ 2017-04-17 1:12 UTC (permalink / raw)
To: davem; +Cc: alexei.starovoitov, kubakici, netdev, Daniel Borkmann
The set fixes cb_access and xdp_adjust_head bits in struct bpf_prog,
that are used for requirement checks on the program rather than f.e.
heuristics. Thus, for tail calls, we cannot make any assumptions and
are forced to set them.
Thanks!
Daniel Borkmann (2):
bpf: fix cb access in socket filter programs on tail calls
bpf: fix checking xdp_adjust_head on tail calls
kernel/bpf/syscall.c | 8 ++++++++
1 file changed, 8 insertions(+)
--
1.9.3
^ permalink raw reply
* [PATCH net 1/2] bpf: fix cb access in socket filter programs on tail calls
From: Daniel Borkmann @ 2017-04-17 1:12 UTC (permalink / raw)
To: davem; +Cc: alexei.starovoitov, kubakici, netdev, Daniel Borkmann
In-Reply-To: <cover.1492390940.git.daniel@iogearbox.net>
Commit ff936a04e5f2 ("bpf: fix cb access in socket filter programs")
added a fix for socket filter programs such that in i) AF_PACKET the
20 bytes of skb->cb[] area gets zeroed before use in order to not leak
data, and ii) socket filter programs attached to TCP/UDP sockets need
to save/restore these 20 bytes since they are also used by protocol
layers at that time.
The problem is that bpf_prog_run_save_cb() and bpf_prog_run_clear_cb()
only look at the actual attached program to determine whether to zero
or save/restore the skb->cb[] parts. There can be cases where the
actual attached program does not access the skb->cb[], but the program
tail calls into another program which does access this area. In such
a case, the zero or save/restore is currently not performed.
Since the programs we tail call into are unknown at verification time
and can dynamically change, we need to assume that whenever the attached
program performs a tail call, that later programs could access the
skb->cb[], and therefore we need to always set cb_access to 1.
Fixes: ff936a04e5f2 ("bpf: fix cb access in socket filter programs")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
---
kernel/bpf/syscall.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 7af0dcc..ee5c969 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -617,6 +617,13 @@ static void fixup_bpf_calls(struct bpf_prog *prog)
if (insn->imm == BPF_FUNC_xdp_adjust_head)
prog->xdp_adjust_head = 1;
if (insn->imm == BPF_FUNC_tail_call) {
+ /* If we tail call into other programs, we
+ * cannot make any assumptions since they
+ * can be replaced dynamically during runtime
+ * in the program array.
+ */
+ prog->cb_access = 1;
+
/* mark bpf_tail_call as different opcode
* to avoid conditional branch in
* interpeter for every normal call
--
1.9.3
^ permalink raw reply related
* Re: ipv6 udp early demux breaks udp_l3mdev_accept=0
From: David Ahern @ 2017-04-17 2:59 UTC (permalink / raw)
To: Subash Abhinov Kasiviswanathan, davem, netdev, rshearma
In-Reply-To: <1492389870-22733-1-git-send-email-subashab@codeaurora.org>
On 4/16/17 6:44 PM, Subash Abhinov Kasiviswanathan wrote:
> Can you try this
>
> ---
> net/ipv6/udp.c | 21 +++++++++++++--------
> 1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
> index b793ed1..0e307e5 100644
> --- a/net/ipv6/udp.c
> +++ b/net/ipv6/udp.c
> @@ -46,6 +46,7 @@
> #include <net/tcp_states.h>
> #include <net/ip6_checksum.h>
> #include <net/xfrm.h>
> +#include <net/inet_hashtables.h>
> #include <net/inet6_hashtables.h>
> #include <net/busy_poll.h>
> #include <net/sock_reuseport.h>
> @@ -864,21 +865,25 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
> return 0;
> }
>
> +
> static struct sock *__udp6_lib_demux_lookup(struct net *net,
> __be16 loc_port, const struct in6_addr *loc_addr,
> __be16 rmt_port, const struct in6_addr *rmt_addr,
> int dif)
> {
> + unsigned short hnum = ntohs(loc_port);
> + unsigned int hash2 = udp6_portaddr_hash(net, loc_addr, hnum);
> + unsigned int slot2 = hash2 & udp_table.mask;
> + struct udp_hslot *hslot2 = &udp_table.hash2[slot2];
> + const __portpair ports = INET_COMBINED_PORTS(rmt_port, hnum);
> struct sock *sk;
>
> - rcu_read_lock();
> - sk = __udp6_lib_lookup(net, rmt_addr, rmt_port, loc_addr, loc_port,
> - dif, &udp_table, NULL);
> - if (sk && !atomic_inc_not_zero(&sk->sk_refcnt))
> - sk = NULL;
> - rcu_read_unlock();
> -
> - return sk;
> + udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
> + if (INET6_MATCH(sk, net, rmt_addr, loc_addr, ports, dif))
> + return sk;
> + break;
> + }
> + return NULL;
> }
>
> static void udp_v6_early_demux(struct sk_buff *skb)
>
That works for me. Thanks for the fast turn around.
^ permalink raw reply
* [PATCH RFC] sparc64: eBPF JIT
From: David Miller @ 2017-04-17 3:38 UTC (permalink / raw)
To: sparclinux; +Cc: netdev, ast, daniel
There are a bunch of things I want to do still, and I know that I have
to attend to sparc32 more cleanly, but I wanted to post this now that
I have it passing the BPF testsuite completely:
[24174.315421] test_bpf: Summary: 305 PASSED, 0 FAILED, [297/297 JIT'ed]
Only major unimplemented feature is tail calls, which I am very sure I
can do simply but until something easy to use like test_bpf can
exercise it I probably won't do it.
>From my side, what I need to do to turn this into a non-RFC is to sort
out sparc32. My plan is to take the existing cBPF JIT, rip out all of
the sparc64 specific bits, and have sparc32 use that. And do it in
such a way that git bisection is not broken.
As a future optimization I'd like to add support for emitting cbcond
instructions on newer chips.
This implementation grabs a register window all the time, and we could
avoid that and use a leaf function in certatin situations. The
register layout is also not optimal, and one side effect is that we
have to move the argument registers over during function calls.
Signed-off-by: David S. Miller <davem@davemloft.net>
diff --git a/arch/sparc/net/bpf_jit.h b/arch/sparc/net/bpf_jit.h
index 33d6b37..cd0efad 100644
--- a/arch/sparc/net/bpf_jit.h
+++ b/arch/sparc/net/bpf_jit.h
@@ -27,17 +27,28 @@
#define O5 0x0d
#define SP 0x0e
#define O7 0x0f
+#define L0 0x10
+#define L1 0x11
+#define L2 0x12
+#define L3 0x13
+#define L4 0x14
+#define L5 0x15
+#define L6 0x16
+#define L7 0x17
+#define I0 0x18
+#define I1 0x19
+#define I2 0x1a
+#define I3 0x1b
+#define I4 0x1c
+#define I5 0x1d
#define FP 0x1e
+#define I7 0x1f
-#define r_SKB O0
-#define r_A O1
-#define r_X O2
-#define r_saved_O7 O3
-#define r_HEADLEN O4
-#define r_SKB_DATA O5
+#define r_SKB L0
+#define r_HEADLEN L4
+#define r_SKB_DATA L5
#define r_TMP G1
-#define r_TMP2 G2
-#define r_OFF G3
+#define r_TMP2 G3
/* assembly code in arch/sparc/net/bpf_jit_asm.S */
extern u32 bpf_jit_load_word[];
@@ -54,15 +65,13 @@ extern u32 bpf_jit_load_byte_negative_offset[];
extern u32 bpf_jit_load_byte_msh_negative_offset[];
#else
+#define r_RESULT %o0
#define r_SKB %o0
-#define r_A %o1
-#define r_X %o2
-#define r_saved_O7 %o3
-#define r_HEADLEN %o4
-#define r_SKB_DATA %o5
+#define r_OFF %o1
+#define r_HEADLEN %l4
+#define r_SKB_DATA %l5
#define r_TMP %g1
-#define r_TMP2 %g2
-#define r_OFF %g3
+#define r_TMP2 %g3
#endif
#endif /* _BPF_JIT_H */
diff --git a/arch/sparc/net/bpf_jit_asm.S b/arch/sparc/net/bpf_jit_asm.S
index 8c83f4b..7d68731 100644
--- a/arch/sparc/net/bpf_jit_asm.S
+++ b/arch/sparc/net/bpf_jit_asm.S
@@ -32,7 +32,7 @@ bpf_jit_load_word_positive_offset:
bne load_word_unaligned
nop
retl
- ld [r_TMP], r_A
+ ld [r_TMP], r_RESULT
load_word_unaligned:
ldub [r_TMP + 0x0], r_OFF
ldub [r_TMP + 0x1], r_TMP2
@@ -44,7 +44,7 @@ load_word_unaligned:
ldub [r_TMP + 0x3], r_TMP2
sll r_OFF, 8, r_OFF
retl
- or r_OFF, r_TMP2, r_A
+ or r_OFF, r_TMP2, r_RESULT
.globl bpf_jit_load_half
bpf_jit_load_half:
@@ -61,13 +61,13 @@ bpf_jit_load_half_positive_offset:
bne load_half_unaligned
nop
retl
- lduh [r_TMP], r_A
+ lduh [r_TMP], r_RESULT
load_half_unaligned:
ldub [r_TMP + 0x0], r_OFF
ldub [r_TMP + 0x1], r_TMP2
sll r_OFF, 8, r_OFF
retl
- or r_OFF, r_TMP2, r_A
+ or r_OFF, r_TMP2, r_RESULT
.globl bpf_jit_load_byte
bpf_jit_load_byte:
@@ -80,27 +80,12 @@ bpf_jit_load_byte_positive_offset:
bge bpf_slow_path_byte
nop
retl
- ldub [r_SKB_DATA + r_OFF], r_A
-
- .globl bpf_jit_load_byte_msh
-bpf_jit_load_byte_msh:
- cmp r_OFF, 0
- bl bpf_slow_path_byte_msh_neg
- nop
- .globl bpf_jit_load_byte_msh_positive_offset
-bpf_jit_load_byte_msh_positive_offset:
- cmp r_OFF, r_HEADLEN
- bge bpf_slow_path_byte_msh
- nop
- ldub [r_SKB_DATA + r_OFF], r_OFF
- and r_OFF, 0xf, r_OFF
- retl
- sll r_OFF, 2, r_X
+ ldub [r_SKB_DATA + r_OFF], r_RESULT
#define bpf_slow_path_common(LEN) \
save %sp, -SAVE_SZ, %sp; \
mov %i0, %o0; \
- mov r_OFF, %o1; \
+ mov %i1, %o1; \
add %fp, SCRATCH_OFF, %o2; \
call skb_copy_bits; \
mov (LEN), %o3; \
@@ -110,33 +95,26 @@ bpf_jit_load_byte_msh_positive_offset:
bpf_slow_path_word:
bpf_slow_path_common(4)
bl bpf_error
- ld [%sp + SCRATCH_OFF], r_A
+ ld [%sp + SCRATCH_OFF], r_RESULT
retl
nop
bpf_slow_path_half:
bpf_slow_path_common(2)
bl bpf_error
- lduh [%sp + SCRATCH_OFF], r_A
+ lduh [%sp + SCRATCH_OFF], r_RESULT
retl
nop
bpf_slow_path_byte:
bpf_slow_path_common(1)
bl bpf_error
- ldub [%sp + SCRATCH_OFF], r_A
+ ldub [%sp + SCRATCH_OFF], r_RESULT
retl
nop
-bpf_slow_path_byte_msh:
- bpf_slow_path_common(1)
- bl bpf_error
- ldub [%sp + SCRATCH_OFF], r_A
- and r_OFF, 0xf, r_OFF
- retl
- sll r_OFF, 2, r_X
#define bpf_negative_common(LEN) \
save %sp, -SAVE_SZ, %sp; \
mov %i0, %o0; \
- mov r_OFF, %o1; \
+ mov %i1, %o1; \
SIGN_EXTEND(%o1); \
call bpf_internal_load_pointer_neg_helper; \
mov (LEN), %o2; \
@@ -157,7 +135,7 @@ bpf_jit_load_word_negative_offset:
bne load_word_unaligned
nop
retl
- ld [r_TMP], r_A
+ ld [r_TMP], r_RESULT
bpf_slow_path_half_neg:
sethi %hi(SKF_MAX_NEG_OFF), r_TMP
@@ -171,7 +149,7 @@ bpf_jit_load_half_negative_offset:
bne load_half_unaligned
nop
retl
- lduh [r_TMP], r_A
+ lduh [r_TMP], r_RESULT
bpf_slow_path_byte_neg:
sethi %hi(SKF_MAX_NEG_OFF), r_TMP
@@ -182,27 +160,9 @@ bpf_slow_path_byte_neg:
bpf_jit_load_byte_negative_offset:
bpf_negative_common(1)
retl
- ldub [r_TMP], r_A
-
-bpf_slow_path_byte_msh_neg:
- sethi %hi(SKF_MAX_NEG_OFF), r_TMP
- cmp r_OFF, r_TMP
- bl bpf_error
- nop
- .globl bpf_jit_load_byte_msh_negative_offset
-bpf_jit_load_byte_msh_negative_offset:
- bpf_negative_common(1)
- ldub [r_TMP], r_OFF
- and r_OFF, 0xf, r_OFF
- retl
- sll r_OFF, 2, r_X
+ ldub [r_TMP], r_RESULT
bpf_error:
- /* Make the JIT program return zero. The JIT epilogue
- * stores away the original %o7 into r_saved_O7. The
- * normal leaf function return is to use "retl" which
- * would evalute to "jmpl %o7 + 8, %g0" but we want to
- * use the saved value thus the sequence you see here.
- */
- jmpl r_saved_O7 + 8, %g0
- clr %o0
+ /* Make the JIT program itself return zero. */
+ ret
+ restore %g0, %g0, %o0
diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
index a6d9204..a43d686 100644
--- a/arch/sparc/net/bpf_jit_comp.c
+++ b/arch/sparc/net/bpf_jit_comp.c
@@ -51,6 +51,7 @@ static void bpf_flush_icache(void *start_, void *end_)
#define F1(X) OP(X)
#define F2(X, Y) (OP(X) | OP2(Y))
#define F3(X, Y) (OP(X) | OP3(Y))
+#define ASI(X) (((X) & 0xff) << 5)
#define CONDN COND(0x0)
#define CONDE COND(0x1)
@@ -73,14 +74,22 @@ static void bpf_flush_icache(void *start_, void *end_)
#define CONDLU CONDCS
#define WDISP22(X) (((X) >> 2) & 0x3fffff)
+#define WDISP19(X) (((X) >> 2) & 0x7ffff)
-#define BA (F2(0, 2) | CONDA)
-#define BGU (F2(0, 2) | CONDGU)
-#define BLEU (F2(0, 2) | CONDLEU)
-#define BGEU (F2(0, 2) | CONDGEU)
-#define BLU (F2(0, 2) | CONDLU)
-#define BE (F2(0, 2) | CONDE)
-#define BNE (F2(0, 2) | CONDNE)
+#define ANNUL (1 << 29)
+#define XCC (1 << 21)
+
+#define BRANCH (F2(0, 1) | XCC)
+
+#define BA (BRANCH | CONDA)
+#define BG (BRANCH | CONDG)
+#define BGU (BRANCH | CONDGU)
+#define BLEU (BRANCH | CONDLEU)
+#define BGE (BRANCH | CONDGE)
+#define BGEU (BRANCH | CONDGEU)
+#define BLU (BRANCH | CONDLU)
+#define BE (BRANCH | CONDE)
+#define BNE (BRANCH | CONDNE)
#ifdef CONFIG_SPARC64
#define BE_PTR (F2(0, 1) | CONDE | (2 << 20))
@@ -100,11 +109,19 @@ static void bpf_flush_icache(void *start_, void *end_)
#define XOR F3(2, 0x03)
#define SUB F3(2, 0x04)
#define SUBCC F3(2, 0x14)
-#define MUL F3(2, 0x0a) /* umul */
-#define DIV F3(2, 0x0e) /* udiv */
+#define MUL F3(2, 0x0a)
+#define MULX F3(2, 0x09)
+#define UDIVX F3(2, 0x0d)
+#define DIV F3(2, 0x0e)
#define SLL F3(2, 0x25)
+#define SLLX (F3(2, 0x25)|(1<<12))
+#define SRA F3(2, 0x27)
+#define SRAX (F3(2, 0x27)|(1<<12))
#define SRL F3(2, 0x26)
+#define SRLX (F3(2, 0x26)|(1<<12))
#define JMPL F3(2, 0x38)
+#define SAVE F3(2, 0x3c)
+#define RESTORE F3(2, 0x3d)
#define CALL F1(1)
#define BR F2(0, 0x01)
#define RD_Y F3(2, 0x28)
@@ -114,7 +131,14 @@ static void bpf_flush_icache(void *start_, void *end_)
#define LD8 F3(3, 0x01)
#define LD16 F3(3, 0x02)
#define LD64 F3(3, 0x0b)
+#define LD64A F3(3, 0x1b)
+#define ST8 F3(3, 0x05)
+#define ST16 F3(3, 0x06)
#define ST32 F3(3, 0x04)
+#define ST64 F3(3, 0x0e)
+
+#define CAS F3(3, 0x3c)
+#define CASX F3(3, 0x3e)
#ifdef CONFIG_SPARC64
#define LDPTR LD64
@@ -131,685 +155,1030 @@ static void bpf_flush_icache(void *start_, void *end_)
#define LDPTRI (LDPTR | IMMED)
#define ST32I (ST32 | IMMED)
-#define emit_nop() \
-do { \
- *prog++ = SETHI(0, G0); \
-} while (0)
-
-#define emit_neg() \
-do { /* sub %g0, r_A, r_A */ \
- *prog++ = SUB | RS1(G0) | RS2(r_A) | RD(r_A); \
-} while (0)
-
-#define emit_reg_move(FROM, TO) \
-do { /* or %g0, FROM, TO */ \
- *prog++ = OR | RS1(G0) | RS2(FROM) | RD(TO); \
-} while (0)
-
-#define emit_clear(REG) \
-do { /* or %g0, %g0, REG */ \
- *prog++ = OR | RS1(G0) | RS2(G0) | RD(REG); \
-} while (0)
-
-#define emit_set_const(K, REG) \
-do { /* sethi %hi(K), REG */ \
- *prog++ = SETHI(K, REG); \
- /* or REG, %lo(K), REG */ \
- *prog++ = OR_LO(K, REG); \
-} while (0)
-
- /* Emit
- *
- * OP r_A, r_X, r_A
- */
-#define emit_alu_X(OPCODE) \
-do { \
- seen |= SEEN_XREG; \
- *prog++ = OPCODE | RS1(r_A) | RS2(r_X) | RD(r_A); \
-} while (0)
-
- /* Emit either:
- *
- * OP r_A, K, r_A
- *
- * or
- *
- * sethi %hi(K), r_TMP
- * or r_TMP, %lo(K), r_TMP
- * OP r_A, r_TMP, r_A
- *
- * depending upon whether K fits in a signed 13-bit
- * immediate instruction field. Emit nothing if K
- * is zero.
- */
-#define emit_alu_K(OPCODE, K) \
-do { \
- if (K || OPCODE == AND || OPCODE == MUL) { \
- unsigned int _insn = OPCODE; \
- _insn |= RS1(r_A) | RD(r_A); \
- if (is_simm13(K)) { \
- *prog++ = _insn | IMMED | S13(K); \
- } else { \
- emit_set_const(K, r_TMP); \
- *prog++ = _insn | RS2(r_TMP); \
- } \
- } \
-} while (0)
-
-#define emit_loadimm(K, DEST) \
-do { \
- if (is_simm13(K)) { \
- /* or %g0, K, DEST */ \
- *prog++ = OR | IMMED | RS1(G0) | S13(K) | RD(DEST); \
- } else { \
- emit_set_const(K, DEST); \
- } \
-} while (0)
-
-#define emit_loadptr(BASE, STRUCT, FIELD, DEST) \
-do { unsigned int _off = offsetof(STRUCT, FIELD); \
- BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(void *)); \
- *prog++ = LDPTRI | RS1(BASE) | S13(_off) | RD(DEST); \
-} while (0)
-
-#define emit_load32(BASE, STRUCT, FIELD, DEST) \
-do { unsigned int _off = offsetof(STRUCT, FIELD); \
- BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(u32)); \
- *prog++ = LD32I | RS1(BASE) | S13(_off) | RD(DEST); \
-} while (0)
-
-#define emit_load16(BASE, STRUCT, FIELD, DEST) \
-do { unsigned int _off = offsetof(STRUCT, FIELD); \
- BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(u16)); \
- *prog++ = LD16I | RS1(BASE) | S13(_off) | RD(DEST); \
-} while (0)
-
-#define __emit_load8(BASE, STRUCT, FIELD, DEST) \
-do { unsigned int _off = offsetof(STRUCT, FIELD); \
- *prog++ = LD8I | RS1(BASE) | S13(_off) | RD(DEST); \
-} while (0)
-
-#define emit_load8(BASE, STRUCT, FIELD, DEST) \
-do { BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(u8)); \
- __emit_load8(BASE, STRUCT, FIELD, DEST); \
-} while (0)
+struct jit_ctx {
+ struct bpf_prog *prog;
+ unsigned int *offset;
+ int idx;
+ int epilogue_offset;
+ bool tmp_1_used;
+ bool tmp_2_used;
+ bool tmp_3_used;
+ bool saw_ld_abs_ind;
+ bool saw_frame_pointer;
+ u32 *image;
+};
+
+#define TMP_REG_1 (MAX_BPF_JIT_REG + 0)
+#define TMP_REG_2 (MAX_BPF_JIT_REG + 1)
+#define SKB_HLEN_REG (MAX_BPF_JIT_REG + 2)
+#define SKB_DATA_REG (MAX_BPF_JIT_REG + 3)
+#define TMP_REG_3 (MAX_BPF_JIT_REG + 4)
+
+/* Map BPF registers to SPARC registers */
+static const int bpf2sparc[] = {
+ /* return value from in-kernel function, and exit value from eBPF */
+ [BPF_REG_0] = I5,
+
+ /* arguments from eBPF program to in-kernel function */
+ [BPF_REG_1] = I0,
+ [BPF_REG_2] = I1,
+ [BPF_REG_3] = I2,
+ [BPF_REG_4] = I3,
+ [BPF_REG_5] = I4,
+
+ /* callee saved registers that in-kernel function will preserve */
+ [BPF_REG_6] = L0,
+ [BPF_REG_7] = L1,
+ [BPF_REG_8] = L2,
+ [BPF_REG_9] = L3,
+
+ /* read-only frame pointer to access stack */
+ [BPF_REG_FP] = FP,
+
+ /* temporary register for internal BPF JIT */
+ [TMP_REG_1] = G1,
+ [TMP_REG_2] = G3,
+ [TMP_REG_3] = L6,
+
+ [SKB_HLEN_REG] = L4,
+ [SKB_DATA_REG] = L5,
+};
+
+static void emit(const u32 insn, struct jit_ctx *ctx)
+{
+ if (ctx->image != NULL)
+ ctx->image[ctx->idx] = insn;
-#ifdef CONFIG_SPARC64
-#define BIAS (STACK_BIAS - 4)
-#else
-#define BIAS (-4)
-#endif
+ ctx->idx++;
+}
-#define emit_ldmem(OFF, DEST) \
-do { *prog++ = LD32I | RS1(SP) | S13(BIAS - (OFF)) | RD(DEST); \
-} while (0)
+static void emit_call(u32 *func, struct jit_ctx *ctx)
+{
+ if (ctx->image != NULL) {
+ void *here = &ctx->image[ctx->idx];
+ unsigned int off;
-#define emit_stmem(OFF, SRC) \
-do { *prog++ = ST32I | RS1(SP) | S13(BIAS - (OFF)) | RD(SRC); \
-} while (0)
+ off = (void *)func - here;
+ ctx->image[ctx->idx] = CALL | ((off >> 2) & 0x3fffffff);
+ }
+ ctx->idx++;
+}
-#ifdef CONFIG_SMP
-#ifdef CONFIG_SPARC64
-#define emit_load_cpu(REG) \
- emit_load16(G6, struct thread_info, cpu, REG)
-#else
-#define emit_load_cpu(REG) \
- emit_load32(G6, struct thread_info, cpu, REG)
-#endif
-#else
-#define emit_load_cpu(REG) emit_clear(REG)
-#endif
+static void emit_nop(struct jit_ctx *ctx)
+{
+ emit(SETHI(0, G0), ctx);
+}
-#define emit_skb_loadptr(FIELD, DEST) \
- emit_loadptr(r_SKB, struct sk_buff, FIELD, DEST)
-#define emit_skb_load32(FIELD, DEST) \
- emit_load32(r_SKB, struct sk_buff, FIELD, DEST)
-#define emit_skb_load16(FIELD, DEST) \
- emit_load16(r_SKB, struct sk_buff, FIELD, DEST)
-#define __emit_skb_load8(FIELD, DEST) \
- __emit_load8(r_SKB, struct sk_buff, FIELD, DEST)
-#define emit_skb_load8(FIELD, DEST) \
- emit_load8(r_SKB, struct sk_buff, FIELD, DEST)
+static void emit_reg_move(u32 from, u32 to, struct jit_ctx *ctx)
+{
+ emit(OR | RS1(G0) | RS2(from) | RD(to), ctx);
+}
-#define emit_jmpl(BASE, IMM_OFF, LREG) \
- *prog++ = (JMPL | IMMED | RS1(BASE) | S13(IMM_OFF) | RD(LREG))
+/* Emit 32-bit constant, zero extended. */
+static void emit_set_const(s32 K, u32 reg, struct jit_ctx *ctx)
+{
+ emit(SETHI(K, reg), ctx);
+ emit(OR_LO(K, reg), ctx);
+}
-#define emit_call(FUNC) \
-do { void *_here = image + addrs[i] - 8; \
- unsigned int _off = (void *)(FUNC) - _here; \
- *prog++ = CALL | (((_off) >> 2) & 0x3fffffff); \
- emit_nop(); \
-} while (0)
+/* Emit 32-bit constant, sign extended. */
+static void emit_set_const_sext(s32 K, u32 reg, struct jit_ctx *ctx)
+{
+ if (K >= 0) {
+ emit(SETHI(K, reg), ctx);
+ emit(OR_LO(K, reg), ctx);
+ } else {
+ u32 hbits = ~(u32) K;
+ u32 lbits = -0x400 | (u32) K;
+
+ emit(SETHI(hbits, reg), ctx);
+ emit(XOR | IMMED | RS1(reg) | S13(lbits) | RD(reg), ctx);
+ }
+}
-#define emit_branch(BR_OPC, DEST) \
-do { unsigned int _here = addrs[i] - 8; \
- *prog++ = BR_OPC | WDISP22((DEST) - _here); \
-} while (0)
+/* Emit: OP DST, SRC, DST */
+static void emit_alu(u32 opcode, u32 src, u32 dst, struct jit_ctx *ctx)
+{
+ emit(opcode | RS1(dst) | RS2(src) | RD(dst), ctx);
+}
-#define emit_branch_off(BR_OPC, OFF) \
-do { *prog++ = BR_OPC | WDISP22(OFF); \
-} while (0)
+/* Emit: OP A, B, C */
+static void emit_alu3(u32 opcode, u32 a, u32 b, u32 c, struct jit_ctx *ctx)
+{
+ emit(opcode | RS1(a) | RS2(b) | RD(c), ctx);
+}
-#define emit_jump(DEST) emit_branch(BA, DEST)
+/* Emit either:
+ *
+ * OP DST, K, DST
+ *
+ * or
+ *
+ * sethi %hi(K), r_TMP
+ * or r_TMP, %lo(K), r_TMP
+ * OP DST, r_TMP, DST
+ *
+ * depending upon whether K fits in a signed 13-bit
+ * immediate instruction field.
+ */
+static void emit_alu_K(unsigned int opcode, unsigned int dst, unsigned int imm,
+ struct jit_ctx *ctx)
+{
+ bool small_immed = is_simm13(imm);
+ unsigned int insn = opcode;
-#define emit_read_y(REG) *prog++ = RD_Y | RD(REG)
-#define emit_write_y(REG) *prog++ = WR_Y | IMMED | RS1(REG) | S13(0)
+ insn |= RS1(dst) | RD(dst);
+ if (small_immed) {
+ emit(insn | IMMED | S13(imm), ctx);
+ } else {
+ unsigned int tmp = bpf2sparc[TMP_REG_1];
-#define emit_cmp(R1, R2) \
- *prog++ = (SUBCC | RS1(R1) | RS2(R2) | RD(G0))
+ ctx->tmp_1_used = true;
-#define emit_cmpi(R1, IMM) \
- *prog++ = (SUBCC | IMMED | RS1(R1) | S13(IMM) | RD(G0));
+ emit_set_const_sext(imm, tmp, ctx);
+ emit(insn | RS2(tmp), ctx);
+ }
+}
-#define emit_btst(R1, R2) \
- *prog++ = (ANDCC | RS1(R1) | RS2(R2) | RD(G0))
+/* Emit either:
+ *
+ * OP SRC, K, DST
+ *
+ * or
+ *
+ * sethi %hi(K), r_TMP
+ * or r_TMP, %lo(K), r_TMP
+ * OP SRC, r_TMP, DST
+ *
+ * depending upon whether K fits in a signed 13-bit
+ * immediate instruction field.
+ */
+static void emit_alu3_K(unsigned int opcode, unsigned int src, unsigned int imm,
+ unsigned int dst, struct jit_ctx *ctx)
+{
+ bool small_immed = is_simm13(imm);
+ unsigned int insn = opcode;
-#define emit_btsti(R1, IMM) \
- *prog++ = (ANDCC | IMMED | RS1(R1) | S13(IMM) | RD(G0));
+ insn |= RS1(src) | RD(dst);
+ if (small_immed) {
+ emit(insn | IMMED | S13(imm), ctx);
+ } else {
+ unsigned int tmp = bpf2sparc[TMP_REG_1];
-#define emit_sub(R1, R2, R3) \
- *prog++ = (SUB | RS1(R1) | RS2(R2) | RD(R3))
+ ctx->tmp_1_used = true;
-#define emit_subi(R1, IMM, R3) \
- *prog++ = (SUB | IMMED | RS1(R1) | S13(IMM) | RD(R3))
+ emit_set_const_sext(imm, tmp, ctx);
+ emit(insn | RS2(tmp), ctx);
+ }
+}
-#define emit_add(R1, R2, R3) \
- *prog++ = (ADD | RS1(R1) | RS2(R2) | RD(R3))
+static void emit_loadimm32(s32 K, unsigned int dest, struct jit_ctx *ctx)
+{
+ if (K >= 0 && is_simm13(K)) {
+ /* or %g0, K, DEST */
+ emit(OR | IMMED | RS1(G0) | S13(K) | RD(dest), ctx);
+ } else {
+ emit_set_const(K, dest, ctx);
+ }
+}
-#define emit_addi(R1, IMM, R3) \
- *prog++ = (ADD | IMMED | RS1(R1) | S13(IMM) | RD(R3))
+static void emit_loadimm(s32 K, unsigned int dest, struct jit_ctx *ctx)
+{
+ if (is_simm13(K)) {
+ /* or %g0, K, DEST */
+ emit(OR | IMMED | RS1(G0) | S13(K) | RD(dest), ctx);
+ } else {
+ emit_set_const(K, dest, ctx);
+ }
+}
-#define emit_and(R1, R2, R3) \
- *prog++ = (AND | RS1(R1) | RS2(R2) | RD(R3))
+static void emit_loadimm_sext(s32 K, unsigned int dest, struct jit_ctx *ctx)
+{
+ if (is_simm13(K)) {
+ /* or %g0, K, DEST */
+ emit(OR | IMMED | RS1(G0) | S13(K) | RD(dest), ctx);
+ } else {
+ emit_set_const_sext(K, dest, ctx);
+ }
+}
-#define emit_andi(R1, IMM, R3) \
- *prog++ = (AND | IMMED | RS1(R1) | S13(IMM) | RD(R3))
+static void emit_loadimm64(u64 K, unsigned int dest, struct jit_ctx *ctx)
+{
+ unsigned int tmp = bpf2sparc[TMP_REG_1];
+ u32 high_part = (K >> 32);
+ u32 low_part = (K & 0xffffffff);
-#define emit_alloc_stack(SZ) \
- *prog++ = (SUB | IMMED | RS1(SP) | S13(SZ) | RD(SP))
+ ctx->tmp_1_used = true;
-#define emit_release_stack(SZ) \
- *prog++ = (ADD | IMMED | RS1(SP) | S13(SZ) | RD(SP))
+ emit_set_const(high_part, tmp, ctx);
+ emit_set_const(low_part, dest, ctx);
+ emit_alu_K(SLLX, tmp, 32, ctx);
+ emit(OR | RS1(dest) | RS2(tmp) | RD(dest), ctx);
+}
-/* A note about branch offset calculations. The addrs[] array,
- * indexed by BPF instruction, records the address after all the
- * sparc instructions emitted for that BPF instruction.
- *
- * The most common case is to emit a branch at the end of such
- * a code sequence. So this would be two instructions, the
- * branch and it's delay slot.
- *
- * Therefore by default the branch emitters calculate the branch
- * offset field as:
- *
- * destination - (addrs[i] - 8)
- *
- * This "addrs[i] - 8" is the address of the branch itself or
- * what "." would be in assembler notation. The "8" part is
- * how we take into consideration the branch and it's delay
- * slot mentioned above.
- *
- * Sometimes we need to emit a branch earlier in the code
- * sequence. And in these situations we adjust "destination"
- * to accommodate this difference. For example, if we needed
- * to emit a branch (and it's delay slot) right before the
- * final instruction emitted for a BPF opcode, we'd use
- * "destination + 4" instead of just plain "destination" above.
- *
- * This is why you see all of these funny emit_branch() and
- * emit_jump() calls with adjusted offsets.
- */
+static void emit_branch(unsigned int br_opc, unsigned int from_idx, unsigned int to_idx,
+ struct jit_ctx *ctx)
+{
+ unsigned int off = to_idx - from_idx;
+
+ if (br_opc & XCC)
+ emit(br_opc | WDISP19(off << 2), ctx);
+ else
+ emit(br_opc | WDISP22(off << 2), ctx);
+}
+
+#define emit_read_y(REG, CTX) emit(RD_Y | RD(REG), CTX)
+#define emit_write_y(REG, CTX) emit(WR_Y | IMMED | RS1(REG) | S13(0), CTX)
+
+#define emit_cmp(R1, R2, CTX) \
+ emit(SUBCC | RS1(R1) | RS2(R2) | RD(G0), CTX)
-void bpf_jit_compile(struct bpf_prog *fp)
+#define emit_cmpi(R1, IMM, CTX) \
+ emit(SUBCC | IMMED | RS1(R1) | S13(IMM) | RD(G0), CTX);
+
+#define emit_btst(R1, R2, CTX) \
+ emit(ANDCC | RS1(R1) | RS2(R2) | RD(G0), CTX)
+
+#define emit_btsti(R1, IMM, CTX) \
+ emit(ANDCC | IMMED | RS1(R1) | S13(IMM) | RD(G0), CTX)
+
+static void load_skb_regs(struct jit_ctx *ctx, u8 r_skb)
{
- unsigned int cleanup_addr, proglen, oldproglen = 0;
- u32 temp[8], *prog, *func, seen = 0, pass;
- const struct sock_filter *filter = fp->insns;
- int i, flen = fp->len, pc_ret0 = -1;
- unsigned int *addrs;
- void *image;
+ const u8 r_headlen = bpf2sparc[SKB_HLEN_REG];
+ const u8 r_data = bpf2sparc[SKB_DATA_REG];
+ const u8 r_tmp = bpf2sparc[TMP_REG_1];
+ unsigned int off;
- if (!bpf_jit_enable)
- return;
+ off = offsetof(struct sk_buff, len);
+ emit(LD32I | RS1(r_skb) | S13(off) | RD(r_headlen), ctx);
- addrs = kmalloc(flen * sizeof(*addrs), GFP_KERNEL);
- if (addrs == NULL)
- return;
+ off = offsetof(struct sk_buff, data_len);
+ emit(LD32I | RS1(r_skb) | S13(off) | RD(r_tmp), ctx);
- /* Before first pass, make a rough estimation of addrs[]
- * each bpf instruction is translated to less than 64 bytes
- */
- for (proglen = 0, i = 0; i < flen; i++) {
- proglen += 64;
- addrs[i] = proglen;
+ emit(SUB | RS1(r_headlen) | RS2(r_tmp) | RD(r_headlen), ctx);
+
+ off = offsetof(struct sk_buff, data);
+ emit(LDPTRI | RS1(r_skb) | S13(off) | RD(r_data), ctx);
+}
+
+static void build_prologue(struct jit_ctx *ctx)
+{
+ s32 stack_needed = 176;
+
+ if (ctx->saw_frame_pointer)
+ stack_needed += MAX_BPF_STACK;
+
+ /* save %sp, -176, %sp */
+ emit(SAVE | IMMED | RS1(SP) | S13(-stack_needed) | RD(SP), ctx);
+
+ if (ctx->saw_ld_abs_ind) {
+ load_skb_regs(ctx, bpf2sparc[BPF_REG_1]);
+ } else {
+ emit_nop(ctx);
+ emit_nop(ctx);
+ emit_nop(ctx);
+ emit_nop(ctx);
}
- cleanup_addr = proglen; /* epilogue address */
- image = NULL;
- for (pass = 0; pass < 10; pass++) {
- u8 seen_or_pass0 = (pass == 0) ? (SEEN_XREG | SEEN_DATAREF | SEEN_MEM) : seen;
-
- /* no prologue/epilogue for trivial filters (RET something) */
- proglen = 0;
- prog = temp;
-
- /* Prologue */
- if (seen_or_pass0) {
- if (seen_or_pass0 & SEEN_MEM) {
- unsigned int sz = BASE_STACKFRAME;
- sz += BPF_MEMWORDS * sizeof(u32);
- emit_alloc_stack(sz);
- }
-
- /* Make sure we dont leek kernel memory. */
- if (seen_or_pass0 & SEEN_XREG)
- emit_clear(r_X);
-
- /* If this filter needs to access skb data,
- * load %o4 and %o5 with:
- * %o4 = skb->len - skb->data_len
- * %o5 = skb->data
- * And also back up %o7 into r_saved_O7 so we can
- * invoke the stubs using 'call'.
+}
+
+static void build_epilogue(struct jit_ctx *ctx)
+{
+ ctx->epilogue_offset = ctx->idx;
+
+ /* ret (jmpl %i7 + 8, %g0) */
+ emit(JMPL | IMMED | RS1(I7) | S13(8) | RD(G0), ctx);
+
+ /* restore %i5, %g0, %o0 */
+ emit(RESTORE | RS1(I5) | RS2(G0) | RD(O0), ctx);
+}
+
+static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
+{
+ const u8 code = insn->code;
+ const u8 dst = bpf2sparc[insn->dst_reg];
+ const u8 src = bpf2sparc[insn->src_reg];
+ const int i = insn - ctx->prog->insnsi;
+ const s16 off = insn->off;
+ const s32 imm = insn->imm;
+ u32 *func;
+
+ if (insn->src_reg == BPF_REG_FP || insn->dst_reg == BPF_REG_FP) {
+ ctx->saw_frame_pointer = true;
+ if (BPF_CLASS(code) == BPF_ALU ||
+ BPF_CLASS(code) == BPF_ALU64) {
+ pr_err_once("ALU op on FP not supported by JIT\n");
+ return -EINVAL;
+ }
+ }
+
+ switch (code) {
+ /* dst = src */
+ case BPF_ALU | BPF_MOV | BPF_X:
+ emit_alu3_K(SRL, src, 0, dst, ctx);
+ break;
+ case BPF_ALU64 | BPF_MOV | BPF_X:
+ emit_reg_move(src, dst, ctx);
+ break;
+ /* dst = dst OP src */
+ case BPF_ALU | BPF_ADD | BPF_X:
+ case BPF_ALU64 | BPF_ADD | BPF_X:
+ emit_alu(ADD, src, dst, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU | BPF_SUB | BPF_X:
+ case BPF_ALU64 | BPF_SUB | BPF_X:
+ emit_alu(SUB, src, dst, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU | BPF_AND | BPF_X:
+ case BPF_ALU64 | BPF_AND | BPF_X:
+ emit_alu(AND, src, dst, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU | BPF_OR | BPF_X:
+ case BPF_ALU64 | BPF_OR | BPF_X:
+ emit_alu(OR, src, dst, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU | BPF_XOR | BPF_X:
+ case BPF_ALU64 | BPF_XOR | BPF_X:
+ emit_alu(XOR, src, dst, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU | BPF_MUL | BPF_X:
+ emit_alu(MUL, src, dst, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU64 | BPF_MUL | BPF_X:
+ emit_alu(MULX, src, dst, ctx);
+ break;
+ case BPF_ALU | BPF_DIV | BPF_X:
+ emit_cmp(src, G0, ctx);
+ emit_branch(BE|ANNUL, ctx->idx, ctx->epilogue_offset, ctx);
+ emit_loadimm(0, bpf2sparc[BPF_REG_0], ctx);
+
+ emit_write_y(G0, ctx);
+ emit_alu(DIV, src, dst, ctx);
+ break;
+
+ case BPF_ALU64 | BPF_DIV | BPF_X:
+ emit_cmp(src, G0, ctx);
+ emit_branch(BE|ANNUL, ctx->idx, ctx->epilogue_offset, ctx);
+ emit_loadimm(0, bpf2sparc[BPF_REG_0], ctx);
+
+ emit_alu(UDIVX, src, dst, ctx);
+ break;
+
+ case BPF_ALU | BPF_MOD | BPF_X: {
+ unsigned int tmp = bpf2sparc[TMP_REG_1];
+
+ ctx->tmp_1_used = true;
+
+ emit_cmp(src, G0, ctx);
+ emit_branch(BE|ANNUL, ctx->idx, ctx->epilogue_offset, ctx);
+ emit_loadimm(0, bpf2sparc[BPF_REG_0], ctx);
+
+ emit_write_y(G0, ctx);
+ emit_alu3(DIV, dst, src, tmp, ctx);
+ emit_alu3(MULX, tmp, src, tmp, ctx);
+ emit_alu3(SUB, dst, tmp, dst, ctx);
+ goto do_alu32_trunc;
+ }
+ case BPF_ALU64 | BPF_MOD | BPF_X: {
+ unsigned int tmp = bpf2sparc[TMP_REG_1];
+
+ ctx->tmp_1_used = true;
+
+ emit_cmp(src, G0, ctx);
+ emit_branch(BE|ANNUL, ctx->idx, ctx->epilogue_offset, ctx);
+ emit_loadimm(0, bpf2sparc[BPF_REG_0], ctx);
+
+ emit_alu3(UDIVX, dst, src, tmp, ctx);
+ emit_alu3(MULX, tmp, src, tmp, ctx);
+ emit_alu3(SUB, dst, tmp, dst, ctx);
+ break;
+ }
+ case BPF_ALU | BPF_LSH | BPF_X:
+ emit_alu(SLL, src, dst, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU64 | BPF_LSH | BPF_X:
+ emit_alu(SLLX, src, dst, ctx);
+ break;
+ case BPF_ALU | BPF_RSH | BPF_X:
+ emit_alu(SRL, src, dst, ctx);
+ break;
+ case BPF_ALU64 | BPF_RSH | BPF_X:
+ emit_alu(SRLX, src, dst, ctx);
+ break;
+ case BPF_ALU | BPF_ARSH | BPF_X:
+ emit_alu(SRA, src, dst, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU64 | BPF_ARSH | BPF_X:
+ emit_alu(SRAX, src, dst, ctx);
+ break;
+
+ /* dst = -dst */
+ case BPF_ALU | BPF_NEG:
+ case BPF_ALU64 | BPF_NEG:
+ emit(SUB | RS1(0) | RS2(dst) | RD(dst), ctx);
+ goto do_alu32_trunc;
+
+ case BPF_ALU | BPF_END | BPF_FROM_BE:
+ switch (imm) {
+ case 16:
+ emit_alu_K(SLL, dst, 16, ctx);
+ emit_alu_K(SRL, dst, 16, ctx);
+ break;
+ case 32:
+ emit_alu_K(SRL, dst, 0, ctx);
+ break;
+ case 64:
+ /* nop */
+ break;
+
+ }
+ break;
+
+ /* dst = BSWAP##imm(dst) */
+ case BPF_ALU | BPF_END | BPF_FROM_LE: {
+ const u8 tmp = bpf2sparc[TMP_REG_1];
+ const u8 tmp2 = bpf2sparc[TMP_REG_2];
+
+ ctx->tmp_1_used = true;
+ switch (imm) {
+ case 16:
+ emit_alu3_K(AND, dst, 0xff, tmp, ctx);
+ emit_alu3_K(SRL, dst, 8, dst, ctx);
+ emit_alu3_K(AND, dst, 0xff, dst, ctx);
+ emit_alu3_K(SLL, tmp, 8, tmp, ctx);
+ emit_alu(OR, tmp, dst, ctx);
+ break;
+
+ case 32:
+ ctx->tmp_2_used = true;
+ emit_alu3_K(SRL, dst, 24, tmp, ctx); /* tmp = dst >> 24 */
+ emit_alu3_K(SRL, dst, 16, tmp2, ctx); /* tmp2 = dst >> 16 */
+ emit_alu3_K(AND, tmp2, 0xff, tmp2, ctx);/* tmp2 = tmp2 & 0xff */
+ emit_alu3_K(SLL, tmp2, 8, tmp2, ctx); /* tmp2 = tmp2 << 8 */
+ emit_alu(OR, tmp2, tmp, ctx); /* tmp = tmp | tmp2 */
+ emit_alu3_K(SRL, dst, 8, tmp2, ctx); /* tmp2 = dst >> 8 */
+ emit_alu3_K(AND, tmp2, 0xff, tmp2, ctx);/* tmp2 = tmp2 & 0xff */
+ emit_alu3_K(SLL, tmp2, 16, tmp2, ctx); /* tmp2 = tmp2 << 16 */
+ emit_alu(OR, tmp2, tmp, ctx); /* tmp = tmp | tmp2 */
+ emit_alu3_K(AND, dst, 0xff, dst, ctx); /* dst = dst & 0xff */
+ emit_alu3_K(SLL, dst, 24, dst, ctx); /* dst = dst << 24 */
+ emit_alu(OR, tmp, dst, ctx); /* dst = dst | tmp */
+ break;
+
+ case 64:
+ emit_alu3_K(ADD, SP, STACK_BIAS + 128, tmp, ctx);
+ emit(ST64 | RS1(tmp) | RS2(G0) | RD(dst), ctx);
+ emit(LD64A | ASI(ASI_PL) | RS1(tmp) | RS2(G0) | RD(dst), ctx);
+ break;
+ }
+ break;
+ }
+ /* dst = imm */
+ case BPF_ALU | BPF_MOV | BPF_K:
+ emit_loadimm32(imm, dst, ctx);
+ break;
+ case BPF_ALU64 | BPF_MOV | BPF_K:
+ emit_loadimm(imm, dst, ctx);
+ break;
+ /* dst = dst OP imm */
+ case BPF_ALU | BPF_ADD | BPF_K:
+ case BPF_ALU64 | BPF_ADD | BPF_K:
+ emit_alu_K(ADD, dst, imm, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU | BPF_SUB | BPF_K:
+ case BPF_ALU64 | BPF_SUB | BPF_K:
+ emit_alu_K(SUB, dst, imm, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU | BPF_AND | BPF_K:
+ case BPF_ALU64 | BPF_AND | BPF_K:
+ emit_alu_K(AND, dst, imm, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU | BPF_OR | BPF_K:
+ case BPF_ALU64 | BPF_OR | BPF_K:
+ emit_alu_K(OR, dst, imm, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU | BPF_XOR | BPF_K:
+ case BPF_ALU64 | BPF_XOR | BPF_K:
+ emit_alu_K(XOR, dst, imm, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU | BPF_MUL | BPF_K:
+ emit_alu_K(MUL, dst, imm, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU64 | BPF_MUL | BPF_K:
+ emit_alu_K(MULX, dst, imm, ctx);
+ break;
+ case BPF_ALU | BPF_DIV | BPF_K:
+ if (imm == 0)
+ return -EINVAL;
+
+ emit_write_y(G0, ctx);
+ emit_alu_K(DIV, dst, imm, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU64 | BPF_DIV | BPF_K:
+ if (imm == 0)
+ return -EINVAL;
+
+ emit_alu_K(UDIVX, dst, imm, ctx);
+ break;
+ case BPF_ALU | BPF_MOD | BPF_K: {
+ unsigned int tmp = bpf2sparc[TMP_REG_2];
+
+ if (imm == 0)
+ return -EINVAL;
+
+ /* XXX Emit non-simm13 constants only once... */
+ ctx->tmp_2_used = true;
+
+ emit_write_y(G0, ctx);
+ emit_alu3_K(DIV, dst, imm, tmp, ctx);
+ emit_alu3_K(MULX, tmp, imm, tmp, ctx);
+ emit_alu3(SUB, dst, tmp, dst, ctx);
+ goto do_alu32_trunc;
+ }
+ case BPF_ALU64 | BPF_MOD | BPF_K: {
+ unsigned int tmp = bpf2sparc[TMP_REG_2];
+
+ if (imm == 0)
+ return -EINVAL;
+
+ /* XXX Emit non-simm13 constants only once... */
+ ctx->tmp_2_used = true;
+
+ emit_alu3_K(UDIVX, dst, imm, tmp, ctx);
+ emit_alu3_K(MULX, tmp, imm, tmp, ctx);
+ emit_alu3(SUB, dst, tmp, dst, ctx);
+ break;
+ }
+ case BPF_ALU | BPF_LSH | BPF_K:
+ emit_alu_K(SLL, dst, imm, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU64 | BPF_LSH | BPF_K:
+ emit_alu_K(SLLX, dst, imm, ctx);
+ break;
+ case BPF_ALU | BPF_RSH | BPF_K:
+ emit_alu_K(SRL, dst, imm, ctx);
+ break;
+ case BPF_ALU64 | BPF_RSH | BPF_K:
+ emit_alu_K(SRLX, dst, imm, ctx);
+ break;
+ case BPF_ALU | BPF_ARSH | BPF_K:
+ emit_alu_K(SRA, dst, imm, ctx);
+ goto do_alu32_trunc;
+ case BPF_ALU64 | BPF_ARSH | BPF_K:
+ emit_alu_K(SRAX, dst, imm, ctx);
+ break;
+
+ do_alu32_trunc:
+ if (BPF_CLASS(code) == BPF_ALU)
+ emit_alu_K(SRL, dst, 0, ctx);
+ break;
+
+ /* JUMP off */
+ case BPF_JMP | BPF_JA:
+ emit_branch(BA, ctx->idx, ctx->offset[i + off], ctx);
+ emit_nop(ctx);
+ break;
+ /* IF (dst COND src) JUMP off */
+ case BPF_JMP | BPF_JEQ | BPF_X:
+ case BPF_JMP | BPF_JGT | BPF_X:
+ case BPF_JMP | BPF_JGE | BPF_X:
+ case BPF_JMP | BPF_JNE | BPF_X:
+ case BPF_JMP | BPF_JSGT | BPF_X:
+ case BPF_JMP | BPF_JSGE | BPF_X: {
+ u32 br_opcode;
+
+ emit_cmp(dst, src, ctx);
+emit_cond_jmp:
+ switch (BPF_OP(code)) {
+ case BPF_JEQ:
+ br_opcode = BE;
+ break;
+ case BPF_JGT:
+ br_opcode = BGU;
+ break;
+ case BPF_JGE:
+ br_opcode = BGEU;
+ break;
+ case BPF_JSET:
+ case BPF_JNE:
+ br_opcode = BNE;
+ break;
+ case BPF_JSGT:
+ br_opcode = BG;
+ break;
+ case BPF_JSGE:
+ br_opcode = BGE;
+ break;
+ default:
+ /* Make sure we dont leak kernel information to the
+ * user.
*/
- if (seen_or_pass0 & SEEN_DATAREF) {
- emit_load32(r_SKB, struct sk_buff, len, r_HEADLEN);
- emit_load32(r_SKB, struct sk_buff, data_len, r_TMP);
- emit_sub(r_HEADLEN, r_TMP, r_HEADLEN);
- emit_loadptr(r_SKB, struct sk_buff, data, r_SKB_DATA);
- }
+ return -EFAULT;
}
- emit_reg_move(O7, r_saved_O7);
-
- /* Make sure we dont leak kernel information to the user. */
- if (bpf_needs_clear_a(&filter[0]))
- emit_clear(r_A); /* A = 0 */
-
- for (i = 0; i < flen; i++) {
- unsigned int K = filter[i].k;
- unsigned int t_offset;
- unsigned int f_offset;
- u32 t_op, f_op;
- u16 code = bpf_anc_helper(&filter[i]);
- int ilen;
-
- switch (code) {
- case BPF_ALU | BPF_ADD | BPF_X: /* A += X; */
- emit_alu_X(ADD);
- break;
- case BPF_ALU | BPF_ADD | BPF_K: /* A += K; */
- emit_alu_K(ADD, K);
- break;
- case BPF_ALU | BPF_SUB | BPF_X: /* A -= X; */
- emit_alu_X(SUB);
- break;
- case BPF_ALU | BPF_SUB | BPF_K: /* A -= K */
- emit_alu_K(SUB, K);
- break;
- case BPF_ALU | BPF_AND | BPF_X: /* A &= X */
- emit_alu_X(AND);
- break;
- case BPF_ALU | BPF_AND | BPF_K: /* A &= K */
- emit_alu_K(AND, K);
- break;
- case BPF_ALU | BPF_OR | BPF_X: /* A |= X */
- emit_alu_X(OR);
- break;
- case BPF_ALU | BPF_OR | BPF_K: /* A |= K */
- emit_alu_K(OR, K);
- break;
- case BPF_ANC | SKF_AD_ALU_XOR_X: /* A ^= X; */
- case BPF_ALU | BPF_XOR | BPF_X:
- emit_alu_X(XOR);
- break;
- case BPF_ALU | BPF_XOR | BPF_K: /* A ^= K */
- emit_alu_K(XOR, K);
- break;
- case BPF_ALU | BPF_LSH | BPF_X: /* A <<= X */
- emit_alu_X(SLL);
- break;
- case BPF_ALU | BPF_LSH | BPF_K: /* A <<= K */
- emit_alu_K(SLL, K);
- break;
- case BPF_ALU | BPF_RSH | BPF_X: /* A >>= X */
- emit_alu_X(SRL);
- break;
- case BPF_ALU | BPF_RSH | BPF_K: /* A >>= K */
- emit_alu_K(SRL, K);
- break;
- case BPF_ALU | BPF_MUL | BPF_X: /* A *= X; */
- emit_alu_X(MUL);
- break;
- case BPF_ALU | BPF_MUL | BPF_K: /* A *= K */
- emit_alu_K(MUL, K);
- break;
- case BPF_ALU | BPF_DIV | BPF_K: /* A /= K with K != 0*/
- if (K == 1)
- break;
- emit_write_y(G0);
-#ifdef CONFIG_SPARC32
- /* The Sparc v8 architecture requires
- * three instructions between a %y
- * register write and the first use.
- */
- emit_nop();
- emit_nop();
- emit_nop();
-#endif
- emit_alu_K(DIV, K);
- break;
- case BPF_ALU | BPF_DIV | BPF_X: /* A /= X; */
- emit_cmpi(r_X, 0);
- if (pc_ret0 > 0) {
- t_offset = addrs[pc_ret0 - 1];
-#ifdef CONFIG_SPARC32
- emit_branch(BE, t_offset + 20);
-#else
- emit_branch(BE, t_offset + 8);
-#endif
- emit_nop(); /* delay slot */
- } else {
- emit_branch_off(BNE, 16);
- emit_nop();
-#ifdef CONFIG_SPARC32
- emit_jump(cleanup_addr + 20);
-#else
- emit_jump(cleanup_addr + 8);
-#endif
- emit_clear(r_A);
- }
- emit_write_y(G0);
-#ifdef CONFIG_SPARC32
- /* The Sparc v8 architecture requires
- * three instructions between a %y
- * register write and the first use.
- */
- emit_nop();
- emit_nop();
- emit_nop();
-#endif
- emit_alu_X(DIV);
- break;
- case BPF_ALU | BPF_NEG:
- emit_neg();
- break;
- case BPF_RET | BPF_K:
- if (!K) {
- if (pc_ret0 == -1)
- pc_ret0 = i;
- emit_clear(r_A);
- } else {
- emit_loadimm(K, r_A);
- }
- /* Fallthrough */
- case BPF_RET | BPF_A:
- if (seen_or_pass0) {
- if (i != flen - 1) {
- emit_jump(cleanup_addr);
- emit_nop();
- break;
- }
- if (seen_or_pass0 & SEEN_MEM) {
- unsigned int sz = BASE_STACKFRAME;
- sz += BPF_MEMWORDS * sizeof(u32);
- emit_release_stack(sz);
- }
- }
- /* jmpl %r_saved_O7 + 8, %g0 */
- emit_jmpl(r_saved_O7, 8, G0);
- emit_reg_move(r_A, O0); /* delay slot */
- break;
- case BPF_MISC | BPF_TAX:
- seen |= SEEN_XREG;
- emit_reg_move(r_A, r_X);
- break;
- case BPF_MISC | BPF_TXA:
- seen |= SEEN_XREG;
- emit_reg_move(r_X, r_A);
- break;
- case BPF_ANC | SKF_AD_CPU:
- emit_load_cpu(r_A);
- break;
- case BPF_ANC | SKF_AD_PROTOCOL:
- emit_skb_load16(protocol, r_A);
- break;
- case BPF_ANC | SKF_AD_PKTTYPE:
- __emit_skb_load8(__pkt_type_offset, r_A);
- emit_andi(r_A, PKT_TYPE_MAX, r_A);
- emit_alu_K(SRL, 5);
- break;
- case BPF_ANC | SKF_AD_IFINDEX:
- emit_skb_loadptr(dev, r_A);
- emit_cmpi(r_A, 0);
- emit_branch(BE_PTR, cleanup_addr + 4);
- emit_nop();
- emit_load32(r_A, struct net_device, ifindex, r_A);
- break;
- case BPF_ANC | SKF_AD_MARK:
- emit_skb_load32(mark, r_A);
- break;
- case BPF_ANC | SKF_AD_QUEUE:
- emit_skb_load16(queue_mapping, r_A);
- break;
- case BPF_ANC | SKF_AD_HATYPE:
- emit_skb_loadptr(dev, r_A);
- emit_cmpi(r_A, 0);
- emit_branch(BE_PTR, cleanup_addr + 4);
- emit_nop();
- emit_load16(r_A, struct net_device, type, r_A);
- break;
- case BPF_ANC | SKF_AD_RXHASH:
- emit_skb_load32(hash, r_A);
- break;
- case BPF_ANC | SKF_AD_VLAN_TAG:
- case BPF_ANC | SKF_AD_VLAN_TAG_PRESENT:
- emit_skb_load16(vlan_tci, r_A);
- if (code != (BPF_ANC | SKF_AD_VLAN_TAG)) {
- emit_alu_K(SRL, 12);
- emit_andi(r_A, 1, r_A);
- } else {
- emit_loadimm(~VLAN_TAG_PRESENT, r_TMP);
- emit_and(r_A, r_TMP, r_A);
- }
- break;
- case BPF_LD | BPF_W | BPF_LEN:
- emit_skb_load32(len, r_A);
- break;
- case BPF_LDX | BPF_W | BPF_LEN:
- emit_skb_load32(len, r_X);
- break;
- case BPF_LD | BPF_IMM:
- emit_loadimm(K, r_A);
- break;
- case BPF_LDX | BPF_IMM:
- emit_loadimm(K, r_X);
- break;
- case BPF_LD | BPF_MEM:
- seen |= SEEN_MEM;
- emit_ldmem(K * 4, r_A);
- break;
- case BPF_LDX | BPF_MEM:
- seen |= SEEN_MEM | SEEN_XREG;
- emit_ldmem(K * 4, r_X);
- break;
- case BPF_ST:
- seen |= SEEN_MEM;
- emit_stmem(K * 4, r_A);
- break;
- case BPF_STX:
- seen |= SEEN_MEM | SEEN_XREG;
- emit_stmem(K * 4, r_X);
- break;
+ emit_branch(br_opcode, ctx->idx, ctx->offset[i + off], ctx);
+ emit_nop(ctx);
+ break;
+ }
+ case BPF_JMP | BPF_JSET | BPF_X:
+ emit_btst(dst, src, ctx);
+ goto emit_cond_jmp;
+ /* IF (dst COND imm) JUMP off */
+ case BPF_JMP | BPF_JEQ | BPF_K:
+ case BPF_JMP | BPF_JGT | BPF_K:
+ case BPF_JMP | BPF_JGE | BPF_K:
+ case BPF_JMP | BPF_JNE | BPF_K:
+ case BPF_JMP | BPF_JSGT | BPF_K:
+ case BPF_JMP | BPF_JSGE | BPF_K:
+ if (is_simm13(imm)) {
+ emit_cmpi(dst, imm, ctx);
+ } else {
+ ctx->tmp_1_used = true;
+ emit_loadimm_sext(imm, bpf2sparc[TMP_REG_1], ctx);
+ emit_cmp(dst, bpf2sparc[TMP_REG_1], ctx);
+ }
+ goto emit_cond_jmp;
+ case BPF_JMP | BPF_JSET | BPF_K:
+ if (is_simm13(imm)) {
+ emit_btsti(dst, imm, ctx);
+ } else {
+ ctx->tmp_1_used = true;
+ emit_loadimm_sext(imm, bpf2sparc[TMP_REG_1], ctx);
+ emit_btst(dst, bpf2sparc[TMP_REG_1], ctx);
+ }
+ goto emit_cond_jmp;
-#define CHOOSE_LOAD_FUNC(K, func) \
- ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
-
- case BPF_LD | BPF_W | BPF_ABS:
- func = CHOOSE_LOAD_FUNC(K, bpf_jit_load_word);
-common_load: seen |= SEEN_DATAREF;
- emit_loadimm(K, r_OFF);
- emit_call(func);
- break;
- case BPF_LD | BPF_H | BPF_ABS:
- func = CHOOSE_LOAD_FUNC(K, bpf_jit_load_half);
- goto common_load;
- case BPF_LD | BPF_B | BPF_ABS:
- func = CHOOSE_LOAD_FUNC(K, bpf_jit_load_byte);
- goto common_load;
- case BPF_LDX | BPF_B | BPF_MSH:
- func = CHOOSE_LOAD_FUNC(K, bpf_jit_load_byte_msh);
- goto common_load;
- case BPF_LD | BPF_W | BPF_IND:
- func = bpf_jit_load_word;
-common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
- if (K) {
- if (is_simm13(K)) {
- emit_addi(r_X, K, r_OFF);
- } else {
- emit_loadimm(K, r_TMP);
- emit_add(r_X, r_TMP, r_OFF);
- }
- } else {
- emit_reg_move(r_X, r_OFF);
- }
- emit_call(func);
- break;
- case BPF_LD | BPF_H | BPF_IND:
- func = bpf_jit_load_half;
- goto common_load_ind;
- case BPF_LD | BPF_B | BPF_IND:
- func = bpf_jit_load_byte;
- goto common_load_ind;
- case BPF_JMP | BPF_JA:
- emit_jump(addrs[i + K]);
- emit_nop();
- break;
-
-#define COND_SEL(CODE, TOP, FOP) \
- case CODE: \
- t_op = TOP; \
- f_op = FOP; \
- goto cond_branch
-
- COND_SEL(BPF_JMP | BPF_JGT | BPF_K, BGU, BLEU);
- COND_SEL(BPF_JMP | BPF_JGE | BPF_K, BGEU, BLU);
- COND_SEL(BPF_JMP | BPF_JEQ | BPF_K, BE, BNE);
- COND_SEL(BPF_JMP | BPF_JSET | BPF_K, BNE, BE);
- COND_SEL(BPF_JMP | BPF_JGT | BPF_X, BGU, BLEU);
- COND_SEL(BPF_JMP | BPF_JGE | BPF_X, BGEU, BLU);
- COND_SEL(BPF_JMP | BPF_JEQ | BPF_X, BE, BNE);
- COND_SEL(BPF_JMP | BPF_JSET | BPF_X, BNE, BE);
-
-cond_branch: f_offset = addrs[i + filter[i].jf];
- t_offset = addrs[i + filter[i].jt];
-
- /* same targets, can avoid doing the test :) */
- if (filter[i].jt == filter[i].jf) {
- emit_jump(t_offset);
- emit_nop();
- break;
- }
-
- switch (code) {
- case BPF_JMP | BPF_JGT | BPF_X:
- case BPF_JMP | BPF_JGE | BPF_X:
- case BPF_JMP | BPF_JEQ | BPF_X:
- seen |= SEEN_XREG;
- emit_cmp(r_A, r_X);
- break;
- case BPF_JMP | BPF_JSET | BPF_X:
- seen |= SEEN_XREG;
- emit_btst(r_A, r_X);
- break;
- case BPF_JMP | BPF_JEQ | BPF_K:
- case BPF_JMP | BPF_JGT | BPF_K:
- case BPF_JMP | BPF_JGE | BPF_K:
- if (is_simm13(K)) {
- emit_cmpi(r_A, K);
- } else {
- emit_loadimm(K, r_TMP);
- emit_cmp(r_A, r_TMP);
- }
- break;
- case BPF_JMP | BPF_JSET | BPF_K:
- if (is_simm13(K)) {
- emit_btsti(r_A, K);
- } else {
- emit_loadimm(K, r_TMP);
- emit_btst(r_A, r_TMP);
- }
- break;
- }
- if (filter[i].jt != 0) {
- if (filter[i].jf)
- t_offset += 8;
- emit_branch(t_op, t_offset);
- emit_nop(); /* delay slot */
- if (filter[i].jf) {
- emit_jump(f_offset);
- emit_nop();
- }
- break;
- }
- emit_branch(f_op, f_offset);
- emit_nop(); /* delay slot */
- break;
-
- default:
- /* hmm, too complex filter, give up with jit compiler */
- goto out;
- }
- ilen = (void *) prog - (void *) temp;
- if (image) {
- if (unlikely(proglen + ilen > oldproglen)) {
- pr_err("bpb_jit_compile fatal error\n");
- kfree(addrs);
- module_memfree(image);
- return;
- }
- memcpy(image + proglen, temp, ilen);
- }
- proglen += ilen;
- addrs[i] = proglen;
- prog = temp;
+ /* function call */
+ case BPF_JMP | BPF_CALL:
+ {
+ u8 *func = ((u8 *)__bpf_call_base) + imm;
+
+ emit_reg_move(bpf2sparc[BPF_REG_1], O0, ctx);
+ emit_reg_move(bpf2sparc[BPF_REG_2], O1, ctx);
+ emit_reg_move(bpf2sparc[BPF_REG_3], O2, ctx);
+ emit_reg_move(bpf2sparc[BPF_REG_4], O3, ctx);
+ emit_call((u32 *)func, ctx);
+ emit_reg_move(bpf2sparc[BPF_REG_5], O4, ctx); /* delay slot */
+
+ emit_reg_move(O0, bpf2sparc[BPF_REG_0], ctx);
+
+ if (bpf_helper_changes_pkt_data(func) && ctx->saw_ld_abs_ind)
+ load_skb_regs(ctx, bpf2sparc[BPF_REG_6]);
+ break;
+ }
+
+ /* function return */
+ case BPF_JMP | BPF_EXIT:
+ /* Optimization: when last instruction is EXIT,
+ simply fallthrough to epilogue. */
+ if (i == ctx->prog->len - 1)
+ break;
+ emit_branch(BA, ctx->idx, ctx->epilogue_offset, ctx);
+ emit_nop(ctx);
+ break;
+
+ /* dst = imm64 */
+ case BPF_LD | BPF_IMM | BPF_DW:
+ {
+ const struct bpf_insn insn1 = insn[1];
+ u64 imm64;
+
+ if (insn1.code != 0 || insn1.src_reg != 0 ||
+ insn1.dst_reg != 0 || insn1.off != 0) {
+ /* Note: verifier in BPF core must catch invalid
+ * instructions.
+ */
+ pr_err_once("Invalid BPF_LD_IMM64 instruction\n");
+ return -EINVAL;
}
- /* last bpf instruction is always a RET :
- * use it to give the cleanup instruction(s) addr
- */
- cleanup_addr = proglen - 8; /* jmpl; mov r_A,%o0; */
- if (seen_or_pass0 & SEEN_MEM)
- cleanup_addr -= 4; /* add %sp, X, %sp; */
-
- if (image) {
- if (proglen != oldproglen)
- pr_err("bpb_jit_compile proglen=%u != oldproglen=%u\n",
- proglen, oldproglen);
+
+ imm64 = (u64)insn1.imm << 32 | (u32)imm;
+ emit_loadimm64(imm64, dst, ctx);
+
+ return 1;
+ }
+
+ /* LDX: dst = *(size *)(src + off) */
+ case BPF_LDX | BPF_MEM | BPF_W:
+ case BPF_LDX | BPF_MEM | BPF_H:
+ case BPF_LDX | BPF_MEM | BPF_B:
+ case BPF_LDX | BPF_MEM | BPF_DW: {
+ const u8 tmp = bpf2sparc[TMP_REG_1];
+ u32 opcode = 0, rs2;
+ s32 real_off = off;
+
+ ctx->tmp_1_used = true;
+ if (src == FP)
+ real_off += STACK_BIAS;
+ switch (BPF_SIZE(code)) {
+ case BPF_W:
+ opcode = LD32;
+ break;
+ case BPF_H:
+ opcode = LD16;
+ break;
+ case BPF_B:
+ opcode = LD8;
+ break;
+ case BPF_DW:
+ opcode = LD64;
break;
}
- if (proglen == oldproglen) {
- image = module_alloc(proglen);
- if (!image)
- goto out;
+
+ if (is_simm13(real_off)) {
+ opcode |= IMMED;
+ rs2 = S13(real_off);
+ } else {
+ emit_loadimm(real_off, tmp, ctx);
+ rs2 = RS2(tmp);
}
- oldproglen = proglen;
+ emit(opcode | RS1(src) | rs2 | RD(dst), ctx);
+ break;
}
+ /* ST: *(size *)(dst + off) = imm */
+ case BPF_ST | BPF_MEM | BPF_W:
+ case BPF_ST | BPF_MEM | BPF_H:
+ case BPF_ST | BPF_MEM | BPF_B:
+ case BPF_ST | BPF_MEM | BPF_DW: {
+ const u8 tmp = bpf2sparc[TMP_REG_1];
+ const u8 tmp2 = bpf2sparc[TMP_REG_2];
+ u32 opcode = 0, rs2;
+ s32 real_off = off;
+
+ if (dst == FP)
+ real_off += STACK_BIAS;
+
+ ctx->tmp_2_used = true;
+ emit_loadimm(imm, tmp2, ctx);
+
+ switch (BPF_SIZE(code)) {
+ case BPF_W:
+ opcode = ST32;
+ break;
+ case BPF_H:
+ opcode = ST16;
+ break;
+ case BPF_B:
+ opcode = ST8;
+ break;
+ case BPF_DW:
+ opcode = ST64;
+ break;
+ }
- if (bpf_jit_enable > 1)
- bpf_jit_dump(flen, proglen, pass + 1, image);
+ if (is_simm13(real_off)) {
+ opcode |= IMMED;
+ rs2 = S13(real_off);
+ } else {
+ ctx->tmp_1_used = true;
+ emit_loadimm(real_off, tmp, ctx);
+ rs2 = RS2(tmp);
+ }
+ emit(opcode | RS1(dst) | rs2 | RD(tmp2), ctx);
+ break;
+ }
- if (image) {
- bpf_flush_icache(image, image + proglen);
- fp->bpf_func = (void *)image;
- fp->jited = 1;
+ /* STX: *(size *)(dst + off) = src */
+ case BPF_STX | BPF_MEM | BPF_W:
+ case BPF_STX | BPF_MEM | BPF_H:
+ case BPF_STX | BPF_MEM | BPF_B:
+ case BPF_STX | BPF_MEM | BPF_DW: {
+ const u8 tmp = bpf2sparc[TMP_REG_1];
+ u32 opcode = 0, rs2;
+ s32 real_off = off;
+
+ if (dst == FP)
+ real_off += STACK_BIAS;
+ switch (BPF_SIZE(code)) {
+ case BPF_W:
+ opcode = ST32;
+ break;
+ case BPF_H:
+ opcode = ST16;
+ break;
+ case BPF_B:
+ opcode = ST8;
+ break;
+ case BPF_DW:
+ opcode = ST64;
+ break;
+ }
+ if (is_simm13(real_off)) {
+ opcode |= IMMED;
+ rs2 = S13(real_off);
+ } else {
+ ctx->tmp_1_used = true;
+ emit_loadimm(real_off, tmp, ctx);
+ rs2 = RS2(tmp);
+ }
+ emit(opcode | RS1(dst) | rs2 | RD(src), ctx);
+ break;
}
-out:
- kfree(addrs);
- return;
+
+ /* STX XADD: lock *(u32 *)(dst + off) += src */
+ case BPF_STX | BPF_XADD | BPF_W: {
+ const u8 tmp = bpf2sparc[TMP_REG_1];
+ const u8 tmp2 = bpf2sparc[TMP_REG_2];
+ const u8 tmp3 = bpf2sparc[TMP_REG_3];
+ s32 real_off = off;
+
+ ctx->tmp_1_used = true;
+ ctx->tmp_2_used = true;
+ ctx->tmp_3_used = true;
+ if (dst == FP)
+ real_off += STACK_BIAS;
+ emit_loadimm(real_off, tmp, ctx);
+ emit_alu3(ADD, dst, tmp, tmp, ctx);
+
+ emit(LD32 | RS1(tmp) | RS2(G0) | RD(tmp2), ctx);
+ emit_alu3(ADD, tmp2, src, tmp3, ctx);
+ emit(CAS | ASI(ASI_P) | RS1(tmp) | RS2(tmp2) | RD(tmp3), ctx);
+ emit_cmp(tmp2, tmp3, ctx);
+ emit_branch(BNE, 4, 0, ctx);
+ emit_nop(ctx);
+ break;
+ }
+ /* STX XADD: lock *(u64 *)(dst + off) += src */
+ case BPF_STX | BPF_XADD | BPF_DW: {
+ const u8 tmp = bpf2sparc[TMP_REG_1];
+ const u8 tmp2 = bpf2sparc[TMP_REG_2];
+ const u8 tmp3 = bpf2sparc[TMP_REG_3];
+ s32 real_off = off;
+
+ ctx->tmp_1_used = true;
+ ctx->tmp_2_used = true;
+ ctx->tmp_3_used = true;
+ if (dst == FP)
+ real_off += STACK_BIAS;
+ emit_loadimm(real_off, tmp, ctx);
+ emit_alu3(ADD, dst, tmp, tmp, ctx);
+
+ emit(LD64 | RS1(tmp) | RS2(G0) | RD(tmp2), ctx);
+ emit_alu3(ADD, tmp2, src, tmp3, ctx);
+ emit(CASX | ASI(ASI_P) | RS1(tmp) | RS2(tmp2) | RD(tmp3), ctx);
+ emit_cmp(tmp2, tmp3, ctx);
+ emit_branch(BNE, 4, 0, ctx);
+ emit_nop(ctx);
+ break;
+ }
+#define CHOOSE_LOAD_FUNC(K, func) \
+ ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
+
+ /* R0 = ntohx(*(size *)(((struct sk_buff *)R6)->data + imm)) */
+ case BPF_LD | BPF_ABS | BPF_W:
+ func = CHOOSE_LOAD_FUNC(imm, bpf_jit_load_word);
+ goto common_load;
+ case BPF_LD | BPF_ABS | BPF_H:
+ func = CHOOSE_LOAD_FUNC(imm, bpf_jit_load_half);
+ goto common_load;
+ case BPF_LD | BPF_ABS | BPF_B:
+ func = CHOOSE_LOAD_FUNC(imm, bpf_jit_load_byte);
+ goto common_load;
+ /* R0 = ntohx(*(size *)(((struct sk_buff *)R6)->data + src + imm)) */
+ case BPF_LD | BPF_IND | BPF_W:
+ func = bpf_jit_load_word;
+ goto common_load;
+ case BPF_LD | BPF_IND | BPF_H:
+ func = bpf_jit_load_half;
+ goto common_load;
+
+ case BPF_LD | BPF_IND | BPF_B:
+ func = bpf_jit_load_byte;
+ common_load:
+ ctx->saw_ld_abs_ind = true;
+
+ emit_reg_move(bpf2sparc[BPF_REG_6], O0, ctx);
+ emit_loadimm(imm, O1, ctx);
+
+ if (BPF_MODE(code) == BPF_IND)
+ emit_alu(ADD, src, O1, ctx);
+
+ emit_call(func, ctx);
+ emit_alu_K(SRA, O1, 0, ctx);
+
+ emit_reg_move(O0, I5, ctx);
+ break;
+
+ default:
+ pr_err_once("unknown opcode %02x\n", code);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int build_body(struct jit_ctx *ctx)
+{
+ const struct bpf_prog *prog = ctx->prog;
+ int i;
+
+ for (i = 0; i < prog->len; i++) {
+ const struct bpf_insn *insn = &prog->insnsi[i];
+ int ret;
+
+ ret = build_insn(insn, ctx);
+ if (ctx->image == NULL)
+ ctx->offset[i] = ctx->idx;
+
+ if (ret > 0) {
+ i++;
+ continue;
+ }
+ if (ret)
+ return ret;
+ }
+ return 0;
+}
+
+static void jit_fill_hole(void *area, unsigned int size)
+{
+ u32 *ptr;
+ /* We are guaranteed to have aligned memory. */
+ for (ptr = area; size >= sizeof(u32); size -= sizeof(u32))
+ *ptr++ = 0x91d02005; /* ta 5 */
}
-void bpf_jit_free(struct bpf_prog *fp)
+struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
{
- if (fp->jited)
- module_memfree(fp->bpf_func);
+ struct bpf_prog *tmp, *orig_prog = prog;
+ bool tmp_blinded = false;
+ struct jit_ctx ctx;
+ struct bpf_binary_header *header;
+ int image_size;
+ u8 *image_ptr;
+
+ if (!bpf_jit_enable)
+ return orig_prog;
+
+ if (!prog || !prog->len)
+ return orig_prog;
+
+ tmp = bpf_jit_blind_constants(prog);
+ /* If blinding was requested and we failed during blinding,
+ * we must fall back to the interpreter.
+ */
+ if (IS_ERR(tmp))
+ return orig_prog;
+ if (tmp != prog) {
+ tmp_blinded = true;
+ prog = tmp;
+ }
- bpf_prog_unlock_free(fp);
+ memset(&ctx, 0, sizeof(ctx));
+ ctx.prog = prog;
+
+ ctx.offset = kcalloc(prog->len, sizeof(unsigned int), GFP_KERNEL);
+ if (ctx.offset == NULL) {
+ prog = orig_prog;
+ goto out;
+ }
+
+ /* 1. Initial fake pass to compute ctx->idx. */
+
+ /* Fake pass to fill in ctx->offset and ctx->tmp_{1,2}_used. */
+ build_prologue(&ctx);
+ if (build_body(&ctx)) {
+ prog = orig_prog;
+ goto out_off;
+ }
+ build_epilogue(&ctx);
+
+ /* Now we know the actual image size. */
+ image_size = sizeof(u32) * ctx.idx;
+ header = bpf_jit_binary_alloc(image_size, &image_ptr,
+ sizeof(u32), jit_fill_hole);
+ if (header == NULL) {
+ prog = orig_prog;
+ goto out_off;
+ }
+
+ /* 2. Now, the actual pass. */
+
+ ctx.image = (u32 *)image_ptr;
+ ctx.idx = 0;
+
+ build_prologue(&ctx);
+
+ if (build_body(&ctx)) {
+ bpf_jit_binary_free(header);
+ prog = orig_prog;
+ goto out_off;
+ }
+
+ build_epilogue(&ctx);
+
+ if (bpf_jit_enable > 1)
+ bpf_jit_dump(prog->len, image_size, 2, ctx.image);
+ bpf_flush_icache(ctx.image, ctx.image + image_size);
+
+ bpf_jit_binary_lock_ro(header);
+
+ prog->bpf_func = (void *)ctx.image;
+ prog->jited = 1;
+
+out_off:
+ kfree(ctx.offset);
+out:
+ if (tmp_blinded)
+ bpf_jit_prog_release_other(prog, prog == orig_prog ?
+ tmp : orig_prog);
+ return prog;
}
^ permalink raw reply related
* [PATCH] net: cx89x0: move attribute declaration before struct keyword
From: Stefan Agner @ 2017-04-17 6:20 UTC (permalink / raw)
To: davem; +Cc: shc_work, jarod, netdev, linux-kernel, Stefan Agner
The attribute declaration is typically before the definition. Move
the __maybe_unused attribute declaration before the struct keyword.
Signed-off-by: Stefan Agner <stefan@agner.ch>
---
drivers/net/ethernet/cirrus/cs89x0.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/cirrus/cs89x0.c b/drivers/net/ethernet/cirrus/cs89x0.c
index 3647b28e8de0..9be1d3babb7a 100644
--- a/drivers/net/ethernet/cirrus/cs89x0.c
+++ b/drivers/net/ethernet/cirrus/cs89x0.c
@@ -1896,7 +1896,7 @@ static int cs89x0_platform_remove(struct platform_device *pdev)
return 0;
}
-static const struct __maybe_unused of_device_id cs89x0_match[] = {
+static const __maybe_unused struct of_device_id cs89x0_match[] = {
{ .compatible = "cirrus,cs8900", },
{ .compatible = "cirrus,cs8920", },
{ },
--
2.12.2
^ permalink raw reply related
* Re: [PATCH net-next 1/1] net sched actions: dump more than TCA_ACT_MAX_PRIO actions per batch
From: Jiri Pirko @ 2017-04-17 8:19 UTC (permalink / raw)
To: Jamal Hadi Salim; +Cc: davem, netdev, eric.dumazet, xiyou.wangcong
In-Reply-To: <1492346070-6002-1-git-send-email-jhs@emojatatu.com>
Sun, Apr 16, 2017 at 02:34:30PM CEST, jhs@mojatatu.com wrote:
>From: Jamal Hadi Salim <jhs@mojatatu.com>
>
>When you dump hundreds of thousands of actions, getting only 32 per
>dump batch even when the socket buffer and memory allocations allow
>is inefficient.
>
>With this change, the user will get as many as possibly fitting
>within the given constraints.
>
>We reuse the pad fields in tcamsg. pad1 is used as a flag space.
>User explicitly requests for the large dump in order to maintain
>backwards compatibility with user space by setting bit
>ACT_LARGE_DUMP_ON; older user space which doesnt set this flag
>doesnt get the large (than 32) batches - so continues to work
>as before. Older kernels ignore this flag, so legacy behavior
>is maintained.
>The kernel uses pad2 to tell the user how many actions are put in
>a single batch. As such user space app(like tc) knows how long
>to iterate instead of hardcoded maximum of 32.
>
>Some results dumping 1.5M actions, first unpatched tc which the
>kernel doesnt help:
>
>prompt$ time -p tc actions ls action gact | grep index | wc -l
>1500000
>real 1388.43
>user 2.07
>sys 1386.79
>
>Now patched tc which sets the correct flags when requesting a dump:
>
>prompt$ time -p updatedtc actions ls action gact | grep index | wc -l
>1500000
>real 178.13
>user 2.02
>sys 176.96
>
>Improvement: Dump time from about 20 minutes to about 2 minutes.
>
>Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
>---
> include/uapi/linux/rtnetlink.h | 7 +++++++
> net/sched/act_api.c | 17 ++++++++++++++---
> 2 files changed, 21 insertions(+), 3 deletions(-)
>
>diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
>index cce0613..3434d98 100644
>--- a/include/uapi/linux/rtnetlink.h
>+++ b/include/uapi/linux/rtnetlink.h
>@@ -678,6 +678,13 @@ struct tcamsg {
> #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
> #define TCA_ACT_TAB 1 /* attr type must be >=1 */
> #define TCAA_MAX 1
>+/* tcamsg flags stored in tca__pad
>+ *
>+ * ACT_LARGE_DUMP_ON user->kernel to request for larger than TCA_ACT_MAX_PRIO
>+ * actions in a dump. All dump responses will contain the number of actions
>+ * being dumped stored in tca__pad2 for user app's info
>+ */
>+#define ACT_LARGE_DUMP_ON (1 << 0)
>
> /* New extended info filters for IFLA_EXT_MASK */
> #define RTEXT_FILTER_VF (1 << 0)
>diff --git a/net/sched/act_api.c b/net/sched/act_api.c
>index 79d875c..90cc774 100644
>--- a/net/sched/act_api.c
>+++ b/net/sched/act_api.c
>@@ -83,6 +83,7 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb,
> struct netlink_callback *cb)
> {
> int err = 0, index = -1, i = 0, s_i = 0, n_i = 0;
>+ unsigned short act_flags = cb->args[2];
> struct nlattr *nest;
>
> spin_lock_bh(&hinfo->lock);
>@@ -111,14 +112,18 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb,
> }
> nla_nest_end(skb, nest);
> n_i++;
>- if (n_i >= TCA_ACT_MAX_PRIO)
>+ if (!(act_flags & ACT_LARGE_DUMP_ON) &&
>+ n_i >= TCA_ACT_MAX_PRIO)
> goto done;
> }
> }
> done:
> spin_unlock_bh(&hinfo->lock);
>- if (n_i)
>+ if (n_i) {
> cb->args[0] += n_i;
>+ if (act_flags & ACT_LARGE_DUMP_ON)
>+ cb->args[1] = n_i;
>+ }
> return n_i;
>
> nla_put_failure:
>@@ -1081,6 +1086,7 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
> struct tc_action_ops *a_o;
> int ret = 0;
> struct tcamsg *t = (struct tcamsg *) nlmsg_data(cb->nlh);
>+ unsigned char act_flags = t->tca__pad1;
> struct nlattr *kind = find_dump_kind(cb->nlh);
>
> if (kind == NULL) {
>@@ -1096,9 +1102,12 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
> cb->nlh->nlmsg_type, sizeof(*t), 0);
> if (!nlh)
> goto out_module_put;
>+
>+ cb->args[2] = act_flags;
>+
> t = nlmsg_data(nlh);
> t->tca_family = AF_UNSPEC;
>- t->tca__pad1 = 0;
>+ t->tca__pad1 = act_flags;
I don't like this one bit. Pad is no longer a pad but by name it still
is. Why don't you introduce new attributes for this?
> t->tca__pad2 = 0;
>
> nest = nla_nest_start(skb, TCA_ACT_TAB);
>@@ -1112,6 +1121,8 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
> if (ret > 0) {
> nla_nest_end(skb, nest);
> ret = skb->len;
>+ t->tca__pad2 = cb->args[1];
>+ cb->args[1] = 0;
> } else
> nlmsg_trim(skb, b);
>
>--
>1.9.1
>
^ permalink raw reply
* Re: [PATCH net-next 1/1] net sched actions: add time filter for action dumping
From: Jiri Pirko @ 2017-04-17 8:21 UTC (permalink / raw)
To: Jamal Hadi Salim; +Cc: davem, netdev, xiyou.wangcong, eric.dumazet
In-Reply-To: <1492350973-6846-1-git-send-email-jhs@emojatatu.com>
Sun, Apr 16, 2017 at 03:56:13PM CEST, jhs@mojatatu.com wrote:
>From: Jamal Hadi Salim <jhs@mojatatu.com>
>
>This adds support for filtering based on time since last used.
>When we are dumping a large number of actions it is useful to
>have the option of filtering based on when the action was last
>used to reduce the amount of data crossing to user space.
>
>With this patch the user space app sets the FILTER_ACCESS_TIME flag
>(in the pad1 flags area) and the "time of interest since now" in seconds
>when the action was last used (in the pad2 area). The kernel converts
Again with the pads. Please don't make the TC uapi uglier than it
already is. Just use new attrs.
>this to jiffies and does the filtering comparison matching entries that
>have seen activity since then and returns them to user space.
>Old kernels and old tc continue to work in legacy mode.
>
>Some example (we have 400 actions bound to 400 filters); at installation
>time using hacked tc which sets the time of interest to 120 seconds:
>
>prompt$ hackedtc actions ls action gact | grep index | wc -l
>400
>
>go get some coffee and wait for > 120 seconds and try again:
>
>prompt$ hackedtc actions ls action gact | grep index | wc -l
>0
>
>Lets see a filter bound to one of these actions:
>..
>filter pref 10 u32
>filter pref 10 u32 fh 800: ht divisor 1
>filter pref 10 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:10 (rule hit 2 success 1)
> match 7f000002/ffffffff at 12 (success 1 )
> action order 1: gact action pass
> random type none pass val 0
> index 23 ref 2 bind 1 installed 1145 sec used 802 sec
> Action statistics:
> Sent 84 bytes 1 pkt (dropped 0, overlimits 0 requeues 0)
> backlog 0b 0p requeues 0
>....
>
>Now lets ping -c 1 127.0.0.2, then run the actions again:
>
>prompt$ hackedtc actions ls action gact | grep index | wc -l
>1
>
>More details please:
>
>prompt$ hackedtc -s actions ls action gact
>total acts 1 flags 0x3
>
> action order 0: gact action pass
> random type none pass val 0
> index 23 ref 2 bind 1 installed 1270 sec used 30 sec
> Action statistics:
> Sent 168 bytes 2 pkt (dropped 0, overlimits 0 requeues 0)
> backlog 0b 0p requeues 0
>
>And the filter?
>
>filter pref 10 u32
>filter pref 10 u32 fh 800: ht divisor 1
>filter pref 10 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:10 (rule hit 4 success 2)
> match 7f000002/ffffffff at 12 (success 2 )
> action order 1: gact action pass
> random type none pass val 0
> index 23 ref 2 bind 1 installed 1324 sec used 84 sec
> Action statistics:
> Sent 168 bytes 2 pkt (dropped 0, overlimits 0 requeues 0)
> backlog 0b 0p requeues 0
>
>Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
>---
> net/sched/act_api.c | 24 ++++++++++++++++++++++--
> 1 file changed, 22 insertions(+), 2 deletions(-)
>
>diff --git a/net/sched/act_api.c b/net/sched/act_api.c
>index 90cc774..4dd55f2 100644
>--- a/net/sched/act_api.c
>+++ b/net/sched/act_api.c
>@@ -84,11 +84,13 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb,
> {
> int err = 0, index = -1, i = 0, s_i = 0, n_i = 0;
> unsigned short act_flags = cb->args[2];
>+ unsigned long jiffy_filter = cb->args[3];
>+
> struct nlattr *nest;
>
> spin_lock_bh(&hinfo->lock);
>
>- s_i = cb->args[0];
>+ s_i = cb->args[4];
>
> for (i = 0; i < (hinfo->hmask + 1); i++) {
> struct hlist_head *head;
>@@ -101,6 +103,12 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb,
> if (index < s_i)
> continue;
>
>+ if (jiffy_filter &&
>+ time_after(jiffy_filter,
>+ (unsigned long)p->tcfa_tm.lastuse)) {
>+ continue;
>+ }
>+
> nest = nla_nest_start(skb, n_i);
> if (nest == NULL)
> goto nla_put_failure;
>@@ -118,6 +126,8 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb,
> }
> }
> done:
>+ if (index > 0)
>+ cb->args[4] = index + 1;
> spin_unlock_bh(&hinfo->lock);
> if (n_i) {
> cb->args[0] += n_i;
>@@ -1086,8 +1096,10 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
> struct tc_action_ops *a_o;
> int ret = 0;
> struct tcamsg *t = (struct tcamsg *) nlmsg_data(cb->nlh);
>- unsigned char act_flags = t->tca__pad1;
> struct nlattr *kind = find_dump_kind(cb->nlh);
>+ unsigned char act_flags = t->tca__pad1;
>+ unsigned short secs = t->tca__pad2;
>+ unsigned long jiffy_wanted = 0;
>
> if (kind == NULL) {
> pr_info("tc_dump_action: action bad kind\n");
>@@ -1103,7 +1115,15 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
> if (!nlh)
> goto out_module_put;
>
>+ if (act_flags & ACT_FILTER_TIME_ACCESS) {
>+ const unsigned int m = secs * 1000L;
>+ unsigned long jiffy_msecs = msecs_to_jiffies(m);
>+
>+ jiffy_wanted = jiffies - jiffy_msecs;
>+ }
>+
> cb->args[2] = act_flags;
>+ cb->args[3] = jiffy_wanted;
>
> t = nlmsg_data(nlh);
> t->tca_family = AF_UNSPEC;
>--
>1.9.1
>
^ permalink raw reply
* КЛИЕНТСКИЕ БАЗЫ http://xurl.es/PR0DAWEZ УЗНАЙТЕ ПОДРОБНЕЕ!
From: . @ 2017-04-17 12:46 UTC (permalink / raw)
To: netdev
^ permalink raw reply
* Re: [PATCH] sh_eth: unmap DMA buffers when freeing rings
From: Sergei Shtylyov @ 2017-04-17 8:57 UTC (permalink / raw)
To: netdev; +Cc: linux-renesas-soc
In-Reply-To: <20170416200157.111095876@cogentembedded.com>
Hello!
On 4/16/2017 11:01 PM, Sergei Shtylyov wrote:
> The DMA API debugging (when enabled) causes:
>
> WARNING: CPU: 0 PID: 1445 at lib/dma-debug.c:519 add_dma_entry+0xe0/0x12c
> DMA-API: exceeded 7 overlapping mappings of cacheline 0x01b2974d
>
> to be printed after repeated initialization of the Ether device, e.g.
> suspend/resume or 'ifconfig' up/down. This is because DMA buffers mapped
> using dma_map_single() in sh_eth_ring_format() and sh_eth_start_xmit() are
> never unmapped. Resolve this problem by unmapping the buffers when freeing
> the descriptor rings; in order to do it right, we'd have to add an extra
> parameter to sh_eth_txfree() (we rename this function to sh_eth_tx_free(),
> while at it).
>
> Based on the commit a47b70ea86bd ("ravb: unmap descriptors when freeing
> rings").
>
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
>
> ---
> drivers/net/ethernet/renesas/sh_eth.c | 122 ++++++++++++++++++----------------
> 1 file changed, 67 insertions(+), 55 deletions(-)
>
> Index: net/drivers/net/ethernet/renesas/sh_eth.c
> ===================================================================
> --- net.orig/drivers/net/ethernet/renesas/sh_eth.c
> +++ net/drivers/net/ethernet/renesas/sh_eth.c
> @@ -1127,12 +1127,70 @@ static struct mdiobb_ops bb_ops = {
> .get_mdio_data = sh_get_mdio,
> };
>
> +/* free Tx skb function */
> +static int sh_eth_tx_free(struct net_device *ndev, bool sent_only)
> +{
> + struct sh_eth_private *mdp = netdev_priv(ndev);
> + struct sh_eth_txdesc *txdesc;
> + int free_num = 0;
> + int entry;
> + bool sent;
> +
> + for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) {
> + entry = mdp->dirty_tx % mdp->num_tx_ring;
> + txdesc = &mdp->tx_ring[entry];
> + sent = txdesc->status & cpu_to_le32(TD_TACT);
Oops, forgot to reverse the condition here. Which means I haven't goved in
enough testing... :-/
> + if (sent_only && !sent)
> + break;
[...]
MBR, Sergei
^ permalink raw reply
* (unknown),
From: kelley @ 2017-04-17 9:12 UTC (permalink / raw)
To: netdev
[-- Attachment #1: MICROSOFT-17050-netdev.zip --]
[-- Type: application/zip, Size: 2060 bytes --]
^ permalink raw reply
* [PATCH net] be2net: VxLAN offload should be re-enabled when only 1 UDP port is left
From: Sriharsha Basavapatna @ 2017-04-17 16:03 UTC (permalink / raw)
To: netdev
We disable VxLAN offload when more than 1 UDP port is added to the driver,
since Skyhawk doesn't support offload with multiple ports. The existing
driver design expects the user to delete all port configurations and create
a configuration with a single UDP port for VxLAN offload to be re-enabled.
Remove this restriction by tracking the ports added and re-enabling offload
when ports get deleted and only 1 port is left.
Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Reviewed-by: Sathya Perla <sathya.perla@broadcom.com>
---
drivers/net/ethernet/emulex/benet/be.h | 12 ++-
drivers/net/ethernet/emulex/benet/be_main.c | 134 +++++++++++++++++++---------
2 files changed, 102 insertions(+), 44 deletions(-)
diff --git a/drivers/net/ethernet/emulex/benet/be.h b/drivers/net/ethernet/emulex/benet/be.h
index d49528ad7821..50566243e6fa 100644
--- a/drivers/net/ethernet/emulex/benet/be.h
+++ b/drivers/net/ethernet/emulex/benet/be.h
@@ -567,6 +567,12 @@ struct be_error_recovery {
/* Ethtool priv_flags */
#define BE_DISABLE_TPE_RECOVERY 0x1
+struct be_vxlan_port {
+ struct list_head list;
+ __be16 port; /* VxLAN UDP dst port */
+ int port_aliases; /* alias count */
+};
+
struct be_adapter {
struct pci_dev *pdev;
struct net_device *netdev;
@@ -671,9 +677,9 @@ struct be_adapter {
u32 sli_family;
u8 hba_port_num;
u16 pvid;
- __be16 vxlan_port;
- int vxlan_port_count;
- int vxlan_port_aliases;
+ __be16 vxlan_port; /* offloaded vxlan port num */
+ int vxlan_port_count; /* active vxlan port count */
+ struct list_head vxlan_port_list; /* vxlan port list */
struct phy_info phy;
u8 wol_cap;
bool wol_en;
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index 6be3b9aba8ed..8702661b99c0 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -3857,6 +3857,44 @@ static void be_cancel_err_detection(struct be_adapter *adapter)
}
}
+static int be_enable_vxlan_offloads(struct be_adapter *adapter)
+{
+ struct net_device *netdev = adapter->netdev;
+ struct device *dev = &adapter->pdev->dev;
+ struct be_vxlan_port *vxlan_port;
+ __be16 port;
+ int status;
+
+ vxlan_port = list_first_entry(&adapter->vxlan_port_list,
+ struct be_vxlan_port, list);
+ port = vxlan_port->port;
+
+ status = be_cmd_manage_iface(adapter, adapter->if_handle,
+ OP_CONVERT_NORMAL_TO_TUNNEL);
+ if (status) {
+ dev_warn(dev, "Failed to convert normal interface to tunnel\n");
+ return status;
+ }
+ adapter->flags |= BE_FLAGS_VXLAN_OFFLOADS;
+
+ status = be_cmd_set_vxlan_port(adapter, port);
+ if (status) {
+ dev_warn(dev, "Failed to add VxLAN port\n");
+ return status;
+ }
+ adapter->vxlan_port = port;
+
+ netdev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
+ NETIF_F_TSO | NETIF_F_TSO6 |
+ NETIF_F_GSO_UDP_TUNNEL;
+ netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
+ netdev->features |= NETIF_F_GSO_UDP_TUNNEL;
+
+ dev_info(dev, "Enabled VxLAN offloads for UDP port %d\n",
+ be16_to_cpu(port));
+ return 0;
+}
+
static void be_disable_vxlan_offloads(struct be_adapter *adapter)
{
struct net_device *netdev = adapter->netdev;
@@ -4903,63 +4941,59 @@ static struct be_cmd_work *be_alloc_work(struct be_adapter *adapter,
* those other tunnels are unexported on the fly through ndo_features_check().
*
* Skyhawk supports VxLAN offloads only for one UDP dport. So, if the stack
- * adds more than one port, disable offloads and don't re-enable them again
- * until after all the tunnels are removed.
+ * adds more than one port, disable offloads and re-enable them again when
+ * there's only one port left. We maintain a list of ports for this purpose.
*/
static void be_work_add_vxlan_port(struct work_struct *work)
{
struct be_cmd_work *cmd_work =
container_of(work, struct be_cmd_work, work);
struct be_adapter *adapter = cmd_work->adapter;
- struct net_device *netdev = adapter->netdev;
struct device *dev = &adapter->pdev->dev;
__be16 port = cmd_work->info.vxlan_port;
+ struct be_vxlan_port *vxlan_port;
int status;
- if (adapter->vxlan_port == port && adapter->vxlan_port_count) {
- adapter->vxlan_port_aliases++;
- goto done;
+ /* Bump up the alias count if it is an existing port */
+ list_for_each_entry(vxlan_port, &adapter->vxlan_port_list, list) {
+ if (vxlan_port->port == port) {
+ vxlan_port->port_aliases++;
+ goto done;
+ }
}
+ /* Add a new port to our list. We don't need a lock here since port
+ * add/delete are done only in the context of a single-threaded work
+ * queue (be_wq).
+ */
+ vxlan_port = kzalloc(sizeof(*vxlan_port), GFP_KERNEL);
+ if (!vxlan_port)
+ goto done;
+
+ vxlan_port->port = port;
+ INIT_LIST_HEAD(&vxlan_port->list);
+ list_add_tail(&vxlan_port->list, &adapter->vxlan_port_list);
+ adapter->vxlan_port_count++;
+
if (adapter->flags & BE_FLAGS_VXLAN_OFFLOADS) {
dev_info(dev,
"Only one UDP port supported for VxLAN offloads\n");
dev_info(dev, "Disabling VxLAN offloads\n");
- adapter->vxlan_port_count++;
goto err;
}
- if (adapter->vxlan_port_count++ >= 1)
+ if (adapter->vxlan_port_count > 1)
goto done;
- status = be_cmd_manage_iface(adapter, adapter->if_handle,
- OP_CONVERT_NORMAL_TO_TUNNEL);
- if (status) {
- dev_warn(dev, "Failed to convert normal interface to tunnel\n");
- goto err;
- }
-
- status = be_cmd_set_vxlan_port(adapter, port);
- if (status) {
- dev_warn(dev, "Failed to add VxLAN port\n");
- goto err;
- }
- adapter->flags |= BE_FLAGS_VXLAN_OFFLOADS;
- adapter->vxlan_port = port;
-
- netdev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
- NETIF_F_TSO | NETIF_F_TSO6 |
- NETIF_F_GSO_UDP_TUNNEL;
- netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
- netdev->features |= NETIF_F_GSO_UDP_TUNNEL;
+ status = be_enable_vxlan_offloads(adapter);
+ if (!status)
+ goto done;
- dev_info(dev, "Enabled VxLAN offloads for UDP port %d\n",
- be16_to_cpu(port));
- goto done;
err:
be_disable_vxlan_offloads(adapter);
done:
kfree(cmd_work);
+ return;
}
static void be_work_del_vxlan_port(struct work_struct *work)
@@ -4968,23 +5002,40 @@ static void be_work_del_vxlan_port(struct work_struct *work)
container_of(work, struct be_cmd_work, work);
struct be_adapter *adapter = cmd_work->adapter;
__be16 port = cmd_work->info.vxlan_port;
+ struct be_vxlan_port *vxlan_port;
- if (adapter->vxlan_port != port)
- goto done;
+ /* Nothing to be done if a port alias is being deleted */
+ list_for_each_entry(vxlan_port, &adapter->vxlan_port_list, list) {
+ if (vxlan_port->port == port) {
+ if (vxlan_port->port_aliases) {
+ vxlan_port->port_aliases--;
+ goto done;
+ }
+ break;
+ }
+ }
+
+ /* No port aliases left; delete the port from the list */
+ list_del(&vxlan_port->list);
+ adapter->vxlan_port_count--;
- if (adapter->vxlan_port_aliases) {
- adapter->vxlan_port_aliases--;
+ /* Disable VxLAN offload if this is the offloaded port */
+ if (adapter->vxlan_port == vxlan_port->port) {
+ WARN_ON(adapter->vxlan_port_count);
+ be_disable_vxlan_offloads(adapter);
+ dev_info(&adapter->pdev->dev,
+ "Disabled VxLAN offloads for UDP port %d\n",
+ be16_to_cpu(port));
goto out;
}
- be_disable_vxlan_offloads(adapter);
+ /* If only 1 port is left, re-enable VxLAN offload */
+ if (adapter->vxlan_port_count == 1)
+ be_enable_vxlan_offloads(adapter);
- dev_info(&adapter->pdev->dev,
- "Disabled VxLAN offloads for UDP port %d\n",
- be16_to_cpu(port));
-done:
- adapter->vxlan_port_count--;
out:
+ kfree(vxlan_port);
+done:
kfree(cmd_work);
}
@@ -5626,6 +5677,7 @@ static int be_drv_init(struct be_adapter *adapter)
/* Must be a power of 2 or else MODULO will BUG_ON */
adapter->be_get_temp_freq = 64;
+ INIT_LIST_HEAD(&adapter->vxlan_port_list);
return 0;
free_rx_filter:
--
2.11.0.258.ge05806da9
^ permalink raw reply related
* Re: [PATCH RFC] ptr_ring: add ptr_ring_unconsume
From: Sergei Shtylyov @ 2017-04-17 9:43 UTC (permalink / raw)
To: Michael S. Tsirkin, linux-kernel; +Cc: netdev, Jason Wang
In-Reply-To: <1492384496-22644-1-git-send-email-mst@redhat.com>
Hello!
On 4/17/2017 2:19 AM, Michael S. Tsirkin wrote:
> Applications that consume a batch of entries in one go
> can benefit from ability to return some of them back
> into the ring.
>
> Add an API for that - assuming there's space. If there's no space
> naturally we can't do this and have to drop entries, but this implies
> ring is full so we'd likely drop some anyway.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>
> Jason, in my mind the biggest issue with your batching patchset is the
> backet drops on disconnect. This API will help avoid that in the common
Packet?
[...]
> diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h
> index 783e7f5..5fbeab4 100644
> --- a/include/linux/ptr_ring.h
> +++ b/include/linux/ptr_ring.h
> @@ -457,6 +457,63 @@ static inline int ptr_ring_init(struct ptr_ring *r, int size, gfp_t gfp)
> return 0;
> }
>
> +/*
> + * Return entries into ring. Destroy entries that don't fit.
> + *
> + * Note: this is expected to be a rare slow path operation.
> + *
> + * Note: producer lock is nested within consumer lock, so if you
> + * resize you must make sure all uses nest correctly.
> + * In particular if you consume ring in interrupt or BH context, you must
> + * disable interrupts/BH when doing so.
> + */
> +static inline void ptr_ring_unconsume(struct ptr_ring *r, void **batch, int n,
> + void (*destroy)(void *))
> +{
> + unsigned long flags;
> + int head;
> +
> + spin_lock_irqsave(&(r)->consumer_lock, flags);
> + spin_lock(&(r)->producer_lock);
The innermost parens seem pointless here....
[...]
> +done:
> + /* Destroy all entries left in the batch. */
> + while (n--) {
> + destroy(batch[n]);
> + }
Braces not needed here.
> + spin_unlock(&(r)->producer_lock);
> + spin_unlock_irqrestore(&(r)->consumer_lock, flags);
Same comment about the innermost parens...
[...]
MBR, Sergei
^ permalink raw reply
* Re: [PATCH net-next 1/1] net sched actions: dump more than TCA_ACT_MAX_PRIO actions per batch
From: Jamal Hadi Salim @ 2017-04-17 11:01 UTC (permalink / raw)
To: Jiri Pirko; +Cc: davem, netdev, eric.dumazet, xiyou.wangcong
In-Reply-To: <20170417081936.GA1892@nanopsycho.orion>
On 17-04-17 04:19 AM, Jiri Pirko wrote:
> Sun, Apr 16, 2017 at 02:34:30PM CEST, jhs@mojatatu.com wrote:
>> From: Jamal Hadi Salim <jhs@mojatatu.com>
>>
>> When you dump hundreds of thousands of actions, getting only 32 per
>> dump batch even when the socket buffer and memory allocations allow
>> is inefficient.
>>
>> With this change, the user will get as many as possibly fitting
>> within the given constraints.
>>
>> We reuse the pad fields in tcamsg. pad1 is used as a flag space.
>> User explicitly requests for the large dump in order to maintain
>> backwards compatibility with user space by setting bit
>> ACT_LARGE_DUMP_ON; older user space which doesnt set this flag
>> doesnt get the large (than 32) batches - so continues to work
>> as before. Older kernels ignore this flag, so legacy behavior
>> is maintained.
>> The kernel uses pad2 to tell the user how many actions are put in
>> a single batch. As such user space app(like tc) knows how long
>> to iterate instead of hardcoded maximum of 32.
>>
>> Some results dumping 1.5M actions, first unpatched tc which the
>> kernel doesnt help:
>>
>> prompt$ time -p tc actions ls action gact | grep index | wc -l
>> 1500000
>> real 1388.43
>> user 2.07
>> sys 1386.79
>>
>> Now patched tc which sets the correct flags when requesting a dump:
>>
>> prompt$ time -p updatedtc actions ls action gact | grep index | wc -l
>> 1500000
>> real 178.13
>> user 2.02
>> sys 176.96
>>
>> Improvement: Dump time from about 20 minutes to about 2 minutes.
>>
>> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
>> ---
>> include/uapi/linux/rtnetlink.h | 7 +++++++
>> net/sched/act_api.c | 17 ++++++++++++++---
>> 2 files changed, 21 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
>> index cce0613..3434d98 100644
>> --- a/include/uapi/linux/rtnetlink.h
>> +++ b/include/uapi/linux/rtnetlink.h
>> @@ -678,6 +678,13 @@ struct tcamsg {
>> #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
>> #define TCA_ACT_TAB 1 /* attr type must be >=1 */
>> #define TCAA_MAX 1
>> +/* tcamsg flags stored in tca__pad
>> + *
>> + * ACT_LARGE_DUMP_ON user->kernel to request for larger than TCA_ACT_MAX_PRIO
>> + * actions in a dump. All dump responses will contain the number of actions
>> + * being dumped stored in tca__pad2 for user app's info
>> + */
>> +#define ACT_LARGE_DUMP_ON (1 << 0)
>>
>> /* New extended info filters for IFLA_EXT_MASK */
>> #define RTEXT_FILTER_VF (1 << 0)
>> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
>> index 79d875c..90cc774 100644
>> --- a/net/sched/act_api.c
>> +++ b/net/sched/act_api.c
>> @@ -83,6 +83,7 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb,
>> struct netlink_callback *cb)
>> {
>> int err = 0, index = -1, i = 0, s_i = 0, n_i = 0;
>> + unsigned short act_flags = cb->args[2];
>> struct nlattr *nest;
>>
>> spin_lock_bh(&hinfo->lock);
>> @@ -111,14 +112,18 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb,
>> }
>> nla_nest_end(skb, nest);
>> n_i++;
>> - if (n_i >= TCA_ACT_MAX_PRIO)
>> + if (!(act_flags & ACT_LARGE_DUMP_ON) &&
>> + n_i >= TCA_ACT_MAX_PRIO)
>> goto done;
>> }
>> }
>> done:
>> spin_unlock_bh(&hinfo->lock);
>> - if (n_i)
>> + if (n_i) {
>> cb->args[0] += n_i;
>> + if (act_flags & ACT_LARGE_DUMP_ON)
>> + cb->args[1] = n_i;
>> + }
>> return n_i;
>>
>> nla_put_failure:
>> @@ -1081,6 +1086,7 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
>> struct tc_action_ops *a_o;
>> int ret = 0;
>> struct tcamsg *t = (struct tcamsg *) nlmsg_data(cb->nlh);
>> + unsigned char act_flags = t->tca__pad1;
>> struct nlattr *kind = find_dump_kind(cb->nlh);
>>
>> if (kind == NULL) {
>> @@ -1096,9 +1102,12 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
>> cb->nlh->nlmsg_type, sizeof(*t), 0);
>> if (!nlh)
>> goto out_module_put;
>> +
>> + cb->args[2] = act_flags;
>> +
>> t = nlmsg_data(nlh);
>> t->tca_family = AF_UNSPEC;
>> - t->tca__pad1 = 0;
>> + t->tca__pad1 = act_flags;
>
> I don't like this one bit. Pad is no longer a pad but by name it still
> is. Why don't you introduce new attributes for this?
>
The name "pad" is ugly - but _we need to put these reserved spaces
to good use_. We cant keep declaring pads and say they should never
be used in the future.
We dont need more than 2-3 bits for the flags for example and i dont
see anyone dumping 64K actions in one message.
An attribute is a big waste of space. I cant change the name pad -
perhaps a union with a new name? We had a similar discussion a while
back on some netlink header, i just dont remember the details.
Suggestions?
cheers,
jamal
^ permalink raw reply
* Re: [PATCH] net: thunderx: Fix set_max_bgx_per_node for 81xx rgx
From: Sunil Kovvuri @ 2017-04-17 11:22 UTC (permalink / raw)
To: George Cherian
Cc: LAKML, Linux Netdev List, LKML, Sunil Goutham, Robert Richter
In-Reply-To: <1492068301-1141-1-git-send-email-george.cherian@cavium.com>
On Thu, Apr 13, 2017 at 12:55 PM, George Cherian
<george.cherian@cavium.com> wrote:
> Add the PCI_SUBSYS_DEVID_81XX_RGX and use the same to set
> the max bgx per node count.
>
> This fixes the issue intoduced by following commit
> 78aacb6f6 net: thunderx: Fix invalid mac addresses for node1 interfaces
> With this commit the max_bgx_per_node for 81xx is set as 2 instead of 3
> because of which num_vfs is always calculated as zero.
>
> Signed-off-by: George Cherian <george.cherian@cavium.com>
> ---
> drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 1 +
> drivers/net/ethernet/cavium/thunder/thunder_bgx.h | 1 +
> 2 files changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> index 64a1095..a0ca68c 100644
> --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> @@ -134,6 +134,7 @@ static void set_max_bgx_per_node(struct pci_dev *pdev)
> pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &sdevid);
> switch (sdevid) {
> case PCI_SUBSYS_DEVID_81XX_BGX:
> + case PCI_SUBSYS_DEVID_81XX_RGX:
> max_bgx_per_node = MAX_BGX_PER_CN81XX;
> break;
> case PCI_SUBSYS_DEVID_83XX_BGX:
> diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
> index c5080f2c..6b7fe6fd 100644
> --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
> +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
> @@ -16,6 +16,7 @@
> /* Subsystem device IDs */
> #define PCI_SUBSYS_DEVID_88XX_BGX 0xA126
> #define PCI_SUBSYS_DEVID_81XX_BGX 0xA226
> +#define PCI_SUBSYS_DEVID_81XX_RGX 0xA254
> #define PCI_SUBSYS_DEVID_83XX_BGX 0xA326
>
> #define MAX_BGX_THUNDER 8 /* Max 2 nodes, 4 per node */
> --
> 2.1.4
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Looks good, thanks.
Sunil.
^ permalink raw reply
* Re: [PATCH] sh_eth: unmap DMA buffers when freeing rings
From: Sergei Shtylyov @ 2017-04-17 12:45 UTC (permalink / raw)
To: netdev; +Cc: linux-renesas-soc
In-Reply-To: <ef4b905e-15fa-d257-72b3-bb5ed7f55b80@cogentembedded.com>
Hello!
On 04/17/2017 11:57 AM, Sergei Shtylyov wrote:
>> WARNING: CPU: 0 PID: 1445 at lib/dma-debug.c:519 add_dma_entry+0xe0/0x12c
>> DMA-API: exceeded 7 overlapping mappings of cacheline 0x01b2974d
>>
>> to be printed after repeated initialization of the Ether device, e.g.
>> suspend/resume or 'ifconfig' up/down. This is because DMA buffers mapped
>> using dma_map_single() in sh_eth_ring_format() and sh_eth_start_xmit() are
>> never unmapped. Resolve this problem by unmapping the buffers when freeing
>> the descriptor rings; in order to do it right, we'd have to add an extra
>> parameter to sh_eth_txfree() (we rename this function to sh_eth_tx_free(),
>> while at it).
>>
>> Based on the commit a47b70ea86bd ("ravb: unmap descriptors when freeing
>> rings").
>>
>> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
>>
>> ---
>> drivers/net/ethernet/renesas/sh_eth.c | 122
>> ++++++++++++++++++----------------
>> 1 file changed, 67 insertions(+), 55 deletions(-)
>>
>> Index: net/drivers/net/ethernet/renesas/sh_eth.c
>> ===================================================================
>> --- net.orig/drivers/net/ethernet/renesas/sh_eth.c
>> +++ net/drivers/net/ethernet/renesas/sh_eth.c
>> @@ -1127,12 +1127,70 @@ static struct mdiobb_ops bb_ops = {
>> .get_mdio_data = sh_get_mdio,
>> };
>>
>> +/* free Tx skb function */
>> +static int sh_eth_tx_free(struct net_device *ndev, bool sent_only)
>> +{
>> + struct sh_eth_private *mdp = netdev_priv(ndev);
>> + struct sh_eth_txdesc *txdesc;
>> + int free_num = 0;
>> + int entry;
>> + bool sent;
>> +
>> + for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) {
>> + entry = mdp->dirty_tx % mdp->num_tx_ring;
>> + txdesc = &mdp->tx_ring[entry];
>> + sent = txdesc->status & cpu_to_le32(TD_TACT);
>
> Oops, forgot to reverse the condition here. Which means I haven't goved in
s/goved in/given it/. :-)
> enough testing... :-/
TX statistics remained all 0s with this patch...
>> + if (sent_only && !sent)
>> + break;
[...]
MBR, Sergei
^ permalink raw reply
* [PATCH v2] sh_eth: unmap DMA buffers when freeing rings
From: Sergei Shtylyov @ 2017-04-17 12:55 UTC (permalink / raw)
To: netdev; +Cc: linux-renesas-soc, Simon Horman, Sergei Shtylyov
[-- Attachment #1: sh_eth-unmap-DMA-buffers-when-freeing-rings-v2.patch --]
[-- Type: text/plain, Size: 6385 bytes --]
The DMA API debugging (when enabled) causes:
WARNING: CPU: 0 PID: 1445 at lib/dma-debug.c:519 add_dma_entry+0xe0/0x12c
DMA-API: exceeded 7 overlapping mappings of cacheline 0x01b2974d
to be printed after repeated initialization of the Ether device, e.g.
suspend/resume or 'ifconfig' up/down. This is because DMA buffers mapped
using dma_map_single() in sh_eth_ring_format() and sh_eth_start_xmit() are
never unmapped. Resolve this problem by unmapping the buffers when freeing
the descriptor rings; in order to do it right, we'd have to add an extra
parameter to sh_eth_txfree() (we rename this function to sh_eth_tx_free(),
while at it).
Based on the commit a47b70ea86bd ("ravb: unmap descriptors when freeing
rings").
Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
---
This patch is against DaveM's 'net.git' repo.
Changed in version 2:
- fixed the "packet sent" condition in sh_eth_tx_free().
drivers/net/ethernet/renesas/sh_eth.c | 122 ++++++++++++++++++----------------
1 file changed, 67 insertions(+), 55 deletions(-)
Index: net/drivers/net/ethernet/renesas/sh_eth.c
===================================================================
--- net.orig/drivers/net/ethernet/renesas/sh_eth.c
+++ net/drivers/net/ethernet/renesas/sh_eth.c
@@ -1127,12 +1127,70 @@ static struct mdiobb_ops bb_ops = {
.get_mdio_data = sh_get_mdio,
};
+/* free Tx skb function */
+static int sh_eth_tx_free(struct net_device *ndev, bool sent_only)
+{
+ struct sh_eth_private *mdp = netdev_priv(ndev);
+ struct sh_eth_txdesc *txdesc;
+ int free_num = 0;
+ int entry;
+ bool sent;
+
+ for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) {
+ entry = mdp->dirty_tx % mdp->num_tx_ring;
+ txdesc = &mdp->tx_ring[entry];
+ sent = !(txdesc->status & cpu_to_le32(TD_TACT));
+ if (sent_only && !sent)
+ break;
+ /* TACT bit must be checked before all the following reads */
+ dma_rmb();
+ netif_info(mdp, tx_done, ndev,
+ "tx entry %d status 0x%08x\n",
+ entry, le32_to_cpu(txdesc->status));
+ /* Free the original skb. */
+ if (mdp->tx_skbuff[entry]) {
+ dma_unmap_single(&ndev->dev, le32_to_cpu(txdesc->addr),
+ le32_to_cpu(txdesc->len) >> 16,
+ DMA_TO_DEVICE);
+ dev_kfree_skb_irq(mdp->tx_skbuff[entry]);
+ mdp->tx_skbuff[entry] = NULL;
+ free_num++;
+ }
+ txdesc->status = cpu_to_le32(TD_TFP);
+ if (entry >= mdp->num_tx_ring - 1)
+ txdesc->status |= cpu_to_le32(TD_TDLE);
+
+ if (sent) {
+ ndev->stats.tx_packets++;
+ ndev->stats.tx_bytes += le32_to_cpu(txdesc->len) >> 16;
+ }
+ }
+ return free_num;
+}
+
/* free skb and descriptor buffer */
static void sh_eth_ring_free(struct net_device *ndev)
{
struct sh_eth_private *mdp = netdev_priv(ndev);
int ringsize, i;
+ if (mdp->rx_ring) {
+ for (i = 0; i < mdp->num_rx_ring; i++) {
+ if (mdp->rx_skbuff[i]) {
+ struct sh_eth_rxdesc *rxdesc = &mdp->rx_ring[i];
+
+ dma_unmap_single(&ndev->dev,
+ le32_to_cpu(rxdesc->addr),
+ ALIGN(mdp->rx_buf_sz, 32),
+ DMA_FROM_DEVICE);
+ }
+ }
+ ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring;
+ dma_free_coherent(NULL, ringsize, mdp->rx_ring,
+ mdp->rx_desc_dma);
+ mdp->rx_ring = NULL;
+ }
+
/* Free Rx skb ringbuffer */
if (mdp->rx_skbuff) {
for (i = 0; i < mdp->num_rx_ring; i++)
@@ -1141,27 +1199,18 @@ static void sh_eth_ring_free(struct net_
kfree(mdp->rx_skbuff);
mdp->rx_skbuff = NULL;
- /* Free Tx skb ringbuffer */
- if (mdp->tx_skbuff) {
- for (i = 0; i < mdp->num_tx_ring; i++)
- dev_kfree_skb(mdp->tx_skbuff[i]);
- }
- kfree(mdp->tx_skbuff);
- mdp->tx_skbuff = NULL;
-
- if (mdp->rx_ring) {
- ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring;
- dma_free_coherent(NULL, ringsize, mdp->rx_ring,
- mdp->rx_desc_dma);
- mdp->rx_ring = NULL;
- }
-
if (mdp->tx_ring) {
+ sh_eth_tx_free(ndev, false);
+
ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring;
dma_free_coherent(NULL, ringsize, mdp->tx_ring,
mdp->tx_desc_dma);
mdp->tx_ring = NULL;
}
+
+ /* Free Tx skb ringbuffer */
+ kfree(mdp->tx_skbuff);
+ mdp->tx_skbuff = NULL;
}
/* format skb and descriptor buffer */
@@ -1409,43 +1458,6 @@ static void sh_eth_dev_exit(struct net_d
update_mac_address(ndev);
}
-/* free Tx skb function */
-static int sh_eth_txfree(struct net_device *ndev)
-{
- struct sh_eth_private *mdp = netdev_priv(ndev);
- struct sh_eth_txdesc *txdesc;
- int free_num = 0;
- int entry;
-
- for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) {
- entry = mdp->dirty_tx % mdp->num_tx_ring;
- txdesc = &mdp->tx_ring[entry];
- if (txdesc->status & cpu_to_le32(TD_TACT))
- break;
- /* TACT bit must be checked before all the following reads */
- dma_rmb();
- netif_info(mdp, tx_done, ndev,
- "tx entry %d status 0x%08x\n",
- entry, le32_to_cpu(txdesc->status));
- /* Free the original skb. */
- if (mdp->tx_skbuff[entry]) {
- dma_unmap_single(&ndev->dev, le32_to_cpu(txdesc->addr),
- le32_to_cpu(txdesc->len) >> 16,
- DMA_TO_DEVICE);
- dev_kfree_skb_irq(mdp->tx_skbuff[entry]);
- mdp->tx_skbuff[entry] = NULL;
- free_num++;
- }
- txdesc->status = cpu_to_le32(TD_TFP);
- if (entry >= mdp->num_tx_ring - 1)
- txdesc->status |= cpu_to_le32(TD_TDLE);
-
- ndev->stats.tx_packets++;
- ndev->stats.tx_bytes += le32_to_cpu(txdesc->len) >> 16;
- }
- return free_num;
-}
-
/* Packet receive function */
static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
{
@@ -1690,7 +1702,7 @@ static void sh_eth_error(struct net_devi
intr_status, mdp->cur_tx, mdp->dirty_tx,
(u32)ndev->state, edtrr);
/* dirty buffer free */
- sh_eth_txfree(ndev);
+ sh_eth_tx_free(ndev, true);
/* SH7712 BUG */
if (edtrr ^ sh_eth_get_edtrr_trns(mdp)) {
@@ -1751,7 +1763,7 @@ static irqreturn_t sh_eth_interrupt(int
/* Clear Tx interrupts */
sh_eth_write(ndev, intr_status & cd->tx_check, EESR);
- sh_eth_txfree(ndev);
+ sh_eth_tx_free(ndev, true);
netif_wake_queue(ndev);
}
@@ -2412,7 +2424,7 @@ static int sh_eth_start_xmit(struct sk_b
spin_lock_irqsave(&mdp->lock, flags);
if ((mdp->cur_tx - mdp->dirty_tx) >= (mdp->num_tx_ring - 4)) {
- if (!sh_eth_txfree(ndev)) {
+ if (!sh_eth_tx_free(ndev, true)) {
netif_warn(mdp, tx_queued, ndev, "TxFD exhausted.\n");
netif_stop_queue(ndev);
spin_unlock_irqrestore(&mdp->lock, flags);
^ permalink raw reply
* (unknown),
From: openhackbangalore @ 2017-04-17 12:59 UTC (permalink / raw)
To: netdev
[-- Attachment #1: EMAIL_5758843219-netdev.zip --]
[-- Type: application/zip, Size: 2011 bytes --]
^ permalink raw reply
* Re: [PATCH net-next 1/1] net sched actions: dump more than TCA_ACT_MAX_PRIO actions per batch
From: Eric Dumazet @ 2017-04-17 13:10 UTC (permalink / raw)
To: Jamal Hadi Salim; +Cc: Jiri Pirko, davem, netdev, xiyou.wangcong
In-Reply-To: <dfc1485f-7d7e-f52e-f62e-273063a59abc@mojatatu.com>
On Mon, 2017-04-17 at 07:01 -0400, Jamal Hadi Salim wrote:
> The name "pad" is ugly - but _we need to put these reserved spaces
> to good use_. We cant keep declaring pads and say they should never
> be used in the future.
> We dont need more than 2-3 bits for the flags for example and i dont
> see anyone dumping 64K actions in one message.
> An attribute is a big waste of space. I cant change the name pad -
> perhaps a union with a new name? We had a similar discussion a while
> back on some netlink header, i just dont remember the details.
> Suggestions?
We can not assume user programs properly cleared the paddings anyway.
Using them for 'new features' is risky, since it might break programs.
So the safe way is using new attributes really.
^ permalink raw reply
* Re: skb_over_panic using UDP and 6lowpan / fakelb
From: Alexander Aring @ 2017-04-17 13:25 UTC (permalink / raw)
To: Cong Wang
Cc: David Palma, LKML, Linux Kernel Network Developers, stefan,
linux-wpan
In-Reply-To: <CAM_iQpWqQj3FLpBLE1Z+==Z7tJGXHyHXTvLmKRCNjyc=vtQvnQ@mail.gmail.com>
Hi,
sorry for the late reply.
On 04/03/2017 07:29 PM, Cong Wang wrote:
> (Cc'ing netdev and maintainers)
>
> On Mon, Mar 27, 2017 at 2:16 AM, David Palma <david.palma@ntnu.no> wrote:
>>
>> Hi,
>>
>> Sending a simple UDP packet (39 bytes long), over a 6lowpan interface
>> (using fakelb), creates a kernel panic (skb_over_panic).
>>
>> Steps to reproduce, and more details, can be found in:
>> https://github.com/PalmaITEM/6lowpan-skb_over_panic
>>
>> This bug has been reported in
>> https://bugzilla.kernel.org/show_bug.cgi?id=195059
>>
>> I have found that lengths around 39 bytes can also trigger this
>> behaviour and that longer packets are handled without problem.
>>
>> Verified in:
>>
>> - Linux version 4.9.0-0.bpo.2-amd64 (debian-kernel@lists.debian.org)
>> (gcc version 4.9.2 (Debian 4.9.2-10) ) #1 SMP Debian 4.9.13-1~bpo8+1
>> (2017-02-27)
>> - Linux version 4.10.4-1-ARCH (builduser@tobias) (gcc version 6.3.1
>> 20170306 (GCC) ) #1 SMP PREEMPT Sat Mar 18 19:39:18 CET 2017
>>
>>
>> I am not familiar with the process of reporting kernel bugs, so
>> apologies beforehand. I am also available to provide any missing
>> information.
>>
I will try to reproduce the failure with an x86_64 qemu virtual machine.
Myself I use a 32 Bit qemu machine because I have a dependency on
userspace software which use x86 assembler (somebody should change it to
setjmp/longjmp)... it's the RIOT-OS native plattform. I use some cross
compiling environment which doesn't support multilib yet, so I used
always 32 Bit.
btw: the github stuff is very useful and thanks for the hard work! I am
on it to reproduce it. I will report when I have more information.
- Alex
^ permalink raw reply
* Re: [PATCH net-next 1/1] net sched actions: dump more than TCA_ACT_MAX_PRIO actions per batch
From: Jamal Hadi Salim @ 2017-04-17 14:02 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Jiri Pirko, davem, netdev, xiyou.wangcong
In-Reply-To: <1492434659.10587.90.camel@edumazet-glaptop3.roam.corp.google.com>
On 17-04-17 09:10 AM, Eric Dumazet wrote:
[..]
>
> We can not assume user programs properly cleared the paddings anyway.
>
> Using them for 'new features' is risky, since it might break programs.
>
> So the safe way is using new attributes really.
Since we agreed to have longer discussions on uapis
when we met I'd like to digress:
Can we talk about what it means to define pads in data
structures and then never using them?
As an example, no-one is setting these fields anywhere on any
app i know of. Would a union not be good enough for new name
vs old name? old binaries should continue to work.
Breakage with any app during compile should be fixable
within the breaking app (since whoever it is would have source).
Maybe by breaking some weird app we can experiment on finding
out.
My contention is that it is not nice to continue to define uapi
pads and then say they cant be used ever.
cheers,
jamal
^ permalink raw reply
* [PATCH net-next] Replace constant with sysctl netdev_budget_jiffies to enable tuning
From: Matthew Whitehead @ 2017-04-17 14:29 UTC (permalink / raw)
To: netdev; +Cc: Matthew Whitehead
Constants used for tuning are generally a bad idea, especially as hardware
changes over time. Replace the constant '2' with netdev_budget_jiffies to
enable sysadmins to tune the behavior. Also document the variable.
For example, a very fast machine might tune this to 1, while my regression
testing 486DX-25 needs it to be 4 on a nearly idle network to prevent
time_squeeze from being incremented.
Signed-off-by: Matthew Whitehead <tedheadster@gmail.com>
---
Documentation/sysctl/net.txt | 12 +++++++++++-
include/linux/netdevice.h | 1 +
include/uapi/linux/sysctl.h | 1 +
kernel/sysctl_binary.c | 1 +
net/core/dev.c | 3 ++-
net/core/sysctl_net_core.c | 7 +++++++
6 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/Documentation/sysctl/net.txt b/Documentation/sysctl/net.txt
index 2ebabc9..36f8a5b 100644
--- a/Documentation/sysctl/net.txt
+++ b/Documentation/sysctl/net.txt
@@ -188,7 +188,17 @@ netdev_budget
Maximum number of packets taken from all interfaces in one polling cycle (NAPI
poll). In one polling cycle interfaces which are registered to polling are
-probed in a round-robin manner.
+probed in a round-robin manner. Also, a polling cycle may not exceed
+netdev_budget_jiffies units of time, even if netdev_budget has not been
+exhausted.
+
+netdev_budget_jiffies
+---------------------
+
+Maximum number of jiffies time units in one NAPI polling cycle. Polling
+will exit when either netdev_budget_jiffies (default 2) time units have
+elapsed during the poll cycle or the number of packets processed
+reaches netdev_budget.
netdev_max_backlog
------------------
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 97456b25..58f2682 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3305,6 +3305,7 @@ static __always_inline int ____dev_forward_skb(struct net_device *dev,
void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
extern int netdev_budget;
+extern int netdev_budget_jiffies;
/* Called by rtnetlink.c:rtnl_unlock() */
void netdev_run_todo(void);
diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
index d2b1215..79c0bd7 100644
--- a/include/uapi/linux/sysctl.h
+++ b/include/uapi/linux/sysctl.h
@@ -274,6 +274,7 @@ enum
NET_CORE_AEVENT_ETIME=20,
NET_CORE_AEVENT_RSEQTH=21,
NET_CORE_WARNINGS=22,
+ NET_CORE_BUDGET_JIFFIES=23,
};
/* /proc/sys/net/ethernet */
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
index ece4b17..e38e197 100644
--- a/kernel/sysctl_binary.c
+++ b/kernel/sysctl_binary.c
@@ -197,6 +197,7 @@ struct bin_table {
{ CTL_INT, NET_CORE_AEVENT_ETIME, "xfrm_aevent_etime" },
{ CTL_INT, NET_CORE_AEVENT_RSEQTH, "xfrm_aevent_rseqth" },
{ CTL_INT, NET_CORE_WARNINGS, "warnings" },
+ { CTL_INT, NET_CORE_BUDGET_JIFFIES, "netdev_budget_jiffies" },
{},
};
diff --git a/net/core/dev.c b/net/core/dev.c
index 7869ae3..6907a6e 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3441,6 +3441,7 @@ int dev_queue_xmit_accel(struct sk_buff *skb, void *accel_priv)
int netdev_tstamp_prequeue __read_mostly = 1;
int netdev_budget __read_mostly = 300;
+int netdev_budget_jiffies __read_mostly = 2;
int weight_p __read_mostly = 64; /* old backlog weight */
int dev_weight_rx_bias __read_mostly = 1; /* bias for backlog weight */
int dev_weight_tx_bias __read_mostly = 1; /* bias for output_queue quota */
@@ -5310,7 +5311,7 @@ static int napi_poll(struct napi_struct *n, struct list_head *repoll)
static __latent_entropy void net_rx_action(struct softirq_action *h)
{
struct softnet_data *sd = this_cpu_ptr(&softnet_data);
- unsigned long time_limit = jiffies + 2;
+ unsigned long time_limit = jiffies + netdev_budget_jiffies;
int budget = netdev_budget;
LIST_HEAD(list);
LIST_HEAD(repoll);
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index 7f9cc40..9cd367c 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -452,6 +452,13 @@ static int proc_do_rss_key(struct ctl_table *table, int write,
.extra1 = &one,
.extra2 = &max_skb_frags,
},
+ {
+ .procname = "netdev_budget_jiffies",
+ .data = &netdev_budget_jiffies,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec
+ },
{ }
};
--
1.8.3.1
^ permalink raw reply related
* (unknown),
From: energi @ 2017-04-17 14:38 UTC (permalink / raw)
To: netdev
[-- Attachment #1: EMAIL_2410371928-netdev.zip --]
[-- Type: application/zip, Size: 1212 bytes --]
^ permalink raw reply
* Re: [PATCH net-next 1/1] net sched actions: dump more than TCA_ACT_MAX_PRIO actions per batch
From: Eric Dumazet @ 2017-04-17 14:58 UTC (permalink / raw)
To: Jamal Hadi Salim; +Cc: Jiri Pirko, davem, netdev, xiyou.wangcong
In-Reply-To: <7a49a797-d9cb-37c1-e46b-bec6888539b9@mojatatu.com>
On Mon, 2017-04-17 at 10:02 -0400, Jamal Hadi Salim wrote:
> On 17-04-17 09:10 AM, Eric Dumazet wrote:
>
> [..]
> >
> > We can not assume user programs properly cleared the paddings anyway.
> >
> > Using them for 'new features' is risky, since it might break programs.
> >
> > So the safe way is using new attributes really.
>
> Since we agreed to have longer discussions on uapis
> when we met I'd like to digress:
> Can we talk about what it means to define pads in data
> structures and then never using them?
> As an example, no-one is setting these fields anywhere on any
> app i know of. Would a union not be good enough for new name
> vs old name? old binaries should continue to work.
> Breakage with any app during compile should be fixable
> within the breaking app (since whoever it is would have source).
> Maybe by breaking some weird app we can experiment on finding
> out.
>
> My contention is that it is not nice to continue to define uapi
> pads and then say they cant be used ever.
Very often, pads are there because of ABI constraints.
We 'name' them to make clear to developers that they are there,
and avoid security issues, because of say few bytes from kernel stack
are copied to user space.
struct foo {
__u32 a;
__u16 b;
};
Note that the 16bit padding is there, even if you do not name it.
Once this structure had been exported to some include file and in a
kernel, there is little point trying to 'reuse' the padding, unless for
very specific cases.
If you name paddings, then developers might think about it.
^ permalink raw reply
* Re: [RFC PATCH linux 0/2] net sched actions: access to uninitialized data and error handling
From: David Miller @ 2017-04-17 14:59 UTC (permalink / raw)
To: w.bumiller; +Cc: netdev, linux-kernel, jhs
In-Reply-To: <20170412142140.26649-1-w.bumiller@proxmox.com>
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
Date: Wed, 12 Apr 2017 16:21:38 +0200
> Commit 1045ba77a ("net sched actions: Add support for user cookies")
> added code to net/sched/act_api.c's tcf_action_init_1 using the `tb`
> nlattr array unconditionally, while it was otherwise used as well as
> initialized only when `name == NULL`:
...
> I'm not sure why the TC_ACT_COOKIE code was added to tcf_action_init_1
> where it is now. It makes me think that it's supposed to be available
> universally, but the `name == NULL` check for how nla is used or passed
> to ->init() shows that the there are various different TC_ACT_* enums in
> use at this point, hence the 'RFC' part of the patches, I'm not that
> familiar with the code yet.
Jamal please review this.
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox