LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v1] mm/hwpoison: Retry with shake_page() for unhandlable pages
@ 2021-08-17  5:37 Naoya Horiguchi
  2021-08-18 18:07 ` Yang Shi
  0 siblings, 1 reply; 3+ messages in thread
From: Naoya Horiguchi @ 2021-08-17  5:37 UTC (permalink / raw)
  To: linux-mm
  Cc: Andrew Morton, Tony Luck, Oscar Salvador, Muchun Song,
	Mike Kravetz, Michal Hocko, Naoya Horiguchi, linux-kernel

From: Naoya Horiguchi <naoya.horiguchi@nec.com>

HWPoisonHandlable() sometimes returns false for typical user pages
due to races with average memory events like transfers over LRU lists.
This causes failures in hwpoison handling.

There's retry code for such a case but does not work because the retry
loop reaches the retry limit too quickly before the page settles down to
handlable state. Let get_any_page() call shake_page() to fix it.

Fixes: 25182f05ffed ("mm,hwpoison: fix race with hugetlb page allocation")
Reported-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: stable@vger.kernel.org # 5.13
---
 mm/memory-failure.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git v5.14-rc6/mm/memory-failure.c v5.14-rc6_patched/mm/memory-failure.c
index eefd823deb67..aa6592540f17 100644
--- v5.14-rc6/mm/memory-failure.c
+++ v5.14-rc6_patched/mm/memory-failure.c
@@ -1146,7 +1146,7 @@ static int __get_hwpoison_page(struct page *page)
 	 * unexpected races caused by taking a page refcount.
 	 */
 	if (!HWPoisonHandlable(head))
-		return 0;
+		return -EBUSY;
 
 	if (PageTransHuge(head)) {
 		/*
@@ -1199,9 +1199,14 @@ static int get_any_page(struct page *p, unsigned long flags)
 			}
 			goto out;
 		} else if (ret == -EBUSY) {
-			/* We raced with freeing huge page to buddy, retry. */
-			if (pass++ < 3)
+			/*
+			 * We raced with (possibly temporary) unhandlable
+			 * page, retry.
+			 */
+			if (pass++ < 3) {
+				shake_page(p, 1);
 				goto try_again;
+			}
 			goto out;
 		}
 	}
-- 
2.25.1


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

* Re: [PATCH v1] mm/hwpoison: Retry with shake_page() for unhandlable pages
  2021-08-17  5:37 [PATCH v1] mm/hwpoison: Retry with shake_page() for unhandlable pages Naoya Horiguchi
@ 2021-08-18 18:07 ` Yang Shi
  2021-08-19  0:13   ` HORIGUCHI NAOYA(堀口 直也)
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Shi @ 2021-08-18 18:07 UTC (permalink / raw)
  To: Naoya Horiguchi
  Cc: Linux MM, Andrew Morton, Tony Luck, Oscar Salvador, Muchun Song,
	Mike Kravetz, Michal Hocko, Naoya Horiguchi,
	Linux Kernel Mailing List

On Mon, Aug 16, 2021 at 10:37 PM Naoya Horiguchi
<naoya.horiguchi@linux.dev> wrote:
>
> From: Naoya Horiguchi <naoya.horiguchi@nec.com>
>
> HWPoisonHandlable() sometimes returns false for typical user pages
> due to races with average memory events like transfers over LRU lists.
> This causes failures in hwpoison handling.
>
> There's retry code for such a case but does not work because the retry
> loop reaches the retry limit too quickly before the page settles down to
> handlable state. Let get_any_page() call shake_page() to fix it.
>
> Fixes: 25182f05ffed ("mm,hwpoison: fix race with hugetlb page allocation")
> Reported-by: Tony Luck <tony.luck@intel.com>
> Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
> Cc: stable@vger.kernel.org # 5.13
> ---
>  mm/memory-failure.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git v5.14-rc6/mm/memory-failure.c v5.14-rc6_patched/mm/memory-failure.c
> index eefd823deb67..aa6592540f17 100644
> --- v5.14-rc6/mm/memory-failure.c
> +++ v5.14-rc6_patched/mm/memory-failure.c
> @@ -1146,7 +1146,7 @@ static int __get_hwpoison_page(struct page *page)
>          * unexpected races caused by taking a page refcount.
>          */
>         if (!HWPoisonHandlable(head))
> -               return 0;
> +               return -EBUSY;
>
>         if (PageTransHuge(head)) {
>                 /*
> @@ -1199,9 +1199,14 @@ static int get_any_page(struct page *p, unsigned long flags)
>                         }
>                         goto out;
>                 } else if (ret == -EBUSY) {
> -                       /* We raced with freeing huge page to buddy, retry. */
> -                       if (pass++ < 3)
> +                       /*
> +                        * We raced with (possibly temporary) unhandlable
> +                        * page, retry.
> +                        */
> +                       if (pass++ < 3) {
> +                               shake_page(p, 1);
>                                 goto try_again;
> +                       }

I think the return value should be set to -EIO before jumping to out.
I'm supposed -EIO means this is really or very likely an unhandlable
page.

>                         goto out;
>                 }
>         }
> --
> 2.25.1
>
>

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

* Re: [PATCH v1] mm/hwpoison: Retry with shake_page() for unhandlable pages
  2021-08-18 18:07 ` Yang Shi
@ 2021-08-19  0:13   ` HORIGUCHI NAOYA(堀口 直也)
  0 siblings, 0 replies; 3+ messages in thread
From: HORIGUCHI NAOYA(堀口 直也) @ 2021-08-19  0:13 UTC (permalink / raw)
  To: Yang Shi
  Cc: Naoya Horiguchi, Linux MM, Andrew Morton, Tony Luck,
	Oscar Salvador, Muchun Song, Mike Kravetz, Michal Hocko,
	Linux Kernel Mailing List

On Wed, Aug 18, 2021 at 11:07:43AM -0700, Yang Shi wrote:
> On Mon, Aug 16, 2021 at 10:37 PM Naoya Horiguchi
> <naoya.horiguchi@linux.dev> wrote:
> >
> > From: Naoya Horiguchi <naoya.horiguchi@nec.com>
> >
> > HWPoisonHandlable() sometimes returns false for typical user pages
> > due to races with average memory events like transfers over LRU lists.
> > This causes failures in hwpoison handling.
> >
> > There's retry code for such a case but does not work because the retry
> > loop reaches the retry limit too quickly before the page settles down to
> > handlable state. Let get_any_page() call shake_page() to fix it.
> >
> > Fixes: 25182f05ffed ("mm,hwpoison: fix race with hugetlb page allocation")
> > Reported-by: Tony Luck <tony.luck@intel.com>
> > Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
> > Cc: stable@vger.kernel.org # 5.13
> > ---
> >  mm/memory-failure.c | 11 ++++++++---
> >  1 file changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git v5.14-rc6/mm/memory-failure.c v5.14-rc6_patched/mm/memory-failure.c
> > index eefd823deb67..aa6592540f17 100644
> > --- v5.14-rc6/mm/memory-failure.c
> > +++ v5.14-rc6_patched/mm/memory-failure.c
> > @@ -1146,7 +1146,7 @@ static int __get_hwpoison_page(struct page *page)
> >          * unexpected races caused by taking a page refcount.
> >          */
> >         if (!HWPoisonHandlable(head))
> > -               return 0;
> > +               return -EBUSY;
> >
> >         if (PageTransHuge(head)) {
> >                 /*
> > @@ -1199,9 +1199,14 @@ static int get_any_page(struct page *p, unsigned long flags)
> >                         }
> >                         goto out;
> >                 } else if (ret == -EBUSY) {
> > -                       /* We raced with freeing huge page to buddy, retry. */
> > -                       if (pass++ < 3)
> > +                       /*
> > +                        * We raced with (possibly temporary) unhandlable
> > +                        * page, retry.
> > +                        */
> > +                       if (pass++ < 3) {
> > +                               shake_page(p, 1);
> >                                 goto try_again;
> > +                       }
> 
> I think the return value should be set to -EIO before jumping to out.
> I'm supposed -EIO means this is really or very likely an unhandlable
> page.

You're right, I have the same assumption that -EBUSY means transient error
and -EIO means permanent one. And we consider an error as permanent when the
retry limit is reached. I'll update the patch. Thank you for the comment.

- Naoya Horiguchi

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

end of thread, other threads:[~2021-08-19  0:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-17  5:37 [PATCH v1] mm/hwpoison: Retry with shake_page() for unhandlable pages Naoya Horiguchi
2021-08-18 18:07 ` Yang Shi
2021-08-19  0:13   ` HORIGUCHI NAOYA(堀口 直也)

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).