Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp85958imn; Wed, 27 Jul 2022 16:08:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sfhjp7Is+a52qjPfipJBJU9UHOC3uN0tpytW677SsrXzz7LxrnqWEqiTSX3t8lYh+CUgN8 X-Received: by 2002:a65:6949:0:b0:41a:69b1:88bf with SMTP id w9-20020a656949000000b0041a69b188bfmr20503206pgq.624.1658963289050; Wed, 27 Jul 2022 16:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658963289; cv=none; d=google.com; s=arc-20160816; b=r1abNEogOfXBJCfMU+7LIseFAUoyaIRg7bxgRnIxc03SuOeuXOS8s4iKMsbSJQwF5Z 6PfrWucXkdIFJ9XrB9YHyIBlsIX58+/kTHlPaATluxTlFOnS5O+wvRPJv5Cfa+wJ+q0X LSsk8mjwpgAXprrIAJVsH4jbwHuelyTOoBY/GhWbM9+S38WOilDSjANUaY/UTDe0gpEl /D+CaB0zfMy6IyFAvPLMurnLNiu3LyDFC+PjBoYOJTnJnHjJJ3AdV6zYOL4ak2tFssnU c9yqpWwvn7IOUoYJx5vAXY+gCVJa1ogdgBqEZfAYFxfiOE82xouXfhHCRNcCxVE3goXF w1UQ== 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=UccYnvkXJ9TbV8KUpT9J6zIdbsOHqZHbizSjT0errm8=; b=sILbXmg7pxifiz/xQP4nzir3N8kWnBpRVgmRdKA8xZIpPdJYodJ1Y5BsOL6v04Gmw/ zJTVv1s4Ozptta+OH/qpGO0fxjnJWSIqX6Nk3Cb5DJWwvXipt9+Xv3zj9OUixFNO171s t3Ck3exg/CJYFHsdaggCwwufvV2UYF/5Jy3x7o732kzoCzASQMlmNxSf0lCv/FRqAhul +liCloO+r+CIAhTTbWDGnb24XHsfWkkxaUQARx8qjw3Q/ChKuM6O0JC/gnkKdeVO/POB /a+sOoSmkk56n7j+CAeBJxxFaIs9SYJ1OXhX7Kh57/3EmXJWGZgkaUk/b57r51Aw1BjU TkNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fd7BlUYo; 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 li13-20020a17090b48cd00b001efe8dcea0csi3453895pjb.108.2022.07.27.16.07.50; Wed, 27 Jul 2022 16:08:09 -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=fd7BlUYo; 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 S236941AbiG0XC6 (ORCPT + 99 others); Wed, 27 Jul 2022 19:02:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229532AbiG0XC5 (ORCPT ); Wed, 27 Jul 2022 19:02:57 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A82420F56; Wed, 27 Jul 2022 16:02:56 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id va17so336424ejb.0; Wed, 27 Jul 2022 16:02:56 -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; bh=UccYnvkXJ9TbV8KUpT9J6zIdbsOHqZHbizSjT0errm8=; b=fd7BlUYoHTBhaInTSJ/QMQQCFgGZuJA3bxO4XT1o7hw/Zb1p6b/XHgCEJ4DZ3Kno1X E382YOICjJf1/0RwQ4bQaU70OocUHcC5FwpsYerBoH7nleD2rzfG6wJ8D2Q4rqyKz3ET ljnrYTVYtwDWIQcNVwhkUfbUq54sSUO7jxTz30dPjaMaU5VVw7Hbr1nMKY++NVBfke45 r9QLkGeCt4/pmrCYN2XCHM+0g0oJYey3hLdnk0tkanaX/65DNA875/QTPXDUgHR9kNUe ALYabtNcw+7zx+w1NqHQuex4MgsNZGEoQ5OMldlnVWO8WLtuuCymj+z7nRVQmZzZ4iCL Wixg== 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; bh=UccYnvkXJ9TbV8KUpT9J6zIdbsOHqZHbizSjT0errm8=; b=Iey1VLoo6jA1GKSXY2zD39ZgRGu0fkr+V11psdhAbyDceK/t7raIClGhRqCdc15fcM Tp8C1nFhRwdnexy+pLg0hU64PeAzRyGIbMcudiQiMz47/6r8sGoHatw2WD68juFcQcJA JthkL4Qk27/ZCbJFyJAz9ppAuvfeMX0wpv3BtAHBsspvaFNGlW0WCptvM+nT+XLHHRll CIxeM9R9e6r75wU//vlbZo+y+29KNN68tY5dMjaeNq1x9FAgM1sKX9AanNYFFh2c8uGU n5zskqBfKcG+BwGqibTIiYiTieesCeY1dJqJT6QRXRt7/Dy94HaSMNGERv6Hk6kAdtEy Os0g== X-Gm-Message-State: AJIora+QznnEfd6I0XT1+8kkHLT08Ajy3V/VSA6KQBaAwxBQi/pVqC1g owGC+oUsMVxbPIsNBvLCqqqrHbXyEeVxYUIO+FY= X-Received: by 2002:a17:907:2808:b0:72b:4d49:b2e9 with SMTP id eb8-20020a170907280800b0072b4d49b2e9mr20015090ejc.176.1658962974933; Wed, 27 Jul 2022 16:02:54 -0700 (PDT) MIME-Version: 1.0 References: <20220719194028.4180569-1-jevburton.kernel@gmail.com> In-Reply-To: <20220719194028.4180569-1-jevburton.kernel@gmail.com> From: Andrii Nakryiko Date: Wed, 27 Jul 2022 16:02:43 -0700 Message-ID: Subject: Re: [PATCH v2 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 , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf , open list , Joe Burton 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, 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 > --- > tools/lib/bpf/bpf.c | 10 ++++++++++ > tools/lib/bpf/bpf.h | 9 +++++++++ > tools/lib/bpf/libbpf.map | 1 + > 3 files changed, 20 insertions(+) > I agree that bpf_obj_get_opts should be separate from bpf_get_fd_opts. Just because both currently have file_flags in them doesn't mean that they should/will always stay in sync. So two separate opts for two separate APIs makes sense to me. So I'd accept this patch, but please see a few small things below and send v3. Thanks! > 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); if you were doing it this way, here should be an empty line. But really you can/should just pass NULL instead of opts in this case. > + 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; please add size_t :0; to avoid non-zero-initialized padding (we do it in a lot of other opts structs) > +}; > +#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 >