Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4755131rwe; Mon, 17 Apr 2023 18:42:23 -0700 (PDT) X-Google-Smtp-Source: AKy350b6911znZDo+q6HjuTP1wURhqz5TLH/MM6E8Qmfo7LoihiZBu3XD+7VMxmmY4MfHZxyX0Ru X-Received: by 2002:a05:6a00:2da2:b0:63d:27a1:d578 with SMTP id fb34-20020a056a002da200b0063d27a1d578mr4973340pfb.20.1681782142751; Mon, 17 Apr 2023 18:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681782142; cv=none; d=google.com; s=arc-20160816; b=HZRT4UzKGM0+5VVIc+DssVxT4clye3KRilusxQ0NlnwlKczwIaT+jS6MrFM0eZT1NM mEok/QSuSfaEYsuvS1wsYVEQQh9yrMl0UfZn7/He0n6lQjUasjJlmsaJ2fEQiRMMNG7E iocHEd+1KnImdixUS/+LVmsrEQRPTWzmzHqnvFagtnziWKn/DPgu780JJYi+tCWPIeDr 91wnNxuOmt6qbGHkmmyJsjovKMROH7nS6iYIu12d5W+ZXbpZpbfSITR5DgUSG9QV6IBQ 2WIAezvky0F6YbVHwJM91A1ZBxzeHBSef38pRbeW4f8p8eYEeWJIoarsxN1jpiJxrOvr nfRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=rGQ9sB/Rwqr1E4RbtpywhCeCd351RoNViaB6XX6OAcM=; b=QzdxHpV769JjcEoZi7y8KlcJGLIz0CYFt7BzQbav4al9Z0N7KMMy4ETiChi9hDxnsz WHW12FAq3qWIlIO3MrsLDTF6yf5iw+R5LrpcrFoeM9uC9eTPNg2YD/Z0ccTJfIfZvCUl +TzOFD2f/fF6XvgkDXzJiYu20uB/rV27T35F2sVpBQQR02G9BWeZOijLGl1O4i+VBwWD 2crsMej1MjWg83JrTR5WHsSEVzFNC72l3WlucjWpc5FtyTGzerqAQbS099l+ypsFeQdj jLbcSuqRJ1Li10xCaWTam1eqxxHwKxjreUt5iyqjoptmYgDFTtFuIvNYhNlUhuaoOekC iBjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=7a7Ftheh; 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 x65-20020a626344000000b0062a46a30cb7si12833306pfb.51.2023.04.17.18.42.08; Mon, 17 Apr 2023 18:42:22 -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=20221208 header.b=7a7Ftheh; 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 S230383AbjDRBln (ORCPT + 99 others); Mon, 17 Apr 2023 21:41:43 -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-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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_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 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 buffers. + * 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 (growth requires alloc) +#define BPF_FUSE_MUST_ALLOCATE (1 << 2) // Buffer must be re allocated before allowing writes + +// Flags set by helper function +#define BPF_FUSE_MODIFIED (1 << 3) // The helper function allowed writes to the buffer +#define BPF_FUSE_ALLOCATED (1 << 4) // The helper function allocated the buffer + +/* + * BPF Fuse Args + * + * Used to translate between bpf program parameters and their userspace equivalent 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 */ -- 2.40.0.634.g4ca3ef3211-goog