Re: new SBus related DMA warnings in 4.18+git

2018-08-28 Thread Christoph Hellwig
On Wed, Aug 29, 2018 at 08:47:04AM +0300, Meelis Roos wrote:
> > Updated version including that has survived contact with a sparc cross
> > compiler below.  Note that this is on top of the previous patch adding
> > a dma_mask to struct platform_device, which I've included as well.
> 
> Works completely fine on both Ultra 1 and Ultra 2 - nothing DMA-relaated 
> in dmesg.

Thanks for testing!  I'll submit the patch for 4.19 in a bit.
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: new SBus related DMA warnings in 4.18+git

2018-08-28 Thread Meelis Roos
> Updated version including that has survived contact with a sparc cross
> compiler below.  Note that this is on top of the previous patch adding
> a dma_mask to struct platform_device, which I've included as well.

Works completely fine on both Ultra 1 and Ultra 2 - nothing DMA-relaated 
in dmesg.

-- 
Meelis Roos (mr...@linux.ee)
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: new SBus related DMA warnings in 4.18+git

2018-08-28 Thread Christoph Hellwig
Updated version including that has survived contact with a sparc cross
compiler below.  Note that this is on top of the previous patch adding
a dma_mask to struct platform_device, which I've included as well.
>From e22d27b9bf48c0e3d6eb106f596972c9357ed24d Mon Sep 17 00:00:00 2001
From: Christoph Hellwig 
Date: Mon, 27 Aug 2018 17:23:24 +0200
Subject: driver core: initialize a default DMA mask for platform device

We still treat devices without a DMA mask as defaulting to 32-bits for
both mask, but a few releases ago we've started warning about such
cases, as they require special cases to work around this sloppyness.
Add a dma_mask field to struct platform_object so that we can initialize
the dma_mask pointer in struct device and initialize both masks to
32-bits by default.  Architectures can still override this in
arch_setup_pdev_archdata if needed.

Note that the code looks a little odd with the various conditionals
because we have to support platform_device structures that are
statically allocated.

Signed-off-by: Christoph Hellwig 
---
 drivers/base/platform.c | 15 +--
 include/linux/platform_device.h |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index dff82a3c2caa..baf4b06cf2d9 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -225,6 +225,17 @@ struct platform_object {
 	char name[];
 };
 
+static void setup_pdev_archdata(struct platform_device *pdev)
+{
+	if (!pdev->dev.coherent_dma_mask)
+		pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+	if (!pdev->dma_mask)
+		pdev->dma_mask = DMA_BIT_MASK(32);
+	if (!pdev->dev.dma_mask)
+		pdev->dev.dma_mask = >dma_mask;
+	arch_setup_pdev_archdata(pdev);
+};
+
 /**
  * platform_device_put - destroy a platform device
  * @pdev: platform device to free
@@ -271,7 +282,7 @@ struct platform_device *platform_device_alloc(const char *name, int id)
 		pa->pdev.id = id;
 		device_initialize(>pdev.dev);
 		pa->pdev.dev.release = platform_device_release;
-		arch_setup_pdev_archdata(>pdev);
+		setup_pdev_archdata(>pdev);
 	}
 
 	return pa ? >pdev : NULL;
@@ -472,7 +483,7 @@ EXPORT_SYMBOL_GPL(platform_device_del);
 int platform_device_register(struct platform_device *pdev)
 {
 	device_initialize(>dev);
-	arch_setup_pdev_archdata(pdev);
+	setup_pdev_archdata(pdev);
 	return platform_device_add(pdev);
 }
 EXPORT_SYMBOL_GPL(platform_device_register);
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 1a9f38f27f65..d9dc4883d5fb 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -25,6 +25,7 @@ struct platform_device {
 	int		id;
 	bool		id_auto;
 	struct device	dev;
+	u64		dma_mask;
 	u32		num_resources;
 	struct resource	*resource;
 
-- 
2.18.0

>From b4c6e6779559a1bcda41fad0f2e8b713fcf96446 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig 
Date: Tue, 28 Aug 2018 11:25:51 +0200
Subject: sparc: set a default 32-bit dma mask for OF devices

This keeps the historic default behavior for devices without a DMA mask,
but removes the warning about a lacking DMA mask for doing DMA without
a mask.

Signed-off-by: Christoph Hellwig 
---
 arch/sparc/kernel/of_device_32.c | 5 +
 arch/sparc/kernel/of_device_64.c | 4 
 2 files changed, 9 insertions(+)

diff --git a/arch/sparc/kernel/of_device_32.c b/arch/sparc/kernel/of_device_32.c
index 3641a294ed54..7f3dec7e1e78 100644
--- a/arch/sparc/kernel/of_device_32.c
+++ b/arch/sparc/kernel/of_device_32.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -381,6 +382,10 @@ static struct platform_device * __init scan_one_device(struct device_node *dp,
 	else
 		dev_set_name(>dev, "%08x", dp->phandle);
 
+	op->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+	op->dev.dma_mask = >dma_mask;
+	op->dma_mask = DMA_BIT_MASK(32);
+
 	if (of_device_register(op)) {
 		printk("%s: Could not register of device.\n",
 		   dp->full_name);
diff --git a/arch/sparc/kernel/of_device_64.c b/arch/sparc/kernel/of_device_64.c
index 44e4d4435bed..d94c31822da1 100644
--- a/arch/sparc/kernel/of_device_64.c
+++ b/arch/sparc/kernel/of_device_64.c
@@ -2,6 +2,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -675,6 +676,9 @@ static struct platform_device * __init scan_one_device(struct device_node *dp,
 		dev_set_name(>dev, "root");
 	else
 		dev_set_name(>dev, "%08x", dp->phandle);
+	op->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+	op->dev.dma_mask = >dma_mask;
+	op->dma_mask = DMA_BIT_MASK(32);
 
 	if (of_device_register(op)) {
 		printk("%s: Could not register of device.\n",
-- 
2.18.0

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

Re: new SBus related DMA warnings in 4.18+git

2018-08-28 Thread Meelis Roos
> Based on the other thread here is a new attempt:

  CC  arch/sparc/kernel/of_device_64.o
arch/sparc/kernel/of_device_64.c: In function ‘scan_one_device’:
arch/sparc/kernel/of_device_64.c:678:2: error: implicit declaration of function 
‘DMA_BIT_MASK’ [-Werror=implicit-function-declaration]
  op->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  ^
arch/sparc/kernel/of_device_64.c:679:24: error: ‘struct platform_device’ has no 
member named ‘dma_mask’
  op->dev.dma_mask = >dma_mask;
^
arch/sparc/kernel/of_device_64.c:680:4: error: ‘struct platform_device’ has no 
member named ‘dma_mask’
  op->dma_mask = DMA_BIT_MASK(32);
^
cc1: all warnings being treated as errors
scripts/Makefile.build:307: recipe for target 
'arch/sparc/kernel/of_device_64.o' failed


-- 
Meelis Roos (mr...@linux.ee)
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Re: new SBus related DMA warnings in 4.18+git

2018-08-28 Thread Christoph Hellwig
On Mon, Aug 27, 2018 at 10:04:58PM +0300, Meelis Roos wrote:
> > On Sun, Aug 26, 2018 at 10:48:44AM +0300, Meelis Roos wrote:
> > > Tried yesterdays git 4.18.0-12789-gaa5b105 on a Sun Ultra 1 with SBus 
> > > and several SBus connected devicess give DMA mapping related warnings:
> > 
> > This should have been around since the warning was added.
> > 
> > The patch below should fix it:
> > 
> > ---
> > >From 6294e0e330851ee06e66ab85b348f1d92d375d7a Mon Sep 17 00:00:00 2001
> > From: Christoph Hellwig 
> > Date: Mon, 27 Aug 2018 17:23:24 +0200
> > Subject: driver core: initialize a default DMA mask for platform device
> 
> No, it does not fix it. Dmesg from another SBus machine that conmpiled 
> it faster (Sun Ultra 2):

Based on the other thread here is a new attempt:

---
diff --git a/arch/sparc/kernel/of_device_32.c b/arch/sparc/kernel/of_device_32.c
index 3641a294ed54..1738f7f12a9f 100644
--- a/arch/sparc/kernel/of_device_32.c
+++ b/arch/sparc/kernel/of_device_32.c
@@ -381,6 +381,10 @@ static struct platform_device * __init 
scan_one_device(struct device_node *dp,
else
dev_set_name(>dev, "%08x", dp->phandle);
 
+   op->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   op->dev.dma_mask = >dma_mask;
+   op->dma_mask = DMA_BIT_MASK(32);
+
if (of_device_register(op)) {
printk("%s: Could not register of device.\n",
   dp->full_name);
diff --git a/arch/sparc/kernel/of_device_64.c b/arch/sparc/kernel/of_device_64.c
index 44e4d4435bed..60ebb1f976ab 100644
--- a/arch/sparc/kernel/of_device_64.c
+++ b/arch/sparc/kernel/of_device_64.c
@@ -675,6 +675,9 @@ static struct platform_device * __init 
scan_one_device(struct device_node *dp,
dev_set_name(>dev, "root");
else
dev_set_name(>dev, "%08x", dp->phandle);
+   op->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   op->dev.dma_mask = >dma_mask;
+   op->dma_mask = DMA_BIT_MASK(32);
 
if (of_device_register(op)) {
printk("%s: Could not register of device.\n",
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: new SBus related DMA warnings in 4.18+git

2018-08-28 Thread Christoph Hellwig
On Mon, Aug 27, 2018 at 01:41:36PM -0700, David Miller wrote:
> From: Sam Ravnborg 
> Date: Mon, 27 Aug 2018 21:15:18 +0200
> 
> > Why not fix the drivers rather than papering over the fact
> > that they are missing the DMA mask?
> > 
> > We are in the lucky situation the Meelis can test any patches.
> 
> SBUS drivers never set the mask because they never needed to and could
> use the default, since SBUS IOMMUs were quite universal in nature.

In addition to that the historical expectation is that you can do
dma to platform_devices without setup, and for some reason sbus
devices all show up as platform_devices.

> I think it's more error prone to add the mask setting to every single
> SBUS driver than to just have the core setup the default properly.

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


Re: new SBus related DMA warnings in 4.18+git

2018-08-27 Thread David Miller
From: Sam Ravnborg 
Date: Mon, 27 Aug 2018 21:15:18 +0200

> Why not fix the drivers rather than papering over the fact
> that they are missing the DMA mask?
> 
> We are in the lucky situation the Meelis can test any patches.

SBUS drivers never set the mask because they never needed to and could
use the default, since SBUS IOMMUs were quite universal in nature.

I think it's more error prone to add the mask setting to every single
SBUS driver than to just have the core setup the default properly.
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: new SBus related DMA warnings in 4.18+git

2018-08-27 Thread Sam Ravnborg
Hi Christoph.

On Mon, Aug 27, 2018 at 05:47:16PM +0200, Christoph Hellwig wrote:
> On Sun, Aug 26, 2018 at 10:48:44AM +0300, Meelis Roos wrote:
> > Tried yesterdays git 4.18.0-12789-gaa5b105 on a Sun Ultra 1 with SBus 
> > and several SBus connected devicess give DMA mapping related warnings:
> 
> This should have been around since the warning was added.
> 
> The patch below should fix it:
> 
> ---
> >From 6294e0e330851ee06e66ab85b348f1d92d375d7a Mon Sep 17 00:00:00 2001
> From: Christoph Hellwig 
> Date: Mon, 27 Aug 2018 17:23:24 +0200
> Subject: driver core: initialize a default DMA mask for platform device
> 
> We still treat devices without a DMA mask as defaulting to 32-bits for
> both mask, but a few releases ago we've started warning about such
> cases, as they require special cases to work around this sloppyness.
> Add a dma_mask field to struct platform_object so that we can initialize
> the dma_mask pointer in struct device and initialize both masks to
> 32-bits by default.  Architectures can still override this in
> arch_setup_pdev_archdata if needed.
> 
> Note that the code looks a little odd with the various conditionals
> because we have to support platform_device structures that are
> statically allocated.
I know the patch did not work out as intended - saw another thread.
But this looks like the patch just paper over the fact that
the drivers are missing to set the DMA mask.

Why not fix the drivers rather than papering over the fact
that they are missing the DMA mask?

We are in the lucky situation the Meelis can test any patches.

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


Re: new SBus related DMA warnings in 4.18+git

2018-08-27 Thread Meelis Roos
> On Sun, Aug 26, 2018 at 10:48:44AM +0300, Meelis Roos wrote:
> > Tried yesterdays git 4.18.0-12789-gaa5b105 on a Sun Ultra 1 with SBus 
> > and several SBus connected devicess give DMA mapping related warnings:
> 
> This should have been around since the warning was added.
> 
> The patch below should fix it:
> 
> ---
> >From 6294e0e330851ee06e66ab85b348f1d92d375d7a Mon Sep 17 00:00:00 2001
> From: Christoph Hellwig 
> Date: Mon, 27 Aug 2018 17:23:24 +0200
> Subject: driver core: initialize a default DMA mask for platform device

No, it does not fix it. Dmesg from another SBus machine that conmpiled 
it faster (Sun Ultra 2):

[0.000112] PROMLIB: Sun IEEE Boot Prom 'OBP 3.25.0 1999/12/03 11:35'
[0.000131] PROMLIB: Root node compatible: 
[0.000250] Linux version 4.18.0-12952-g2923b27-dirty (mroos@u2) (gcc 
version 4.9.3 (Debian 4.9.3-2)) #239 SMP Mon Aug 27 21:42:14 EEST 2018
[0.000448] debug: ignoring loglevel setting.
[0.329860] bootconsole [earlyprom0] enabled
[0.380881] ARCH: SUN4U
[0.410167] Ethernet address: 08:00:20:89:2a:a0
[0.464243] MM: PAGE_OFFSET is 0xf800 (max_phys_bits == 40)
[0.543372] MM: VMALLOC [0x0001 --> 0x0600]
[0.618366] MM: VMEMMAP [0x0600 --> 0x0c00]
[0.697932] Kernel: Using 2 locked TLB entries for main kernel image.
[0.774140] Remapping the kernel... 
[0.807146] done.
[1.154827] OF stdout device is: /sbus@1f,0/zs@f,110:a
[1.219566] PROM: Built device tree with 63364 bytes of memory.
[1.290510] Top of RAM: 0x6ff2c000, Total RAM: 0x37f1a000
[1.354970] Memory hole size: 896MB
[1.406349] Allocated 16384 bytes for kernel page tables.
[1.470133] Zone ranges:
[1.500269]   Normal   [mem 0x-0x6ff2bfff]
[1.574219] Movable zone start for each node
[1.625258] Early memory node ranges
[1.667967]   node   0: [mem 0x-0x0fff]
[1.742961]   node   0: [mem 0x2000-0x27ff]
[1.817956]   node   0: [mem 0x4000-0x4fff]
[1.892948]   node   0: [mem 0x6000-0x6fefdfff]
[1.967942]   node   0: [mem 0x6ff0-0x6ff05fff]
[2.042936]   node   0: [mem 0x6ff16000-0x6ff2bfff]
[2.118044] Initmem setup node 0 [mem 0x-0x6ff2bfff]
[2.202302] On node 0 totalpages: 114573
[2.249169]   Normal zone: 896 pages used for memmap
[2.308537]   Normal zone: 0 pages reserved
[2.358535]   Normal zone: 114573 pages, LIFO batch:31
[2.495241] Booting Linux...
[2.528734] CPU CAPS: [flush,stbar,swap,muldiv,v9,mul32,div32,v8plus]
[2.605799] CPU CAPS: [vis]
[2.668258] percpu: Embedded 10 pages/cpu @(ptrval) s44928 r8192 
d28800 u2097152
[2.766410] pcpu-alloc: s44928 r8192 d28800 u2097152 alloc=1*4194304
[2.841510] pcpu-alloc: [0] 0 1 
[2.885668] Built 1 zonelists, mobility grouping on.  Total pages: 113677
[2.965990] Kernel command line: root=/dev/sda2 ro ignore_loglevel
[3.046466] Dentry cache hash table entries: 131072 (order: 7, 1048576 bytes)
[3.134227] Inode-cache hash table entries: 65536 (order: 6, 524288 bytes)
[3.215649] Sorting __ex_table...
[3.310465] Memory: 892040K/916584K available (4329K kernel code, 255K 
rwdata, 816K rodata, 232K init, 268K bss, 24544K reserved, 0K cma-reserved)
[3.467295] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=2, Nodes=1
[3.545872] rcu: Hierarchical RCU implementation.
[3.601352] NR_IRQS: 2048, nr_irqs: 2048, preallocated irqs: 1
[3.671504] clocksource: tick: mask: 0x max_cycles: 
0x44439c2a93, max_idle_ns: 440795210626 ns
[3.790815] clocksource: mult[360e5ba] shift[24]
[3.846017] clockevent: mult[4bc5ed4a] shift[32]
[3.901587] Console: colour dummy device 80x25
[3.954414] console [tty0] enabled
[3.994980] bootconsole [earlyprom0] disabled
[4.197213] Calibrating delay using timer specific routine.. 593.26 BogoMIPS 
(lpj=2966300)
[4.197267] pid_max: default: 32768 minimum: 301
[4.197757] Mount-cache hash table entries: 2048 (order: 1, 16384 bytes)
[4.197861] Mountpoint-cache hash table entries: 2048 (order: 1, 16384 bytes)
[4.201878] rcu: Hierarchical SRCU implementation.
[4.203657] smp: Bringing up secondary CPUs ...
[4.237851] CPU 1: synchronized TICK with master CPU (last diff -17 cycles, 
maxerr 539 cycles)
[4.238252] smp: Brought up 1 node, 2 CPUs
[4.239996] devtmpfs: initialized
[4.245228] random: get_random_u32 called from 
bucket_table_alloc.isra.18+0x7c/0x1c0 with crng_init=0
[4.245850] clocksource: jiffies: mask: 0x max_cycles: 0x, 
max_idle_ns: 1911260446275 ns
[4.245913] futex hash table entries: 512 (order: 2, 32768 bytes)
[4.247101] NET: Registered protocol family 16
[4.261051] SYSIO: UPA portID , at 01fe
[

Re: new SBus related DMA warnings in 4.18+git

2018-08-27 Thread Christoph Hellwig
On Sun, Aug 26, 2018 at 10:48:44AM +0300, Meelis Roos wrote:
> Tried yesterdays git 4.18.0-12789-gaa5b105 on a Sun Ultra 1 with SBus 
> and several SBus connected devicess give DMA mapping related warnings:

This should have been around since the warning was added.

The patch below should fix it:

---
>From 6294e0e330851ee06e66ab85b348f1d92d375d7a Mon Sep 17 00:00:00 2001
From: Christoph Hellwig 
Date: Mon, 27 Aug 2018 17:23:24 +0200
Subject: driver core: initialize a default DMA mask for platform device

We still treat devices without a DMA mask as defaulting to 32-bits for
both mask, but a few releases ago we've started warning about such
cases, as they require special cases to work around this sloppyness.
Add a dma_mask field to struct platform_object so that we can initialize
the dma_mask pointer in struct device and initialize both masks to
32-bits by default.  Architectures can still override this in
arch_setup_pdev_archdata if needed.

Note that the code looks a little odd with the various conditionals
because we have to support platform_device structures that are
statically allocated.

Signed-off-by: Christoph Hellwig 
---
 drivers/base/platform.c | 15 +--
 include/linux/platform_device.h |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index dff82a3c2caa..baf4b06cf2d9 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -225,6 +225,17 @@ struct platform_object {
char name[];
 };
 
+static void setup_pdev_archdata(struct platform_device *pdev)
+{
+   if (!pdev->dev.coherent_dma_mask)
+   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   if (!pdev->dma_mask)
+   pdev->dma_mask = DMA_BIT_MASK(32);
+   if (!pdev->dev.dma_mask)
+   pdev->dev.dma_mask = >dma_mask;
+   arch_setup_pdev_archdata(pdev);
+};
+
 /**
  * platform_device_put - destroy a platform device
  * @pdev: platform device to free
@@ -271,7 +282,7 @@ struct platform_device *platform_device_alloc(const char 
*name, int id)
pa->pdev.id = id;
device_initialize(>pdev.dev);
pa->pdev.dev.release = platform_device_release;
-   arch_setup_pdev_archdata(>pdev);
+   setup_pdev_archdata(>pdev);
}
 
return pa ? >pdev : NULL;
@@ -472,7 +483,7 @@ EXPORT_SYMBOL_GPL(platform_device_del);
 int platform_device_register(struct platform_device *pdev)
 {
device_initialize(>dev);
-   arch_setup_pdev_archdata(pdev);
+   setup_pdev_archdata(pdev);
return platform_device_add(pdev);
 }
 EXPORT_SYMBOL_GPL(platform_device_register);
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 1a9f38f27f65..d84ec1de6022 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -25,6 +25,7 @@ struct platform_device {
int id;
boolid_auto;
struct device   dev;
+   dma_addr_t  dma_mask;
u32 num_resources;
struct resource *resource;
 
-- 
2.18.0

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