From patchwork Fri Apr 1 16:44:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 12798499 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 576C3C433FE for ; Fri, 1 Apr 2022 16:46:20 +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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=9KttyMgbVM9EoYccMjM/2hRrDqa5SOR5gITBttvUQFE=; b=Z8n+/saSC6xETh RQhJ3fYUT11IG9e5iJrybiUOKEpYbUWK+gg+pm0ENDU6QA6xGU5zNfvWtoy19CTm3iJmO2puqkGzB SDXPxBQMIPKgNv7Kx4pCKeCYk9syCuKOQPkG38j/1NEm/lyfHI5W7UHGm/PqHeRBOhWIjMwRX03kJ MCSkvlKXP2CAtCYva9in2M6l8cprvDe3cJB4Qj8m068jE6+vPprMyh47xSh5tCnsdDMyxgDZs32fh 1OOLat1tNl8SC3xGM/apypv/8nPx0pAlwUVFgPZsQeT/BPgeHk8csjtylJK5aNmwfWtaQgKJTOEPa Wc9l48XrNQYi/BKebVQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1naKOi-006b2J-6s; Fri, 01 Apr 2022 16:45:16 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1naKOd-006b0W-Vs for linux-arm-kernel@lists.infradead.org; Fri, 01 Apr 2022 16:45:13 +0000 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 8062211FB; Fri, 1 Apr 2022 09:45:05 -0700 (PDT) Received: from mammon-tx2.austin.arm.com (mammon-tx2.austin.arm.com [10.118.28.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5C0AD3F66F; Fri, 1 Apr 2022 09:45:05 -0700 (PDT) From: Jeremy Linton To: linux-arm-kernel@lists.infradead.org Cc: gcc@gcc.gnu.org, catalin.marinas@arm.com, will@kernel.org, marcan@marcan.st, maz@kernel.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, szabolcs.nagy@arm.com, f.fainelli@gmail.com, opendmb@gmail.com, Jeremy Linton Subject: [PATCH] arm64/io: Remind compiler that there is a memory side effect Date: Fri, 1 Apr 2022 11:44:06 -0500 Message-Id: <20220401164406.61583-1-jeremy.linton@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220401_094512_129389_9F90BF44 X-CRM114-Status: GOOD ( 11.27 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. 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. 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