From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEA49C433E1 for ; Thu, 13 Aug 2020 18:01:16 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 9C26220774 for ; Thu, 13 Aug 2020 18:01:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VyNV4W7P"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="A/rtatHY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C26220774 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To:Subject:To:From: Date:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SzaceLyNDXasAp6HQ6L2HHRp+BknDe0tZ/FpBWSCYMA=; b=VyNV4W7PRid4DQugYYbJG14Yy x4Y5BhQmUoB28ucKQdKgh6elRplIJJvk2+yfbRovklfMd2j47Iq2hu/rvOruBwfYX39vrnqwSsgNu XxygSwz+ks3HgWNjsNq5E191Et2irqRkK2/O/J23YpmsV1Wyh7fISpEc7sYcYsxTbfseoxaqdO8IU G70TjsqI5MyQ7pMRHhOfjRGbUO8s5vNofHnsNJRYQe+xH2pxSoG+CSeK64B8yGlBnLBRKVVw0SvOT dkl9gnsuGNRL1ZtbUlVv/Dd5VXvGIg4AdlDOyqZzJa4bAHepEKZIZtCo8sWtLx4Yn4PFcoARhMCj8 80AOH5DIg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k6HVq-00080n-F8; Thu, 13 Aug 2020 17:59:38 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k6HVm-00080J-E5 for linux-arm-kernel@lists.infradead.org; Thu, 13 Aug 2020 17:59:35 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6DF132078D; Thu, 13 Aug 2020 17:59:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597341573; bh=CFADI5K3ybqlcI8c32cfvSt3eSFxRcdgnW/IUHOEoBQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=A/rtatHY8zbxQCJNEvrAKDbUf6pObl+Ye84cXF2q7CRd0h6vC7MfxK+hMRgde2x7W UxkKBq/1LN6WZ8eMxAG6QEd3N9jesHDIdJlY4sHd5+WVLvZdhE5S0nS3yR96dppNXu gNNsCaG81ubAsaYs5P9khhRJ8Q2sez93yO/ydg4I= Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1k6HVj-001yy9-UI; Thu, 13 Aug 2020 18:59:32 +0100 MIME-Version: 1.0 Date: Thu, 13 Aug 2020 18:59:31 +0100 From: Marc Zyngier To: Sai Prakash Ranjan Subject: Re: [PATCH] arm64: Add KRYO4XX gold CPU core to spectre-v2 safe list In-Reply-To: <368280026c8af5b5a58a52c1e19cfae9@codeaurora.org> References: <20200813081834.13576-1-saiprakash.ranjan@codeaurora.org> <20200813090324.GB9829@willie-the-truck> <89f0f41514e547533c3fa66364e5a2ac@codeaurora.org> <20200813094041.GA9894@willie-the-truck> <368280026c8af5b5a58a52c1e19cfae9@codeaurora.org> User-Agent: Roundcube Webmail/1.4.7 Message-ID: <8ffd22d5926aedda0c9fa6ea429fd84e@kernel.org> X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: saiprakash.ranjan@codeaurora.org, will@kernel.org, catalin.marinas@arm.com, andre.przywara@arm.com, mark.rutland@arm.com, suzuki.poulose@arm.com, swboyd@chromium.org, dianders@chromium.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200813_135934_670627_4C2A383A X-CRM114-Status: GOOD ( 41.12 ) 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 , linux-arm-msm@vger.kernel.org, Douglas Anderson , Stephen Boyd , linux-arm-kernel@lists.infradead.org, Andre Przywara , Will Deacon , linux-kernel@vger.kernel.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2020-08-13 13:33, Sai Prakash Ranjan wrote: > On 2020-08-13 16:09, Marc Zyngier wrote: >> On 2020-08-13 10:40, Will Deacon wrote: >>> On Thu, Aug 13, 2020 at 02:49:37PM +0530, Sai Prakash Ranjan wrote: >>>> On 2020-08-13 14:33, Will Deacon wrote: >>>> > On Thu, Aug 13, 2020 at 01:48:34PM +0530, Sai Prakash Ranjan wrote: >>>> > > KRYO4XX gold/big CPU cores are based on Cortex-A76 which has CSV2 >>>> > > bits set and are spectre-v2 safe. But on big.LITTLE systems where >>>> > > they are coupled with other CPU cores such as the KRYO4XX silver >>>> > > based on Cortex-A55 which are spectre-v2 safe but do not have CSV2 >>>> > > bits set, the system wide safe value will be set to the lowest value >>>> > > of CSV2 bits as per FTR_LOWER_SAFE defined for CSV2 bits of register >>>> > > ID_AA64PFR0_EL1. >>>> > > >>>> > > This is a problem when booting a guest kernel on gold CPU cores >>>> > > where it will incorrectly report ARM_SMCCC_ARCH_WORKAROUND_1 warning >>>> > > and consider them as vulnerable for Spectre variant 2 due to system >>>> > > wide safe value which is used in kvm emulation code when reading id >>>> > > registers. One wrong way of fixing this is to set the FTR_HIGHER_SAFE >>>> > > for CSV2 bits, so instead add the KRYO4XX gold CPU core to the safe >>>> > > list which will be consulted even when the sanitised read reports >>>> > > that CSV2 bits are not set for KRYO4XX gold cores. >>>> > > >>>> > > Reported-by: Stephen Boyd >>>> > > Signed-off-by: Sai Prakash Ranjan >>>> > > --- >>>> > > arch/arm64/kernel/cpu_errata.c | 1 + >>>> > > 1 file changed, 1 insertion(+) >>>> > > >>>> > > diff --git a/arch/arm64/kernel/cpu_errata.c >>>> > > b/arch/arm64/kernel/cpu_errata.c >>>> > > index 6bd1d3ad037a..6cbdd2d98a2a 100644 >>>> > > --- a/arch/arm64/kernel/cpu_errata.c >>>> > > +++ b/arch/arm64/kernel/cpu_errata.c >>>> > > @@ -545,6 +545,7 @@ static const struct midr_range >>>> > > spectre_v2_safe_list[] = { >>>> > > MIDR_ALL_VERSIONS(MIDR_HISI_TSV110), >>>> > > MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_3XX_SILVER), >>>> > > MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_4XX_SILVER), >>>> > > + MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_4XX_GOLD), >>>> > >>>> > We shouldn't be putting CPUs in the safe list when they have CSV2 >>>> > reporting >>>> > that they are mitigated in hardware, so I don't think this is the right >>>> > approach. >>>> > >>>> >>>> Ok but the only thing I find wrong in this approach is that it is a >>>> redundant >>>> information because CSV2 is already advertising the mitigation, but >>>> again >>>> CSV2 check is done first so it doesn't really hurt to add it to the >>>> safe >>>> list because we already know that it is safe. >>> >>> It simply doesn't scale. That's why CSV2 exists in the first place, >>> so we >>> don't have to modify the kernel everytime a new CPU is invented. >>> >>>> > Sounds more like KVM should advertise CSV2 for the vCPUs if all of the >>>> > physical CPUs without CSV2 set are on the safe list. But then again, KVM >>>> > has always been slightly in denial about big.LITTLE because you can't >>>> > sensibly expose it to a guest if there are detectable differences... >>>> > >>>> >>>> Sorry but I don't see how the guest kernel will see the CSV2 bits >>>> set for >>>> gold CPU cores without actually adding them to the safe list or >>>> reading the >>>> not sanitised value of ID_AA64PFR0_EL1 ? >>> >>> Well that's for somebody to figure out in the patch. I'm just saying >>> that >>> adding cores to the safe list when they already have a CSV2 field >>> conveying >>> the same information is the wrong approach. The right appproach is >>> for KVM >>> to expose CSV2 as set when the system is not affected by the erratum. >> >> A sensible way to fix this would be with something like that: >> >> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c >> index 077293b5115f..2735db21ff0d 100644 >> --- a/arch/arm64/kvm/sys_regs.c >> +++ b/arch/arm64/kvm/sys_regs.c >> @@ -1131,6 +1131,9 @@ static u64 read_id_reg(const struct kvm_vcpu >> *vcpu, >> if (!vcpu_has_sve(vcpu)) >> val &= ~(0xfUL << ID_AA64PFR0_SVE_SHIFT); >> val &= ~(0xfUL << ID_AA64PFR0_AMU_SHIFT); >> + if (!(val & (0xfUL << ID_AA64PFR0_CSV2_SHIFT)) && >> + get_spectre_v2_workaround_state() == >> ARM64_BP_HARDEN_NOT_REQUIRED) >> + val |= (1UL << ID_AA64PFR0_CSV2_SHIFT); >> } else if (id == SYS_ID_AA64ISAR1_EL1 && !vcpu_has_ptrauth(vcpu)) { >> val &= ~((0xfUL << ID_AA64ISAR1_APA_SHIFT) | >> (0xfUL << ID_AA64ISAR1_API_SHIFT) | >> > > Thanks Marc, I gave this a go on SC7180 where the issue was seen and > this fix is good. > > Tested-by: Sai Prakash Ranjan There is still a problem with this approach. A late CPU could come up after a guest has been started. If that CPU identified as vulnerable by the host kernel, get_spectre_v2_workaround_state() will return a different value, breaking the guest (or more likely, leaving it exposed to Spectre-v2 attacks). We'd need to disable the late onlining of CPUs that would change the mitigation state, and this is... ugly. M. -- Jazz is not dead. It just smells funny... _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel