Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4755779rwe; Mon, 17 Apr 2023 18:43:14 -0700 (PDT) X-Google-Smtp-Source: AKy350a9lb8rCyRj0OOS4AKgbDvI4AxkLH3up02kW1utIQPntL5laL6VC1v3fk61cUUKXFVzP2yb X-Received: by 2002:a05:6a20:1583:b0:f0:558b:8fbb with SMTP id h3-20020a056a20158300b000f0558b8fbbmr3305691pzj.34.1681782194506; Mon, 17 Apr 2023 18:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681782194; cv=none; d=google.com; s=arc-20160816; b=NxV2RYETwBmawHiXRzXeBVqaCbf1AXvSL+el2Bn9S3jsDK6SSi5Ic5EA9MloKEUIlv yyXZQjFaWLB2+xkZO+2ZWEmN5rZuxCOR4Um9sPm+cdFO4B1iDIKjKqyVvsgwyb3tk9tH KOs2IStQ3SogDP63zU4uJdbmy/g03b9aVIfXIrKXoapC6L/CG161ccQ7g5ldcFx8VN38 Xc2v8pY+vOn6vk98EGIlqzURpIf0yuM1yxsZ3V7pN/C5pFZuzWNho6pztb3gaWhoZTBT XKCf4OR3AidL/mWn6RAV+lAlELzOxbA+Fzt3B5i3eo9KhqsV7YH6UNjGIFE0sPZr1mZu ZiHQ== 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=oN6x+PcjBowjEB90+rsteKN+eOkqOSAMj6ggqH7i4oE=; b=voLv28ArZpTFtgVLZdSPW168OrOSjqgzGF8O6OP3hayKNOHfJuxZHfAQF2cQU0kxlf oRWiaInYl8zsabAo639EFhoEB66AOrrbLNdH2/nGEU6DI6YzccwM3C2FkutbnOXl/W// S1Q6a8OhFmgoZHQoPSY3wPLHKGnNoBu3CI6yVXdmWW4kP8E2fmLLhzvHQgySpOrLNrJN mni3a1/dmPhVyqSwyEWMfUcMKqFxLKO7SAlqVbRHywxy7tIcu9+rRuypTEHjNueHHZSJ J9fY4X6FQFgy686KV0a/A04wGS9pDFctftvlA0R3EpAMJ42GkPOMHG1ykUj+9+3aawq8 dLkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=e2l+365Y; 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 h64-20020a638343000000b0051bacd63758si4410765pge.245.2023.04.17.18.43.01; Mon, 17 Apr 2023 18:43:14 -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=e2l+365Y; 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 S231137AbjDRBmn (ORCPT + 99 others); Mon, 17 Apr 2023 21:42:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbjDRBl7 (ORCPT ); Mon, 17 Apr 2023 21:41:59 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AC9A61A7 for ; Mon, 17 Apr 2023 18:41:19 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54faf2e22afso139555587b3.7 for ; Mon, 17 Apr 2023 18:41:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681782078; x=1684374078; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oN6x+PcjBowjEB90+rsteKN+eOkqOSAMj6ggqH7i4oE=; b=e2l+365Y5NfwgrmJ3glTREcW5dUMa28BQ3rkaEXIxzCaUVeE1IhaW2auQ6TAoZSlTV 2DPfi5gIQFGcRKYkma2DV8pvrKv+CMBRJ5PqPI/sdCdJlujipWSi8TX5fpC7CIATr/wd IZ08/Y5ullb70ZOKJIK0Fa3l1w37fzqtYaUA2LBOQ+U08RbTKlpgXJi+kOkZuc5emqyT txsRKHpNndZBshfMylH2G+PKKT4M75pZSQdvHa69EiYZG+SqYwtca9kBbOLbesWQNZOV ScLqr6LEl57hIDUX6HFB91pq60LCptprJlfycy0AaC9T8kF5M0PJh2968Q/Fdg6j+/Y2 nZBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681782078; x=1684374078; 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=oN6x+PcjBowjEB90+rsteKN+eOkqOSAMj6ggqH7i4oE=; b=aXqCZNInJZsck6XY6VvJHtj05BbvRWrdP/FyjWItdVMxQaIRSB5Wh8AnRoBGxQpdOx 2L/N6PaZ+dRMBNvpArQ/fDpEum0j+sOx0/DJ7kAn+JC5QUpuZbZ25rS8pUIpGSvVW23y IWU9trc4HEOSze5zyO6w81tTIOiMrg2my8/AoftoBvfWn7PQV9PA71YubfL7iYdxLKph vfaovo95SFvkTbykSZmLBBIzThC5G5W7P7IogKvHLofBUluU75C1gL93sfpgrGvRd0ac gLuWy0MkAPkZr1mAkGNGIkp1meTk/NevWaUp5xIeeBZ2uawaxU7hzVtL+iumeYH3yMXL RGNw== X-Gm-Message-State: AAQBX9fZddaDRpbGslANUVzUe7GbQ4E8C3KTth1NZtSqherQ7+rBpBxy 7OQs93UfLlF/6CPC7VzW9EEV2ylzXQc= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:e67a:98b0:942d:86aa]) (user=drosen job=sendgmr) by 2002:a25:74d4:0:b0:b8e:cb88:1b8a with SMTP id p203-20020a2574d4000000b00b8ecb881b8amr10919222ybc.8.1681782078105; Mon, 17 Apr 2023 18:41:18 -0700 (PDT) Date: Mon, 17 Apr 2023 18:40:12 -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-13-drosen@google.com> Subject: [RFC PATCH v3 12/37] fuse-bpf: Partially add mapping support 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 , Paul Lawrence 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=ham 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 This adds a backing implementation for mapping, but is not currently hooked into the infrastructure that will call the bpf programs. Signed-off-by: Daniel Rosenberg Signed-off-by: Paul Lawrence --- fs/fuse/backing.c | 37 +++++++++++++++++++++++++++++++++++++ fs/fuse/file.c | 6 ++++++ fs/fuse/fuse_i.h | 4 +++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index e42622584037..930aa370e376 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -207,6 +207,43 @@ static void fuse_stat_to_attr(struct fuse_conn *fc, struct inode *inode, attr->blksize = 1 << blkbits; } +ssize_t fuse_backing_mmap(struct file *file, struct vm_area_struct *vma) +{ + int ret; + struct fuse_file *ff = file->private_data; + struct inode *fuse_inode = file_inode(file); + struct file *backing_file = ff->backing_file; + struct inode *backing_inode = file_inode(backing_file); + + if (!backing_file->f_op->mmap) + return -ENODEV; + + if (WARN_ON(file != vma->vm_file)) + return -EIO; + + vma->vm_file = get_file(backing_file); + + ret = call_mmap(vma->vm_file, vma); + + if (ret) + fput(backing_file); + else + fput(file); + + if (file->f_flags & O_NOATIME) + return ret; + + if ((!timespec64_equal(&fuse_inode->i_mtime, &backing_inode->i_mtime) || + !timespec64_equal(&fuse_inode->i_ctime, + &backing_inode->i_ctime))) { + fuse_inode->i_mtime = backing_inode->i_mtime; + fuse_inode->i_ctime = backing_inode->i_ctime; + } + touch_atime(&file->f_path); + + return ret; +} + /******************************************************************************* * Directory operations after here * ******************************************************************************/ diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 25fb49f0a9f7..865167a80d35 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2527,6 +2527,12 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) if (FUSE_IS_DAX(file_inode(file))) return fuse_dax_mmap(file, vma); +#ifdef CONFIG_FUSE_BPF + /* TODO - this is simply passthrough, not a proper BPF filter */ + if (ff->backing_file) + return fuse_backing_mmap(file, vma); +#endif + if (ff->open_flags & FOPEN_DIRECT_IO) { /* Can't provide the coherency needed for MAP_SHARED */ if (vma->vm_flags & VM_MAYSHARE) diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index cb166168f9c2..5eb357f482dc 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1422,7 +1422,9 @@ static inline int fuse_bpf_access(int *out, struct inode *inode, int mask) #endif // CONFIG_FUSE_BPF -int fuse_handle_backing(struct fuse_bpf_entry *feb, struct path *backing_path); +ssize_t fuse_backing_mmap(struct file *file, struct vm_area_struct *vma); + +int fuse_handle_backing(struct fuse_bpf_entry *fbe, struct path *backing_path); int fuse_revalidate_backing(struct dentry *entry, unsigned int flags); -- 2.40.0.634.g4ca3ef3211-goog