From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mail.toke.dk (Postfix) with ESMTPS id 56F0B982C49 for ; Tue, 28 Jun 2022 21:49:22 +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=W3EHOWey DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656445762; x=1687981762; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Br7PA2LhyRZLtGRuJC1NdDKYX7AsconXTD56haHkAIc=; b=W3EHOWeyD+wtgfIFO/6gFrM1UddEmGJLGs4LdVDQY4H3Z5X6z8IR1gqg Ekd2Z79vVFAqiu5YrQwoTRUO/gIr/R6John5d2/NgnOp20nlZLWcZZgn8 7nTtO2wjFU4AgTNyqF+LqhUD2FzWVjSxHFbINQoKFA0mUSVt++kOxSv6L HC+TvvsF0/PJ9kVpLmwDfXw54TI4bCRc5maFV8oHJQP7/9leRjFk91BJM wkIc0ULbNwVUPa+saV6BwKkF/sHYGmZnuWvNEor8VcPCGrhzhdRUCV+Be Z0fEOr+vpEVO6HTH5U+/EINMcE1dngpCE7NPzAzG3+Pw9Ju+3JkWCdEv4 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="343523220" X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="343523220" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 12:49:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="540598913" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga003.jf.intel.com with ESMTP; 28 Jun 2022 12:49:15 -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 25SJmr9F022013; Tue, 28 Jun 2022 20:49:14 +0100 From: Alexander Lobakin To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Date: Tue, 28 Jun 2022 21:47:35 +0200 Message-Id: <20220628194812.1453059-16-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: NT2YHZ5MEVSIJTANINRY7GQONE3AXVK5 X-Message-ID-Hash: NT2YHZ5MEVSIJTANINRY7GQONE3AXVK5 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 15/52] libbpf: add bpf_program__attach_xdp_opts() List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add a version of bpf_program__attach_xdp() which can take an optional pointer to &bpf_xdp_attach_opts to carry opts from it to bpf_link_create(), primarily to be able to specify a BTF/type ID and a metadata threshold when attaching an XDP program. This struct is originally designed for bpf_xdp_{at,de}tach(), reuse it here as well to not spawn entities (with ::old_prog_fd reused for XDP flags via union). Signed-off-by: Alexander Lobakin --- tools/lib/bpf/libbpf.c | 16 ++++++++++++++++ tools/lib/bpf/libbpf.h | 27 ++++++++++++++++++--------- tools/lib/bpf/libbpf.map | 1 + 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index f4014c09f1cf..b6cc238a2657 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -12010,6 +12010,22 @@ struct bpf_link *bpf_program__attach_xdp(const struct bpf_program *prog, int ifi return bpf_program__attach_fd(prog, ifindex, NULL, "xdp"); } +struct bpf_link * +bpf_program__attach_xdp_opts(const struct bpf_program *prog, int ifindex, + const struct bpf_xdp_attach_opts *opts) +{ + LIBBPF_OPTS(bpf_link_create_opts, lc_opts); + + if (!OPTS_VALID(opts, bpf_xdp_attach_opts)) + return libbpf_err_ptr(-EINVAL); + + lc_opts.flags = OPTS_GET(opts, flags, 0); + lc_opts.xdp.btf_id = OPTS_GET(opts, btf_id, 0); + lc_opts.xdp.meta_thresh = OPTS_GET(opts, meta_thresh, 0); + + return bpf_program__attach_fd(prog, ifindex, &lc_opts, "xdp"); +} + struct bpf_link *bpf_program__attach_freplace(const struct bpf_program *prog, int target_fd, const char *attach_func_name) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 99ac94f148fc..d6dd05b5b753 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -678,8 +678,26 @@ LIBBPF_API struct bpf_link * bpf_program__attach_cgroup(const struct bpf_program *prog, int cgroup_fd); LIBBPF_API struct bpf_link * bpf_program__attach_netns(const struct bpf_program *prog, int netns_fd); + +struct bpf_xdp_attach_opts { + size_t sz; + union { + int old_prog_fd; + /* for bpf_program__attach_xdp_opts() */ + __u32 flags; + }; + __u32 meta_thresh; + __u64 btf_id; + size_t :0; +}; +#define bpf_xdp_attach_opts__last_field btf_id + LIBBPF_API struct bpf_link * bpf_program__attach_xdp(const struct bpf_program *prog, int ifindex); +LIBBPF_API struct bpf_link * +bpf_program__attach_xdp_opts(const struct bpf_program *prog, int ifindex, + const struct bpf_xdp_attach_opts *opts); + LIBBPF_API struct bpf_link * bpf_program__attach_freplace(const struct bpf_program *prog, int target_fd, const char *attach_func_name); @@ -1210,15 +1228,6 @@ LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_xdp_query() instead") LIBBPF_API int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info, size_t info_size, __u32 flags); -struct bpf_xdp_attach_opts { - size_t sz; - int old_prog_fd; - __u32 meta_thresh; - __u64 btf_id; - size_t :0; -}; -#define bpf_xdp_attach_opts__last_field btf_id - struct bpf_xdp_query_opts { size_t sz; __u32 prog_id; /* output */ diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index f0987df15b7a..d14bbf82e37c 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -464,6 +464,7 @@ LIBBPF_1.0.0 { global: btf__add_enum64; btf__add_enum64_value; + bpf_program__attach_xdp_opts; libbpf_bpf_attach_type_str; libbpf_bpf_link_type_str; libbpf_bpf_map_type_str; -- 2.36.1