linux-stable/arch/powerpc/mm/book3s64
Ryan Roberts 7a2bc8b34e mm: fix race between __split_huge_pmd_locked() and GUP-fast
commit 3a5a8d343e upstream.

__split_huge_pmd_locked() can be called for a present THP, devmap or
(non-present) migration entry.  It calls pmdp_invalidate() unconditionally
on the pmdp and only determines if it is present or not based on the
returned old pmd.  This is a problem for the migration entry case because
pmd_mkinvalid(), called by pmdp_invalidate() must only be called for a
present pmd.

On arm64 at least, pmd_mkinvalid() will mark the pmd such that any future
call to pmd_present() will return true.  And therefore any lockless
pgtable walker could see the migration entry pmd in this state and start
interpretting the fields as if it were present, leading to BadThings (TM).
GUP-fast appears to be one such lockless pgtable walker.

x86 does not suffer the above problem, but instead pmd_mkinvalid() will
corrupt the offset field of the swap entry within the swap pte.  See link
below for discussion of that problem.

Fix all of this by only calling pmdp_invalidate() for a present pmd.  And
for good measure let's add a warning to all implementations of
pmdp_invalidate[_ad]().  I've manually reviewed all other
pmdp_invalidate[_ad]() call sites and believe all others to be conformant.

This is a theoretical bug found during code review.  I don't have any test
case to trigger it in practice.

Link: https://lkml.kernel.org/r/20240501143310.1381675-1-ryan.roberts@arm.com
Link: https://lore.kernel.org/all/0dd7827a-6334-439a-8fd0-43c98e6af22b@arm.com/
Fixes: 84c3fc4e9c ("mm: thp: check pmd migration entry in common path")
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Naveen N. Rao <naveen.n.rao@linux.ibm.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-06-16 13:41:38 +02:00
..
hash_4k.c
hash_64k.c
hash_hugepage.c
hash_native.c powerpc/64s: Fix native_hpte_remove() to be irq-safe 2023-07-23 13:49:33 +02:00
hash_pgtable.c powerpc/64s: Fix hash__change_memory_range preemption warning 2022-10-18 22:46:18 +11:00
hash_tlb.c powerpc/mm/book3s/hash: Rename flush_tlb_pmd_range 2022-09-30 18:35:52 +10:00
hash_utils.c powerpc/64s: make linear_map_hash_lock a raw spinlock 2022-10-18 22:46:18 +11:00
hugetlbpage.c powerpc/mm: Update default hugetlb size early 2022-02-12 22:47:44 +11:00
internal.h
iommu_api.c KVM: PPC: Book3s: Retire H_PUT_TCE/etc real mode handlers 2022-05-19 00:44:01 +10:00
Makefile powerpc: Book3S 64-bit outline-only KASAN support 2022-05-22 15:58:29 +10:00
mmu_context.c powerpc/mm: Add __init attribute to eligible functions 2021-12-23 22:33:11 +11:00
pgtable.c mm: fix race between __split_huge_pmd_locked() and GUP-fast 2024-06-16 13:41:38 +02:00
pkeys.c powerpc: Include asm/firmware.h in all users of firmware_has_feature() 2022-06-29 16:45:05 +10:00
radix_hugetlbpage.c powerpc/64s: POWER10 nest MMU can upgrade PTE access authority without TLB flush 2022-07-27 21:36:04 +10:00
radix_pgtable.c powerpc/book3s64/mm: Fix DirectMap stats in /proc/meminfo 2023-07-19 16:21:40 +02:00
radix_tlb.c powerpc/radix: Move some functions into #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 2023-09-13 09:42:47 +02:00
slb.c powerpc: Don't include lppaca.h in paca.h 2023-09-13 09:42:48 +02:00
slice.c powerpc/mm: Enable full randomisation of memory mappings 2022-05-05 22:11:58 +10:00
subpage_prot.c powerpc: remove mmap linked list walks 2022-09-26 19:46:19 -07:00
trace.c mm/migration: add trace events for THP migrations 2022-03-24 19:06:45 -07:00