Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp116303iof; Sun, 5 Jun 2022 22:51:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy74hmZ+C78T+E4M5ZmZrTMBUADLsSToho1aqYnqO0aZCco4A/8lw6dWpaSZ+/NtD0SlZKu X-Received: by 2002:a17:902:da8e:b0:164:537:d910 with SMTP id j14-20020a170902da8e00b001640537d910mr22506153plx.75.1654494714670; Sun, 05 Jun 2022 22:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654494714; cv=none; d=google.com; s=arc-20160816; b=SBLua2OgbaD8vzkjHVWFsaIQCg9FAgzKeGvhLgLHhPWvxAMrh2xZhHH7/gYsuWmUyE 5FctQlqh0ZryVfcn3cJviYg8HUkMFqH5gQ+efNe4ZCnqQJfIi68hXRMGVWZ5c4M7KYck YINEOKZ2yd31J19hvbIkwOvhKdGH8PbAOsy+4nqh1Zt0BNb0T8bdG6O2m1cJK3yCD/JR /Oal4kMQ8sq14/ScCW30sBsHt40dqmAqXGfddBvioW/FzE2ODYgu6H2OIqpfwFr6vkfg 5B8UEdFjh7GR5Qergk1NfylTJk9ctrgn4BpDq9GCIX15Y3q7VU9Dd5ZTI345PQV3rDTd Qoyw== 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=IX+iMCliQnk5qmBtapwSE0VVJPm4P2CWRKK142TwuuI=; b=qZyKo4UqwvwGgz9sVU58D1WOq3B9kk3po0umkDw0SccsQlV5qZHjfD4xH+AJ+hn/uy UmJn9byjhurRsbBhbz5R2ayzLHXsAQEw6XSbGNV7uHg1xwZwN0SNXvugpTHaMtGM/Hyu 6IDeYx9dIEdxgNTTDyL3AQgWcNpYGVDtbs3LJxyQrdC7t5PD/6ZSq0gK1Vf0pHywoF3D 3euRgeJkx6SGjE05Eb6i5ER8O96U3I2gGq5ucyW/MZ3LssdGQbjtdc30yKwgoyr8njcu 8hg/Jss+W2/3/fzGUNXRqTkMdaQQPFcRs57ye6pw/AqfULk3cpZSQqGKKkBFdoTilaIe acoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=eN1y0OM8; 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 pl5-20020a17090b268500b001e299f85017si20488703pjb.63.2022.06.05.22.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:51:54 -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=eN1y0OM8; 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 E35FE2A25EC; Sun, 5 Jun 2022 21:40:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348777AbiFCU7N (ORCPT + 99 others); Fri, 3 Jun 2022 16:59:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347000AbiFCU7M (ORCPT ); Fri, 3 Jun 2022 16:59:12 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AE1531DC9; Fri, 3 Jun 2022 13:59:11 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id a2so8301810lfg.5; Fri, 03 Jun 2022 13:59:11 -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=IX+iMCliQnk5qmBtapwSE0VVJPm4P2CWRKK142TwuuI=; b=eN1y0OM89VHdmi/uPaz3CRJNkv1PEwRSxCtqtavf3GHv6A3EsBrl6WSSdVeq++yX54 uCRPx7UxgsIsaERNw3rZhalMvLsiXapql5pflslT78MxFWr7NGQUm/u3IJDXROf9K49x O5b4cYOh1Sd8a7xg1g7SGnZfwaLIkMrgMiHfy82fVUZB8zJJheQJHcvSe+Dr6g5E4hc7 rnMW88w5Q42AF8RBFQwSbHm1hm50dqoL8TWtAiboe73q1z2Bgc7XI1s6gRTNsFBlYyBE QFR1A1MRINjA/V0N/NkdWy2mv/nBo1NkrTGu36ONz0czMPzt1bV6Thg5zNpi7e0lOw34 yyVA== 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=IX+iMCliQnk5qmBtapwSE0VVJPm4P2CWRKK142TwuuI=; b=sf/DUdxdL2dmRq+6ik+CTZI1xIPwEcec+7058x8md3iOQO/jEpMXC8OvDWDpGtajas 2OhJFHyFIqXZT70RSfiRZOU4Sz+RdIHLouJLnRXY2JmNunTpJbIzZLV5IV4LUgcTsi5n IQsrFvfPYeLtqzeqW6/tI5bGR4WVqNxXmUaylH2mJKm/+PUlyoygwPHNEdWYxpGnhEIs nxohjjZhyl97Lv+og8u/kFVs5CCdikbo4YyW9ysl/4kHPJ1R/DsHtKXceLI/yPyKS54w 1QJOCj+burUB1COfUZVxLGASmwsLWCPChd+IhyhVc8zgKNa4WKXSZuDx7dP1qE3WGycB mtBg== X-Gm-Message-State: AOAM533d9mmBeWEVXyo/UNOD6Je4fkfGBeIxyCf2hTevT+3zoWAIszIb 06GA9NjVWu1t7QZRN6EBpTq49u5USyuSakrMg5Q= X-Received: by 2002:ac2:4e88:0:b0:477:c186:6e83 with SMTP id o8-20020ac24e88000000b00477c1866e83mr53530043lfr.663.1654289949710; Fri, 03 Jun 2022 13:59:09 -0700 (PDT) MIME-Version: 1.0 References: <20220602143748.673971-1-roberto.sassu@huawei.com> <20220602143748.673971-2-roberto.sassu@huawei.com> In-Reply-To: <20220602143748.673971-2-roberto.sassu@huawei.com> From: Andrii Nakryiko Date: Fri, 3 Jun 2022 13:58:58 -0700 Message-ID: Subject: Re: [PATCH v2 1/9] libbpf: Introduce bpf_map_get_fd_by_id_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 bpf_map_get_fd_by_id_flags(), to let a caller specify the open > flags needed for the operation. This could make an operation succeed, if > access to a map is restricted (i.e. it allows only certain operations). > > 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 240186aac8e6..33bac2006043 100644 > --- a/tools/lib/bpf/bpf.c > +++ b/tools/lib/bpf/bpf.c > @@ -1047,18 +1047,24 @@ int bpf_prog_get_fd_by_id(__u32 id) > return libbpf_err_errno(fd); > } > > -int bpf_map_get_fd_by_id(__u32 id) > +int bpf_map_get_fd_by_id_flags(__u32 id, __u32 flags) let's go the OPTS route instead so that we don't have to add any more new variants? We can probably use common bpf_get_fd_by_id_opts for map/prog/link/btf get_fd_by_id operations (and let's add all variants for consistency)? > { > union bpf_attr attr; > int fd; > > memset(&attr, 0, sizeof(attr)); > attr.map_id = id; > + attr.open_flags = flags; > > fd = sys_bpf_fd(BPF_MAP_GET_FD_BY_ID, &attr, sizeof(attr)); > return libbpf_err_errno(fd); > } > > +int bpf_map_get_fd_by_id(__u32 id) > +{ > + return bpf_map_get_fd_by_id_flags(id, 0); > +} > + > int bpf_btf_get_fd_by_id(__u32 id) > { > union bpf_attr attr; > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h > index cabc03703e29..20e4c852362d 100644 > --- a/tools/lib/bpf/bpf.h > +++ b/tools/lib/bpf/bpf.h > @@ -438,6 +438,7 @@ LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id); > LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id); > LIBBPF_API int bpf_link_get_next_id(__u32 start_id, __u32 *next_id); > LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id); > +LIBBPF_API int bpf_map_get_fd_by_id_flags(__u32 id, __u32 flags); > LIBBPF_API int bpf_map_get_fd_by_id(__u32 id); > LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id); > LIBBPF_API int bpf_link_get_fd_by_id(__u32 id); > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map > index 38e284ff057d..019278e66836 100644 > --- a/tools/lib/bpf/libbpf.map > +++ b/tools/lib/bpf/libbpf.map > @@ -466,6 +466,7 @@ LIBBPF_1.0.0 { > libbpf_bpf_link_type_str; > libbpf_bpf_map_type_str; > libbpf_bpf_prog_type_str; > + bpf_map_get_fd_by_id_flags; > > local: *; > }; > -- > 2.25.1 >