From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mail.toke.dk (Postfix) with ESMTPS id 1726A982C26 for ; Tue, 28 Jun 2022 21:49:18 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=PxPLx4Vg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656445759; x=1687981759; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yNkO5OonyawD491tq3UN3yp8qYpkGlKlrdxkHHQ0Dbc=; b=PxPLx4VgH3p8+zrawC8Xz3wRgwzHqOLYNpvNO4Irp0z8XWNCdn6oNL+n +SD3Mz5cuJbKLteMHL3pQLyxmuUOllaWY+QhJTcJXGnWlE8e4T73tXVrh 4+/vYbFHSOBJNmusN6c+7XL7BEr2PZsGBgDPdiAvH+uzozy/ODSlc5lAx Fgda7rU6Qdhzty+E1IF+fDRxDwSsyZg46ELe+Y+11H8BhIl/F8QEOZiaw WyvodAanaYOUos8Zb3XNtuMRUItgOkuhzfOg8+ZrBovGUYBCkmMf5SEc7 66sqk0U+D3p8nCDyDJlbwAKwR0T01JASQVHb6904c5BOoIXBTvH2vXupT A==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="279378892" X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="279378892" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 12:49:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="917306820" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by fmsmga005.fm.intel.com with ESMTP; 28 Jun 2022 12:49:13 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 25SJmr9D022013; Tue, 28 Jun 2022 20:49:11 +0100 From: Alexander Lobakin To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Date: Tue, 28 Jun 2022 21:47:33 +0200 Message-Id: <20220628194812.1453059-14-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628194812.1453059-1-alexandr.lobakin@intel.com> References: <20220628194812.1453059-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: SXD5CSNV5VC2I5PZA2P2JCBP7EY4NKYQ X-Message-ID-Hash: SXD5CSNV5VC2I5PZA2P2JCBP7EY4NKYQ X-MailFrom: alexandr.lobakin@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alexander Lobakin , Larysa Zaremba , Michal Swiatkowski , Jesper Dangaard Brouer , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , Toke Hoiland-Jorgensen , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesse Brandeburg , John Fastabend , Yajun Deng , Willem de Bruijn , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.5 Precedence: list Subject: [xdp-hints] [PATCH RFC bpf-next 13/52] libbpf: add ability to set the meta threshold on setting XDP prog List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Covered functions: * bpf_link_create() - via &bpf_link_create_ops; * bpf_link_update() - via &bpf_link_update_ops; * bpf_xdp_attach() - via &bpf_xdp_attach_ops; * bpf_set_link_xdp_fd_opts() - via &bpf_xdp_set_link_opts; No support for bpf_get_link_xdp_info()/&xdp_link_info as we store additional data in the kernel in BPF link mode only. Signed-off-by: Alexander Lobakin --- tools/lib/bpf/bpf.c | 3 +++ tools/lib/bpf/bpf.h | 8 +++++++- tools/lib/bpf/libbpf.h | 4 ++-- tools/lib/bpf/netlink.c | 10 ++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 6036dc75cc7b..e7c713a418f6 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -807,6 +807,9 @@ int bpf_link_create(int prog_fd, int target_fd, break; case BPF_XDP: attr.link_create.xdp.btf_id = OPTS_GET(opts, xdp.btf_id, 0); + attr.link_create.xdp.meta_thresh = OPTS_GET(opts, + xdp.meta_thresh, + 0); if (!OPTS_ZEROED(opts, xdp)) return libbpf_err(-EINVAL); break; diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 4e17995fdaff..c0f54f24d675 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -385,6 +385,8 @@ struct bpf_link_create_opts { struct { /* target metadata BTF + type ID */ __aligned_u64 btf_id; + /* frame size to start composing XDP metadata from */ + __u32 meta_thresh; } xdp; }; size_t :0; @@ -408,11 +410,15 @@ struct bpf_link_update_opts { struct { /* new target metadata BTF + type ID */ __aligned_u64 new_btf_id; + /* new frame size to start composing XDP + * metadata from + */ + __u32 new_meta_thresh; } xdp; }; size_t :0; }; -#define bpf_link_update_opts__last_field xdp.new_btf_id +#define bpf_link_update_opts__last_field xdp.new_meta_thresh LIBBPF_API int bpf_link_update(int link_fd, int new_prog_fd, const struct bpf_link_update_opts *opts); diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 4f77128ba770..99ac94f148fc 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -1193,7 +1193,7 @@ struct xdp_link_info { struct bpf_xdp_set_link_opts { size_t sz; int old_fd; - __u32 :32; + __u32 meta_thresh; __u64 btf_id; size_t :0; }; @@ -1213,7 +1213,7 @@ LIBBPF_API int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info, struct bpf_xdp_attach_opts { size_t sz; int old_prog_fd; - __u32 :32; + __u32 meta_thresh; __u64 btf_id; size_t :0; }; diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c index 104a809d5fb2..ac2a87243ecd 100644 --- a/tools/lib/bpf/netlink.c +++ b/tools/lib/bpf/netlink.c @@ -236,6 +236,7 @@ struct __bpf_set_link_xdp_fd_opts { int old_fd; __u32 flags; __u64 btf_id; + __u32 meta_thresh; }; static int @@ -276,6 +277,13 @@ __bpf_set_link_xdp_fd_replace(const struct __bpf_set_link_xdp_fd_opts *opts) if (ret < 0) return ret; } + if (opts->meta_thresh) { + ret = nlattr_add(&req, IFLA_XDP_META_THRESH, + &opts->meta_thresh, + sizeof(opts->meta_thresh)); + if (ret < 0) + return ret; + } nlattr_end_nested(&req, nla); return libbpf_netlink_send_recv(&req, NULL, NULL, NULL); @@ -300,6 +308,7 @@ int bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags, const struct bpf_xdp_a sl_opts.old_fd = -1; sl_opts.btf_id = OPTS_GET(opts, btf_id, 0); + sl_opts.meta_thresh = OPTS_GET(opts, meta_thresh, 0); err = __bpf_set_link_xdp_fd_replace(&sl_opts); return libbpf_err(err); @@ -330,6 +339,7 @@ int bpf_set_link_xdp_fd_opts(int ifindex, int fd, __u32 flags, } sl_opts.btf_id = OPTS_GET(opts, btf_id, 0); + sl_opts.meta_thresh = OPTS_GET(opts, meta_thresh, 0); ret = __bpf_set_link_xdp_fd_replace(&sl_opts); return libbpf_err(ret); -- 2.36.1