1. 28 2月, 2022 3 次提交
  2. 31 1月, 2022 2 次提交
    • J
      iommu: Fix some W=1 warnings · 30209b93
      John Garry 提交于
      The code is mostly free of W=1 warning, so fix the following:
      
      drivers/iommu/iommu.c:996: warning: expecting prototype for iommu_group_for_each_dev(). Prototype was for __iommu_group_for_each_dev() instead
      drivers/iommu/iommu.c:3048: warning: Function parameter or member 'drvdata' not described in 'iommu_sva_bind_device'
      drivers/iommu/ioasid.c:354: warning: Function parameter or member 'ioasid' not described in 'ioasid_get'
      drivers/iommu/omap-iommu.c:1098: warning: expecting prototype for omap_iommu_suspend_prepare(). Prototype was for omap_iommu_prepare() instead
      Signed-off-by: NJohn Garry <john.garry@huawei.com>
      Reviewed-by: NRobin Murphy <robin.murphy@arm.com>
      Link: https://lore.kernel.org/r/1643366673-26803-1-git-send-email-john.garry@huawei.comSigned-off-by: NJoerg Roedel <jroedel@suse.de>
      30209b93
    • V
      iommu: Fix potential use-after-free during probe · b54240ad
      Vijayanand Jitta 提交于
      Kasan has reported the following use after free on dev->iommu.
      when a device probe fails and it is in process of freeing dev->iommu
      in dev_iommu_free function, a deferred_probe_work_func runs in parallel
      and tries to access dev->iommu->fwspec in of_iommu_configure path thus
      causing use after free.
      
      BUG: KASAN: use-after-free in of_iommu_configure+0xb4/0x4a4
      Read of size 8 at addr ffffff87a2f1acb8 by task kworker/u16:2/153
      
      Workqueue: events_unbound deferred_probe_work_func
      Call trace:
       dump_backtrace+0x0/0x33c
       show_stack+0x18/0x24
       dump_stack_lvl+0x16c/0x1e0
       print_address_description+0x84/0x39c
       __kasan_report+0x184/0x308
       kasan_report+0x50/0x78
       __asan_load8+0xc0/0xc4
       of_iommu_configure+0xb4/0x4a4
       of_dma_configure_id+0x2fc/0x4d4
       platform_dma_configure+0x40/0x5c
       really_probe+0x1b4/0xb74
       driver_probe_device+0x11c/0x228
       __device_attach_driver+0x14c/0x304
       bus_for_each_drv+0x124/0x1b0
       __device_attach+0x25c/0x334
       device_initial_probe+0x24/0x34
       bus_probe_device+0x78/0x134
       deferred_probe_work_func+0x130/0x1a8
       process_one_work+0x4c8/0x970
       worker_thread+0x5c8/0xaec
       kthread+0x1f8/0x220
       ret_from_fork+0x10/0x18
      
      Allocated by task 1:
       ____kasan_kmalloc+0xd4/0x114
       __kasan_kmalloc+0x10/0x1c
       kmem_cache_alloc_trace+0xe4/0x3d4
       __iommu_probe_device+0x90/0x394
       probe_iommu_group+0x70/0x9c
       bus_for_each_dev+0x11c/0x19c
       bus_iommu_probe+0xb8/0x7d4
       bus_set_iommu+0xcc/0x13c
       arm_smmu_bus_init+0x44/0x130 [arm_smmu]
       arm_smmu_device_probe+0xb88/0xc54 [arm_smmu]
       platform_drv_probe+0xe4/0x13c
       really_probe+0x2c8/0xb74
       driver_probe_device+0x11c/0x228
       device_driver_attach+0xf0/0x16c
       __driver_attach+0x80/0x320
       bus_for_each_dev+0x11c/0x19c
       driver_attach+0x38/0x48
       bus_add_driver+0x1dc/0x3a4
       driver_register+0x18c/0x244
       __platform_driver_register+0x88/0x9c
       init_module+0x64/0xff4 [arm_smmu]
       do_one_initcall+0x17c/0x2f0
       do_init_module+0xe8/0x378
       load_module+0x3f80/0x4a40
       __se_sys_finit_module+0x1a0/0x1e4
       __arm64_sys_finit_module+0x44/0x58
       el0_svc_common+0x100/0x264
       do_el0_svc+0x38/0xa4
       el0_svc+0x20/0x30
       el0_sync_handler+0x68/0xac
       el0_sync+0x160/0x180
      
      Freed by task 1:
       kasan_set_track+0x4c/0x84
       kasan_set_free_info+0x28/0x4c
       ____kasan_slab_free+0x120/0x15c
       __kasan_slab_free+0x18/0x28
       slab_free_freelist_hook+0x204/0x2fc
       kfree+0xfc/0x3a4
       __iommu_probe_device+0x284/0x394
       probe_iommu_group+0x70/0x9c
       bus_for_each_dev+0x11c/0x19c
       bus_iommu_probe+0xb8/0x7d4
       bus_set_iommu+0xcc/0x13c
       arm_smmu_bus_init+0x44/0x130 [arm_smmu]
       arm_smmu_device_probe+0xb88/0xc54 [arm_smmu]
       platform_drv_probe+0xe4/0x13c
       really_probe+0x2c8/0xb74
       driver_probe_device+0x11c/0x228
       device_driver_attach+0xf0/0x16c
       __driver_attach+0x80/0x320
       bus_for_each_dev+0x11c/0x19c
       driver_attach+0x38/0x48
       bus_add_driver+0x1dc/0x3a4
       driver_register+0x18c/0x244
       __platform_driver_register+0x88/0x9c
       init_module+0x64/0xff4 [arm_smmu]
       do_one_initcall+0x17c/0x2f0
       do_init_module+0xe8/0x378
       load_module+0x3f80/0x4a40
       __se_sys_finit_module+0x1a0/0x1e4
       __arm64_sys_finit_module+0x44/0x58
       el0_svc_common+0x100/0x264
       do_el0_svc+0x38/0xa4
       el0_svc+0x20/0x30
       el0_sync_handler+0x68/0xac
       el0_sync+0x160/0x180
      
      Fix this by setting dev->iommu to NULL first and
      then freeing dev_iommu structure in dev_iommu_free
      function.
      Suggested-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NVijayanand Jitta <quic_vjitta@quicinc.com>
      Link: https://lore.kernel.org/r/1643613155-20215-1-git-send-email-quic_vjitta@quicinc.comSigned-off-by: NJoerg Roedel <jroedel@suse.de>
      b54240ad
  3. 06 12月, 2021 1 次提交
  4. 04 10月, 2021 1 次提交
  5. 28 9月, 2021 1 次提交
  6. 18 8月, 2021 7 次提交
  7. 11 8月, 2021 1 次提交
  8. 09 8月, 2021 1 次提交
  9. 02 8月, 2021 1 次提交
    • F
      iommu: Check if group is NULL before remove device · 5aa95d88
      Frank Wunderlich 提交于
      If probe_device is failing, iommu_group is not initialized because
      iommu_group_add_device is not reached, so freeing it will result
      in NULL pointer access.
      
      iommu_bus_init
        ->bus_iommu_probe
            ->probe_iommu_group in for each:/* return -22 in fail case */
                ->iommu_probe_device
                    ->__iommu_probe_device       /* return -22 here.*/
                        -> ops->probe_device          /* return -22 here.*/
                        -> iommu_group_get_for_dev
                              -> ops->device_group
                              -> iommu_group_add_device //good case
        ->remove_iommu_group  //in fail case, it will remove group
           ->iommu_release_device
               ->iommu_group_remove_device // here we don't have group
      
      In my case ops->probe_device (mtk_iommu_probe_device from
      mtk_iommu_v1.c) is due to failing fwspec->ops mismatch.
      
      Fixes: d72e31c9 ("iommu: IOMMU Groups")
      Signed-off-by: NFrank Wunderlich <frank-w@public-files.de>
      Link: https://lore.kernel.org/r/20210731074737.4573-1-linux@fw-web.deSigned-off-by: NJoerg Roedel <jroedel@suse.de>
      5aa95d88
  10. 26 7月, 2021 8 次提交
  11. 09 6月, 2021 1 次提交
  12. 16 4月, 2021 1 次提交
  13. 07 4月, 2021 8 次提交
  14. 18 3月, 2021 1 次提交
  15. 02 2月, 2021 1 次提交
  16. 28 1月, 2021 1 次提交
    • L
      iommu: use the __iommu_attach_device() directly for deferred attach · 3ab65729
      Lianbo Jiang 提交于
      Currently, because domain attach allows to be deferred from iommu
      driver to device driver, and when iommu initializes, the devices
      on the bus will be scanned and the default groups will be allocated.
      
      Due to the above changes, some devices could be added to the same
      group as below:
      
      [    3.859417] pci 0000:01:00.0: Adding to iommu group 16
      [    3.864572] pci 0000:01:00.1: Adding to iommu group 16
      [    3.869738] pci 0000:02:00.0: Adding to iommu group 17
      [    3.874892] pci 0000:02:00.1: Adding to iommu group 17
      
      But when attaching these devices, it doesn't allow that a group has
      more than one device, otherwise it will return an error. This conflicts
      with the deferred attaching. Unfortunately, it has two devices in the
      same group for my side, for example:
      
      [    9.627014] iommu_group_device_count(): device name[0]:0000:01:00.0
      [    9.633545] iommu_group_device_count(): device name[1]:0000:01:00.1
      ...
      [   10.255609] iommu_group_device_count(): device name[0]:0000:02:00.0
      [   10.262144] iommu_group_device_count(): device name[1]:0000:02:00.1
      
      Finally, which caused the failure of tg3 driver when tg3 driver calls
      the dma_alloc_coherent() to allocate coherent memory in the tg3_test_dma().
      
      [    9.660310] tg3 0000:01:00.0: DMA engine test failed, aborting
      [    9.754085] tg3: probe of 0000:01:00.0 failed with error -12
      [    9.997512] tg3 0000:01:00.1: DMA engine test failed, aborting
      [   10.043053] tg3: probe of 0000:01:00.1 failed with error -12
      [   10.288905] tg3 0000:02:00.0: DMA engine test failed, aborting
      [   10.334070] tg3: probe of 0000:02:00.0 failed with error -12
      [   10.578303] tg3 0000:02:00.1: DMA engine test failed, aborting
      [   10.622629] tg3: probe of 0000:02:00.1 failed with error -12
      
      In addition, the similar situations also occur in other drivers such
      as the bnxt_en driver. That can be reproduced easily in kdump kernel
      when SME is active.
      
      Let's move the handling currently in iommu_dma_deferred_attach() into
      the iommu core code so that it can call the __iommu_attach_device()
      directly instead of the iommu_attach_device(). The external interface
      iommu_attach_device() is not suitable for handling this situation.
      Signed-off-by: NLianbo Jiang <lijiang@redhat.com>
      Reviewed-by: NRobin Murphy <robin.murphy@arm.com>
      Link: https://lore.kernel.org/r/20210126115337.20068-3-lijiang@redhat.comSigned-off-by: NJoerg Roedel <jroedel@suse.de>
      3ab65729
  17. 27 1月, 2021 1 次提交