Received: by 10.223.164.202 with SMTP id h10csp2728369wrb; Sun, 12 Nov 2017 17:07:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMakdp0wgByI2nJMoE5Z/PxRuudoVJLAgyyET3pPBg9eMGVTjFiEQFIdvFfhi5jbUtaerRvy X-Received: by 10.98.60.27 with SMTP id j27mr6701703pfa.68.1510535238707; Sun, 12 Nov 2017 17:07:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510535238; cv=none; d=google.com; s=arc-20160816; b=nAWK9oUnQLLREjyB1I8OTOStlWpRDWIDaGMiO5AuW/YNWHfHrK1h0NOHZrnwQSq1Br A5b/vXmq6A1rPWVwxmx0JZmKvWwkjq0pZhcWcAXN68QYe6KIx+a0gsf5ira2p1WzDutT 4DUwPhujBMxdvZ7JzilDwJ1a55K81rqVkJIZ0lHb0t/LZ9MGFEzxkZwLgeMDlXSn0S2a yyIDNZDWUdG7zLZQ7azfBwyDq/wufCnfLSsNa9MrQM91NDKpKjwOWLRTo8/CMMZCQEJY /UorC55crY0M8OE0qU+cX1MpyR7kJ3qb+h7ZlpLK5XfhIvLD2YDRuk0d8SD9lszqYY1s G5pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:reply-to:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=O9vu54nfKRDN94Cy1LHVsie2h9wrUG0Nki5JQ5UblaI=; b=RBSXdpURe3sBbwEv7taColOsWmTux3B7Pi+CIYlsa6gbJZKClnK7rYgMPGHk34c+dl uXcwJNFo4+Jd7JMrk75M/RtD41f+vpGZ4bPUOutlPE3w4V50bVlTCk73rXp5zcLP/xjV wfiELYlzwapJka0sUmYiJ9E/XBnbE3cbO1raaV782vAPDsG86nsws9ThODZA9pjCDl7n CzSYvZeVmSzyIJGOYAurE4s5V8l2PpbIUm4dnOzNdmyAXaJ5W+NcjWqcW19jN17cjYjq psr/XuhIiBlAK51mZWYYE21iwpNUvK00i9cz+poQ0ZRnGgf1xw3LMd8eG2mnAEfTBEkm x6gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=d/YRnQZf; dkim=pass header.i=@codeaurora.org header.s=default header.b=Ue6Ky0UZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1si11734878pgf.543.2017.11.12.17.07.06; Sun, 12 Nov 2017 17:07:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=d/YRnQZf; dkim=pass header.i=@codeaurora.org header.s=default header.b=Ue6Ky0UZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751489AbdKMBGb (ORCPT + 87 others); Sun, 12 Nov 2017 20:06:31 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:53044 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751056AbdKMBG3 (ORCPT ); Sun, 12 Nov 2017 20:06:29 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 18B226080B; Mon, 13 Nov 2017 01:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1510535189; bh=nuHYA+SU2Vmg7rGZkzXTn3xG5pHgHBGLzDz+PIjfWJI=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=d/YRnQZfOKpKcb7AWZRgVL9UlmC3iqszHimQVWRbd6350ZXzuf6Q4yIB6udbbSLwT 5pA2URox6dMeyGysuCT/Mu4Wq52XGx4PXgHICk16cg9WpfOvEr9IVCUFBDlYTNssa5 N+JdBAJddxivyMXKIY24K4exmdfrmLaj+vy4+IQ4= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [10.0.2.15] (unknown [70.123.43.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: shankerd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 904EF6055A; Mon, 13 Nov 2017 01:06:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1510535188; bh=nuHYA+SU2Vmg7rGZkzXTn3xG5pHgHBGLzDz+PIjfWJI=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Ue6Ky0UZ/zuk10+x8GFNuBBDIbqKZkesLkQq7L5Y6II8ajGSkU3+8vGy8YmU1UuKp vsvOQh7L4EYr4Z4rPSHVUHIFqt3XHSMBSeiVm8XnHD5ONgrRNbugoi9jF7YZv8GUKU PWm+VGjN6tuB02JgKPz3Zz4wV96lg71JgcsCf1B8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 904EF6055A Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=shankerd@codeaurora.org Reply-To: shankerd@codeaurora.org Subject: Re: [PATCH 3/3] arm64: Add software workaround for Falkor erratum 1041 To: James Morse Cc: linux-efi@vger.kernel.org, Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, Matt Fleming , linux-arm-kernel@lists.infradead.org, Robin Murphy , kvmarm@lists.cs.columbia.edu, Christoffer Dall References: <1509679664-3749-1-git-send-email-shankerd@codeaurora.org> <1509679664-3749-4-git-send-email-shankerd@codeaurora.org> <1f4a523c-608b-b46b-527a-bc1e02e7db5e@arm.com> <2ef66b5c-d1b7-a5fc-a19d-88dddff95bad@codeaurora.org> <5A04372B.2090902@arm.com> <93801988-e785-bd49-796e-4a73e0b77413@codeaurora.org> <5A057E44.3050109@arm.com> From: Shanker Donthineni Message-ID: Date: Sun, 12 Nov 2017 19:06:25 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <5A057E44.3050109@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi James, On 11/10/2017 04:24 AM, James Morse wrote: > Hi Shanker, > > On 09/11/17 15:22, Shanker Donthineni wrote: >> On 11/09/2017 05:08 AM, James Morse wrote: >>> On 04/11/17 21:43, Shanker Donthineni wrote: >>>> On 11/03/2017 10:11 AM, Robin Murphy wrote: >>>>> On 03/11/17 03:27, Shanker Donthineni wrote: >>>>>> The ARM architecture defines the memory locations that are permitted >>>>>> to be accessed as the result of a speculative instruction fetch from >>>>>> an exception level for which all stages of translation are disabled. >>>>>> Specifically, the core is permitted to speculatively fetch from the >>>>>> 4KB region containing the current program counter and next 4KB. >>>>>> >>>>>> When translation is changed from enabled to disabled for the running >>>>>> exception level (SCTLR_ELn[M] changed from a value of 1 to 0), the >>>>>> Falkor core may errantly speculatively access memory locations outside >>>>>> of the 4KB region permitted by the architecture. The errant memory >>>>>> access may lead to one of the following unexpected behaviors. >>>>>> >>>>>> 1) A System Error Interrupt (SEI) being raised by the Falkor core due >>>>>> to the errant memory access attempting to access a region of memory >>>>>> that is protected by a slave-side memory protection unit. >>>>>> 2) Unpredictable device behavior due to a speculative read from device >>>>>> memory. This behavior may only occur if the instruction cache is >>>>>> disabled prior to or coincident with translation being changed from >>>>>> enabled to disabled. >>>>>> >>>>>> To avoid the errant behavior, software must execute an ISB immediately >>>>>> prior to executing the MSR that will change SCTLR_ELn[M] from 1 to 0. > >>>>>> diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h >>>>>> index b6dfb4f..4c91efb 100644 >>>>>> --- a/arch/arm64/include/asm/assembler.h >>>>>> +++ b/arch/arm64/include/asm/assembler.h >>>>>> @@ -514,6 +515,22 @@ >>>>>> * reg: the value to be written. >>>>>> */ >>>>>> .macro write_sctlr, eln, reg >>>>>> +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1041 >>>>>> +alternative_if ARM64_WORKAROUND_QCOM_FALKOR_E1041 >>>>>> + tbnz \reg, #0, 8000f // enable MMU? >>> >>> Won't this match any change that leaves the MMU enabled? >> >> Yes. No need to apply workaround if the MMU is going to be enabled. > > (Sorry, looks like I had this upside down) > > My badly-made-point is you can't know if the MMU is being disabled unless you > have both the old and new values. > > As an example, in el2_setup, (where the MMU is disabled), we set the EE/E0E bits > to match the kernel's endianness. Won't your macro will insert an unnecessary > isb? Is this needed for the errata workaround? > Yes, It's not required in this case. I'll post a v2 patch and apply the workaround where it's absolutely required. Seems handling a workaround inside helper macros causing confusion. > >>> I think the macro is making this more confusing. Disabling the MMU is obvious >>> from the call-site, (and really rare!). Trying to work it out from a macro makes >>> it more complicated than necessary. > >> Not clear, are you suggesting not to use read{write}_sctlr() macros instead apply >> the workaround from the call-site based on the MMU-on status? > > Yes. This is the only way to patch only the locations that turn the MMU off. > > >> If yes, It simplifies >> the code logic but CONFIG_QCOM_FALKOR_ERRATUM_1041 references are scatter everywhere. > > Wouldn't they only appear in the places that are affected by the errata? > This is exactly what we want, anyone touching that code now knows they need to > double check this behaviour, (and ask you to test it!). > > Otherwise we have a macro second guessing what is happening, if its not quite > right (because some information has been lost), we're now not sure what we need > to do if we ever refactor any of this code. > > [...] > >>>> I'll prefer alternatives >>>> just to avoid the unnecessary overhead on future Qualcomm Datacenter >>>> server CPUs and regression on other CPUs because of inserting an ISB >>> >>> I think hiding errata on other CPUs is a good argument. >>> >>> My suggestion would be: >>>> #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1041 >>>> isb >>>> #endif >>> >>> In head.S and efi-entry.S, as these run before alternatives. >>> Then use alternatives to add just the isb in the mmu-off path for the other callers. > >> Thanks for your opinion on this one, I'll change to an unconditional ISB in v2 patch. >> After this change the enable_mmu() issues two ISBs before writing to SCTLR_EL1. > > Another great reason not to wrap this in a macro, there may already be a > suitable isb, in which case a comment will suffice. > > >> Are you okay with this behavior? > > Back-to-back isb doesn't sound like a good idea. > > >> ENTRY(__enable_mmu) >> mrs x1, ID_AA64MMFR0_EL1 >> ubfx x2, x1, #ID_AA64MMFR0_TGRAN_SHIFT, 4 >> cmp x2, #ID_AA64MMFR0_TGRAN_SUPPORTED >> b.ne __no_granule_support >> update_early_cpu_boot_status 0, x1, x2 >> adrp x1, idmap_pg_dir >> adrp x2, swapper_pg_dir >> msr ttbr0_el1, x1 // load TTBR0 >> msr ttbr1_el1, x2 // load TTBR1 >> isb >> write_sctlr el1, x0 >> isb > > Now I'm thoroughly confused. Isn't this one of the sequences that doesn't hit > the issue? Here we're switching SCTLR.M from 0 to 1. > > > Thanks, > > James > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > -- Shanker Donthineni Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. From 1583702344198548382@xxx Fri Nov 10 17:50:50 +0000 2017 X-GM-THRID: 1583013979194485035 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread