Skip to content

Commit c6a90fe

Browse files
Matthew Wilcox (Oracle)brauner
authored andcommitted
netfs: Fix a few minor bugs in netfs_page_mkwrite()
We can't return with VM_FAULT_SIGBUS | VM_FAULT_LOCKED; the core code will not unlock the folio in this instance. Introduce a new "unlock" error exit to handle this case. Use it to handle the "folio is truncated" check, and change the "writeback interrupted by a fatal signal" to do a NOPAGE exit instead of letting the core code install the folio currently under writeback before killing the process. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent fcd4904 commit c6a90fe

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

fs/netfs/buffered_write.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,9 @@ EXPORT_SYMBOL(netfs_file_write_iter);
491491

492492
/*
493493
* Notification that a previously read-only page is about to become writable.
494-
* Note that the caller indicates a single page of a multipage folio.
494+
* The caller indicates the precise page that needs to be written to, but
495+
* we only track group on a per-folio basis, so we block more often than
496+
* we might otherwise.
495497
*/
496498
vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_group)
497499
{
@@ -501,7 +503,7 @@ vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_gr
501503
struct address_space *mapping = file->f_mapping;
502504
struct inode *inode = file_inode(file);
503505
struct netfs_inode *ictx = netfs_inode(inode);
504-
vm_fault_t ret = VM_FAULT_RETRY;
506+
vm_fault_t ret = VM_FAULT_NOPAGE;
505507
int err;
506508

507509
_enter("%lx", folio->index);
@@ -510,21 +512,15 @@ vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_gr
510512

511513
if (folio_lock_killable(folio) < 0)
512514
goto out;
513-
if (folio->mapping != mapping) {
514-
folio_unlock(folio);
515-
ret = VM_FAULT_NOPAGE;
516-
goto out;
517-
}
518-
519-
if (folio_wait_writeback_killable(folio)) {
520-
ret = VM_FAULT_LOCKED;
521-
goto out;
522-
}
515+
if (folio->mapping != mapping)
516+
goto unlock;
517+
if (folio_wait_writeback_killable(folio) < 0)
518+
goto unlock;
523519

524520
/* Can we see a streaming write here? */
525521
if (WARN_ON(!folio_test_uptodate(folio))) {
526-
ret = VM_FAULT_SIGBUS | VM_FAULT_LOCKED;
527-
goto out;
522+
ret = VM_FAULT_SIGBUS;
523+
goto unlock;
528524
}
529525

530526
group = netfs_folio_group(folio);
@@ -559,5 +555,8 @@ vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_gr
559555
out:
560556
sb_end_pagefault(inode->i_sb);
561557
return ret;
558+
unlock:
559+
folio_unlock(folio);
560+
goto out;
562561
}
563562
EXPORT_SYMBOL(netfs_page_mkwrite);

0 commit comments

Comments
 (0)