* [PATCH v2 0/2] zonefs: Fix data corruption and error return
@ 2023-03-30 1:54 Damien Le Moal
2023-03-30 1:54 ` [PATCH v2 1/2] zonefs: Always invalidate last cached page on append write Damien Le Moal
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Damien Le Moal @ 2023-03-30 1:54 UTC (permalink / raw)
To: linux-fsdevel; +Cc: Johannes Thumshirn, Hans Holmberg, Christoph Hellwig
Patch 1 fixes a potential data corruption when the last page of the
inode is cached and a sync append direct write partially modify the
data of that page on disk. The second patch avoids propagating to user
space the -ENOTBLK error potentially returned by iomap_dio_rw().
Changes from v1:
- Reworked patch 1 commit message and use an exact end argument for the
call to invalidate_inode_pages2_range().
- Added patch 2.
Damien Le Moal (2):
zonefs: Always invalidate last cached page on append write
zonefs: Do not propagate iomap_dio_rw() ENOTBLK error to user space
fs/zonefs/file.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/2] zonefs: Always invalidate last cached page on append write
2023-03-30 1:54 [PATCH v2 0/2] zonefs: Fix data corruption and error return Damien Le Moal
@ 2023-03-30 1:54 ` Damien Le Moal
2023-03-30 1:58 ` Christoph Hellwig
2023-03-30 1:54 ` [PATCH v2 2/2] zonefs: Do not propagate iomap_dio_rw() ENOTBLK error to user space Damien Le Moal
2023-03-30 8:45 ` [PATCH v2 0/2] zonefs: Fix data corruption and error return Johannes Thumshirn
2 siblings, 1 reply; 7+ messages in thread
From: Damien Le Moal @ 2023-03-30 1:54 UTC (permalink / raw)
To: linux-fsdevel; +Cc: Johannes Thumshirn, Hans Holmberg, Christoph Hellwig
When a direct append write is executed, the append offset may correspond
to the last page of a sequential file inode which might have been cached
already by buffered reads, page faults with mmap-read or non-direct
readahead. To ensure that the on-disk and cached data is consistant for
such last cached page, make sure to always invalidate it in
zonefs_file_dio_append(). If the invalidation fails, return -EBUSY to
userspace to differentiate from IO errors.
This invalidation will always be a no-op when the FS block size (device
zone write granularity) is equal to the page size (e.g. 4K).
Reported-by: Hans Holmberg <Hans.Holmberg@wdc.com>
Fixes: 02ef12a663c7 ("zonefs: use REQ_OP_ZONE_APPEND for sync DIO")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
---
fs/zonefs/file.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c
index 617e4f9db42e..c6ab2732955e 100644
--- a/fs/zonefs/file.c
+++ b/fs/zonefs/file.c
@@ -382,6 +382,7 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)
struct zonefs_zone *z = zonefs_inode_zone(inode);
struct block_device *bdev = inode->i_sb->s_bdev;
unsigned int max = bdev_max_zone_append_sectors(bdev);
+ pgoff_t start, end;
struct bio *bio;
ssize_t size = 0;
int nr_pages;
@@ -390,6 +391,19 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)
max = ALIGN_DOWN(max << SECTOR_SHIFT, inode->i_sb->s_blocksize);
iov_iter_truncate(from, max);
+ /*
+ * If the inode block size (zone write granularity) is smaller than the
+ * page size, we may be appending data belonging to the last page of the
+ * inode straddling inode->i_size, with that page already cached due to
+ * a buffered read or readahead. So make sure to invalidate that page.
+ * This will always be a no-op for the case where the block size is
+ * equal to the page size.
+ */
+ start = iocb->ki_pos >> PAGE_SHIFT;
+ end = (iocb->ki_pos + iov_iter_count(from) - 1) >> PAGE_SHIFT;
+ if (invalidate_inode_pages2_range(inode->i_mapping, start, end))
+ return -EBUSY;
+
nr_pages = iov_iter_npages(from, BIO_MAX_VECS);
if (!nr_pages)
return 0;
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] zonefs: Do not propagate iomap_dio_rw() ENOTBLK error to user space
2023-03-30 1:54 [PATCH v2 0/2] zonefs: Fix data corruption and error return Damien Le Moal
2023-03-30 1:54 ` [PATCH v2 1/2] zonefs: Always invalidate last cached page on append write Damien Le Moal
@ 2023-03-30 1:54 ` Damien Le Moal
2023-03-30 1:58 ` Christoph Hellwig
2023-03-30 8:45 ` [PATCH v2 0/2] zonefs: Fix data corruption and error return Johannes Thumshirn
2 siblings, 1 reply; 7+ messages in thread
From: Damien Le Moal @ 2023-03-30 1:54 UTC (permalink / raw)
To: linux-fsdevel; +Cc: Johannes Thumshirn, Hans Holmberg, Christoph Hellwig
The call to invalidate_inode_pages2_range() in __iomap_dio_rw() may
fail, in which case -ENOTBLK is returned and this error code is
propagated back to user space trhough iomap_dio_rw() ->
zonefs_file_dio_write() return chain. This error code is fairly obscure
and may confuse the user. Avoid this and be consistent with the behavior
of zonefs_file_dio_append() for similar invalidate_inode_pages2_range()
errors by returning -EBUSY to user space when iomap_dio_rw() returns
-ENOTBLK.
Suggested-by: Christoph Hellwig <hch@infradead.org>
Fixes: 8dcc1a9d90c1 ("fs: New zonefs file system")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
---
fs/zonefs/file.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c
index c6ab2732955e..132f01d3461f 100644
--- a/fs/zonefs/file.c
+++ b/fs/zonefs/file.c
@@ -581,11 +581,21 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from)
append = sync;
}
- if (append)
+ if (append) {
ret = zonefs_file_dio_append(iocb, from);
- else
+ } else {
+ /*
+ * iomap_dio_rw() may return ENOTBLK if there was an issue with
+ * page invalidation. Overwrite that error code with EBUSY to
+ * be consistent with zonefs_file_dio_append() return value for
+ * similar issues.
+ */
ret = iomap_dio_rw(iocb, from, &zonefs_write_iomap_ops,
&zonefs_write_dio_ops, 0, NULL, 0);
+ if (ret == -ENOTBLK)
+ ret = -EBUSY;
+ }
+
if (zonefs_zone_is_seq(z) &&
(ret > 0 || ret == -EIOCBQUEUED)) {
if (ret > 0)
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] zonefs: Always invalidate last cached page on append write
2023-03-30 1:54 ` [PATCH v2 1/2] zonefs: Always invalidate last cached page on append write Damien Le Moal
@ 2023-03-30 1:58 ` Christoph Hellwig
0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2023-03-30 1:58 UTC (permalink / raw)
To: Damien Le Moal
Cc: linux-fsdevel, Johannes Thumshirn, Hans Holmberg, Christoph Hellwig
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] zonefs: Do not propagate iomap_dio_rw() ENOTBLK error to user space
2023-03-30 1:54 ` [PATCH v2 2/2] zonefs: Do not propagate iomap_dio_rw() ENOTBLK error to user space Damien Le Moal
@ 2023-03-30 1:58 ` Christoph Hellwig
0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2023-03-30 1:58 UTC (permalink / raw)
To: Damien Le Moal
Cc: linux-fsdevel, Johannes Thumshirn, Hans Holmberg, Christoph Hellwig
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/2] zonefs: Fix data corruption and error return
2023-03-30 1:54 [PATCH v2 0/2] zonefs: Fix data corruption and error return Damien Le Moal
2023-03-30 1:54 ` [PATCH v2 1/2] zonefs: Always invalidate last cached page on append write Damien Le Moal
2023-03-30 1:54 ` [PATCH v2 2/2] zonefs: Do not propagate iomap_dio_rw() ENOTBLK error to user space Damien Le Moal
@ 2023-03-30 8:45 ` Johannes Thumshirn
2023-03-30 11:25 ` Hans Holmberg
2 siblings, 1 reply; 7+ messages in thread
From: Johannes Thumshirn @ 2023-03-30 8:45 UTC (permalink / raw)
To: Damien Le Moal, linux-fsdevel; +Cc: Hans Holmberg, Christoph Hellwig
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/2] zonefs: Fix data corruption and error return
2023-03-30 8:45 ` [PATCH v2 0/2] zonefs: Fix data corruption and error return Johannes Thumshirn
@ 2023-03-30 11:25 ` Hans Holmberg
0 siblings, 0 replies; 7+ messages in thread
From: Hans Holmberg @ 2023-03-30 11:25 UTC (permalink / raw)
To: Johannes Thumshirn
Cc: Damien Le Moal, linux-fsdevel, Hans Holmberg, Christoph Hellwig
Retested with this series, and it solves the reported issue.
Tested-by: Hans Holmberg <hans.holmberg@wdc.com>
On Thu, Mar 30, 2023 at 10:46 AM Johannes Thumshirn
<Johannes.Thumshirn@wdc.com> wrote:
>
> Looks good,
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-03-30 11:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-30 1:54 [PATCH v2 0/2] zonefs: Fix data corruption and error return Damien Le Moal
2023-03-30 1:54 ` [PATCH v2 1/2] zonefs: Always invalidate last cached page on append write Damien Le Moal
2023-03-30 1:58 ` Christoph Hellwig
2023-03-30 1:54 ` [PATCH v2 2/2] zonefs: Do not propagate iomap_dio_rw() ENOTBLK error to user space Damien Le Moal
2023-03-30 1:58 ` Christoph Hellwig
2023-03-30 8:45 ` [PATCH v2 0/2] zonefs: Fix data corruption and error return Johannes Thumshirn
2023-03-30 11:25 ` Hans Holmberg
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).