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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9A5AC4332F for ; Fri, 11 Nov 2022 22:36:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234598AbiKKWgp (ORCPT ); Fri, 11 Nov 2022 17:36:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234567AbiKKWgo (ORCPT ); Fri, 11 Nov 2022 17:36:44 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B5BE77E6C; Fri, 11 Nov 2022 14:36:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4067E62112; Fri, 11 Nov 2022 22:36:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B131C433C1; Fri, 11 Nov 2022 22:36:37 +0000 (UTC) Date: Fri, 11 Nov 2022 22:36:31 +0000 From: Catalin Marinas To: Anshuman Khandual 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 Subject: Re: [PATCH 2/2] arm64: errata: Workaround possible Cortex-A715 [ESR|FAR]_ELx corruption Message-ID: References: <20221027023915.1318100-1-anshuman.khandual@arm.com> <20221027023915.1318100-3-anshuman.khandual@arm.com> <73c40107-0d7a-d988-c817-7bba6d72c371@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <73c40107-0d7a-d988-c817-7bba6d72c371@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org 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); > > 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. -- Catalin 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 03385C433FE for ; Fri, 11 Nov 2022 22:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=49kHA8DI1o4X9fIQU8RULTnXhQva03jtMsLeX6nhgT4=; b=tMsJL7I/WoWuHi OZuKjKrKvmia3rA7wA0Yh5XkMzrAeOKUwF9beMWuKKLkNTeDzxUbOb270flmJyLAoqUMwGwOUuQUd +rcDy9UpNjy+g8csqPbJdVyuZjpxRruqRoTwKNXcwsgeKFB3yfSThOKxqkT4SIzCXaBvH/Ap/QYoh 3PwxYLU/NOzGWM1wDPdbUss+ELUXMARZWC5k59UA4oovKxgowqaTCiVDyMc26gb9S14V7/gSrpzW8 VnZjqnlVslNdv1jDDJ9own4I2bE7gtrBPftMagyJzCnugsYniyy9kA35b2HWMgAc+I9OrkHiVnVgX 5pxaz6aAsA1XQ+rJscqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1otcdr-001cie-5Y; Fri, 11 Nov 2022 22:36:55 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1otcdm-001cfO-Fb for linux-arm-kernel@lists.infradead.org; Fri, 11 Nov 2022 22:36:53 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 655CDCE2A5A; Fri, 11 Nov 2022 22:36:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B131C433C1; Fri, 11 Nov 2022 22:36:37 +0000 (UTC) Date: Fri, 11 Nov 2022 22:36:31 +0000 From: Catalin Marinas To: Anshuman Khandual 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 Subject: Re: [PATCH 2/2] arm64: errata: Workaround possible Cortex-A715 [ESR|FAR]_ELx corruption Message-ID: References: <20221027023915.1318100-1-anshuman.khandual@arm.com> <20221027023915.1318100-3-anshuman.khandual@arm.com> <73c40107-0d7a-d988-c817-7bba6d72c371@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <73c40107-0d7a-d988-c817-7bba6d72c371@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221111_143650_741302_F12D2350 X-CRM114-Status: GOOD ( 22.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); > > 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. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel