From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-pl0-x233.google.com ([2607:f8b0:400e:c01::233]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fKxmU-00047k-ON for barebox@lists.infradead.org; Tue, 22 May 2018 03:16:12 +0000 Received: by mail-pl0-x233.google.com with SMTP id c19-v6so9990417pls.6 for ; Mon, 21 May 2018 20:16:00 -0700 (PDT) From: Andrey Smirnov Date: Mon, 21 May 2018 20:15:04 -0700 Message-Id: <20180522031510.25505-24-andrew.smirnov@gmail.com> In-Reply-To: <20180522031510.25505-1-andrew.smirnov@gmail.com> References: <20180522031510.25505-1-andrew.smirnov@gmail.com> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH v4 23/29] ARM: mmu: Make sure that address is 1M aligned in arm_create_pte() To: barebox@lists.infradead.org Cc: Andrey Smirnov If address passed arm_create_pte() is not 1M (PGDIR_SIZE) aligned, page table that is created will end up having unexpected mapping offset, breaking "1:1 mapping" assumption and leading to bugs that are not immediately obvious in their nature. To prevent this and because all of the callers already do said alignement in-place, move the alignment code to be a part of arm_create_pte(). Signed-off-by: Andrey Smirnov --- arch/arm/cpu/mmu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c index 1713238ad..21394deb1 100644 --- a/arch/arm/cpu/mmu.c +++ b/arch/arm/cpu/mmu.c @@ -92,6 +92,8 @@ static u32 *arm_create_pte(unsigned long virt, uint32_t flags) u32 *table; int i; + virt = ALIGN_DOWN(virt, PGDIR_SIZE); + table = xmemalign(PTRS_PER_PTE * sizeof(u32), PTRS_PER_PTE * sizeof(u32)); @@ -291,8 +293,7 @@ static void create_vector_table(unsigned long adr) vectors = xmemalign(PAGE_SIZE, PAGE_SIZE); pr_debug("Creating vector table, virt = 0x%p, phys = 0x%08lx\n", vectors, adr); - exc = arm_create_pte(ALIGN_DOWN(adr, PGDIR_SIZE), - pte_flags_uncached); + exc = arm_create_pte(adr, pte_flags_uncached); idx = (adr & (PGDIR_SIZE - 1)) >> PAGE_SHIFT; exc[idx] = (u32)vectors | PTE_TYPE_SMALL | pte_flags_cached; } -- 2.17.0 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox