All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] cachefiles, afs: mm wait fixes
@ 2021-03-23 11:53 David Howells
  2021-03-23 11:53 ` [PATCH 1/3] fs/cachefiles: Remove wait_bit_key layout dependency David Howells
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: David Howells @ 2021-03-23 11:53 UTC (permalink / raw)
  To: linux-cachefs, linux-afs
  Cc: Christoph Hellwig, Matthew Wilcox (Oracle),
	linux-mm, dhowells, Matthew Wilcox (Oracle),
	Christoph Hellwig, linux-fsdevel, linux-kernel


Here are some patches to fix page waiting-related issues in cachefiles and
afs[1]:

 (1) In cachefiles, remove the use of the wait_bit_key struct to access
     something that's actually in wait_page_key format.  The proper struct
     is now available in the header, so that should be used instead.

 (2) Add a proper wait function for waiting killably on the page writeback
     flag.  This includes a recent bugfix here (presumably commit
     c2407cf7d22d0c0d94cf20342b3b8f06f1d904e7).

 (3) In afs, use the function added in (2) rather than using
     wait_on_page_bit_killable() which doesn't have the aforementioned
     bugfix.

     Note that I modified this to work with the upstream code where the
     page pointer isn't cached in a local variable.

The patches can be found here:

	https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=afs-fixes

David

Link: https://lore.kernel.org/r/20210320054104.1300774-1-willy@infradead.org[1]

---
Matthew Wilcox (Oracle) (3):
      fs/cachefiles: Remove wait_bit_key layout dependency
      mm/writeback: Add wait_on_page_writeback_killable
      afs: Use wait_on_page_writeback_killable


 fs/afs/write.c          |  3 +--
 include/linux/pagemap.h |  1 +
 mm/page-writeback.c     | 16 ++++++++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)



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

* [PATCH 1/3] fs/cachefiles: Remove wait_bit_key layout dependency
  2021-03-23 11:53 [PATCH 0/3] cachefiles, afs: mm wait fixes David Howells
@ 2021-03-23 11:53 ` David Howells
  2021-03-23 11:53 ` [PATCH 2/3] mm/writeback: Add wait_on_page_writeback_killable David Howells
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David Howells @ 2021-03-23 11:53 UTC (permalink / raw)
  To: linux-cachefs, linux-afs
  Cc: Matthew Wilcox (Oracle),
	Christoph Hellwig, linux-mm, dhowells, Matthew Wilcox (Oracle),
	Christoph Hellwig, linux-fsdevel, linux-kernel

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

Cachefiles was relying on wait_page_key and wait_bit_key being the
same layout, which is fragile.  Now that wait_page_key is exposed in
the pagemap.h header, we can remove that fragility

A comment on the need to maintain structure layout equivalence was added by
Linus[1] and that is no longer applicable.

Fixes: 62906027091f ("mm: add PageWaiters indicating tasks are waiting for a page bit")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: linux-cachefs@redhat.com
cc: linux-mm@kvack.org
Link: https://lore.kernel.org/r/20210320054104.1300774-2-willy@infradead.org/
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3510ca20ece0150af6b10c77a74ff1b5c198e3e2 [1]
---

 fs/cachefiles/rdwr.c    |    7 +++----
 include/linux/pagemap.h |    1 -
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
index e027c718ca01..8ffc40e84a59 100644
--- a/fs/cachefiles/rdwr.c
+++ b/fs/cachefiles/rdwr.c
@@ -24,17 +24,16 @@ static int cachefiles_read_waiter(wait_queue_entry_t *wait, unsigned mode,
 		container_of(wait, struct cachefiles_one_read, monitor);
 	struct cachefiles_object *object;
 	struct fscache_retrieval *op = monitor->op;
-	struct wait_bit_key *key = _key;
+	struct wait_page_key *key = _key;
 	struct page *page = wait->private;
 
 	ASSERT(key);
 
 	_enter("{%lu},%u,%d,{%p,%u}",
 	       monitor->netfs_page->index, mode, sync,
-	       key->flags, key->bit_nr);
+	       key->page, key->bit_nr);
 
-	if (key->flags != &page->flags ||
-	    key->bit_nr != PG_locked)
+	if (key->page != page || key->bit_nr != PG_locked)
 		return 0;
 
 	_debug("--- monitor %p %lx ---", page, page->flags);
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 20225b067583..8f4daac6eb4b 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -559,7 +559,6 @@ static inline pgoff_t linear_page_index(struct vm_area_struct *vma,
 	return pgoff;
 }
 
-/* This has the same layout as wait_bit_key - see fs/cachefiles/rdwr.c */
 struct wait_page_key {
 	struct page *page;
 	int bit_nr;



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

* [PATCH 2/3] mm/writeback: Add wait_on_page_writeback_killable
  2021-03-23 11:53 [PATCH 0/3] cachefiles, afs: mm wait fixes David Howells
  2021-03-23 11:53 ` [PATCH 1/3] fs/cachefiles: Remove wait_bit_key layout dependency David Howells
@ 2021-03-23 11:53 ` David Howells
  2021-03-23 11:53 ` [PATCH 3/3] afs: Use wait_on_page_writeback_killable David Howells
  2021-03-23 12:08 ` [PATCH 0/3] cachefiles, afs: mm wait fixes Matthew Wilcox
  3 siblings, 0 replies; 5+ messages in thread
From: David Howells @ 2021-03-23 11:53 UTC (permalink / raw)
  To: linux-cachefs, linux-afs
  Cc: Matthew Wilcox (Oracle),
	Christoph Hellwig, linux-mm, dhowells, Matthew Wilcox (Oracle),
	Christoph Hellwig, linux-fsdevel, linux-kernel

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

This is the killable version of wait_on_page_writeback.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: linux-afs@lists.infradead.org
cc: linux-mm@kvack.org
Link: https://lore.kernel.org/r/20210320054104.1300774-3-willy@infradead.org
---

 include/linux/pagemap.h |    1 +
 mm/page-writeback.c     |   16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 8f4daac6eb4b..8c9947fd62f3 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -682,6 +682,7 @@ static inline int wait_on_page_locked_killable(struct page *page)
 
 int put_and_wait_on_page_locked(struct page *page, int state);
 void wait_on_page_writeback(struct page *page);
+int wait_on_page_writeback_killable(struct page *page);
 extern void end_page_writeback(struct page *page);
 void wait_for_stable_page(struct page *page);
 
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index eb34d204d4ee..9e35b636a393 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2833,6 +2833,22 @@ void wait_on_page_writeback(struct page *page)
 }
 EXPORT_SYMBOL_GPL(wait_on_page_writeback);
 
+/*
+ * Wait for a page to complete writeback.  Returns -EINTR if we get a
+ * fatal signal while waiting.
+ */
+int wait_on_page_writeback_killable(struct page *page)
+{
+	while (PageWriteback(page)) {
+		trace_wait_on_page_writeback(page, page_mapping(page));
+		if (wait_on_page_bit_killable(page, PG_writeback))
+			return -EINTR;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(wait_on_page_writeback_killable);
+
 /**
  * wait_for_stable_page() - wait for writeback to finish, if necessary.
  * @page:	The page to wait on.



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

* [PATCH 3/3] afs: Use wait_on_page_writeback_killable
  2021-03-23 11:53 [PATCH 0/3] cachefiles, afs: mm wait fixes David Howells
  2021-03-23 11:53 ` [PATCH 1/3] fs/cachefiles: Remove wait_bit_key layout dependency David Howells
  2021-03-23 11:53 ` [PATCH 2/3] mm/writeback: Add wait_on_page_writeback_killable David Howells
@ 2021-03-23 11:53 ` David Howells
  2021-03-23 12:08 ` [PATCH 0/3] cachefiles, afs: mm wait fixes Matthew Wilcox
  3 siblings, 0 replies; 5+ messages in thread
From: David Howells @ 2021-03-23 11:53 UTC (permalink / raw)
  To: linux-cachefs, linux-afs
  Cc: Matthew Wilcox (Oracle),
	Christoph Hellwig, linux-mm, dhowells, Matthew Wilcox (Oracle),
	Christoph Hellwig, linux-fsdevel, linux-kernel

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

Open-coding this function meant it missed out on the recent bugfix
for waiters being woken by a delayed wake event from a previous
instantiation of the page.

[DH: Changed the patch to use vmf->page rather than variable page which
 doesn't exist yet upstream]

Fixes: 1cf7a1518aef ("afs: Implement shared-writeable mmap")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: linux-afs@lists.infradead.org
cc: linux-mm@kvack.org
Link: https://lore.kernel.org/r/20210320054104.1300774-4-willy@infradead.org
---

 fs/afs/write.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/afs/write.c b/fs/afs/write.c
index c9195fc67fd8..eb737ed63afb 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -851,8 +851,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 	fscache_wait_on_page_write(vnode->cache, vmf->page);
 #endif
 
-	if (PageWriteback(vmf->page) &&
-	    wait_on_page_bit_killable(vmf->page, PG_writeback) < 0)
+	if (wait_on_page_writeback_killable(vmf->page))
 		return VM_FAULT_RETRY;
 
 	if (lock_page_killable(vmf->page) < 0)



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

* Re: [PATCH 0/3] cachefiles, afs: mm wait fixes
  2021-03-23 11:53 [PATCH 0/3] cachefiles, afs: mm wait fixes David Howells
                   ` (2 preceding siblings ...)
  2021-03-23 11:53 ` [PATCH 3/3] afs: Use wait_on_page_writeback_killable David Howells
@ 2021-03-23 12:08 ` Matthew Wilcox
  3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox @ 2021-03-23 12:08 UTC (permalink / raw)
  To: David Howells
  Cc: linux-cachefs, linux-afs, Christoph Hellwig, linux-mm,
	linux-fsdevel, linux-kernel

On Tue, Mar 23, 2021 at 11:53:22AM +0000, David Howells wrote:
> 
> Here are some patches to fix page waiting-related issues in cachefiles and
> afs[1]:
> 
>  (1) In cachefiles, remove the use of the wait_bit_key struct to access
>      something that's actually in wait_page_key format.  The proper struct
>      is now available in the header, so that should be used instead.
> 
>  (2) Add a proper wait function for waiting killably on the page writeback
>      flag.  This includes a recent bugfix here (presumably commit
>      c2407cf7d22d0c0d94cf20342b3b8f06f1d904e7).
> 
>  (3) In afs, use the function added in (2) rather than using
>      wait_on_page_bit_killable() which doesn't have the aforementioned
>      bugfix.
> 
>      Note that I modified this to work with the upstream code where the
>      page pointer isn't cached in a local variable.

Thanks, the minor modifications to the patches (changelogs, fixes to apply
to upstream) all look good to me.

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

end of thread, other threads:[~2021-03-23 12:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 11:53 [PATCH 0/3] cachefiles, afs: mm wait fixes David Howells
2021-03-23 11:53 ` [PATCH 1/3] fs/cachefiles: Remove wait_bit_key layout dependency David Howells
2021-03-23 11:53 ` [PATCH 2/3] mm/writeback: Add wait_on_page_writeback_killable David Howells
2021-03-23 11:53 ` [PATCH 3/3] afs: Use wait_on_page_writeback_killable David Howells
2021-03-23 12:08 ` [PATCH 0/3] cachefiles, afs: mm wait fixes Matthew Wilcox

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.