[PATCH v2 09/20] f2fs: support subpage blocks in pinned files

From: Daeho Jeong

Date: Sun Nov 15 2026 - 23:09:24 EST


From: Daeho Jeong <daehojeong@xxxxxxxxxx>

Pinned files must not allocate blocks outside fallocate(). As write()
does, return -EIO from page_mkwrite when the folio range up to EOF is
not fully allocated, and remove the -EOPNOTSUPP checks.

page_mkwrite keeps failing a device aliasing file with -EIO, as it does
when the block size equals PAGE_SIZE. Its block addresses are only in
the extent cache, so f2fs_overwrite_io() does not catch it.

Signed-off-by: Daeho Jeong <daehojeong@xxxxxxxxxx>
---
fs/f2fs/file.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index bec7988ca54b..72c601d240d4 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -142,7 +142,8 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
struct folio *folio = page_folio(vmf->page);
struct inode *inode = file_inode(vmf->vma->vm_file);
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
- bool need_alloc = !f2fs_is_pinned_file(inode);
+ bool pinned = f2fs_is_pinned_file(inode);
+ bool need_alloc = !pinned;
pgoff_t pidx = folio->index + folio_page_idx(folio, vmf->page);
loff_t pos = (loff_t)pidx << PAGE_SHIFT;
pgoff_t bidx = F2FS_BYTES_TO_BLK(sbi, pos);
@@ -245,6 +246,19 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
nr = DIV_ROUND_UP(dirty_len, PAGE_SIZE);

if (f2fs_has_subpage_blocks(sbi)) {
+ /*
+ * A device aliasing file has its block addresses only in the
+ * extent cache, where f2fs_overwrite_io() finds them. Fail it
+ * as f2fs_get_block_mkwrite() does.
+ */
+ if (pinned &&
+ (IS_DEVICE_ALIASING(inode) ||
+ !f2fs_overwrite_io(inode, folio_pos(folio), dirty_len))) {
+ folio_unlock(folio);
+ err = -EIO;
+ goto out_sem;
+ }
+
/*
* A writable PTE covers the whole base folio. Like ext4's
* block_page_mkwrite(), prepare every filesystem block through EOF
@@ -2285,8 +2299,7 @@ static long f2fs_fallocate(struct file *file, int mode,

if (f2fs_has_subpage_blocks(F2FS_I_SB(inode))) {
if ((mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)) ||
- f2fs_is_pinned_file(inode) || f2fs_is_atomic_file(inode) ||
- f2fs_compressed_file(inode)) {
+ f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode)) {
ret = -EOPNOTSUPP;
goto out;
}
@@ -3828,9 +3841,6 @@ static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg)
__u32 pin;
int ret = 0;

- if (f2fs_has_subpage_blocks(sbi))
- return -EOPNOTSUPP;
-
if (get_user(pin, (__u32 __user *)arg))
return -EFAULT;

--
2.56.0.611.g1030f0b940-goog