linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: mmu: set the contiguous for kernel mappings when appropriate
@ 2016-10-10 18:12 Ard Biesheuvel
  2016-10-11  7:44 ` Mark Rutland
  0 siblings, 1 reply; 11+ messages in thread
From: Ard Biesheuvel @ 2016-10-10 18:12 UTC (permalink / raw)
  To: linux-arm-kernel

Now that we no longer allow live kernel PMDs to be split, it is safe to
start using the contiguous bit for kernel mappings. So set the contiguous
bit in the kernel page mappings for regions whose size and alignment are
suitable for this.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/arm64/mm/mmu.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 05615a3fdc6f..c491025c6a70 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -98,8 +98,11 @@ static phys_addr_t __init early_pgtable_alloc(void)
 static void alloc_init_pte(pmd_t *pmd, unsigned long addr,
 				  unsigned long end, unsigned long pfn,
 				  pgprot_t prot,
-				  phys_addr_t (*pgtable_alloc)(void))
+				  phys_addr_t (*pgtable_alloc)(void),
+				  bool allow_block_mappings)
 {
+	pgprot_t prot_cont = __pgprot(pgprot_val(prot) | PTE_CONT);
+	bool cont = false;
 	pte_t *pte;
 
 	BUG_ON(pmd_sect(*pmd));
@@ -115,7 +118,20 @@ static void alloc_init_pte(pmd_t *pmd, unsigned long addr,
 
 	pte = pte_set_fixmap_offset(pmd, addr);
 	do {
-		set_pte(pte, pfn_pte(pfn, prot));
+		/*
+		 * Set the contiguous bit for the subsequent group of PTEs if
+		 * its size and alignment are suitable.
+		 */
+		if (((addr | PFN_PHYS(pfn)) & ~CONT_MASK) == 0)
+			cont = allow_block_mappings && end - addr >= CONT_SIZE;
+
+		/*
+		 * Ensure that we do not change the contiguous bit once this
+		 * PTE has been assigned.
+		 */
+		BUG_ON(!pte_none(*pte) && (cont ^ !!(pte_val(*pte) & PTE_CONT)));
+
+		set_pte(pte, pfn_pte(pfn, cont ? prot_cont : prot));
 		pfn++;
 	} while (pte++, addr += PAGE_SIZE, addr != end);
 
@@ -166,7 +182,8 @@ static void alloc_init_pmd(pud_t *pud, unsigned long addr, unsigned long end,
 			}
 		} else {
 			alloc_init_pte(pmd, addr, next, __phys_to_pfn(phys),
-				       prot, pgtable_alloc);
+				       prot, pgtable_alloc,
+				       allow_block_mappings);
 		}
 		phys += next - addr;
 	} while (pmd++, addr = next, addr != end);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-10-11 16:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-10 18:12 [PATCH] arm64: mmu: set the contiguous for kernel mappings when appropriate Ard Biesheuvel
2016-10-11  7:44 ` Mark Rutland
2016-10-11  7:48   ` Mark Rutland
2016-10-11  8:21   ` Ard Biesheuvel
2016-10-11 15:10     ` Mark Rutland
     [not found]   ` <CAPvkgC1p5yZLtENYMi6zd5-pPDOYUtMw0Lxvb592u975gc+Zvg@mail.gmail.com>
2016-10-11  9:09     ` Ard Biesheuvel
2016-10-11 11:17       ` Ard Biesheuvel
2016-10-11 12:41         ` Will Deacon
2016-10-11 12:56           ` Ard Biesheuvel
2016-10-11 16:29             ` Will Deacon
2016-10-11 16:38               ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).