Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5618294imw; Wed, 20 Jul 2022 09:03:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vYohQL9Qb+xlVUbx4EX0v/Y7iCz0K9ST3INoKfVcTFGDSmsHwO2kdu9/FdMm7JUop5aAP/ X-Received: by 2002:a65:4ccc:0:b0:41a:69b2:2b18 with SMTP id n12-20020a654ccc000000b0041a69b22b18mr2567243pgt.215.1658333039059; Wed, 20 Jul 2022 09:03:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658333039; cv=none; d=google.com; s=arc-20160816; b=yrV7YFu77ff1v7r8NSIjZXtGNdzXSYSHXfKWAhR06wGrErK+DWwTDL9HkxPtu3A2G/ nMXUkVy2q3dYxqyvgPPzhWHVm32RjmXVHfV00vir1dpzSPa+BdClsVde7KL46pbl0GiP h6IWogs5mRPQOqCEv7FLkBQ/Ye0LVuMhaIQIJWuFsHwb6d3ePrCCIoZPoz6iYx9WF9qW CPf16fnZBJ9Aicqah+UZhUCWIwIOTvi/UUA+upd7aALaHRuxrZJS3QB6qH5fRNC6M+sO +Wg7KUxts1mNCLWHtkW+BP7uUpssIIA5l8LWBoQz1cbL9yIRcZaRIK7o8+qnPztbKfqQ hMLQ== 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=ce/0l8zZFSWxrvXqTD1rFm6VFoYD2QFsbPDkuHHkwaY=; b=XWjzxV9bTSCk2U+mOixWMiHv4NmVxHkEBNffmoE9xHrdI/pFJkgc73rqwhpL7rUgSJ TvJ1ZM0h7Ek4DPONjxAYcnWyoD4hjyanwp9yNQD1CSLKXTcTg5JEJubV0BrgDeD6+apo TCpHhZrN/mA0/B3dk/EHS9f57CzR/CdtFSUJtUZyt+fYyxI6YLQ3uMg9q34o4Bvj6a6p d6jvEb2QtJovI/aFsInUsiyzq15jL2Q825737eJdF3E7wx9ksLV5RfhuQ11aQSvtbuuG sNOGIy1mbcm1TiLU+ZtJWTPwR+ykFE3okd1lILWocNu6DH+Sc1f+8wyatB9+Q4nTO6eq yIUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RoKxGblm; 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 t7-20020a170902e84700b0016a52b34991si2152578plg.113.2022.07.20.09.03.41; Wed, 20 Jul 2022 09:03:59 -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=RoKxGblm; 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 S234566AbiGTP5M (ORCPT + 99 others); Wed, 20 Jul 2022 11:57:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbiGTP5K (ORCPT ); Wed, 20 Jul 2022 11:57:10 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD9154AD76 for ; Wed, 20 Jul 2022 08:57:09 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id g4so16792089pgc.1 for ; Wed, 20 Jul 2022 08:57:09 -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=ce/0l8zZFSWxrvXqTD1rFm6VFoYD2QFsbPDkuHHkwaY=; b=RoKxGblmnegdrP1c0em3AoK5G4jeKtLnt4i2jnxOgsuI+WbC12ClEOCv9Ip327DSg7 u7OnrzBCQmTAwD+iIRo4E0bBUAtsQwk/sSFIcHyfCPfi4m6TuSAM0WjJ+8aBs9oEx8DK DD3Cu1D+VkUuCfBitqFMXA33WbLqlm+RNcifcOjjqb4S6n9UvPsvHWxolZCqjcMHq3KW 4x3ZPxHAb5LAAy7nyabAsOBA78W5D+RxyePrw8YyXj9FhxpOkkpCWKP26QFKzl4f7bYl /oxLuZtpYcd4TB0ACz9ww0YZgW93ZjrcR4e4Imq/iHY5wC+wQ+Hbckqw7+BV/+LCQ5jV /3kQ== 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=ce/0l8zZFSWxrvXqTD1rFm6VFoYD2QFsbPDkuHHkwaY=; b=dni3OoINUUpBiY1C2glNkCQyyJmalFfMTgth6ATCThhXmFdStnEFeRufUdi2SiSt6G k4j/Y03c9mNO/KSKN47cauCgYW4gW92557Y3O9/BYN0tQw74WhoL5+11V7YeRakNBIUp YByZPP7mR3ZAH13M69AquqQgLIMRYBGJtbS10B+g9a/V+uZgAMGZKeHiljDCaUjG7c9m Myvn9r5TYRCQ6tyhSx8UmKty8Ebtv9nnyVY3qIl39L+t7Nswk6grjgFywoGv9pipkckF 8mXtTE4wDKkN4doYHUMFfxWFIoKMtf8sf+QzmRj5Hk2g32H6xfz0B+eB7T1hcQHILcGY 9T3w== X-Gm-Message-State: AJIora/vc28xcCjkqqzMyl/l69w5AH+1AkGE2/l3ULue1QmCp0iN5mHM hb9FCYNI0sqgOdtKu3SrzJsl/S6YTBRvXCjtJGnsfg== X-Received: by 2002:a65:4c0b:0:b0:415:d3a4:44d1 with SMTP id u11-20020a654c0b000000b00415d3a444d1mr34871068pgq.191.1658332629110; Wed, 20 Jul 2022 08:57:09 -0700 (PDT) MIME-Version: 1.0 References: <20220719194028.4180569-1-jevburton.kernel@gmail.com> <179cfb89be0e4f928a55d049fe62aa9e@huawei.com> In-Reply-To: <179cfb89be0e4f928a55d049fe62aa9e@huawei.com> From: Stanislav Fomichev Date: Wed, 20 Jul 2022 08:56:58 -0700 Message-ID: Subject: Re: [PATCH v2 bpf-next] libbpf: Add bpf_obj_get_opts() To: Roberto Sassu Cc: Joe Burton , 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 Wed, Jul 20, 2022 at 1:02 AM Roberto Sassu wrote: > > > From: Stanislav Fomichev [mailto:sdf@google.com] > > Sent: Tuesday, July 19, 2022 10:40 PM > > On Tue, Jul 19, 2022 at 12:40 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 > > > > Reviewed-by: Stanislav Fomichev > > > > For context: > > We've found this out while we were trying to add support for unpriv > > processes to open pinned r-x maps. > > Maybe this deserves a test as well? Not sure. > > Hi Stanislav, Joe > > I noticed now this patch. I'm doing a broader work to add opts > to bpf_*_get_fd_by_id(). I also adjusted permissions of bpftool > depending on the operation type (e.g. show, dump: BPF_F_RDONLY). > > Will send it soon (I'm trying to solve an issue with the CI, where > libbfd is not available in the VM doing actual tests). Is something like this patch included in your series as well? Can you use this new interface or do you need something different? > Roberto > > > > --- > > > tools/lib/bpf/bpf.c | 10 ++++++++++ > > > tools/lib/bpf/bpf.h | 9 +++++++++ > > > tools/lib/bpf/libbpf.map | 1 + > > > 3 files changed, 20 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 */ > > > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map > > > index 0625adb9e888..119e6e1ea7f1 100644 > > > --- a/tools/lib/bpf/libbpf.map > > > +++ b/tools/lib/bpf/libbpf.map > > > @@ -355,6 +355,7 @@ LIBBPF_0.8.0 { > > > > > > LIBBPF_1.0.0 { > > > global: > > > + bpf_obj_get_opts; > > > bpf_prog_query_opts; > > > bpf_program__attach_ksyscall; > > > btf__add_enum64; > > > -- > > > 2.37.0.170.g444d1eabd0-goog > > >