Linux-NVDIMM Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] fs/dax: Fix pmd vs pte conflict detection
@ 2019-10-19 16:26 Dan Williams
  2019-10-19 20:50 ` Matthew Wilcox
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Dan Williams @ 2019-10-19 16:26 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Jeff Smits, Doug Nelson, stable, Jan Kara,
	Matthew Wilcox (Oracle),
	linux-nvdimm, linux-kernel

Check for NULL entries before checking the entry order, otherwise NULL
is misinterpreted as a present pte conflict. The 'order' check needs to
happen before the locked check as an unlocked entry at the wrong order
must fallback to lookup the correct order.

Reported-by: Jeff Smits <jeff.smits@intel.com>
Reported-by: Doug Nelson <doug.nelson@intel.com>
Cc: <stable@vger.kernel.org>
Fixes: 23c84eb78375 ("dax: Fix missed wakeup with PMD faults")
Cc: Jan Kara <jack@suse.cz>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 fs/dax.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/dax.c b/fs/dax.c
index a71881e77204..08160011d94c 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -221,10 +221,11 @@ static void *get_unlocked_entry(struct xa_state *xas, unsigned int order)
 
 	for (;;) {
 		entry = xas_find_conflict(xas);
+		if (!entry || WARN_ON_ONCE(!xa_is_value(entry)))
+			return entry;
 		if (dax_entry_order(entry) < order)
 			return XA_RETRY_ENTRY;
-		if (!entry || WARN_ON_ONCE(!xa_is_value(entry)) ||
-				!dax_is_locked(entry))
+		if (!dax_is_locked(entry))
 			return entry;
 
 		wq = dax_entry_waitqueue(xas, entry, &ewait.key);
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* Re: [PATCH] fs/dax: Fix pmd vs pte conflict detection
  2019-10-19 16:26 [PATCH] fs/dax: Fix pmd vs pte conflict detection Dan Williams
@ 2019-10-19 20:50 ` Matthew Wilcox
  2019-10-19 23:09   ` Dan Williams
  2019-10-21  8:47 ` Jan Kara
  2019-10-21 12:07 ` Jeff Moyer
  2 siblings, 1 reply; 7+ messages in thread
From: Matthew Wilcox @ 2019-10-19 20:50 UTC (permalink / raw)
  To: Dan Williams
  Cc: linux-fsdevel, Jeff Smits, Doug Nelson, stable, Jan Kara,
	linux-nvdimm, linux-kernel

On Sat, Oct 19, 2019 at 09:26:19AM -0700, Dan Williams wrote:
> Check for NULL entries before checking the entry order, otherwise NULL
> is misinterpreted as a present pte conflict. The 'order' check needs to
> happen before the locked check as an unlocked entry at the wrong order
> must fallback to lookup the correct order.
> 
> Reported-by: Jeff Smits <jeff.smits@intel.com>
> Reported-by: Doug Nelson <doug.nelson@intel.com>
> Cc: <stable@vger.kernel.org>
> Fixes: 23c84eb78375 ("dax: Fix missed wakeup with PMD faults")
> Cc: Jan Kara <jack@suse.cz>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  fs/dax.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/dax.c b/fs/dax.c
> index a71881e77204..08160011d94c 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -221,10 +221,11 @@ static void *get_unlocked_entry(struct xa_state *xas, unsigned int order)
>  
>  	for (;;) {
>  		entry = xas_find_conflict(xas);
> +		if (!entry || WARN_ON_ONCE(!xa_is_value(entry)))
> +			return entry;
>  		if (dax_entry_order(entry) < order)
>  			return XA_RETRY_ENTRY;
> -		if (!entry || WARN_ON_ONCE(!xa_is_value(entry)) ||
> -				!dax_is_locked(entry))
> +		if (!dax_is_locked(entry))
>  			return entry;

Yes, I think this works.  Should we also add:

 static unsigned int dax_entry_order(void *entry)
 {
+	BUG_ON(!xa_is_value(entry));
 	if (xa_to_value(entry) & DAX_PMD)
 		return PMD_ORDER;
 	return 0;
 }

which would have caught this logic error before it caused a performance
regression?
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* Re: [PATCH] fs/dax: Fix pmd vs pte conflict detection
  2019-10-19 20:50 ` Matthew Wilcox
@ 2019-10-19 23:09   ` Dan Williams
  2019-10-19 23:27     ` Dan Williams
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Williams @ 2019-10-19 23:09 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: linux-fsdevel, Jeff Smits, Doug Nelson, stable, Jan Kara,
	linux-nvdimm, Linux Kernel Mailing List

On Sat, Oct 19, 2019 at 1:50 PM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Sat, Oct 19, 2019 at 09:26:19AM -0700, Dan Williams wrote:
> > Check for NULL entries before checking the entry order, otherwise NULL
> > is misinterpreted as a present pte conflict. The 'order' check needs to
> > happen before the locked check as an unlocked entry at the wrong order
> > must fallback to lookup the correct order.
> >
> > Reported-by: Jeff Smits <jeff.smits@intel.com>
> > Reported-by: Doug Nelson <doug.nelson@intel.com>
> > Cc: <stable@vger.kernel.org>
> > Fixes: 23c84eb78375 ("dax: Fix missed wakeup with PMD faults")
> > Cc: Jan Kara <jack@suse.cz>
> > Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> > Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> > ---
> >  fs/dax.c |    5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/dax.c b/fs/dax.c
> > index a71881e77204..08160011d94c 100644
> > --- a/fs/dax.c
> > +++ b/fs/dax.c
> > @@ -221,10 +221,11 @@ static void *get_unlocked_entry(struct xa_state *xas, unsigned int order)
> >
> >       for (;;) {
> >               entry = xas_find_conflict(xas);
> > +             if (!entry || WARN_ON_ONCE(!xa_is_value(entry)))
> > +                     return entry;
> >               if (dax_entry_order(entry) < order)
> >                       return XA_RETRY_ENTRY;
> > -             if (!entry || WARN_ON_ONCE(!xa_is_value(entry)) ||
> > -                             !dax_is_locked(entry))
> > +             if (!dax_is_locked(entry))
> >                       return entry;
>
> Yes, I think this works.  Should we also add:
>
>  static unsigned int dax_entry_order(void *entry)
>  {
> +       BUG_ON(!xa_is_value(entry));
>         if (xa_to_value(entry) & DAX_PMD)
>                 return PMD_ORDER;
>         return 0;
>  }
>
> which would have caught this logic error before it caused a performance
> regression?

Sounds good will add it to v2.
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* Re: [PATCH] fs/dax: Fix pmd vs pte conflict detection
  2019-10-19 23:09   ` Dan Williams
@ 2019-10-19 23:27     ` Dan Williams
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Williams @ 2019-10-19 23:27 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: linux-fsdevel, Jeff Smits, Doug Nelson, stable, Jan Kara,
	linux-nvdimm, Linux Kernel Mailing List

On Sat, Oct 19, 2019 at 4:09 PM Dan Williams <dan.j.williams@intel.com> wrote:
>
> On Sat, Oct 19, 2019 at 1:50 PM Matthew Wilcox <willy@infradead.org> wrote:
> >
> > On Sat, Oct 19, 2019 at 09:26:19AM -0700, Dan Williams wrote:
> > > Check for NULL entries before checking the entry order, otherwise NULL
> > > is misinterpreted as a present pte conflict. The 'order' check needs to
> > > happen before the locked check as an unlocked entry at the wrong order
> > > must fallback to lookup the correct order.
> > >
> > > Reported-by: Jeff Smits <jeff.smits@intel.com>
> > > Reported-by: Doug Nelson <doug.nelson@intel.com>
> > > Cc: <stable@vger.kernel.org>
> > > Fixes: 23c84eb78375 ("dax: Fix missed wakeup with PMD faults")
> > > Cc: Jan Kara <jack@suse.cz>
> > > Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> > > Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> > > ---
> > >  fs/dax.c |    5 +++--
> > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/fs/dax.c b/fs/dax.c
> > > index a71881e77204..08160011d94c 100644
> > > --- a/fs/dax.c
> > > +++ b/fs/dax.c
> > > @@ -221,10 +221,11 @@ static void *get_unlocked_entry(struct xa_state *xas, unsigned int order)
> > >
> > >       for (;;) {
> > >               entry = xas_find_conflict(xas);
> > > +             if (!entry || WARN_ON_ONCE(!xa_is_value(entry)))
> > > +                     return entry;
> > >               if (dax_entry_order(entry) < order)
> > >                       return XA_RETRY_ENTRY;
> > > -             if (!entry || WARN_ON_ONCE(!xa_is_value(entry)) ||
> > > -                             !dax_is_locked(entry))
> > > +             if (!dax_is_locked(entry))
> > >                       return entry;
> >
> > Yes, I think this works.  Should we also add:
> >
> >  static unsigned int dax_entry_order(void *entry)
> >  {
> > +       BUG_ON(!xa_is_value(entry));
> >         if (xa_to_value(entry) & DAX_PMD)
> >                 return PMD_ORDER;
> >         return 0;
> >  }
> >
> > which would have caught this logic error before it caused a performance
> > regression?
>
> Sounds good will add it to v2.

...except that there are multiple dax helpers that have the 'value'
entry assumption. I'd rather do all of them in a separate patch, or
none of them. It turns out that after this change all
dax_entry_order() invocations are now protected by a xa_is_value()
assert earlier in the calling function.
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* Re: [PATCH] fs/dax: Fix pmd vs pte conflict detection
  2019-10-19 16:26 [PATCH] fs/dax: Fix pmd vs pte conflict detection Dan Williams
  2019-10-19 20:50 ` Matthew Wilcox
@ 2019-10-21  8:47 ` Jan Kara
  2019-10-21 12:07 ` Jeff Moyer
  2 siblings, 0 replies; 7+ messages in thread
From: Jan Kara @ 2019-10-21  8:47 UTC (permalink / raw)
  To: Dan Williams
  Cc: linux-fsdevel, Jeff Smits, Doug Nelson, stable, Jan Kara,
	Matthew Wilcox (Oracle),
	linux-nvdimm, linux-kernel

On Sat 19-10-19 09:26:19, Dan Williams wrote:
> Check for NULL entries before checking the entry order, otherwise NULL
> is misinterpreted as a present pte conflict. The 'order' check needs to
> happen before the locked check as an unlocked entry at the wrong order
> must fallback to lookup the correct order.
> 
> Reported-by: Jeff Smits <jeff.smits@intel.com>
> Reported-by: Doug Nelson <doug.nelson@intel.com>
> Cc: <stable@vger.kernel.org>
> Fixes: 23c84eb78375 ("dax: Fix missed wakeup with PMD faults")
> Cc: Jan Kara <jack@suse.cz>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>

Good catch! The patch looks good to me. You can add:

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

								Honza

> ---
>  fs/dax.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/dax.c b/fs/dax.c
> index a71881e77204..08160011d94c 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -221,10 +221,11 @@ static void *get_unlocked_entry(struct xa_state *xas, unsigned int order)
>  
>  	for (;;) {
>  		entry = xas_find_conflict(xas);
> +		if (!entry || WARN_ON_ONCE(!xa_is_value(entry)))
> +			return entry;
>  		if (dax_entry_order(entry) < order)
>  			return XA_RETRY_ENTRY;
> -		if (!entry || WARN_ON_ONCE(!xa_is_value(entry)) ||
> -				!dax_is_locked(entry))
> +		if (!dax_is_locked(entry))
>  			return entry;
>  
>  		wq = dax_entry_waitqueue(xas, entry, &ewait.key);
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* Re: [PATCH] fs/dax: Fix pmd vs pte conflict detection
  2019-10-19 16:26 [PATCH] fs/dax: Fix pmd vs pte conflict detection Dan Williams
  2019-10-19 20:50 ` Matthew Wilcox
  2019-10-21  8:47 ` Jan Kara
@ 2019-10-21 12:07 ` Jeff Moyer
  2019-10-21 14:44   ` Dan Williams
  2 siblings, 1 reply; 7+ messages in thread
From: Jeff Moyer @ 2019-10-21 12:07 UTC (permalink / raw)
  To: Dan Williams
  Cc: linux-fsdevel, Jeff Smits, Doug Nelson, stable, Jan Kara,
	Matthew Wilcox (Oracle),
	linux-nvdimm, linux-kernel

Dan Williams <dan.j.williams@intel.com> writes:

> Check for NULL entries before checking the entry order, otherwise NULL
> is misinterpreted as a present pte conflict. The 'order' check needs to
> happen before the locked check as an unlocked entry at the wrong order
> must fallback to lookup the correct order.

Please include the user-visible effects of the problem in the changelog.

Thanks,
Jeff

>
> Reported-by: Jeff Smits <jeff.smits@intel.com>
> Reported-by: Doug Nelson <doug.nelson@intel.com>
> Cc: <stable@vger.kernel.org>
> Fixes: 23c84eb78375 ("dax: Fix missed wakeup with PMD faults")
> Cc: Jan Kara <jack@suse.cz>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  fs/dax.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/dax.c b/fs/dax.c
> index a71881e77204..08160011d94c 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -221,10 +221,11 @@ static void *get_unlocked_entry(struct xa_state *xas, unsigned int order)
>  
>  	for (;;) {
>  		entry = xas_find_conflict(xas);
> +		if (!entry || WARN_ON_ONCE(!xa_is_value(entry)))
> +			return entry;
>  		if (dax_entry_order(entry) < order)
>  			return XA_RETRY_ENTRY;
> -		if (!entry || WARN_ON_ONCE(!xa_is_value(entry)) ||
> -				!dax_is_locked(entry))
> +		if (!dax_is_locked(entry))
>  			return entry;
>  
>  		wq = dax_entry_waitqueue(xas, entry, &ewait.key);
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* Re: [PATCH] fs/dax: Fix pmd vs pte conflict detection
  2019-10-21 12:07 ` Jeff Moyer
@ 2019-10-21 14:44   ` Dan Williams
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Williams @ 2019-10-21 14:44 UTC (permalink / raw)
  To: Jeff Moyer
  Cc: linux-fsdevel, Jeff Smits, Doug Nelson, stable, Jan Kara,
	Matthew Wilcox (Oracle),
	linux-nvdimm, Linux Kernel Mailing List

On Mon, Oct 21, 2019 at 5:07 AM Jeff Moyer <jmoyer@redhat.com> wrote:
>
> Dan Williams <dan.j.williams@intel.com> writes:
>
> > Check for NULL entries before checking the entry order, otherwise NULL
> > is misinterpreted as a present pte conflict. The 'order' check needs to
> > happen before the locked check as an unlocked entry at the wrong order
> > must fallback to lookup the correct order.
>
> Please include the user-visible effects of the problem in the changelog.
>

Yup, I noticed that right after sending.
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-19 16:26 [PATCH] fs/dax: Fix pmd vs pte conflict detection Dan Williams
2019-10-19 20:50 ` Matthew Wilcox
2019-10-19 23:09   ` Dan Williams
2019-10-19 23:27     ` Dan Williams
2019-10-21  8:47 ` Jan Kara
2019-10-21 12:07 ` Jeff Moyer
2019-10-21 14:44   ` Dan Williams

Linux-NVDIMM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-nvdimm/0 linux-nvdimm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-nvdimm linux-nvdimm/ https://lore.kernel.org/linux-nvdimm \
		linux-nvdimm@lists.01.org
	public-inbox-index linux-nvdimm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.01.lists.linux-nvdimm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git