From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE71AC433EF for ; Wed, 20 Jul 2022 23:26:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231397AbiGTX0k (ORCPT ); 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-Google-Smtp-Source: AGRyM1t0P4fuHckbHl2pK6lXBgp1lrSKqcFhSdGxUQLjPoxHBQJykdV36MkckdP1DgzKclwel/JrBsO63EydO9Y3GGY= 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" 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.