Received: by 10.213.65.68 with SMTP id h4csp3487986imn; Tue, 3 Apr 2018 05:58:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/7ITE5aKe/ASOST4sM6xLy6Lc0WbJo7WvNs6IOwqz6Md5888kQka1nRhIZK/RHiRAxycGf X-Received: by 2002:a17:902:32a2:: with SMTP id z31-v6mr14431712plb.41.1522760296943; Tue, 03 Apr 2018 05:58:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522760296; cv=none; d=google.com; s=arc-20160816; b=RTHJdJ5HT7Mi5iENniuzH3PR4w7y9onCR/oOrbYv/OJ4FAsbYyLCL/emFtjlHzpZIm ihaDDYgb29C71W2w7OI1PjkyG4F0IEGTjV4Odc4BgiC7CKlyGJEvIlHaErA1UdiLhDhJ kLDFJQWI/5SzIhSC6qX21gMo1EeykeHT3ro4BysiWXrlcki45o7tGAS/LTtX4MHj4Bi4 yh+4gD8yQOja7BTkpajcu3KOFtFEOQBAzNq7S83kQsumosd5lsI4V3//MjrZ8sLapF1C A28oswfHKKUNOlAkVuWKJoyevtgESily3dVTvdRH3UxjZiNFHc5RbrgsVwQ7W7kYWlrb ILEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=kgGpTq5CXmwEN0deQbx7vCA5kUuwosb34Wqd2pHbKak=; b=FeChYqe/DCIRB+3lsfGaOO0ayOPVnonmz5JE/JVTC4U8WecW2E5/ribTPRa5yvW0Tr NMH9rk8yxB1zO4pJa/SLhlQArwnJ1CuqSxeuaXOmFTZ5ckGAfalW9MH/iwLXCsy1FX1F QzMlhZ1cQ1/b8kQCQYbh3efeTh92fknGt1xeudIiti1CmFHO2qkcq4+rfZ4h3veEf75u jt2jg41WDMANk+IrhjYyatQD1uPuiTAYdQL80hKa4eQ1XI+mKAlpiwFaKCV1w7lkCFBK VLN0n5FcFD7XFu5mKg3Zv11+r8kuHrcxih9coY5w0AxYdCb+nD0+yq76sKfq7qbB6kxz uAAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=doUqJqZG; 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 h90-v6si484839plb.377.2018.04.03.05.58.03; Tue, 03 Apr 2018 05:58:16 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=doUqJqZG; 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 S932246AbeDCM4W (ORCPT + 99 others); Tue, 3 Apr 2018 08:56:22 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:41497 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932141AbeDCM4U (ORCPT ); Tue, 3 Apr 2018 08:56:20 -0400 Received: by mail-qt0-f194.google.com with SMTP id d3so15672642qth.8; Tue, 03 Apr 2018 05:56:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=kgGpTq5CXmwEN0deQbx7vCA5kUuwosb34Wqd2pHbKak=; b=doUqJqZGdaGzg2Ygkw/6MDO5HvZs/Co1HCwciRyO3FC7UwQS6wI6rtt5klHq6azlgO MGLM8kxREXeSTd/G47il6VWTAobjhBXZ/tEArp2eMrSgrEs4VBf+Q2Xlej4GuPw6ocFi /2pw5fq/WYyI+u94sKojTmMRZVEPASOKFlND8oKvXHhLYpntBAxkA5yq++vV0f2GdR4z /XHl2VQeE87iw5A0CEKKfnVo6iH331uxUOu8oxqja/u/BpK0NK4p7NMfo/JHWzvIpYLu qTwTOvJYd4b/NkxlYQUMYzIRtsHWkywhHVK0eWrljfccyUdP9OCAFes3Na4S9ELm5S1e BnJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=kgGpTq5CXmwEN0deQbx7vCA5kUuwosb34Wqd2pHbKak=; b=Xc4wHF+jls5xLKPf1yO2AAVT8OKtRzcUS55faz59GwIpL73IXdU8ho1y2oEWolv02V thBjPS60UZWFBCXFF+rFLz4y0rSeNfVOI3zbZW+EM8juD2CQry60/CkQXWHQvXJkA7J7 D0AD9tgXAPrF+A4aGkEU6d/MOTgJqrY1YiUq82nHL3Opogz0IxtKoexhoQLS0aE1fRrv vTfUyfUj6+Fnsohvd6yXkBa4vbiiy0V7aEMo6rOeDI3TOh2KF4+/Rvzi/aNhptkSu24j 9+mGjqM7najLOuzu9xPDopxby1xss30q2x+SrjBXnoi7WOIoRviW47TOJ6tSzjRcLlqC vj7w== X-Gm-Message-State: ALQs6tBfzxq+yD5Xvh5N1dfDvJxioxh3m8LXBMsOy8mPOyk8jDxtEzyd WVq/HPtiDGgDz4g0rt/KFfBBRgy2/Zj05C9JEFk= X-Received: by 10.200.18.71 with SMTP id g7mr19980427qtj.35.1522760179459; Tue, 03 Apr 2018 05:56:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.185.25 with HTTP; Tue, 3 Apr 2018 05:56:18 -0700 (PDT) In-Reply-To: References: <1522425494-2916-1-git-send-email-okaya@codeaurora.org> <1522425494-2916-2-git-send-email-okaya@codeaurora.org> <20180403104925.fuyajja6tyanlna4@lakrids.cambridge.arm.com> From: Arnd Bergmann Date: Tue, 3 Apr 2018 14:56:18 +0200 X-Google-Sender-Auth: BLbWm1vyxsgGIRsrDo2VYgvnHtQ Message-ID: Subject: Re: [PATCH v2 2/2] io: prevent compiler reordering on the default readX() implementation To: Sinan Kaya Cc: Mark Rutland , Timur Tabi , sulrich@codeaurora.org, linux-arm-msm@vger.kernel.org, Linux ARM , linux-arch , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 3, 2018 at 2:44 PM, Sinan Kaya wrote: > On 4/3/2018 7:13 AM, Arnd Bergmann wrote: >> On Tue, Apr 3, 2018 at 12:49 PM, Mark Rutland wrote: >>> 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). >> >> I think that is correct: the compiler won't reorder those because of the >> 'volatile' pointer dereference, but it can reorder access to a normal >> pointer against a __raw_readl()/__raw_writel(), which breaks the scenario >> of using writel to trigger a DMA, or using a readl to see if a DMA has >> completed. > > Yes, we are worried about memory update vs. IO update ordering here. > That was the reason why barrier() was introduced in this patch. I'll try to > clarify that better in the commit text. > >> >> The question is whether we should use a stronger barrier such >> as rmb() amd wmb() here rather than a simple compiler barrier. >> >> I would assume that on complex architectures with write buffers and >> out-of-order prefetching, those are required, while on architectures >> without those features, the barriers are cheap. > > That's my reasoning too. I'm trying to follow the x86 example here where there > is a compiler barrier in writeX() and readX() family of functions. I think x86 is the special case here because it implicitly guarantees the strict ordering in the hardware, as long as the compiler gets it right. For the asm-generic version, it may be better to play safe and do the safest version, requiring architectures to override that barrier if they want to be faster. We could use the same macros that riscv has, using __io_br(), __io_ar(), __io_bw() and __io_aw() for before/after read/write. Arnd