Re: [PATCH] powerpc/iommu: Do not do platform domain attach atctions after probe

2023-10-06 Thread Joerg Roedel
On Thu, Oct 05, 2023 at 10:35:11AM -0300, Jason Gunthorpe wrote:
>  arch/powerpc/kernel/iommu.c | 10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)

Applied, thanks.

-- 
Jörg Rödel
jroe...@suse.de

SUSE Software Solutions Germany GmbH
Frankenstraße 146
90461 Nürnberg
Germany

(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman



[PATCH] powerpc/iommu: Do not do platform domain attach atctions after probe

2023-10-05 Thread Jason Gunthorpe
POWER throws a splat at boot, it looks like the DMA ops were probably
changed while a driver was attached. Something is still weird about how
power sequences its bootup. Previously this was hidden since the core
iommu code did nothing during probe, now it calls
spapr_tce_platform_iommu_attach_dev().

Make spapr_tce_platform_iommu_attach_dev() do nothing on the probe time
call like it did before.

  WARNING: CPU: 0 PID: 8 at arch/powerpc/kernel/iommu.c:407 
__iommu_free+0x1e4/0x1f0
  Modules linked in: sd_mod t10_pi crc64_rocksoft crc64 sg ibmvfc mlx5_core(+) 
scsi_transport_fc ibmveth mlxfw psample dm_multipath dm_mirror dm_region_hash 
dm_log dm_mod fuse
  CPU: 0 PID: 8 Comm: kworker/0:0 Not tainted 6.6.0-rc3-next-20230929-auto #1
  Hardware name: IBM,9080-HEX POWER10 (raw) 0x800200 0xf06 of:IBM,FW1030.30 
(NH1030_062) hv:phyp pSeries
  Workqueue: events work_for_cpu_fn
  NIP:  c005f6d4 LR: c005f6d0 CTR: 005ca81c
  REGS: c3a27890 TRAP: 0700   Not tainted (6.6.0-rc3-next-20230929-auto)
  MSR:  8282b033   CR: 48000824  XER: 
0008
  CFAR: c020f738 IRQMASK: 0
  GPR00: c005f6d0 c3a27b30 c1481800 017
  GPR04: 7fff c3a27950 c3a27948 0027
  GPR08: c00c18c07c10 0001 0027 c2ac8a08
  GPR12:  c2ff c019cc88 c3042300
  GPR16:    c3071ab0
  GPR20: c349f80d c3215440 c3215480 61c8864680b583eb
  GPR24:  7fff 08002000 0010
  GPR28: 0002 8002 cc5dc800 cc5dc880
  NIP [c005f6d4] __iommu_free+0x1e4/0x1f0
  LR [c005f6d0] __iommu_free+0x1e0/0x1f0
  Call Trace:
  [c3a27b30] [c005f6d0] __iommu_free+0x1e0/0x1f0 (unreliable)
  [c3a27bc0] [c005f848] iommu_free+0x28/0x70
  [c3a27bf0] [c0061518] iommu_free_coherent+0x68/0xa0
  [c3a27c20] [c005e8d4] dma_iommu_free_coherent+0x24/0x40
  [c3a27c40] [c024698c] dma_free_attrs+0x10c/0x140
  [c3a27c90] [c00800dcb8d4] mlx5_cmd_cleanup+0x5c/0x90 [mlx5_core]
  [c3a27cc0] [c00800dc45a0] mlx5_mdev_uninit+0xc8/0x100 [mlx5_core]
  [c3a27d00] [c00800dc4ac4] probe_one+0x3ec/0x530 [mlx5_core]
  [c3a27d90] [c08c5edc] local_pci_probe+0x6c/0x110
  [c3a27e10] [c0189c98] work_for_cpu_fn+0x38/0x60
  [c3a27e40] [c018d1d0] process_scheduled_works+0x230/0x4f0
  [c3a27f10] [c018ff14] worker_thread+0x1e4/0x500
  [c3a27f90] [c019cdb8] kthread+0x138/0x140
  [c3a27fe0] [c000df98] start_kernel_thread+0x14/0x18
  Code: 481b004d 6000 e89e0028 3c62ffe0 3863dd20 481b0039 6000 e89e0038 
3c62ffe0 3863dd38 481b0025 6000 <0fe0> 4b20 6000 3c4c0142
  ---[ end trace  ]---
  iommu_free: invalid entry
  entry = 0x800203d0
  dma_addr  = 0x800203d
  Table = 0xcc5dc800
  bus#  = 0x1
  size  = 0x2
  startOff  = 0x8000
  index = 0x70200016

Fixes: 2ad56efa80db ("powerpc/iommu: Setup a default domain and remove 
set_platform_dma_ops")
Reported-by: Tasmiya Nalatwad 
Link: 
https://lore.kernel.org/r/d06cee81-c47f-9d62-dfc6-4c77b6005...@linux.vnet.ibm.com
Tested-by: Tasmiya Nalatwad 
Signed-off-by: Jason Gunthorpe 
---
 arch/powerpc/kernel/iommu.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

Joerg, this would need to go to your tree, thanks

diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index d6ad3fde85a212..bf19932147517b 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -1280,13 +1280,19 @@ struct iommu_table_group_ops spapr_tce_table_group_ops 
= {
 /*
  * A simple iommu_ops to allow less cruft in generic VFIO code.
  */
-static int spapr_tce_platform_iommu_attach_dev(struct iommu_domain *dom,
-  struct device *dev)
+static int
+spapr_tce_platform_iommu_attach_dev(struct iommu_domain *platform_domain,
+   struct device *dev)
 {
+   struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
struct iommu_group *grp = iommu_group_get(dev);
struct iommu_table_group *table_group;
int ret = -EINVAL;
 
+   /* At first attach the ownership is already set */
+   if (!domain)
+   return 0;
+
if (!grp)
return -ENODEV;
 

base-commit: 20700abdf2393c8c0bd3a100e3111d0fcd3d5bf3
-- 
2.42.0