All of lore.kernel.org
 help / color / mirror / Atom feed
From: Grygorii Strashko via iommu <iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
To: Russell King - ARM Linux
	<linux-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org>,
	Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org,
	x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	sudeep.holla-5wv7dgnIgG8@public.gmane.org,
	frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	hch-jcswGhMUV9g@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH v2 7/7] OF: Don't set default coherent DMA mask
Date: Fri, 27 Jul 2018 13:45:26 -0500	[thread overview]
Message-ID: <affa2718-5f3a-7439-db25-ce171a99414a@ti.com> (raw)
In-Reply-To: <20180727181302.GC17271-l+eeeJia6m9URfEZ8mYm6t73F7V6hmMc@public.gmane.org>



On 07/27/2018 01:13 PM, Russell King - ARM Linux wrote:
> On Fri, Jul 27, 2018 at 12:36:00PM +0100, Robin Murphy wrote:
>> That is intentional. Consider a 32-bit device on a bus with an upstream DMA
>> range of 40 bits (which could easily happen with e.g. PCI). If the firmware
>> code gives that device 40-bit DMA masks and the driver doesn't change them,
>> then DMA is not going to work correctly. Therefore the firmware code cannot
>> safely make {coherent_}dma_mask larger than the default value passed in, and
>> if the default is 0 then that should be fixed in whatever code created the
>> device, not worked around later.
> 
> I think you're missing the point.
> 
> When OF creates platform devices, they are created without any DMA masks
> what so ever.  It is only during device probe that dma_configure() gets
> called, which then calls of_dma_configure(), where the DMA mask for any
> DT declared device is setup.
> 
> What this means is that your change has broken all existing DT devices
> that are trying to use DMA, because they now end up with a zero coherent
> DMA mask and/or streaming DMA mask.
> 
> Your original idea behind the patch may be a sound one, but since the
> implementation has caused a regression, the implementation is obviously
> broken, and that needs fixing or reworking in some way.
> 

There was additional patch [1] which fixes an issue.

But I have a question to all:
- The patch [1] sets default DMA mask to DMA_BIT_MASK(32)
+	dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+	if (!dev->dev.dma_mask)
+		dev->dev.dma_mask = &dev->dev.coherent_dma_mask;

this will also work the same way for ARM64

- But of_dma_configure() still have code which does:
	dev->coherent_dma_mask &= mask;
	*dev->dma_mask &= mask;

As result, DMA mask supplied from DT will always be truncated
 to 32 bit for platform devices. for example:

soc0: soc0 {
        compatible = "simple-bus";
        #address-cells = <2>;
        #size-cells = <2>;
        ranges;
+        dma-ranges = <0 0 0 0 0x10000 0>; 

^ 48 bit DMA mask expected to be generated and assigned.

But real mask will be DMA_BIT_MASK(32). As result, any 
DMA capable driver will have be modified to do dma_set_xxx_mask(),
which disregards DT DMA configuration (especially for HW modules
which are used on ARM32 and ARM64).

Could it be considered to do one the changes below?

1) assign mask in case of dt
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 5957cd4..f7dc121 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -150,8 +150,8 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma)
         */
        mask = DMA_BIT_MASK(ilog2(dma_addr + size - 1) + 1);
        dev->bus_dma_mask = mask;
-       dev->coherent_dma_mask &= mask;
-       *dev->dma_mask &= mask;
+       dev->coherent_dma_mask = mask;
+       *dev->dma_mask = mask;
 
        coherent = of_dma_is_coherent(np);

2) use BITS_PER_LONG for default DMA mask for of_platform devices

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 7ba90c2..3f326e2 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -185,7 +185,7 @@ static struct platform_device *of_platform_device_create_pdata(
        if (!dev)
                goto err_clear_flag;
 
-       dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+       dev->dev.coherent_dma_mask = DMA_BIT_MASK(BITS_PER_LONG);
        if (!dev->dev.dma_mask)
                dev->dev.dma_mask = &dev->dev.coherent_dma_mask;

3) ...

[1] https://www.spinics.net/lists/arm-kernel/msg668934.html
-- 
regards,
-grygorii

WARNING: multiple messages have this Message-ID (diff)
From: grygorii.strashko@ti.com (Grygorii Strashko)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 7/7] OF: Don't set default coherent DMA mask
Date: Fri, 27 Jul 2018 13:45:26 -0500	[thread overview]
Message-ID: <affa2718-5f3a-7439-db25-ce171a99414a@ti.com> (raw)
In-Reply-To: <20180727181302.GC17271@n2100.armlinux.org.uk>



On 07/27/2018 01:13 PM, Russell King - ARM Linux wrote:
> On Fri, Jul 27, 2018 at 12:36:00PM +0100, Robin Murphy wrote:
>> That is intentional. Consider a 32-bit device on a bus with an upstream DMA
>> range of 40 bits (which could easily happen with e.g. PCI). If the firmware
>> code gives that device 40-bit DMA masks and the driver doesn't change them,
>> then DMA is not going to work correctly. Therefore the firmware code cannot
>> safely make {coherent_}dma_mask larger than the default value passed in, and
>> if the default is 0 then that should be fixed in whatever code created the
>> device, not worked around later.
> 
> I think you're missing the point.
> 
> When OF creates platform devices, they are created without any DMA masks
> what so ever.  It is only during device probe that dma_configure() gets
> called, which then calls of_dma_configure(), where the DMA mask for any
> DT declared device is setup.
> 
> What this means is that your change has broken all existing DT devices
> that are trying to use DMA, because they now end up with a zero coherent
> DMA mask and/or streaming DMA mask.
> 
> Your original idea behind the patch may be a sound one, but since the
> implementation has caused a regression, the implementation is obviously
> broken, and that needs fixing or reworking in some way.
> 

There was additional patch [1] which fixes an issue.

But I have a question to all:
- The patch [1] sets default DMA mask to DMA_BIT_MASK(32)
+	dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+	if (!dev->dev.dma_mask)
+		dev->dev.dma_mask = &dev->dev.coherent_dma_mask;

this will also work the same way for ARM64

- But of_dma_configure() still have code which does:
	dev->coherent_dma_mask &= mask;
	*dev->dma_mask &= mask;

As result, DMA mask supplied from DT will always be truncated
 to 32 bit for platform devices. for example:

soc0: soc0 {
        compatible = "simple-bus";
        #address-cells = <2>;
        #size-cells = <2>;
        ranges;
+        dma-ranges = <0 0 0 0 0x10000 0>; 

^ 48 bit DMA mask expected to be generated and assigned.

But real mask will be DMA_BIT_MASK(32). As result, any 
DMA capable driver will have be modified to do dma_set_xxx_mask(),
which disregards DT DMA configuration (especially for HW modules
which are used on ARM32 and ARM64).

Could it be considered to do one the changes below?

1) assign mask in case of dt
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 5957cd4..f7dc121 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -150,8 +150,8 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma)
         */
        mask = DMA_BIT_MASK(ilog2(dma_addr + size - 1) + 1);
        dev->bus_dma_mask = mask;
-       dev->coherent_dma_mask &= mask;
-       *dev->dma_mask &= mask;
+       dev->coherent_dma_mask = mask;
+       *dev->dma_mask = mask;
 
        coherent = of_dma_is_coherent(np);

2) use BITS_PER_LONG for default DMA mask for of_platform devices

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 7ba90c2..3f326e2 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -185,7 +185,7 @@ static struct platform_device *of_platform_device_create_pdata(
        if (!dev)
                goto err_clear_flag;
 
-       dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+       dev->dev.coherent_dma_mask = DMA_BIT_MASK(BITS_PER_LONG);
        if (!dev->dev.dma_mask)
                dev->dev.dma_mask = &dev->dev.coherent_dma_mask;

3) ...

[1] https://www.spinics.net/lists/arm-kernel/msg668934.html
-- 
regards,
-grygorii

  parent reply	other threads:[~2018-07-27 18:45 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-23 22:16 [PATCH v2 0/7] Stop losing firmware-set DMA masks Robin Murphy
2018-07-23 22:16 ` Robin Murphy
2018-07-23 22:16 ` [PATCH v2 1/7] ACPI/IORT: Support address size limit for root complexes Robin Murphy
2018-07-23 22:16   ` Robin Murphy
2018-07-23 22:16 ` [PATCH v2 2/7] dma-mapping: Generalise dma_32bit_limit flag Robin Murphy
2018-07-23 22:16   ` Robin Murphy
     [not found]   ` <c1720f0181b66f711e4097d85149757b16a7b0a7.1532382222.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-07-25 11:29     ` Christoph Hellwig
2018-07-25 11:29       ` Christoph Hellwig
2018-07-27 17:45     ` Grygorii Strashko via iommu
2018-07-27 17:45       ` Grygorii Strashko
     [not found]       ` <7872d914-8ea7-06e4-4a0c-489023e098d6-l0cyMroinI0@public.gmane.org>
2018-07-27 20:11         ` Robin Murphy
2018-07-27 20:11           ` Robin Murphy
     [not found]           ` <5354ef69-c54e-170b-62d4-5110dc60aa8f-5wv7dgnIgG8@public.gmane.org>
2018-07-27 20:41             ` Grygorii Strashko via iommu
2018-07-27 20:41               ` Grygorii Strashko
2018-07-23 22:16 ` [PATCH v2 3/7] ACPI/IORT: Set bus DMA mask as appropriate Robin Murphy
2018-07-23 22:16   ` Robin Murphy
     [not found]   ` <07cbf8f77fac552dca9b4c85a9d3bd8ed5a4cd29.1532382222.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-07-25 11:29     ` Christoph Hellwig
2018-07-25 11:29       ` Christoph Hellwig
2018-07-25 13:16     ` Lorenzo Pieralisi
2018-07-25 13:16       ` Lorenzo Pieralisi
2018-07-23 22:16 ` [PATCH v2 4/7] of/device: " Robin Murphy
2018-07-23 22:16   ` Robin Murphy
     [not found]   ` <cc56f074b8da7e03a187b2363b1f2c2955d62c1c.1532382222.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-07-25 11:30     ` Christoph Hellwig
2018-07-25 11:30       ` Christoph Hellwig
2018-07-23 22:16 ` [PATCH v2 5/7] iommu/dma: Respect bus DMA limit for IOVAs Robin Murphy
2018-07-23 22:16   ` Robin Murphy
     [not found]   ` <d370670edae9c9c537a5280c5e7c96bf3ec7ed8f.1532382222.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-07-26  8:58     ` Christoph Hellwig
2018-07-26  8:58       ` Christoph Hellwig
2018-07-23 22:16 ` [PATCH v2 6/7] ACPI/IORT: Don't set default coherent DMA mask Robin Murphy
2018-07-23 22:16   ` Robin Murphy
     [not found]   ` <3525869e8e7530128bf9718ae8af7d7564b3c684.1532382222.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-07-25 15:27     ` Lorenzo Pieralisi
2018-07-25 15:27       ` Lorenzo Pieralisi
2018-07-25 15:43       ` Robin Murphy
2018-07-25 15:43         ` Robin Murphy
2018-07-23 22:16 ` [PATCH v2 7/7] OF: " Robin Murphy
2018-07-23 22:16   ` Robin Murphy
     [not found]   ` <66c08e4df2032fde82a2f97544f41fd3a2f24a94.1532382222.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-07-26 23:52     ` Grygorii Strashko via iommu
2018-07-26 23:52       ` Grygorii Strashko
2018-07-27  0:22       ` Grygorii Strashko
2018-07-27  0:22         ` Grygorii Strashko
     [not found]         ` <92d6b010-b5c0-fc59-0668-5b455e26c912-l0cyMroinI0@public.gmane.org>
2018-07-27 11:36           ` Robin Murphy
2018-07-27 11:36             ` Robin Murphy
2018-07-27 17:34             ` Grygorii Strashko
2018-07-27 17:34               ` Grygorii Strashko
     [not found]               ` <108a6254-1257-5daf-deaa-69bc4db2ec77-l0cyMroinI0@public.gmane.org>
2018-07-27 19:46                 ` Robin Murphy
2018-07-27 19:46                   ` Robin Murphy
     [not found]             ` <c7a9c7ae-1f4a-af9d-df78-1f48bb5c28a5-5wv7dgnIgG8@public.gmane.org>
2018-07-27 18:13               ` Russell King - ARM Linux
2018-07-27 18:13                 ` Russell King - ARM Linux
     [not found]                 ` <20180727181302.GC17271-l+eeeJia6m9URfEZ8mYm6t73F7V6hmMc@public.gmane.org>
2018-07-27 18:45                   ` Grygorii Strashko via iommu [this message]
2018-07-27 18:45                     ` Grygorii Strashko
     [not found]                     ` <affa2718-5f3a-7439-db25-ce171a99414a-l0cyMroinI0@public.gmane.org>
2018-07-27 20:42                       ` Robin Murphy
2018-07-27 20:42                         ` Robin Murphy
2018-07-27 19:29                   ` Robin Murphy
2018-07-27 19:29                     ` Robin Murphy
2018-07-26 23:45 ` [PATCH v2 0/7] Stop losing firmware-set DMA masks Grygorii Strashko
2018-07-26 23:45   ` Grygorii Strashko
     [not found]   ` <c73bc8d2-b745-ff31-1949-7a59ab04ede6-l0cyMroinI0@public.gmane.org>
2018-07-27 10:55     ` Robin Murphy
2018-07-27 10:55       ` Robin Murphy
     [not found]       ` <8b8ac841-5c4c-ae27-21d5-d7aaaf4c277c-5wv7dgnIgG8@public.gmane.org>
2018-07-27 17:22         ` Grygorii Strashko via iommu
2018-07-27 17:22           ` Grygorii Strashko
     [not found] ` <cover.1532382222.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-07-25 11:31   ` Christoph Hellwig
2018-07-25 11:31     ` Christoph Hellwig
     [not found]     ` <20180725113122.GD24736-jcswGhMUV9g@public.gmane.org>
2018-07-25 12:11       ` Joerg Roedel
2018-07-25 12:11         ` Joerg Roedel
2018-07-25 12:12       ` Robin Murphy
2018-07-25 12:12         ` Robin Murphy
     [not found]         ` <5e036ade-db0b-f628-a4a0-6d014d1d76c8-5wv7dgnIgG8@public.gmane.org>
2018-07-25 12:17           ` Will Deacon
2018-07-25 12:17             ` Will Deacon
2018-07-25 13:58       ` Ard Biesheuvel
2018-07-25 13:58         ` Ard Biesheuvel
2018-07-26  9:00   ` Christoph Hellwig
2018-07-26  9:00     ` Christoph Hellwig
2018-07-29 12:32   ` Arnd Bergmann
2018-07-29 12:32     ` Arnd Bergmann
     [not found]     ` <CAK8P3a3HDJ6svNN_cwvegxu20yNv8+tvc0D1A6Ooeq8agawbFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-07-31 11:24       ` Robin Murphy
2018-07-31 11:24         ` Robin Murphy
     [not found]         ` <1ccccc4b-7d4c-a3ee-23a2-f108916705e9-5wv7dgnIgG8@public.gmane.org>
2018-08-06 10:01           ` Arnd Bergmann
2018-08-06 10:01             ` Arnd Bergmann
     [not found]             ` <CAK8P3a3ZcOeHMR_qFnsBdXED+2X8_AEMKoS5MeAQhbapbGmm9w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-08-06 12:13               ` Christoph Hellwig
2018-08-06 12:13                 ` Christoph Hellwig
     [not found]                 ` <20180806121334.GA5340-jcswGhMUV9g@public.gmane.org>
2018-08-06 12:13                   ` Arnd Bergmann
2018-08-06 12:13                     ` Arnd Bergmann

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=affa2718-5f3a-7439-db25-ce171a99414a@ti.com \
    --to=iommu-cuntk1mwbs9qetfly7kem3xjstq8ys+chz5vsktnxna@public.gmane.org \
    --cc=frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=grygorii.strashko-l0cyMroinI0@public.gmane.org \
    --cc=hch-jcswGhMUV9g@public.gmane.org \
    --cc=linux-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org \
    --cc=linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=robin.murphy-5wv7dgnIgG8@public.gmane.org \
    --cc=sudeep.holla-5wv7dgnIgG8@public.gmane.org \
    --cc=x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    /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 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.