From patchwork Fri Oct 4 12:04:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174337 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED0A916B1 for ; Fri, 4 Oct 2019 12:08:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BB7B22070B for ; Fri, 4 Oct 2019 12:08:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ob517t74"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="AS1lQW85" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB7B22070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=4irwi5Y6N/HFcxwtcH3tLgze9kdOYJ4sl1Z1DzlnmPU=; b=ob517t745j1zGU fXUG8IwThtXa40AQsV5BaMoZUBjz0U3Y/UzQvGW8qDK3kf8YzGyiu1Mq5aZwQq54d4lyK0ECeEU2l KZ68n2HBLJRULVUp3ZzRgVvHPZSJGdvXm1aij1BGIpdloWNycRDUou5WRL+VzsnIdDSuRfrvh+n0i oKMGG07P1P9QBqUvbaapJh7LDMkbdimesjK9Zj7FpYBCWnOeoCyAdujy6VVQBYq1sIFaGz3JWdtix /AQLAh1lAtnOmDIiDF5/zVnDupR005OW9rihZ+Vo5SIlSA8i+UFtP31w2XVa61Oct8XQH75Xm3/zz Z70FCqKuOfAFjA06j9sg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMO5-0006ZI-PX; Fri, 04 Oct 2019 12:08:45 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMK7-0001iK-Vz for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:41 +0000 Received: by mail-wm1-x343.google.com with SMTP id r19so5555638wmh.2 for ; Fri, 04 Oct 2019 05:04:39 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=Hm2VGN+4jk338hFYugKYyPTMrQCM4dvgKpTWHVIaO1U=; b=AS1lQW85UmdThSw2617hQWjERpQVepj7SGquCKSs4H9dxJCLhmKh63fT1iiaTvNGFT qAGU0Oqxefo6HPlUXbTRzRb7y2AZyXuz7y2l+97onQWTcdkm6wdGhKfRmHHyeSchT/+0 6CFD4lZR8D1S0U8ebo/tPlA6+kSiSTQGYaqlHmEeHg/A9QY9Gu50lwoUsqwuvDMIZe+9 9vuXOWfa8IQt0dVj7fq8Fe1/dd0YJSDJFhbph0BadmO8Jpn9S9o8Q4MieKWCO8vAwceb B720jEcOfI1I342lDfOUu55gPEm7s3zrhzPRSFO7E5ebx+asNLGiDZE2s770PFxNrYu+ 03mQ== 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:mime-version:content-transfer-encoding; bh=Hm2VGN+4jk338hFYugKYyPTMrQCM4dvgKpTWHVIaO1U=; b=sET5IbSAHH+3z5u+oKLREjE4BjsSPZvHV5jeh8fgBGWOsYHdsd/X93qe5kAtbU8o0b 7UDOAz1wlbMVDfqL9/L4yz9WpgZIZLoERr6w4gTQTFBnHPuHSxXppABPkLQPPBZs7ZeT EsyCsAs8l6ntz8lL5z4S+z4iy7O1292auWYSuxeU0wsE/08reXl42ra26U4P0ijB8Ckl fm3Zzzmmvc1Q/SOu/z3KKejj4q3nssojN0oWvoAv4DlIb1wKLK6SIYrPzMRZoNl3khne N+oaXHK4aYmKsFvW+7K4CpNJU07co9t9ZW2YOFlaQ7ljFVHIusCpmhXsZ4fQiJO6jJmr ujDg== X-Gm-Message-State: APjAAAW2JzQMpJ8T+RCQwwPhxJ2sTyq7wyHchNiKJMmPn4ECvvYteuLQ 2nSuY4uiSl7WqHapRJdm1dP9ELPg8S06uwfr X-Google-Smtp-Source: APXvYqy4akeTS/fnQeAGbgTt9QF3zDAFtslyYuKAH9F55Sy/FA2VCJKgEkSWhTn8IYslyPxDjUFMQg== X-Received: by 2002:a1c:2397:: with SMTP id j145mr10160185wmj.69.1570190677608; Fri, 04 Oct 2019 05:04:37 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:36 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 01/16] arm64: cpufeature: Detect SSBS and advertise to userspace Date: Fri, 4 Oct 2019 14:04:15 +0200 Message-Id: <20191004120430.11929-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050440_244857_060D754F X-CRM114-Status: GOOD ( 15.95 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:343 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Will Deacon , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Will Deacon Armv8.5 introduces a new PSTATE bit known as Speculative Store Bypass Safe (SSBS) which can be used as a mitigation against Spectre variant 4. Additionally, a CPU may provide instructions to manipulate PSTATE.SSBS directly, so that userspace can toggle the SSBS control without trapping to the kernel. This patch probes for the existence of SSBS and advertise the new instructions to userspace if they exist. Reviewed-by: Suzuki K Poulose Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas (cherry picked from commit d71be2b6c0e19180b5f80a6d42039cc074a693a2) Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/include/asm/sysreg.h | 16 ++++++++++++---- arch/arm64/include/uapi/asm/hwcap.h | 1 + arch/arm64/kernel/cpufeature.c | 19 +++++++++++++++++-- arch/arm64/kernel/cpuinfo.c | 1 + 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h index 25ce9056cf64..c3de0bbf0e9a 100644 --- a/arch/arm64/include/asm/cpucaps.h +++ b/arch/arm64/include/asm/cpucaps.h @@ -52,7 +52,8 @@ #define ARM64_MISMATCHED_CACHE_TYPE 31 #define ARM64_HAS_STAGE2_FWB 32 #define ARM64_WORKAROUND_1463225 33 +#define ARM64_SSBS 34 -#define ARM64_NCAPS 34 +#define ARM64_NCAPS 35 #endif /* __ASM_CPUCAPS_H */ diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index c1470931b897..2fc6242baf11 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -419,6 +419,7 @@ #define SYS_ICH_LR15_EL2 __SYS__LR8_EL2(7) /* Common SCTLR_ELx flags. */ +#define SCTLR_ELx_DSSBS (1UL << 44) #define SCTLR_ELx_EE (1 << 25) #define SCTLR_ELx_IESB (1 << 21) #define SCTLR_ELx_WXN (1 << 19) @@ -439,7 +440,7 @@ (1 << 10) | (1 << 13) | (1 << 14) | (1 << 15) | \ (1 << 17) | (1 << 20) | (1 << 24) | (1 << 26) | \ (1 << 27) | (1 << 30) | (1 << 31) | \ - (0xffffffffUL << 32)) + (0xffffefffUL << 32)) #ifdef CONFIG_CPU_BIG_ENDIAN #define ENDIAN_SET_EL2 SCTLR_ELx_EE @@ -453,7 +454,7 @@ #define SCTLR_EL2_SET (SCTLR_ELx_IESB | ENDIAN_SET_EL2 | SCTLR_EL2_RES1) #define SCTLR_EL2_CLEAR (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \ SCTLR_ELx_SA | SCTLR_ELx_I | SCTLR_ELx_WXN | \ - ENDIAN_CLEAR_EL2 | SCTLR_EL2_RES0) + SCTLR_ELx_DSSBS | ENDIAN_CLEAR_EL2 | SCTLR_EL2_RES0) #if (SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != 0xffffffffffffffff #error "Inconsistent SCTLR_EL2 set/clear bits" @@ -477,7 +478,7 @@ (1 << 29)) #define SCTLR_EL1_RES0 ((1 << 6) | (1 << 10) | (1 << 13) | (1 << 17) | \ (1 << 27) | (1 << 30) | (1 << 31) | \ - (0xffffffffUL << 32)) + (0xffffefffUL << 32)) #ifdef CONFIG_CPU_BIG_ENDIAN #define ENDIAN_SET_EL1 (SCTLR_EL1_E0E | SCTLR_ELx_EE) @@ -494,7 +495,7 @@ ENDIAN_SET_EL1 | SCTLR_EL1_UCI | SCTLR_EL1_RES1) #define SCTLR_EL1_CLEAR (SCTLR_ELx_A | SCTLR_EL1_CP15BEN | SCTLR_EL1_ITD |\ SCTLR_EL1_UMA | SCTLR_ELx_WXN | ENDIAN_CLEAR_EL1 |\ - SCTLR_EL1_RES0) + SCTLR_ELx_DSSBS | SCTLR_EL1_RES0) #if (SCTLR_EL1_SET ^ SCTLR_EL1_CLEAR) != 0xffffffffffffffff #error "Inconsistent SCTLR_EL1 set/clear bits" @@ -544,6 +545,13 @@ #define ID_AA64PFR0_EL0_64BIT_ONLY 0x1 #define ID_AA64PFR0_EL0_32BIT_64BIT 0x2 +/* id_aa64pfr1 */ +#define ID_AA64PFR1_SSBS_SHIFT 4 + +#define ID_AA64PFR1_SSBS_PSTATE_NI 0 +#define ID_AA64PFR1_SSBS_PSTATE_ONLY 1 +#define ID_AA64PFR1_SSBS_PSTATE_INSNS 2 + /* id_aa64mmfr0 */ #define ID_AA64MMFR0_TGRAN4_SHIFT 28 #define ID_AA64MMFR0_TGRAN64_SHIFT 24 diff --git a/arch/arm64/include/uapi/asm/hwcap.h b/arch/arm64/include/uapi/asm/hwcap.h index 17c65c8f33cb..2bcd6e4f3474 100644 --- a/arch/arm64/include/uapi/asm/hwcap.h +++ b/arch/arm64/include/uapi/asm/hwcap.h @@ -48,5 +48,6 @@ #define HWCAP_USCAT (1 << 25) #define HWCAP_ILRCPC (1 << 26) #define HWCAP_FLAGM (1 << 27) +#define HWCAP_SSBS (1 << 28) #endif /* _UAPI__ASM_HWCAP_H */ diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 859d63cc99a3..58146d636a83 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -164,6 +164,11 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { ARM64_FTR_END, }; +static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = { + ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_SSBS_SHIFT, 4, ID_AA64PFR1_SSBS_PSTATE_NI), + ARM64_FTR_END, +}; + static const struct arm64_ftr_bits ftr_id_aa64mmfr0[] = { /* * We already refuse to boot CPUs that don't support our configured @@ -379,7 +384,7 @@ static const struct __ftr_reg_entry { /* Op1 = 0, CRn = 0, CRm = 4 */ ARM64_FTR_REG(SYS_ID_AA64PFR0_EL1, ftr_id_aa64pfr0), - ARM64_FTR_REG(SYS_ID_AA64PFR1_EL1, ftr_raz), + ARM64_FTR_REG(SYS_ID_AA64PFR1_EL1, ftr_id_aa64pfr1), ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1, ftr_raz), /* Op1 = 0, CRn = 0, CRm = 5 */ @@ -669,7 +674,6 @@ void update_cpu_features(int cpu, /* * EL3 is not our concern. - * ID_AA64PFR1 is currently RES0. */ taint |= check_update_ftr_reg(SYS_ID_AA64PFR0_EL1, cpu, info->reg_id_aa64pfr0, boot->reg_id_aa64pfr0); @@ -1254,6 +1258,16 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .cpu_enable = cpu_enable_hw_dbm, }, #endif + { + .desc = "Speculative Store Bypassing Safe (SSBS)", + .capability = ARM64_SSBS, + .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE, + .matches = has_cpuid_feature, + .sys_reg = SYS_ID_AA64PFR1_EL1, + .field_pos = ID_AA64PFR1_SSBS_SHIFT, + .sign = FTR_UNSIGNED, + .min_field_value = ID_AA64PFR1_SSBS_PSTATE_ONLY, + }, {}, }; @@ -1299,6 +1313,7 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = { #ifdef CONFIG_ARM64_SVE HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_SVE_SHIFT, FTR_UNSIGNED, ID_AA64PFR0_SVE, CAP_HWCAP, HWCAP_SVE), #endif + HWCAP_CAP(SYS_ID_AA64PFR1_EL1, ID_AA64PFR1_SSBS_SHIFT, FTR_UNSIGNED, ID_AA64PFR1_SSBS_PSTATE_INSNS, CAP_HWCAP, HWCAP_SSBS), {}, }; diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c index e9ab7b3ed317..dce971f2c167 100644 --- a/arch/arm64/kernel/cpuinfo.c +++ b/arch/arm64/kernel/cpuinfo.c @@ -81,6 +81,7 @@ static const char *const hwcap_str[] = { "uscat", "ilrcpc", "flagm", + "ssbs", NULL }; From patchwork Fri Oct 4 12:04:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174345 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B81CF13BD for ; Fri, 4 Oct 2019 12:09:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 88DA82070B for ; Fri, 4 Oct 2019 12:09:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NDzl/psM"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="U9OhNYvh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88DA82070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=4knHNLq0sPSLgCKCw+68Z1FTf/bUI3vB1O1kj8Rk8k8=; b=NDzl/psME6oPlF U0tdMXE2hEPy8CIfCs8yl91HAPeG97Bnb3+Zd6UK5fIAu8cAnIMcdzNcKzAvm3ysg/7JwEH1d/ree glnbTddsgykT4VckQQNs01oi8ZQebYFC0mzdWI3/dZMjbPT7wi53m/W+T0gBXu107zD/4uuxOFrsx 2b8q1oqPEFnPuuBO+JG/l3W0RBWgPjJmIP42TwpbPax83jyDA7DHmnrYztjvpp2D2/n7wsNPqg4B9 7/ghWLqsSXTDU/PZPpCd5lgIpcBtZoUUyp5L5Hr91dbmIE8ibarUoSGAE5dhOOsZZoXierdIr/kCK /ruk5X3XIKmR5+TAOVXg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMOL-0006nb-GU; Fri, 04 Oct 2019 12:09:01 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKA-0001k1-9t for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:44 +0000 Received: by mail-wm1-x342.google.com with SMTP id b24so5563100wmj.5 for ; Fri, 04 Oct 2019 05:04:40 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=JJdRfhRUTAqVHFD/UGGB0HHQQfyfvSfAZbMZXQD/Afo=; b=U9OhNYvhiwDoOXRBDfOOBRcc+jk+OQyhyhgbk91pIui0YBT+IZV+BFmcFnSXCZnsNY JSFeMZj8LA1ZZDMj68vJR1ZoMDI8fCFoDwgkwtvi3393p+KFQc/RvkZAR700NUDvo08x jqGoJOZH4jSVsS25bTU9te2kgsDuWGQ7wZB8SqL1CyI5jifXN0vsNTON3VlXA9D/v4x6 sf24MLzDAloZk8vZT1gfU3zNtkFLy2iOJsfr7Eii2zwn6O0bEGS4NYyAwNrDsvHHJewp EiI7BSfFK3Rpf13oHawxsIKw7SH0mI+9kSp2EBqcUxyovfDPuXIVIpP8wn6JJHzmK7wo 51eg== 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:mime-version:content-transfer-encoding; bh=JJdRfhRUTAqVHFD/UGGB0HHQQfyfvSfAZbMZXQD/Afo=; b=Btz6WkCBTaMFuLq24AB3KHC+giKEb1oOatiY+kavnXPOf+OZq8gi4ZHXYylxhrOO+i bDC5WrFmNIz0TjBzDBi4eoYmA9bcE5P74FlI4ku8c+XJGVRYGj564IFwcxcnzsJghYM1 Kltl180pSwdjXFUl/O64KTtq/oom1vJNRptaWdZw59uR1ZwMNDXNsBUi/adz4pNpProk Zz2+61zC6Knj4uvtLKeHljGuDil177O2/0htdms2HMNbRERpXDy5TLJ7KiZqSAZhQkhc n1eF+Vkt7/klcJy7ME5tNFAoeLZVnzoGzpNlZY5t6lJ7pWjDxkeejzFU+9zsw5VT87t9 hxMA== X-Gm-Message-State: APjAAAWOeT0TecdnBLXwQSTmjSTIcXowxfNZWXew+LIKGk/Af7ovoxGs eE/K2fFtBUEx7dOtFbrc5kZbn8gQWorIdrxv X-Google-Smtp-Source: APXvYqw8Zj1nKT5xssLcXtdcD5A8IwO+ZmQOI8gf5m5ZhlIcooHT8z3lbADr6Vnti8O47CVRI0qztA== X-Received: by 2002:a1c:1a45:: with SMTP id a66mr10594853wma.102.1570190678825; Fri, 04 Oct 2019 05:04:38 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:38 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 02/16] arm64: ssbd: Add support for PSTATE.SSBS rather than trapping to EL3 Date: Fri, 4 Oct 2019 14:04:16 +0200 Message-Id: <20191004120430.11929-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050442_399537_8AFB978F X-CRM114-Status: GOOD ( 18.85 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:342 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Will Deacon , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Will Deacon On CPUs with support for PSTATE.SSBS, the kernel can toggle the SSBD state without needing to call into firmware. This patch hooks into the existing SSBD infrastructure so that SSBS is used on CPUs that support it, but it's all made horribly complicated by the very real possibility of big/little systems that don't uniformly provide the new capability. Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas (cherry picked from commit 8f04e8e6e29c93421a95b61cad62e3918425eac7) Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/processor.h | 7 +++ arch/arm64/include/asm/ptrace.h | 1 + arch/arm64/include/asm/sysreg.h | 3 ++ arch/arm64/include/uapi/asm/ptrace.h | 1 + arch/arm64/kernel/cpu_errata.c | 26 ++++++++++- arch/arm64/kernel/cpufeature.c | 45 ++++++++++++++++++++ arch/arm64/kernel/process.c | 4 ++ arch/arm64/kernel/ssbd.c | 21 +++++++++ 8 files changed, 106 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index def5a5e807f0..ad208bd402f7 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -182,6 +182,10 @@ static inline void start_thread(struct pt_regs *regs, unsigned long pc, { start_thread_common(regs, pc); regs->pstate = PSR_MODE_EL0t; + + if (arm64_get_ssbd_state() != ARM64_SSBD_FORCE_ENABLE) + regs->pstate |= PSR_SSBS_BIT; + regs->sp = sp; } @@ -198,6 +202,9 @@ static inline void compat_start_thread(struct pt_regs *regs, unsigned long pc, regs->pstate |= PSR_AA32_E_BIT; #endif + if (arm64_get_ssbd_state() != ARM64_SSBD_FORCE_ENABLE) + regs->pstate |= PSR_AA32_SSBS_BIT; + regs->compat_sp = sp; } #endif diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h index 177b851ca6d9..6bc43889d11e 100644 --- a/arch/arm64/include/asm/ptrace.h +++ b/arch/arm64/include/asm/ptrace.h @@ -50,6 +50,7 @@ #define PSR_AA32_I_BIT 0x00000080 #define PSR_AA32_A_BIT 0x00000100 #define PSR_AA32_E_BIT 0x00000200 +#define PSR_AA32_SSBS_BIT 0x00800000 #define PSR_AA32_DIT_BIT 0x01000000 #define PSR_AA32_Q_BIT 0x08000000 #define PSR_AA32_V_BIT 0x10000000 diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index 2fc6242baf11..3091ae5975a3 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -86,11 +86,14 @@ #define REG_PSTATE_PAN_IMM sys_reg(0, 0, 4, 0, 4) #define REG_PSTATE_UAO_IMM sys_reg(0, 0, 4, 0, 3) +#define REG_PSTATE_SSBS_IMM sys_reg(0, 3, 4, 0, 1) #define SET_PSTATE_PAN(x) __emit_inst(0xd5000000 | REG_PSTATE_PAN_IMM | \ (!!x)<<8 | 0x1f) #define SET_PSTATE_UAO(x) __emit_inst(0xd5000000 | REG_PSTATE_UAO_IMM | \ (!!x)<<8 | 0x1f) +#define SET_PSTATE_SSBS(x) __emit_inst(0xd5000000 | REG_PSTATE_SSBS_IMM | \ + (!!x)<<8 | 0x1f) #define SYS_DC_ISW sys_insn(1, 0, 7, 6, 2) #define SYS_DC_CSW sys_insn(1, 0, 7, 10, 2) diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h index 5dff8eccd17d..b0fd1d300154 100644 --- a/arch/arm64/include/uapi/asm/ptrace.h +++ b/arch/arm64/include/uapi/asm/ptrace.h @@ -46,6 +46,7 @@ #define PSR_I_BIT 0x00000080 #define PSR_A_BIT 0x00000100 #define PSR_D_BIT 0x00000200 +#define PSR_SSBS_BIT 0x00001000 #define PSR_PAN_BIT 0x00400000 #define PSR_UAO_BIT 0x00800000 #define PSR_V_BIT 0x10000000 diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index dc6c535cbd13..7fe3a60d1086 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -312,6 +312,14 @@ void __init arm64_enable_wa2_handling(struct alt_instr *alt, void arm64_set_ssbd_mitigation(bool state) { + if (this_cpu_has_cap(ARM64_SSBS)) { + if (state) + asm volatile(SET_PSTATE_SSBS(0)); + else + asm volatile(SET_PSTATE_SSBS(1)); + return; + } + switch (psci_ops.conduit) { case PSCI_CONDUIT_HVC: arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_2, state, NULL); @@ -336,6 +344,11 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); + if (this_cpu_has_cap(ARM64_SSBS)) { + required = false; + goto out_printmsg; + } + if (psci_ops.smccc_version == SMCCC_VERSION_1_0) { ssbd_state = ARM64_SSBD_UNKNOWN; return false; @@ -384,7 +397,6 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, switch (ssbd_state) { case ARM64_SSBD_FORCE_DISABLE: - pr_info_once("%s disabled from command-line\n", entry->desc); arm64_set_ssbd_mitigation(false); required = false; break; @@ -397,7 +409,6 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, break; case ARM64_SSBD_FORCE_ENABLE: - pr_info_once("%s forced from command-line\n", entry->desc); arm64_set_ssbd_mitigation(true); required = true; break; @@ -407,6 +418,17 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, break; } +out_printmsg: + switch (ssbd_state) { + case ARM64_SSBD_FORCE_DISABLE: + pr_info_once("%s disabled from command-line\n", entry->desc); + break; + + case ARM64_SSBD_FORCE_ENABLE: + pr_info_once("%s forced from command-line\n", entry->desc); + break; + } + return required; } #endif /* CONFIG_ARM64_SSBD */ diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 58146d636a83..18fd61f6d578 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1071,6 +1071,48 @@ static void cpu_has_fwb(const struct arm64_cpu_capabilities *__unused) WARN_ON(val & (7 << 27 | 7 << 21)); } +#ifdef CONFIG_ARM64_SSBD +static int ssbs_emulation_handler(struct pt_regs *regs, u32 instr) +{ + if (user_mode(regs)) + return 1; + + if (instr & BIT(CRm_shift)) + regs->pstate |= PSR_SSBS_BIT; + else + regs->pstate &= ~PSR_SSBS_BIT; + + arm64_skip_faulting_instruction(regs, 4); + return 0; +} + +static struct undef_hook ssbs_emulation_hook = { + .instr_mask = ~(1U << CRm_shift), + .instr_val = 0xd500001f | REG_PSTATE_SSBS_IMM, + .fn = ssbs_emulation_handler, +}; + +static void cpu_enable_ssbs(const struct arm64_cpu_capabilities *__unused) +{ + static bool undef_hook_registered = false; + static DEFINE_SPINLOCK(hook_lock); + + spin_lock(&hook_lock); + if (!undef_hook_registered) { + register_undef_hook(&ssbs_emulation_hook); + undef_hook_registered = true; + } + spin_unlock(&hook_lock); + + if (arm64_get_ssbd_state() == ARM64_SSBD_FORCE_DISABLE) { + sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_DSSBS); + arm64_set_ssbd_mitigation(false); + } else { + arm64_set_ssbd_mitigation(true); + } +} +#endif /* CONFIG_ARM64_SSBD */ + static const struct arm64_cpu_capabilities arm64_features[] = { { .desc = "GIC system register CPU interface", @@ -1258,6 +1300,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .cpu_enable = cpu_enable_hw_dbm, }, #endif +#ifdef CONFIG_ARM64_SSBD { .desc = "Speculative Store Bypassing Safe (SSBS)", .capability = ARM64_SSBS, @@ -1267,7 +1310,9 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .field_pos = ID_AA64PFR1_SSBS_SHIFT, .sign = FTR_UNSIGNED, .min_field_value = ID_AA64PFR1_SSBS_PSTATE_ONLY, + .cpu_enable = cpu_enable_ssbs, }, +#endif {}, }; diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 7f1628effe6d..ce99c58cd1f1 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -358,6 +358,10 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start, if (IS_ENABLED(CONFIG_ARM64_UAO) && cpus_have_const_cap(ARM64_HAS_UAO)) childregs->pstate |= PSR_UAO_BIT; + + if (arm64_get_ssbd_state() == ARM64_SSBD_FORCE_DISABLE) + childregs->pstate |= PSR_SSBS_BIT; + p->thread.cpu_context.x19 = stack_start; p->thread.cpu_context.x20 = stk_sz; } diff --git a/arch/arm64/kernel/ssbd.c b/arch/arm64/kernel/ssbd.c index 388f8fc13080..f496fb2f7122 100644 --- a/arch/arm64/kernel/ssbd.c +++ b/arch/arm64/kernel/ssbd.c @@ -3,13 +3,31 @@ * Copyright (C) 2018 ARM Ltd, All Rights Reserved. */ +#include #include #include #include +#include #include #include +static void ssbd_ssbs_enable(struct task_struct *task) +{ + u64 val = is_compat_thread(task_thread_info(task)) ? + PSR_AA32_SSBS_BIT : PSR_SSBS_BIT; + + task_pt_regs(task)->pstate |= val; +} + +static void ssbd_ssbs_disable(struct task_struct *task) +{ + u64 val = is_compat_thread(task_thread_info(task)) ? + PSR_AA32_SSBS_BIT : PSR_SSBS_BIT; + + task_pt_regs(task)->pstate &= ~val; +} + /* * prctl interface for SSBD * FIXME: Drop the below ifdefery once merged in 4.18. @@ -47,12 +65,14 @@ static int ssbd_prctl_set(struct task_struct *task, unsigned long ctrl) return -EPERM; task_clear_spec_ssb_disable(task); clear_tsk_thread_flag(task, TIF_SSBD); + ssbd_ssbs_enable(task); break; case PR_SPEC_DISABLE: if (state == ARM64_SSBD_FORCE_DISABLE) return -EPERM; task_set_spec_ssb_disable(task); set_tsk_thread_flag(task, TIF_SSBD); + ssbd_ssbs_disable(task); break; case PR_SPEC_FORCE_DISABLE: if (state == ARM64_SSBD_FORCE_DISABLE) @@ -60,6 +80,7 @@ static int ssbd_prctl_set(struct task_struct *task, unsigned long ctrl) task_set_spec_ssb_disable(task); task_set_spec_ssb_force_disable(task); set_tsk_thread_flag(task, TIF_SSBD); + ssbd_ssbs_disable(task); break; default: return -ERANGE; From patchwork Fri Oct 4 12:04:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174353 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E788513BD for ; Fri, 4 Oct 2019 12:10:15 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BF18B2070B for ; Fri, 4 Oct 2019 12:10:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Ltz9mkPd"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="CK6qZipI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BF18B2070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=36LqoD/l2/laGs9b9umoA8YT2SDv0bWZ29o6OBQdbsg=; b=Ltz9mkPdocAa1Z zieXPaQrpFqW2mfqEhsTAjcg95ln51apMI/dq8mwL8cGitDc/FLaGfMbj+9logGFQ9LR08uElSZ4A QucmRKFdcNahQJsFRwW4ITY55cxkY4sRmzIHcv1slmTZqtZObj1YpMkwrtASkeD2OGXoIr01qXgM2 atoeRWHoDZL6DEwaGR/CAg+axDiH1O8IWW8VFvErvuSoJupjtR9rI1FXDBwnpNXm8LJG8VUCkzLUE NuuEqGkjQJ4mnfhaxmIrwPFxTp2jvRShMK8KH6sWkuYhAK6WMejAggU9O4W6YwRmodkA2FUJk/ktn OF7F8yjive9K+7fypLCw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMPX-0000W6-60; Fri, 04 Oct 2019 12:10:15 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKB-0001l8-8i for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:46 +0000 Received: by mail-wr1-x442.google.com with SMTP id j18so6054202wrq.10 for ; Fri, 04 Oct 2019 05:04:41 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=TWQSpGfEQaZEDJmKuJhffA9rJ/sPngSGcPa+bzYw/v0=; b=CK6qZipIDATO6K7IolEca2mCxEmRJrBu6B68PL9CtB976w3GH/1bR9ljLrEssR5rd8 gcilzm+mQDNPfKJJIgSecWp78SaL+brVhIKz1kluThlsQFpSmj6YcG4tYAcN0LCdT7qj PDh68SGMMkqR5CW3LZybRe7qnwCTe0KJqPmKoMtnkSF+wHFkkDPSmqL5PPK791D4Ym6x soGkNkwyHwuGA/OnDx6LVVCXL/BShD3c+U0f4viSTEFgaGVHJZ4wnqujcsFXmV9abbn4 KyHA0puIpIQtUpZ4HjwmcnxVIDd6aeurRAQFVd2Ki1mbmcd+yaS3D4rNRDtAfBdt+5Ja xa7A== 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:mime-version:content-transfer-encoding; bh=TWQSpGfEQaZEDJmKuJhffA9rJ/sPngSGcPa+bzYw/v0=; b=rtmk6JcgCOSHicFEtPJH/aukyagE4gSJSdWBjrKpeUJKOo/mCzDLmWY2gShJ93247X Is6ChhJsSFFwydHJXuqDQQEumrkfmqC99Eo+enRLyteTRuyPAfZs/XpjbDFJwugGTXnF m1kBClzPYQHL3cKGcRo8TUtcqjImWMDjUuQXipikSgxxVKkMI1e8VR5ar1j8U9OJ5dnf VDeMryZWDFrl+vKG8hJozFiSVFupZs7GPHuDOdZKhw0QNJ8M2KFgHnEz7W4TJge7eRH+ 8oe/rDoAb33Ra88G2VR/xuiubXSLR+7VElFfAFvxbF3QYm9BsKprIDNWw9brbldx4Bkg x4nw== X-Gm-Message-State: APjAAAU6cfoMzBylWZ6Q+syaXjCmCxhIASfT89swAzKsUAElccr9IvyJ nKZ8UhkKtpx4z7AWIQRDhNUTwHGFYKwKdYFK X-Google-Smtp-Source: APXvYqw0Rty4YcmmIVPc/oOzSyfhwOXpYNKn7oCDNDiMVtZPknlkqKG7QB2rj9+7H9l8ZSVPP7BciQ== X-Received: by 2002:a05:6000:105:: with SMTP id o5mr10946803wrx.51.1570190680252; Fri, 04 Oct 2019 05:04:40 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:39 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 03/16] KVM: arm64: Set SCTLR_EL2.DSSBS if SSBD is forcefully disabled and !vhe Date: Fri, 4 Oct 2019 14:04:17 +0200 Message-Id: <20191004120430.11929-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050443_346874_2B084720 X-CRM114-Status: GOOD ( 11.52 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:442 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Will Deacon , Christoffer Dall , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Will Deacon When running without VHE, it is necessary to set SCTLR_EL2.DSSBS if SSBD has been forcefully disabled on the kernel command-line. Acked-by: Christoffer Dall Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas (cherry picked from commit 7c36447ae5a090729e7b129f24705bb231a07e0b) Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/kvm_host.h | 11 +++++++++++ arch/arm64/kvm/hyp/sysreg-sr.c | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 6abe4002945f..367b2e0b6d76 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -398,6 +398,8 @@ struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr); DECLARE_PER_CPU(kvm_cpu_context_t, kvm_host_cpu_state); +void __kvm_enable_ssbs(void); + static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr, unsigned long hyp_stack_ptr, unsigned long vector_ptr) @@ -418,6 +420,15 @@ static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr, */ BUG_ON(!static_branch_likely(&arm64_const_caps_ready)); __kvm_call_hyp((void *)pgd_ptr, hyp_stack_ptr, vector_ptr, tpidr_el2); + + /* + * Disabling SSBD on a non-VHE system requires us to enable SSBS + * at EL2. + */ + if (!has_vhe() && this_cpu_has_cap(ARM64_SSBS) && + arm64_get_ssbd_state() == ARM64_SSBD_FORCE_DISABLE) { + kvm_call_hyp(__kvm_enable_ssbs); + } } static inline bool kvm_arch_check_sve_has_vhe(void) diff --git a/arch/arm64/kvm/hyp/sysreg-sr.c b/arch/arm64/kvm/hyp/sysreg-sr.c index 963d669ae3a2..7414b76191c2 100644 --- a/arch/arm64/kvm/hyp/sysreg-sr.c +++ b/arch/arm64/kvm/hyp/sysreg-sr.c @@ -293,3 +293,14 @@ void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu) vcpu->arch.sysregs_loaded_on_cpu = false; } + +void __hyp_text __kvm_enable_ssbs(void) +{ + u64 tmp; + + asm volatile( + "mrs %0, sctlr_el2\n" + "orr %0, %0, %1\n" + "msr sctlr_el2, %0" + : "=&r" (tmp) : "L" (SCTLR_ELx_DSSBS)); +} From patchwork Fri Oct 4 12:04:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174347 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D6BAA16B1 for ; Fri, 4 Oct 2019 12:09:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 81F402070B for ; Fri, 4 Oct 2019 12:09:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="SPSFAkka"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="W58ZeFCJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81F402070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=nrSVrUMTrLWlL9TTJqreuVGkTWL0wDn2R/bip0tjBR8=; b=SPSFAkka0ihiW6 wtmF2rmH73WzFC9Zr8pp6qcknih0mjZqFmRl2SLZGw26dfmtcSHnbk7pS4EpNj1FIFeYhYEq6Xfs/ jlYc3mwuy4iquuOSNb9+qmi2wobXQTqNuHatzGwKzXwDxFUYzLpApBludNxDKHVWX5uR11cpeoUaa EQ/IGawYor3fBzDDyGIAUeW9860vdrdkNXwpEB925zpig8UlOD3IS2NEEWJvJ+JDi+B7SZNl87NBq RgMj0qh8HsKDI2R4xN0r1ex4QolGroxJExWT1qYnroQZfhUHECEMiDSU5R8VtADrc1yceX5zbmozC PUF+zsNIubLP0YSIQolg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMOb-000754-4K; Fri, 04 Oct 2019 12:09:17 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKB-0001ml-23 for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:44 +0000 Received: by mail-wm1-x343.google.com with SMTP id f22so5581040wmc.2 for ; Fri, 04 Oct 2019 05:04:42 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=8r+04X1U74bdgfUkYIluwO6bKAocs6mvudJLF8T0HZA=; b=W58ZeFCJf65fFOo7DSR5+O7+YUsBq3AUgxBHse+0vrXC9hzvVVtjaRPQrK6fLPzZ9z uPcFtVVhxEHTDZHtCBeVFMjSRNmKrqK8v/6baAaVAGtxgwz/VO/CVTmmAvE+sFrb6cv2 d+q9ceW8gDObKv5sZNs0CIJQI9R8AQVKg1s+1hpglROKbVyE0bJ+Kc6wsvpVFNRPthf0 HZqkoJHutTwWtmIaESf2WJ6rbDu1y1rWjTmbKjQFXJpHHuyVHpHjTAPNn3Y7IkjyFzdj y40P6gQxpEspv9FVli+/eYdoDAapRrYaw2cdWwpmGjTB63Jgtvs2HvdgFppzepZX8aQ+ x4zQ== 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:mime-version:content-transfer-encoding; bh=8r+04X1U74bdgfUkYIluwO6bKAocs6mvudJLF8T0HZA=; b=Egdy4GJfd2DjLyOWiLpklE9zQ54FvhIii256/v2kvn2HTjOrSHmFiXx4vSJSUo0USR F3S0bb6bOdYVX3gSXKCZkSX7GbTEwJupfQwPXguaUjUgLPD2U1lnxOpY42DernPMmC8C eKxbDm0LCZbFDQakfeejKapwJd6JsnTdeSMaRgWZRuZ8ah5jtwhvY6cC0x5s3SFoxNBb tlgmv9XaZXRoFcUD/9JDr8fpypsomICac/F4jsiA7UJ+lcdp0MKzkkduX7qYDWeQBqD+ /5HvuQzLETTS/r/8itTMxhGQxY5D0eI05JzzcKPePNiMAPhBxJ1M2Z28zboe4OZXK04p 3kUA== X-Gm-Message-State: APjAAAUiE6p7AhRoLFtCSVSkXD8zkEapjHmvdMFKK8esd/qpU11Zqg1l 3tHJjo6Z7VJqusdlEjvlbETlBjLjIZd4auxV X-Google-Smtp-Source: APXvYqz+eH0h7XaAQSIakBnH0srj7J+gQFjOQo0NYuDsMcgQc7JkuF5Vm39OexdY1GPGccRq3PPD+w== X-Received: by 2002:a05:600c:2052:: with SMTP id p18mr10546311wmg.13.1570190681521; Fri, 04 Oct 2019 05:04:41 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:40 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 04/16] arm64: docs: Document SSBS HWCAP Date: Fri, 4 Oct 2019 14:04:18 +0200 Message-Id: <20191004120430.11929-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050443_141946_5A8D1A51 X-CRM114-Status: UNSURE ( 8.39 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:343 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Will Deacon , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Will Deacon We advertise the MRS/MSR instructions for toggling SSBS at EL0 using an HWCAP, so document it along with the others. Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas (cherry picked from commit ee91176120bd584aa10c564e7e9fdcaf397190a1) Signed-off-by: Ard Biesheuvel --- Documentation/arm64/elf_hwcaps.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/arm64/elf_hwcaps.txt b/Documentation/arm64/elf_hwcaps.txt index d6aff2c5e9e2..6feaffe90e22 100644 --- a/Documentation/arm64/elf_hwcaps.txt +++ b/Documentation/arm64/elf_hwcaps.txt @@ -178,3 +178,7 @@ HWCAP_ILRCPC HWCAP_FLAGM Functionality implied by ID_AA64ISAR0_EL1.TS == 0b0001. + +HWCAP_SSBS + + Functionality implied by ID_AA64PFR1_EL1.SSBS == 0b0010. From patchwork Fri Oct 4 12:04:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174349 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0426113BD for ; Fri, 4 Oct 2019 12:09:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C5AF92070B for ; Fri, 4 Oct 2019 12:09:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rlfUs/cz"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="kJ88dIsH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C5AF92070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=XvMmij2/niW4PAuKJuDPg3KNyj1QdEx5Z81SHTXAEE4=; b=rlfUs/cz0VK51K OJ9DKynEf9I9Er+80VcSZllFXAvmjeYsjM8CMMyrgO3hkZ42qsN97gGVMqWwDDrJtBXpuDne1YBtY LZtz/57O8ORYrh0KZ/yDSwZXaHFJYNREZVXqu4qYD3opAySgLXkIiFXl2oDf6mFxFRnjRbELgck7G 9A1TtCLNJwftnJvvVmgZmLkiLXkoo+EZnLU8DWmIa8txrVFfVajLiuYvrBagQ5ky3zU/JYcTvOxK4 UpIpIKCjD3qvDF2EUoI+eZcLsTt1jJo7CRXCzE+4wcLuiCVFcTwxZJUqYR83uCIDTS4O3RwCSDqvJ vQ+tL8L3XOaiJNSLnBRQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMOq-0007Lw-9z; Fri, 04 Oct 2019 12:09:32 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKC-0001oP-Io for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:47 +0000 Received: by mail-wr1-x442.google.com with SMTP id p14so5921931wro.4 for ; Fri, 04 Oct 2019 05:04:44 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=Tutiye7X8Cf1Dsey2kXkk0MPW9x++NY7Pa/cCEc+R2U=; b=kJ88dIsHxnuH8Q61H3BW3PjMFwV7iFuHmhe2qH/yjYZBXu0brNN/Pm+bq4lxgSgSNr 8zNwjv5qAjbDQZ9kFI1yZt2Gv6UqfhS0uGmO+I/qcQiLXXnQzxePzIxKi+V/Eihl3eI2 t5akX5+hD+pdLw9a7JaceaNlUytTaU0t/BwlNY4y4NHn4ovMO9gQ5B9l8Mk4VsG7AsNq 9nxBsQsjD0NMXAFmaExPAiJwhUubobkCSmGF2FkJShP12gotKXEBDeq18sNXdp907KIk yC/mtllkoom72Po7zG0xEsE6mxKOr7UCyU+Rfi5fDSyenQ9A1MOgiUY4RxQAfRSPpG/s i+gQ== 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:mime-version:content-transfer-encoding; bh=Tutiye7X8Cf1Dsey2kXkk0MPW9x++NY7Pa/cCEc+R2U=; b=BnaDCK1mUROhi2AWu/YK23Ku2BkrVibGKpUoe6enhxbqlem/erS+ycdWl0WocLAKi5 mbPRD7AyLXM3jvXOp9UkImalnN0VjBLI4EsANjI8MKy+JVYiE2bkzNkef4mjknWb1+Mi B3mxOzE3WyoaJa+5IgbXHEjoqD5Zc3lGs3sgV1QQtknikBC9ytueKt4YizOWDh87d2iz 2EFxrvAAxRyTmFDA3tbRP6dKbH7WVg53zFt6c+2SQtL8UHZf8ftmfxSCqCd+o3DqiVr8 jQLbpVxeeE4E0Pb7Fpy3v1q+aVTyvDs6Xgoq3KQScXgjoqiUNIKD4Hq2o/U1yjVEURzA ad8Q== X-Gm-Message-State: APjAAAWtehuIB0IzeWfqwhPZsCVCKdprM2Tw8oALNcEFef+auZzc87G/ 7f0s3WgzEXBH2XNGobY1/9lLI6qjXrbQPfdI X-Google-Smtp-Source: APXvYqy9TWfcjsqfoHxRHbb0uFugSsWlgsppGr4psiPl/l9O1csbM64b63nKPP/qq8/9+ENjflrzIQ== X-Received: by 2002:a5d:4dd2:: with SMTP id f18mr11975835wru.20.1570190682784; Fri, 04 Oct 2019 05:04:42 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:42 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 05/16] arm64: fix SSBS sanitization Date: Fri, 4 Oct 2019 14:04:19 +0200 Message-Id: <20191004120430.11929-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050444_712433_2D13EDD6 X-CRM114-Status: GOOD ( 12.28 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:442 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Will Deacon , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Mark Rutland In valid_user_regs() we treat SSBS as a RES0 bit, and consequently it is unexpectedly cleared when we restore a sigframe or fiddle with GPRs via ptrace. This patch fixes valid_user_regs() to account for this, updating the function to refer to the latest ARM ARM (ARM DDI 0487D.a). For AArch32 tasks, SSBS appears in bit 23 of SPSR_EL1, matching its position in the AArch32-native PSR format, and we don't need to translate it as we have to for DIT. There are no other bit assignments that we need to account for today. As the recent documentation describes the DIT bit, we can drop our comment regarding DIT. While removing SSBS from the RES0 masks, existing inconsistent whitespace is corrected. Fixes: d71be2b6c0e19180 ("arm64: cpufeature: Detect SSBS and advertise to userspace") Signed-off-by: Mark Rutland Cc: Catalin Marinas Cc: Suzuki K Poulose Cc: Will Deacon Signed-off-by: Will Deacon (cherry picked from commit f54dada8274643e3ff4436df0ea124aeedc43cae) Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/ptrace.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 6219486fa25f..0211c3c7533b 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -1666,19 +1666,20 @@ void syscall_trace_exit(struct pt_regs *regs) } /* - * SPSR_ELx bits which are always architecturally RES0 per ARM DDI 0487C.a - * We also take into account DIT (bit 24), which is not yet documented, and - * treat PAN and UAO as RES0 bits, as they are meaningless at EL0, and may be - * allocated an EL0 meaning in future. + * SPSR_ELx bits which are always architecturally RES0 per ARM DDI 0487D.a. + * We permit userspace to set SSBS (AArch64 bit 12, AArch32 bit 23) which is + * not described in ARM DDI 0487D.a. + * We treat PAN and UAO as RES0 bits, as they are meaningless at EL0, and may + * be allocated an EL0 meaning in future. * Userspace cannot use these until they have an architectural meaning. * Note that this follows the SPSR_ELx format, not the AArch32 PSR format. * We also reserve IL for the kernel; SS is handled dynamically. */ #define SPSR_EL1_AARCH64_RES0_BITS \ - (GENMASK_ULL(63,32) | GENMASK_ULL(27, 25) | GENMASK_ULL(23, 22) | \ - GENMASK_ULL(20, 10) | GENMASK_ULL(5, 5)) + (GENMASK_ULL(63, 32) | GENMASK_ULL(27, 25) | GENMASK_ULL(23, 22) | \ + GENMASK_ULL(20, 13) | GENMASK_ULL(11, 10) | GENMASK_ULL(5, 5)) #define SPSR_EL1_AARCH32_RES0_BITS \ - (GENMASK_ULL(63,32) | GENMASK_ULL(23, 22) | GENMASK_ULL(20,20)) + (GENMASK_ULL(63, 32) | GENMASK_ULL(22, 22) | GENMASK_ULL(20, 20)) static int valid_compat_regs(struct user_pt_regs *regs) { From patchwork Fri Oct 4 12:04:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174351 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7788D16B1 for ; Fri, 4 Oct 2019 12:09:53 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2DE622070B for ; Fri, 4 Oct 2019 12:09:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TBf7jkpQ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="FuzKo3Bp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DE622070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=XJLJ/yOFydpXfH/bCQ4mdhjdR6xMQdpVuwR8jpOC70k=; b=TBf7jkpQQc15HV b1fQkp0aNwFxrugcn+Q07c70wZ+lUZyNkgNFMr86ltFlIIe/QHnq3Qi8qLJMQviQRnlOqmEw2bJBC 7tIzAr43EeQtVcLloqnT/QCEymF6tZ/jPqdhm4BBtNJfw2ESNn5e5RYBOgAXoi82ti1XSpmKY3QnX WRbsSt+ahdK7LL938wCu7FOC8nu+bQ3o86cTjRFUU+SNhAAjCs++NEwaYrHgR8+wyKCjNTNYBIIw9 qfRYxpZhbHPeKd47pIZnK39m2SKTnIEhDSqlgRURm2lj1VPANrokuAUahm3MzGby5ytwZpxU/mCQ7 Nv240JwDBE29dTgiNU2A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMP8-0007fS-6M; Fri, 04 Oct 2019 12:09:50 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKE-0001pj-7D for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:48 +0000 Received: by mail-wr1-x442.google.com with SMTP id v8so6894678wrt.2 for ; Fri, 04 Oct 2019 05:04:46 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=tFoAdqBLSyk0vZf6DS/EoHCTPxZncgXa+o7HCkM11aA=; b=FuzKo3BpnIg/0swZYbfGIFA4PGyd2EHKLKAI8rLcm6NT6sa0/QWTzFQEtQJTEQoMn2 1Z8P/BT2kJTpL25lfJAK7xlYakdueOiMheXxevmb8d4pK6JWH0g3osVsKxbU4WwPgWa9 ukwzxksSebYMZ/uepoG7rgSc04lx17/7OiEU8rtoSbAokUhMVvYVFeUdb6jVhK6Y/SNv aChqcMrpCEadqBhzgEKck7nszBYjTx9hnT6A8Txc9++51TVY+co9ZM4tBwtkz0OVXCmG 2/ZtaX2mXqixZb7EHLg26aBNqr3bL/cycBSaCavuhPvD2TVlSSDBD5rnBadQO55Z1vCw D44g== 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:mime-version:content-transfer-encoding; bh=tFoAdqBLSyk0vZf6DS/EoHCTPxZncgXa+o7HCkM11aA=; b=rmmDRY2JNQJoQUF7TzLGKaZwWn127iDWxgX3eVxHZ8nzWvhaSedId0OMIeoCXZqIgR N4qdcGcIbE7eI3UWQuL+EXWaz+8AtTcw56Nuxl4pwUZEVGPRgyHwXSPSVABT5eTzsOA3 Jz/sLEuZBbjR9FzeTcbtvFK4uJ0x2LIliQ5qNwteQ67szhgZDNYkoNafBZiJRq9whyz2 6NQHJwgJyLC4RJx1Idro463qjH4wYzhNhfvsQ1l+6otit7PJs6DYnSL7Q6EozgJVvNOX g2rPNbUqPAwXyS8s28yeoUadQ1E1+XVKRChzcYSuEIjPYVO96mhPsh82FbvqwTevaI0L +gYA== X-Gm-Message-State: APjAAAXVv3zSWfv4IrxaCfls4OZ3ldC/tZ4ncoIZvwWNZ/Dk1aAXDt98 IkXhurZ4ZMdxGTA03htohQyImjuq09m9eRxb X-Google-Smtp-Source: APXvYqyWO4f+J8l9DLWRg98/8IopX9xSrB3tv+oCli1PaCRSBUAzuBYk0ryqZQPWW4C+tiCuZeNzSw== X-Received: by 2002:adf:ec86:: with SMTP id z6mr178703wrn.231.1570190684222; Fri, 04 Oct 2019 05:04:44 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:43 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 06/16] arm64: Add sysfs vulnerability show for spectre-v1 Date: Fri, 4 Oct 2019 14:04:20 +0200 Message-Id: <20191004120430.11929-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050446_307054_840DD06F X-CRM114-Status: GOOD ( 10.29 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:442 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Stefan Wahren , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Mian Yousaf Kaukab , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Mian Yousaf Kaukab spectre-v1 has been mitigated and the mitigation is always active. Report this to userspace via sysfs Signed-off-by: Mian Yousaf Kaukab Signed-off-by: Jeremy Linton Reviewed-by: Andre Przywara Reviewed-by: Catalin Marinas Tested-by: Stefan Wahren Acked-by: Suzuki K Poulose Signed-off-by: Will Deacon (cherry picked from commit 3891ebccace188af075ce143d8b072b65e90f695) Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/cpu_errata.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 7fe3a60d1086..3758ba538a43 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -729,3 +729,9 @@ const struct arm64_cpu_capabilities arm64_errata[] = { { } }; + +ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "Mitigation: __user pointer sanitization\n"); +} From patchwork Fri Oct 4 12:04:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174355 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 601A613BD for ; Fri, 4 Oct 2019 12:10:31 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 369C7222C0 for ; Fri, 4 Oct 2019 12:10:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="e7l7aNxa"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="YtxiqArp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 369C7222C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=7lRDoFa/pcMqWGIT4rqmS8Ezifs3ZGY31OvOitzQQCk=; b=e7l7aNxaSq5pDo Lx54wd/XqONtzMWiUKmbgd96uq59ON+Uf+qgq1S2vUXbP2d/OYILE6JDlKQ1uPYbBrgfdnI9C+Y5C ibH/hV1QZnULylzqgqGCZHwQtiEYiMGe45/F4CDOByKSGv7fALCQ4IYAchv8Jkr4FgI17o+JSr6Rs zmjyIkWUNNjF2zJFFQgkW9q+1zctveYVi352octisDIJKE5KVGtOMF679UUh2SEZ31AC87Bxb9Zhm pLu59mSLe4am5rDk2P3Hrj99FhXYWMCgQow5HZrBxZsIcho4qC4fEpavq2Fu/hBufgI0NGZhVEzve SR3Lri8WJRqB72qwEsJg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMPk-0000uh-Pk; Fri, 04 Oct 2019 12:10:28 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKF-0001qR-PR for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:50 +0000 Received: by mail-wr1-x441.google.com with SMTP id y19so6890075wrd.3 for ; Fri, 04 Oct 2019 05:04:46 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=FAtbDeWjPlKkFNUFITEx0/p3Vh2NGLFot6q73BBvfrs=; b=YtxiqArpScdYa6I9iPo5QbXkBiWbNHIyc2ilgsdvbc2UL6G8h0NxL0+OLtdrK0/6qK HgbDV8P+gK2baq5cpXV3wI3/oiOj6bfR6dogI30B8gld4LqeAx5BKtqQpMguLCjzcDFG xf82TxmqDEsmiDG7JCWiu1Htvqif/rJr4e/NI80yqzDd6CfZmVgZ51rJwS+4l1Q+gtTr ilRjHBcPzDpE2cKIPXJzFzujSsyvJ7Am47wBaQQBmV1c2ghIGYiBxmOwrxPSIo7YLXnR 7gHLXcQBh0kKtHke0fgs9AAKRFqoXo8deGqAC+68rzzoqkt/OGJaooUKj06iZf+o3JvZ s2Ag== 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:mime-version:content-transfer-encoding; bh=FAtbDeWjPlKkFNUFITEx0/p3Vh2NGLFot6q73BBvfrs=; b=MUCmgQ44oSJB88D0pbgoWlS6g/9R6RBigYdxYWtedI4GhriM5mDPA12qgJkLxe6wur YR93WRrNMaQg2TA4kEz20yEc+tkrDRITEu+EY5nWWE0kS34kxTPM+rUoizW/L6rJmrUt J4FYut0NUirAQbf3R7IS7zm5IvOQvBfiQo6VSN2rvkSFt3+vFoWQzV9cVAtQALBeCGCC /mlfSZ4xlA//1vSRFRlY+R717xfc98RG0RD8dLI2Pzh8bV8dP2dXdQX2m/7VwSgSBq5K nY7Fqtp0uuD3Bc5Tw8USyA2WrmYOXgpbxgTSWEpyF51sVacuYplTTIAF/DZTfjLhvSAn 8hPA== X-Gm-Message-State: APjAAAVMeOF+SpvCSLyZtdYDG68ucUIyiWSNGEeI3zMrUKrPKfi/TYvo xETZLNc6fXDqnTlWWLdUkwPIJ7ZG4cWKO030 X-Google-Smtp-Source: APXvYqznMVLiyDuOchQ7CeXVcd4v8/xRZGSmLl7pz2sEYKXd1IFrIQvbZo58hLQyd/hAU6dRJPEzNw== X-Received: by 2002:adf:cc0a:: with SMTP id x10mr7548980wrh.195.1570190685438; Fri, 04 Oct 2019 05:04:45 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:44 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 07/16] arm64: add sysfs vulnerability show for meltdown Date: Fri, 4 Oct 2019 14:04:21 +0200 Message-Id: <20191004120430.11929-8-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050447_892527_CE0A016D X-CRM114-Status: GOOD ( 16.58 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:441 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Stefan Wahren , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Will Deacon , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jeremy Linton We implement page table isolation as a mitigation for meltdown. Report this to userspace via sysfs. Signed-off-by: Jeremy Linton Reviewed-by: Suzuki K Poulose Reviewed-by: Andre Przywara Reviewed-by: Catalin Marinas Tested-by: Stefan Wahren Signed-off-by: Will Deacon (cherry picked from commit 1b3ccf4be0e7be8c4bd8522066b6cbc92591e912) Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/cpufeature.c | 58 +++++++++++++++----- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 18fd61f6d578..e93bbadc0cf1 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -889,7 +889,7 @@ static bool has_cache_dic(const struct arm64_cpu_capabilities *entry, return ctr & BIT(CTR_DIC_SHIFT); } -#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +static bool __meltdown_safe = true; 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, @@ -908,6 +908,16 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, { /* sentinel */ } }; char const *str = "command line option"; + bool meltdown_safe; + + meltdown_safe = is_midr_in_range_list(read_cpuid_id(), kpti_safe_list); + + /* Defer to CPU feature registers */ + if (has_cpuid_feature(entry, scope)) + meltdown_safe = true; + + if (!meltdown_safe) + __meltdown_safe = false; /* * For reasons that aren't entirely clear, enabling KPTI on Cavium @@ -919,6 +929,19 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, __kpti_forced = -1; } + /* Useful for KASLR robustness */ + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_offset() > 0) { + if (!__kpti_forced) { + str = "KASLR"; + __kpti_forced = 1; + } + } + + if (!IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0)) { + pr_info_once("kernel page table isolation disabled by kernel configuration\n"); + return false; + } + /* Forced? */ if (__kpti_forced) { pr_info_once("kernel page table isolation forced %s by %s\n", @@ -926,18 +949,10 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, return __kpti_forced > 0; } - /* Useful for KASLR robustness */ - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) - return true; - - /* Don't force KPTI for CPUs that are not vulnerable */ - if (is_midr_in_range_list(read_cpuid_id(), kpti_safe_list)) - return false; - - /* Defer to CPU feature registers */ - return !has_cpuid_feature(entry, scope); + return !meltdown_safe; } +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 static void kpti_install_ng_mappings(const struct arm64_cpu_capabilities *__unused) { @@ -962,6 +977,12 @@ kpti_install_ng_mappings(const struct arm64_cpu_capabilities *__unused) return; } +#else +static void +kpti_install_ng_mappings(const struct arm64_cpu_capabilities *__unused) +{ +} +#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ static int __init parse_kpti(char *str) { @@ -975,7 +996,6 @@ static int __init parse_kpti(char *str) return 0; } early_param("kpti", parse_kpti); -#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ #ifdef CONFIG_ARM64_HW_AFDBM static inline void __cpu_enable_hw_dbm(void) @@ -1196,7 +1216,6 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .field_pos = ID_AA64PFR0_EL0_SHIFT, .min_field_value = ID_AA64PFR0_EL0_32BIT_64BIT, }, -#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 { .desc = "Kernel page table isolation (KPTI)", .capability = ARM64_UNMAP_KERNEL_AT_EL0, @@ -1212,7 +1231,6 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .matches = unmap_kernel_at_el0, .cpu_enable = kpti_install_ng_mappings, }, -#endif { /* FP/SIMD is not implemented */ .capability = ARM64_HAS_NO_FPSIMD, @@ -1853,3 +1871,15 @@ void cpu_clear_disr(const struct arm64_cpu_capabilities *__unused) /* Firmware may have left a deferred SError in this register. */ write_sysreg_s(0, SYS_DISR_EL1); } + +ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, + char *buf) +{ + if (__meltdown_safe) + return sprintf(buf, "Not affected\n"); + + if (arm64_kernel_unmapped_at_el0()) + return sprintf(buf, "Mitigation: PTI\n"); + + return sprintf(buf, "Vulnerable\n"); +} From patchwork Fri Oct 4 12:04:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174357 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12F1C13BD for ; Fri, 4 Oct 2019 12:11:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E0DA921D71 for ; Fri, 4 Oct 2019 12:10:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tp+LyR/E"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MLo9nwHG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0DA921D71 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=FuuBe0mOXOjxGxHFQxecxio7uedH+0BMVsBtlyhke9A=; b=tp+LyR/EVyYWUJ XPsV7IjE5k1P9UxPcB1jHtLuaeU5HZEGhlSFEyCY/3WmPgloJTv9gvUqPxUazcGweIWAW8m61dphp TzK8r7XUqLq6yZvvw4KDbQXk7ILF7UmoBVZCfayBWY7JTHXPZnYy5osSO4k3ciRjXKYL4GUdePf8a ISmQuTMESd7H4LcSFx+tDqGkQrr9UtSsxVnWzCe1UIFf0LIpFfmp3CC575kITpRdN8r14hQY0kVm/ 976aM3yIGVouSCboWn2yV/6JfxPZMj+yVChEEtF2bYnqxjhSDgroHw5la6pSMUAeDUBySTGIYeJnj MlOsW0bDwHQGep6y69mg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMQE-0001FT-Or; Fri, 04 Oct 2019 12:10:58 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKH-0001rX-OP for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:53 +0000 Received: by mail-wm1-x32f.google.com with SMTP id v17so5580390wml.4 for ; Fri, 04 Oct 2019 05:04:48 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=LY+LcXEZQGuXDzdfKBNERn2UxGP3UKGhRpRtxbLi/Bo=; b=MLo9nwHGtx4S3a1vu+SHqAUOUASgJFRcf/ppbjTVtjXHHDuVbwBsIFDC75ddJ+ez89 rZygLYfmSm/lBLu+tI0Gm3BocMi821tZJpjT331P6OB6AOSJobuA0aZ0FimM2G6dU01L JgQ+brybwXfwLoA9dgMvVK6Qx9MtQ3ISS6n4+7yQqTbp93rZL116FWwcRD8MgSBZDKe7 vDIE4bw8P8d2IEdRIBsc3WO/NBnGEfBVqFyai9cbVWYTJAtQUiCSMiIcRH0LmFwCK7WF nAxKKx6b22/TMnwDi/QZc39cIaVWAD/X17/m9IM/V4aXyco6SwhFXJ3bhP7a63NzM/78 hulA== 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:mime-version:content-transfer-encoding; bh=LY+LcXEZQGuXDzdfKBNERn2UxGP3UKGhRpRtxbLi/Bo=; b=CYZoRmk1mtsE0vRdVHi9djcWySmgDBaceY6EVjmfrc3M+xDAx3+w01T+6iq+fY81rk fC4shL9cKDBSYd/6LHF+3F5DscjqklWu2mJmLFpbX8lvCke5+oX3II3+eWp1GMY5lK+s bBpLcm6glPkAAhRALQ4jOd1zzQp7oh6d5mjSOARmGhyu68Nr84Gzvfeej1FBMPDCsPDt eiFgKYTNlfAk+xi42OCcUH2nec5Vo3cuQFehdb2juULQfgIoS58TItX3pEyk2iNEE8mg nA7HKrY2sS5nR9vtuNX3VGCdK6i8zC4AJJMptMpMqbfya5BEixQqxuMBk+sUsp4xB7Vf VLoA== X-Gm-Message-State: APjAAAXd0q3ieIoXnId4uZEOSWRzxaHB8sd7oJ5dUZEVW6h2aje9jdcI SPmS3L3d8iw0AhnxyjHt2CQb6ZKs22ueHxte X-Google-Smtp-Source: APXvYqy1HOgnDYvWVcjAi/uozZ2aBCWj+TSrGaxk77MeRSLNBugJUU77W/CXQSOfpjyBRirdL2T2pQ== X-Received: by 2002:a1c:658b:: with SMTP id z133mr10877700wmb.130.1570190686715; Fri, 04 Oct 2019 05:04:46 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:46 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 08/16] arm64: enable generic CPU vulnerabilites support Date: Fri, 4 Oct 2019 14:04:22 +0200 Message-Id: <20191004120430.11929-9-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050449_825946_06A2D1C0 X-CRM114-Status: GOOD ( 10.19 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:32f listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Stefan Wahren , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Mian Yousaf Kaukab , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Mian Yousaf Kaukab Enable CPU vulnerabilty show functions for spectre_v1, spectre_v2, meltdown and store-bypass. Signed-off-by: Mian Yousaf Kaukab Signed-off-by: Jeremy Linton Reviewed-by: Andre Przywara Reviewed-by: Catalin Marinas Tested-by: Stefan Wahren Signed-off-by: Will Deacon (cherry picked from commit 61ae1321f06c4489c724c803e9b8363dea576da3) Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index e3ebece79617..51fe21f5d078 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -84,6 +84,7 @@ config ARM64 select GENERIC_CLOCKEVENTS select GENERIC_CLOCKEVENTS_BROADCAST select GENERIC_CPU_AUTOPROBE + select GENERIC_CPU_VULNERABILITIES select GENERIC_EARLY_IOREMAP select GENERIC_IDLE_POLL_SETUP select GENERIC_IRQ_MULTI_HANDLER From patchwork Fri Oct 4 12:04:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 00BAA16B1 for ; Fri, 4 Oct 2019 12:11:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D1DE62070B for ; Fri, 4 Oct 2019 12:11:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cZ4G63bG"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="u7JSTFaB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1DE62070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=9m8n7FQfyimfwSOj7XAFBVktNmEtLTKl8zQ+kzHxsfc=; b=cZ4G63bGAWgCPa gyefEWo2dq6+gmPRIDhZC48U23ZBqJqBB1m1S8EdRIYtLoIVpx3L05ryFAgQ6qY7JdfqenVY3usm5 z6QTJxxtX/TSzurNvc6iLEmbNpvcaduQ763VvokqgZzFMAyrCBWcp5P8KGnKDodpLfGYmwq+PNwoq tNc+RGOKauTyRSY343e0Wwp/BVFtJZ6G/AqHcUdGPGM+bbwIb0P20ekrp8nyey+I0T5XU2wtY1IsF JOW8xIRqIRx95exfLr487iWin8VDLBv21T/TLlgLTC2dorKqAlDjYpBMvSGWobMf3nR3AJ2DLWSKm AWapiho/B+sOTMcfcGVw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMQU-0001V8-NY; Fri, 04 Oct 2019 12:11:14 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKI-0001sc-HS for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:55 +0000 Received: by mail-wr1-x444.google.com with SMTP id o18so6814663wrv.13 for ; Fri, 04 Oct 2019 05:04:49 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=suth/yl7C9uDuKnFfHGvtaLYw1nAU2JE6foMZrBU1qQ=; b=u7JSTFaB3+6rww5bw+3zAh8GYbUYNGvNJBk1J9hUrtPLM7vZElrKeGjaaUd1XJ8PDd euAnU9ckEGTlg7UuDgpIborMmJESaMf9DasD+8yHhFRglwvviGUjeXTpNSZaoXjIAXUU Im3yyNR3PSVhsLhSW3KBut6GiRLjRlEx8HBXG7tTyUYdj6+glb3/aShDgyR8hscPSZ7t s1lEPWbGZ0Vclg5qDq14T1u/BJbqXNN2WwxgVILo1ebNKtqAUauCdBqEKXRONWDpIFq/ TcNXNspgq3oSHlbs/GcR1NeqUhZsD6YLQvRCz16zvaVNMHCPleM68EET/mVU8eGscQ50 Q+XA== 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:mime-version:content-transfer-encoding; bh=suth/yl7C9uDuKnFfHGvtaLYw1nAU2JE6foMZrBU1qQ=; b=O+PIgZ2KSRmi0c2rTVrEuhwNobKTGwlk1t2c/UHj4DFEl/WGpxKe/DsMAQf/Uc+iXY MfPFIl1O9ZsfQoxEekzAHVryP8GvSCj2RZNuopxXfzk5C7+XDtTCOucOrsq2I0UqVcUE 8qRpas4WZWeP3e9KyfOrgNwWZM8xJLB9+0ShcEDqkQ428+wn0R1mbjMTLJy8iDhgtaLj lROWxMa/gBfys/bhNqUpHPQwBIz9sHRtGIKSjDSW0e5Jz2Xc0/8woe11t+18FVLDPaUb 2MyRoVj3AZRfdd9SATwtBqUHDwH1YR7BZ7PqdB0H+6JjTDlbjoreoEXffLJ8ZISJFWIT ZtJw== X-Gm-Message-State: APjAAAWjgatxdAY8c/9f7IOX4Fq7Ds2+TUi52ibegODWHer5cbH6EZBZ lXervIqWXhXYpC3l2wYUI4CB78fHcAN8fr7h X-Google-Smtp-Source: APXvYqyY9s67nKyPhoAmHbDhr4NeD9R/VMYYs5ICoX9odFWy6lJ8OkI9K04wXpCG7oQAaWEbrkuGtw== X-Received: by 2002:adf:f58c:: with SMTP id f12mr8665663wro.38.1570190687975; Fri, 04 Oct 2019 05:04:47 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:47 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 09/16] arm64: Provide a command line to disable spectre_v2 mitigation Date: Fri, 4 Oct 2019 14:04:23 +0200 Message-Id: <20191004120430.11929-10-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050450_623323_8FA6A289 X-CRM114-Status: GOOD ( 13.56 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:444 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Stefan Wahren , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , linux-doc@vger.kernel.org, Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon , Jonathan Corbet , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jeremy Linton There are various reasons, such as benchmarking, to disable spectrev2 mitigation on a machine. Provide a command-line option to do so. Signed-off-by: Jeremy Linton Reviewed-by: Suzuki K Poulose Reviewed-by: Andre Przywara Reviewed-by: Catalin Marinas Tested-by: Stefan Wahren Cc: Jonathan Corbet Cc: linux-doc@vger.kernel.org Signed-off-by: Will Deacon (cherry picked from commit e5ce5e7267ddcbe13ab9ead2542524e1b7993e5a) Signed-off-by: Ard Biesheuvel --- Documentation/admin-guide/kernel-parameters.txt | 8 ++++---- arch/arm64/kernel/cpu_errata.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index e8ddf0ef232e..cc2f5c9a8161 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2866,10 +2866,10 @@ (bounds check bypass). With this option data leaks are possible in the system. - nospectre_v2 [X86,PPC_FSL_BOOK3E] Disable all mitigations for the Spectre variant 2 - (indirect branch prediction) vulnerability. System may - allow data leaks with this option, which is equivalent - to spectre_v2=off. + nospectre_v2 [X86,PPC_FSL_BOOK3E,ARM64] Disable all mitigations for + the Spectre variant 2 (indirect branch prediction) + vulnerability. System may allow data leaks with this + option. nospec_store_bypass_disable [HW] Disable all mitigations for the Speculative Store Bypass vulnerability diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 3758ba538a43..5a7fa90c668f 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -189,6 +189,14 @@ static void qcom_link_stack_sanitization(void) : "=&r" (tmp)); } +static bool __nospectre_v2; +static int __init parse_nospectre_v2(char *str) +{ + __nospectre_v2 = true; + return 0; +} +early_param("nospectre_v2", parse_nospectre_v2); + static void enable_smccc_arch_workaround_1(const struct arm64_cpu_capabilities *entry) { @@ -200,6 +208,11 @@ enable_smccc_arch_workaround_1(const struct arm64_cpu_capabilities *entry) if (!entry->matches(entry, SCOPE_LOCAL_CPU)) return; + if (__nospectre_v2) { + pr_info_once("spectrev2 mitigation disabled by command line option\n"); + return; + } + if (psci_ops.smccc_version == SMCCC_VERSION_1_0) return; From patchwork Fri Oct 4 12:04:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174363 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 392C213BD for ; Fri, 4 Oct 2019 12:11:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D3DD2070B for ; Fri, 4 Oct 2019 12:11:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TxmQvyCX"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="kD58VDxx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D3DD2070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=IakHseFdjMiLm7116z6VNPl2vVXPyQ66DGOZgHcXkTk=; b=TxmQvyCXaEE5A7 U6N3Rsz7FqQ9rYsd7xQoJK47xfvAAujOCr9YjjLJKmm3fkTdakIk+aY6a8CIAnfiUZpqXYg8qerHc BP7IkB+lJakwP7BS410u5p0YFygP2AZB0KIdm9lm3gyeXB7jvU6P1qBJWygileZARSg4AWAwsWGp7 vadCsnhEvvYO1Z1EbbRbbyOV7JlvZYTtZXnsJGEPyc/z0vrrQpU9n3t55Vt3zK8pegpHetoksQgAE Q8K9TpUIONMuGDcztmB9hBy9sTWLAE7El7ub04x0KNu2C3PP9vtabvlcpb0aDBx2dukqQwSg6JNQp LScLjrYgqxKM1tmyyoIQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMQy-0001vX-5Y; Fri, 04 Oct 2019 12:11:44 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKJ-0001u3-1W for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:56 +0000 Received: by mail-wm1-x343.google.com with SMTP id 3so5578826wmi.3 for ; Fri, 04 Oct 2019 05:04:50 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=jNXIdIPJRLzwVgxDiCdXk/OkCvY1+s2BsHAVrOZpyyQ=; b=kD58VDxx9nlL1n6YLK8tb1dpAQrvuYyS3K2jtm2V3hDU3piWavLna29mVOXtha9d3q jflMduNioIrPLsd/+8kbLa8GLAIam4YxWDR6KghNIIkVB/syIbUrFurQgnXDUyo61392 E5ZUT9+fAhtoBx9EsHKsIPTiSXwo1SXx0mD0OQJ218nvidl1m5cMk68uMUQoYk8xIJgo SrIlWnKPGJQY0miU6Sfx8h7imh2nUgxWBCEfGcEdAEXokdvqehY64sRGdJjKipK2Tlqn sXebSJB4FnMGTwh/gPjEbxcrxOkxEDD2lBGALRtUZf+njHqp0e9kKMZZeBCCv3dbvDlL cc3w== 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:mime-version:content-transfer-encoding; bh=jNXIdIPJRLzwVgxDiCdXk/OkCvY1+s2BsHAVrOZpyyQ=; b=itmjHMZQaUxvPJBgzXz7cowTyMbRRq0M6zgjW0jMB+LcU8PpdXPN6UIYGqfNRU3JpB 5nNLRFmHCVYhpb3TB2492zMqObP/GxkmrCdQ0w/RDJ7J1aUxsjcG+DXWE3kvrP8N6She a4Axk8fVtKtm+Y7CetTKfnkcIPDgMW8WakI2aoshQvFeHxj+B6gnlE9pBkL17erM2+ko KbWeT8PCx27PVyvIePUa06biR8zzDjr4/53JLLol77JZq9OHDVkgjrGdg/RBLp0xocdd J92FmtPSsRJSmdFRVXbIAeR8V8ChdJzgsqjVm9lN0JwVqf5miE2S3NmGSSFHG1jvGsG2 D2mA== X-Gm-Message-State: APjAAAUuKcJLawFs8V8LYdWhprs9Zq91Cpsw3MVD0jnn2X03tzmwkqn6 8ifMXZ0SndxDFfbUHM2dGSlZXBbPileFQam+ X-Google-Smtp-Source: APXvYqyy5ZJZePoe10gKtp3fWYAY0YAMb9OVqJ7Nfvr+p0Gv96DjQa8zTfUnId/rbYNf4ru94Hsj7Q== X-Received: by 2002:a1c:7f84:: with SMTP id a126mr5907866wmd.42.1570190689386; Fri, 04 Oct 2019 05:04:49 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:48 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 10/16] arm64: Advertise mitigation of Spectre-v2, or lack thereof Date: Fri, 4 Oct 2019 14:04:24 +0200 Message-Id: <20191004120430.11929-11-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050451_190524_5C21B3E3 X-CRM114-Status: GOOD ( 19.70 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:343 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Stefan Wahren , Suzuki K Poulose , Marc Zyngier , Catalin Marinas , Ard Biesheuvel , Will Deacon , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Marc Zyngier We currently have a list of CPUs affected by Spectre-v2, for which we check that the firmware implements ARCH_WORKAROUND_1. It turns out that not all firmwares do implement the required mitigation, and that we fail to let the user know about it. Instead, let's slightly revamp our checks, and rely on a whitelist of cores that are known to be non-vulnerable, and let the user know the status of the mitigation in the kernel log. Signed-off-by: Marc Zyngier Signed-off-by: Jeremy Linton Reviewed-by: Andre Przywara Reviewed-by: Suzuki K Poulose Reviewed-by: Catalin Marinas Tested-by: Stefan Wahren Signed-off-by: Will Deacon (cherry picked from commit 73f38166095947f3b86b02fbed6bd592223a7ac8) Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/cpu_errata.c | 109 ++++++++++---------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 5a7fa90c668f..def847873d21 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -109,9 +109,9 @@ static void __copy_hyp_vect_bpi(int slot, const char *hyp_vecs_start, __flush_icache_range((uintptr_t)dst, (uintptr_t)dst + SZ_2K); } -static void __install_bp_hardening_cb(bp_hardening_cb_t fn, - const char *hyp_vecs_start, - const char *hyp_vecs_end) +static void install_bp_hardening_cb(bp_hardening_cb_t fn, + const char *hyp_vecs_start, + const char *hyp_vecs_end) { static DEFINE_SPINLOCK(bp_lock); int cpu, slot = -1; @@ -138,7 +138,7 @@ static void __install_bp_hardening_cb(bp_hardening_cb_t fn, #define __smccc_workaround_1_smc_start NULL #define __smccc_workaround_1_smc_end NULL -static void __install_bp_hardening_cb(bp_hardening_cb_t fn, +static void install_bp_hardening_cb(bp_hardening_cb_t fn, const char *hyp_vecs_start, const char *hyp_vecs_end) { @@ -146,23 +146,6 @@ static void __install_bp_hardening_cb(bp_hardening_cb_t fn, } #endif /* CONFIG_KVM_INDIRECT_VECTORS */ -static void install_bp_hardening_cb(const struct arm64_cpu_capabilities *entry, - bp_hardening_cb_t fn, - const char *hyp_vecs_start, - const char *hyp_vecs_end) -{ - u64 pfr0; - - if (!entry->matches(entry, SCOPE_LOCAL_CPU)) - return; - - pfr0 = read_cpuid(ID_AA64PFR0_EL1); - if (cpuid_feature_extract_unsigned_field(pfr0, ID_AA64PFR0_CSV2_SHIFT)) - return; - - __install_bp_hardening_cb(fn, hyp_vecs_start, hyp_vecs_end); -} - #include #include #include @@ -197,31 +180,27 @@ static int __init parse_nospectre_v2(char *str) } early_param("nospectre_v2", parse_nospectre_v2); -static void -enable_smccc_arch_workaround_1(const struct arm64_cpu_capabilities *entry) +/* + * -1: No workaround + * 0: No workaround required + * 1: Workaround installed + */ +static int detect_harden_bp_fw(void) { bp_hardening_cb_t cb; void *smccc_start, *smccc_end; struct arm_smccc_res res; u32 midr = read_cpuid_id(); - if (!entry->matches(entry, SCOPE_LOCAL_CPU)) - return; - - if (__nospectre_v2) { - pr_info_once("spectrev2 mitigation disabled by command line option\n"); - return; - } - if (psci_ops.smccc_version == SMCCC_VERSION_1_0) - return; + return -1; switch (psci_ops.conduit) { case PSCI_CONDUIT_HVC: arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, ARM_SMCCC_ARCH_WORKAROUND_1, &res); if ((int)res.a0 < 0) - return; + return -1; cb = call_hvc_arch_workaround_1; /* This is a guest, no need to patch KVM vectors */ smccc_start = NULL; @@ -232,23 +211,23 @@ enable_smccc_arch_workaround_1(const struct arm64_cpu_capabilities *entry) arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, ARM_SMCCC_ARCH_WORKAROUND_1, &res); if ((int)res.a0 < 0) - return; + return -1; cb = call_smc_arch_workaround_1; smccc_start = __smccc_workaround_1_smc_start; smccc_end = __smccc_workaround_1_smc_end; break; default: - return; + return -1; } if (((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR) || ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1)) cb = qcom_link_stack_sanitization; - install_bp_hardening_cb(entry, cb, smccc_start, smccc_end); + install_bp_hardening_cb(cb, smccc_start, smccc_end); - return; + return 1; } #endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ @@ -532,24 +511,48 @@ multi_entry_cap_cpu_enable(const struct arm64_cpu_capabilities *entry) } #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR - /* - * List of CPUs where we need to issue a psci call to - * harden the branch predictor. + * List of CPUs that do not need any Spectre-v2 mitigation at all. */ -static const struct midr_range arm64_bp_harden_smccc_cpus[] = { - MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), - MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), - MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), - MIDR_ALL_VERSIONS(MIDR_CORTEX_A75), - MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), - MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), - MIDR_ALL_VERSIONS(MIDR_QCOM_FALKOR_V1), - MIDR_ALL_VERSIONS(MIDR_QCOM_FALKOR), - MIDR_ALL_VERSIONS(MIDR_NVIDIA_DENVER), - {}, +static const struct midr_range spectre_v2_safe_list[] = { + MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), + MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), + MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), + { /* sentinel */ } }; +static bool __maybe_unused +check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) +{ + int need_wa; + + WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); + + /* If the CPU has CSV2 set, we're safe */ + if (cpuid_feature_extract_unsigned_field(read_cpuid(ID_AA64PFR0_EL1), + ID_AA64PFR0_CSV2_SHIFT)) + return false; + + /* Alternatively, we have a list of unaffected CPUs */ + if (is_midr_in_range_list(read_cpuid_id(), spectre_v2_safe_list)) + return false; + + /* Fallback to firmware detection */ + need_wa = detect_harden_bp_fw(); + if (!need_wa) + return false; + + /* forced off */ + if (__nospectre_v2) { + pr_info_once("spectrev2 mitigation disabled by command line option\n"); + return false; + } + + if (need_wa < 0) + pr_warn_once("ARM_SMCCC_ARCH_WORKAROUND_1 missing from firmware\n"); + + return (need_wa > 0); +} #endif #ifdef CONFIG_HARDEN_EL2_VECTORS @@ -712,8 +715,8 @@ const struct arm64_cpu_capabilities arm64_errata[] = { #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR { .capability = ARM64_HARDEN_BRANCH_PREDICTOR, - .cpu_enable = enable_smccc_arch_workaround_1, - ERRATA_MIDR_RANGE_LIST(arm64_bp_harden_smccc_cpus), + .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, + .matches = check_branch_predictor, }, #endif #ifdef CONFIG_HARDEN_EL2_VECTORS From patchwork Fri Oct 4 12:04:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174361 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E3D2813BD for ; Fri, 4 Oct 2019 12:11:31 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B24A32070B for ; Fri, 4 Oct 2019 12:11:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qbHeKbnM"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="EEDqPWRx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B24A32070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=fCvR9NYdLl9t7Kl5c3jCTl1InFD0v3o/NqweK7jdLEo=; b=qbHeKbnMwBsQtr BI3rPLNzhry5XjlgJYDxN8oI5aLDh/q0WI61bVqTaFOzEL8dzvTbHhe40YmlNX3c2ZKXW2+AtDBTz oueTVX/8lpjOE8URfkBLiKGjb6reZXD7lRvzVLQBoBITtwFlFsZ3C7fHHNTmPfUZLX/C4AxwtscC+ e8aHNlsmv9VSUk6NQAVUi7h1BjXrkXsjyQ1xL/Ukv51waA0NGn5XBn7ZmiovBPCqlaqCfD3u8a0gW eT2jOIuAfBhVebEPhl36LtZ//YgTmv0EVCiu6vQDUvxLCPxQY9+2ZgWkeIpt946fs5p2ce4Gm9Od7 JyeJoSt9iRQcypi68+Bw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMQi-0001ic-AK; Fri, 04 Oct 2019 12:11:28 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKK-0001vE-8Y for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:57 +0000 Received: by mail-wr1-x441.google.com with SMTP id w12so6883310wro.5 for ; Fri, 04 Oct 2019 05:04:52 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=pigH1Udp2BxTOSUepV8N3rBhXILI0lOVFvsXNcDQY2U=; b=EEDqPWRxnaoA7KUyzkQuFS+/eALvRvNc32hAPNRkOXUAKqfXeWyCSXKMfCxLLWJxUu YcgrAyFsx4IB5fpKnSxinfEeeXRCZsyZOUv42rKnCTFk+DDKLGRSOytXd7KtFmQCEhBN 1JXemJrtYT7gdPqaGpDuSUw2IoP74wmq/nkazqHIqUY/kAqiPSc4K9FPwr40eBlFGLjj tfy8N7dNl99t7wtdBWkDXZDXUzP8qy2K/KhQa09deSbhJdnhqiyauvPQtXFr8XMeTrm6 8qVMhj8vWEBOHfq1hPDkZ0TFO/G0ZqEJId4ZZMKMri0N1F8MrgMcTPQhIugCiuxQNjFM ScOg== 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:mime-version:content-transfer-encoding; bh=pigH1Udp2BxTOSUepV8N3rBhXILI0lOVFvsXNcDQY2U=; b=sj3E/mVDhmfoD82HWsj2V8ALurYDTastzQrOMLjm7OgJtRJxmJI7ZhmjwEv/hpkO9B PteynaBd3b55dFlVVx1DVayeON27fJlG/OqzQ4xa5MyL88zQxui4ANC2RYTNB2IiXqfi QhwTLnZj+/+MX2Z1dyOybu+HNJ05kj3TKXaq2GAkF5z4pXPaaTF9iPjs9hwamnJ4zei8 5EZLm1lsj6ypUKSOIlCEN++nW9WWYs4GXmZNAE5vbodlbsnkaHhxvI71Ds/sc3hoekyQ kEMcDlnz2UrGRFqym6J8p65OWPR4ru8x/m8BbhUvqcJjlkQnUpaOr8MD4dozHHRIrQHh XgzA== X-Gm-Message-State: APjAAAXqEOoijsM5NmEFYn64JOhgKImYlBA5MMxEZCe0AmFcOMY3Vbtg 2WpLH1BGFuvfiKDSo1tDwRvjH/r68IGPzbHE X-Google-Smtp-Source: APXvYqz3+jtLkp3r7t6Duw6fJtkqsGj6MNkTBttDKIogQ8HZPgbCpjmYEFhRTCjg3ULUziudX+pDPQ== X-Received: by 2002:a5d:548d:: with SMTP id h13mr880946wrv.215.1570190690607; Fri, 04 Oct 2019 05:04:50 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:49 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 11/16] arm64: Always enable spectre-v2 vulnerability detection Date: Fri, 4 Oct 2019 14:04:25 +0200 Message-Id: <20191004120430.11929-12-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050453_744820_07D5D39C X-CRM114-Status: GOOD ( 15.10 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:441 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Stefan Wahren , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Will Deacon , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jeremy Linton Ensure we are always able to detect whether or not the CPU is affected by Spectre-v2, so that we can later advertise this to userspace. Signed-off-by: Jeremy Linton Reviewed-by: Andre Przywara Reviewed-by: Catalin Marinas Tested-by: Stefan Wahren Signed-off-by: Will Deacon (cherry picked from commit 8c1e3d2bb44cbb998cb28ff9a18f105fee7f1eb3) Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/cpu_errata.c | 47 ++++---------------- 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index def847873d21..ae7d6761262f 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -87,7 +87,6 @@ cpu_enable_trap_ctr_access(const struct arm64_cpu_capabilities *__unused) atomic_t arm64_el2_vector_last_slot = ATOMIC_INIT(-1); -#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR #include #include @@ -225,11 +224,11 @@ static int detect_harden_bp_fw(void) ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1)) cb = qcom_link_stack_sanitization; - install_bp_hardening_cb(cb, smccc_start, smccc_end); + if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) + install_bp_hardening_cb(cb, smccc_start, smccc_end); return 1; } -#endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ #ifdef CONFIG_ARM64_SSBD DEFINE_PER_CPU_READ_MOSTLY(u64, arm64_ssbd_callback_required); @@ -478,39 +477,6 @@ has_cortex_a76_erratum_1463225(const struct arm64_cpu_capabilities *entry, .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ CAP_MIDR_RANGE_LIST(midr_list) -/* - * Generic helper for handling capabilties with multiple (match,enable) pairs - * of call backs, sharing the same capability bit. - * Iterate over each entry to see if at least one matches. - */ -static bool __maybe_unused -multi_entry_cap_matches(const struct arm64_cpu_capabilities *entry, int scope) -{ - const struct arm64_cpu_capabilities *caps; - - for (caps = entry->match_list; caps->matches; caps++) - if (caps->matches(caps, scope)) - return true; - - return false; -} - -/* - * Take appropriate action for all matching entries in the shared capability - * entry. - */ -static void __maybe_unused -multi_entry_cap_cpu_enable(const struct arm64_cpu_capabilities *entry) -{ - const struct arm64_cpu_capabilities *caps; - - for (caps = entry->match_list; caps->matches; caps++) - if (caps->matches(caps, SCOPE_LOCAL_CPU) && - caps->cpu_enable) - caps->cpu_enable(caps); -} - -#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR /* * List of CPUs that do not need any Spectre-v2 mitigation at all. */ @@ -542,6 +508,12 @@ check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) if (!need_wa) return false; + if (!IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) { + pr_warn_once("spectrev2 mitigation disabled by kernel configuration\n"); + __hardenbp_enab = false; + return false; + } + /* forced off */ if (__nospectre_v2) { pr_info_once("spectrev2 mitigation disabled by command line option\n"); @@ -553,7 +525,6 @@ check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) return (need_wa > 0); } -#endif #ifdef CONFIG_HARDEN_EL2_VECTORS @@ -712,13 +683,11 @@ const struct arm64_cpu_capabilities arm64_errata[] = { ERRATA_MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), }, #endif -#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR { .capability = ARM64_HARDEN_BRANCH_PREDICTOR, .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, .matches = check_branch_predictor, }, -#endif #ifdef CONFIG_HARDEN_EL2_VECTORS { .desc = "EL2 vector hardening", From patchwork Fri Oct 4 12:04:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174365 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5529F16B1 for ; Fri, 4 Oct 2019 12:12:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 261102070B for ; Fri, 4 Oct 2019 12:12:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Xd5HL9fv"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="iz5HSgnM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 261102070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=RfngJPUITcpt5pBhjDnvHtc6iwiAi1m+861k8800Qy0=; b=Xd5HL9fvis7DJo vLA+BjxZWFcv1ElHr/Zqn0QM8dRoOsbuWxj5axbol9rC8Ncfsq3zrUDQ3V8ttpVPTAR/LkmDjQGpZ nZYsflgiBxhpmDSEnz1/UFpccbdKrrw30koh8u+ILJS39Q1+OM9uwM019GLpwcIC6CIzHKYfD8kPs IyHXAqoVJUlmYoGPyokuMIU63QzNGWkDRcWA+mxx3RGmJotmfb9/FP16hCJwso4oobWXa7Q/IZOVH 0y0Suvbt1kNFe0JJcUp+RaYKuk1H3a6NvpeAY3nR8Q1R5A3PVLnT+2fi02NaSyxCB7yUOcJxZ/09v ypMMPw4d0Kkt/hZXT1Ig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMRH-0002EN-GD; Fri, 04 Oct 2019 12:12:03 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKL-0001vT-Qy for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:57 +0000 Received: by mail-wr1-x444.google.com with SMTP id r3so6879515wrj.6 for ; Fri, 04 Oct 2019 05:04:53 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=Ky21pTDoxlbEAaqi946F6fzctKA5frfPnRQOMtfqswU=; b=iz5HSgnMoVl0hcq1qAw5NuOZ20IIu+04urARIN+b9hxCNPqNT1L4QxSZS0Fc5ZJZ3y 33dOpBUzNOVXrcY+SomeaR+Kcqz1VCxpI83ynvGJ++KUoVNxB/cS9+LHMUdl0pG6lQfN ou0QIxa80XntdKeDUoI7CYQZrBTFZax5RYB9xTm7/7hnpZ181REnfuYlvkGtHQy381jz eQi5909ak/cHXY2swk66Ka6pOIrikRwiNpRr/xl2VMQa5vfyx2qPBmDvWfNCdAwmEoBo m3GSj63G5D/l4+vRTVraeNwPK6I7pmwTXJff6ivd3c8BBfdYckGj04SVig3HuV7Mgkb+ MTYQ== 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:mime-version:content-transfer-encoding; bh=Ky21pTDoxlbEAaqi946F6fzctKA5frfPnRQOMtfqswU=; b=ftWd9ARbTeEeGw3nkOhRiISYWSnTnBewy9KyD1Oph3CoG8GI+dUWyqNpIJ1aec9ZcO OPfHwvemnxMYzm3QUZvIo01V6xLHxcvMJ2x/t8/PlN549GCNaEzp2D2ahBRUb+QktCgp BQubnWGVFQFYYSXYlpdpJhHcT8ld9epYgrowLuO4WeA4npQFhBrwW4gv0j32sIMZDnvl er4gmHDn8Vn7pOBAYXadacP8UANeris3XC41coy8l4/eTq8X6yRD8YoIKvqrFw222L1L dnzwZEDLU/kOkCWs3uBESKZqgvU+N/K8/fEevsmYSKebOObJ195y+UfsRGjq/BwyTpFw WCQg== X-Gm-Message-State: APjAAAVsh1o54usHg5T+3sug8CJjZqNVTOOvGgTFnG2gGpyrLygZBXBE BwbAIUmmq25Z7OZYOQXilPGfGW31QRvr/iUP X-Google-Smtp-Source: APXvYqztGnMmOSsm6tQdfJOJ6afcTVAfTZ9gy+9lx970WhR/rhcQlRKuLbxYi3CFSpSrT3hofTIV5w== X-Received: by 2002:adf:f34c:: with SMTP id e12mr11493381wrp.320.1570190692177; Fri, 04 Oct 2019 05:04:52 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:51 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 12/16] arm64: Always enable ssb vulnerability detection Date: Fri, 4 Oct 2019 14:04:26 +0200 Message-Id: <20191004120430.11929-13-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050453_965755_FB14D497 X-CRM114-Status: GOOD ( 13.93 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:444 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Stefan Wahren , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Will Deacon , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jeremy Linton Ensure we are always able to detect whether or not the CPU is affected by SSB, so that we can later advertise this to userspace. Signed-off-by: Jeremy Linton Reviewed-by: Andre Przywara Reviewed-by: Catalin Marinas Tested-by: Stefan Wahren [will: Use IS_ENABLED instead of #ifdef] Signed-off-by: Will Deacon (cherry picked from commit d42281b6e49510f078ace15a8ea10f71e6262581) Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/cpufeature.h | 4 ---- arch/arm64/kernel/cpu_errata.c | 9 +++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 510f687d269a..dda6e5056810 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -525,11 +525,7 @@ static inline int arm64_get_ssbd_state(void) #endif } -#ifdef CONFIG_ARM64_SSBD void arm64_set_ssbd_mitigation(bool state); -#else -static inline void arm64_set_ssbd_mitigation(bool state) {} -#endif #endif /* __ASSEMBLY__ */ diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index ae7d6761262f..78ce2e27396d 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -230,7 +230,6 @@ static int detect_harden_bp_fw(void) return 1; } -#ifdef CONFIG_ARM64_SSBD DEFINE_PER_CPU_READ_MOSTLY(u64, arm64_ssbd_callback_required); int ssbd_state __read_mostly = ARM64_SSBD_KERNEL; @@ -303,6 +302,11 @@ void __init arm64_enable_wa2_handling(struct alt_instr *alt, void arm64_set_ssbd_mitigation(bool state) { + if (!IS_ENABLED(CONFIG_ARM64_SSBD)) { + pr_info_once("SSBD disabled by kernel configuration\n"); + return; + } + if (this_cpu_has_cap(ARM64_SSBS)) { if (state) asm volatile(SET_PSTATE_SSBS(0)); @@ -422,7 +426,6 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, return required; } -#endif /* CONFIG_ARM64_SSBD */ #ifdef CONFIG_ARM64_ERRATUM_1463225 DEFINE_PER_CPU(int, __in_cortex_a76_erratum_1463225_wa); @@ -695,14 +698,12 @@ const struct arm64_cpu_capabilities arm64_errata[] = { ERRATA_MIDR_RANGE_LIST(arm64_harden_el2_vectors), }, #endif -#ifdef CONFIG_ARM64_SSBD { .desc = "Speculative Store Bypass Disable", .capability = ARM64_SSBD, .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, .matches = has_ssbd_mitigation, }, -#endif #ifdef CONFIG_ARM64_ERRATUM_1463225 { .desc = "ARM erratum 1463225", From patchwork Fri Oct 4 12:04:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174367 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B91D816B1 for ; Fri, 4 Oct 2019 12:12:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7FA8521D71 for ; Fri, 4 Oct 2019 12:12:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="K7YnAeqe"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="x3r0rNAB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7FA8521D71 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=kdyHhPMmwZ3JXw4A0aTJiNvT14/iIXmJoZUDVr38ssk=; b=K7YnAeqe+dc758 PKCUBB1EKJr3mMqTdWbIzEArzD3lg3RL2y9k5CIwcn0+ba46qOp87wRlFvHBcewlo+1+FvBi0dlGb AHCt45Gs9C5gHPvuEU5KYlNS6veTxYCTTKafMthIGqKRqoWwSnaPrruk36p0kTxE0eosFQRqL7qq6 W4ARka1H61QUkf4m3d2fWToQs69v79xl5IF1IfGQo8AgCIoVrosDpz5BlgcXkkoV0N1k7z+fjzfPh UShpT+e5W5Za+R3z3ZxgNL6BV9EHbfpEHdxDRer/NyVrSSfSPFc1Z7VPVdg8vjkLHIuPEHy9kZQ8g GZy+orY8iXhXfMmp4dNQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMRX-0002V3-8a; Fri, 04 Oct 2019 12:12:19 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKN-0001wd-4I for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:04:58 +0000 Received: by mail-wr1-x444.google.com with SMTP id j11so1080023wrp.1 for ; Fri, 04 Oct 2019 05:04:54 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=Z3yfkGPPDxwuc3Iyqi5NnIEB57DgeJDhHrId4yOa5Ag=; b=x3r0rNABzw8FQK5n8Kg+8Ti1kcRm7M/M3Ue1e1GdtCwV1oMhs7d+lvW+odW9wt5EtD MMAItiQAHQnNM4IRkKd3mYY/PSGVfmQ6bQe9fwHLTP/tjpDyBljc6rDWCljXw491cF/3 YgB2emtKQjepGdJbE+2p9UEC8k5jWKlJaV3jf4Vxf1Ytx4rDAUxYHUY8LGIEvvxBPelS EnyeFGswdtYbRmdt54PJQiTm68/eAHk1wnVC2EkNNh5/4XqNt/H6u3p6kRFUaeolaAEb XTCfj06bdbSHhfai43LWFGcxlj4MlQVp2TbQ6gTh/kUtqi96yPnAW8dmgcY301BuqeUS K9Kw== 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:mime-version:content-transfer-encoding; bh=Z3yfkGPPDxwuc3Iyqi5NnIEB57DgeJDhHrId4yOa5Ag=; b=jNrB4NGPK5Nw3ZNaTvxNVwtf7lTRpeQNXn9JJX2IxUlUJGABUvfkHncwfn/pz0G9ZX 5gX9DVhmauJYCFkPz5HWWL5USGkW/2WK4SRAKCpSphmtvYaKg+ljZCz2beY/RCEAGL1p XqwbAr9FpsYeawe/ljAgGLjynnksDQIogkDTvNP26VV9o0/9v4I+Z0QdZO49hQ5J7rR+ i4jCi/UlwIhjXUbuEkmAn962bBeZ7Ov+kpJkia18JHpwx+KDHizyF2EUOc9hptY14h3x 60fZroJyj3TIc2h41bZFKwBiIy9U4C/uHdFhRYJR3MidizCux9mdSMtYGW276LguRhSE 5n8A== X-Gm-Message-State: APjAAAXouiplQhj72T9hDNnxwYVEke/MoqJaE3XVffufe+bfFnl9fSXe HqYB9MB6UNmSEgSdKwe91rqz7dB5B/Aq6jEL X-Google-Smtp-Source: APXvYqzHG904BjtgZR93K5y9l9xIJdFEOtQV850OUN+PVpYpOemUrM/9YN1w3CNj7qbhPhts9NfLPg== X-Received: by 2002:adf:9d88:: with SMTP id p8mr10934277wre.391.1570190693434; Fri, 04 Oct 2019 05:04:53 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:52 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 13/16] arm64: add sysfs vulnerability show for spectre-v2 Date: Fri, 4 Oct 2019 14:04:27 +0200 Message-Id: <20191004120430.11929-14-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050455_242918_97D53AAC X-CRM114-Status: GOOD ( 15.42 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:444 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Stefan Wahren , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Will Deacon , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jeremy Linton Track whether all the cores in the machine are vulnerable to Spectre-v2, and whether all the vulnerable cores have been mitigated. We then expose this information to userspace via sysfs. Signed-off-by: Jeremy Linton Reviewed-by: Andre Przywara Reviewed-by: Catalin Marinas Tested-by: Stefan Wahren Signed-off-by: Will Deacon (cherry picked from commit d2532e27b5638bb2e2dd52b80b7ea2ec65135377) Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/cpu_errata.c | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 78ce2e27396d..6c8e8a5bfabf 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -480,6 +480,10 @@ has_cortex_a76_erratum_1463225(const struct arm64_cpu_capabilities *entry, .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ CAP_MIDR_RANGE_LIST(midr_list) +/* Track overall mitigation state. We are only mitigated if all cores are ok */ +static bool __hardenbp_enab = true; +static bool __spectrev2_safe = true; + /* * List of CPUs that do not need any Spectre-v2 mitigation at all. */ @@ -490,6 +494,10 @@ static const struct midr_range spectre_v2_safe_list[] = { { /* sentinel */ } }; +/* + * Track overall bp hardening for all heterogeneous cores in the machine. + * We are only considered "safe" if all booted cores are known safe. + */ static bool __maybe_unused check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) { @@ -511,6 +519,8 @@ check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) if (!need_wa) return false; + __spectrev2_safe = false; + if (!IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) { pr_warn_once("spectrev2 mitigation disabled by kernel configuration\n"); __hardenbp_enab = false; @@ -520,11 +530,14 @@ check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) /* forced off */ if (__nospectre_v2) { pr_info_once("spectrev2 mitigation disabled by command line option\n"); + __hardenbp_enab = false; return false; } - if (need_wa < 0) + if (need_wa < 0) { pr_warn_once("ARM_SMCCC_ARCH_WORKAROUND_1 missing from firmware\n"); + __hardenbp_enab = false; + } return (need_wa > 0); } @@ -721,3 +734,15 @@ ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, { return sprintf(buf, "Mitigation: __user pointer sanitization\n"); } + +ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, + char *buf) +{ + if (__spectrev2_safe) + return sprintf(buf, "Not affected\n"); + + if (__hardenbp_enab) + return sprintf(buf, "Mitigation: Branch predictor hardening\n"); + + return sprintf(buf, "Vulnerable\n"); +} From patchwork Fri Oct 4 12:04:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174371 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F4A216B1 for ; Fri, 4 Oct 2019 12:12:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 39032215EA for ; Fri, 4 Oct 2019 12:12:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Me8jokRx"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DwRJpBng" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39032215EA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=kzjs9mOyqVmXkgjYTqfSA0ImtGkQxgn9ZXMdIvzdRx8=; b=Me8jokRxo+Uodg pFoIszkiqb6VvZK+xuMAIKBiHQDmcnBIu09reEuVKSgmPV+fpZiRXYTXo5ZLRyn++NMQWfw7bNcUL 606unHC2TfyjrDl3XsID5mUdXuR1nvCHg9RMYnAyaxdder3OohPNI+dSF4jYZ3OhD3mRdApuJQVgU 5K6rU16LptOyrVm1CpR7oHdoQScXSiTaZveK2+SP8FaeKijsCQMUXok17YSpisVZGs3HlpTfAEWDH 97+cW0NUOUl0PIJU/EjUBPTSBZJBfrpVl7oN+w7yCbFpc/yYKRZ8KMlqbAkBELlmVLP3B4/m6CzrU WW0206hLBq2zW4Ulimig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMRz-0002vY-EX; Fri, 04 Oct 2019 12:12:47 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKO-0001xW-PH for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:05:00 +0000 Received: by mail-wm1-x343.google.com with SMTP id r19so5556476wmh.2 for ; Fri, 04 Oct 2019 05:04:56 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=R4I/ik/BVtoA0l1EVkoqrO4/pV5oBJPxNuRokuQO4Z4=; b=DwRJpBngnA6tfnZfQeF3Rg/B02OblDywvru5+/yol9pmLHYC8Jga0nxFR1X5AoB9Fs +aMgRT4PcpG7JGC1sT221+a06ro1qb/JfpVdNBPbIOfFyt4oYr8KNzXRJKsH22ZjJyoM mMaxiqO9pVUdSsuCKcI2di/++DWwBW/MLpoe9U1+rpB55lBl3H3PVeRWryCDdmkuS9/b hbP+cswWNm1oQTRAIvwA+j89iUqGic72E4qHXDfFdOr9PqPYqHbnARVeoZ5Cm/3m0R3m iooDLRhA9agR6XjS+H19si6QUP5NGJ95vJ2kCInVBf9xAXp9P+N/63PTB8oyr1wIASWh eYtA== 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:mime-version:content-transfer-encoding; bh=R4I/ik/BVtoA0l1EVkoqrO4/pV5oBJPxNuRokuQO4Z4=; b=sfZb22ep6zxoswAaixEbzsMd7A+0OoIFdrLtV5Gwg+UoJ0zxBW/mw4JIhPc2SwXlbg EfGrb/m0tCafQjxHbOM7JS3R4lQBpcBiSKzEVIjwM0+L9YG1Tg7blUhAu66v92xNKVC5 p4KMHaQk08HUcV3mhD7xoTVHHrdhFcxbvD5mJg13eJPM8CzirMjBuFcRiSN6VBRrbVsC TT1lzB3EAjvWI3FK3/1lyipUBv8AfkIjIcY5xLz1jcdb2h1JoZV4uABdCcnJ69vhRdpL GNYB/s2mElcTEm+ocILfqc58sZAi9EVW53p9ohIOBdLorT/tGjmJQfitS1M+9MKyRhpS 2wHA== X-Gm-Message-State: APjAAAW5F2CyGp0cHUvF6DB5OZmU5YM7p1hEtKcZEGGQdsnYTRbrjus2 qWv0SY5WyhoGoOi08wKJ5IkGD1SmRhodSRYc X-Google-Smtp-Source: APXvYqwb+t+Dyw/NtD0AE3aAc0s0HBIWgN8vz/f5OP7uz0MdDVLw1n8FMgsOCl1BmYMMzhcbKdqqiw== X-Received: by 2002:a1c:7c15:: with SMTP id x21mr9851207wmc.36.1570190694928; Fri, 04 Oct 2019 05:04:54 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:54 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 14/16] arm64: add sysfs vulnerability show for speculative store bypass Date: Fri, 4 Oct 2019 14:04:28 +0200 Message-Id: <20191004120430.11929-15-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050456_895581_5E64FF12 X-CRM114-Status: GOOD ( 14.97 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:343 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Stefan Wahren , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Will Deacon , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jeremy Linton Return status based on ssbd_state and __ssb_safe. If the mitigation is disabled, or the firmware isn't responding then return the expected machine state based on a whitelist of known good cores. Given a heterogeneous machine, the overall machine vulnerability defaults to safe but is reset to unsafe when we miss the whitelist and the firmware doesn't explicitly tell us the core is safe. In order to make that work we delay transitioning to vulnerable until we know the firmware isn't responding to avoid a case where we miss the whitelist, but the firmware goes ahead and reports the core is not vulnerable. If all the cores in the machine have SSBS, then __ssb_safe will remain true. Tested-by: Stefan Wahren Signed-off-by: Jeremy Linton Signed-off-by: Will Deacon --- arch/arm64/kernel/cpu_errata.c | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 6c8e8a5bfabf..534111eab864 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -233,6 +233,7 @@ static int detect_harden_bp_fw(void) DEFINE_PER_CPU_READ_MOSTLY(u64, arm64_ssbd_callback_required); int ssbd_state __read_mostly = ARM64_SSBD_KERNEL; +static bool __ssb_safe = true; static const struct ssbd_options { const char *str; @@ -336,6 +337,7 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, struct arm_smccc_res res; bool required = true; s32 val; + bool this_cpu_safe = false; WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); @@ -344,8 +346,14 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, goto out_printmsg; } + /* delay setting __ssb_safe until we get a firmware response */ + if (is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list)) + this_cpu_safe = true; + if (psci_ops.smccc_version == SMCCC_VERSION_1_0) { ssbd_state = ARM64_SSBD_UNKNOWN; + if (!this_cpu_safe) + __ssb_safe = false; return false; } @@ -362,6 +370,8 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, default: ssbd_state = ARM64_SSBD_UNKNOWN; + if (!this_cpu_safe) + __ssb_safe = false; return false; } @@ -370,14 +380,18 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, switch (val) { case SMCCC_RET_NOT_SUPPORTED: ssbd_state = ARM64_SSBD_UNKNOWN; + if (!this_cpu_safe) + __ssb_safe = false; return false; + /* machines with mixed mitigation requirements must not return this */ case SMCCC_RET_NOT_REQUIRED: pr_info_once("%s mitigation not required\n", entry->desc); ssbd_state = ARM64_SSBD_MITIGATED; return false; case SMCCC_RET_SUCCESS: + __ssb_safe = false; required = true; break; @@ -387,6 +401,8 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, default: WARN_ON(1); + if (!this_cpu_safe) + __ssb_safe = false; return false; } @@ -427,6 +443,14 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, return required; } +/* known invulnerable cores */ +static const struct midr_range arm64_ssb_cpus[] = { + MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), + MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), + MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), + {}, +}; + #ifdef CONFIG_ARM64_ERRATUM_1463225 DEFINE_PER_CPU(int, __in_cortex_a76_erratum_1463225_wa); @@ -716,6 +740,7 @@ const struct arm64_cpu_capabilities arm64_errata[] = { .capability = ARM64_SSBD, .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, .matches = has_ssbd_mitigation, + .midr_range_list = arm64_ssb_cpus, }, #ifdef CONFIG_ARM64_ERRATUM_1463225 { @@ -746,3 +771,20 @@ ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, return sprintf(buf, "Vulnerable\n"); } + +ssize_t cpu_show_spec_store_bypass(struct device *dev, + struct device_attribute *attr, char *buf) +{ + if (__ssb_safe) + return sprintf(buf, "Not affected\n"); + + switch (ssbd_state) { + case ARM64_SSBD_KERNEL: + case ARM64_SSBD_FORCE_ENABLE: + if (IS_ENABLED(CONFIG_ARM64_SSBD)) + return sprintf(buf, + "Mitigation: Speculative Store Bypass disabled via prctl\n"); + } + + return sprintf(buf, "Vulnerable\n"); +} From patchwork Fri Oct 4 12:04:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AAD8913BD for ; Fri, 4 Oct 2019 12:12:32 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 853E8215EA for ; Fri, 4 Oct 2019 12:12:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LYKMx5JQ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="us9gGLWD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 853E8215EA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=cki2qqHi5FphXAspZrmY3IfYdL/Ts9BOTLfJIOL6po0=; b=LYKMx5JQwt3/oq JGQJ5aP0Bspcw9uFqVLT+7amzZ0hbWe1pLO6pvwQBhSmsBSU1qKTrGQtjSZLhRjrPZjQOKfds0u6t azDqmarDPxBm85RWnq/itpFZD3Lkz6I6mIWWltmSkvp30vSQTMFU8dgixw1M+4CUBsmAxBOtt2No2 cWLFjJ8UoqCQLPXlwIDbzxqUuQoMt8FhCI7WDKfL4XIHdxZUat+XfbADc97oLZHr1KA+4qvSMvLO4 YxhWuAg7OFxeDHyNrKgDIzm3K5497i7TqJj/bHveo1LN6QhMx/SpC9J2NBbeVwWNKwL1dF6bjUIbe PtjOCkyeLQHl5qmItRlw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMRh-0002g6-Ur; Fri, 04 Oct 2019 12:12:30 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKQ-0001yY-Pe for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:05:01 +0000 Received: by mail-wm1-x344.google.com with SMTP id v17so5580932wml.4 for ; Fri, 04 Oct 2019 05:04:57 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=6vdcJpY6kjs31UUpmKpTlnwItStrMhbxBjdYfHyk8nk=; b=us9gGLWDgsVjLc86ifXC6p5QEkZB5ybWEbH7Uw6sj84f0BRZ6uyEY7uoHm9eqSHJci Hrx09iSf4ewXadLEfTVPuHzXCG1HRO/6A1Iyo2VwgLudG9lIZRbtin93MXDggM/YqpLJ JrOFbniF3mJ4vRf1ZHHquUJMNOQ+Ei1EPub/mB1zrORiioLAJjkGxG44xRk4A0OPX8Q+ fK/2L9KIlSteIkkiiziFOhU9A0ayJ8WtMr+ODvHTDoTrIoM0ApRKq0DmvX0qAqmefkL0 0mvZe/NZMZic3tvqKZY1+VkDZyWgNGff4UTXM6rsUpQQS2Iru04wPl2flElR732BXJxK 0xQg== 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:mime-version:content-transfer-encoding; bh=6vdcJpY6kjs31UUpmKpTlnwItStrMhbxBjdYfHyk8nk=; b=RK/yzSmns0OnJldunQoIFnWJtqxuaqeZqxjvU8IjdkPNwfv10g4FGN0yAPV39XH8hu Og7czcOMqLTKPZALiUX8k3U6PQNzP078g6wOUALn0WdXbV2zn7/CLYoO1D5W6iRyOxzP tMuyzmehhX0sSdmDw5iXBwXMe9YfzhUmB+xPqyKZbuOAa+wyVvYP1BVU2gfBwp5fziMv zSpiGwzOgjzpJLlA1s82LX5MMUi85uF9uv8g+SSZoYWvcmWAzZOeSlcPAiT1HhKgNO0F +7V0E1MmcikMB9MmYsDgqFvPJ4cv5i6pWxwudvhxz138zL9DKzv4amSxR6TH/fNSP99t tTBA== X-Gm-Message-State: APjAAAUywpfPcwVdkrSQObSK27R32HxksIZ9mzHKq/HCqGEFrQgEJGu+ bY6fy1dheXVNwVKMf4R8nlpcUUj6YG2eR5+J X-Google-Smtp-Source: APXvYqwkrnLxx5zZyBXBMKfgOgOmHouSUgnzYn21AmTYJmDZWMMT3CaITGcN1kSQcdiPKMtEs3IM7w== X-Received: by 2002:a1c:1c7:: with SMTP id 190mr9898347wmb.23.1570190696256; Fri, 04 Oct 2019 05:04:56 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:55 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 15/16] arm64: ssbs: Don't treat CPUs with SSBS as unaffected by SSB Date: Fri, 4 Oct 2019 14:04:29 +0200 Message-Id: <20191004120430.11929-16-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050458_924895_CDA78A3A X-CRM114-Status: GOOD ( 11.25 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:344 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Suzuki K Poulose , Catalin Marinas , Ard Biesheuvel , Will Deacon , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Will Deacon SSBS provides a relatively cheap mitigation for SSB, but it is still a mitigation and its presence does not indicate that the CPU is unaffected by the vulnerability. Tweak the mitigation logic so that we report the correct string in sysfs. Signed-off-by: Will Deacon (cherry picked from commit eb337cdfcd5dd3b10522c2f34140a73a4c285c30) Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/cpu_errata.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 534111eab864..a9ad932160cc 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -341,7 +341,13 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); + /* delay setting __ssb_safe until we get a firmware response */ + if (is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list)) + this_cpu_safe = true; + if (this_cpu_has_cap(ARM64_SSBS)) { + if (!this_cpu_safe) + __ssb_safe = false; required = false; goto out_printmsg; } From patchwork Fri Oct 4 12:04:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11174375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9AFE51902 for ; Fri, 4 Oct 2019 12:13:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6DE6D215EA for ; Fri, 4 Oct 2019 12:13:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PFHHD7dV"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="b6HmhLqE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6DE6D215EA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=Q+e3c0HUpPNMUMnupJ28n4HyiltSt1RmlHJsq74TLx4=; b=PFHHD7dVKVFHm/ +oUPTzmAIHPUJ8/OlA9ZA7GFK69BMfI9A6ji+kfttW1VW6e3nEoXMDUTcJuxB/DG/4zAfGorkumzc H75CyDkwMnrpSvFbbhSKW7ciYU7J1JnjBljVyEB6EMz2Qv55BJUXxEri7c2ARSb2g56HZEP28lZDk z+i8xPSgqc4xK6sf9Co0o5+aCmQ12OgVSF7/H8DW16i8HsNPpM5lGcTMueoeE+x/uvyFpBezGhHAQ zU5MCapI9eivoxx+3weP8v5kPOPebmaOjpO4fFaRzkX+298rtSQ6dM5qXa67a3nAFAxpa034BGuPa qMlAr9QGmGXg0iv8XSMg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMSI-0003Ba-Vm; Fri, 04 Oct 2019 12:13:07 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGMKR-0001zR-A0 for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2019 12:05:01 +0000 Received: by mail-wr1-x441.google.com with SMTP id o18so6815294wrv.13 for ; Fri, 04 Oct 2019 05:04:59 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=jyWUdEZangMl23Y/z3me7Cr0MiFTlQrstZmKMhID7pk=; b=b6HmhLqE8uHgPW6jON0IKeGRLW1JnxE7uzXTd56vV2r9hNXEN2nPAk9xU6t3FnU/26 s6utKUdpAmBngrtJtuNqg9BT5Ew5nAbtZyxtr00b9BZUaOJ5FjDmXOi/NhBfvBe8v21s 6QQOJLQjAYKtLzCF6waIbv5cv9YjLVY3wELravvDMD54fcSTdXFnJI8wqqqT+eNFs8bJ WfvbPoG2BcnPrXGbyB+TPVovkXnFeVtlI7BROXTGhcSE0RWZ/SxCzIV2q+tOZNTTRCoX dB0CSRAK4HseRvQEVaxnsl5gx63QuS91N3GrXQNy8wpCGHNS/FtcL69wPGF6nYvyeRVX bS2Q== 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:mime-version:content-transfer-encoding; bh=jyWUdEZangMl23Y/z3me7Cr0MiFTlQrstZmKMhID7pk=; b=CBAzROyR4ZBB9PwHXiPZ8xW9pSTl/+AgHluuSmYDSAdNQql2stmOxkMaDa8zRJB29b lnNzopsden1HBTOYe3Ul5/MU8i4/GtVS+8Cg184uI1l8chqWT0cU/ccEZyZeTVtpuIrd uUQ70tJFyynhNLv7DeHLBrZa2W2CCbnIJgJxCNdM43E0cHOjq5hlJyLhzBs2mhZbflR2 aBWFS2Kdm5zQFQgqSPAGOw8adYQ4UQszmWsClQbcZwrpHFa4KLTzzx8OZVJ0cKQauyPH xBBLOsJtgHRC7/3MZwnPGRjqFyCshT8Fsiuz0JCkiPHVs0qH7Pu6nbw3r1XVYzcCUFzU jAsg== X-Gm-Message-State: APjAAAXrX9e/Mk7jc1itviWQFPXPbRmL/qxyV9dxWNIDPE01Rsg4SJ52 rbOmwLRI7AD2WKijFPquQe+Khuxg7+g2yBeP X-Google-Smtp-Source: APXvYqwmuV0mx2+B0zE37LPywhrk2AGREP1jeZdL8iymjsa9QhmU72CBjnEPBedm5vdsfPswjJczqw== X-Received: by 2002:a5d:6a8b:: with SMTP id s11mr11294333wru.167.1570190697534; Fri, 04 Oct 2019 05:04:57 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:b51e:3d9d:ec16:def5]) by smtp.gmail.com with ESMTPSA id f8sm5019628wmb.37.2019.10.04.05.04.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 05:04:56 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 16/16] arm64: Force SSBS on context switch Date: Fri, 4 Oct 2019 14:04:30 +0200 Message-Id: <20191004120430.11929-17-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004120430.11929-1-ard.biesheuvel@linaro.org> References: <20191004120430.11929-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191004_050459_394275_3B461009 X-CRM114-Status: GOOD ( 15.02 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:441 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Suzuki K Poulose , Marc Zyngier , Catalin Marinas , Ard Biesheuvel , Jeremy Linton , Andre Przywara , Marc Zyngier , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Marc Zyngier On a CPU that doesn't support SSBS, PSTATE[12] is RES0. In a system where only some of the CPUs implement SSBS, we end-up losing track of the SSBS bit across task migration. To address this issue, let's force the SSBS bit on context switch. Fixes: 8f04e8e6e29c ("arm64: ssbd: Add support for PSTATE.SSBS rather than trapping to EL3") Signed-off-by: Marc Zyngier [will: inverted logic and added comments] Signed-off-by: Will Deacon (cherry picked from commit cbdf8a189a66001c36007bf0f5c975d0376c5c3a) Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/processor.h | 14 ++++++++-- arch/arm64/kernel/process.c | 29 +++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index ad208bd402f7..773ea8e0e442 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -177,6 +177,16 @@ static inline void start_thread_common(struct pt_regs *regs, unsigned long pc) regs->pc = pc; } +static inline void set_ssbs_bit(struct pt_regs *regs) +{ + regs->pstate |= PSR_SSBS_BIT; +} + +static inline void set_compat_ssbs_bit(struct pt_regs *regs) +{ + regs->pstate |= PSR_AA32_SSBS_BIT; +} + static inline void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp) { @@ -184,7 +194,7 @@ static inline void start_thread(struct pt_regs *regs, unsigned long pc, regs->pstate = PSR_MODE_EL0t; if (arm64_get_ssbd_state() != ARM64_SSBD_FORCE_ENABLE) - regs->pstate |= PSR_SSBS_BIT; + set_ssbs_bit(regs); regs->sp = sp; } @@ -203,7 +213,7 @@ static inline void compat_start_thread(struct pt_regs *regs, unsigned long pc, #endif if (arm64_get_ssbd_state() != ARM64_SSBD_FORCE_ENABLE) - regs->pstate |= PSR_AA32_SSBS_BIT; + set_compat_ssbs_bit(regs); regs->compat_sp = sp; } diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index ce99c58cd1f1..bc2226608e13 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -360,7 +360,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start, childregs->pstate |= PSR_UAO_BIT; if (arm64_get_ssbd_state() == ARM64_SSBD_FORCE_DISABLE) - childregs->pstate |= PSR_SSBS_BIT; + set_ssbs_bit(childregs); p->thread.cpu_context.x19 = stack_start; p->thread.cpu_context.x20 = stk_sz; @@ -401,6 +401,32 @@ void uao_thread_switch(struct task_struct *next) } } +/* + * Force SSBS state on context-switch, since it may be lost after migrating + * from a CPU which treats the bit as RES0 in a heterogeneous system. + */ +static void ssbs_thread_switch(struct task_struct *next) +{ + struct pt_regs *regs = task_pt_regs(next); + + /* + * Nothing to do for kernel threads, but 'regs' may be junk + * (e.g. idle task) so check the flags and bail early. + */ + if (unlikely(next->flags & PF_KTHREAD)) + return; + + /* If the mitigation is enabled, then we leave SSBS clear. */ + if ((arm64_get_ssbd_state() == ARM64_SSBD_FORCE_ENABLE) || + test_tsk_thread_flag(next, TIF_SSBD)) + return; + + if (compat_user_mode(regs)) + set_compat_ssbs_bit(regs); + else if (user_mode(regs)) + set_ssbs_bit(regs); +} + /* * We store our current task in sp_el0, which is clobbered by userspace. Keep a * shadow copy so that we can restore this upon entry from userspace. @@ -429,6 +455,7 @@ __notrace_funcgraph struct task_struct *__switch_to(struct task_struct *prev, contextidr_thread_switch(next); entry_task_switch(next); uao_thread_switch(next); + ssbs_thread_switch(next); /* * Complete any pending TLB or cache maintenance on this CPU in case