Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3489633rwb; Sat, 12 Nov 2022 06:40:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Br/o8rnhGyaI7g7IqnHb63RXtHA4fnWnmKn+dkKDbJJMUXqC0HdmWywCMS/f9nxKvi/KN X-Received: by 2002:a17:906:24cb:b0:78d:4167:cf08 with SMTP id f11-20020a17090624cb00b0078d4167cf08mr5445571ejb.337.1668264032994; Sat, 12 Nov 2022 06:40:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668264032; cv=none; d=google.com; s=arc-20160816; b=nsvg35z2ptz5Kwwc6yAFEBcHL4aLaObGt9xdBjBgSi0B3z/AYnV/BdZHR2fYCcPsqM ImmyGoY+8wx0FK++NOMYNY/E7/XRuHmKHmHdK/ym4FATlYDxoIb8OeAM6UaNnw/PYaKb OmIcJq1pW1W2D1eRf31WbMIR8K2E1btY27gCr7/xvVSpCGkbeskXcNOjD5aa0iMwxHT+ 4scZTb9zI7hmWOWuyL6qa2s8/lbXySeAXPh7MdLtnGpZtgs/x2muneBXXLQQczImWH4L xkkG0h9sk6rVEA73YBCNdke60Xy/lu+/nQbkKyqfVyGOwEVvoVLih5+kOVTZ51osAZ78 XUDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=vNiEdOiM82LNJjcYelmu6ukvXgMZKlDr9AugPK4N15g=; b=cJYO2FVmZBVyBmFv6xXFaebpEtaSspHoxup1Z8OsyoZNZL64+nq6i61oa936eSSUe5 VGUN8ZgCPMjpSWdN2GSfhjO/nFPxZyzEHJnmx6GlskvbLYaCPza6QCSXfpBGySZ1vaMm HlxnFeahlsHN95Z2UKtA5Bu4ZyiNUXznIWXQdP7Mk6ZoSvzpEAgTF8Xkanz98FSi3ZLq G56T1+sZDWBr4B8Wy+qJllTQsFza5Jlj75lzMbgMpYpDsdgObk/hAI/3aRz3Kw7Utv91 Etmi4feWf5lk3364H+lEXvL+7ExyZwfZ8sEiX4Q9B29+dKV7W1DQmERLAF9Zl44OkUgC wq7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk39-20020a1709077fa700b007a8a40e6146si5060354ejc.363.2022.11.12.06.40.09; Sat, 12 Nov 2022 06:40:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234714AbiKLNxE (ORCPT + 90 others); Sat, 12 Nov 2022 08:53:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234627AbiKLNw7 (ORCPT ); Sat, 12 Nov 2022 08:52:59 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D4DE512621; Sat, 12 Nov 2022 05:52:57 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8BE651FB; Sat, 12 Nov 2022 05:53:03 -0800 (PST) Received: from [10.163.38.229] (unknown [10.163.38.229]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 575F73F534; Sat, 12 Nov 2022 05:52:54 -0800 (PST) Message-ID: <0d4df07b-da7f-3cad-7066-97ecd72c3d5e@arm.com> Date: Sat, 12 Nov 2022 19:22:51 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH 2/2] arm64: errata: Workaround possible Cortex-A715 [ESR|FAR]_ELx corruption Content-Language: en-US To: Catalin Marinas Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, Suzuki K Poulose , James Morse , Jonathan Corbet , Mark Rutland , linux-doc@vger.kernel.org References: <20221027023915.1318100-1-anshuman.khandual@arm.com> <20221027023915.1318100-3-anshuman.khandual@arm.com> <73c40107-0d7a-d988-c817-7bba6d72c371@arm.com> From: Anshuman Khandual In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/12/22 04:06, Catalin Marinas wrote: > On Thu, Nov 10, 2022 at 08:45:07AM +0530, Anshuman Khandual wrote: >> On 11/10/22 00:48, Catalin Marinas wrote: >>> On Thu, Oct 27, 2022 at 08:09:15AM +0530, Anshuman Khandual wrote: >>>> +#define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION >>>> +static inline pte_t ptep_modify_prot_start(struct vm_area_struct *vma, >>>> + unsigned long addr, >>>> + pte_t *ptep) >>>> +{ >>>> + pte_t pte = ptep_get_and_clear(vma->vm_mm, addr, ptep); >>>> >>>> + if (IS_ENABLED(CONFIG_ARM64_WORKAROUND_2645198)) { >>>> + /* >>>> + * Break-before-make (BBM) is required for all user space mappings >>>> + * when the permission changes from executable to non-executable >>>> + * in cases where cpu is affected with errata #2645198. >>>> + */ >>>> + if (pte_user_exec(pte) && cpus_have_const_cap(ARM64_WORKAROUND_2645198)) >>>> + __flush_tlb_range(vma, addr, addr + PAGE_SIZE, PAGE_SIZE, false, 3); >>> >>> Why not flush_tlb_page() here? >>> >>> But more importantly, can we not use ptep_clear_flush() instead (and >> >> Something like ... >> >> ptep_modify_prot_start - >> >> if (IS_ENABLED(CONFIG_ARM64_WORKAROUND_2645198)) { >> if (pte_user_exec(READ_ONCE(*ptep)) && cpus_have_const_cap(ARM64_WORKAROUND_2645198)) >> return ptep_clear_flush(vma, addr, ptep); >> } else { >> return ptep_get_and_clear(vma->vm_mm, addr, ptep); >> } > > Yes, this should work but avoid the 'else' when you have a return, so > something like: > > if (IS_ENABLED(CONFIG_ARM64_WORKAROUND_2645198) && > cpus_have_const_cap(ARM64_WORKAROUND_2645198) && > pte_user_exec(READ_ONCE(*ptep))) > return ptep_clear_flush(vma, addr, ptep); > > return ptep_get_and_clear(vma->vm_mm, addr, ptep); Right, realized that later. > > >>> huge_ptep_clear_flush())? They return the pte and do the TLBI. >> >> huge_ptep_modify_prot_start - >> >> if (IS_ENABLED(CONFIG_ARM64_WORKAROUND_2645198)) { >> if (pte_user_exec(READ_ONCE(*ptep)) && cpus_have_const_cap(ARM64_WORKAROUND_2645198)) >> return huge_ptep_clear_flush(vma, addr, ptep); >> } else { >> return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); >> } >> >> pte_user_exec(READ_ONCE(*ptep) should identify an user exec mapping even though >> ptep represents a cont PTE/PMD huge page ? OR should huge_ptep_get() helper be >> used instead ? > > This should work as a shortcut. The contiguous ptes should all be the > same, so it's sufficient to check one of them. Sure, will read the first one.