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 DDB51C54E67 for ; Wed, 27 Mar 2024 14:41:38 +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=jkzkrv340XlIVs1mnB3cc09m45Yi9SaujVWo8EYDoSE=; b=gsfDSHQTpKy6M2 7FhX0o3wgaujWS8QizB7A6bQLLbRTNxjb57rdo/0iFNaCK6o9n1f3siu+jLtspv5er1LWJpMNV6AB T/ed/YET1K0CXwQxQIOWt3KQZwvhDNWR6JXq/w65KgVACI4mE5aKD1a5+zWpuUYNyNw6gcYLuhFxI ysDs8RvcZwe6s/VgELc+Ms+ItXmCLE91kUNgRrTVMz1VjqIsWR6S9ktrOYw45XM5APdf+p9WRqiXP 2CAcBz/IHPVzJVtYHlj9RNwmfU1QhNBSDBI+5NJyFm4Pofdj5Ox4C4JG8zQWNXM8sdvmtjBDgUT53 1K6jZe512WPPFSMQyNdA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpUSt-00000009Xte-420z; Wed, 27 Mar 2024 14:41:19 +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 1rpUSr-00000009XsH-18vf for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2024 14:41:18 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 819A56153F; Wed, 27 Mar 2024 14:41:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7727C433C7; Wed, 27 Mar 2024 14:41:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711550476; bh=GZn0lPbljrhoUZPvSpqPd5G1GDxvCnTDxPMxHrzqZYs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hTDN/h6r4yW/J6zbIKa4hm0+2ydfLjwZwO6fGYPt2A9TeacK4GZSB/u9jvdOy4SdJ r+Q2d7chhrHAmFZ8kGZhiPK1iHSE2K6vvl3nrCHjNRuBHwgh+lrni1N1igmzn+xKr+ M9Y7icC/VMl579wyPpsY9f1MB/Ugxoa6V60r+w26fMYdIAH8X2ig9gqMcB303Xyhil G8zDoZW4013xRwgPyZzs6ULhdZvZmo1qOSX3+8RqetKtcSr7PLuj7dkuqmYvfIsxM/ YI8ySauEoKzz3aLvdAWnUdj/XwAGie9iNo8Wfhy5jAZxroYR9CjFsyyeTi68zHEl65 CEoty3z2cPhRg== Date: Wed, 27 Mar 2024 07:41:13 -0700 From: Nathan Chancellor To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk, arnd@arndb.de, linus.walleij@linaro.org, stable@kernel.org Subject: Re: [PATCH] ARM: vfp: use asm volatile for FP control register accesses Message-ID: <20240327144113.GA1138120@dev-arch.thelio-3990X> References: <20240318093004.117153-2-ardb+git@google.com> <20240326235529.GA2025585@dev-arch.thelio-3990X> 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-20240327_074117_427919_A3A8FD3E X-CRM114-Status: GOOD ( 28.43 ) 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, Mar 27, 2024 at 09:05:17AM +0200, Ard Biesheuvel wrote: > On Wed, 27 Mar 2024 at 01:55, Nathan Chancellor wrote: > > > > On Mon, Mar 18, 2024 at 10:30:05AM +0100, Ard Biesheuvel wrote: > > > From: Ard Biesheuvel > > > > > > Clang may reorder FP control register reads and writes, due to the fact > > > that the inline asm() blocks in the read/write wrappers are not volatile > > > qualified, and the compiler has no idea that these reads and writes may > > > have side effects. > > > > > > In particular, reads of FPSCR may generate an UNDEF exception if a > > > floating point exception is pending, and the FP emulation code in > > > VFP_bounce() explicitly clears FP exceptions temporarily in order to be > > > able to perform the emulation on behalf of user space. This requires > > > that the writes to FPEXC are never reordered with respect to accesses to > > > other FP control registers, such as FPSCR. > > > > > > So use asm volatile for both the read and the write helpers. > > > > > > Cc: > > > Signed-off-by: Ard Biesheuvel > > > > This seems reasonable to me based on my understanding of GCC's > > documentation. However, their documentation states "the compiler can > > move even volatile asm instructions relative to other code, including > > across jump instructions" and I feel like there was some discussion > > around this sentence in the past but I can't remember what the > > conclusion was, although I want to say Clang did not have the same > > behavior. > > The only thing that matters here is whether two asm blocks are emitted > in a different order than they appear in the program, and I would be > very surprised if volatile permits that. Otherwise, we might introduce > a fake input dependency or a memory clobber instead. Yeah, I think it is reasonable to go with this approach and fall back to your follow up suggestion if this proves not to be robust enough. > > Regardless: > > > > Acked-by: Nathan Chancellor > > > > Thanks. > > > I am just curious, how was this discovered or noticed? Was there a > > report I missed? > > > > I noticed this when building a recent kernel for the original > Raspberry Pi, which is ARMv6 not ARMv7, and has a VFP which partially > relies on emulation. On more recent cores, we never hit the issue > because emulation is never needed. On older cores, there is no VFP so > we never reach this code path either. Ah, good to know. I boot test -next on a Pi 3 with a 32-bit kernel, so that explains why I have not seen any issues. Just wanted to make sure I did not miss something :) Cheers, Nathan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel