From patchwork Sat Mar 4 14:30:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9603987 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 5296C60453 for ; Sat, 4 Mar 2017 14:33:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4354B28503 for ; Sat, 4 Mar 2017 14:33:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37FA028589; Sat, 4 Mar 2017 14:33:14 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham 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 DA3B828503 for ; Sat, 4 Mar 2017 14:33:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=cqz33DYpFsmTggttJ29I32IlFRZata6O293yMCn4Sk8=; b=MVPurw1U0JSxnKuEAusIFgu1S6 lP5DYUiPtNKCFpwzedIAiOIj2WCxOPsA/zxS77S6LLHHvbgrET2bB3MA0bmkAgdpMww8YTqoBCjjl pShfQpfUP0RgAVnX7dwJgBzd0MV4Ln/xShBQ1s7iyGuGsKZZv3dOAyPyyXrpav6kUVPemsc0dOF8j BdbLNWu2YuxeyCeYft9KwDH8kQ8H2cKO53SRp3U5yDSZTF1P6y/LRDUXCb4K7Qi9o4di6UPmGgyAU yG4Z1Yes8hfzGe8YDhkFz1Z0Yn8oSlQvFdfyz9XtC0KWj6qxyX583vyycTKvvbUNAAlMVuLRvjkgS 8/nNWHPQ==; 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 1ckAkD-0003MG-6v; Sat, 04 Mar 2017 14:33:13 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckAin-0002Qg-Ie for linux-arm-kernel@lists.infradead.org; Sat, 04 Mar 2017 14:31:47 +0000 Received: by mail-wm0-x234.google.com with SMTP id n11so34481454wma.0 for ; Sat, 04 Mar 2017 06:31:24 -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=JebjuArTEIOtC/kn65SzY3JKRevvVf+oRFy/m3BY+b4=; b=e2G8KgXOPtqnfVNHttsXLaVge/u0sTZMAY56AsgQE0aLuYrzw12sMK5jgx6fmLycXB 5tUnDeVbtyzRbdjyAK4/7EvI0YI+U7SaYeckM35J/rvlkQJo1yTfFDdIuhUbfvlf5Pcp t14fqcVVsbqTQDZlueKP6/5GfGT45R8U7VEj0= 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=JebjuArTEIOtC/kn65SzY3JKRevvVf+oRFy/m3BY+b4=; b=m6xHlih+w8a8FAkzBi0UdcC3foMGBNlg9UM1+q5SFpBfnWyC2iUZ5YA7DxaWAUwB16 J2NC/6FDb+WKoWlHwbf2N8FyeGKHF5kUIm1kEhdwLokTjjOoSSPwasOmANGKC+B2t6wo +1+D+fnmheCoHOhakbCd7PjhswaawBMekc3CCw3UGY0J9ReN2BAQg8eHR+R+kRAn0sTX nRpciyhusARhD4Q/ALm4Gxx7knuhPPXX17zU3ODk6TrF0/YrvRFEIo7jgW/i0pJvuJnU 2V//O6LFJiJLmBg6J7w0YrhWeIH9Nl/OIL26NWhFDE7z/oj6/t8it8t7aZVAmLQ4OiO/ T/kA== X-Gm-Message-State: AMke39mqBsFgu/JeKpeHMf1KD64O1l/dDoAVag4rHY8+7Bc7hrThD9phl9Llolsj29GbaeHg X-Received: by 10.28.92.193 with SMTP id q184mr7502297wmb.139.1488637883561; Sat, 04 Mar 2017 06:31:23 -0800 (PST) Received: from localhost.localdomain ([197.130.214.201]) by smtp.gmail.com with ESMTPSA id c35sm19497267wra.1.2017.03.04.06.31.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 04 Mar 2017 06:31:22 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, kernel-hardening@lists.openwall.com, mark.rutland@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, labbott@fedoraproject.org Subject: [PATCH v4 2/6] arm64: mmu: move TLB maintenance from callers to create_mapping_late() Date: Sat, 4 Mar 2017 14:30:44 +0000 Message-Id: <1488637848-13588-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488637848-13588-1-git-send-email-ard.biesheuvel@linaro.org> References: <1488637848-13588-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170304_063145_776729_1F840340 X-CRM114-Status: GOOD ( 12.68 ) 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: keescook@chromium.org, suzuki.poulose@arm.com, marc.zyngier@arm.com, andre.przywara@arm.com, Ard Biesheuvel , james.morse@arm.com, kvmarm@lists.cs.columbia.edu 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 In preparation of refactoring the kernel mapping logic so that text regions are never mapped writable, which would require adding explicit TLB maintenance to new call sites of create_mapping_late() (which is currently invoked twice from the same function), move the TLB maintenance from the call site into create_mapping_late() itself, and change it from a full TLB flush into a flush by VA, which is more appropriate here. Also, given that create_mapping_late() has evolved into a routine that only updates protection bits on existing mappings, rename it to update_mapping_prot() Reviewed-by: Mark Rutland Tested-by: Mark Rutland Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/mmu.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index d28dbcf596b6..6cafd8723d1a 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -319,17 +319,20 @@ void __init create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, pgd_pgtable_alloc, page_mappings_only); } -static void create_mapping_late(phys_addr_t phys, unsigned long virt, - phys_addr_t size, pgprot_t prot) +static void update_mapping_prot(phys_addr_t phys, unsigned long virt, + phys_addr_t size, pgprot_t prot) { if (virt < VMALLOC_START) { - pr_warn("BUG: not creating mapping for %pa at 0x%016lx - outside kernel range\n", + pr_warn("BUG: not updating mapping for %pa at 0x%016lx - outside kernel range\n", &phys, virt); return; } __create_pgd_mapping(init_mm.pgd, phys, virt, size, prot, NULL, debug_pagealloc_enabled()); + + /* flush the TLBs after updating live kernel mappings */ + flush_tlb_kernel_range(virt, virt + size); } static void __init __map_memblock(pgd_t *pgd, phys_addr_t start, phys_addr_t end) @@ -402,19 +405,16 @@ void mark_rodata_ro(void) unsigned long section_size; section_size = (unsigned long)_etext - (unsigned long)_text; - create_mapping_late(__pa_symbol(_text), (unsigned long)_text, + update_mapping_prot(__pa_symbol(_text), (unsigned long)_text, section_size, PAGE_KERNEL_ROX); /* * mark .rodata as read only. Use __init_begin rather than __end_rodata * to cover NOTES and EXCEPTION_TABLE. */ section_size = (unsigned long)__init_begin - (unsigned long)__start_rodata; - create_mapping_late(__pa_symbol(__start_rodata), (unsigned long)__start_rodata, + update_mapping_prot(__pa_symbol(__start_rodata), (unsigned long)__start_rodata, section_size, PAGE_KERNEL_RO); - /* flush the TLBs after updating live kernel mappings */ - flush_tlb_all(); - debug_checkwx(); }