From patchwork Tue Dec 9 07:26:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhichang.yuan@linaro.org X-Patchwork-Id: 42030 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 73D2E244AC for ; Tue, 9 Dec 2014 07:27:53 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf18596wgh.1 for ; Mon, 08 Dec 2014 23:27:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=FpHAxjED6XodX5IAa0wTV47fVNUUaxbk83pAzLKZ50A=; b=NfF27VWMmY9/AEvl69ZoFJBEuDf0JsR8kxJjHSQmaFq8tRC4/ikT74JyBG8KGdyQ+m Y7bxgdo19uukB/1BzVmkxnLgx1mxEyktttnCbw817OCYfMh65SSgFKgFPN3qhRp5cK6i Y5LWqfB0QrfrOmenk8xx66mvaSFIZGrMPpGHgZ2S9kbSf7jynDBGUwkSz5bvvtyQlGji GAbxMSvaavqiyxYwdIioWL247zA0QKDH+QOITUyg6d3R4CvJGsNGk2DokWvSa0BUPs4r mSLqj8B11YlQ9DXn3VrnF7Dejreh9m7csrMGoMzW54x2iArn6egB87wQlFEeL6DH79x8 bi7A== X-Gm-Message-State: ALoCoQn21C48gCuR2ASx8XE0vVFNQgcnHF6rflS0G1xlpGZii4TcxU69bthKivnBii/NZXtH4byJ X-Received: by 10.152.29.226 with SMTP id n2mr67438lah.9.1418110072669; Mon, 08 Dec 2014 23:27:52 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.227 with SMTP id v3ls736118lav.91.gmail; Mon, 08 Dec 2014 23:27:52 -0800 (PST) X-Received: by 10.152.115.172 with SMTP id jp12mr20208595lab.33.1418110072402; Mon, 08 Dec 2014 23:27:52 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id s7si393378laj.74.2014.12.08.23.27.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Dec 2014 23:27:52 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id n15so15480lbi.16 for ; Mon, 08 Dec 2014 23:27:52 -0800 (PST) X-Received: by 10.152.21.66 with SMTP id t2mr19906018lae.27.1418110072177; Mon, 08 Dec 2014 23:27:52 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp719308lbc; Mon, 8 Dec 2014 23:27:51 -0800 (PST) X-Received: by 10.70.87.238 with SMTP id bb14mr27762882pdb.7.1418110070395; Mon, 08 Dec 2014 23:27:50 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cp3si404959pbb.204.2014.12.08.23.27.20 for ; Mon, 08 Dec 2014 23:27:50 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751597AbaLIH1H (ORCPT + 27 others); Tue, 9 Dec 2014 02:27:07 -0500 Received: from mail-pa0-f51.google.com ([209.85.220.51]:56928 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750885AbaLIH1E (ORCPT ); Tue, 9 Dec 2014 02:27:04 -0500 Received: by mail-pa0-f51.google.com with SMTP id ey11so5096pad.38 for ; Mon, 08 Dec 2014 23:27:04 -0800 (PST) X-Received: by 10.68.111.37 with SMTP id if5mr2724150pbb.140.1418110024331; Mon, 08 Dec 2014 23:27:04 -0800 (PST) Received: from localhost ([58.251.159.252]) by mx.google.com with ESMTPSA id ay4sm575625pbb.29.2014.12.08.23.27.01 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 08 Dec 2014 23:27:03 -0800 (PST) From: zhichang.yuan@linaro.org To: Catalin.Marinas@arm.com, will.deacon@arm.com Cc: linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, liguozhu@huawei.com, dsaxena@linaro.org, "zhichang.yuan" Subject: [PATCHv2] arm64:mm: free the useless initial page table Date: Tue, 9 Dec 2014 15:26:47 +0800 Message-Id: <1418110007-13270-1-git-send-email-zhichang.yuan@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: zhichang.yuan@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: "zhichang.yuan" For 64K page system, after mapping a PMD section, the corresponding initial page table is not needed any more. That page can be freed. Changes since v1: * make consistent code between alloc_init_pmd and alloc_init_pud; * flush the TLB before the unused page table is freed; Signed-off-by: Zhichang Yuan --- arch/arm64/include/asm/pgtable.h | 3 +++ arch/arm64/mm/mmu.c | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 41a43bf..8a135b6 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -337,9 +337,12 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, #ifdef CONFIG_ARM64_64K_PAGES #define pud_sect(pud) (0) +#define pud_table(pud) (1) #else #define pud_sect(pud) ((pud_val(pud) & PUD_TYPE_MASK) == \ PUD_TYPE_SECT) +#define pud_table(pud) ((pud_val(pud) & PUD_TYPE_MASK) == \ + PUD_TYPE_TABLE) #endif static inline void set_pmd(pmd_t *pmdp, pmd_t pmd) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index f4f8b50..515f75b 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -191,8 +191,14 @@ static void __init alloc_init_pmd(pud_t *pud, unsigned long addr, * Check for previous table entries created during * boot (__create_page_tables) and flush them. */ - if (!pmd_none(old_pmd)) + if (!pmd_none(old_pmd)) { flush_tlb_all(); + if (pmd_table(old_pmd)) { + phys_addr_t table = __pa(pte_offset_map(&old_pmd, 0)); + + memblock_free(table, PAGE_SIZE); + } + } } else { alloc_init_pte(pmd, addr, next, __phys_to_pfn(phys), prot_pte); @@ -234,9 +240,12 @@ static void __init alloc_init_pud(pgd_t *pgd, unsigned long addr, * Look up the old pmd table and free it. */ if (!pud_none(old_pud)) { - phys_addr_t table = __pa(pmd_offset(&old_pud, 0)); - memblock_free(table, PAGE_SIZE); flush_tlb_all(); + if (pud_table(old_pud)) { + phys_addr_t table = __pa(pmd_offset(&old_pud, 0)); + + memblock_free(table, PAGE_SIZE); + } } } else { alloc_init_pmd(pud, addr, next, phys, map_io);