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 BD7CEC67861 for ; Tue, 9 Apr 2024 16:47:05 +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=Gck+T0TFwuqi7ytUlWD0zOBn/faiK4SQc665mMj+y9U=; b=AUx5Uz+or3hWuV xum6aG8x1cFa0P8cmeV8g8qC3J5wvHiu/WXkXsJD8UjU3EHjPx7s9PaamLD2ht3aoEIcfaDJeuLOj WVhipihUPYN1bmsmJ/TWeUhxKcxcNgf9wUhLYsYECpZ+/0Zr6+dmPhfke2zoxqXBDJPD6aYOXRns9 h4jTrH7KLW3xDLHTQPy0IF4+X/b7iwcpQyA2yd0wyMxS3D4L9+Qn9aDyQzvzFl7prAofIQh1hFyl/ W1FqAKhAOInH4qR9R0z8inmgR/1vfYk7rIgTyialZDK6JtTGnblYMKeH0YzsnLTG+/s677PLOEHnp Iww4dPdl1c1EuRiNCIvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruEcT-000000030GL-19Kj; Tue, 09 Apr 2024 16:46:49 +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 1ruEcP-000000030FX-14Mr for linux-arm-kernel@lists.infradead.org; Tue, 09 Apr 2024 16:46:46 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1E2AD6174C; Tue, 9 Apr 2024 16:46:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3118DC433C7; Tue, 9 Apr 2024 16:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712681203; bh=o0OAciAt/jXavMnT0VtNrsX62U+AXVJqJQ9T4iXq+7k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qj2j4il8RUcgG+h9QuuOQyyLw5K4BETmu32EIMGukESkD6+rVLGhgu7Wo6j7f1gHI Kprshu1febqMDXtTaROJ5oOUXGjzhN8HC914Kiwarg6YGOJ+qecCtdkWjwCLCsPiWD 4BfXplP3CSNLrdPwyFS0BxRPT5G36dK/+lQY0kwxK8jbd4zuFT9t1QWkCbKihBPM9x bkTC+JpcPN5XMhDoyc4m2d7ubhQHwJrQ7SQUir9GI4MydoBb2r0y0JluVaomu34jtd wm9q9aWIiGS9z8NqqogdRRtOHcHAoudKafnIjr0d0GE4G++ztQiVvDRrborxRw/9iU zzm+JkIcGTO5Q== Date: Tue, 9 Apr 2024 09:46:41 -0700 From: Nathan Chancellor To: zhuqiuer Cc: linux@armlinux.org.uk, ndesaulniers@google.com, morbo@google.com, justinstitt@google.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ardb@kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] ARM: Add a memory clobber to the fmrx instruction Message-ID: <20240409164641.GC3219862@dev-arch.thelio-3990X> References: <20240409113844.4813-1-zhuqiuer1@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240409113844.4813-1-zhuqiuer1@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240409_094645_367900_B99AB763 X-CRM114-Status: GOOD ( 24.26 ) 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 + Ard On Tue, Apr 09, 2024 at 07:38:44PM +0800, 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 > --- > arch/arm/vfp/vfpinstr.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm/vfp/vfpinstr.h b/arch/arm/vfp/vfpinstr.h > index 3c7938fd40aa..e70129e10b8e 100644 > --- a/arch/arm/vfp/vfpinstr.h > +++ b/arch/arm/vfp/vfpinstr.h > @@ -68,7 +68,7 @@ > u32 __v; \ > asm(".fpu vfpv2\n" \ > "vmrs %0, " #_vfp_ \ > - : "=r" (__v) : : "cc"); \ > + : "=r" (__v) : : "memory", "cc"); \ > __v; \ > }) > > -- > 2.12.3 > This seems like the same issue that Ard was addressing with this patch at https://lore.kernel.org/20240318093004.117153-2-ardb+git@google.com/, does that change work for your situation as well? I do not really have a strong preference between the two approaches, Ard also mentioned using *current in the asm constraints as another option. Cheers, Nathan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel