nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] filesystem-dax: Fix dax_layout_busy_page() livelock
@ 2018-10-07  5:59 Dan Williams
  2018-10-08 13:42 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Williams @ 2018-10-07  5:59 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Jan Kara, linux-nvdimm, linux-kernel, Matthew Wilcox, stable,
	Ross Zwisler

In the presence of multi-order entries the typical
pagevec_lookup_entries() pattern may loop forever:

	while (index < end && pagevec_lookup_entries(&pvec, mapping, index,
				min(end - index, (pgoff_t)PAGEVEC_SIZE),
				indices)) {
		...
		for (i = 0; i < pagevec_count(&pvec); i++) {
			index = indices[i];
			...
		}
		index++; /* BUG */
	}

The loop updates 'index' for each index found and then increments to the
next possible page to continue the lookup. However, if the last entry in
the pagevec is multi-order then the next possible page index is more
than 1 page away. Fix this locally for the filesystem-dax case by
checking for dax-multi-order entries. Going forward new users of
multi-order entries need to be similarly careful, or we need a generic
way to report the page increment in the radix iterator.

Fixes: 5fac7408d828 ("mm, fs, dax: handle layout changes to pinned dax...")
Cc: <stable@vger.kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Ross Zwisler <zwisler@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
Changes in v2:
* Only update nr_pages if the last entry in the pagevec is multi-order.

 fs/dax.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/dax.c b/fs/dax.c
index 4becbf168b7f..0fb270f0a0ef 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -666,6 +666,8 @@ struct page *dax_layout_busy_page(struct address_space *mapping)
 	while (index < end && pagevec_lookup_entries(&pvec, mapping, index,
 				min(end - index, (pgoff_t)PAGEVEC_SIZE),
 				indices)) {
+		pgoff_t nr_pages = 1;
+
 		for (i = 0; i < pagevec_count(&pvec); i++) {
 			struct page *pvec_ent = pvec.pages[i];
 			void *entry;
@@ -680,8 +682,15 @@ struct page *dax_layout_busy_page(struct address_space *mapping)
 
 			xa_lock_irq(&mapping->i_pages);
 			entry = get_unlocked_mapping_entry(mapping, index, NULL);
-			if (entry)
+			if (entry) {
 				page = dax_busy_page(entry);
+				/*
+				 * Account for multi-order entries at
+				 * the end of the pagevec.
+				 */
+				if (i + 1 >= pagevec_count(&pvec))
+					nr_pages = 1UL << dax_radix_order(entry);
+			}
 			put_unlocked_mapping_entry(mapping, index, entry);
 			xa_unlock_irq(&mapping->i_pages);
 			if (page)
@@ -696,7 +705,7 @@ struct page *dax_layout_busy_page(struct address_space *mapping)
 		 */
 		pagevec_remove_exceptionals(&pvec);
 		pagevec_release(&pvec);
-		index++;
+		index += nr_pages;
 
 		if (page)
 			break;

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [PATCH v2] filesystem-dax: Fix dax_layout_busy_page() livelock
  2018-10-07  5:59 [PATCH v2] filesystem-dax: Fix dax_layout_busy_page() livelock Dan Williams
@ 2018-10-08 13:42 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2018-10-08 13:42 UTC (permalink / raw)
  To: Dan Williams
  Cc: Jan Kara, linux-nvdimm, linux-kernel, Matthew Wilcox, stable,
	Ross Zwisler, linux-fsdevel

On Sat 06-10-18 22:59:56, Dan Williams wrote:
> In the presence of multi-order entries the typical
> pagevec_lookup_entries() pattern may loop forever:
> 
> 	while (index < end && pagevec_lookup_entries(&pvec, mapping, index,
> 				min(end - index, (pgoff_t)PAGEVEC_SIZE),
> 				indices)) {
> 		...
> 		for (i = 0; i < pagevec_count(&pvec); i++) {
> 			index = indices[i];
> 			...
> 		}
> 		index++; /* BUG */
> 	}
> 
> The loop updates 'index' for each index found and then increments to the
> next possible page to continue the lookup. However, if the last entry in
> the pagevec is multi-order then the next possible page index is more
> than 1 page away. Fix this locally for the filesystem-dax case by
> checking for dax-multi-order entries. Going forward new users of
> multi-order entries need to be similarly careful, or we need a generic
> way to report the page increment in the radix iterator.
> 
> Fixes: 5fac7408d828 ("mm, fs, dax: handle layout changes to pinned dax...")
> Cc: <stable@vger.kernel.org>
> Cc: Jan Kara <jack@suse.cz>
> Cc: Ross Zwisler <zwisler@kernel.org>
> Cc: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
> Changes in v2:
> * Only update nr_pages if the last entry in the pagevec is multi-order.
> 
>  fs/dax.c |   13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)

Thanks for fixing this up! It is somewhat ugly but nicer fixes would be
more intrusive so I agree with this approach for the ease of backporting
and let's clean up the iteration code later. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> 
> diff --git a/fs/dax.c b/fs/dax.c
> index 4becbf168b7f..0fb270f0a0ef 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -666,6 +666,8 @@ struct page *dax_layout_busy_page(struct address_space *mapping)
>  	while (index < end && pagevec_lookup_entries(&pvec, mapping, index,
>  				min(end - index, (pgoff_t)PAGEVEC_SIZE),
>  				indices)) {
> +		pgoff_t nr_pages = 1;
> +
>  		for (i = 0; i < pagevec_count(&pvec); i++) {
>  			struct page *pvec_ent = pvec.pages[i];
>  			void *entry;
> @@ -680,8 +682,15 @@ struct page *dax_layout_busy_page(struct address_space *mapping)
>  
>  			xa_lock_irq(&mapping->i_pages);
>  			entry = get_unlocked_mapping_entry(mapping, index, NULL);
> -			if (entry)
> +			if (entry) {
>  				page = dax_busy_page(entry);
> +				/*
> +				 * Account for multi-order entries at
> +				 * the end of the pagevec.
> +				 */
> +				if (i + 1 >= pagevec_count(&pvec))
> +					nr_pages = 1UL << dax_radix_order(entry);
> +			}
>  			put_unlocked_mapping_entry(mapping, index, entry);
>  			xa_unlock_irq(&mapping->i_pages);
>  			if (page)
> @@ -696,7 +705,7 @@ struct page *dax_layout_busy_page(struct address_space *mapping)
>  		 */
>  		pagevec_remove_exceptionals(&pvec);
>  		pagevec_release(&pvec);
> -		index++;
> +		index += nr_pages;
>  
>  		if (page)
>  			break;
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

end of thread, other threads:[~2018-10-08 13:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-07  5:59 [PATCH v2] filesystem-dax: Fix dax_layout_busy_page() livelock Dan Williams
2018-10-08 13:42 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).