Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp61251imi; Wed, 20 Jul 2022 17:08:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vT5q+y42FE0Hv56nMK54EEv/f/nxFJT0jLX0Dwx1tmXbaZAPyThETGv3jv5SokGWzrurdt X-Received: by 2002:a17:906:149:b0:711:fca6:bc2f with SMTP id 9-20020a170906014900b00711fca6bc2fmr37036421ejh.497.1658362103411; Wed, 20 Jul 2022 17:08:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658362103; cv=none; d=google.com; s=arc-20160816; b=eBgThEPHyTBJTScPfMZ47N4LIgKbtYhWReebvpB5DeuIMEiqGe5AHD86ERGy8yNFBL +56HPsEOe2ebrfS9dUA8nNwR+RntGdn8G6GRTzZt61PEVrWiCmfhK9JlQJp176LdM/kH U/8FMccJkpwbdwWWO7FqMxNuO0FNTZtfSscByYzu8Wrh54d+tQsmghjQk8y4gglqbvL3 if9U2b16vnXw2gHMhzUXmPapTBRF9UG+e9GJTTipBDrUgM5dMt8rL2x86thKBdk1VaA+ gATrPwx7z+wTHQKgUWR/mtYg6ImCSoogtxoimoKNHWHfGgg3pKbbPWABrOLT3WWWMS2C QtTA== 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=biQfKVkYP0pKtswQt3kzw1zka1n8k/er3b8pHLQhGbo=; b=RDkdVkkbXfQmu3fySYqAH91CCY/6qWspzF7MN0maskRhqQpsICZ7GMcX0gGgztuD0y J926vkBhzi6z5FuO3CcxfyKYZt6JubzlW4UU3JANzN+le6jTAwUfazjIkeFdBjGRXcql reu6GDnXbNaHfJgtlLbmmgbA8pBM/NspX3yA9/eUZdwHlNMex7CHNko8lh/EpEd1mWN9 FNZGWNf7OakhURwJXGd88xVnuuxvON58nNC4WjsTIjIZswbvKXu8B60XffMDkFlaqMlH 8qQavJ4zmW6GffzQHxtB/7UtqAJsoeyOMThhpjm44qSoCLCp2ew36gGWkiq9sv3w+Aqw qc5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QSNpm6ni; 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 hw19-20020a170907a0d300b0072b0f8a987csi541511ejc.822.2022.07.20.17.07.58; Wed, 20 Jul 2022 17:08:23 -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=QSNpm6ni; 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 S231309AbiGTX0k (ORCPT + 99 others); Wed, 20 Jul 2022 19:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbiGTX0i (ORCPT ); Wed, 20 Jul 2022 19:26:38 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E668D2E9DE for ; Wed, 20 Jul 2022 16:26:37 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id s206so56932pgs.3 for ; Wed, 20 Jul 2022 16:26: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=biQfKVkYP0pKtswQt3kzw1zka1n8k/er3b8pHLQhGbo=; b=QSNpm6ni7NgkQBZuAHl6j2XjdW//Yi/pj60mJ8jm5LMKQG6g4kChOUNyLkBg71iOvO LEMFv98cDlIlunj0UuXI8eOwhFqwUAucR+V0O/mDZURxCvChdgGdMhVBXuFmepN1GfLy Cuy+II6JY0jdQR5I4Cdn1nzSOzu603+4vjcMKPdFFUyu6TqfSZtkjoM1mbwXqKezGfOI PuomCkFSly8cNiY8Qa+AU0hNSArl3yhTlU0Dmrj6xjqmZLyvuAQP5RYITdLdQ7qeo/y4 uxMLDZ6eJRt5s35+/aKfOxbms7Ef0dEFmFwMLkAwP7nmwDB0YAau/NeokqWKKOupkA+C yB/A== 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=biQfKVkYP0pKtswQt3kzw1zka1n8k/er3b8pHLQhGbo=; b=KmMQrXHSJOIdvmJACbjTBwbHURtiEniIP57az+uY31iVA0p5wzO4rq0UZ5YeAsRE/E Maqg3AaNDbhmzQtMRMGGDBNzJk5Klmk90tVZhjPTA4CCqu8o9+KyDrnptdeC7BBZJuF3 bIffSDXYJhQq4CMB+cspccuAP+cwSpqa1C72MaMm8qWaPq9XJfk/DKpjCsHRQLgdsmZA dn+BnBmlXdKS4SaSHng1p9bBOESrGsjLPKhmK34oTcRu3/w3j8lAwCb67TDW3FdwpHus kZ77ZEMMsHq7Pqdvz3rN3VnmlJHyv2nipE5GyQ+iCX4Alprba9eK7kGwrFVIk4u9iH08 /HJA== X-Gm-Message-State: AJIora/K5fUQ7mFF6iaSNWaSDJE+nD6LuO5WgxQBcygYBh62eWANqfXW bK36RB2qW0JYVPhVWXn4gvq5yOjcN/4uDcPOZoQLJQ== X-Received: by 2002:a65:4c0b:0:b0:415:d3a4:44d1 with SMTP id u11-20020a654c0b000000b00415d3a444d1mr36349247pgq.191.1658359597244; Wed, 20 Jul 2022 16:26:37 -0700 (PDT) MIME-Version: 1.0 References: <20220719194028.4180569-1-jevburton.kernel@gmail.com> <179cfb89be0e4f928a55d049fe62aa9e@huawei.com> <31473ddf364f4f16becfd5cd4b9cd7d2@huawei.com> <0c284e09817e4e699aa448aa25af5d79@huawei.com> <8fe67e829d95477d884131641ca0961d@huawei.com> In-Reply-To: <8fe67e829d95477d884131641ca0961d@huawei.com> From: Stanislav Fomichev Date: Wed, 20 Jul 2022 16:26:26 -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=unavailable 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 4:17 PM Roberto Sassu wrote: > > > From: Stanislav Fomichev [mailto:sdf@google.com] > > Sent: Thursday, July 21, 2022 1:15 AM > > On Wed, Jul 20, 2022 at 4:12 PM Roberto Sassu > > wrote: > > > > > > > From: Stanislav Fomichev [mailto:sdf@google.com] > > > > Sent: Thursday, July 21, 2022 1:09 AM > > > > On Wed, Jul 20, 2022 at 4:02 PM Roberto Sassu > > > > > > wrote: > > > > > > > > > > > From: Stanislav Fomichev [mailto:sdf@google.com] > > > > > > Sent: Thursday, July 21, 2022 12:48 AM > > > > > > On Wed, Jul 20, 2022 at 3:44 PM Roberto Sassu > > > > > > > > > > wrote: > > > > > > > > > > > > > > > From: Stanislav Fomichev [mailto:sdf@google.com] > > > > > > > > Sent: Thursday, July 21, 2022 12:38 AM > > > > > > > > On Wed, Jul 20, 2022 at 3:30 PM Roberto Sassu > > > > > > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > > > From: Stanislav Fomichev [mailto:sdf@google.com] > > > > > > > > > > Sent: Wednesday, July 20, 2022 5:57 PM > > > > > > > > > > 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? > > > > > > > > > > > > > > > > > > It is very similar. Except that I called it bpf_get_fd_opts, as it > > > > > > > > > is shared with the bpf_*_get_fd_by_id() functions. The member > > > > > > > > > name is just flags, plus an extra u32 for alignment. > > > > > > > > > > > > > > > > We can bikeshed the naming, but we've been using existing > > conventions > > > > > > > > where opts fields match syscall fields, that seems like a sensible > > > > > > > > thing to do? > > > > > > > > > > > > > > The only problem is that bpf_*_get_fd_by_id() functions would > > > > > > > set the open_flags member of bpf_attr. > > > > > > > > > > > > > > Flags would be good for both, even if not exact. Believe me, > > > > > > > duplicating the opts would just create more confusion. > > > > > > > > > > > > Wait, that's completely different, right? We are talking here about > > > > > > BPF_OBJ_GET (which has related BPF_OBJ_PIN). > > > > > > Your GET_XXX_BY_ID are different so you'll still have to have another > > > > > > wrapper with opts? > > > > > > > > > > Yes, they have different wrappers, just accept the same opts as > > > > > obj_get(). From bpftool subcommands you want to set the correct > > > > > permission, and propagate it uniformly to bpf_*_get_fd_by_id() > > > > > or obj_get(). See map_parse_fds(). > > > > > > > > I don't think they are accepting the same opts. > > > > > > > > For our case, we care about: > > > > > > > > struct { /* anonymous struct used by BPF_OBJ_* commands */ > > > > __aligned_u64 pathname; > > > > __u32 bpf_fd; > > > > __u32 file_flags; > > > > }; > > > > > > > > For your case, you care about: > > > > > > > > struct { /* anonymous struct used by BPF_*_GET_*_ID */ > > > > union { > > > > __u32 start_id; > > > > __u32 prog_id; > > > > __u32 map_id; > > > > __u32 btf_id; > > > > __u32 link_id; > > > > }; > > > > __u32 next_id; > > > > __u32 open_flags; > > > > }; > > > > > > > > So your new _opts libbpf routine should be independent of what Joe is > > > > doing here. > > > > > > It is. Just I use the same opts to set file_flags or open_flags. > > > > That seems confusing. Let's have separate calls for separate syscall > > commands as we do already? > > Can you wait one day, I send what I have, so that we see > everything together? Sure, CC us both on the patches.