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: 129903 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp568739lja; Tue, 27 Feb 2018 19:59:59 -0800 (PST) X-Google-Smtp-Source: AH8x227s1cx+Q0x6/IIur6ud55s8GxxhTsKTV09g3VjZUvrZPI8kikf7hEBVdLVKSX3JRWI/d3kW X-Received: by 10.101.76.13 with SMTP id u13mr12788888pgq.287.1519790399003; Tue, 27 Feb 2018 19:59:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519790398; cv=none; d=google.com; s=arc-20160816; b=fXNcdHIE0V1Xd9nl3aB/HNujlZy708ZDKoEXiWmfNCOjmqNvm/BTzwKDNnFWOQf/ke +/zzuQPXomKE9T00KZudZz6yfHs7dFIOeo5AFBiU4e4vsoNL+s+W1wAOc52sFRAD9oUr TzFjMV3jBHA+fAASm05eiwSl6zF3L/esl3ZqzikiooxSctcEyzd7/ZLtEcFhyjWQLFrd oxsBs//JdJzWu2z251L1UrUUgDyzCBIHywxrHi5AU1893Zm1xcTfu/boj6Us0aAQpNqE 5ANHYx7Z7TUPz74Hv4oNrHFid9eGRcjC5bswl+muArOVTJz+Ucl+1hh0KTsI8RpeJJ/W 1S2A== 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=Y7Yb5ubO8PqpEAZQ4vm3NWKhm2ulQzVizy5/nfrU5Tc=; b=ln1UbKMiL38Gr6PMU5z2AGAiUCsbTMcJb8dIzgmXGSIpZKJblx/hB7gu2yqJ31oL6r VA8tx2/c9Adf4zH/AZx6MyhC2zid83nt53OoHFqhsk1oZZ3SCTcEE6B3coEJl/xNC9Xm ufZC/n/joTs0F1+TbNCzfnV5LBZ1cfdwfmNVN9dXC1YPXJNNLxpI2Df6WPVUj4Bnca3y tqKPCnlr0sg0hqyFRzs49Mrov1kg7YPWOs9PxEkkqrU1EbjQ+H4sxtZ3tV48i2KX+hha gd/52PGggybMkNMXkdAdt5Pdwo+fEd71FGWy16RYt9WOLUU0IPbWQZWV+GS4SjzZDM+4 VOYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kQsGIn/P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 a34-v6si597978pld.27.2018.02.27.19.59.58; Tue, 27 Feb 2018 19:59:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=kQsGIn/P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S932226AbeB1D74 (ORCPT + 28 others); Tue, 27 Feb 2018 22:59:56 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:34125 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932197AbeB1D7w (ORCPT ); Tue, 27 Feb 2018 22:59:52 -0500 Received: by mail-pl0-f67.google.com with SMTP id u13-v6so780974plq.1 for ; Tue, 27 Feb 2018 19:59:52 -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=JJiQPSteVfGi8e96xlaRRvVBDDrGtLpdpedaZe5X26V/tJP744j65plK/FTVKSAjCt FV8R0nEN3RkfWAv5C0KTmyB3vG5eZZV+iGlClq6ng0IG8TJLPlzCRyp3FDRQcB6ucS+1 VI+cGzRn/ESdUGaaAeqXQdKmO4uJaTKLToWPDESrofXo8BYxciW46QfQclQ0WYBi+eXS 8YjEnpeG031QUUGcCFnS+dmT5FGse2CKVKDIYiVsoAMmqYhuVsJxNE5nI1zeuTMWDv14 X9inSRo2ZvJwrMZYKQPqeKZj7jRtWgchAeguERkjHTj3HnKNq47hiUP9/oex4FqnOfe9 Sbdw== X-Gm-Message-State: APf1xPD7ndhUBZwogqVosoENp8FWHGGqZimO5NoMvStCQaIekXmlX04c HyU5/TTimDHFJd9XW5llsxE1HQ== 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 Cc: Alex Shi 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.7.4 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,