bpf: xdp: allow offloads to store into rx_queue_index
authorJakub Kicinski <jakub.kicinski@netronome.com>
Wed, 9 May 2018 02:37:06 +0000 (19:37 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 9 May 2018 16:04:36 +0000 (18:04 +0200)
It's fairly easy for offloaded XDP programs to select the RX queue
packets go to.  We need a way of expressing this in the software.
Allow write to the rx_queue_index field of struct xdp_md for
device-bound programs.

Skip convert_ctx_access callback entirely for offloads.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
include/linux/bpf.h
kernel/bpf/verifier.c
net/core/filter.c

index 321969da67b77776ed0d27027668b5baffebdb0c..a38e474bf7ee213a9a06b6ca8e5d01c628e09ca3 100644 (file)
@@ -627,7 +627,7 @@ bool bpf_offload_dev_match(struct bpf_prog *prog, struct bpf_map *map);
 #if defined(CONFIG_NET) && defined(CONFIG_BPF_SYSCALL)
 int bpf_prog_offload_init(struct bpf_prog *prog, union bpf_attr *attr);
 
-static inline bool bpf_prog_is_dev_bound(struct bpf_prog_aux *aux)
+static inline bool bpf_prog_is_dev_bound(const struct bpf_prog_aux *aux)
 {
        return aux->offload_requested;
 }
index d5e1a6c4165d997a1921243568a884e62f898eeb..d92d9c37affd70d3e4b16d97d3dcdc00de818c62 100644 (file)
@@ -5215,7 +5215,7 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
                }
        }
 
-       if (!ops->convert_ctx_access)
+       if (!ops->convert_ctx_access || bpf_prog_is_dev_bound(env->prog->aux))
                return 0;
 
        insn = env->prog->insnsi + delta;
index 6877426c23a682809bb8349ed461b18d7fe3012d..0baa715e469986aa6f97de60937e93a5bbccc286 100644 (file)
@@ -4645,8 +4645,15 @@ static bool xdp_is_valid_access(int off, int size,
                                const struct bpf_prog *prog,
                                struct bpf_insn_access_aux *info)
 {
-       if (type == BPF_WRITE)
+       if (type == BPF_WRITE) {
+               if (bpf_prog_is_dev_bound(prog->aux)) {
+                       switch (off) {
+                       case offsetof(struct xdp_md, rx_queue_index):
+                               return __is_valid_xdp_access(off, size);
+                       }
+               }
                return false;
+       }
 
        switch (off) {
        case offsetof(struct xdp_md, data):