From: Russell King - ARM Linux <linux@armlinux.org.uk> To: Bjorn Helgaas <helgaas@kernel.org> Cc: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>, Mark Rutland <mark.rutland@arm.com>, Mason <slash.tmp@free.fr>, Marc Zyngier <marc.zyngier@arm.com>, linux-pci <linux-pci@vger.kernel.org>, Thibaud Cornic <thibaud_cornic@sigmadesigns.com>, Ard Biesheuvel <ard.biesheuvel@linaro.org>, LKML <linux-kernel@vger.kernel.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Thomas Gleixner <tglx@linutronix.de>, Linux ARM <linux-arm-kernel@lists.infradead.org> Subject: Re: [PATCH v9 2/3] PCI: Add tango PCIe host bridge support Date: Tue, 4 Jul 2017 19:17:37 +0100 [thread overview] Message-ID: <20170704181737.GF4902@n2100.armlinux.org.uk> (raw) In-Reply-To: <20170704151502.GH13824@bhelgaas-glaptop.roam.corp.google.com> On Tue, Jul 04, 2017 at 10:15:02AM -0500, Bjorn Helgaas wrote: > On Mon, Jul 03, 2017 at 07:11:28PM +0100, Russell King - ARM Linux wrote: > > On Mon, Jul 03, 2017 at 08:40:31AM -0500, Bjorn Helgaas wrote: > > > The problem is serializing vs. memory accesses, since they don't use > > > any wrappers. However, they are ioremapped(), so it's at least > > > conceivable that another solution would be to use VM to trap those > > > accesses. I'm not a VM person, so I don't know whether that's > > > feasible in Linux. > > > > Bjorn, > > > > You're forgetting that MMIO (iow, memory returned by ioremap()) must > > be accessed through the appropriate accessors, and must not be > > directly dereferenced in C. (We do have buggy drivers that do that > > but they are buggy, and in many cases are getting attention to fix > > that.) > > Oh, you're right, thank you! I guess you're referring to readb() > and friends. I haven't found an actual prohibition on directly > dereferencing addresses returned from ioremap(), but > Documentation/driver-api/device-io.rst is clear that they're > suitable for passing to readb(), etc. There was a strong suggestion years ago that what is returned from ioremap() is a cookie that must not be dereferenced by drivers, and that there was a suggestion that having ioremap() return the virtual address with an offset (which read*() and friends would undo) would be a good idea. However, even back then, we had some cases where drivers would directly dereference the pointer. We have sparse today which helps point these places out (provided drivers stay away from __force, but unfortunately, I think we've ended up with people who think that silencing sparse warnings with __force is more preferable than leaving them there to point out where things are actually wrong.) So, imho, unfortunately sparse has lost its usefulness in this regard. > I recently told someone else my mistaken idea that ioremap() must > return a valid virtual address. I wish I remembered who it was, so I > could correct that. Documentation/DMA-API-HOWTO.txt also suggests > that ioremap() returns a virtual address -- I think I wrote that, and > maybe that virtual address reference should be tweaked a bit. For most implementations, ioremap() does indeed return a virtual address, but that was never how the API was defined in the first place - it was always referred to as returning a cookie. > Another wrinkle is that the pci_mmap_resource() interface is exposed > via sysfs and allows direct userspace mmap of PCI MMIO resources. In > that case, there is no accessor available. I wonder if we need some > way to disable this mmap when readb() is non-trivial. Hmm, no comment, except that while the PCI MMIO space is available to userspace, and userspace is capable of running that thread on any CPU, PCI MMIO space can't be switched to config space. That's another nail in this coffin... -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
WARNING: multiple messages have this Message-ID (diff)
From: linux@armlinux.org.uk (Russell King - ARM Linux) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v9 2/3] PCI: Add tango PCIe host bridge support Date: Tue, 4 Jul 2017 19:17:37 +0100 [thread overview] Message-ID: <20170704181737.GF4902@n2100.armlinux.org.uk> (raw) In-Reply-To: <20170704151502.GH13824@bhelgaas-glaptop.roam.corp.google.com> On Tue, Jul 04, 2017 at 10:15:02AM -0500, Bjorn Helgaas wrote: > On Mon, Jul 03, 2017 at 07:11:28PM +0100, Russell King - ARM Linux wrote: > > On Mon, Jul 03, 2017 at 08:40:31AM -0500, Bjorn Helgaas wrote: > > > The problem is serializing vs. memory accesses, since they don't use > > > any wrappers. However, they are ioremapped(), so it's at least > > > conceivable that another solution would be to use VM to trap those > > > accesses. I'm not a VM person, so I don't know whether that's > > > feasible in Linux. > > > > Bjorn, > > > > You're forgetting that MMIO (iow, memory returned by ioremap()) must > > be accessed through the appropriate accessors, and must not be > > directly dereferenced in C. (We do have buggy drivers that do that > > but they are buggy, and in many cases are getting attention to fix > > that.) > > Oh, you're right, thank you! I guess you're referring to readb() > and friends. I haven't found an actual prohibition on directly > dereferencing addresses returned from ioremap(), but > Documentation/driver-api/device-io.rst is clear that they're > suitable for passing to readb(), etc. There was a strong suggestion years ago that what is returned from ioremap() is a cookie that must not be dereferenced by drivers, and that there was a suggestion that having ioremap() return the virtual address with an offset (which read*() and friends would undo) would be a good idea. However, even back then, we had some cases where drivers would directly dereference the pointer. We have sparse today which helps point these places out (provided drivers stay away from __force, but unfortunately, I think we've ended up with people who think that silencing sparse warnings with __force is more preferable than leaving them there to point out where things are actually wrong.) So, imho, unfortunately sparse has lost its usefulness in this regard. > I recently told someone else my mistaken idea that ioremap() must > return a valid virtual address. I wish I remembered who it was, so I > could correct that. Documentation/DMA-API-HOWTO.txt also suggests > that ioremap() returns a virtual address -- I think I wrote that, and > maybe that virtual address reference should be tweaked a bit. For most implementations, ioremap() does indeed return a virtual address, but that was never how the API was defined in the first place - it was always referred to as returning a cookie. > Another wrinkle is that the pci_mmap_resource() interface is exposed > via sysfs and allows direct userspace mmap of PCI MMIO resources. In > that case, there is no accessor available. I wonder if we need some > way to disable this mmap when readb() is non-trivial. Hmm, no comment, except that while the PCI MMIO space is available to userspace, and userspace is capable of running that thread on any CPU, PCI MMIO space can't be switched to config space. That's another nail in this coffin... -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
next prev parent reply other threads:[~2017-07-04 18:17 UTC|newest] Thread overview: 109+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-06-20 8:12 [PATCH v9 0/3] Tango PCIe controller support Marc Gonzalez 2017-06-20 8:12 ` Marc Gonzalez 2017-06-20 8:12 ` Marc Gonzalez 2017-06-20 8:14 ` [PATCH v9 1/3] PCI: Add DT binding for tango PCIe controller Marc Gonzalez 2017-06-20 8:14 ` Marc Gonzalez 2017-06-20 8:14 ` Marc Gonzalez 2017-06-20 8:17 ` [PATCH v9 2/3] PCI: Add tango PCIe host bridge support Marc Gonzalez 2017-06-20 8:17 ` Marc Gonzalez 2017-06-20 8:17 ` Marc Gonzalez 2017-07-02 23:18 ` Bjorn Helgaas 2017-07-02 23:18 ` Bjorn Helgaas 2017-07-02 23:18 ` Bjorn Helgaas 2017-07-03 9:35 ` Ard Biesheuvel 2017-07-03 9:35 ` Ard Biesheuvel 2017-07-03 13:27 ` Bjorn Helgaas 2017-07-03 13:27 ` Bjorn Helgaas 2017-07-03 13:27 ` Bjorn Helgaas 2017-07-04 6:58 ` Jisheng Zhang 2017-07-04 6:58 ` Jisheng Zhang 2017-07-04 6:58 ` Jisheng Zhang 2017-07-04 7:16 ` Jisheng Zhang 2017-07-04 7:16 ` Jisheng Zhang 2017-07-04 8:02 ` Ard Biesheuvel 2017-07-04 8:02 ` Ard Biesheuvel 2017-07-04 8:19 ` Jisheng Zhang 2017-07-04 8:19 ` Jisheng Zhang 2017-07-04 8:19 ` Jisheng Zhang 2017-07-04 9:38 ` Ard Biesheuvel 2017-07-04 9:38 ` Ard Biesheuvel 2017-07-05 13:53 ` Joao Pinto 2017-07-05 13:53 ` Joao Pinto 2017-07-03 9:54 ` Marc Gonzalez 2017-07-03 9:54 ` Marc Gonzalez 2017-07-03 9:54 ` Marc Gonzalez 2017-07-03 13:13 ` Marc Gonzalez 2017-07-03 13:13 ` Marc Gonzalez 2017-07-03 15:30 ` Marc Gonzalez 2017-07-03 15:30 ` Marc Gonzalez 2017-07-03 15:30 ` Marc Gonzalez 2017-07-04 7:09 ` Peter Zijlstra 2017-07-04 7:09 ` Peter Zijlstra 2017-07-04 13:08 ` Mason 2017-07-04 13:08 ` Mason 2017-07-04 14:27 ` Peter Zijlstra 2017-07-04 14:27 ` Peter Zijlstra 2017-07-04 15:18 ` Mason 2017-07-04 15:18 ` Mason 2017-07-03 13:40 ` Bjorn Helgaas 2017-07-03 13:40 ` Bjorn Helgaas 2017-07-03 13:40 ` Bjorn Helgaas 2017-07-03 14:34 ` Marc Gonzalez 2017-07-03 14:34 ` Marc Gonzalez 2017-07-03 14:34 ` Marc Gonzalez 2017-07-04 15:58 ` Bjorn Helgaas 2017-07-04 15:58 ` Bjorn Helgaas 2017-07-04 15:58 ` Bjorn Helgaas 2017-07-04 23:42 ` Mason 2017-07-04 23:42 ` Mason 2017-07-03 18:11 ` Russell King - ARM Linux 2017-07-03 18:11 ` Russell King - ARM Linux 2017-07-03 18:44 ` Ard Biesheuvel 2017-07-03 18:44 ` Ard Biesheuvel 2017-07-04 15:15 ` Bjorn Helgaas 2017-07-04 15:15 ` Bjorn Helgaas 2017-07-04 15:15 ` Bjorn Helgaas 2017-07-04 18:17 ` Russell King - ARM Linux [this message] 2017-07-04 18:17 ` Russell King - ARM Linux 2017-07-04 23:59 ` Mason 2017-07-04 23:59 ` Mason 2017-07-05 5:21 ` Greg Kroah-Hartman 2017-07-05 5:21 ` Greg Kroah-Hartman 2017-07-05 12:33 ` Mark Brown 2017-07-05 12:33 ` Mark Brown 2017-06-20 8:18 ` [PATCH v9 3/3] PCI: Add tango MSI controller support Marc Gonzalez 2017-06-20 8:18 ` Marc Gonzalez 2017-06-20 8:18 ` Marc Gonzalez 2017-07-04 20:24 ` [PATCH v9 0/3] Tango PCIe " Bjorn Helgaas 2017-07-04 20:24 ` Bjorn Helgaas 2017-07-04 20:24 ` Bjorn Helgaas 2017-07-04 22:55 ` Mason 2017-07-04 22:55 ` Mason 2017-07-04 22:55 ` Mason 2017-07-05 18:03 ` Bjorn Helgaas 2017-07-05 18:03 ` Bjorn Helgaas 2017-07-05 18:03 ` Bjorn Helgaas 2017-07-05 20:39 ` Mason 2017-07-05 20:39 ` Mason 2017-07-05 20:39 ` Mason 2017-07-05 21:34 ` Bjorn Helgaas 2017-07-05 21:34 ` Bjorn Helgaas 2017-07-05 21:34 ` Bjorn Helgaas 2017-07-05 21:34 ` Bjorn Helgaas 2017-07-05 21:59 ` Mason 2017-07-05 21:59 ` Mason 2017-07-05 21:59 ` Mason 2017-07-06 3:39 ` Bjorn Helgaas 2017-07-06 3:39 ` Bjorn Helgaas 2017-07-06 3:39 ` Bjorn Helgaas 2017-07-06 3:39 ` Bjorn Helgaas 2017-07-06 12:26 ` Mason 2017-07-06 12:26 ` Mason 2017-07-06 12:40 ` Marc Zyngier 2017-07-06 12:40 ` Marc Zyngier 2017-07-06 12:40 ` Marc Zyngier 2017-07-06 19:46 ` Bjorn Helgaas 2017-07-06 19:46 ` Bjorn Helgaas 2017-07-06 19:46 ` Bjorn Helgaas 2017-07-07 9:55 ` Marc Gonzalez 2017-07-07 9:55 ` Marc Gonzalez
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20170704181737.GF4902@n2100.armlinux.org.uk \ --to=linux@armlinux.org.uk \ --cc=ard.biesheuvel@linaro.org \ --cc=gregkh@linuxfoundation.org \ --cc=helgaas@kernel.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-pci@vger.kernel.org \ --cc=marc.zyngier@arm.com \ --cc=marc_gonzalez@sigmadesigns.com \ --cc=mark.rutland@arm.com \ --cc=slash.tmp@free.fr \ --cc=tglx@linutronix.de \ --cc=thibaud_cornic@sigmadesigns.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.