Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1967921pxb; Sat, 2 Apr 2022 09:59:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAU2S9xt0AtiKqpTkhsz/KDV48JY+Pd5qGZeEpbhY5jeSaYj3b8lhwY8CU9Dp7DbziHCrW X-Received: by 2002:a05:6a00:228b:b0:4fa:e12b:2c7b with SMTP id f11-20020a056a00228b00b004fae12b2c7bmr49304256pfe.79.1648918742274; Sat, 02 Apr 2022 09:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648918742; cv=none; d=google.com; s=arc-20160816; b=LA9nEmAqolSI9kFphgMKwYSKqeLgnB28j6kSCFlhnHRhY4OWC/DBznQvTwPEG095Nd r8X+1TyzG/5X0yHkgWppb/eAw1D13tO12ZH5EMEACHufh3teSKPzewEyp2+Os7nlMn0y 2AlRLLfP/NtqyEpDQNSCi4Om8x8guOjawT4pfeq6naNWk26S5nh4PNTk2Wvk4i/4l5za cfDWd7XtCKyVYs3IEKPpO6qfIXNBA+TG26Z+FWD4ZL0wpXIiU75MsK9aSX2cDntfBHjU dsUWhVSQc94r7Ces1jyQPbHRSjNpOjA8f5f6SZDBc+arunaUJUMVhCA+43L5y9uckR5l +J2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=N/tPYIJF7VD85GpJ3lKQWdUGtm3UfSxbSlN0xBU73yU=; b=dnkQAEr+I0a6YCkOPwFyTxYt4aYr17PG76zSFTPBUCwfNMGLh0RM6KbhckOQUE8rn2 z0mhbecOjy6ASIpGnlm4RsTcSy+cjW13XzJaXz3Ejf95+B10LDhC2zIHRU9v4Lm7q7OP CCmal8Xgk5NfdFkC7+MOCJoximcFcZmR3SfVO4dKCxrHE5UJRfw7t+uw4tKQw+s51QoH jjXuyqbB+Uot1E3nXbvKzG1BJoBbla4n4FvCeplWjEwY1bLPxPn4DPrpm5hphptVXuvI nrqQtpayx6DVZfY8zMTHpQs/ZOAThzKpGbZfa0t438PVxLm+Clo3BwnpdluIpSBK0OFw pWCQ== 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 u71-20020a63854a000000b003823f33adb2si5344396pgd.815.2022.04.02.09.58.48; Sat, 02 Apr 2022 09:59:02 -0700 (PDT) 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 S1349865AbiDARYV (ORCPT + 99 others); Fri, 1 Apr 2022 13:24:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347073AbiDARYQ (ORCPT ); Fri, 1 Apr 2022 13:24:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A2BBD20C1A5 for ; Fri, 1 Apr 2022 10:22:26 -0700 (PDT) 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 5DB4911FB; Fri, 1 Apr 2022 10:22:26 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.6.144]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 900493F66F; Fri, 1 Apr 2022 10:22:24 -0700 (PDT) Date: Fri, 1 Apr 2022 18:22:14 +0100 From: Mark Rutland To: Jeremy Linton Cc: linux-arm-kernel@lists.infradead.org, gcc@gcc.gnu.org, catalin.marinas@arm.com, will@kernel.org, marcan@marcan.st, maz@kernel.org, linux-kernel@vger.kernel.org, szabolcs.nagy@arm.com, f.fainelli@gmail.com, opendmb@gmail.com Subject: Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect Message-ID: References: <20220401164406.61583-1-jeremy.linton@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220401164406.61583-1-jeremy.linton@arm.com> X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Hi Jeremy, Thanks for raising this. On Fri, Apr 01, 2022 at 11:44:06AM -0500, Jeremy Linton wrote: > The relaxed variants of read/write macros are only declared > as `asm volatile()` which forces the compiler to generate the > instruction in the code path as intended. The only problem > is that it doesn't also tell the compiler that there may > be memory side effects. Meaning that if a function is comprised > entirely of relaxed io operations, the compiler may think that > it only has register side effects and doesn't need to be called. As I mentioned on a private mail, I don't think that reasoning above is correct, and I think this is a miscompilation (i.e. a compiler bug). The important thing is that any `asm volatile` may have a side effects generally outside of memory or GPRs, and whether the assembly contains a memory load/store is immaterial. We should not need to add a memory clobber in order to retain the volatile semantic. See: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile ... and consider the x86 example that reads rdtsc, or an arm64 sequence like: | void do_sysreg_thing(void) | { | unsigned long tmp; | | tmp = read_sysreg(some_reg); | tmp |= SOME_BIT; | write_sysreg(some_reg); | } ... where there's no memory that we should need to hazard against. This patch might workaround the issue, but I don't believe it is a correct fix. > For an example function look at bcmgenet_enable_dma(), before the > relaxed variants were removed. When built with gcc12 the code > contains the asm blocks as expected, but then the function is > never called. So it sounds like this is a regression in GCC 12, which IIUC isn't released yet per: https://gcc.gnu.org/gcc-12/changes.html ... which says: | Note: GCC 12 has not been released yet Surely we can fix it prior to release? Thanks, Mark. > > Signed-off-by: Jeremy Linton > --- > arch/arm64/include/asm/io.h | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h > index 7fd836bea7eb..3cceda7948a0 100644 > --- a/arch/arm64/include/asm/io.h > +++ b/arch/arm64/include/asm/io.h > @@ -24,25 +24,25 @@ > #define __raw_writeb __raw_writeb > static inline void __raw_writeb(u8 val, volatile void __iomem *addr) > { > - asm volatile("strb %w0, [%1]" : : "rZ" (val), "r" (addr)); > + asm volatile("strb %w0, [%1]" : : "rZ" (val), "r" (addr) : "memory"); > } > > #define __raw_writew __raw_writew > static inline void __raw_writew(u16 val, volatile void __iomem *addr) > { > - asm volatile("strh %w0, [%1]" : : "rZ" (val), "r" (addr)); > + asm volatile("strh %w0, [%1]" : : "rZ" (val), "r" (addr) : "memory"); > } > > #define __raw_writel __raw_writel > static __always_inline void __raw_writel(u32 val, volatile void __iomem *addr) > { > - asm volatile("str %w0, [%1]" : : "rZ" (val), "r" (addr)); > + asm volatile("str %w0, [%1]" : : "rZ" (val), "r" (addr) : "memory"); > } > > #define __raw_writeq __raw_writeq > static inline void __raw_writeq(u64 val, volatile void __iomem *addr) > { > - asm volatile("str %x0, [%1]" : : "rZ" (val), "r" (addr)); > + asm volatile("str %x0, [%1]" : : "rZ" (val), "r" (addr) : "memory"); > } > > #define __raw_readb __raw_readb > -- > 2.35.1 >