From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Trond Myklebust <trond.myklebust@hammerspace.com>,
Anna Schumaker <Anna.Schumaker@Netapp.com>,
Christoph Hellwig <hch@infradead.org>
Subject: [PATCH] nfs: Fix misuses of folio_shift() and folio_order()
Date: Tue, 28 May 2024 22:03:15 +0100 [thread overview]
Message-ID: <20240528210407.2158964-1-willy@infradead.org> (raw)
In-Reply-To: <20240527163616.1135968-1-hch@lst.de>
Page cache indices are in units of PAGE_SIZE, not in units of
the folio size. Revert the change in nfs_grow_file(), and
pass the inode to nfs_folio_length() so it can be reimplemented
in terms of folio_mkwrite_check_truncate() which handles this
correctly.
Fixes: 0c493b5cf16e ("NFS: Convert buffered writes to use folios")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>
Cc: Anna Schumaker <Anna.Schumaker@Netapp.com>
Cc: Christoph Hellwig <hch@infradead.org>
---
fs/nfs/file.c | 6 +++---
fs/nfs/internal.h | 16 +++++-----------
fs/nfs/read.c | 2 +-
fs/nfs/write.c | 9 +++++----
include/linux/pagemap.h | 4 ++--
5 files changed, 16 insertions(+), 21 deletions(-)
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 6bd127e6683d..723d78bbfe3f 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -301,7 +301,7 @@ EXPORT_SYMBOL_GPL(nfs_file_fsync);
static bool nfs_folio_is_full_write(struct folio *folio, loff_t pos,
unsigned int len)
{
- unsigned int pglen = nfs_folio_length(folio);
+ unsigned int pglen = nfs_folio_length(folio, folio->mapping->host);
unsigned int offset = offset_in_folio(folio, pos);
unsigned int end = offset + len;
@@ -386,7 +386,7 @@ static int nfs_write_end(struct file *file, struct address_space *mapping,
*/
if (!folio_test_uptodate(folio)) {
size_t fsize = folio_size(folio);
- unsigned pglen = nfs_folio_length(folio);
+ unsigned pglen = nfs_folio_length(folio, mapping->host);
unsigned end = offset + copied;
if (pglen == 0) {
@@ -610,7 +610,7 @@ static vm_fault_t nfs_vm_page_mkwrite(struct vm_fault *vmf)
folio_wait_writeback(folio);
- pagelen = nfs_folio_length(folio);
+ pagelen = nfs_folio_length(folio, inode);
if (pagelen == 0)
goto out_unlock;
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 9f0f4534744b..3b0236e67257 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -819,19 +819,13 @@ unsigned int nfs_page_length(struct page *page)
/*
* Determine the number of bytes of data the page contains
*/
-static inline size_t nfs_folio_length(struct folio *folio)
+static inline size_t nfs_folio_length(struct folio *folio, struct inode *inode)
{
- loff_t i_size = i_size_read(folio_file_mapping(folio)->host);
+ ssize_t ret = folio_mkwrite_check_truncate(folio, inode);
- if (i_size > 0) {
- pgoff_t index = folio_index(folio) >> folio_order(folio);
- pgoff_t end_index = (i_size - 1) >> folio_shift(folio);
- if (index < end_index)
- return folio_size(folio);
- if (index == end_index)
- return offset_in_folio(folio, i_size - 1) + 1;
- }
- return 0;
+ if (ret < 0)
+ ret = 0;
+ return ret;
}
/*
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index a142287d86f6..ba3bb496f832 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -296,7 +296,7 @@ int nfs_read_add_folio(struct nfs_pageio_descriptor *pgio,
unsigned int len, aligned_len;
int error;
- len = nfs_folio_length(folio);
+ len = nfs_folio_length(folio, inode);
if (len == 0)
return nfs_return_empty_folio(folio);
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 2329cbb0e446..7713ce7c5b3a 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -278,8 +278,8 @@ static void nfs_grow_file(struct folio *folio, unsigned int offset,
spin_lock(&inode->i_lock);
i_size = i_size_read(inode);
- end_index = ((i_size - 1) >> folio_shift(folio)) << folio_order(folio);
- if (i_size > 0 && folio_index(folio) < end_index)
+ end_index = (i_size - 1) >> PAGE_SHIFT;
+ if (i_size > 0 && folio->index < end_index)
goto out;
end = folio_file_pos(folio) + (loff_t)offset + (loff_t)count;
if (i_size >= end)
@@ -358,7 +358,8 @@ nfs_page_group_search_locked(struct nfs_page *head, unsigned int page_offset)
*/
static bool nfs_page_group_covers_page(struct nfs_page *req)
{
- unsigned int len = nfs_folio_length(nfs_page_to_folio(req));
+ struct folio *folio = nfs_page_to_folio(req);
+ unsigned int len = nfs_folio_length(folio, folio->mapping->host);
struct nfs_page *tmp;
unsigned int pos = 0;
@@ -1356,7 +1357,7 @@ int nfs_update_folio(struct file *file, struct folio *folio,
struct nfs_open_context *ctx = nfs_file_open_context(file);
struct address_space *mapping = folio_file_mapping(folio);
struct inode *inode = mapping->host;
- unsigned int pagelen = nfs_folio_length(folio);
+ unsigned int pagelen = nfs_folio_length(folio, inode);
int status = 0;
nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE);
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index c6aaceed0de6..df57d7361a9a 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -212,8 +212,8 @@ enum mapping_flags {
AS_FOLIO_ORDER_MAX = 21, /* Bits 16-25 are used for FOLIO_ORDER */
};
-#define AS_FOLIO_ORDER_MIN_MASK 0x001f0000
-#define AS_FOLIO_ORDER_MAX_MASK 0x03e00000
+#define AS_FOLIO_ORDER_MIN_MASK (31 << AS_FOLIO_ORDER_MIN)
+#define AS_FOLIO_ORDER_MAX_MASK (31 << AS_FOLIO_ORDER_MAX)
#define AS_FOLIO_ORDER_MASK (AS_FOLIO_ORDER_MIN_MASK | AS_FOLIO_ORDER_MAX_MASK)
/**
--
2.43.0
next prev parent reply other threads:[~2024-05-28 21:04 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-27 16:36 support large folios for NFS Christoph Hellwig
2024-05-27 16:36 ` [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios Christoph Hellwig
2024-05-27 18:17 ` Matthew Wilcox
2024-05-28 8:12 ` Christoph Hellwig
[not found] ` <CGME20240528152340eucas1p17ba2ad78d8ea869ef44cdeedb2601f80@eucas1p1.samsung.com>
2024-05-28 15:23 ` Daniel Gomez
2024-05-28 16:50 ` Matthew Wilcox
2024-05-28 19:01 ` Daniel Gomez
2024-06-11 10:47 ` Shaun Tancheff
2024-06-11 16:13 ` Christoph Hellwig
[not found] ` <1d87741b-7178-4791-aca2-da3ac3033552@gmail.com>
2024-06-12 4:02 ` Christoph Hellwig
2024-05-27 16:36 ` [PATCH 2/2] nfs: add support for " Christoph Hellwig
2024-05-27 19:43 ` support large folios for NFS Sagi Grimberg
2024-05-28 21:03 ` Matthew Wilcox (Oracle) [this message]
2024-05-29 5:15 ` [PATCH] nfs: Fix misuses of folio_shift() and folio_order() Christoph Hellwig
2024-05-29 6:30 ` Christoph Hellwig
2024-05-29 14:31 ` Trond Myklebust
2024-05-28 21:05 ` support large folios for NFS Matthew Wilcox
2024-05-29 5:14 ` Christoph Hellwig
2024-05-29 13:35 ` Trond Myklebust
2024-05-29 21:59 ` Trond Myklebust
2024-05-31 6:14 ` hch
2024-06-07 5:29 ` hch
2024-06-07 7:57 ` Cedric Blancher
2024-06-07 15:32 ` Trond Myklebust
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240528210407.2158964-1-willy@infradead.org \
--to=willy@infradead.org \
--cc=Anna.Schumaker@Netapp.com \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trond.myklebust@hammerspace.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).