From nobody Wed Dec 17 21:14:52 2025 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 45E18C77B72 for ; Tue, 18 Apr 2023 01:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230429AbjDRBlp (ORCPT ); Mon, 17 Apr 2023 21:41:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230253AbjDRBlR (ORCPT ); Mon, 17 Apr 2023 21:41:17 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 779E65279 for ; Mon, 17 Apr 2023 18:41:04 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 63-20020a250042000000b00b924691cef2so3638174yba.6 for ; Mon, 17 Apr 2023 18:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681782064; x=1684374064; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rGQ9sB/Rwqr1E4RbtpywhCeCd351RoNViaB6XX6OAcM=; b=7a7FthehtIU1LDZHaPCjM+OU4rQTnwIJO65M0avbzwBgquVMpBou6qbE9n76s23acW 0ZLBEZD6ViB5CGK7UFFeuO58ubsaYIEMTp4GXx/KH8KrYV2koGO24wTVipTnAT5jPPv2 vDoFrFqHAHBzZbYHVKyk17HtLm24Tprum8PLjWK078LB0eS6ATINZq6HTShyS6UJyTbI Pz0+UzgNTfLj4UnUR7Pl9WJGy4IzEKBoqH51/+5DCpzyuozlPN46l34XGNt300XMi2vv 0zHLgyVCJ6YKv4vRZGoF3hq5Tl/PhsQ2JO+iP5xq437JP1RbmlU4dS+oNmu6RXuBXKdD Wvyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681782064; x=1684374064; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rGQ9sB/Rwqr1E4RbtpywhCeCd351RoNViaB6XX6OAcM=; b=dNbLy+jxe7VppqSRL2VHzWRFKeWaWnxGaVpYkrHeYF/zhdE4GZ8+wsbtk9zv6e6UAQ AGEx77tGHgx12sb+N0lgWstpy1DjRAQ/Xx+nZ2BSA31LqG9/0ATfieIzcBtv3VOmSc2Q c0m0v/mpZ+pSt8vvAOyI/tCHsc5wCZyL+dcUSu0Ozvl/BEaSpSYgoyOmBym1Sxh68MAu quVkBav1uYzrOR1t6+DUbu/d1nLMrxxPqnGz8pcNk13pePXCUmqPsk2oykVMAbgMfscw XodknTl0Qz5ePCderu9675CaSpR/lrJeBvO9tu3Ivq9/ax+eLNsJBRxDDFANNXC31qYa hJWw== X-Gm-Message-State: AAQBX9essutExp53NUpyXXibcdvfJd2Z+22ADAAOqytJbw9fJIfk8Vfm gL574/HtdqugeL0nlyhg91MxU+BzPZw= X-Google-Smtp-Source: AKy350bEg5Yq5yN301eh/701p5EkdiweIgQB8V883Xlr2DXOiBdY6xkRbjC+SVvzsfu/0C5Gu4BhRNTqFN8= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:e67a:98b0:942d:86aa]) (user=drosen job=sendgmr) by 2002:a25:d10e:0:b0:b8f:3881:1638 with SMTP id i14-20020a25d10e000000b00b8f38811638mr8759594ybg.7.1681782064219; Mon, 17 Apr 2023 18:41:04 -0700 (PDT) Date: Mon, 17 Apr 2023 18:40:06 -0700 In-Reply-To: <20230418014037.2412394-1-drosen@google.com> Mime-Version: 1.0 References: <20230418014037.2412394-1-drosen@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230418014037.2412394-7-drosen@google.com> Subject: [RFC PATCH v3 06/37] fuse-bpf: Add data structures for fuse-bpf From: Daniel Rosenberg To: Miklos Szeredi , bpf@vger.kernel.org, Alexei Starovoitov Cc: Amir Goldstein , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jonathan Corbet , Joanne Koong , Mykola Lysenko , kernel-team@android.com, Daniel Rosenberg Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These structures will be used to interact between the fuse bpf calls and normal userspace calls Signed-off-by: Daniel Rosenberg --- include/linux/bpf_fuse.h | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 include/linux/bpf_fuse.h diff --git a/include/linux/bpf_fuse.h b/include/linux/bpf_fuse.h new file mode 100644 index 000000000000..ce8b1b347496 --- /dev/null +++ b/include/linux/bpf_fuse.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright 2022 Google LLC. + */ + +#ifndef _BPF_FUSE_H +#define _BPF_FUSE_H + +#include +#include + +struct fuse_buffer { + void *data; + unsigned size; + unsigned alloc_size; + unsigned max_size; + int flags; +}; + +/* These flags are used internally to track information about the fuse buf= fers. + * Fuse sets some of the flags in init. The helper functions sets others, = depending on what + * was requested by the bpf program. + */ +// Flags set by FUSE +#define BPF_FUSE_IMMUTABLE (1 << 0) // Buffer may not be written to +#define BPF_FUSE_VARIABLE_SIZE (1 << 1) // Buffer length may be changed (g= rowth requires alloc) +#define BPF_FUSE_MUST_ALLOCATE (1 << 2) // Buffer must be re allocated bef= ore allowing writes + +// Flags set by helper function +#define BPF_FUSE_MODIFIED (1 << 3) // The helper function allowed writes t= o the buffer +#define BPF_FUSE_ALLOCATED (1 << 4) // The helper function allocated the b= uffer + +/* + * BPF Fuse Args + * + * Used to translate between bpf program parameters and their userspace eq= uivalent calls. + * Variable sized arguments are held in fuse_buffers. To access these, bpf= programs must + * use kfuncs to access them as dynptrs. + * + */ + +#define FUSE_MAX_ARGS_IN 3 +#define FUSE_MAX_ARGS_OUT 2 + +struct bpf_fuse_arg { + union { + void *value; + struct fuse_buffer *buffer; + }; + unsigned size; + bool is_buffer; +}; + +struct bpf_fuse_meta_info { + uint64_t nodeid; + uint32_t opcode; + uint32_t error_in; +}; + +struct bpf_fuse_args { + struct bpf_fuse_meta_info info; + uint32_t in_numargs; + uint32_t out_numargs; + uint32_t flags; + struct bpf_fuse_arg in_args[FUSE_MAX_ARGS_IN]; + struct bpf_fuse_arg out_args[FUSE_MAX_ARGS_OUT]; +}; + +// Mirrors for struct fuse_args flags +#define FUSE_BPF_FORCE (1 << 0) +#define FUSE_BPF_OUT_ARGVAR (1 << 6) +#define FUSE_BPF_IS_LOOKUP (1 << 11) + +static inline void *bpf_fuse_arg_value(const struct bpf_fuse_arg *arg) +{ + return arg->is_buffer ? arg->buffer : arg->value; +} + +static inline unsigned bpf_fuse_arg_size(const struct bpf_fuse_arg *arg) +{ + return arg->is_buffer ? arg->buffer->size : arg->size; +} + +#endif /* _BPF_FUSE_H */ --=20 2.40.0.634.g4ca3ef3211-goog