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 A7C35CD128A for ; Wed, 10 Apr 2024 15:35:45 +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=C2WwAxvP383yKQNAePSKdHMFpak0CuHTDc0aNSIP/rU=; b=RJU2j0whri/qu+ 4lT19bruTck8pwU+/5rYgev6IiEGyXmG7Sj2oOT7lDpkm/LMITWliBeL4mX+UMcr/sBQl1Dbj/74G hziwXQYOAM8bB2or5vL4goY6WMZFhwows8kZEBOy+kcE6DaFMkJXGQEqY/wAF80tntuDpN95OFdpA /glDzVpP/cIOHf0NujuAwP7iCVl3IQeGXJQpuVsufO2pAv+Ngeipq4aNld8ytA7hiFqD856q5KGIn SbVSegWWP6vWtLaGWpq24EHkdxaJ5s25NLnxTcHCSzDWbi0AbXuX9ZRZDhUWrAWroqQD+CfW7P56P NNpwUOdAo2GylG1qErAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruZz3-00000007oIy-0PSa; Wed, 10 Apr 2024 15:35:33 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruZz0-00000007oHf-2GzT for linux-arm-kernel@lists.infradead.org; Wed, 10 Apr 2024 15:35:31 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C1FD161C3A; Wed, 10 Apr 2024 15:35:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6F6FC433C7; Wed, 10 Apr 2024 15:35:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712763328; bh=8walZAK6NKjpVLbHHEWlhePnShxtE50CiegFbxlpbWI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=c6Y5zMarCKVz3VPX6NsdWppeDYYLGFkgF0PbgtXXc+k2laIh0nDzyC4Y/efTBFxiU 2JCUjjKClnzkNX/Qr9FWnzmw0yrKxqVJVoAMIqNdUnS0IyV6haPm1To1d/ddU+Q2fZ wDMzjlUhPXh+xN0UF+2iAuQWAdRKyZhFMZp8jivs/LioNfa2RK/igv2dPedDvsqDho xRphNNEY4zs19RJLQN26ElP2IQvOxjZvHK7hCvjZCYSpOpMPlOGFNTEHRWBsKzWeza Vn9ZfyO/qXGe6djlH+GvaXmf4UKYY4MiBhRNX4MFYaYnFjIwwNJkVCx9nm2ImIuVDn J3aJEbjGGbK5w== Date: Wed, 10 Apr 2024 08:35:26 -0700 From: Nathan Chancellor To: Ard Biesheuvel Cc: zhuqiuer , justinstitt@google.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux@armlinux.org.uk, llvm@lists.linux.dev, morbo@google.com, ndesaulniers@google.com Subject: Re: [PATCH v2] ARM: Add a memory clobber to the fmrx instruction Message-ID: <20240410153526.GA3904754@dev-arch.thelio-3990X> References: <20240409164641.GC3219862@dev-arch.thelio-3990X> <20240410024126.21589-1-zhuqiuer1@huawei.com> <20240410024126.21589-2-zhuqiuer1@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240410_083530_692087_8D392E79 X-CRM114-Status: GOOD ( 25.73 ) 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 Wed, Apr 10, 2024 at 02:31:11PM +0200, Ard Biesheuvel wrote: > On Wed, 10 Apr 2024 at 04:41, zhuqiuer wrote: > > > > The instruction fmrx is used throughout the kernel, > > where it is sometimes expected to be skipped > > by incrementing the program counter, such as in vfpmodule.c:vfp_init(). > > Therefore, the instruction should not be reordered when it is not intended. > > Adding a barrier() instruction before and after this call cannot prevent > > reordering by the compiler, as the fmrx instruction is constrained > > by '=r', meaning it works on the general register but not on memory. > > To ensure the order of the instruction after compiling, > > adding a memory clobber is necessary. > > > > Below is the code snippet disassembled from the method: > > vfpmodule.c:vfp_init(), compiled by LLVM. > > > > Before the patching: > > xxxxx: xxxxx bl c010c688 > > xxxxx: xxxxx mov r0, r4 > > xxxxx: xxxxx bl c010c6e4 > > ... > > xxxxx: xxxxx bl c0791c8c > > xxxxx: xxxxx movw r5, #23132 ; 0x5a5c > > xxxxx: xxxxx vmrs r4, fpsid <- this is the fmrx instruction > > > > After the patching: > > xxxxx: xxxxx bl c010c688 > > xxxxx: xxxxx mov r0, r4 > > xxxxx: xxxxx vmrs r5, fpsid <- this is the fmrx instruction > > xxxxx: xxxxx bl c010c6e4 > > > > Signed-off-by: zhuqiuer > > This also fixes the issue I observed so > > Reviewed-by: Ard Biesheuvel Reviewed-by: Nathan Chancellor This can probably go in Russell's patch tracker? Your patch had Cc: stable@vger.kernel.org in it, should this one as well? > > --- > > arch/arm/vfp/vfpinstr.h | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm/vfp/vfpinstr.h b/arch/arm/vfp/vfpinstr.h > > index 3c7938fd40aa..ae2c9b9b7701 100644 > > --- a/arch/arm/vfp/vfpinstr.h > > +++ b/arch/arm/vfp/vfpinstr.h > > @@ -68,14 +68,14 @@ > > u32 __v; \ > > asm(".fpu vfpv2\n" \ > > "vmrs %0, " #_vfp_ \ > > - : "=r" (__v) : : "cc"); \ > > + : "=r" (__v) : : "memory", "cc"); \ > > __v; \ > > }) > > > > #define fmxr(_vfp_,_var_) \ > > asm(".fpu vfpv2\n" \ > > "vmsr " #_vfp_ ", %0" \ > > - : : "r" (_var_) : "cc") > > + : : "r" (_var_) : "memory", "cc") > > > > #else > > > > -- > > 2.12.3 > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel