From patchwork Wed Feb 28 03:56:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 129885 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp567377lja; Tue, 27 Feb 2018 19:57:42 -0800 (PST) X-Google-Smtp-Source: AH8x226Q52Jpc/a2OjhDftFL1AolVTm13xj55gq3SGfEoAyG2Q5BZv+2Plt4FqIE+EfDsTuBhuyb X-Received: by 2002:a17:902:904b:: with SMTP id w11-v6mr16617185plz.11.1519790262072; Tue, 27 Feb 2018 19:57:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519790262; cv=none; d=google.com; s=arc-20160816; b=gtCPKDbQDa6gJJbUQn8CA3rNm95u89uUHr671QxGTUdSZoWEDES2qAw2CCtC+I8Xmf mdFgT5KM8E+nkg33KVMUPByS0qHvi+KnEwvJRb5repED+sKv+/7n1UhYJ5LZDyo0PFEE ykfwOFr7Z6ebCVPOllNfldPBXbdqyIp/eg0DJZGqqHZNDzOTdmi9x3LXLirSoMILJA6n AuaM1umesNX0Gg9xiuZlsXA2tMvoChXrYg4SM47ZWSuG+lu7vTJk5oymmAcYboo+oF4C aOU8UV/+K5kIC3YkpdLWnbXswotUDWb+6xLn/+rFEpkDSryDNvfxLaQSBpM2/CmjM3eS W8jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=hqY92IyaOn566ESbjSLskW0cc57GoyIQ8cfMxC4afJE=; b=X+SRcPo3CS06snHj0F+kqhq2yCDvBWmbYbntQkfHJdChDjTOSukv/9bXKEjir1WSXg LRkiiAbCvEbxPl6CNso0QtbA8oBZQcP09l0RgjdUqfIXcAYKbY6uwZUqQIydjbvJBBLS psGpa8Fk6QhODDhYFVIL5kKUJAbd9Jh18sxLhSqYMIA1D/Ob65S0qlHyFxJ/7uYkMNol ngZzLmYwvxByVtbJ3DGqHDxaMZWWSP7JGTmFW1hzryflAdduLKfVubHzMebH4OUiwf53 +W3JH9OdY5d1WOM+vE/abqchJXhVHalQ9/Q4UCS/QgSnIt2DoPwM/n9xShktL9aNzMuC vHrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UghItTln; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6-v6si567987pla.619.2018.02.27.19.57.41; Tue, 27 Feb 2018 19:57:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UghItTln; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751821AbeB1D5j (ORCPT + 10 others); Tue, 27 Feb 2018 22:57:39 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34119 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751793AbeB1D5h (ORCPT ); Tue, 27 Feb 2018 22:57:37 -0500 Received: by mail-pf0-f193.google.com with SMTP id j20so513416pfi.1 for ; Tue, 27 Feb 2018 19:57:36 -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=hqY92IyaOn566ESbjSLskW0cc57GoyIQ8cfMxC4afJE=; b=UghItTlnmrIu+FmVYwuGgCTbkf8lc1x4j6i+X0l2vHsOGkqDDr2JfFGN/EcEncC7vX 5WibJtVoQyv2gDQm1g05k6fl8tySKz0AwxTLz1jE4CR0ouHlyyKDpFlh0mrYvLvNpMwD PCoUNqE5n6nZLXL0QoCbm+an8+4NmBVasTsVU= 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=hqY92IyaOn566ESbjSLskW0cc57GoyIQ8cfMxC4afJE=; b=RQv0iDtbIlVK54dPIstPh8bMuyn+GDe6j35eMxCScFGNLIj82nyp4SerInX0YGYoJV qip4qyCyS7Vvp+XuInU+/tSY0drs3gzexzKmcaqau77LbnslRzfjMm40AZkZq0+zVvo5 O0mvTTLl0a+mwrDn+3uZjFQtTDu6QQm7NxFcovwaJ2lyX2pfw2alzRChprvksEpbZQCm M7v/ykgHcp24fAe2W9pPpy020sDEA3HiU/7Pm9F9vIefP3KGieuntU1oI54suricKdCv kBh64BPETPktT+yhJxKO8nuMwhW7Ixe7mBMoSRT0LY8YNtwiEtTnCMqXXom6bVDQrazB Pdmg== X-Gm-Message-State: APf1xPDkv37N7EAdp+utSvUapXeAqavYoghj8vMg1VseDCWOjSIIny91 8r3cg/KBuFlEicnZD38kyinD0Q== X-Received: by 10.98.35.68 with SMTP id j65mr11761651pfj.5.1519790255665; Tue, 27 Feb 2018 19:57:35 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id q17sm739911pgt.7.2018.02.27.19.57.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 19:57:34 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alex Shi Subject: [PATCH 01/29] arm64: mm: Use non-global mappings for kernel space Date: Wed, 28 Feb 2018 11:56:23 +0800 Message-Id: <1519790211-16582-2-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519790211-16582-1-git-send-email-alex.shi@linaro.org> References: <1519790211-16582-1-git-send-email-alex.shi@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Will Deacon commit e046eb0c9bf2 upstream. In preparation for unmapping the kernel whilst running in userspace, make the kernel mappings non-global so we can avoid expensive TLB invalidation on kernel exit to userspace. Reviewed-by: Mark Rutland Tested-by: Laura Abbott Tested-by: Shanker Donthineni Signed-off-by: Will Deacon Signed-off-by: Alex Shi Conflicts: skip PTE_RDONLY of PAGE_NONE in arch/arm64/include/asm/pgtable-prot.h --- arch/arm64/include/asm/kernel-pgtable.h | 12 ++++++++++-- arch/arm64/include/asm/pgtable-prot.h | 21 +++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h index 7e51d1b..e4ddac9 100644 --- a/arch/arm64/include/asm/kernel-pgtable.h +++ b/arch/arm64/include/asm/kernel-pgtable.h @@ -71,8 +71,16 @@ /* * Initial memory map attributes. */ -#define SWAPPER_PTE_FLAGS (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) -#define SWAPPER_PMD_FLAGS (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) +#define _SWAPPER_PTE_FLAGS (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) +#define _SWAPPER_PMD_FLAGS (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) + +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +#define SWAPPER_PTE_FLAGS (_SWAPPER_PTE_FLAGS | PTE_NG) +#define SWAPPER_PMD_FLAGS (_SWAPPER_PMD_FLAGS | PMD_SECT_NG) +#else +#define SWAPPER_PTE_FLAGS _SWAPPER_PTE_FLAGS +#define SWAPPER_PMD_FLAGS _SWAPPER_PMD_FLAGS +#endif #if ARM64_SWAPPER_USES_SECTION_MAPS #define SWAPPER_MM_MMUFLAGS (PMD_ATTRINDX(MT_NORMAL) | SWAPPER_PMD_FLAGS) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index 2142c77..84b5283 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -34,8 +34,16 @@ #include -#define PROT_DEFAULT (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) -#define PROT_SECT_DEFAULT (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) +#define _PROT_DEFAULT (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) +#define _PROT_SECT_DEFAULT (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) + +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +#define PROT_DEFAULT (_PROT_DEFAULT | PTE_NG) +#define PROT_SECT_DEFAULT (_PROT_SECT_DEFAULT | PMD_SECT_NG) +#else +#define PROT_DEFAULT _PROT_DEFAULT +#define PROT_SECT_DEFAULT _PROT_SECT_DEFAULT +#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ #define PROT_DEVICE_nGnRnE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRnE)) #define PROT_DEVICE_nGnRE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRE)) @@ -48,6 +56,7 @@ #define PROT_SECT_NORMAL_EXEC (PROT_SECT_DEFAULT | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL)) #define _PAGE_DEFAULT (PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL)) +#define _HYP_PAGE_DEFAULT (_PAGE_DEFAULT & ~PTE_NG) #define PAGE_KERNEL __pgprot(_PAGE_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE) #define PAGE_KERNEL_RO __pgprot(_PAGE_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_RDONLY) @@ -55,15 +64,15 @@ #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_HYP __pgprot(_PAGE_DEFAULT | PTE_HYP | PTE_HYP_XN) -#define PAGE_HYP_EXEC __pgprot(_PAGE_DEFAULT | PTE_HYP | PTE_RDONLY) -#define PAGE_HYP_RO __pgprot(_PAGE_DEFAULT | PTE_HYP | PTE_RDONLY | PTE_HYP_XN) +#define PAGE_HYP __pgprot(_HYP_PAGE_DEFAULT | PTE_HYP | PTE_HYP_XN) +#define PAGE_HYP_EXEC __pgprot(_HYP_PAGE_DEFAULT | PTE_HYP | PTE_RDONLY) +#define PAGE_HYP_RO __pgprot(_HYP_PAGE_DEFAULT | PTE_HYP | PTE_RDONLY | PTE_HYP_XN) #define PAGE_HYP_DEVICE __pgprot(PROT_DEVICE_nGnRE | PTE_HYP) #define PAGE_S2 __pgprot(PROT_DEFAULT | PTE_S2_MEMATTR(MT_S2_NORMAL) | PTE_S2_RDONLY) #define PAGE_S2_DEVICE __pgprot(PROT_DEFAULT | PTE_S2_MEMATTR(MT_S2_DEVICE_nGnRE) | PTE_S2_RDONLY | PTE_UXN) -#define PAGE_NONE __pgprot(((_PAGE_DEFAULT) & ~PTE_VALID) | PTE_PROT_NONE | PTE_PXN | PTE_UXN) +#define PAGE_NONE __pgprot(((_PAGE_DEFAULT) & ~PTE_VALID) | PTE_PROT_NONE | PTE_NG | PTE_PXN | PTE_UXN) #define PAGE_SHARED __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE) #define PAGE_SHARED_EXEC __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_NG | PTE_PXN | PTE_WRITE) #define PAGE_COPY __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_NG | PTE_PXN | PTE_UXN)