From: Jiaqi Yan <jiaqiyan@google.com>
To: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Miaohe Lin <linmiaohe@huawei.com>,
akpm@linux-foundation.org, naoya.horiguchi@nec.com,
songmuchun@bytedance.com, shy828301@gmail.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
duenwen@google.com, axelrasmussen@google.com,
jthoughton@google.com
Subject: Re: [PATCH v3 2/4] mm/hwpoison: check if a subpage of a hugetlb folio is raw HWPOISON
Date: Tue, 11 Jul 2023 15:22:52 -0700 [thread overview]
Message-ID: <CACw3F53s6pX50TV3Lq79=THsxff0T1eS2wUdLZSp1JL8gFHQyg@mail.gmail.com> (raw)
In-Reply-To: <20230711180159.GA3887@monkey>
On Tue, Jul 11, 2023 at 11:02 AM Mike Kravetz <mike.kravetz@oracle.com> wrote:
>
> On 07/11/23 10:05, Jiaqi Yan wrote:
> > On Mon, Jul 10, 2023 at 8:16 AM Jiaqi Yan <jiaqiyan@google.com> wrote:
> > > On Fri, Jul 7, 2023 at 7:57 PM Miaohe Lin <linmiaohe@huawei.com> wrote:
> > > > On 2023/7/8 4:19, Jiaqi Yan wrote:
> > > >
> > > > > + if (subpage == p->page) {
> > > > > + ret = true;
> > > > > + break;
> > > > > + }
> > > > > + }
> > > > > +
> > > > > + return ret;
> > > > > }
> > > >
> > > > It seems there's a race between __is_raw_hwp_subpage and unpoison_memory:
> > > > unpoison_memory __is_raw_hwp_subpage
> > > > if (!folio_test_hwpoison(folio)) -- hwpoison is set
> > > > folio_free_raw_hwp llist_for_each_entry_safe raw_hwp_list
> > > > llist_del_all ..
> > > > folio_test_clear_hwpoison
> > > >
> > >
> > > Thanks Miaohe for raising this concern.
> > >
> > > > But __is_raw_hwp_subpage is used in hugetlbfs, unpoison_memory couldn't reach here because there's a
> > > > folio_mapping == NULL check before folio_free_raw_hwp.
> > >
> > > I agree. But in near future I do want to make __is_raw_hwp_subpage
> > > work for shared-mapping hugetlb, so it would be nice to work with
> > > unpoison_memory. It doesn't seem to me that holding mf_mutex in
> > > __is_raw_hwp_subpage is nice or even absolutely correct. Let me think
> > > if I can come up with something in v4.
> >
> > At my 2nd thought, if __is_raw_hwp_subpage simply takes mf_mutex
> > before llist_for_each_entry, it will introduce a deadlock:
> >
> > unpoison_memory __is_raw_hwp_subpage
> > held mf_mutex held hugetlb_lock
> > get_hwpoison_hugetlb_folio attempts mf_mutex
> > attempts hugetlb lock
> >
> > Not for this patch series, but for future, is it a good idea to make
> > mf_mutex available to hugetlb code? Then enforce the order of locking
> > to be mf_mutex first, hugetlb_lock second? I believe this is the
> > current locking pattern / order for try_memory_failure_hugetlb.
>
> I think only holding mf_mutex in __is_raw_hwp_subpage would be sufficient
> to prevent races with unpoison_memory. memory failure code needs to take
> both mf_mutex and hugetlb_lock. The hugetlb lock is to prevent hugetlb
> page state changes. IIUC, __is_raw_hwp_subpage is only taking hugetlb_lock
> to prevent races with memory failure code.
Thanks Mike, I think mf_mutex is a simple and correct solution. I will
drop hugetlb_lock from __is_raw_hwp_subpage in v4.
>
> Of course, I could be missing something as there are subtle issues with
> locking in the memory failure code.
> --
> Mike Kravetz
next prev parent reply other threads:[~2023-07-11 22:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-07 20:19 [PATCH v3 0/4] Improve hugetlbfs read on HWPOISON hugepages Jiaqi Yan
2023-07-07 20:19 ` [PATCH v3 1/4] mm/hwpoison: delete all entries before traversal in __folio_free_raw_hwp Jiaqi Yan
2023-07-08 2:40 ` Miaohe Lin
2023-07-07 20:19 ` [PATCH v3 2/4] mm/hwpoison: check if a subpage of a hugetlb folio is raw HWPOISON Jiaqi Yan
2023-07-07 20:31 ` Matthew Wilcox
2023-07-07 21:05 ` Andrew Morton
2023-07-10 0:21 ` Naoya Horiguchi
2023-07-10 15:11 ` Jiaqi Yan
2023-07-11 8:59 ` Naoya Horiguchi
2023-07-08 2:57 ` Miaohe Lin
2023-07-10 15:16 ` Jiaqi Yan
2023-07-11 17:05 ` Jiaqi Yan
2023-07-11 18:01 ` Mike Kravetz
2023-07-11 22:22 ` Jiaqi Yan [this message]
2023-07-12 2:25 ` Miaohe Lin
2023-07-07 20:19 ` [PATCH v3 3/4] hugetlbfs: improve read HWPOISON hugepage Jiaqi Yan
2023-07-07 20:19 ` [PATCH v3 4/4] selftests/mm: add tests for HWPOISON hugetlbfs read Jiaqi Yan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACw3F53s6pX50TV3Lq79=THsxff0T1eS2wUdLZSp1JL8gFHQyg@mail.gmail.com' \
--to=jiaqiyan@google.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=duenwen@google.com \
--cc=jthoughton@google.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=naoya.horiguchi@nec.com \
--cc=shy828301@gmail.com \
--cc=songmuchun@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox