From patchwork Sat Aug 4 07:00:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: R Sricharan X-Patchwork-Id: 1272991 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 92CAFDF24C for ; Sat, 4 Aug 2012 07:03:27 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SxYLu-0002L6-3u; Sat, 04 Aug 2012 07:00:46 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SxYLq-0002KQ-Su for linux-arm-kernel@lists.infradead.org; Sat, 04 Aug 2012 07:00:43 +0000 Received: from dbdp20.itg.ti.com ([172.24.170.38]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id q7470XC3029704; Sat, 4 Aug 2012 02:00:34 -0500 Received: from DBDE70.ent.ti.com (localhost [127.0.0.1]) by dbdp20.itg.ti.com (8.13.8/8.13.8) with ESMTP id q7470WMC012697; Sat, 4 Aug 2012 12:30:33 +0530 (IST) Received: from dbdp32.itg.ti.com (172.24.170.251) by dbde70.ent.ti.com (172.24.170.148) with Microsoft SMTP Server id 14.1.323.3; Sat, 4 Aug 2012 12:30:32 +0530 Received: from lokesh.apr.dhcp.ti.com (smtpvbd.itg.ti.com [172.24.170.250]) by dbdp32.itg.ti.com (8.13.8/8.13.8) with ESMTP id q7470Trw005142; Sat, 4 Aug 2012 12:30:31 +0530 From: R Sricharan To: Subject: [PATCH 1/1] ARM: Fix mapping in alloc_init_section for unaligned addresses. Date: Sat, 4 Aug 2012 12:30:22 +0530 Message-ID: <1344063622-11021-1-git-send-email-r.sricharan@ti.com> X-Mailer: git-send-email 1.7.1 MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -6.9 (------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-6.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [198.47.26.153 listed in list.dnswl.org] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: catalin.marinas@arm.com, santosh.shilimkar@ti.com, R Sricharan X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org When either the start address or end address or physical address to be mapped is unaligned, alloc_init_section creates page granularity mappings. alloc_init_section calls alloc_init_pte which populates one pmd entry and sets up the ptes. But if the size is greater than what can be mapped by one pmd entry, then the rest remains unmapped. The issue becomes visible when LPAE is enabled, where we have the 3 levels with seperate pgd and pmd's. When a static mapping for 3MB is requested, only 2MB is mapped and the remaining 1MB is unmapped. Fixing this here, by looping in to map the entire unaligned address range. Signed-off-by: R Sricharan Reviewed-by: Santosh Shilimkar Cc: Catalin Marinas --- arch/arm/mm/mmu.c | 54 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index cf4528d..c8c405f 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -597,34 +597,42 @@ static void __init alloc_init_section(pud_t *pud, unsigned long addr, const struct mem_type *type) { pmd_t *pmd = pmd_offset(pud, addr); - - /* - * Try a section mapping - end, addr and phys must all be aligned - * to a section boundary. Note that PMDs refer to the individual - * L1 entries, whereas PGDs refer to a group of L1 entries making - * up one logical pointer to an L2 table. - */ - if (type->prot_sect && ((addr | end | phys) & ~SECTION_MASK) == 0) { - pmd_t *p = pmd; + unsigned long next; #ifndef CONFIG_ARM_LPAE - if (addr & SECTION_SIZE) - pmd++; + if ((addr & SECTION_SIZE) && + (type->prot_sect && ((addr | next | phys) & ~SECTION_MASK) == 0)) + pmd++; #endif - - do { - *pmd = __pmd(phys | type->prot_sect); - phys += SECTION_SIZE; - } while (pmd++, addr += SECTION_SIZE, addr != end); - - flush_pmd_entry(p); - } else { + do { + if ((end - addr) & SECTION_MASK) + next = (addr + SECTION_SIZE) & SECTION_MASK; + else + next = end; /* - * No need to loop; pte's aren't interested in the - * individual L1 entries. + * Try a section mapping - end, addr and phys must all be + * aligned to a section boundary. Note that PMDs refer to + * the individual L1 entries, whereas PGDs refer to a group + * of L1 entries making up one logical pointer to an L2 table. */ - alloc_init_pte(pmd, addr, end, __phys_to_pfn(phys), type); - } + if (type->prot_sect && + ((addr | next | phys) & ~SECTION_MASK) == 0) { + *pmd = __pmd(phys | type->prot_sect); + flush_pmd_entry(pmd); + } else { + /* + * when addresses are not aligned, + * we may be required to map address range greater + * than a section size. So loop in here to map the + * complete range. + */ + alloc_init_pte(pmd, addr, next, + __phys_to_pfn(phys), type); + } + + phys += next - addr; + + } while (pmd++, addr = next, addr != end); } static void __init alloc_init_pud(pgd_t *pgd, unsigned long addr,