iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: Jim Quinlan <james.quinlan@broadcom.com>,
	Nathan Chancellor <natechancellor@gmail.com>,
	Christoph Hellwig <hch@lst.de>
Cc: Rich Felker <dalias@libc.org>,
	"open list:SUPERH" <linux-sh@vger.kernel.org>,
	David Airlie <airlied@linux.ie>,
	"open list:PCI NATIVE HOST BRIDGE AND ENDPOINT DRIVERS"
	<linux-pci@vger.kernel.org>, Hanjun Guo <guohanjun@huawei.com>,
	"open list:REMOTE PROCESSOR REMOTEPROC SUBSYSTEM"
	<linux-remoteproc@vger.kernel.org>,
	"open list:DRM DRIVERS FOR ALLWINNER A10"
	<dri-devel@lists.freedesktop.org>,
	Julien Grall <julien.grall@arm.com>,
	"H. Peter Anvin" <hpa@zytor.com>, Will Deacon <will@kernel.org>,
	Christoph Hellwig <hch@lst.de>,
	"open list:STAGING SUBSYSTEM" <devel@driverdev.osuosl.org>,
	Jean-Philippe Brucker <jean-philippe@linaro.org>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Yoshinori Sato <ysato@users.sourceforge.jp>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Frank Rowand <frowand.list@gmail.com>,
	"maintainer:X86 ARCHITECTURE 32-BIT AND 64-BIT" <x86@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	"open list:ACPI FOR ARM64 ACPI/arm64"
	<linux-acpi@vger.kernel.org>, Chen-Yu Tsai <wens@csie.org>,
	Ingo Molnar <mingo@redhat.com>,
	"maintainer:BROADCOM BCM7XXX ARM ARCHITECTURE"
	<bcm-kernel-feedback-list@broadcom.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	Len Brown <lenb@kernel.org>, Ohad Ben-Cohen <ohad@wizery.com>,
	"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE"
	<devicetree@vger.kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Maxime Ripard <mripard@kernel.org>,
	Rob Herring <robh+dt@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Yong Deng <yong.deng@magewell.com>,
	Santosh Shilimkar <ssantosh@kernel.org>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	"moderated list:ARM PORT" <linux-arm-kernel@lists.infradead.org>,
	Felipe Balbi <balbi@kernel.org>,
	Saravana Kannan <saravanak@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"open list:USB SUBSYSTEM" <linux-usb@vger.kernel.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	open list <linux-kernel@vger.kernel.org>,
	Paul Kocialkowski <paul.kocialkowski@bootlin.com>,
	"open list:IOMMU DRIVERS" <iommu@lists.linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Daniel Vetter <daniel@ffwll.ch>,
	Sudeep Holla <sudeep.holla@arm.com>,
	"open list:ALLWINNER A10 CSI DRIVER"
	<linux-media@vger.kernel.org>,
	Robin Murphy <robin.murphy@arm.com>
Subject: Re: [PATCH v11 07/11] device-mapping: Introduce DMA range map, supplanting dma_pfn_offset
Date: Mon, 07 Sep 2020 17:01:08 +0200	[thread overview]
Message-ID: <34aa0d6094e7d6fb3492d2cda0fec8ecc04790ed.camel@suse.de> (raw)
In-Reply-To: <CA+-6iNyv_sFJOxDi5OcYNWe=ovLnOnrZNsWFQk5b-bzQzA8T_Q@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 3806 bytes --]

Hi Jim, sorry I'm a little late to the party, but was on vacation.

On Thu, 2020-09-03 at 13:32 -0400, Jim Quinlan wrote:
> On Wed, Sep 2, 2020 at 8:52 PM Nathan Chancellor
> <natechancellor@gmail.com> wrote:
> > On Wed, Sep 02, 2020 at 05:36:29PM -0700, Florian Fainelli wrote:
> > > 
> > > On 9/2/2020 3:38 PM, Nathan Chancellor wrote:
> > > [snip]
> > > > > Hello Nathan,
> > > > > 
> > > > > Can you tell me how much memory your RPI has and if all of it is
> > > > 
> > > > This is the 4GB version.
> > > > 
> > > > > accessible by the PCIe device?  Could you also please include the DTS
> > > > > of the PCIe node?  IIRC, the RPI firmware does some mangling of the
> > > > > PCIe DT before Linux boots -- could you describe what is going on
> > > > > there?
> > > > 
> > > > Unfortunately, I am not familiar with how to get this information. If
> > > > you could provide some instructions for how to do so, I am more than
> > > > happy to. I am not very knowleagable about the inner working of the Pi,
> > > > I mainly use it as a test platform for making sure that LLVM does not
> > > > cause problems on real devices.
> > > 
> > > Can you bring the dtc application to your Pi root filesystem, and if so, can
> > > you run the following:
> > > 
> > > dtc -I fs -O dtb /proc/device-tree -f > /tmp/device.dtb
> > 
> > Sure, the result is attached.
> > 
> > > or cat /sys/firmware/fdt > device.dtb
> > > 
> > > and attach the resulting file?
> > > 
> > > > > Finally, can you attach the text of the full boot log?
> > > > 
> > > > I have attached a working and broken boot log. Thank you for the quick
> > > > response!
> > > 
> > > Is it possible for you to rebuild your kernel with CONFIG_MMC_DEBUG by any
> > > chance?
> > 
> > Of course. A new log is attached with the debug output from that config.
> 
> Hi Nicolas,
> 
> Can you please help us out here?  It appears that your commit

It's dma_offset_from_dma_addr() that's causing trouble. It goes over all the
dma regions and, if no region matches the phys address range, it returns 0.
This isn't acceptable as is. In the past, we used to pass the offset
nonetheless, which would make the phys address grow out of the dma memory area
and fail the dma_capable() test.

For example, RPi4 devices attached to the old interconnect see phys [0x0
0x3fffffff] at [0xc0000000 0xffffffff]. So say you're trying to convert
physical address 0xfa000000, you'll get 0 from dma_offset_from_phys_addr()
(since your dma range only covers the first GB) to then test if 0xfa000000 is
dma_capable(), which it is, but for the wrong reasons. Causing DMA issues
further down the line.

I don't have a proper suggestion on how to solve this but here's the solution I
used:

diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 4c4646761afe..40fe3c97f2be 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -217,11 +217,19 @@ static inline u64 dma_offset_from_phys_addr(struct device *dev,
 {
        const struct bus_dma_region *m = dev->dma_range_map;
 
-       if (m)
+       if (m) {
                for (; m->size; m++)
                        if (paddr >= m->cpu_start &&
                            paddr - m->cpu_start < m->size)
                                return m->offset;
+
+               /*
+                * The physical address doesn't fit any of the DMA regions,
+                * return an impossible to fulfill offset.
+                */
+               return -(1ULL << 46);
+       }
+
        return 0;
 }

I didn't catch this on my previous tests as I was using a newer bcm2711 SoC
revision which expanded emmc2's DMA capabilities (can do 32 bit DMA as opposed
to 30 bit).

Regards,
Nicolas


[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 156 bytes --]

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2020-09-07 15:01 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-24 19:30 [PATCH v11 00/11] PCI: brcmstb: enable PCIe for STB chips Jim Quinlan via iommu
2020-08-24 19:30 ` [PATCH v11 07/11] device-mapping: Introduce DMA range map, supplanting dma_pfn_offset Jim Quinlan via iommu
2020-08-25  9:45   ` Andy Shevchenko
2020-08-25 15:37     ` Jim Quinlan via iommu
2020-09-01  8:24   ` Christoph Hellwig
2020-09-02 15:02     ` Jim Quinlan via iommu
2020-09-03 16:06       ` Christoph Hellwig
2020-09-07 15:18     ` Nicolas Saenz Julienne
2020-09-08  6:54       ` Christoph Hellwig
2020-09-02 21:53   ` Nathan Chancellor
2020-09-02 22:11     ` Jim Quinlan via iommu
2020-09-02 22:38       ` Nathan Chancellor
2020-09-03  0:36         ` Florian Fainelli
2020-09-03  0:52           ` Nathan Chancellor
2020-09-03 17:32             ` Jim Quinlan via iommu
2020-09-07 15:01               ` Nicolas Saenz Julienne [this message]
2020-09-07 17:40                 ` Jim Quinlan via iommu
2020-09-07 18:19                   ` Nicolas Saenz Julienne
2020-09-08  6:59                     ` Christoph Hellwig
2020-09-08  7:29                     ` Christoph Hellwig
2020-09-08  7:32                       ` Christoph Hellwig
2020-09-08  9:43                         ` Christoph Hellwig
2020-09-08 11:20                           ` Nicolas Saenz Julienne
2020-09-08 12:41                             ` Christoph Hellwig
2020-09-08 15:59                           ` Jim Quinlan via iommu
2020-09-09  6:21                           ` Nathan Chancellor
2020-09-08  6:58                   ` Christoph Hellwig
2020-08-25 17:40 ` [PATCH v11 00/11] PCI: brcmstb: enable PCIe for STB chips Florian Fainelli
2020-08-27  6:35   ` Christoph Hellwig
2020-08-27 13:29     ` Jim Quinlan via iommu
2020-09-07  9:16       ` Lorenzo Pieralisi
2020-09-07 17:43         ` Jim Quinlan via iommu
2020-09-07 18:29           ` Florian Fainelli
2020-09-08 10:42             ` Lorenzo Pieralisi
2020-09-08 12:20               ` Christoph Hellwig

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=34aa0d6094e7d6fb3492d2cda0fec8ecc04790ed.camel@suse.de \
    --to=nsaenzjulienne@suse.de \
    --cc=airlied@linux.ie \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=balbi@kernel.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=dalias@libc.org \
    --cc=dan.j.williams@intel.com \
    --cc=daniel@ffwll.ch \
    --cc=devel@driverdev.osuosl.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=f.fainelli@gmail.com \
    --cc=frowand.list@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=guohanjun@huawei.com \
    --cc=hch@lst.de \
    --cc=hpa@zytor.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=james.quinlan@broadcom.com \
    --cc=jean-philippe@linaro.org \
    --cc=julien.grall@arm.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mchehab@kernel.org \
    --cc=mingo@redhat.com \
    --cc=mripard@kernel.org \
    --cc=natechancellor@gmail.com \
    --cc=ohad@wizery.com \
    --cc=paul.kocialkowski@bootlin.com \
    --cc=rjw@rjwysocki.net \
    --cc=robh+dt@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=saravanak@google.com \
    --cc=ssantosh@kernel.org \
    --cc=sstabellini@kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=sudeep.holla@arm.com \
    --cc=tglx@linutronix.de \
    --cc=wens@csie.org \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    --cc=yong.deng@magewell.com \
    --cc=ysato@users.sourceforge.jp \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).