From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C102B1C769 for ; Wed, 21 Jun 2023 23:41:10 +0000 (UTC) Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15682172C for ; Wed, 21 Jun 2023 16:41:09 -0700 (PDT) Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35LJcQhO032367 for ; Wed, 21 Jun 2023 16:41:08 -0700 Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3rbwks6cv3-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 21 Jun 2023 16:41:08 -0700 Received: from twshared24695.38.frc1.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 21 Jun 2023 16:41:07 -0700 Received: by devbig019.vll3.facebook.com (Postfix, from userid 137359) id 241AB333E8896; Wed, 21 Jun 2023 16:38:19 -0700 (PDT) From: Andrii Nakryiko To: CC: , , , , , , , Subject: [PATCH v3 bpf-next 05/14] libbpf: add BPF token support to bpf_map_create() API Date: Wed, 21 Jun 2023 16:38:00 -0700 Message-ID: <20230621233809.1941811-6-andrii@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621233809.1941811-1-andrii@kernel.org> References: <20230621233809.1941811-1-andrii@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: WEY8yg8s_rEsbH_gYOBjskha-8NYV5xT X-Proofpoint-ORIG-GUID: WEY8yg8s_rEsbH_gYOBjskha-8NYV5xT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-21_13,2023-06-16_01,2023-05-22_02 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Add ability to provide token_fd for BPF_MAP_CREATE command through bpf_map_create() API. Also wire through token_create.allowed_map_types param for BPF_TOKEN_CREATE command. Signed-off-by: Andrii Nakryiko --- tools/lib/bpf/bpf.c | 5 ++++- tools/lib/bpf/bpf.h | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index a247a1612f29..882297b1e136 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -169,7 +169,7 @@ int bpf_map_create(enum bpf_map_type map_type, __u32 max_entries, const struct bpf_map_create_opts *opts) { - const size_t attr_sz =3D offsetofend(union bpf_attr, map_extra); + const size_t attr_sz =3D offsetofend(union bpf_attr, map_token_fd); union bpf_attr attr; int fd; =20 @@ -198,6 +198,8 @@ int bpf_map_create(enum bpf_map_type map_type, attr.numa_node =3D OPTS_GET(opts, numa_node, 0); attr.map_ifindex =3D OPTS_GET(opts, map_ifindex, 0); =20 + attr.map_token_fd =3D OPTS_GET(opts, token_fd, 0); + fd =3D sys_bpf_fd(BPF_MAP_CREATE, &attr, attr_sz); return libbpf_err_errno(fd); } @@ -1218,6 +1220,7 @@ int bpf_token_create(int pin_path_fd, const char *p= in_pathname, struct bpf_token attr.token_create.token_flags =3D OPTS_GET(opts, token_flags, 0); attr.token_create.pin_flags =3D OPTS_GET(opts, pin_flags, 0); attr.token_create.allowed_cmds =3D OPTS_GET(opts, allowed_cmds, 0); + attr.token_create.allowed_map_types =3D OPTS_GET(opts, allowed_map_type= s, 0); =20 ret =3D sys_bpf(BPF_TOKEN_CREATE, &attr, attr_sz); return libbpf_err_errno(ret); diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index ab0355d90a2c..cd3fb5ce6fe2 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -51,8 +51,10 @@ struct bpf_map_create_opts { =20 __u32 numa_node; __u32 map_ifindex; + + __u32 token_fd; }; -#define bpf_map_create_opts__last_field map_ifindex +#define bpf_map_create_opts__last_field token_fd =20 LIBBPF_API int bpf_map_create(enum bpf_map_type map_type, const char *map_name, @@ -557,9 +559,10 @@ struct bpf_token_create_opts { __u32 token_flags; __u32 pin_flags; __u64 allowed_cmds; + __u64 allowed_map_types; size_t :0; }; -#define bpf_token_create_opts__last_field allowed_cmds +#define bpf_token_create_opts__last_field allowed_map_types =20 /** * @brief **bpf_token_create()** creates a new instance of BPF token, pi= nning --=20 2.34.1