Files
linux/include/linux
Baolin Wang 3a44ae4afa mm/hugetlb: fix races when looking up a CONT-PTE/PMD size hugetlb page
[ Upstream commit fac35ba763 ]

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 bb9dd3df8e ("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 5480280d3f ("arm64/mm:
enable HugeTLB migration for contiguous bit HugeTLB pages") I would go
with 5480280d3f for the Fixes: targe.

Link: https://lkml.kernel.org/r/635f43bdd85ac2615a58405da82b4d33c6e5eb05.1662017562.git.baolin.wang@linux.alibaba.com
Fixes: 5480280d3f ("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>
2022-11-10 18:15:24 +01:00
..
2021-07-21 19:54:21 -07:00
2021-09-20 12:43:34 +01:00
2021-08-29 14:47:42 +03:00
2022-08-17 14:23:11 +02:00
2021-05-06 19:24:11 -07:00
2021-04-14 16:30:30 +03:00
2022-10-26 12:35:12 +02:00
2022-08-31 17:16:34 +02:00
2021-05-24 21:13:05 -07:00
2021-08-16 10:50:32 -06:00
2021-04-08 16:04:20 -07:00
2021-08-26 16:52:03 -07:00
2021-12-14 10:57:11 +01:00
2022-07-07 17:53:26 +02:00
2021-11-25 09:48:41 +01:00
2021-07-20 09:20:49 -07:00
2021-09-07 21:17:28 +02:00
2021-03-22 03:57:39 +01:00
2021-08-26 15:32:28 -04:00
2021-07-27 11:00:36 +02:00
2021-09-06 07:20:56 -04:00
2021-04-12 15:04:23 +02:00
2021-06-25 19:57:01 -04:00
2021-07-26 15:09:44 +02:00
2021-07-27 20:11:45 +01:00
2021-07-27 20:11:44 +01:00
2021-09-03 09:58:13 -07:00
2021-08-05 11:46:42 +01:00
2021-04-30 11:20:40 -07:00
2022-10-26 12:35:26 +02:00
2022-04-13 20:59:03 +02:00
2021-07-27 17:05:06 +01:00
2021-07-27 09:29:15 +02:00
2022-08-17 14:24:08 +02:00
2021-06-01 10:29:21 +01:00
2021-11-18 19:15:51 +01:00
2022-07-12 16:35:08 +02:00
2021-05-12 20:11:17 +02:00
2021-06-17 13:09:27 -04:00
2021-06-15 17:46:57 +02:00
2021-06-29 10:53:53 -07:00
2021-07-01 11:06:05 -07:00
2022-06-09 10:23:32 +02:00
2021-09-17 13:52:17 +01:00
2021-06-16 17:20:40 -05:00
2021-07-06 10:37:46 -05:00
2022-11-03 23:59:15 +09:00
2021-06-07 14:11:47 -07:00
2022-07-02 16:41:17 +02:00
2021-08-18 22:08:24 +02:00
2021-09-02 21:38:56 +02:00
2021-10-07 16:51:57 +02:00
2021-08-17 17:50:51 +02:00
2021-03-18 12:58:27 -04:00
2022-07-12 16:35:08 +02:00
2021-05-10 16:03:35 -07:00
2021-08-06 13:41:48 -07:00
2021-08-19 09:02:55 +09:00
2021-06-24 15:49:32 +02:00
2021-11-21 13:44:12 +01:00
2021-07-01 11:06:03 -07:00
2021-07-27 12:17:21 +02:00
2022-07-29 17:25:32 +02:00
2021-07-27 12:12:08 +02:00
2021-09-08 15:32:35 -07:00
2022-09-15 11:30:05 +02:00
2021-08-11 06:44:24 -04:00
2021-03-30 13:42:33 -04:00