Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp139124rwb; Wed, 5 Oct 2022 16:08:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5WajyJ8voOct/E/SMa9u8RRbC8Aj3Mcz0+sVRMKDgDgWUrDNVOg316RifBGK35ogSh4vN8 X-Received: by 2002:a65:538e:0:b0:434:aa53:2244 with SMTP id x14-20020a65538e000000b00434aa532244mr1733421pgq.343.1665011297773; Wed, 05 Oct 2022 16:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665011297; cv=none; d=google.com; s=arc-20160816; b=iFMTkpUv8cTcPs/tiPEmfYyEcjPeVIDEwu4D5Ux/8AYKNIM78GgadefH54rP+w036p W5O+fQZJVs9AS4vNWUxXGFaKWAw4upU/fQGpnmfwVyld1tLPy6m/A8CZfuXAsoCZ6G/t lAjiXnixUB7YLHT4oEZ/yFHvk9GbE9BgBv9MZh+OMImNvd3yUWQbG7Uo4ifZ59ZvXhtH rQX7IkMreTtSWF9PG5aKsom9KA3dx+A87vdcsWqRMhGqZA1O5O0Y/g7Gep70oIt++4En JjcMVsBcBLgbbYBEHB3XAuFEZ5vzv4I2wGrMjos8m7sNIFuBaME1LvzK7NyOt6w0u/j/ jqaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=FmImwKatnMwbFulNzGw3sRM/1NjJtezQ9bl/fz9hQTc=; b=QDTNVLrPTU+8F2uS9e+clIq2XJ8FF0+2jrNcxAYiYfF4l4cyecrEMn5syNELjVMOUM CXjkSvEWQv1itCWd8sDBtf1rYoeAQhbf33KRAgCTb9IGz8cG3lkfjxlknsFb2b9mWpRy Bpu2hBzcHRfBIzbrqoBdYtv9GkbpMgIpCDk3BtFmF2w4u/dh75zCzw1uylx3OlZIfZCS qi6X2NDn48U3/n+Jd3xNQgtKNMdmISrD4qnXQCIz+vwLdy6IeXeCXrIePp/BYXwmrwKA GpDBOf5eYcsU68xjxcX3yb5CajW5KNwN1OWmh39m+1thbuWdzZ0BjitsOHR9foC/ZNm+ rKXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JefZ4Zlr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a63e90e000000b0041bfb11f138si17485094pgh.442.2022.10.05.16.08.05; Wed, 05 Oct 2022 16:08:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JefZ4Zlr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229689AbiJEXHD (ORCPT + 99 others); Wed, 5 Oct 2022 19:07:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbiJEXHA (ORCPT ); Wed, 5 Oct 2022 19:07:00 -0400 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A540857D7; Wed, 5 Oct 2022 16:06:57 -0700 (PDT) Received: by mail-yb1-xb2e.google.com with SMTP id b145so399897yba.0; Wed, 05 Oct 2022 16:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=FmImwKatnMwbFulNzGw3sRM/1NjJtezQ9bl/fz9hQTc=; b=JefZ4ZlrnfEPRiZxSl7bQ8/CvH5MuUBBTDrYGiueAVz7XyQrGQhtgC2vUBZ8viKzkz 700xK66FJwez1MSQq6JtWMTPEUjh+jwfW6NasVaztWFz/CgDRu3PVU23J3MEsgvq9N9O 9l8iGZrAks162LaJzfDxLJhgpmfcY+oNKsVKvBGaP49m6ehuzGMOZLE3LV1U4RQ2Yfmh NkTvlkdhL3JRwdefCi+JNx6I8rVIMQbj8Y0PdAi22sJUmCjBFfC9j9Xz28+Hjlvg4pll o10MMafSnLTYnh9wnDp6F2Wwooukz9rcZRUPAP/HWlDpoNVIgT6aiyAnhwc0r9GYXySl jQwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FmImwKatnMwbFulNzGw3sRM/1NjJtezQ9bl/fz9hQTc=; b=7dOIhMJMmhIg+8OB3TZeRGnfxJkYuVmZXVyRzb/L/tYbFqLLtunI3m+G6yxtsDTy7e n1eqojUaXIP7ffvINY1MJapIDLK6m1B43F6xLRbCup4qt8KQ5kKYSmAASD6IzNLFyPb/ mGW4zI6mde0vknFKTzw1SHEG+NBd11Vr/zLAPsTm/K9S46HFv2CgfdauG53xlbWkFpNA yeGbRtoznD+Y2NbAFyqyvwp14dCb1G5fXgbC8AwX1b9Ef9SPnc/cAKCjIHfHxN8gaZPw bsJHmtSWNnzG/4Rf9ajBwgh0636tlZeVGf0o5RHlEUCR9Zm3HosallFokqUM/bcnzpz3 Tw0w== X-Gm-Message-State: ACrzQf2RRO/IfAhvGyQMOPHDDNgKI/3Cbfea3D/EI0DOgBuIT+iXeUm3 1ZC2OMTyPtA1uAEwhXelw6d+8BsvrjZ7SIEaYss= X-Received: by 2002:a25:6d88:0:b0:6be:6dbd:c477 with SMTP id i130-20020a256d88000000b006be6dbdc477mr2140673ybc.385.1665011216127; Wed, 05 Oct 2022 16:06:56 -0700 (PDT) MIME-Version: 1.0 References: <20221004131750.2306251-1-roberto.sassu@huaweicloud.com> <20221004131750.2306251-5-roberto.sassu@huaweicloud.com> In-Reply-To: <20221004131750.2306251-5-roberto.sassu@huaweicloud.com> From: Andrii Nakryiko Date: Wed, 5 Oct 2022 16:06:43 -0700 Message-ID: Subject: Re: [RESEND][PATCH 4/6] libbpf: Introduce bpf_btf_get_fd_by_id_opts() To: Roberto Sassu Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Roberto Sassu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 4, 2022 at 6:18 AM Roberto Sassu wrote: > > From: Roberto Sassu > > Introduce bpf_btf_get_fd_by_id_opts(), for symmetry with > bpf_map_get_fd_by_id_opts(), to let the caller pass the newly introduced > data structure bpf_get_fd_opts. Keep the existing bpf_btf_get_fd_by_id(), > and call bpf_btf_get_fd_by_id_opts() with NULL as opts argument, to prevent > setting open_flags. > > Currently, the kernel does not support non-zero open_flags for > bpf_btf_get_fd_by_id_opts(), and a call with them will result in an error > returned by the bpf() system call. The caller should always pass zero > open_flags. > > Signed-off-by: Roberto Sassu > --- > tools/lib/bpf/bpf.c | 12 +++++++++++- > tools/lib/bpf/bpf.h | 2 ++ > tools/lib/bpf/libbpf.map | 1 + > 3 files changed, 14 insertions(+), 1 deletion(-) > > diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c > index 92464c2d1da7..f43e8c8afbd3 100644 > --- a/tools/lib/bpf/bpf.c > +++ b/tools/lib/bpf/bpf.c > @@ -980,19 +980,29 @@ int bpf_map_get_fd_by_id(__u32 id) > return bpf_map_get_fd_by_id_opts(id, NULL); > } > > -int bpf_btf_get_fd_by_id(__u32 id) > +int bpf_btf_get_fd_by_id_opts(__u32 id, > + const struct bpf_get_fd_opts *opts) > { > const size_t attr_sz = offsetofend(union bpf_attr, open_flags); > union bpf_attr attr; > int fd; > > + if (!OPTS_VALID(opts, bpf_get_fd_opts)) > + return libbpf_err(-EINVAL); > + > memset(&attr, 0, attr_sz); > attr.btf_id = id; > + attr.open_flags = OPTS_GET(opts, open_flags, 0); > > fd = sys_bpf_fd(BPF_BTF_GET_FD_BY_ID, &attr, attr_sz); > return libbpf_err_errno(fd); > } > > +int bpf_btf_get_fd_by_id(__u32 id) > +{ > + return bpf_btf_get_fd_by_id_opts(id, NULL); > +} > + > int bpf_link_get_fd_by_id(__u32 id) > { > const size_t attr_sz = offsetofend(union bpf_attr, open_flags); > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h > index 595d342fb7f9..559af0b84299 100644 > --- a/tools/lib/bpf/bpf.h > +++ b/tools/lib/bpf/bpf.h > @@ -379,6 +379,8 @@ LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id); > LIBBPF_API int bpf_map_get_fd_by_id_opts(__u32 id, > const struct bpf_get_fd_opts *opts); > LIBBPF_API int bpf_map_get_fd_by_id(__u32 id); > +LIBBPF_API int bpf_btf_get_fd_by_id_opts(__u32 id, > + const struct bpf_get_fd_opts *opts); It's subjective, but opts variants of APIs, being more "advanced" usually are listed after their simpler non-opts variants. Can you please add new _opts APIs after their non-opts variants? > LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id); > LIBBPF_API int bpf_link_get_fd_by_id(__u32 id); > LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len); > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map > index c3604eaa220d..7011d5eec67b 100644 > --- a/tools/lib/bpf/libbpf.map > +++ b/tools/lib/bpf/libbpf.map > @@ -371,6 +371,7 @@ LIBBPF_1.0.0 { > > LIBBPF_1.1.0 { > global: > + bpf_btf_get_fd_by_id_opts; > bpf_map_get_fd_by_id_opts; > bpf_prog_get_fd_by_id_opts; > user_ring_buffer__discard; > -- > 2.25.1 >