public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Samuel Mendoza-Jonas <samjonas@amazon.com>
Cc: stable@vger.kernel.org, benh@amazon.com,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	David Hildenbrand <david@redhat.com>,
	Muchun Song <songmuchun@bytedance.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Sasha Levin <sashal@kernel.org>
Subject: Re: [PATCH 5.4 v2] mm/hugetlb: fix races when looking up a CONT-PTE/PMD size hugetlb page
Date: Wed, 14 Dec 2022 19:31:28 +0100	[thread overview]
Message-ID: <Y5oWgLw6AiwTIq1f@kroah.com> (raw)
In-Reply-To: <20221214020609.832545-1-samjonas@amazon.com>

On Tue, Dec 13, 2022 at 06:06:09PM -0800, Samuel Mendoza-Jonas wrote:
> From: Baolin Wang <baolin.wang@linux.alibaba.com>
> 
> [ Upstream commit fac35ba763ed07ba93154c95ffc0c4a55023707f ]
> 
> On some architectures (like ARM64), it can support CONT-PTE/PMD size
> hugetlb, which means it can support not only PMD/PUD size hugetlb (2M and
> 1G), but also CONT-PTE/PMD size(64K and 32M) if a 4K page size specified.
> 
> So when looking up a CONT-PTE size hugetlb page by follow_page(), it will
> use pte_offset_map_lock() to get the pte entry lock for the CONT-PTE size
> hugetlb in follow_page_pte().  However this pte entry lock is incorrect
> for the CONT-PTE size hugetlb, since we should use huge_pte_lock() to get
> the correct lock, which is mm->page_table_lock.
> 
> That means the pte entry of the CONT-PTE size hugetlb under current pte
> lock is unstable in follow_page_pte(), we can continue to migrate or
> poison the pte entry of the CONT-PTE size hugetlb, which can cause some
> potential race issues, even though they are under the 'pte lock'.
> 
> For example, suppose thread A is trying to look up a CONT-PTE size hugetlb
> page by move_pages() syscall under the lock, however antoher thread B can
> migrate the CONT-PTE hugetlb page at the same time, which will cause
> thread A to get an incorrect page, if thread A also wants to do page
> migration, then data inconsistency error occurs.
> 
> Moreover we have the same issue for CONT-PMD size hugetlb in
> follow_huge_pmd().
> 
> To fix above issues, rename the follow_huge_pmd() as follow_huge_pmd_pte()
> to handle PMD and PTE level size hugetlb, which uses huge_pte_lock() to
> get the correct pte entry lock to make the pte entry stable.
> 
> Mike said:
> 
> Support for CONT_PMD/_PTE was added with bb9dd3df8ee9 ("arm64: hugetlb:
> refactor find_num_contig()").  Patch series "Support for contiguous pte
> hugepages", v4.  However, I do not believe these code paths were
> executed until migration support was added with 5480280d3f2d ("arm64/mm:
> enable HugeTLB migration for contiguous bit HugeTLB pages") I would go
> with 5480280d3f2d for the Fixes: targe.
> 
> Link: https://lkml.kernel.org/r/635f43bdd85ac2615a58405da82b4d33c6e5eb05.1662017562.git.baolin.wang@linux.alibaba.com
> Fixes: 5480280d3f2d ("arm64/mm: enable HugeTLB migration for contiguous bit HugeTLB pages")
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> Suggested-by: Mike Kravetz <mike.kravetz@oracle.com>
> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Muchun Song <songmuchun@bytedance.com>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> [5.4: Fixup contextual diffs before pin_user_pages()]
> Signed-off-by: Samuel Mendoza-Jonas <samjonas@amazon.com>
> ---
> v2: Fix up stray out label that is now unused.

Now queued up, thanks.

greg k-h

      reply	other threads:[~2022-12-14 18:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14  2:06 [PATCH 5.4 v2] mm/hugetlb: fix races when looking up a CONT-PTE/PMD size hugetlb page Samuel Mendoza-Jonas
2022-12-14 18:31 ` Greg KH [this message]

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=Y5oWgLw6AiwTIq1f@kroah.com \
    --to=greg@kroah.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=benh@amazon.com \
    --cc=david@redhat.com \
    --cc=mike.kravetz@oracle.com \
    --cc=samjonas@amazon.com \
    --cc=sashal@kernel.org \
    --cc=songmuchun@bytedance.com \
    --cc=stable@vger.kernel.org \
    /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