Commit 8e2d4340 authored by Will Deacon's avatar Will Deacon Committed by Linus Torvalds

lib/ioremap: ensure break-before-make is used for huge p4d mappings

Whilst no architectures actually enable support for huge p4d mappings in
the vmap area, the code that is implemented should be using
break-before-make, as we do for pud and pmd huge entries.

Link: http://lkml.kernel.org/r/1544120495-17438-6-git-send-email-will.deacon@arm.comSigned-off-by: default avatarWill Deacon <will.deacon@arm.com>
Reviewed-by: default avatarToshi Kani <toshi.kani@hpe.com>
Cc: Chintan Pandya <cpandya@codeaurora.org>
Cc: Toshi Kani <toshi.kani@hpe.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Michal Hocko <mhocko@suse.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 36ddc5a7
...@@ -1043,6 +1043,11 @@ int pud_free_pmd_page(pud_t *pudp, unsigned long addr) ...@@ -1043,6 +1043,11 @@ int pud_free_pmd_page(pud_t *pudp, unsigned long addr)
return 1; return 1;
} }
int p4d_free_pud_page(p4d_t *p4d, unsigned long addr)
{
return 0; /* Don't attempt a block mapping */
}
#ifdef CONFIG_MEMORY_HOTPLUG #ifdef CONFIG_MEMORY_HOTPLUG
int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
bool want_memblock) bool want_memblock)
......
...@@ -794,6 +794,14 @@ int pmd_clear_huge(pmd_t *pmd) ...@@ -794,6 +794,14 @@ int pmd_clear_huge(pmd_t *pmd)
return 0; return 0;
} }
/*
* Until we support 512GB pages, skip them in the vmap area.
*/
int p4d_free_pud_page(p4d_t *p4d, unsigned long addr)
{
return 0;
}
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
/** /**
* pud_free_pmd_page - Clear pud entry and free pmd page. * pud_free_pmd_page - Clear pud entry and free pmd page.
......
...@@ -1057,6 +1057,7 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot); ...@@ -1057,6 +1057,7 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot);
int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot); int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot);
int pud_clear_huge(pud_t *pud); int pud_clear_huge(pud_t *pud);
int pmd_clear_huge(pmd_t *pmd); int pmd_clear_huge(pmd_t *pmd);
int p4d_free_pud_page(p4d_t *p4d, unsigned long addr);
int pud_free_pmd_page(pud_t *pud, unsigned long addr); int pud_free_pmd_page(pud_t *pud, unsigned long addr);
int pmd_free_pte_page(pmd_t *pmd, unsigned long addr); int pmd_free_pte_page(pmd_t *pmd, unsigned long addr);
#else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ #else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */
...@@ -1084,6 +1085,10 @@ static inline int pmd_clear_huge(pmd_t *pmd) ...@@ -1084,6 +1085,10 @@ static inline int pmd_clear_huge(pmd_t *pmd)
{ {
return 0; return 0;
} }
static inline int p4d_free_pud_page(p4d_t *p4d, unsigned long addr)
{
return 0;
}
static inline int pud_free_pmd_page(pud_t *pud, unsigned long addr) static inline int pud_free_pmd_page(pud_t *pud, unsigned long addr)
{ {
return 0; return 0;
......
...@@ -156,6 +156,25 @@ static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr, ...@@ -156,6 +156,25 @@ static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr,
return 0; return 0;
} }
static int ioremap_try_huge_p4d(p4d_t *p4d, unsigned long addr,
unsigned long end, phys_addr_t phys_addr,
pgprot_t prot)
{
if (!ioremap_p4d_enabled())
return 0;
if ((end - addr) != P4D_SIZE)
return 0;
if (!IS_ALIGNED(phys_addr, P4D_SIZE))
return 0;
if (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr))
return 0;
return p4d_set_huge(p4d, phys_addr, prot);
}
static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr, static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr,
unsigned long end, phys_addr_t phys_addr, pgprot_t prot) unsigned long end, phys_addr_t phys_addr, pgprot_t prot)
{ {
...@@ -168,12 +187,8 @@ static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr, ...@@ -168,12 +187,8 @@ static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr,
do { do {
next = p4d_addr_end(addr, end); next = p4d_addr_end(addr, end);
if (ioremap_p4d_enabled() && if (ioremap_try_huge_p4d(p4d, addr, next, phys_addr, prot))
((next - addr) == P4D_SIZE) &&
IS_ALIGNED(phys_addr, P4D_SIZE)) {
if (p4d_set_huge(p4d, phys_addr, prot))
continue; continue;
}
if (ioremap_pud_range(p4d, addr, next, phys_addr, prot)) if (ioremap_pud_range(p4d, addr, next, phys_addr, prot))
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment