Skip to content

Commit ec50023

Browse files
davidhildenbrandgregkh
authored andcommitted
mm/hugetlb: enforce that PMD PT sharing has split PMD PT locks
[ Upstream commit 188cac5 ] Sharing page tables between processes but falling back to per-MM page table locks cannot possibly work. So, let's make sure that we do have split PMD locks by adding a new Kconfig option and letting that depend on CONFIG_SPLIT_PMD_PTLOCKS. Link: https://lkml.kernel.org/r/20240726150728.3159964-3-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Borislav Petkov <bp@alien8.de> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Christian Brauner <brauner@kernel.org> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Juergen Gross <jgross@suse.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Muchun Song <muchun.song@linux.dev> Cc: "Naveen N. Rao" <naveen.n.rao@linux.ibm.com> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Peter Xu <peterx@redhat.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Stable-dep-of: 59d9094 ("mm: hugetlb: independent PMD page table shared count") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5cfadda commit ec50023

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

fs/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ config HUGETLB_PAGE_OPTIMIZE_VMEMMAP
284284
depends on ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP
285285
depends on SPARSEMEM_VMEMMAP
286286

287+
config HUGETLB_PMD_PAGE_TABLE_SHARING
288+
def_bool HUGETLB_PAGE
289+
depends on ARCH_WANT_HUGE_PMD_SHARE && SPLIT_PMD_PTLOCKS
290+
287291
config ARCH_HAS_GIGANTIC_PAGE
288292
bool
289293

include/linux/hugetlb.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ static inline __init void hugetlb_cma_reserve(int order)
12391239
}
12401240
#endif
12411241

1242-
#ifdef CONFIG_ARCH_WANT_HUGE_PMD_SHARE
1242+
#ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING
12431243
static inline bool hugetlb_pmd_shared(pte_t *pte)
12441244
{
12451245
return page_count(virt_to_page(pte)) > 1;
@@ -1275,8 +1275,7 @@ bool __vma_private_lock(struct vm_area_struct *vma);
12751275
static inline pte_t *
12761276
hugetlb_walk(struct vm_area_struct *vma, unsigned long addr, unsigned long sz)
12771277
{
1278-
#if defined(CONFIG_HUGETLB_PAGE) && \
1279-
defined(CONFIG_ARCH_WANT_HUGE_PMD_SHARE) && defined(CONFIG_LOCKDEP)
1278+
#if defined(CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING) && defined(CONFIG_LOCKDEP)
12801279
struct hugetlb_vma_lock *vma_lock = vma->vm_private_data;
12811280

12821281
/*

mm/hugetlb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6907,7 +6907,7 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
69076907
return 0;
69086908
}
69096909

6910-
#ifdef CONFIG_ARCH_WANT_HUGE_PMD_SHARE
6910+
#ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING
69116911
static unsigned long page_table_shareable(struct vm_area_struct *svma,
69126912
struct vm_area_struct *vma,
69136913
unsigned long addr, pgoff_t idx)
@@ -7069,7 +7069,7 @@ int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma,
70697069
return 1;
70707070
}
70717071

7072-
#else /* !CONFIG_ARCH_WANT_HUGE_PMD_SHARE */
7072+
#else /* !CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING */
70737073

70747074
pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct *vma,
70757075
unsigned long addr, pud_t *pud)
@@ -7092,7 +7092,7 @@ bool want_pmd_share(struct vm_area_struct *vma, unsigned long addr)
70927092
{
70937093
return false;
70947094
}
7095-
#endif /* CONFIG_ARCH_WANT_HUGE_PMD_SHARE */
7095+
#endif /* CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING */
70967096

70977097
#ifdef CONFIG_ARCH_WANT_GENERAL_HUGETLB
70987098
pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
@@ -7190,7 +7190,7 @@ unsigned long hugetlb_mask_last_page(struct hstate *h)
71907190
/* See description above. Architectures can provide their own version. */
71917191
__weak unsigned long hugetlb_mask_last_page(struct hstate *h)
71927192
{
7193-
#ifdef CONFIG_ARCH_WANT_HUGE_PMD_SHARE
7193+
#ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING
71947194
if (huge_page_size(h) == PMD_SIZE)
71957195
return PUD_SIZE - PMD_SIZE;
71967196
#endif

0 commit comments

Comments
 (0)