* [PATCH v1] exfat: mark straddling folio RO for 4K block size
@ 2026-09-30 10:43 Yuezhang Mo
2026-10-01 5:05 ` Chi Zhiling
0 siblings, 1 reply; 5+ messages in thread
From: Yuezhang Mo @ 2026-09-30 10:43 UTC (permalink / raw)
To: exfat; +Cc: linux-kernel, linkinjeon, sj1557.seo, chizhiling, dxdt, Yuezhang Mo
The maximum file system block size supported by exFAT is 4096 bytes.
When extending a file whose EOF is not page aligned, the straddling
folio must be marked RO so that a subsequent mmap write can trigger
->page_mkwrite() and extend the valid data size.
This is normally handled by pagecache_isize_extended(), which marks
the straddling folio RO when the filesystem block size is smaller
than 4K. However, pagecache_isize_extended() returns early when the
filesystem block size is PAGE_SIZE:
if (from >= to || bsize >= PAGE_SIZE)
return;
As a result, on an exFAT filesystem with a 4K block size, the PTE
for the straddling folio remains writable after a file extension.
A subsequent mmap write operation that modifies the straddling folio
beyond the old EOF, will not trigger ->page_mkwrite(), leaving
valid_size unchanged.
This was found by running xfstests generic/030 on a block device with
a 4096-byte sector size: the test fails without this fix and passes
with it.
Fix this by marking the straddling folio RO in exfat_cont_expand()
when the filesystem block size is 4K and the old EOF is not page
aligned. This mirrors what pagecache_isize_extended() does for smaller
filesystem block sizes.
Fixes: 82a81a7352bc ("exfat: add iomap buffered I/O support")
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
---
fs/exfat/file.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index a2a9ee1a20048..390bfae3f3aa4 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -17,6 +17,7 @@
#include <linux/fileattr.h>
#include <linux/iomap.h>
#include <linux/pagemap.h>
+#include <linux/rmap.h>
#include "exfat_raw.h"
#include "exfat_fs.h"
@@ -91,6 +92,20 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
*/
pagecache_isize_extended(inode, oldsize, inode->i_size);
+ if (i_blocksize(inode) >= PAGE_SIZE && (oldsize & (PAGE_SIZE - 1))) {
+ struct folio *folio;
+
+ folio = filemap_lock_folio(inode->i_mapping,
+ oldsize >> PAGE_SHIFT);
+ if (!IS_ERR(folio)) {
+ if (folio_mkclean(folio))
+ folio_mark_dirty(folio);
+
+ folio_unlock(folio);
+ folio_put(folio);
+ }
+ }
+
inode->i_blocks = round_up(size, sbi->cluster_size) >> 9;
mark_inode_dirty(inode);
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] exfat: mark straddling folio RO for 4K block size
2026-09-30 10:43 [PATCH v1] exfat: mark straddling folio RO for 4K block size Yuezhang Mo
@ 2026-10-01 5:05 ` Chi Zhiling
2026-10-09 2:46 ` Yuezhang.Mo
0 siblings, 1 reply; 5+ messages in thread
From: Chi Zhiling @ 2026-10-01 5:05 UTC (permalink / raw)
To: Yuezhang Mo, exfat; +Cc: linux-kernel, linkinjeon, sj1557.seo, dxdt
On 9/30/26 6:43 PM, Yuezhang Mo wrote:
> The maximum file system block size supported by exFAT is 4096 bytes.
> When extending a file whose EOF is not page aligned, the straddling
> folio must be marked RO so that a subsequent mmap write can trigger
> ->page_mkwrite() and extend the valid data size.
>
> This is normally handled by pagecache_isize_extended(), which marks
> the straddling folio RO when the filesystem block size is smaller
> than 4K. However, pagecache_isize_extended() returns early when the
> filesystem block size is PAGE_SIZE:
>
> if (from >= to || bsize >= PAGE_SIZE)
> return;
>
> As a result, on an exFAT filesystem with a 4K block size, the PTE
> for the straddling folio remains writable after a file extension.
> A subsequent mmap write operation that modifies the straddling folio
> beyond the old EOF, will not trigger ->page_mkwrite(), leaving
> valid_size unchanged.
>
> This was found by running xfstests generic/030 on a block device with
> a 4096-byte sector size: the test fails without this fix and passes
> with it.
>
> Fix this by marking the straddling folio RO in exfat_cont_expand()
> when the filesystem block size is 4K and the old EOF is not page
> aligned. This mirrors what pagecache_isize_extended() does for smaller
> filesystem block sizes.
>
> Fixes: 82a81a7352bc ("exfat: add iomap buffered I/O support")
> Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
> ---
> fs/exfat/file.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/fs/exfat/file.c b/fs/exfat/file.c
> index a2a9ee1a20048..390bfae3f3aa4 100644
> --- a/fs/exfat/file.c
> +++ b/fs/exfat/file.c
> @@ -17,6 +17,7 @@
> #include <linux/fileattr.h>
> #include <linux/iomap.h>
> #include <linux/pagemap.h>
> +#include <linux/rmap.h>
>
> #include "exfat_raw.h"
> #include "exfat_fs.h"
> @@ -91,6 +92,20 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
> */
> pagecache_isize_extended(inode, oldsize, inode->i_size);
>
> + if (i_blocksize(inode) >= PAGE_SIZE && (oldsize & (PAGE_SIZE - 1))) {
> + struct folio *folio;
> +
> + folio = filemap_lock_folio(inode->i_mapping,
> + oldsize >> PAGE_SHIFT);
> + if (!IS_ERR(folio)) {
> + if (folio_mkclean(folio))
> + folio_mark_dirty(folio);
> +
> + folio_unlock(folio);
> + folio_put(folio);
> + }
> + }
I think fixing this issue specifically for the block size = 4K case may
not be thorough enough, because pagecache_isize_extended() may also fail
to work when the block size is smaller than 4K.
We should set the folio containing valid_size to RO whenever valid_size
!= i_size and valid_size is not page-aligned, regardless of the block size.
> +
> inode->i_blocks = round_up(size, sbi->cluster_size) >> 9;
> mark_inode_dirty(inode);
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] exfat: mark straddling folio RO for 4K block size
2026-10-01 5:05 ` Chi Zhiling
@ 2026-10-09 2:46 ` Yuezhang.Mo
2026-10-09 6:12 ` Chi Zhiling
0 siblings, 1 reply; 5+ messages in thread
From: Yuezhang.Mo @ 2026-10-09 2:46 UTC (permalink / raw)
To: Chi Zhiling, exfat; +Cc: linux-kernel, linkinjeon, sj1557.seo, dxdt
> > #include "exfat_raw.h"
> > #include "exfat_fs.h"
> > @@ -91,6 +92,20 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
> > */
> > pagecache_isize_extended(inode, oldsize, inode->i_size);
> >
> > + if (i_blocksize(inode) >= PAGE_SIZE && (oldsize & (PAGE_SIZE - 1))) {
> > + struct folio *folio;
> > +
> > + folio = filemap_lock_folio(inode->i_mapping,
> > + oldsize >> PAGE_SHIFT);
> > + if (!IS_ERR(folio)) {
> > + if (folio_mkclean(folio))
> > + folio_mark_dirty(folio);
> > +
> > + folio_unlock(folio);
> > + folio_put(folio);
> > + }
> > + }
>
> I think fixing this issue specifically for the block size = 4K case may
> not be thorough enough, because pagecache_isize_extended() may also fail
> to work when the block size is smaller than 4K.
What condition might pagecache_isize_extended() fail to work when the block
size is smaller than 4K?
>
> We should set the folio containing valid_size to RO whenever valid_size
> != i_size and valid_size is not page-aligned, regardless of the block size.
We should set the folio containing oldsize to RO, rather than valid_size.
This is because, when the folio containing oldsize was first set to RW, oldsize
constrained valid_size, after the file size is subsequently expanded, that
constraint changes, necessitating a re-setting of valid_size.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] exfat: mark straddling folio RO for 4K block size
2026-10-09 2:46 ` Yuezhang.Mo
@ 2026-10-09 6:12 ` Chi Zhiling
2026-10-09 7:57 ` Yuezhang.Mo
0 siblings, 1 reply; 5+ messages in thread
From: Chi Zhiling @ 2026-10-09 6:12 UTC (permalink / raw)
To: Yuezhang.Mo; +Cc: linux-kernel, linkinjeon, sj1557.seo, dxdt, exfat
On 10/9/26 10:46 AM, Yuezhang.Mo@sony.com wrote:
>>> #include "exfat_raw.h"
>>> #include "exfat_fs.h"
>>> @@ -91,6 +92,20 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
>>> */
>>> pagecache_isize_extended(inode, oldsize, inode->i_size);
>>>
>>> + if (i_blocksize(inode) >= PAGE_SIZE && (oldsize & (PAGE_SIZE - 1))) {
>>> + struct folio *folio;
>>> +
>>> + folio = filemap_lock_folio(inode->i_mapping,
>>> + oldsize >> PAGE_SHIFT);
>>> + if (!IS_ERR(folio)) {
>>> + if (folio_mkclean(folio))
>>> + folio_mark_dirty(folio);
>>> +
>>> + folio_unlock(folio);
>>> + folio_put(folio);
>>> + }
>>> + }
>>
>> I think fixing this issue specifically for the block size = 4K case may
>> not be thorough enough, because pagecache_isize_extended() may also fail
>> to work when the block size is smaller than 4K.
>
> What condition might pagecache_isize_extended() fail to work when the block
> size is smaller than 4K?
I didn’t explain this clearly. What I meant is that the issue is not the
block size, but the fact that VDL in exFAT is not block-aligned.
pagecache_isize_extended is designed to work at block granularity, so it
won’t work either if oldsize and newsize fall within the same block.
/* Page straddling @from will not have any hole block created? */
rounded_from = round_up(from, bsize);
if (to <= rounded_from || !(rounded_from & (PAGE_SIZE - 1)))
return;
>
>>
>> We should set the folio containing valid_size to RO whenever valid_size
>> != i_size and valid_size is not page-aligned, regardless of the block size.
>
> We should set the folio containing oldsize to RO, rather than valid_size.
> This is because, when the folio containing oldsize was first set to RW, oldsize
> constrained valid_size, after the file size is subsequently expanded, that
> constraint changes, necessitating a re-setting of valid_size.
Yes, using oldsize is better.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] exfat: mark straddling folio RO for 4K block size
2026-10-09 6:12 ` Chi Zhiling
@ 2026-10-09 7:57 ` Yuezhang.Mo
0 siblings, 0 replies; 5+ messages in thread
From: Yuezhang.Mo @ 2026-10-09 7:57 UTC (permalink / raw)
To: Chi Zhiling; +Cc: linux-kernel, linkinjeon, sj1557.seo, dxdt, exfat
> On 10/9/26 10:46 AM, Yuezhang.Mo@sony.com wrote:
>>>> #include "exfat_raw.h"
>>>> #include "exfat_fs.h"
>>>> @@ -91,6 +92,20 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
>>>> */
>>>> pagecache_isize_extended(inode, oldsize, inode->i_size);
>>>>
>>>> + if (i_blocksize(inode) >= PAGE_SIZE && (oldsize & (PAGE_SIZE - 1))) {
>>>> + struct folio *folio;
>>>> +
>>>> + folio = filemap_lock_folio(inode->i_mapping,
>>>> + oldsize >> PAGE_SHIFT);
>>>> + if (!IS_ERR(folio)) {
>>>> + if (folio_mkclean(folio))
>>>> + folio_mark_dirty(folio);
>>>> +
>>>> + folio_unlock(folio);
>>>> + folio_put(folio);
>>>> + }
>>>> + }
>>>
>>> I think fixing this issue specifically for the block size = 4K case may
>>> not be thorough enough, because pagecache_isize_extended() may also fail
>>> to work when the block size is smaller than 4K.
>>
>> What condition might pagecache_isize_extended() fail to work when the block
>> size is smaller than 4K?
>
> I didn’t explain this clearly. What I meant is that the issue is not the
> block size, but the fact that VDL in exFAT is not block-aligned.
> pagecache_isize_extended is designed to work at block granularity, so it
> won’t work either if oldsize and newsize fall within the same block.
>
> /* Page straddling @from will not have any hole block created? */
> rounded_from = round_up(from, bsize);
> if (to <= rounded_from || !(rounded_from & (PAGE_SIZE - 1)))
> return;
I got it, thank you for the explanation.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-10-09 7:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-30 10:43 [PATCH v1] exfat: mark straddling folio RO for 4K block size Yuezhang Mo
2026-10-01 5:05 ` Chi Zhiling
2026-10-09 2:46 ` Yuezhang.Mo
2026-10-09 6:12 ` Chi Zhiling
2026-10-09 7:57 ` Yuezhang.Mo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®