Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3817535imw; Mon, 18 Jul 2022 15:14:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1urObUwGpS0ey9cMe06ULCzAuYGWMp2YfVX+NX27RbEdQK5l5QPu21TnwvZ7yupIo6pSJQf X-Received: by 2002:a05:6402:5299:b0:435:61da:9bb9 with SMTP id en25-20020a056402529900b0043561da9bb9mr40255164edb.21.1658182478526; Mon, 18 Jul 2022 15:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658182478; cv=none; d=google.com; s=arc-20160816; b=V0lgxNj4Pni+34zaVoee/xI7/qauaRI5jGNnbcDhnWuMIePQ7jujRsmGeNf8OKjEVT veIsDEPz2gpUvD5w3xOTxI8GuEtHgldV5dG5PkIcT7ZI1BMjjgvyUdSUGxC9A9SFnjuB 7w7z05w3bpPJkFcv4FuQ7ZTO/acsmfGWxWtYLrTrXNC9LHlYLAm4xFcTUIRR7/XXUlUK SijUqkAPSYM5vL9PIRqUCbpF9mlZzpqenpXPJtxcm2BiIvJNOAN1YywzD7MmaRvaoc2F iZB6MeOuGoQtPN/EpMoS85RNCdiv0U2pIpuhw4O5MyOUuQOZgG9wejUHXlODHmu9MnqH nP8Q== 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=u27wz2PCMuVYYB7HICVQ28Lin1veQrrJpBv68Mte6sw=; b=suOGrSrRBAvvAmdXWQsXkuTmuY1NLKsqPeW2oSsYCA0sHx4pElYGhGhx0jZvIQm7lS Gv95rU2h2go0kmgcJRjixiWTTfkqdMOBLb5zln9ILHdXz4Zci4XR2Kj8l8nt9YCJnI+K f5GB3nuc+MgJ2676mJRdEpy+62+KlVYXyrNxW11bMj5qveiVKvxAiEQ4RRAfBr1IJD/E D/98tt6flY4zJjhwoPmYylyGAG3sctxmG31RXLScXv/MX5qBRIuQx+HFL+900CGdaLFT FK1SLOdhzmLJ8luqwMCO4pvL0hAq8f7WdOvRh7/yeeXuyDixh/jLYw2/Z2J3i6gUNWzB Srlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="pAHT/4wQ"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gr19-20020a170906e2d300b0072b4dc6ba6bsi15784994ejb.659.2022.07.18.15.14.13; Mon, 18 Jul 2022 15:14:38 -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=@google.com header.s=20210112 header.b="pAHT/4wQ"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236333AbiGRVuk (ORCPT + 99 others); Mon, 18 Jul 2022 17:50:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234131AbiGRVuj (ORCPT ); Mon, 18 Jul 2022 17:50:39 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BADE628E3E for ; Mon, 18 Jul 2022 14:50:37 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id y9so11831690pff.12 for ; Mon, 18 Jul 2022 14:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=u27wz2PCMuVYYB7HICVQ28Lin1veQrrJpBv68Mte6sw=; b=pAHT/4wQsN1037mdKqH7SN5eIImP9H7JRUFzZk0usOzy7EyhEqSdAq3FdYP0CKGk9O PzZZI1eqUkRw98kEjDWtZ8PlnBGXc0uAMeOjt9RwhyFdXXPWHI6SrKjLlY8F1/UZAj73 BIC3PJzt5KgRRffqUio2MipR4fON7lsjaV3Z+/J6x73skVJo76PnF3KRsm881BwVrVuC lgWUNIoq++vT+vpzMiIIGnq4zme7LRjKEYtPXh2n2BSI2DlSeSurJobLpmKmmvjGIP09 opxEkY5g+9TucHWoKYqC2JwmiDlcvSbUHWtXtHTMMwdTIfd97DV2bXA3YzV4Num8Wc7h p0qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=u27wz2PCMuVYYB7HICVQ28Lin1veQrrJpBv68Mte6sw=; b=HVtl8s0BZN0U/rzQt1JN+K20o9XHcGYgAT1CUDdOAITzlniwdvlbmZPsSjLaiFNwtC zkxEhSQdv5lnd44LMhFQk5TWIs+XwDvuu+wsD8dkjBbe8gbJlIGPcCw2xkFWOR4SJGu4 otG2BztgMGXQ/zq3pmzqlth6kkQYc74mLB0Sn3ji8xczVxmo/7MjmHtd6DJdAM41LYtO kusISHhnLTVghi6jJ6Aq9iUfBS/MBJRO+xTB2uQ0UqQUGodTxTRQLl9lZCtS63dS1DFk J32cLT6HDekQsMg/j1fR0nPrSjLMlqVy2VkEI2DLt0I8zzWixOgUNW/oBAiZ5muL5gW7 NMWA== X-Gm-Message-State: AJIora9TWrOSbae61iVT7rHtTS67IKmNWMfUCT6RQG1hZUplpg7Vt/jQ Eige2AcmbUBH50VMa6d630+j6awn+yB1PBMV9n1krQ== X-Received: by 2002:a63:85c6:0:b0:412:a94c:16d0 with SMTP id u189-20020a6385c6000000b00412a94c16d0mr26759268pgd.253.1658181037079; Mon, 18 Jul 2022 14:50:37 -0700 (PDT) MIME-Version: 1.0 References: <20220718214633.3951533-1-jevburton.kernel@gmail.com> In-Reply-To: <20220718214633.3951533-1-jevburton.kernel@gmail.com> From: Stanislav Fomichev Date: Mon, 18 Jul 2022 14:50:26 -0700 Message-ID: Subject: Re: [PATCH] [PATCH bpf-next] libbpf: Add bpf_obj_get_opts() To: Joe Burton Cc: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Joe Burton Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Mon, Jul 18, 2022 at 2:46 PM Joe Burton wrote: > > From: Joe Burton > > Add an extensible variant of bpf_obj_get() capable of setting the > `file_flags` parameter. > > This parameter is needed to enable unprivileged access to BPF maps. > Without a method like this, users must manually make the syscall. > > Signed-off-by: Joe Burton > --- > tools/lib/bpf/bpf.c | 10 ++++++++++ > tools/lib/bpf/bpf.h | 9 +++++++++ Needs a libbpf.map change as well? > 2 files changed, 19 insertions(+) > > diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c > index 5eb0df90eb2b..5acb0e8bd13c 100644 > --- a/tools/lib/bpf/bpf.c > +++ b/tools/lib/bpf/bpf.c > @@ -578,12 +578,22 @@ int bpf_obj_pin(int fd, const char *pathname) > } > > int bpf_obj_get(const char *pathname) > +{ > + LIBBPF_OPTS(bpf_obj_get_opts, opts); > + return bpf_obj_get_opts(pathname, &opts); > +} > + > +int bpf_obj_get_opts(const char *pathname, const struct bpf_obj_get_opts *opts) > { > union bpf_attr attr; > int fd; > > + if (!OPTS_VALID(opts, bpf_obj_get_opts)) > + return libbpf_err(-EINVAL); > + > memset(&attr, 0, sizeof(attr)); > attr.pathname = ptr_to_u64((void *)pathname); > + attr.file_flags = OPTS_GET(opts, file_flags, 0); > > fd = sys_bpf_fd(BPF_OBJ_GET, &attr, sizeof(attr)); > return libbpf_err_errno(fd); > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h > index 88a7cc4bd76f..f31b493b5f9a 100644 > --- a/tools/lib/bpf/bpf.h > +++ b/tools/lib/bpf/bpf.h > @@ -270,8 +270,17 @@ LIBBPF_API int bpf_map_update_batch(int fd, const void *keys, const void *values > __u32 *count, > const struct bpf_map_batch_opts *opts); > > +struct bpf_obj_get_opts { > + size_t sz; /* size of this struct for forward/backward compatibility */ > + > + __u32 file_flags; > +}; > +#define bpf_obj_get_opts__last_field file_flags > + > LIBBPF_API int bpf_obj_pin(int fd, const char *pathname); > LIBBPF_API int bpf_obj_get(const char *pathname); > +LIBBPF_API int bpf_obj_get_opts(const char *pathname, > + const struct bpf_obj_get_opts *opts); > > struct bpf_prog_attach_opts { > size_t sz; /* size of this struct for forward/backward compatibility */ > -- > 2.37.0.170.g444d1eabd0-goog >