From patchwork Wed Feb 28 03:56:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 129909 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp569425lja; Tue, 27 Feb 2018 20:00:38 -0800 (PST) X-Google-Smtp-Source: AH8x225wUYNCRb7Yr/HRH3nFyyS96s3tcxQdMUpxaKYLHiJ+rvsfD6qGhj5cvNmmksntxsBQhF0+ X-Received: by 2002:a17:902:b28a:: with SMTP id u10-v6mr16250569plr.292.1519790438416; Tue, 27 Feb 2018 20:00:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519790438; cv=none; d=google.com; s=arc-20160816; b=y4648Xaf3ESDjuGDukM8csWln0YRJMbKGJGSA8FNkzT6t1VD6fPIqapggWKyOJXttQ 9OzBqQ6z9rzmDjjj4xyrwX3mcHr8Y0hdmEmBQ3iy1FWDr9TVGz6yW8Ey5qmF7uWzNRfL OvcD774dtNBvW6QCDlSWrNxXyJUQftcC++puFt2XOkcQwF91gjPI1m/nLFibMTJWYDAr 2x0i2TrZ8eZ9QdKxGJElzja2o9stPdE3B4rZcgzIOslpNO5dghQfMLdZ5boSLD9NQd0f 6ztySEdc+j0tXbn5IbO5WI+hpqFdChnkVrIJntqDERJWPWH3lsLn1dFqWCVK2kc0pTI8 ioNA== 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=mYI9hVlX+A1UhBZZtOVFtY/jGzDIohyGCUWHl33Z7RM=; b=e0ZQ0PhY/FxOADwTcyIb64ruKZG+UCxIAxsz8lBfxeDCSzGDjTWurydT4rUFyDWGFU sdn3F2nbWJSlYKTwfzzVYzVwaYnlkRqk1VZp53F0mOOcp6aTdRC3Epk1ZcC8oThX66II iYFQmicYFMU/OcSGBeLZtKqJLonJTQcjvA459/dnu4EAcrsoc5sWzUhcBz2/fFknfbzI UGLGZzO7Dt8jGelYF9XRh5RgX58t33zMiO5wE+Hc839EfbeUjIoJbOCuZH8RhwPGI0tK z49iWWvQZgeDaEenVxdzodjiz0V+7KzF3Kv0oeajCMQhUTI13f/qtBEFAwnVhcOSsX/k MkEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A6UnT8xk; 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 g17-v6si571790plo.357.2018.02.27.20.00.38; Tue, 27 Feb 2018 20:00:38 -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=A6UnT8xk; 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 S1752368AbeB1EAf (ORCPT + 10 others); Tue, 27 Feb 2018 23:00:35 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:35208 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752339AbeB1EAc (ORCPT ); Tue, 27 Feb 2018 23:00:32 -0500 Received: by mail-pl0-f67.google.com with SMTP id bb3-v6so779837plb.2 for ; Tue, 27 Feb 2018 20:00:32 -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=mYI9hVlX+A1UhBZZtOVFtY/jGzDIohyGCUWHl33Z7RM=; b=A6UnT8xkC++L73mAAWRsuF0rN9V4e2vc6BAUuHpJHmWyRJy/DHTUDkXwGL14bh7mjK ViNx1I/sgQTTHh6U2ZMY/i/iYzuvpIVCtcieqaVjq+OO8nu77YbUPQYfLsun+/Jx1LoV bFaYY21cUFSwZsF1pPHRUaLXAV9YbKAR69dqI= 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=mYI9hVlX+A1UhBZZtOVFtY/jGzDIohyGCUWHl33Z7RM=; b=BnPEUhqx9MLFzWku8x4gVspb+lNJvIdO9C4DWtwIi6sgDKMF/yTQ0iaCWOcYWJ0yb8 PjDuR9v0+drPJmcEiR+VsWwCCb667EBCCa4hHEZ3TSYGSWCn+1iCF0x4DGYYi1p9HLny Jk6xu1L8yxY49JfYchph5tXE9Q2TaDnGtTkEXirRQOyOEZPbXZRWqXlAPI7mKvtQlwb4 2r0RKCL0h2RjDk/Zs+c8t3HL62iTUc/kQzzAT2QITSBGafSVGo/MsRkFIkmv2IEDPoq0 JfctCKmgdJryiqu3M6X9JVND6G+EKuRV7I93uUpus2eNupjQRUHJ0fCe1oEvIEI1Bh6+ o7Ag== X-Gm-Message-State: APf1xPAbEJs5dfj8Js3x/6PQfLHq6EIBy5KtNUzvuzrpC7bHpz3hc4Xe OQ7mzUjv8nETwAgwOT4+TmC9bLBctHY= X-Received: by 2002:a17:902:10d:: with SMTP id 13-v6mr16322078plb.266.1519790432043; Tue, 27 Feb 2018 20:00:32 -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.20.00.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 20:00:31 -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 25/29] arm64: kpti: Make use of nG dependent on arm64_kernel_unmapped_at_el0() Date: Wed, 28 Feb 2018 11:56:47 +0800 Message-Id: <1519790211-16582-26-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 41acec624087 upstream. To allow systems which do not require kpti to continue running with global kernel mappings (which appears to be a requirement for Cavium ThunderX due to a CPU erratum), make the use of nG in the kernel page tables dependent on arm64_kernel_unmapped_at_el0(), which is resolved at runtime. Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Alex Shi --- arch/arm64/include/asm/kernel-pgtable.h | 12 ++---------- arch/arm64/include/asm/pgtable-prot.h | 30 ++++++++++++++---------------- 2 files changed, 16 insertions(+), 26 deletions(-) -- 2.7.4 diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h index 135e829..be151cc 100644 --- a/arch/arm64/include/asm/kernel-pgtable.h +++ b/arch/arm64/include/asm/kernel-pgtable.h @@ -73,16 +73,8 @@ /* * 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) - -#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 +#define SWAPPER_PTE_FLAGS (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) +#define SWAPPER_PMD_FLAGS (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) #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 84b5283..f705d96 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -37,13 +37,11 @@ #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 PTE_MAYBE_NG (arm64_kernel_unmapped_at_el0() ? PTE_NG : 0) +#define PMD_MAYBE_NG (arm64_kernel_unmapped_at_el0() ? PMD_SECT_NG : 0) + +#define PROT_DEFAULT (_PROT_DEFAULT | PTE_MAYBE_NG) +#define PROT_SECT_DEFAULT (_PROT_SECT_DEFAULT | PMD_MAYBE_NG) #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)) @@ -55,22 +53,22 @@ #define PROT_SECT_NORMAL (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL)) #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_DEFAULT (_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL)) +#define _HYP_PAGE_DEFAULT _PAGE_DEFAULT -#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) -#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 __pgprot(PROT_NORMAL) +#define PAGE_KERNEL_RO __pgprot((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY) +#define PAGE_KERNEL_ROX __pgprot((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN)) | PTE_RDONLY) +#define PAGE_KERNEL_EXEC __pgprot(PROT_NORMAL & ~PTE_PXN) +#define PAGE_KERNEL_EXEC_CONT __pgprot((PROT_NORMAL & ~PTE_PXN) | PTE_CONT) #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_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_NG | PTE_PXN | PTE_UXN) #define PAGE_SHARED __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE)