Received: by 10.223.164.202 with SMTP id h10csp32434wrb; Wed, 29 Nov 2017 16:24:38 -0800 (PST) X-Google-Smtp-Source: AGs4zMbuNeO2VpUC1ZyY9ui6bplItJPi6+oQ2P2e/vRv5soshV6i0nwKk3hx6L2F8LzCPOp83yJN X-Received: by 10.84.132.46 with SMTP id 43mr693961ple.126.1512001478393; Wed, 29 Nov 2017 16:24:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512001478; cv=none; d=google.com; s=arc-20160816; b=0HbXiD0k/I+81MgQmfj9HYSypexx+8gy198eBmJSZkMyP+vBo4yw9FJVbeEagOnM2R q7XD6MPSnhygiH8xb9i2gjFmQGqR7aW4jrF01JQgPsBsa9Ln2qxo6bTx0LXTGmE3eeKA +P+Lg6F6uZS3RbcIdR9pUbzF5PlBeQ+iea5SQVltZqmkO1a83HRWL90/dhNwZWrNU59v TfK+/TPvTUBTFzgp1nTYdU6sVOewyKq/ey8t5lguG615vGg0B42q/yAWQ9eZIilViPZy MGiR2QpGuM4lnibNuNKhnarP5W8bkcJvPxfPEK/JedXlylx408SNFlJ3VWPd1BhGo00+ PJbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=vtWOgqBC84uY/6/VGRjTJxsBhI6vVvXrTvjO59zRxEM=; b=b8ptdZPwfmSJzFAAHTNL5bodP5kvsGTZWXOyOYRT9aJ7mgmS6dvnvpgji7SvB9MnfQ YzFC/ELH7HJw7iLFcjcFo72qZF3X+qz+jseYfl5Is/AfqxKqNAbEa94W9kOxNXxWPU3g k0DTGxNUYtCYXzKfMvFV49AHBhGDRdLjXFVUHHZT+4XcHt+ynPuqMb6Wcg/f/Jn6Vs+G srOfshUZhfaXCxvrsl2WpzIJCJBNIYl/qWDxq/b067UzqrM07njNmDPpRXBg9ct4H/Aj NC/rSPu32gaJr/WxXkKgtL2x7CsKlYYXnAmyUxN0LU7NVD8z9mPC4uIO0P++i9BI7BR6 a60Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=09bpydAX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t21si2138042pfh.167.2017.11.29.16.24.24; Wed, 29 Nov 2017 16:24:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=09bpydAX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753555AbdK3AYM (ORCPT + 99 others); Wed, 29 Nov 2017 19:24:12 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:40852 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752716AbdK3AYK (ORCPT ); Wed, 29 Nov 2017 19:24:10 -0500 Received: by mail-pg0-f65.google.com with SMTP id k15so2245687pgr.7 for ; Wed, 29 Nov 2017 16:24:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=vtWOgqBC84uY/6/VGRjTJxsBhI6vVvXrTvjO59zRxEM=; b=09bpydAXJFsKuWVw9t1C67U38DNjjjlLo/ls9Dv/Pw1mLR434MQ0urKKafkRr8V8He SZr8Dagr95cgHrddgdoK1jjgQf78Lspb7h7wCddZLQbpV+5AP+9OXR9bFTFfJP/M3txa nlOmON8Y/AoeqiERhBdk9mBY/sPHy0HpnaL0SSM++FUAXRwxdFKRAfY2T2T5HSHvlI/G kGsR61sjK5U2iBW5ZnSc6ZpZ59MqZS7u0HDE5LURHdwBl18dTb7dOYrJtwZvr/PbYH00 DC1Y7UOh7o9wCf2yAycEMR73g5EwbOUI6JE2Yy7IMGgfByHzxxE2wHH9CVv/nAgFrBFE 4uNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vtWOgqBC84uY/6/VGRjTJxsBhI6vVvXrTvjO59zRxEM=; b=GyWDHO9ekyiGRczRWYAPNP8rvC4++/bmcLX/n4L8MUTuQx4+CYDQiS6R37hyCrtk8h U2y+AMhPAIPk3gaosg6tvWjJOOicmPMp/aDDckziFHbfPXyYwgl8VP8lWsjGl1N9SNyB SVD3AGDsljvkVD6P1vLTqhxCKpWPu7cMpxQsg7fizL2IU5lv3nUIqEweqlMFKmkLvoa1 Dx4wJtrYCvbepoTVgX9VxoX4ikihea/vr18iehQAH8vPpvmBdT+GwmxoEIeueEvSFFL4 AV08YPxjfi7f3jFRa1j6BYozFaM7IQxnni46qXlVQcRfuaCQkwxwBA7XxYKzVE2N4DHJ 7fUA== X-Gm-Message-State: AJaThX4/5Qppr4idlrG1gcgAacu3O/9Ek3Dthiq2MWQTOQWkU6N4p4+9 PIWwlfi5D17+5CnRWJ+XRjUOLQ== X-Received: by 10.99.121.74 with SMTP id u71mr647341pgc.251.1512001449576; Wed, 29 Nov 2017 16:24:09 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id e87sm5582194pfd.165.2017.11.29.16.24.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Nov 2017 16:24:08 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, oss-drivers@netronome.com, alexei.starovoitov@gmail.com, daniel@iogearbox.net, "Eric W . Biederman" , Kirill Tkhai , Jakub Kicinski Subject: [RFC] bpf: offload: report device information for offloaded programs Date: Wed, 29 Nov 2017 16:22:51 -0800 Message-Id: <20171130002251.30498-1-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Report to the user ifindex and namespace information of offloaded programs. Always set dev_bound to true if program was loaded for a device which has been since removed. Specify the namespace using dev/inode combination. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Reviewed-by: Quentin Monnet --- fs/nsfs.c | 2 +- include/linux/bpf.h | 2 ++ include/linux/proc_ns.h | 1 + include/uapi/linux/bpf.h | 5 +++++ kernel/bpf/offload.c | 34 ++++++++++++++++++++++++++++++++++ kernel/bpf/syscall.c | 6 ++++++ tools/include/uapi/linux/bpf.h | 5 +++++ 7 files changed, 54 insertions(+), 1 deletion(-) diff --git a/fs/nsfs.c b/fs/nsfs.c index ef243e14b6eb..d2b89372544a 100644 --- a/fs/nsfs.c +++ b/fs/nsfs.c @@ -51,7 +51,7 @@ static void nsfs_evict(struct inode *inode) ns->ops->put(ns); } -static void *__ns_get_path(struct path *path, struct ns_common *ns) +void *__ns_get_path(struct path *path, struct ns_common *ns) { struct vfsmount *mnt = nsfs_mnt; struct dentry *dentry; diff --git a/include/linux/bpf.h b/include/linux/bpf.h index e55e4255a210..fc7ab26e10bf 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -516,6 +516,8 @@ static inline struct bpf_prog *bpf_prog_get_type(u32 ufd, int bpf_prog_offload_compile(struct bpf_prog *prog); void bpf_prog_offload_destroy(struct bpf_prog *prog); +int bpf_prog_offload_info_fill(struct bpf_prog_info *info, + 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); diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h index 2ff18c9840a7..1733359cf713 100644 --- a/include/linux/proc_ns.h +++ b/include/linux/proc_ns.h @@ -76,6 +76,7 @@ static inline int ns_alloc_inum(struct ns_common *ns) extern struct file *proc_ns_fget(int fd); #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private) +extern void *__ns_get_path(struct path *path, struct ns_common *ns); extern void *ns_get_path(struct path *path, struct task_struct *task, const struct proc_ns_operations *ns_ops); diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 4c223ab30293..3183674496a2 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -910,6 +910,11 @@ struct bpf_prog_info { __u32 nr_map_ids; __aligned_u64 map_ids; char name[BPF_OBJ_NAME_LEN]; + __u32 dev_bound:1; + __u32 reserved:31; + __u32 ifindex; + __u64 ns_dev; + __u64 ns_inode; } __attribute__((aligned(8))); struct bpf_map_info { diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c index 8455b89d1bbf..da98349c647d 100644 --- a/kernel/bpf/offload.c +++ b/kernel/bpf/offload.c @@ -16,9 +16,11 @@ #include #include #include +#include #include #include #include +#include #include /* protected by RTNL */ @@ -164,6 +166,38 @@ int bpf_prog_offload_compile(struct bpf_prog *prog) return bpf_prog_offload_translate(prog); } +int bpf_prog_offload_info_fill(struct bpf_prog_info *info, + struct bpf_prog *prog) +{ + struct bpf_dev_offload *offload = prog->aux->offload; + struct inode *ns_inode; + struct path ns_path; + struct net *net; + int ret = 0; + void *ptr; + + info->dev_bound = 1; + + rtnl_lock(); + if (!offload->netdev) + goto out; + + net = dev_net(offload->netdev); + get_net(net); /* __ns_get_path() drops the reference */ + ptr = __ns_get_path(&ns_path, &net->ns); + ret = PTR_ERR_OR_ZERO(ptr); + if (ret) + goto out; + ns_inode = ns_path.dentry->d_inode; + + info->ns_dev = new_encode_dev(ns_inode->i_sb->s_dev); + info->ns_inode = ns_inode->i_ino; + info->ifindex = offload->netdev->ifindex; +out: + rtnl_unlock(); + return ret; +} + const struct bpf_prog_ops bpf_offload_prog_ops = { }; diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 2c4cfeaa8d5e..101ee3a3e80e 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -1616,6 +1616,12 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, return -EFAULT; } + if (bpf_prog_is_dev_bound(prog->aux)) { + err = bpf_prog_offload_info_fill(&info, prog); + if (err) + return err; + } + done: if (copy_to_user(uinfo, &info, info_len) || put_user(info_len, &uattr->info.info_len)) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 4c223ab30293..3183674496a2 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -910,6 +910,11 @@ struct bpf_prog_info { __u32 nr_map_ids; __aligned_u64 map_ids; char name[BPF_OBJ_NAME_LEN]; + __u32 dev_bound:1; + __u32 reserved:31; + __u32 ifindex; + __u64 ns_dev; + __u64 ns_inode; } __attribute__((aligned(8))); struct bpf_map_info { -- 2.14.1 From 1585625571497038566@xxx Fri Dec 01 23:19:42 +0000 2017 X-GM-THRID: 1585625571497038566 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread