]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
bpf: add napi_id read access to __sk_buff
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 19 Apr 2017 21:01:17 +0000 (23:01 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 21 Apr 2017 17:53:27 +0000 (13:53 -0400)
Add napi_id access to __sk_buff for socket filter program types, tc
program types and other bpf_convert_ctx_access() users. Having access
to skb->napi_id is useful for per RX queue listener siloing, f.e.
in combination with SO_ATTACH_REUSEPORT_EBPF and when busy polling is
used, meaning SO_REUSEPORT enabled listeners can then select the
corresponding socket at SYN time already [1]. The skb is marked via
skb_mark_napi_id() early in the receive path (e.g., napi_gro_receive()).

Currently, sockets can only use SO_INCOMING_NAPI_ID from 6d4339028b35
("net: Introduce SO_INCOMING_NAPI_ID") as a socket option to look up
the NAPI ID associated with the queue for steering, which requires a
prior sk_mark_napi_id() after the socket was looked up.

Semantics for the __sk_buff napi_id access are similar, meaning if
skb->napi_id is < MIN_NAPI_ID (e.g. outgoing packets using sender_cpu),
then an invalid napi_id of 0 is returned to the program, otherwise a
valid non-zero napi_id.

  [1] http://netdevconf.org/2.1/slides/apr6/dumazet-BUSY-POLLING-Netdev-2.1.pdf

Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/uapi/linux/bpf.h
net/core/filter.c
tools/include/uapi/linux/bpf.h
tools/testing/selftests/bpf/test_verifier.c

index 1e062bb54eec11b866cfb8faf99e44c725d2c4e5..e553529929f683c4c39ae336d10c6f670e589b54 100644 (file)
@@ -603,6 +603,7 @@ struct __sk_buff {
        __u32 tc_classid;
        __u32 data;
        __u32 data_end;
+       __u32 napi_id;
 };
 
 struct bpf_tunnel_key {
index 0859258347277dbcf53bd70f976dcc8984404fff..9a37860a80fc78378705b681ec3b0468824cbcf4 100644 (file)
@@ -53,6 +53,7 @@
 #include <net/dst_metadata.h>
 #include <net/dst.h>
 #include <net/sock_reuseport.h>
+#include <net/busy_poll.h>
 
 /**
  *     sk_filter_trim_cap - run a packet through a socket filter
@@ -3201,6 +3202,19 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,
                        *insn++ = BPF_MOV64_REG(si->dst_reg, si->dst_reg);
                else
                        *insn++ = BPF_MOV64_IMM(si->dst_reg, 0);
+#endif
+               break;
+
+       case offsetof(struct __sk_buff, napi_id):
+#if defined(CONFIG_NET_RX_BUSY_POLL)
+               BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, napi_id) != 4);
+
+               *insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->src_reg,
+                                     offsetof(struct sk_buff, napi_id));
+               *insn++ = BPF_JMP_IMM(BPF_JGE, si->dst_reg, MIN_NAPI_ID, 1);
+               *insn++ = BPF_MOV64_IMM(si->dst_reg, 0);
+#else
+               *insn++ = BPF_MOV64_IMM(si->dst_reg, 0);
 #endif
                break;
        }
index 1e062bb54eec11b866cfb8faf99e44c725d2c4e5..e553529929f683c4c39ae336d10c6f670e589b54 100644 (file)
@@ -603,6 +603,7 @@ struct __sk_buff {
        __u32 tc_classid;
        __u32 data;
        __u32 data_end;
+       __u32 napi_id;
 };
 
 struct bpf_tunnel_key {
index 6178b65fee5941f9566fa711bd4ac77f34b816ad..95a8d5f3ab80d9c3dd65e35dea74fab558adb21d 100644 (file)
@@ -772,6 +772,9 @@ static struct bpf_test tests[] = {
                        BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
                                    offsetof(struct __sk_buff, vlan_tci)),
                        BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 0, 0),
+                       BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, napi_id)),
+                       BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 0, 0),
                        BPF_EXIT_INSN(),
                },
                .result = ACCEPT,