1. 26 7月, 2021 7 次提交
  2. 09 6月, 2021 1 次提交
  3. 16 4月, 2021 1 次提交
  4. 07 4月, 2021 8 次提交
  5. 18 3月, 2021 1 次提交
  6. 02 2月, 2021 1 次提交
  7. 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
  8. 27 1月, 2021 5 次提交
  9. 07 12月, 2020 1 次提交
  10. 26 11月, 2020 1 次提交
  11. 25 11月, 2020 3 次提交
    • S
      iommu: Take lock before reading iommu group default domain type · 0b8a96a3
      Sai Praneeth Prakhya 提交于
      "/sys/kernel/iommu_groups/<grp_id>/type" file could be read to find out the
      default domain type of an iommu group. The default domain of an iommu group
      doesn't change after booting and hence could be read directly. But,
      after addding support to dynamically change iommu group default domain, the
      above assumption no longer stays valid.
      
      iommu group default domain type could be changed at any time by writing to
      "/sys/kernel/iommu_groups/<grp_id>/type". So, take group mutex before
      reading iommu group default domain type so that the user wouldn't see stale
      values or iommu_group_show_type() doesn't try to derefernce stale pointers.
      Signed-off-by: NSai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
      Signed-off-by: NLu Baolu <baolu.lu@linux.intel.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Joerg Roedel <joro@8bytes.org>
      Cc: Ashok Raj <ashok.raj@intel.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Sohil Mehta <sohil.mehta@intel.com>
      Cc: Robin Murphy <robin.murphy@arm.com>
      Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
      Link: https://lore.kernel.org/r/20201124130604.2912899-4-baolu.lu@linux.intel.comSigned-off-by: NWill Deacon <will@kernel.org>
      0b8a96a3
    • S
      iommu: Add support to change default domain of an iommu group · 08a27c1c
      Sai Praneeth Prakhya 提交于
      Presently, the default domain of an iommu group is allocated during boot
      time and it cannot be changed later. So, the device would typically be
      either in identity (also known as pass_through) mode or the device would be
      in DMA mode as long as the machine is up and running. There is no way to
      change the default domain type dynamically i.e. after booting, a device
      cannot switch between identity mode and DMA mode.
      
      But, assume a use case wherein the user trusts the device and believes that
      the OS is secure enough and hence wants *only* this device to bypass IOMMU
      (so that it could be high performing) whereas all the other devices to go
      through IOMMU (so that the system is protected). Presently, this use case
      is not supported. It will be helpful if there is some way to change the
      default domain of an iommu group dynamically. Hence, add such support.
      
      A privileged user could request the kernel to change the default domain
      type of a iommu group by writing to
      "/sys/kernel/iommu_groups/<grp_id>/type" file. Presently, only three values
      are supported
      1. identity: all the DMA transactions from the device in this group are
                   *not* translated by the iommu
      2. DMA: all the DMA transactions from the device in this group are
              translated by the iommu
      3. auto: change to the type the device was booted with
      
      Note:
      1. Default domain of an iommu group with two or more devices cannot be
         changed.
      2. The device in the iommu group shouldn't be bound to any driver.
      3. The device shouldn't be assigned to user for direct access.
      4. The change request will fail if any device in the group has a mandatory
         default domain type and the requested one conflicts with that.
      
      Please see "Documentation/ABI/testing/sysfs-kernel-iommu_groups" for more
      information.
      Signed-off-by: NSai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
      Signed-off-by: NLu Baolu <baolu.lu@linux.intel.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Joerg Roedel <joro@8bytes.org>
      Cc: Ashok Raj <ashok.raj@intel.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Sohil Mehta <sohil.mehta@intel.com>
      Cc: Robin Murphy <robin.murphy@arm.com>
      Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
      Link: https://lore.kernel.org/r/20201124130604.2912899-3-baolu.lu@linux.intel.comSigned-off-by: NWill Deacon <will@kernel.org>
      08a27c1c
    • L
      iommu: Move def_domain type check for untrusted device into core · 28b41e2c
      Lu Baolu 提交于
      So that the vendor iommu drivers are no more required to provide the
      def_domain_type callback to always isolate the untrusted devices.
      Signed-off-by: NLu Baolu <baolu.lu@linux.intel.com>
      Cc: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
      Link: https://lore.kernel.org/linux-iommu/243ce89c33fe4b9da4c56ba35acebf81@huawei.com/
      Link: https://lore.kernel.org/r/20201124130604.2912899-2-baolu.lu@linux.intel.comSigned-off-by: NWill Deacon <will@kernel.org>
      28b41e2c
  12. 23 11月, 2020 1 次提交
  13. 18 11月, 2020 1 次提交
  14. 03 11月, 2020 1 次提交
  15. 01 10月, 2020 2 次提交
  16. 18 9月, 2020 1 次提交
  17. 04 9月, 2020 1 次提交
  18. 24 7月, 2020 1 次提交
  19. 22 7月, 2020 1 次提交
  20. 09 7月, 2020 1 次提交
    • Q
      iommu: Fix use-after-free in iommu_release_device · 9ac85451
      Qian Cai 提交于
      In pci_disable_sriov(), i.e.,
      
       # echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
      
      iommu_release_device
        iommu_group_remove_device
          arm_smmu_domain_free
            kfree(smmu_domain)
      
      Later,
      
      iommu_release_device
        arm_smmu_release_device
          arm_smmu_detach_dev
            spin_lock_irqsave(&smmu_domain->devices_lock,
      
      would trigger an use-after-free. Fixed it by call
      arm_smmu_release_device() first before iommu_group_remove_device().
      
       BUG: KASAN: use-after-free in __lock_acquire+0x3458/0x4440
        __lock_acquire at kernel/locking/lockdep.c:4250
       Read of size 8 at addr ffff0089df1a6f68 by task bash/3356
      
       CPU: 5 PID: 3356 Comm: bash Not tainted 5.8.0-rc3-next-20200630 #2
       Hardware name: HPE Apollo 70             /C01_APACHE_MB         , BIOS L50_5.13_1.11 06/18/2019
       Call trace:
        dump_backtrace+0x0/0x398
        show_stack+0x14/0x20
        dump_stack+0x140/0x1b8
        print_address_description.isra.12+0x54/0x4a8
        kasan_report+0x134/0x1b8
        __asan_report_load8_noabort+0x2c/0x50
        __lock_acquire+0x3458/0x4440
        lock_acquire+0x204/0xf10
        _raw_spin_lock_irqsave+0xf8/0x180
        arm_smmu_detach_dev+0xd8/0x4a0
        arm_smmu_detach_dev at drivers/iommu/arm-smmu-v3.c:2776
        arm_smmu_release_device+0xb4/0x1c8
        arm_smmu_disable_pasid at drivers/iommu/arm-smmu-v3.c:2754
        (inlined by) arm_smmu_release_device at drivers/iommu/arm-smmu-v3.c:3000
        iommu_release_device+0xc0/0x178
        iommu_release_device at drivers/iommu/iommu.c:302
        iommu_bus_notifier+0x118/0x160
        notifier_call_chain+0xa4/0x128
        __blocking_notifier_call_chain+0x70/0xa8
        blocking_notifier_call_chain+0x14/0x20
        device_del+0x618/0xa00
        pci_remove_bus_device+0x108/0x2d8
        pci_stop_and_remove_bus_device+0x1c/0x28
        pci_iov_remove_virtfn+0x228/0x368
        sriov_disable+0x8c/0x348
        pci_disable_sriov+0x5c/0x70
        mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
        sriov_numvfs_store+0x240/0x318
        dev_attr_store+0x38/0x68
        sysfs_kf_write+0xdc/0x128
        kernfs_fop_write+0x23c/0x448
        __vfs_write+0x54/0xe8
        vfs_write+0x124/0x3f0
        ksys_write+0xe8/0x1b8
        __arm64_sys_write+0x68/0x98
        do_el0_svc+0x124/0x220
        el0_sync_handler+0x260/0x408
        el0_sync+0x140/0x180
      
       Allocated by task 3356:
        save_stack+0x24/0x50
        __kasan_kmalloc.isra.13+0xc4/0xe0
        kasan_kmalloc+0xc/0x18
        kmem_cache_alloc_trace+0x1ec/0x318
        arm_smmu_domain_alloc+0x54/0x148
        iommu_group_alloc_default_domain+0xc0/0x440
        iommu_probe_device+0x1c0/0x308
        iort_iommu_configure+0x434/0x518
        acpi_dma_configure+0xf0/0x128
        pci_dma_configure+0x114/0x160
        really_probe+0x124/0x6d8
        driver_probe_device+0xc4/0x180
        __device_attach_driver+0x184/0x1e8
        bus_for_each_drv+0x114/0x1a0
        __device_attach+0x19c/0x2a8
        device_attach+0x10/0x18
        pci_bus_add_device+0x70/0xf8
        pci_iov_add_virtfn+0x7b4/0xb40
        sriov_enable+0x5c8/0xc30
        pci_enable_sriov+0x64/0x80
        mlx5_core_sriov_configure+0x58/0x260 [mlx5_core]
        sriov_numvfs_store+0x1c0/0x318
        dev_attr_store+0x38/0x68
        sysfs_kf_write+0xdc/0x128
        kernfs_fop_write+0x23c/0x448
        __vfs_write+0x54/0xe8
        vfs_write+0x124/0x3f0
        ksys_write+0xe8/0x1b8
        __arm64_sys_write+0x68/0x98
        do_el0_svc+0x124/0x220
        el0_sync_handler+0x260/0x408
        el0_sync+0x140/0x180
      
       Freed by task 3356:
        save_stack+0x24/0x50
        __kasan_slab_free+0x124/0x198
        kasan_slab_free+0x10/0x18
        slab_free_freelist_hook+0x110/0x298
        kfree+0x128/0x668
        arm_smmu_domain_free+0xf4/0x1a0
        iommu_group_release+0xec/0x160
        kobject_put+0xf4/0x238
        kobject_del+0x110/0x190
        kobject_put+0x1e4/0x238
        iommu_group_remove_device+0x394/0x938
        iommu_release_device+0x9c/0x178
        iommu_release_device at drivers/iommu/iommu.c:300
        iommu_bus_notifier+0x118/0x160
        notifier_call_chain+0xa4/0x128
        __blocking_notifier_call_chain+0x70/0xa8
        blocking_notifier_call_chain+0x14/0x20
        device_del+0x618/0xa00
        pci_remove_bus_device+0x108/0x2d8
        pci_stop_and_remove_bus_device+0x1c/0x28
        pci_iov_remove_virtfn+0x228/0x368
        sriov_disable+0x8c/0x348
        pci_disable_sriov+0x5c/0x70
        mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
        sriov_numvfs_store+0x240/0x318
        dev_attr_store+0x38/0x68
        sysfs_kf_write+0xdc/0x128
        kernfs_fop_write+0x23c/0x448
        __vfs_write+0x54/0xe8
        vfs_write+0x124/0x3f0
        ksys_write+0xe8/0x1b8
        __arm64_sys_write+0x68/0x98
        do_el0_svc+0x124/0x220
        el0_sync_handler+0x260/0x408
        el0_sync+0x140/0x180
      
       The buggy address belongs to the object at ffff0089df1a6e00
        which belongs to the cache kmalloc-512 of size 512
       The buggy address is located 360 bytes inside of
        512-byte region [ffff0089df1a6e00, ffff0089df1a7000)
       The buggy address belongs to the page:
       page:ffffffe02257c680 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff0089df1a1400
       flags: 0x7ffff800000200(slab)
       raw: 007ffff800000200 ffffffe02246b8c8 ffffffe02257ff88 ffff000000320680
       raw: ffff0089df1a1400 00000000002a000e 00000001ffffffff ffff0089df1a5001
       page dumped because: kasan: bad access detected
       page->mem_cgroup:ffff0089df1a5001
      
       Memory state around the buggy address:
        ffff0089df1a6e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
        ffff0089df1a6e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
       >ffff0089df1a6f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                                 ^
        ffff0089df1a6f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
        ffff0089df1a7000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      
      Fixes: a6a4c7e2 ("iommu: Add probe_device() and release_device() call-backs")
      Signed-off-by: NQian Cai <cai@lca.pw>
      Link: https://lore.kernel.org/r/20200704001003.2303-1-cai@lca.pwSigned-off-by: NJoerg Roedel <jroedel@suse.de>
      9ac85451