From patchwork Wed Feb 28 03:56:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10246775 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 7BCBF60211 for ; Wed, 28 Feb 2018 04:17:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CFE928A05 for ; Wed, 28 Feb 2018 04:17:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 617F628A0E; Wed, 28 Feb 2018 04:17:50 +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=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 E221328A05 for ; Wed, 28 Feb 2018 04:17:49 +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=3G5TjyUmcX5Ffd477wgE7ZTYkBM12K2BsOd2N1IlYk8=; b=d6L9ZaYLJSG+lrlW2UUB+vAo2+ o9uD7BcL6khNcAPRDxNuBjskRVl77/VjK6DNtujvBOq0t0OKeNWUintdv3jw7ZACI6YpEBdh0dC/E C0y0Pw5mz+Kup4M25ZaFYAJUtqEfesfqjy639KTZDqT6zDXuKBhfD9EimdQUkTJNpr1GHM09oSWYH VvZ3WV4KKB8etK6zyoG/UXr44SIbAlPTaEL+NGmivHXmSDUdwA0I82OvzpE00TiOT+OAsTQGcRaK6 PXD3a2y5TrGcLJZhCy8lT36jYJ8QTbZcaOdqqdQlkKZ0nSXsQU96yOsK7RgAWd8rUks+1nIvKHg5V qaeYP7mw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqtBS-0005Cg-Jx; Wed, 28 Feb 2018 04:17:38 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqt9T-0002b7-6V for linux-arm-kernel@bombadil.infradead.org; Wed, 28 Feb 2018 04:15:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Y7Yb5ubO8PqpEAZQ4vm3NWKhm2ulQzVizy5/nfrU5Tc=; b=D2dzKDVoQFlN75TEJvCKnpC3f DquQFDFPoSlefRbf2hNNcW4OSe306q64KnCtCbALRyyfjRrFxKIxD2IiGJ/QeCHPjpR/aGmHF/QNY dXtrQw0atTmuoNcYeup9YCkv6BmTfG/WSTm3TXX6aa2QVq6bubLF+UOMd3b+C1Zv6HQVZMnAqb3t7 sRwBlKl5tVpqKezBPdVEa+CTqJMoP2VGEBWNPhA0tokJsTLsFxkAENLNG0gwc4u7gP63r5INtDukB mEIoLYRvMwu44igV4nVbnMWVesPfT8ZfA68WBz3HlAntR3e/k3/KDRLA/xoDms9hx57LmglBxec6V Xqg1j10oA==; Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqsuS-0002P2-21 for linux-arm-kernel@lists.infradead.org; Wed, 28 Feb 2018 04:00:09 +0000 Received: by mail-pl0-x244.google.com with SMTP id y8-v6so761058pll.13 for ; Tue, 27 Feb 2018 19:59:53 -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=Y7Yb5ubO8PqpEAZQ4vm3NWKhm2ulQzVizy5/nfrU5Tc=; b=kQsGIn/PXxWANlzu2KuirJ298WQt6Lq2i490awihM/Q16+AXttHAsoFBG5ITJiWqJO 3DPwWPwtLJAmGW8vuww/+ESywolI1YJTkmQZxSqmwGEi6wvAfTaj3VwWvToKmWIPcYHE 3Szp6g8mcqAZWMgYemBRaxlm0CoFxPBoYnRkY= 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=Y7Yb5ubO8PqpEAZQ4vm3NWKhm2ulQzVizy5/nfrU5Tc=; b=GT5Zl1slL5LIi7wJsaRJFUsLdHJ5SpCSRA7YjsUjdsWVpB78zUPdpiY09jv3LBWSQS zLRvtb/VqhoYulnuCGSE/8/EXTCCaq+suYfJYvHEsrsDVLpd1AXOklKbcUaa5eD5ie29 YLix9RFoFG6+KfDmtkWk03djWUt/lUzJ2cyAjI5IEssy/+ObQ8szdqc5EJ/hCvUyu8M4 oQNsdYwwHhYAhZX8dB2dkoA3RqnAIHyJZjaYscV+IUGghWnB+dOLyHxRxmK2bWK2tlXC O40Fq+wJb1L7skLmHlr1iK5/e4gvO6/9L0eCtcz8k/AcrnhwHWLBbUc0UEqCnPGkjHlJ Lz9g== X-Gm-Message-State: APf1xPD5mdyaVV/wy7C42TzKuiEtXZoiXeKG4xQWtm33IjiLBdBMWtzE ZIBBsedvb+qe2S+LuFQhUJ6hwQ== X-Google-Smtp-Source: AG47ELsZ1xGyJgrii3u04/5DfAt+X2LqSV7t0Tbjmx55cpCI4Ib2+NLngcLT1ptsmJoyb9DqBIdTdA== X-Received: by 2002:a17:902:678e:: with SMTP id g14-v6mr127770plk.440.1519790392423; Tue, 27 Feb 2018 19:59:52 -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.59.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 19:59:51 -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 Subject: [PATCH 19/29] arm64: Take into account ID_AA64PFR0_EL1.CSV3 Date: Wed, 28 Feb 2018 11:56:41 +0800 Message-Id: <1519790211-16582-20-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180228_040004_109255_7891CB52 X-CRM114-Status: GOOD ( 17.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: Alex Shi 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 From: Will Deacon commit 179a56f6f9fb upstream. For non-KASLR kernels where the KPTI behaviour has not been overridden on the command line we can use ID_AA64PFR0_EL1.CSV3 to determine whether or not we should unmap the kernel whilst running at EL0. Reviewed-by: Suzuki K Poulose Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Alex Shi Conflicts: skip cpu features like SVE etc. and use 5 paramaters function ARM64_FTR_BITS() replace read_sanitised_ftr_reg with old name read_system_reg arch/arm64/include/asm/sysreg.h arch/arm64/kernel/cpufeature.c --- arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kernel/cpufeature.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index 7393cc7..7cb7f7c 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -117,6 +117,7 @@ #define ID_AA64ISAR0_AES_SHIFT 4 /* id_aa64pfr0 */ +#define ID_AA64PFR0_CSV3_SHIFT 60 #define ID_AA64PFR0_GIC_SHIFT 24 #define ID_AA64PFR0_ASIMD_SHIFT 20 #define ID_AA64PFR0_FP_SHIFT 16 diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 74b168c..3ec6517 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -98,6 +98,7 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64PFR0_GIC_SHIFT, 4, 0), S_ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_ASIMD_SHIFT, 4, ID_AA64PFR0_ASIMD_NI), S_ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_FP_SHIFT, 4, ID_AA64PFR0_FP_NI), + ARM64_FTR_BITS(FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR0_CSV3_SHIFT, 4, 0), /* Linux doesn't care about the EL3 */ ARM64_FTR_BITS(FTR_NONSTRICT, FTR_EXACT, ID_AA64PFR0_EL3_SHIFT, 4, 0), ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64PFR0_EL2_SHIFT, 4, 0), @@ -752,6 +753,8 @@ static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, int __unused) { + u64 pfr0 = read_system_reg(SYS_ID_AA64PFR0_EL1); + /* Forced on command line? */ if (__kpti_forced) { pr_info_once("kernel page table isolation forced %s by command line option\n", @@ -763,7 +766,9 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) return true; - return false; + /* Defer to CPU feature registers */ + return !cpuid_feature_extract_unsigned_field(pfr0, + ID_AA64PFR0_CSV3_SHIFT); } static int __init parse_kpti(char *str) @@ -865,6 +870,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = { }, #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 { + .desc = "Kernel page table isolation (KPTI)", .capability = ARM64_UNMAP_KERNEL_AT_EL0, .def_scope = SCOPE_SYSTEM, .matches = unmap_kernel_at_el0,