Received: by 10.213.65.68 with SMTP id h4csp3370609imn; Tue, 3 Apr 2018 03:51:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx489rSdpAajMp1mF7s+RdQqJQ+imK6emjLrx41LJeIcp2IJiHh0GtwHDqGBdvnXvQaem8Azp X-Received: by 10.98.202.10 with SMTP id n10mr10256737pfg.220.1522752688801; Tue, 03 Apr 2018 03:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522752688; cv=none; d=google.com; s=arc-20160816; b=DTMSDa+WTfWcoGxMLhHWXrB2ugOvzsXsBuULeUlhL6txHS1N9uuAXyAhyAUnoLSGtm S3PvuGPj5lGSyt96965h2SWadE0mzSiKdal6aA1sBOHJ2+Poe0NBuSBe4186yRb5PK98 oz54jTGJalVMXQceVoz1WWnaZyp9bEbH/4X1oUECYe3903Hhqf2eSIPpUzdQEzXSVBnS 0dbhNH9Ds5aseIZuzTxRgs4UUxHPOu9P/Jo/C/BjQtFauMXyXpqti1WowFhyaZJqgkNh RNai/aCm8EMP+x/ENWiQfVtAU/j4k8zpderiCySncdljb2Puv1FZOVgDgLtpx5iLs5on jZfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=QTZ+t7CRHb7zF+uNQqB4piHosT47OvEj6RNardagp5A=; b=pnmsCrauuXuYueZoE5957TAS7guMzQP9RVF22nipY3u+g/RYQJ7NP1BSgX6N7HobuL qE11eC5tFYdN968MC7Ahbyf12zxDAgHkixEH/5BuUZKUG3PkuDebGpJR4NK72QyDxERn wIxG6X56JIoW7qiO1zkA3jyt8pwNinrDRwrwFrrHZusNAnxg+c69AQ387WshE6I4tVcb aeaKkUVv9Zqw3B/liDENBUBd/IWeQQy3DJSX+mr9D72objbuIwmuPOwdrhyryUU7toLz N7tEfxyeyiXkEmrg+TbPhzDwMn9BXGak3rJPlsW8MsYHMVmvAawlIhXToE4jtJ3HTMtP aDCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31-v6si240826plz.467.2018.04.03.03.51.15; Tue, 03 Apr 2018 03:51:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932089AbeDCKtg (ORCPT + 99 others); Tue, 3 Apr 2018 06:49:36 -0400 Received: from foss.arm.com ([217.140.101.70]:59064 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755049AbeDCKtd (ORCPT ); Tue, 3 Apr 2018 06:49:33 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 99C3A1435; Tue, 3 Apr 2018 03:49:32 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1FA2A3F587; Tue, 3 Apr 2018 03:49:30 -0700 (PDT) Date: Tue, 3 Apr 2018 11:49:25 +0100 From: Mark Rutland To: Sinan Kaya Cc: arnd@arndb.de, timur@codeaurora.org, sulrich@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] io: prevent compiler reordering on the default readX() implementation Message-ID: <20180403104925.fuyajja6tyanlna4@lakrids.cambridge.arm.com> References: <1522425494-2916-1-git-send-email-okaya@codeaurora.org> <1522425494-2916-2-git-send-email-okaya@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1522425494-2916-2-git-send-email-okaya@codeaurora.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, Mar 30, 2018 at 11:58:13AM -0400, Sinan Kaya wrote: > The default implementation of mapping readX() to __raw_readX() is wrong. > readX() has stronger ordering semantics. Compiler is allowed to reorder > __raw_readX(). Could you please specify what the compiler is potentially reordering __raw_readX() against, and why this would be wrong? e.g. do we care about prior normal memory accesses, subsequent normal memory accesses, and/or other IO accesses? I assume that the asm-generic __raw_{read,write}X() implementations are all ordered w.r.t. each other (at least for a specific device). Thanks, Mark. > In the abscence of a read barrier or when using a strongly ordered > architecture, readX() should at least have a compiler barrier in > it to prevent commpiler from clobbering the execution order. > > Signed-off-by: Sinan Kaya > --- > include/asm-generic/io.h | 28 ++++++++++++++++++++++++---- > 1 file changed, 24 insertions(+), 4 deletions(-) > > diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h > index e8c2078..2554f15 100644 > --- a/include/asm-generic/io.h > +++ b/include/asm-generic/io.h > @@ -110,7 +110,12 @@ static inline void __raw_writeq(u64 value, volatile void __iomem *addr) > #define readb readb > static inline u8 readb(const volatile void __iomem *addr) > { > - return __raw_readb(addr); > + u8 val; > + > + val = __raw_readb(addr); > + barrier(); > + > + return val; > } > #endif > > @@ -118,7 +123,12 @@ static inline u8 readb(const volatile void __iomem *addr) > #define readw readw > static inline u16 readw(const volatile void __iomem *addr) > { > - return __le16_to_cpu(__raw_readw(addr)); > + u16 val; > + > + val = __le16_to_cpu(__raw_readw(addr)); > + barrier(); > + > + return val; > } > #endif > > @@ -126,7 +136,12 @@ static inline u16 readw(const volatile void __iomem *addr) > #define readl readl > static inline u32 readl(const volatile void __iomem *addr) > { > - return __le32_to_cpu(__raw_readl(addr)); > + u32 val; > + > + val = __le32_to_cpu(__raw_readl(addr)); > + barrier(); > + > + return val; > } > #endif > > @@ -135,7 +150,12 @@ static inline u32 readl(const volatile void __iomem *addr) > #define readq readq > static inline u64 readq(const volatile void __iomem *addr) > { > - return __le64_to_cpu(__raw_readq(addr)); > + u64 val; > + > + val = __le64_to_cpu(__raw_readq(addr)); > + barrier(); > + > + return val; > } > #endif > #endif /* CONFIG_64BIT */ > -- > 2.7.4 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html