From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755555AbbKRMjf (ORCPT ); Wed, 18 Nov 2015 07:39:35 -0500 Received: from mout.kundenserver.de ([212.227.126.135]:56068 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751513AbbKRMje (ORCPT ); Wed, 18 Nov 2015 07:39:34 -0500 From: Arnd Bergmann To: Andy Shevchenko Cc: Ulf Hansson , Jaehoon Chung , "linux-mmc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , linux-arm Mailing List Subject: Re: [PATCH] mmc: dw_mmc: use resource_size_t to store physical address Date: Wed, 18 Nov 2015 13:38:59 +0100 Message-ID: <5141236.CHnzdS7Lto@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: References: <28102387.ALpaBHpim0@wuerfel> <6288847.N1QBIiXedG@wuerfel> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:5BuvYdceBgiXSGXObgA2IbV3a6ZsCjDC41SSFSJo3dKzbbpnOOJ 7pYZIJIMpO59RCvkITe6/w+Rr/EI74Tdv4z0RXs5x642AnIDSN0aiCUJzV/Iz+bv7qQBE++ kB0fajFFgzt555muLek/CsLb4xQ+hQDoxu2MwaYyU6JxoUYisNemDt5/B4kua3xtMl9XsWr zYDU8diaGMeSh0/KlHjxw== X-UI-Out-Filterresults: notjunk:1;V01:K0:6oaPxvtBaL0=:Q+SO0AjXQzYJEzW1IRpTI3 lKaGeBUqv8FWsjenK4Qp+mPJkhqYta5AOVJI/qYiI1WEV85ABjQpytviNTZyWYswLvwk10+NW oDIi3+yPCnwMYGs5ca+ErBRRMIoYsNFO3i5v1Wy1D4jpKQ27+2tTTIgY1CChWPoScsXHkD8lr 0P6Gw5b3/o55S51FpyIgnI47R4Mjyc+fi3OKt4ZM7+nYvs0Tz/OJ0OcPTitqSr76jut4+DOQr 9B1PVAEnT529tBZnD7mdcRvZKqnJXmEng4r4ym+slBkymx47cndspy693li11Oy/InFzLWDeM pXMhCPPJ3R7wTE8w4GB17+Sha5TIORHWP0Jr/GujYUn+YHuZLP38SMqwnmwSR4kNs0Zfecohc lXNQYIDi+JjzTrra2rIddtxypNZ5fU4wKKyZTUB741afadrR4JE2sWDVAYOnRLYH0t4LjcA3h oLZbktxPD2De3QHfk9h9xXirvofFRlbByM3YLOdN5ABaIF+c0+FiELp4dF9RcrM7R/F2TJ53A iuRX1RuNpDhZ0BvH/+1fagV9SkUVDW08Jhg3pJZZiLzTlSJaj1rfDSc0cJmSwMLOWvfiG2OZN VKHA320RE8xfIkpJVkUH5Vv5As0hFxKTsoBTeH+3+V/SGeydkEZrow1mA4QsQgy7o0Fg5ap08 a5fDq5Wnf5eZjrfZbFnZAPKXr+oAR8Jqq1/PtDZGwo1BLoRYSJ06baLJ2G57LU8dWKuvfunY7 0JefYovm4B5FJ2BW Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday 18 November 2015 11:35:27 Andy Shevchenko wrote: > On Fri, Nov 13, 2015 at 11:35 AM, Arnd Bergmann wrote: > > On Friday 13 November 2015 03:10:13 Andy Shevchenko wrote: > >> On Thu, Nov 12, 2015 at 4:14 PM, Arnd Bergmann wrote: > >> > The dw_mmc driver stores the physical address of the MMIO registers > >> > in a pointer, which requires the use of type casts, and is actually > >> > broken if anyone ever has this device on a 32-bit SoC in registers > >> > above 4GB. Gcc warns about this possibility when the driver is built > >> > with ARM LPAE enabled: > >> > >> > - host->phy_regs = (void *)(regs->start); > >> > + host->phy_regs = regs->start; > >> > >> > /* Set external dma config: burst size, burst width */ > >> > - cfg.dst_addr = (dma_addr_t)(host->phy_regs + fifo_offset); > >> > + cfg.dst_addr = host->phy_regs + fifo_offset; > >> > >> dst_addr is dma_addr_t? > > > > Sort of. It doesn't really fit into any of the categories, and we actually > > had a patch to change the type in the past, see > > https://lkml.org/lkml/2015/7/10/167. Not sure what is going on there. > > > >> > /* Registers's physical base address */ > >> > - void *phy_regs; > >> > + resource_size_t phy_regs; > >> > >> If dst_addr is dma_addr_t wouldn't be a problem when > >> resource_size_t is defined as 64-bit address, and dma_addr_t as 32-bit? > >> > >> Btw, for me casting to dma_addr_t looks sane. > > > > The background here is that the address comes from a resource_size_t > > that describes the MMIO register area as seen from the CPU, and that > > is normally a phys_addr_t (resource_size_t is defined as being long > > enough to store a phys_addr_t or various other things depending on > > resource->flags). > > > > dma_addr_t strictly speaking refers to a RAM location as seen by a > > DMA master, and that only comes out of dma_map_*() or > > dma_alloc_coherent(). > > > > The DMA engine wants something else here, which is an MMIO register > > address as seen by a DMA master, and we don't have a separate typedef > > for that. Almost universally all of resource_size_t, phys_addr_t and > > dma_addr_t are the same type, and if we ever get a platform that > > wants something other than a phys_addr_t to put into cfg.dst_addr, > > we are in deep trouble. > > DMA operates with address space covered by dma_addr_t, if you use > phys_addr_t you may get address out of DMA boundaries. This is should > be done in hardware / firmware / platform representation. > So, I don't see any reason not to use dma_addr_t here. As I said above, this isn't really the same as DMA: all normal dma_addr_t are returned from dma_alloc_* or dma_map_*, point to RAM and might go trhough an IOMMU, all of which is not true here, hence the patch to change the type to phys_addr_t. You really can't get out of bounds because the data comes from a phys_addr_t and refers to a fixed location in hardware. If a platform has registers higher than a 32-bit address, its phys_addr_t must be 64-bit, but its dma_addr_t not necessarily so (even though the two are the same almost always in practice). Arnd