]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
bpf: report offload info to user space
authorJakub Kicinski <jakub.kicinski@netronome.com>
Fri, 3 Nov 2017 20:56:18 +0000 (13:56 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sun, 5 Nov 2017 13:26:18 +0000 (22:26 +0900)
Extend struct bpf_prog_info to contain information about program
being bound to a device.  Since the netdev may get destroyed while
program still exists we need a flag to indicate the program is
loaded for a device, even if the device is gone.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/bpf.h
include/uapi/linux/bpf.h
kernel/bpf/offload.c
kernel/bpf/syscall.c

index e45d43f9ec92d2c6d27cf3057538061fb936c66f..98bacd0fa5cc8b6885751820bb1f421894b848af 100644 (file)
@@ -506,6 +506,7 @@ static inline int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu,
 
 int bpf_prog_offload_compile(struct bpf_prog *prog);
 void bpf_prog_offload_destroy(struct bpf_prog *prog);
+u32 bpf_prog_offload_ifindex(struct bpf_prog *prog);
 
 #if defined(CONFIG_NET) && defined(CONFIG_BPF_SYSCALL)
 int bpf_prog_offload_init(struct bpf_prog *prog, union bpf_attr *attr);
index 80d191a93fb0c6874862dabdd61f935b7e0458d9..4455dd1952016a86d5465b520b669a587ef7c22a 100644 (file)
@@ -895,6 +895,10 @@ enum sk_action {
 
 #define BPF_TAG_SIZE   8
 
+enum bpf_prog_status {
+       BPF_PROG_STATUS_DEV_BOUND       = (1 << 0),
+};
+
 struct bpf_prog_info {
        __u32 type;
        __u32 id;
@@ -908,6 +912,8 @@ struct bpf_prog_info {
        __u32 nr_map_ids;
        __aligned_u64 map_ids;
        char name[BPF_OBJ_NAME_LEN];
+       __u32 ifindex;
+       __u32 status;
 } __attribute__((aligned(8)));
 
 struct bpf_map_info {
index 5553e0e2f8b19d3f0c73cf60b854dfceb13bd12a..2816feb38be16a0137bc7aa351606f24466c55e1 100644 (file)
@@ -144,6 +144,18 @@ int bpf_prog_offload_compile(struct bpf_prog *prog)
        return bpf_prog_offload_translate(prog);
 }
 
+u32 bpf_prog_offload_ifindex(struct bpf_prog *prog)
+{
+       struct bpf_dev_offload *offload = prog->aux->offload;
+       u32 ifindex;
+
+       rtnl_lock();
+       ifindex = offload->netdev ? offload->netdev->ifindex : 0;
+       rtnl_unlock();
+
+       return ifindex;
+}
+
 const struct bpf_prog_ops bpf_offload_prog_ops = {
 };
 
index 1574b9f0f24eaf5dce4dfaeb7331408f0bc709e6..3217c20ea91b5812a96e17aa2f21438f1cda42e9 100644 (file)
@@ -1592,6 +1592,11 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
                        return -EFAULT;
        }
 
+       if (bpf_prog_is_dev_bound(prog->aux)) {
+               info.status |= BPF_PROG_STATUS_DEV_BOUND;
+               info.ifindex = bpf_prog_offload_ifindex(prog);
+       }
+
 done:
        if (copy_to_user(uinfo, &info, info_len) ||
            put_user(info_len, &uattr->info.info_len))