linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: James Houghton <jthoughton@google.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Miaohe Lin <linmiaohe@huawei.com>,
	David Hildenbrand <david@redhat.com>,
	Muchun Song <songmuchun@bytedance.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Nadav Amit <nadav.amit@gmail.com>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	Rik van Riel <riel@surriel.com>
Subject: Re: [PATCH RFC 07/10] mm/hugetlb: Make hugetlb_follow_page_mask() RCU-safe
Date: Thu, 3 Nov 2022 11:50:06 -0400	[thread overview]
Message-ID: <Y2PjLlJaBVWDd2bn@x1n> (raw)
In-Reply-To: <CADrL8HUJZMGaWtyVCcXUfmU3neTO4Q6e=3Fi5=osiEVH9jRZ=w@mail.gmail.com>

On Wed, Nov 02, 2022 at 11:24:57AM -0700, James Houghton wrote:
> On Sun, Oct 30, 2022 at 2:29 PM Peter Xu <peterx@redhat.com> wrote:
> >
> > RCU makes sure the pte_t* won't go away from under us.  Please refer to the
> > comment above huge_pte_offset() for more information.
> >
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> >  mm/hugetlb.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> > index 9869c12e6460..85214095fb85 100644
> > --- a/mm/hugetlb.c
> > +++ b/mm/hugetlb.c
> > @@ -6229,10 +6229,12 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma,
> >         if (WARN_ON_ONCE(flags & FOLL_PIN))
> >                 return NULL;
> >
> > +       /* For huge_pte_offset() */
> > +       rcu_read_lock();
> >  retry:
> >         pte = huge_pte_offset(mm, haddr, huge_page_size(h));
> >         if (!pte)
> > -               return NULL;
> > +               goto out_rcu;
> >
> >         ptl = huge_pte_lock(h, mm, pte);
> 
> Just to make sure -- this huge_pte_lock doesn't count as "blocking"
> (for the purposes of what is allowed in an RCU read-side critical
> section), right? If so, great!

Yeah I think spinlock should be fine, iiuc it'll be fine as long as we
don't proactively yield with any form of sleeping locks.

For RT sleepable spinlock should also be fine in this case, as explicitly
mentioned in the RCU docs:

b.	What about the -rt patchset?  If readers would need to block
	in an non-rt kernel, you need SRCU.  If readers would block
	in a -rt kernel, but not in a non-rt kernel, SRCU is not
	necessary.  (The -rt patchset turns spinlocks into sleeplocks,
	hence this distinction.)

> But I think we need to call `rcu_read_unlock` before entering
> `__migration_entry_wait_huge`, as that function really can block.

Right, let me revisit this after I figure out how to do with the
hugetlb_fault() path first, as you commented in the other patch.

Actually here I really think we should just remove the migration chunk and
return with page==NULL, since I really don't think follow_page_mask should
block at all.. then for !sleep cases (FOLL_NOWAIT) or follow_page we'll
return the NULL upwards early, while for generic GUP (__get_user_pages)
we'll just wait in the upcoming faultin_page().  That's afaict what we do
with non-hugetlb memories too (after the recent removal of FOLL_MIGRATE in
4a0499782a).

-- 
Peter Xu



  reply	other threads:[~2022-11-03 15:50 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-30 21:29 [PATCH RFC 00/10] mm/hugetlb: Make huge_pte_offset() thread-safe for pmd unshare Peter Xu
2022-10-30 21:29 ` [PATCH RFC 01/10] mm/hugetlb: Let vma_offset_start() to return start Peter Xu
2022-11-03 15:25   ` Mike Kravetz
2022-10-30 21:29 ` [PATCH RFC 02/10] mm/hugetlb: Comment huge_pte_offset() for its locking requirements Peter Xu
2022-11-01  5:46   ` Nadav Amit
2022-11-02 20:51     ` Peter Xu
2022-11-03 15:42   ` Mike Kravetz
2022-11-03 18:11     ` Peter Xu
2022-11-03 18:38       ` Mike Kravetz
2022-10-30 21:29 ` [PATCH RFC 03/10] mm/hugetlb: Make hugetlb_vma_maps_page() RCU-safe Peter Xu
2022-10-30 21:29 ` [PATCH RFC 04/10] mm/hugetlb: Make userfaultfd_huge_must_wait() RCU-safe Peter Xu
2022-11-02 18:06   ` James Houghton
2022-11-02 21:17     ` Peter Xu
2022-10-30 21:29 ` [PATCH RFC 05/10] mm/hugetlb: Make walk_hugetlb_range() RCU-safe Peter Xu
2022-11-06  8:14   ` kernel test robot
2022-11-06 16:41     ` Peter Xu
2022-10-30 21:29 ` [PATCH RFC 06/10] mm/hugetlb: Make page_vma_mapped_walk() RCU-safe Peter Xu
2022-10-30 21:29 ` [PATCH RFC 07/10] mm/hugetlb: Make hugetlb_follow_page_mask() RCU-safe Peter Xu
2022-11-02 18:24   ` James Houghton
2022-11-03 15:50     ` Peter Xu [this message]
2022-10-30 21:30 ` [PATCH RFC 08/10] mm/hugetlb: Make follow_hugetlb_page RCU-safe Peter Xu
2022-10-30 21:30 ` [PATCH RFC 09/10] mm/hugetlb: Make hugetlb_fault() RCU-safe Peter Xu
2022-11-02 18:04   ` James Houghton
2022-11-03 15:39     ` Peter Xu
2022-10-30 21:30 ` [PATCH RFC 10/10] mm/hugetlb: Comment at rest huge_pte_offset() places Peter Xu
2022-11-01  5:39   ` Nadav Amit
2022-11-02 21:21     ` Peter Xu
2022-11-04  0:21 ` [PATCH RFC 00/10] mm/hugetlb: Make huge_pte_offset() thread-safe for pmd unshare Mike Kravetz
2022-11-04 15:02   ` Peter Xu
2022-11-04 15:44     ` Mike Kravetz

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=Y2PjLlJaBVWDd2bn@x1n \
    --to=peterx@redhat.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.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=nadav.amit@gmail.com \
    --cc=riel@surriel.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