From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fJPzy-0005Yl-H9 for barebox@lists.infradead.org; Thu, 17 May 2018 21:00:30 +0000 Received: by mail-pf0-x244.google.com with SMTP id a14-v6so2666801pfi.1 for ; Thu, 17 May 2018 13:59:32 -0700 (PDT) From: Andrey Smirnov Date: Thu, 17 May 2018 13:58:32 -0700 Message-Id: <20180517205837.32421-24-andrew.smirnov@gmail.com> In-Reply-To: <20180517205837.32421-1-andrew.smirnov@gmail.com> References: <20180517205837.32421-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 v3 23/28] 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 are_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