All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] afs: Re-enable freezing once a page fault is interrupted
@ 2021-06-16 21:22 David Howells
  2021-06-18 20:52 ` Linus Torvalds
  0 siblings, 1 reply; 3+ messages in thread
From: David Howells @ 2021-06-16 21:22 UTC (permalink / raw)
  To: torvalds
  Cc: Matthew Wilcox (Oracle),
	linux-afs, dhowells, marc.dionne, linux-afs, linux-fsdevel,
	linux-kernel

From: Matthew Wilcox (Oracle) <willy@infradead.org>

If a task is killed during a page fault, it does not currently call
sb_end_pagefault(), which means that the filesystem cannot be frozen
at any time thereafter.  This may be reported by lockdep like this:

====================================
WARNING: fsstress/10757 still has locks held!
5.13.0-rc4-build4+ #91 Not tainted
------------------------------------
1 lock held by fsstress/10757:
 #0: ffff888104eac530
 (
sb_pagefaults

as filesystem freezing is modelled as a lock.

Fix this by removing all the direct returns from within the function,
and using 'ret' to indicate whether we were interrupted or successful.

Fixes: 1cf7a1518aef ("afs: Implement shared-writeable mmap")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: linux-afs@lists.infradead.org
Link: https://lore.kernel.org/r/20210616154900.1958373-1-willy@infradead.org/
---

 fs/afs/write.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/fs/afs/write.c b/fs/afs/write.c
index f722cb80a594..ff36800a7389 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -848,6 +848,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 	struct inode *inode = file_inode(file);
 	struct afs_vnode *vnode = AFS_FS_I(inode);
 	unsigned long priv;
+	vm_fault_t ret = VM_FAULT_RETRY;
 
 	_enter("{{%llx:%llu}},{%lx}", vnode->fid.vid, vnode->fid.vnode, page->index);
 
@@ -859,14 +860,14 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 #ifdef CONFIG_AFS_FSCACHE
 	if (PageFsCache(page) &&
 	    wait_on_page_fscache_killable(page) < 0)
-		return VM_FAULT_RETRY;
+		goto out;
 #endif
 
 	if (wait_on_page_writeback_killable(page))
-		return VM_FAULT_RETRY;
+		goto out;
 
 	if (lock_page_killable(page) < 0)
-		return VM_FAULT_RETRY;
+		goto out;
 
 	/* We mustn't change page->private until writeback is complete as that
 	 * details the portion of the page we need to write back and we might
@@ -874,7 +875,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 	 */
 	if (wait_on_page_writeback_killable(page) < 0) {
 		unlock_page(page);
-		return VM_FAULT_RETRY;
+		goto out;
 	}
 
 	priv = afs_page_dirty(page, 0, thp_size(page));
@@ -888,8 +889,10 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 	}
 	file_update_time(file);
 
+	ret = VM_FAULT_LOCKED;
+out:
 	sb_end_pagefault(inode->i_sb);
-	return VM_FAULT_LOCKED;
+	return ret;
 }
 
 /*



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] afs: Re-enable freezing once a page fault is interrupted
  2021-06-16 21:22 [PATCH] afs: Re-enable freezing once a page fault is interrupted David Howells
@ 2021-06-18 20:52 ` Linus Torvalds
  0 siblings, 0 replies; 3+ messages in thread
From: Linus Torvalds @ 2021-06-18 20:52 UTC (permalink / raw)
  To: David Howells
  Cc: Matthew Wilcox (Oracle),
	linux-afs, Marc Dionne, linux-fsdevel, Linux Kernel Mailing List

On Wed, Jun 16, 2021 at 2:22 PM David Howells <dhowells@redhat.com> wrote:
>
> If a task is killed during a page fault, it does not currently call
> sb_end_pagefault(), which means that the filesystem cannot be frozen
> at any time thereafter.  This may be reported by lockdep like this:

I've applied this patch.

Everything in my screams "the sb_start/end_pagefault() code is
completely broken", but in the meantime this patch fixes the immediate
bug.

I suspect that the whole sb_start/end_pagefault thing should just go
away entirely, and the freezer should be re-examined. Alternatively,
it should just be done by generic code, not by the filesystem.

But it is what it is.

           Linus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] afs: Re-enable freezing once a page fault is interrupted
@ 2021-06-16 15:49 Matthew Wilcox (Oracle)
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Wilcox (Oracle) @ 2021-06-16 15:49 UTC (permalink / raw)
  To: David Howells, Marc Dionne, linux-afs, linux-kernel, linux-fsdevel
  Cc: Matthew Wilcox (Oracle)

If a task is killed during a page fault, it does not currently call
sb_end_pagefault(), which means that the filesystem cannot be frozen
at any time thereafter.  This may be reported by lockdep like this:

====================================
WARNING: fsstress/10757 still has locks held!
5.13.0-rc4-build4+ #91 Not tainted
------------------------------------
1 lock held by fsstress/10757:
 #0: ffff888104eac530
 (
sb_pagefaults

as filesystem freezing is modelled as a lock.

Fix this by removing all the direct returns from within the function,
and using 'ret' to indicate whether we were interrupted or successful.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/afs/write.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/fs/afs/write.c b/fs/afs/write.c
index a523bb86915d..62dd906f9b72 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -832,6 +832,7 @@ int afs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
  */
 vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 {
+	vm_fault_t ret = VM_FAULT_RETRY;
 	struct page *page = thp_head(vmf->page);
 	struct file *file = vmf->vma->vm_file;
 	struct inode *inode = file_inode(file);
@@ -848,14 +849,14 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 #ifdef CONFIG_AFS_FSCACHE
 	if (PageFsCache(page) &&
 	    wait_on_page_fscache_killable(page) < 0)
-		return VM_FAULT_RETRY;
+		goto out;
 #endif
 
 	if (wait_on_page_writeback_killable(page))
-		return VM_FAULT_RETRY;
+		goto out;
 
 	if (lock_page_killable(page) < 0)
-		return VM_FAULT_RETRY;
+		goto out;
 
 	/* We mustn't change page->private until writeback is complete as that
 	 * details the portion of the page we need to write back and we might
@@ -863,7 +864,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 	 */
 	if (wait_on_page_writeback_killable(page) < 0) {
 		unlock_page(page);
-		return VM_FAULT_RETRY;
+		goto out;
 	}
 
 	priv = afs_page_dirty(page, 0, thp_size(page));
@@ -877,8 +878,10 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 	}
 	file_update_time(file);
 
+	ret = VM_FAULT_LOCKED;
+out:
 	sb_end_pagefault(inode->i_sb);
-	return VM_FAULT_LOCKED;
+	return ret;
 }
 
 /*
-- 
2.30.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-18 20:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-16 21:22 [PATCH] afs: Re-enable freezing once a page fault is interrupted David Howells
2021-06-18 20:52 ` Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
2021-06-16 15:49 Matthew Wilcox (Oracle)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.