Skip to content

Commit 1d37713

Browse files
ryanhrobctmarinas
authored andcommitted
arm64: mm: Remove pmd_sect() and pud_sect()
The semantics of pXd_leaf() are very similar to pXd_sect(). The only difference is that pXd_sect() only considers it a section if PTE_VALID is set, whereas pXd_leaf() permits both "valid" and "present-invalid" types. Using pXd_sect() has caused issues now that large leaf entries can be present-invalid since commit a166563 ("arm64: mm: support large block mapping when rodata=full"), so let's just remove the API and standardize on pXd_leaf(). There are a few callsites of the form pXd_leaf(READ_ONCE(*pXdp)). This was previously fine for the pXd_sect() macro because it only evaluated its argument once. But pXd_leaf() evaluates its argument multiple times. So let's avoid unintended side effects by reimplementing pXd_leaf() as an inline function. Signed-off-by: Ryan Roberts <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent 15bfba1 commit 1d37713

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

arch/arm64/include/asm/pgtable.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,13 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
784784

785785
#define pmd_table(pmd) ((pmd_val(pmd) & PMD_TYPE_MASK) == \
786786
PMD_TYPE_TABLE)
787-
#define pmd_sect(pmd) ((pmd_val(pmd) & PMD_TYPE_MASK) == \
788-
PMD_TYPE_SECT)
789-
#define pmd_leaf(pmd) (pmd_present(pmd) && !pmd_table(pmd))
787+
788+
#define pmd_leaf pmd_leaf
789+
static inline bool pmd_leaf(pmd_t pmd)
790+
{
791+
return pmd_present(pmd) && !pmd_table(pmd);
792+
}
793+
790794
#define pmd_bad(pmd) (!pmd_table(pmd))
791795

792796
#define pmd_leaf_size(pmd) (pmd_cont(pmd) ? CONT_PMD_SIZE : PMD_SIZE)
@@ -804,11 +808,8 @@ static inline int pmd_trans_huge(pmd_t pmd)
804808
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
805809

806810
#if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS < 3
807-
static inline bool pud_sect(pud_t pud) { return false; }
808811
static inline bool pud_table(pud_t pud) { return true; }
809812
#else
810-
#define pud_sect(pud) ((pud_val(pud) & PUD_TYPE_MASK) == \
811-
PUD_TYPE_SECT)
812813
#define pud_table(pud) ((pud_val(pud) & PUD_TYPE_MASK) == \
813814
PUD_TYPE_TABLE)
814815
#endif
@@ -878,7 +879,11 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
878879
PUD_TYPE_TABLE)
879880
#define pud_present(pud) pte_present(pud_pte(pud))
880881
#ifndef __PAGETABLE_PMD_FOLDED
881-
#define pud_leaf(pud) (pud_present(pud) && !pud_table(pud))
882+
#define pud_leaf pud_leaf
883+
static inline bool pud_leaf(pud_t pud)
884+
{
885+
return pud_present(pud) && !pud_table(pud);
886+
}
882887
#else
883888
#define pud_leaf(pud) false
884889
#endif

arch/arm64/mm/mmu.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr,
204204
pmd_t pmd = READ_ONCE(*pmdp);
205205
pte_t *ptep;
206206

207-
BUG_ON(pmd_sect(pmd));
207+
BUG_ON(pmd_leaf(pmd));
208208
if (pmd_none(pmd)) {
209209
pmdval_t pmdval = PMD_TYPE_TABLE | PMD_TABLE_UXN | PMD_TABLE_AF;
210210
phys_addr_t pte_phys;
@@ -303,7 +303,7 @@ static int alloc_init_cont_pmd(pud_t *pudp, unsigned long addr,
303303
/*
304304
* Check for initial section mappings in the pgd/pud.
305305
*/
306-
BUG_ON(pud_sect(pud));
306+
BUG_ON(pud_leaf(pud));
307307
if (pud_none(pud)) {
308308
pudval_t pudval = PUD_TYPE_TABLE | PUD_TABLE_UXN | PUD_TABLE_AF;
309309
phys_addr_t pmd_phys;
@@ -1503,7 +1503,7 @@ static void unmap_hotplug_pmd_range(pud_t *pudp, unsigned long addr,
15031503
continue;
15041504

15051505
WARN_ON(!pmd_present(pmd));
1506-
if (pmd_sect(pmd)) {
1506+
if (pmd_leaf(pmd)) {
15071507
pmd_clear(pmdp);
15081508

15091509
/*
@@ -1536,7 +1536,7 @@ static void unmap_hotplug_pud_range(p4d_t *p4dp, unsigned long addr,
15361536
continue;
15371537

15381538
WARN_ON(!pud_present(pud));
1539-
if (pud_sect(pud)) {
1539+
if (pud_leaf(pud)) {
15401540
pud_clear(pudp);
15411541

15421542
/*
@@ -1650,7 +1650,7 @@ static void free_empty_pmd_table(pud_t *pudp, unsigned long addr,
16501650
if (pmd_none(pmd))
16511651
continue;
16521652

1653-
WARN_ON(!pmd_present(pmd) || !pmd_table(pmd) || pmd_sect(pmd));
1653+
WARN_ON(!pmd_present(pmd) || !pmd_table(pmd));
16541654
free_empty_pte_table(pmdp, addr, next, floor, ceiling);
16551655
} while (addr = next, addr < end);
16561656

@@ -1690,7 +1690,7 @@ static void free_empty_pud_table(p4d_t *p4dp, unsigned long addr,
16901690
if (pud_none(pud))
16911691
continue;
16921692

1693-
WARN_ON(!pud_present(pud) || !pud_table(pud) || pud_sect(pud));
1693+
WARN_ON(!pud_present(pud) || !pud_table(pud));
16941694
free_empty_pmd_table(pudp, addr, next, floor, ceiling);
16951695
} while (addr = next, addr < end);
16961696

@@ -1786,7 +1786,7 @@ int __meminit vmemmap_check_pmd(pmd_t *pmdp, int node,
17861786
{
17871787
vmemmap_verify((pte_t *)pmdp, node, addr, next);
17881788

1789-
return pmd_sect(READ_ONCE(*pmdp));
1789+
return pmd_leaf(READ_ONCE(*pmdp));
17901790
}
17911791

17921792
int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
@@ -1850,15 +1850,15 @@ void p4d_clear_huge(p4d_t *p4dp)
18501850

18511851
int pud_clear_huge(pud_t *pudp)
18521852
{
1853-
if (!pud_sect(READ_ONCE(*pudp)))
1853+
if (!pud_leaf(READ_ONCE(*pudp)))
18541854
return 0;
18551855
pud_clear(pudp);
18561856
return 1;
18571857
}
18581858

18591859
int pmd_clear_huge(pmd_t *pmdp)
18601860
{
1861-
if (!pmd_sect(READ_ONCE(*pmdp)))
1861+
if (!pmd_leaf(READ_ONCE(*pmdp)))
18621862
return 0;
18631863
pmd_clear(pmdp);
18641864
return 1;

0 commit comments

Comments
 (0)