From patchwork Mon Nov 27 16:37:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 119748 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp512313qgn; Mon, 27 Nov 2017 08:39:02 -0800 (PST) X-Google-Smtp-Source: AGs4zMZYhERbByRhDH0CAEZXKF+r9OKwDrxw7X3THm5FmGGYUOHagitfaF2diT/9iHZUwUkSC/dq X-Received: by 10.98.79.86 with SMTP id d83mr37709187pfb.26.1511800741977; Mon, 27 Nov 2017 08:39:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511800741; cv=none; d=google.com; s=arc-20160816; b=e4Ot3eBGTSpE5OiwdPRB9Opsc6VTKQLWaFSmidURBMRuUK2wLUAgrI6+ylZU0+gybC fu89YmXiyuAfYH5dz+NKwuzSD23BtpnXPFt2Oel+RLdhqy1NpAAQbPMp4fzhpqcbNEGa 19tbk4ll20U00YP7+80tRb896Xw6TLjRl+FiHhOtn4KsPDw12e3VCrV/kn9eXsQR3qBH jEvST6XsipWkWSIqquP4sNyMGHpGaiiZc94Oes1S5XKrMSc6+CCVCEe/5/m7HmvZTyiL cZGRwuP15NKMCtommIWjgtjikvefOJSFZ4mq1HAuHODAIGVG1Io6e55fXzrI0z13uwLs 9Z1w== 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:arc-authentication-results; bh=Y9vM+s0N8jo7csHN2zvbtY1+njoj1QxvIsMuVADp1ik=; b=Y2iZ6lDosnDPyTIC50Dk86mL7/pLG50EZ6onhuqzrYWWGuCRdlup3YG35TZjv8MEQd C3jffO6HpqhzOj19jF2z0ZFMTdsTCMb/HSUOJGpRT+z/D6Hu51V6pMRiVWrVeVwSOba0 GiXthm/j989p9w8533kdPH9j15Lm2D/6M4Av5E/m+++TbCPwUgDE8rmAnTK+F6HIPzbs KLeiexWCJaHR+/lO+Wg5pOwkjjpBbuMMHsFr3e5eVueCCJ/ez4xZ+yZqLYfGf3BXvNm8 2MC5nRCOvmHGnpKcbLT5oCexAt6fReDu66TWnrScDZEKKnXUw/nOmp0KwIYm2lsfkzdM uLcw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z11si22737582pgp.662.2017.11.27.08.39.01; Mon, 27 Nov 2017 08:39:01 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932074AbdK0Qi7 (ORCPT + 28 others); Mon, 27 Nov 2017 11:38:59 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:40130 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753650AbdK0Qi5 (ORCPT ); Mon, 27 Nov 2017 11:38:57 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 67F7515A2; Mon, 27 Nov 2017 08:38:57 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B5BB93F246; Mon, 27 Nov 2017 08:38:54 -0800 (PST) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: arnd@arndb.de, catalin.marinas@arm.com, cdall@linaro.org, kvmarm@lists.cs.columbia.edu, linux-arch@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, suzuki.poulose@arm.com, will.deacon@arm.com, yao.qi@arm.com, kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, awallis@codeaurora.org Subject: [PATCHv2 04/12] arm64/cpufeature: detect pointer authentication Date: Mon, 27 Nov 2017 16:37:58 +0000 Message-Id: <20171127163806.31435-5-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171127163806.31435-1-mark.rutland@arm.com> References: <20171127163806.31435-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org So that we can dynamically handle the presence of pointer authentication functionality, wire up probing code in cpufeature.c. It is assumed that if all CPUs support an IMP DEF algorithm, the same algorithm is used across all CPUs. Signed-off-by: Mark Rutland Cc: Catalin Marinas Cc: Suzuki K Poulose Cc: Will Deacon --- arch/arm64/include/asm/cpucaps.h | 8 +++- arch/arm64/kernel/cpufeature.c | 82 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h index 2ff7c5e8efab..d2830ce5c1c7 100644 --- a/arch/arm64/include/asm/cpucaps.h +++ b/arch/arm64/include/asm/cpucaps.h @@ -41,7 +41,13 @@ #define ARM64_WORKAROUND_CAVIUM_30115 20 #define ARM64_HAS_DCPOP 21 #define ARM64_SVE 22 +#define ARM64_HAS_ADDRESS_AUTH_ARCH 23 +#define ARM64_HAS_ADDRESS_AUTH_IMP_DEF 24 +#define ARM64_HAS_ADDRESS_AUTH 25 +#define ARM64_HAS_GENERIC_AUTH_ARCH 26 +#define ARM64_HAS_GENERIC_AUTH_IMP_DEF 27 +#define ARM64_HAS_GENERIC_AUTH 28 -#define ARM64_NCAPS 23 +#define ARM64_NCAPS 29 #endif /* __ASM_CPUCAPS_H */ diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 1883cdffcdf7..babd4c173092 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -853,6 +853,36 @@ static bool has_no_fpsimd(const struct arm64_cpu_capabilities *entry, int __unus ID_AA64PFR0_FP_SHIFT) < 0; } +#ifdef CONFIG_ARM64_POINTER_AUTHENTICATION +static bool has_address_auth(const struct arm64_cpu_capabilities *entry, + int __unused) +{ + u64 isar1 = read_sanitised_ftr_reg(SYS_ID_AA64ISAR1_EL1); + bool api, apa; + + apa = cpuid_feature_extract_unsigned_field(isar1, + ID_AA64ISAR1_APA_SHIFT) > 0; + api = cpuid_feature_extract_unsigned_field(isar1, + ID_AA64ISAR1_API_SHIFT) > 0; + + return apa || api; +} + +static bool has_generic_auth(const struct arm64_cpu_capabilities *entry, + int __unused) +{ + u64 isar1 = read_sanitised_ftr_reg(SYS_ID_AA64ISAR1_EL1); + bool gpi, gpa; + + gpa = cpuid_feature_extract_unsigned_field(isar1, + ID_AA64ISAR1_GPA_SHIFT) > 0; + gpi = cpuid_feature_extract_unsigned_field(isar1, + ID_AA64ISAR1_GPI_SHIFT) > 0; + + return gpa || gpi; +} +#endif /* CONFIG_ARM64_POINTER_AUTHENTICATION */ + static const struct arm64_cpu_capabilities arm64_features[] = { { .desc = "GIC system register CPU interface", @@ -970,6 +1000,58 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .enable = sve_kernel_enable, }, #endif /* CONFIG_ARM64_SVE */ +#ifdef CONFIG_ARM64_POINTER_AUTHENTICATION + { + .desc = "Address authentication (architected algorithm)", + .capability = ARM64_HAS_ADDRESS_AUTH_ARCH, + .def_scope = SCOPE_SYSTEM, + .sys_reg = SYS_ID_AA64ISAR1_EL1, + .sign = FTR_UNSIGNED, + .field_pos = ID_AA64ISAR1_APA_SHIFT, + .min_field_value = ID_AA64ISAR1_APA_ARCHITECTED, + .matches = has_cpuid_feature, + }, + { + .desc = "Address authentication (IMP DEF algorithm)", + .capability = ARM64_HAS_ADDRESS_AUTH_IMP_DEF, + .def_scope = SCOPE_SYSTEM, + .sys_reg = SYS_ID_AA64ISAR1_EL1, + .sign = FTR_UNSIGNED, + .field_pos = ID_AA64ISAR1_API_SHIFT, + .min_field_value = ID_AA64ISAR1_API_IMP_DEF, + .matches = has_cpuid_feature, + }, + { + .capability = ARM64_HAS_ADDRESS_AUTH, + .def_scope = SCOPE_SYSTEM, + .matches = has_address_auth, + }, + { + .desc = "Generic authentication (architected algorithm)", + .capability = ARM64_HAS_GENERIC_AUTH_ARCH, + .def_scope = SCOPE_SYSTEM, + .sys_reg = SYS_ID_AA64ISAR1_EL1, + .sign = FTR_UNSIGNED, + .field_pos = ID_AA64ISAR1_GPA_SHIFT, + .min_field_value = ID_AA64ISAR1_GPA_ARCHITECTED, + .matches = has_cpuid_feature + }, + { + .desc = "Generic authentication (IMP DEF algorithm)", + .capability = ARM64_HAS_GENERIC_AUTH_IMP_DEF, + .def_scope = SCOPE_SYSTEM, + .sys_reg = SYS_ID_AA64ISAR1_EL1, + .sign = FTR_UNSIGNED, + .field_pos = ID_AA64ISAR1_GPI_SHIFT, + .min_field_value = ID_AA64ISAR1_GPI_IMP_DEF, + .matches = has_cpuid_feature + }, + { + .capability = ARM64_HAS_GENERIC_AUTH, + .def_scope = SCOPE_SYSTEM, + .matches = has_generic_auth, + }, +#endif /* CONFIG_ARM64_POINTER_AUTHENTICATION */ {}, };