Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp820702lqh; Thu, 28 Mar 2024 18:57:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVOWsIe4xXzifI01iXk5zrvXBvggIOk8PBB5t359IiM8PTLYnKzFc26qNmRr8gD0va3yjy2yDKk69hczaLBWyP4powZVyXeBz0jc1uTpQ== X-Google-Smtp-Source: AGHT+IGYoQV8jkfQnPduwM0I9SHPBDNOJr7nCiQ5TMYSHayIXuCxkM966/XMw/tWubBFUbO3Ll0j X-Received: by 2002:a17:906:e205:b0:a47:322b:c94d with SMTP id gf5-20020a170906e20500b00a47322bc94dmr925768ejb.6.1711677450058; Thu, 28 Mar 2024 18:57:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711677450; cv=pass; d=google.com; s=arc-20160816; b=Sq2IaI8Q0vQu3Bx7FO2tsMXPma3RKx+UIgZVd4ASVYr2L6hwKD8gmB1o5K15uiAg9s dUF/OZ7zeiGURJdCtvbazWJZz3rwAt/c68XcKxOJpPaTZeB1iFvGlFh2ZXMW1WyoPopn z8H2oyPyh8IweFXiZRzV1d5gNK0FXNWloYnPp1GjrgKKiXscMV/kMMxx/w/AG6wyV5du C2Dt+4B+fUQ2s45Xx2zS+OW3IDqPZWoldCGfr15tv2ZVsdeQ/XhMFuEFuHr3HmSgUwi5 39LjfxC7cWc5B2+qDnumUP+XXgzkf9wdwfYtHB5kbETnu3+pWqFouKiQdrMSgNsCfdH9 Vysg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=1qqFZWrpXHSloU4DHzngdNGiVBp7dRUntmvVSQg8HHI=; fh=3p0fXwuSCEg3V2eXOLhtrfkJ+e7kPkVMMDwSHZL2lgM=; b=lDLd8Nmms8F/038cd6OwhBDVSEhjDOSxGGVhpNcJUI2GySpxkFsg4kRvChFe2uWtJT wtMj3GXRgZPuCGYHvADTR2VKW4w6OADb6e1Tv++YffPXOTDTRZNDnF0TzYo7TggKH26o R4nc4Ym415bZvH57kmzWohoDv9LGvKzn9yaL3t95ZUA8gC+wz928e3HZwKLJYfcy3tUt JDG744s4DSBNwpr0bkJ1mWP5cC3frXpDwty8vUtVsgdeobDHshfd52HOGtx/jvrWQzq8 dEcS/9Gtawh5sBFYHveVW2Vz3NGRu3FjH1xwHS/6idXSetqH1CQgF0TBldFctCGHO6Hz Gddw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=imRu2q3Z; arc=pass (i=1 spf=pass spfdomain=flex--drosen.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-123987-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123987-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y10-20020a1709063daa00b00a474b7dd311si1306589ejh.694.2024.03.28.18.57.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 18:57:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123987-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=imRu2q3Z; arc=pass (i=1 spf=pass spfdomain=flex--drosen.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-123987-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123987-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9F3DF1F2235D for ; Fri, 29 Mar 2024 01:57:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A418C3BBFD; Fri, 29 Mar 2024 01:54:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="imRu2q3Z" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0405C3B293 for ; Fri, 29 Mar 2024 01:54:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711677259; cv=none; b=pmMaiKYPLGibOekFhzsw6z1SxpcqzN07oIKsYbfqrTtV2XHbXrQmtssVum1vlM/YjqDCXGH47kSG3BegKXgGuN0ond5X3cbItFG49Rprtuox6ekMi7FDM3WxBQGSrsYl6uq1IXGCSMNhlstZ5QzfiswyrZWgogXxiltfpK9IwwE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711677259; c=relaxed/simple; bh=v5AwnjQKV/7OH7UGGRZtC3sy6l1pNzMEDPgRfXAhH7g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HJl9488/ls6e8E4JGjSEYqocOY4LQqF0mJEQRLTCD3xY9wCEzo8suTZa8KslITEz9Z9JodUr5+SPEfZlY4/kx84nvvCXlEfDaVUnD0LtcDywZ7VctJfTtNAsQJjAGTLvv0f90SNZr4mmIlhXIup62imi6E73DAU1uwFiJ07EpDw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--drosen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=imRu2q3Z; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--drosen.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60f9d800a29so25397467b3.0 for ; Thu, 28 Mar 2024 18:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711677257; x=1712282057; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1qqFZWrpXHSloU4DHzngdNGiVBp7dRUntmvVSQg8HHI=; b=imRu2q3ZUgP4igk/dyN9A0ZpjyHHhMbidocZhV7Q9uzufiZOawkgJjQyO0OMwzyq5u D+taXfRplr6J0gESe53K23uhR1J9xFTMLRsDuP5TCj+qwVG0Ynt7RsUsoanoddS0Ybng 2TR4Yt9CWGPhrDwZpDq/DOY4jZTKZyYio+6xF9myWMZ8I2sTiy3qP5wbPGvInFyHUSpG oiTicVQ/LnCeOwSgWZr8UA9ABwT1sMkeEJQek6KJlOoCqdPrsxnfCw2RdMHW8Ozq9Kd3 GQaJXeCaOKB+/2TJqH5UoHeaNMLJIqTwZOS2DMvtOYIRejWbl2WqbQBkEAO48FDvsiZo qinA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711677257; x=1712282057; 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=1qqFZWrpXHSloU4DHzngdNGiVBp7dRUntmvVSQg8HHI=; b=U1qEEiB5eZZt51ia6VlVqLtByPAAmrToORH2AI591lDEe6+ZQtjtsRyAALWrWhF8AC t9QNjVcE0I8IS3RZinEl/gnKb+DR3VR9t9J5UwTSnFZZvcEkK1qGFdVaB1aQi28Odb8B RlZ4A9UNn7IR2X5CJPP6n5JnybF6Tq6WE6DkINFNnLPPKtVO4bA5s+OsE9noZamflKAD ZaG+j0leDssn4NgUATLwhTCoN+vES0chKf/e7my5lAug5r9fywrkKK2TDNDeIfVsNwmU pt+oQ1MoDNGFwJFyN56uqXADc5Pqn7F4sf66v6VbpqslZ7/ptWd5IJzj73PtAEztq9Qi t3WQ== X-Forwarded-Encrypted: i=1; AJvYcCXKhj2WrDLilDla+ImthT+ZJDEZVhRmizEM9wWR0DL7CRXG4N24f8mmTwQcCCYZ0VYnMGJmOtdqwpGyK54x19EEK9RxmTyVarpUHzHf X-Gm-Message-State: AOJu0YyEIErvCz5PJcKczoGzstQDDmCedpnRiYT6HeDZW6luMiGQuBmF M8uRd10DSTMuU98SIsuU4kePtblGIkyqigAj48EsoH1x8S1OVte1LN/B9QeT1MXdNXIDQd0B/2L Znw== X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:fcce:d6ab:804c:b94b]) (user=drosen job=sendgmr) by 2002:a0d:d816:0:b0:611:a254:8b9 with SMTP id a22-20020a0dd816000000b00611a25408b9mr254675ywe.0.1711677257071; Thu, 28 Mar 2024 18:54:17 -0700 (PDT) Date: Thu, 28 Mar 2024 18:53:23 -0700 In-Reply-To: <20240329015351.624249-1-drosen@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240329015351.624249-1-drosen@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240329015351.624249-9-drosen@google.com> Subject: [RFC PATCH v4 08/36] 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 , Eduard Zingerman , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jonathan Corbet , Joanne Koong , Mykola Lysenko , Christian Brauner , kernel-team@android.com, Daniel Rosenberg , Paul Lawrence Content-Type: text/plain; charset="UTF-8" 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 | 41 +++++++++++++++++++++++++++++++++++++++++ fs/fuse/file.c | 6 ++++++ fs/fuse/fuse_i.h | 4 +++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index a94d99ff9862..331b3f23ef78 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -210,6 +210,47 @@ 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); + struct timespec64 mtime, bmtime, ctime, bctime; + + 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; + + mtime = inode_get_mtime(fuse_inode); + bmtime = inode_get_mtime(backing_inode); + ctime = inode_get_ctime(fuse_inode); + bctime = inode_get_ctime(backing_inode); + if ((!timespec64_equal(&mtime, &bmtime) || + !timespec64_equal(&ctime, &bctime))) { + inode_set_mtime_to_ts(fuse_inode, bmtime); + inode_set_ctime_to_ts(fuse_inode, bctime); + } + touch_atime(&file->f_path); + + return ret; +} + /******************************************************************************* * Directory operations after here * ******************************************************************************/ diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 41a2e88e8646..b15a0c30fec8 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2486,6 +2486,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 FUSE_DIRECT_IO_ALLOW_MMAP isn't set. diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 08ee98b7bb95..5f76ba3c1e4b 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1455,7 +1455,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.44.0.478.gd926399ef9-goog