From patchwork Tue Feb 7 08:08:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 9559345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 229AF60216 for ; Tue, 7 Feb 2017 08:09:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 156D020410 for ; Tue, 7 Feb 2017 08:09:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0833023F88; Tue, 7 Feb 2017 08:09:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1CE0D20410 for ; Tue, 7 Feb 2017 08:09:18 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cb0pv-00050g-Nk; Tue, 07 Feb 2017 08:09:15 +0000 Received: from mail-pf0-f175.google.com ([209.85.192.175]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cb0pi-0004V6-IV for linux-arm-kernel@lists.infradead.org; Tue, 07 Feb 2017 08:09:09 +0000 Received: by mail-pf0-f175.google.com with SMTP id 189so31315198pfu.3 for ; Tue, 07 Feb 2017 00:08:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uK/tBf4h5DOB8doKRgYgsKz80xpl4/ZqEt2mKX8vSuk=; b=TZI93xmomLRVzk9Tc44Bthz5aXYtr5+YmBmzJymLwJViHjC0ofXOFAMg09Iz+sb4s4 6ZbPU4RHVUOYwrThCOB3Ifnf1Aa1PRc0k1uJW/BAs4Hq9a8CbSd5F5HEumX7mzJ0qjuf liaHOcRFpL+mCA3PW1mFc5U9JRzjBmXAvFyLw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uK/tBf4h5DOB8doKRgYgsKz80xpl4/ZqEt2mKX8vSuk=; b=lAWO/ljyUnjR+BsgagHZZGjCvVdgsVfhJZiVPVaw0Ucnx76kPZy6mdLCBY7Wa7HCJx 3nK/6nCIg98C8hovWQgEaX+9n5T1NxU4f8Fvms4cOVUEqSOFfRICOPELUKJRqMDMHA+O B05z/7L1Cdjcl29NMCrMexVtna2CMl2/A0hwusJ5w0H8iEZ6N5rReuF7/R5F3cElZg+A N+NKza6EFJh3VV0SJn4QfRO9vA2eXL71d8QyLXl1ZGeswrzLsHncek1fuigC2084DiAa 1QOOgFENaNI/cRXi+rTeATvMwwOk4KpXQxDmHctyiFVBqDzTvMbSkNlZumgxrd2FaoyB Vaqw== X-Gm-Message-State: AIkVDXIJSWHnnmGmvKY/MUmnM7GPyKfMHsFwtxgCVEqcWKbc/syC5qT705zUabDn39Dve/fw X-Received: by 10.99.44.3 with SMTP id s3mr18960555pgs.148.1486454861700; Tue, 07 Feb 2017 00:07:41 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id n8sm8613320pgc.16.2017.02.07.00.07.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Feb 2017 00:07:41 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com Subject: [PATCH v32 05/13] arm64: mm: allow for unmapping part of kernel mapping Date: Tue, 7 Feb 2017 17:08:57 +0900 Message-Id: <20170207080904.5974-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170207080601.5816-1-takahiro.akashi@linaro.org> References: <20170207080601.5816-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170207_000902_836764_412B1A74 X-CRM114-Status: GOOD ( 12.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, geoff@infradead.org, kexec@lists.infradead.org, AKASHI Takahiro , james.morse@arm.com, bauerman@linux.vnet.ibm.com, dyoung@redhat.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP create_pgd_mapping() is enhanced here so that it will accept PAGE_KERNEL_INVALID protection attribute and unmap a given range of memory. The feature will be used in a later kdump patch to implement the protection against possible corruption of crash dump kernel memory which is to be set aside from ther other memory on primary kernel. Note that, in this implementation, it assumes that all the range of memory to be processed is mapped in page-level since the only current user is kdump where page mappings are also required. Signed-off-by: AKASHI Takahiro --- arch/arm64/include/asm/pgtable-prot.h | 1 + arch/arm64/mm/mmu.c | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index 2142c7726e76..945d84cd5df7 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -54,6 +54,7 @@ #define PAGE_KERNEL_ROX __pgprot(_PAGE_DEFAULT | PTE_UXN | PTE_DIRTY | PTE_RDONLY) #define PAGE_KERNEL_EXEC __pgprot(_PAGE_DEFAULT | PTE_UXN | PTE_DIRTY | PTE_WRITE) #define PAGE_KERNEL_EXEC_CONT __pgprot(_PAGE_DEFAULT | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_CONT) +#define PAGE_KERNEL_INVALID __pgprot(0) #define PAGE_HYP __pgprot(_PAGE_DEFAULT | PTE_HYP | PTE_HYP_XN) #define PAGE_HYP_EXEC __pgprot(_PAGE_DEFAULT | PTE_HYP | PTE_RDONLY) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 17243e43184e..3c674831f856 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -140,7 +140,11 @@ static void alloc_init_pte(pmd_t *pmd, unsigned long addr, __prot = prot; } - set_pte(pte, pfn_pte(pfn, __prot)); + if (pgprot_val(prot) & PTE_VALID) + set_pte(pte, pfn_pte(pfn, __prot)); + else + pte_clear(null, null, pte); + pfn++; /* @@ -334,12 +338,14 @@ static void __init create_mapping_noalloc(phys_addr_t phys, unsigned long virt, __create_pgd_mapping(init_mm.pgd, phys, virt, size, prot, NULL, false); } -void __init create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, - unsigned long virt, phys_addr_t size, - pgprot_t prot, bool page_mappings_only) +/* + * Note that PAGE_KERNEL_INVALID should be used with page_mappings_only + * true for now. + */ +void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, + unsigned long virt, phys_addr_t size, + pgprot_t prot, bool page_mappings_only) { - BUG_ON(mm == &init_mm); - __create_pgd_mapping(mm->pgd, phys, virt, size, prot, pgd_pgtable_alloc, page_mappings_only); }