summaryrefslogtreecommitdiffstats
path: root/lib/ioremap.c
diff options
context:
space:
mode:
authorWill Deacon <will.deacon@arm.com>2018-12-28 03:37:53 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2018-12-28 15:11:50 -0500
commit8e2d43405b22e98cf5f3730c1829ec1fdbe17ae7 (patch)
treec30cf15a54d92a9e56c9c2c1e5fd9455e816b432 /lib/ioremap.c
parent36ddc5a78c878e9b10c323d2fe88b0dae2f487eb (diff)
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.com Signed-off-by: Will Deacon <will.deacon@arm.com> Reviewed-by: Toshi 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/ioremap.c')
-rw-r--r--lib/ioremap.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/ioremap.c b/lib/ioremap.c
index 10d7c5485c39..063213685563 100644
--- a/lib/ioremap.c
+++ b/lib/ioremap.c
@@ -156,6 +156,25 @@ static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr,
156 return 0; 156 return 0;
157} 157}
158 158
159static int ioremap_try_huge_p4d(p4d_t *p4d, unsigned long addr,
160 unsigned long end, phys_addr_t phys_addr,
161 pgprot_t prot)
162{
163 if (!ioremap_p4d_enabled())
164 return 0;
165
166 if ((end - addr) != P4D_SIZE)
167 return 0;
168
169 if (!IS_ALIGNED(phys_addr, P4D_SIZE))
170 return 0;
171
172 if (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr))
173 return 0;
174
175 return p4d_set_huge(p4d, phys_addr, prot);
176}
177
159static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr, 178static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr,
160 unsigned long end, phys_addr_t phys_addr, pgprot_t prot) 179 unsigned long end, phys_addr_t phys_addr, pgprot_t prot)
161{ 180{
@@ -168,12 +187,8 @@ static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr,
168 do { 187 do {
169 next = p4d_addr_end(addr, end); 188 next = p4d_addr_end(addr, end);
170 189
171 if (ioremap_p4d_enabled() && 190 if (ioremap_try_huge_p4d(p4d, addr, next, phys_addr, prot))
172 ((next - addr) == P4D_SIZE) && 191 continue;
173 IS_ALIGNED(phys_addr, P4D_SIZE)) {
174 if (p4d_set_huge(p4d, phys_addr, prot))
175 continue;
176 }
177 192
178 if (ioremap_pud_range(p4d, addr, next, phys_addr, prot)) 193 if (ioremap_pud_range(p4d, addr, next, phys_addr, prot))
179 return -ENOMEM; 194 return -ENOMEM;