From patchwork Mon Sep 26 23:17:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 12989530 X-Patchwork-Delegate: bpf@iogearbox.net 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 CA578C32771 for ; Mon, 26 Sep 2022 23:19:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231142AbiIZXTJ (ORCPT ); Mon, 26 Sep 2022 19:19:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbiIZXSt (ORCPT ); Mon, 26 Sep 2022 19:18:49 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B459AB2853 for ; Mon, 26 Sep 2022 16:18:37 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3451e7b0234so75341287b3.23 for ; Mon, 26 Sep 2022 16:18:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=oVFvJR4OdSBz8jEGY2bk02KLDgmIc1+T4MHAuS02Jcs=; b=I6GbLsFxJgTygTcZfHIxUxiMFf9w+Xtu3hA0y982MmIQMnv+eN66XSQwnU3fA3HfXL Z1VcX5VFM5T83x1xCwxv9QK1rGcXmLi/9dPpWlSbzwK8Uo+1kRRfCQ+MtUzrL7rOFToK KFGk0FSEp3UimYXlhQril1LsxLtWyU9HlmiSy4WexK3UK5s5AL52sqT5l7h93dSDSJ7X 9EH6UwdJfj+H0kT5vgMEQj53HvqUgRNZASKKyqWoXylr2ZEBGQ6CoVR6V/WaBcJ9INtx WCkGmrGVYA0sI7fFhgAKyaHDWpl7Iby+rvLN/AstcQ+9GTXxI8p83bR2Mz2IV/y0Y955 TfEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=oVFvJR4OdSBz8jEGY2bk02KLDgmIc1+T4MHAuS02Jcs=; b=Xz+Vnce4pIa3xN+zT0WHmgxBmg3xh0bW+iF6PDoxgyeuCPdzRzi6WRITyHf8YZ0NQ1 7ujnX6MRC6mBWnUEkog+0ySTxLqhLIMsSiAh18sRW11UvmhBOmcP7+5Xaoq+cOdR3PDp P3OckxeJQTLSJ1WBAvi9GsWNMmMNPb0JXIYspnZ8oAtpNePDG+7AwQUJzPUjo9Ax0pvF 4ghP76ABMuTGWh+HXdF48GELR3DY3I/xzCsxT26g/Iuf82Ar/+3J+xlcwXv25ALRLOHP cc6c5m4vSoOSk+PfHJaAwWJ3bCsh210a/3z0Hvz0HXCB0MJjZzIUyIwwhPXLqZ01IhdW F/hg== X-Gm-Message-State: ACrzQf3iT1626HHf0ZkHfDUs2O/gvsy5HDck8m4ANxrZGGh6A5Dke/Zd jLRNgsjPX3ezE76y42tmXCTHHfKHHY4= X-Google-Smtp-Source: AMsMyM5L3Kbi+AtpufhWkHrInTI1CTOrQSz0EP+DieLqmDEcI3OtasU7xDE9zeLviDjP5CNu0NxoTxsS+vY= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:200:4643:a68e:2b7:f873]) (user=drosen job=sendgmr) by 2002:a5b:94e:0:b0:6bb:ee52:1a66 with SMTP id x14-20020a5b094e000000b006bbee521a66mr3598602ybq.506.1664234317049; Mon, 26 Sep 2022 16:18:37 -0700 (PDT) Date: Mon, 26 Sep 2022 16:17:59 -0700 In-Reply-To: <20220926231822.994383-1-drosen@google.com> Mime-Version: 1.0 References: <20220926231822.994383-1-drosen@google.com> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog Message-ID: <20220926231822.994383-4-drosen@google.com> Subject: [PATCH 03/26] fuse-bpf: Update uapi for fuse-bpf From: Daniel Rosenberg To: Miklos Szeredi , Alexei Starovoitov , Daniel Borkmann , John Fastabend Cc: Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Daniel Rosenberg , Paul Lawrence , Alessio Balsini , David Anderson , Sandeep Patil , linux-fsdevel@vger.kernel.org, bpf@vger.kernel.org, kernel-team@android.com Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This adds the bpf prog type for fuse-bpf, and the associated structures. Signed-off-by: Daniel Rosenberg Signed-off-by: Paul Lawrence --- include/linux/bpf_fuse.h | 50 +++++++++++++++++++++++++++++++++++++++ include/linux/bpf_types.h | 4 ++++ include/uapi/linux/bpf.h | 31 ++++++++++++++++++++++++ include/uapi/linux/fuse.h | 13 +++++++++- 4 files changed, 97 insertions(+), 1 deletion(-) diff --git a/include/linux/bpf_fuse.h b/include/linux/bpf_fuse.h index 18e2ec5bf453..9d22205c9ae0 100644 --- a/include/linux/bpf_fuse.h +++ b/include/linux/bpf_fuse.h @@ -6,6 +6,56 @@ #ifndef _BPF_FUSE_H #define _BPF_FUSE_H +/* + * Fuse BPF Args + * + * Used to communicate with bpf programs to allow checking or altering certain values. + * The end_offset allows the bpf verifier to check boundaries statically. This reflects + * the ends of the buffer. size shows the length that was actually used. + * + * In order to write to the output args, you must use the pointer returned by + * bpf_fuse_get_writeable. + * + */ + +#define FUSE_MAX_ARGS_IN 3 +#define FUSE_MAX_ARGS_OUT 2 + +struct bpf_fuse_arg { + void *value; // Start of the buffer + void *end_offset; // End of the buffer + uint32_t size; // Used size of the buffer + uint32_t max_size; // Max permitted size, if buffer is resizable. Otherwise 0 + uint32_t flags; // Flags indicating buffer status +}; + +#define FUSE_BPF_FORCE (1 << 0) +#define FUSE_BPF_OUT_ARGVAR (1 << 6) + +struct bpf_fuse_args { + uint64_t nodeid; + uint32_t opcode; + uint32_t error_in; + 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]; +}; + +/* 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 + bool bpf_helper_changes_one_pkt_data(void *func); #endif /* _BPF_FUSE_H */ diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h index 2b9112b80171..80c7f7d69794 100644 --- a/include/linux/bpf_types.h +++ b/include/linux/bpf_types.h @@ -79,6 +79,10 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_LSM, lsm, #endif BPF_PROG_TYPE(BPF_PROG_TYPE_SYSCALL, bpf_syscall, void *, void *) +#ifdef CONFIG_FUSE_BPF +BPF_PROG_TYPE(BPF_PROG_TYPE_FUSE, fuse, + struct __bpf_fuse_args, struct bpf_fuse_args) +#endif BPF_MAP_TYPE(BPF_MAP_TYPE_ARRAY, array_map_ops) BPF_MAP_TYPE(BPF_MAP_TYPE_PERCPU_ARRAY, percpu_array_map_ops) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 59a217ca2dfd..ac81763f002b 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -952,6 +952,7 @@ enum bpf_prog_type { BPF_PROG_TYPE_LSM, BPF_PROG_TYPE_SK_LOOKUP, BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */ + BPF_PROG_TYPE_FUSE, }; enum bpf_attach_type { @@ -6848,4 +6849,34 @@ struct bpf_core_relo { enum bpf_core_relo_kind kind; }; +struct __bpf_fuse_arg { + __u64 value; + __u64 end_offset; + __u32 size; + __u32 max_size; +}; + +struct __bpf_fuse_args { + __u64 nodeid; + __u32 opcode; + __u32 error_in; + __u32 in_numargs; + __u32 out_numargs; + __u32 flags; + struct __bpf_fuse_arg in_args[3]; + struct __bpf_fuse_arg out_args[2]; +}; + +/* Return Codes for Fuse BPF programs */ +#define BPF_FUSE_CONTINUE 0 +#define BPF_FUSE_USER 1 +#define BPF_FUSE_USER_PREFILTER 2 +#define BPF_FUSE_POSTFILTER 3 +#define BPF_FUSE_USER_POSTFILTER 4 + +/* Op Code Filter values for BPF Programs */ +#define FUSE_OPCODE_FILTER 0x0ffff +#define FUSE_PREFILTER 0x10000 +#define FUSE_POSTFILTER 0x20000 + #endif /* _UAPI__LINUX_BPF_H__ */ diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index d6ccee961891..8c80c146e69b 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -572,6 +572,17 @@ struct fuse_entry_out { struct fuse_attr attr; }; +#define FUSE_ACTION_KEEP 0 +#define FUSE_ACTION_REMOVE 1 +#define FUSE_ACTION_REPLACE 2 + +struct fuse_entry_bpf_out { + uint64_t backing_action; + uint64_t backing_fd; + uint64_t bpf_action; + uint64_t bpf_fd; +}; + struct fuse_forget_in { uint64_t nlookup; }; @@ -870,7 +881,7 @@ struct fuse_in_header { uint32_t uid; uint32_t gid; uint32_t pid; - uint32_t padding; + uint32_t error_in; }; struct fuse_out_header {