Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp90471iof; Sun, 5 Jun 2022 22:04:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwj5hs73VC+6igTbaatg0mcyJNEYcCQeQsh6wf/9Xgl8x97WYpqmG+bFcc17uOOa2Q97HvR X-Received: by 2002:a17:902:b703:b0:15e:ea16:2c6e with SMTP id d3-20020a170902b70300b0015eea162c6emr22412900pls.100.1654491842365; Sun, 05 Jun 2022 22:04:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654491842; cv=none; d=google.com; s=arc-20160816; b=NDTy/SylIadGrPmMbv2AwNxrZSrO7KyGlBAtRuw/3h8EZ/DwQH4RF6khhntPi8osk2 h1g4dgdBu/2RHKC62zFvZAMD3twzP5r91r3O33UfuudPfULyuhoVGZ1R9sqJ5ovPl8xX jKc7VPlcKDaY3N8z4ecobnTgvKVMQrBrpXJY3za9K4Sdy485JSJAC2eH3XqI5u46hcfs lJaGTkpSwYbR1807rdwFaLK53CgiFZAMNzTUyGt9Skz+PqhY0EogT9DQwkXMAtNoHXZS IBSEUHVeJn2za9Z5DydT1+JokUkLO7J2LUOtK2V9eE7lcXiYGTYUJrCP3405/bsjBTrl wWYg== 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=VG18wTnR8sVhdBQaPjEWxn+wEw8AOfc4wd3Cmh+GZuM=; b=sFmPJ8sLCaLVKheQGut6E0nNlWIV8vpJeU9q4dTQwVq1sIOS+xpoBmHA34LBMT9Mfs mThq5CLHO6deWu+8JMGttyG/pPbLkyrcgO5CpT8lJUNOdrFQMwvx+ExdSXYC8HYbSVVP 9Fx8WxnVQvxtU8PlqILcixBqPV4Vy0ozZTDaoz6b1i0+bJbN2Gu6dZL9++gZCKVU8UJV cVVyD/gnwjRK4gYZlIFxyuHEkuG8105e5hgUHshuXBmnEo2zXQEDMUmRAAt1nFHWROHP rljxXKZeAXTXKIe7Kz/9dcCKXWzMQsHV5Fi0SY/WyYcx9hhmtep++6cuaToqew9jte7A ZS0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FFU1mT2F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id pb2-20020a17090b3c0200b001d28b845edcsi19203031pjb.59.2022.06.05.22.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:04:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FFU1mT2F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F377D11044B; Sun, 5 Jun 2022 21:12:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349384AbiFCU7T (ORCPT + 99 others); Fri, 3 Jun 2022 16:59:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343709AbiFCU7Q (ORCPT ); Fri, 3 Jun 2022 16:59:16 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A3BE3525A; Fri, 3 Jun 2022 13:59:15 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id m25so6344005lji.11; Fri, 03 Jun 2022 13:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VG18wTnR8sVhdBQaPjEWxn+wEw8AOfc4wd3Cmh+GZuM=; b=FFU1mT2FIn9Dusqyo01GRwvphdcK00uhcFOyVS9PmC9Tm/49InMSdgsB9GA5i9ABep talMa2tAb5zxit99YUg0J0eBIrkJPyZA8KrKdcJBx55+kWybEGi3b8boKUstTrGW7034 wcDnZ0BuvGa8agdEcsuVmKveULmzX7PtaGRgZGtfHoLmTT5hQBI8ho210OZCjHKiYL11 nLc71suBzFFE7xcODufzYerMaNdmkjtgDJ5siQyhR2fc6rbrWcZk4oSYd9NBPIEUcQ3t 89+Yf8R7DGSRcIP6kd5r0mlFm4b76klqRZPMGRtymmNVy3vS2gZVoZkX7yjtHOhI4q0S KplQ== 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=VG18wTnR8sVhdBQaPjEWxn+wEw8AOfc4wd3Cmh+GZuM=; b=myF4XNNBdHsJ0GtlA+dRK4ypasr4LQ9titQZMHOYTLb1kppJNJfzddqx6GNGhsmdk+ BxDYc09m5ywkIe/m1l+LDYPNUSJLG5pO+sAOwobPKM65L4SRq9yXCGrG/e1hho+JPyeg FqWU3kjXIzftca2+qwEQk9ntk2QKeUyAGrnZQBNE+ydkd9FBmYcxX6MqWdz3rT2kmsTw EotVn3t8vFKbY0hBql5YGV7Ic397UO5MmydcKhOBJ1v+JG/oPc0jMmv0c81h27GmRejw eP7ZW103P9KMc2j7bCxJai+mUY1JB4EL6NiZyLbr3bPcGn2D3UoQNlpVtaXqVjvBkRdY n6dQ== X-Gm-Message-State: AOAM533nwQVDepxVVgVc5VhMvbbP9Sk5ev4cczmQqiPZBVHr22sJNxDK T89CoBxL8IlcTlI7EtuIbdCaelcP1l4Nb534oo/UqQTD X-Received: by 2002:a2e:bd13:0:b0:246:1ff8:6da1 with SMTP id n19-20020a2ebd13000000b002461ff86da1mr44955810ljq.219.1654289953352; Fri, 03 Jun 2022 13:59:13 -0700 (PDT) MIME-Version: 1.0 References: <20220602143748.673971-1-roberto.sassu@huawei.com> <20220602143748.673971-3-roberto.sassu@huawei.com> In-Reply-To: <20220602143748.673971-3-roberto.sassu@huawei.com> From: Andrii Nakryiko Date: Fri, 3 Jun 2022 13:59:02 -0700 Message-ID: Subject: Re: [PATCH v2 2/9] libbpf: Introduce bpf_obj_get_flags() To: Roberto Sassu Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , KP Singh , bpf , Networking , "open list:KERNEL SELFTEST FRAMEWORK" , open list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Thu, Jun 2, 2022 at 7:38 AM Roberto Sassu wrote: > > Introduce the bpf_obj_get_flags() function, so that it is possible to > specify the needed permissions for obtaining a file descriptor from a > pinned object. > > Signed-off-by: Roberto Sassu > --- > tools/lib/bpf/bpf.c | 8 +++++++- > tools/lib/bpf/bpf.h | 1 + > tools/lib/bpf/libbpf.map | 1 + > 3 files changed, 9 insertions(+), 1 deletion(-) > > diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c > index 33bac2006043..a5fc40f6ce13 100644 > --- a/tools/lib/bpf/bpf.c > +++ b/tools/lib/bpf/bpf.c > @@ -670,18 +670,24 @@ int bpf_obj_pin(int fd, const char *pathname) > return libbpf_err_errno(ret); > } > > -int bpf_obj_get(const char *pathname) > +int bpf_obj_get_flags(const char *pathname, __u32 flags) same note about bpf_obj_get_opts() instead > { > union bpf_attr attr; > int fd; > > memset(&attr, 0, sizeof(attr)); > attr.pathname = ptr_to_u64((void *)pathname); > + attr.file_flags = flags; > > fd = sys_bpf_fd(BPF_OBJ_GET, &attr, sizeof(attr)); > return libbpf_err_errno(fd); > } > > +int bpf_obj_get(const char *pathname) > +{ > + return bpf_obj_get_flags(pathname, 0); > +} > + > int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type, > unsigned int flags) > { > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h > index 20e4c852362d..6d0ceb2e90c4 100644 > --- a/tools/lib/bpf/bpf.h > +++ b/tools/lib/bpf/bpf.h > @@ -339,6 +339,7 @@ LIBBPF_API int bpf_map_update_batch(int fd, const void *keys, const void *values > const struct bpf_map_batch_opts *opts); > > LIBBPF_API int bpf_obj_pin(int fd, const char *pathname); > +LIBBPF_API int bpf_obj_get_flags(const char *pathname, __u32 flags); > LIBBPF_API int bpf_obj_get(const char *pathname); > > struct bpf_prog_attach_opts { > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map > index 019278e66836..6c3ace12b27b 100644 > --- a/tools/lib/bpf/libbpf.map > +++ b/tools/lib/bpf/libbpf.map > @@ -467,6 +467,7 @@ LIBBPF_1.0.0 { > libbpf_bpf_map_type_str; > libbpf_bpf_prog_type_str; > bpf_map_get_fd_by_id_flags; > + bpf_obj_get_flags; > > local: *; > }; > -- > 2.25.1 >