[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAHbLzkpUX9NdKz5yz8j7ej-2hh0hKSB20_E_Ug4d2r3_NC6YUA@mail.gmail.com>
Date: Mon, 8 Nov 2021 17:03:13 -0800
From: Yang Shi <shy828301@...il.com>
To: Naoya Horiguchi <naoya.horiguchi@...ux.dev>
Cc: Linux MM <linux-mm@...ck.org>,
Andrew Morton <akpm@...ux-foundation.org>,
David Hildenbrand <david@...hat.com>,
Oscar Salvador <osalvador@...e.de>,
Michal Hocko <mhocko@...e.com>,
Ding Hui <dinghui@...gfor.com.cn>,
Tony Luck <tony.luck@...el.com>,
"Aneesh Kumar K.V" <aneesh.kumar@...ux.vnet.ibm.com>,
Miaohe Lin <linmiaohe@...wei.com>,
Peter Xu <peterx@...hat.com>,
Naoya Horiguchi <naoya.horiguchi@....com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3 3/3] mm/hwpoison: fix unpoison_memory()
On Mon, Nov 8, 2021 at 4:53 PM Naoya Horiguchi
<naoya.horiguchi@...ux.dev> wrote:
>
> On Mon, Nov 08, 2021 at 03:27:55PM -0800, Yang Shi wrote:
> > On Thu, Nov 4, 2021 at 10:52 PM Naoya Horiguchi
> > <naoya.horiguchi@...ux.dev> wrote:
> ...
> > > @@ -1942,6 +1987,26 @@ core_initcall(memory_failure_init);
> > > pr_info(fmt, pfn); \
> > > })
> > >
> > > +static inline int clear_page_hwpoison(struct ratelimit_state *rs, struct page *p)
> > > +{
> > > + if (TestClearPageHWPoison(p)) {
> > > + unpoison_pr_info("Unpoison: Software-unpoisoned page %#lx\n",
> > > + page_to_pfn(p), rs);
> > > + num_poisoned_pages_dec();
> > > + return 1;
> > > + }
> > > + return 0;
> > > +}
> > > +
> > > +static inline int unpoison_taken_off_page(struct ratelimit_state *rs,
> > > + struct page *p)
> > > +{
> > > + if (put_page_back_buddy(p) && clear_page_hwpoison(rs, p))
> >
> > It seems there might be race condition between free and allocation to
> > kick the page out of buddy before the hwpoisoned flag is cleared IIUC?
> >
> > CPU A CPU B
> > Free: Allocation:
> > acquire zone lock
> > put back to buddy
> > release zone lock
> > acquire zone lock
> > try to allocate this page
> > if it is hwpoisoned then reset
> > PageBuddy (not buddy page anymore)
> > release zone lock
> >
> > Did I miss something?
>
> No, this is a nice catch. CPU B finds hwpoisoned page on free list then
> calling bad_page(). So doing "put back to buddy" and clear_page_hwpoison
> inside a single zone lock should prevent this race.
Yeah, or clear the flag before putting it back to buddy? Anyway
clearing the flag under zone lock is not a big deal either.
>
> Thanks,
> Naoya Horiguchi
Powered by blists - more mailing lists