Commit Graph

89 Commits

Author SHA1 Message Date
Jerry Snitselaar 24e9c7b30a dma-mapping: report unlimited DMA addressing in IOMMU DMA path
JIRA: https://issues.redhat.com/browse/RHEL-61942
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit b348b6d17fd1d5d89b86db602f02bea54a754bd8
Author: Leon Romanovsky <leon@kernel.org>
Date:   Sun Sep 22 21:09:48 2024 +0300

    dma-mapping: report unlimited DMA addressing in IOMMU DMA path

    While using the IOMMU DMA path, the dma_addressing_limited() function
    checks ops struct which doesn't exist in the IOMMU case. This causes
    to the kernel panic while loading ADMGPU driver.

    BUG: kernel NULL pointer dereference, address: 00000000000000a0
    PGD 0 P4D 0
    Oops: Oops: 0000 [#1] PREEMPT SMP NOPTI
    CPU: 10 UID: 0 PID: 611 Comm: (udev-worker) Tainted: G                T  6.11.0-clang-07154-g726e2d0cf2bb #257
    Tainted: [T]=RANDSTRUCT
    Hardware name: ASUS System Product Name/ROG STRIX Z690-G GAMING WIFI, BIOS 3701 07/03/2024
    RIP: 0010:dma_addressing_limited+0x53/0xa0
    Code: 8b 93 48 02 00 00 48 39 d1 49 89 d6 4c 0f 42 f1 48 85 d2 4c 0f 44 f1 f6 83 fc 02 00 00 40 75 0a 48 89 df e8 1f 09 00 00 eb 24 <4c> 8b 1c 25 a0 00 00 00 4d 85 db 74 17 48 89 df 41 ba 8b 84 2d 55
    RSP: 0018:ffffa8d2c12cf740 EFLAGS: 00010202
    RAX: 00000000ffffffff RBX: ffff8948820220c8 RCX: 000000ffffffffff
    RDX: 0000000000000000 RSI: ffffffffc124dc6d RDI: ffff8948820220c8
    RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000000 R12: ffff894883c3f040
    R13: ffff89488dac8828 R14: 000000ffffffffff R15: ffff8948820220c8
    FS:  00007fe6ba881900(0000) GS:ffff894fdf700000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00000000000000a0 CR3: 0000000111984000 CR4: 0000000000f50ef0
    PKRU: 55555554
    Call Trace:
     <TASK>
     ? __die_body+0x65/0xc0
     ? page_fault_oops+0x3b9/0x450
     ? _prb_read_valid+0x212/0x390
     ? do_user_addr_fault+0x608/0x680
     ? exc_page_fault+0x4e/0xa0
     ? asm_exc_page_fault+0x26/0x30
     ? dma_addressing_limited+0x53/0xa0
     amdgpu_ttm_init+0x56/0x4b0 [amdgpu]
     gmc_v8_0_sw_init+0x561/0x670 [amdgpu]
     amdgpu_device_ip_init+0xf5/0x570 [amdgpu]
     amdgpu_device_init+0x1a57/0x1ea0 [amdgpu]
     ? _raw_spin_unlock_irqrestore+0x1a/0x40
     ? pci_conf1_read+0xc0/0xe0
     ? pci_bus_read_config_word+0x52/0xa0
     amdgpu_driver_load_kms+0x15/0xa0 [amdgpu]
     amdgpu_pci_probe+0x1b7/0x4c0 [amdgpu]
     pci_device_probe+0x1c5/0x260
     really_probe+0x130/0x470
     __driver_probe_device+0x77/0x150
     driver_probe_device+0x19/0x120
     __driver_attach+0xb1/0x1e0
     ? __cfi___driver_attach+0x10/0x10
     bus_for_each_dev+0x115/0x170
     bus_add_driver+0x192/0x2d0
     driver_register+0x5c/0xf0
     ? __cfi_init_module+0x10/0x10 [amdgpu]
     do_one_initcall+0x128/0x380
     ? idr_alloc_cyclic+0x139/0x1d0
     ? security_kernfs_init_security+0x42/0x140
     ? __kernfs_new_node+0x1be/0x250
     ? sysvec_apic_timer_interrupt+0xb6/0xc0
     ? asm_sysvec_apic_timer_interrupt+0x1a/0x20
     ? _raw_spin_unlock+0x11/0x30
     ? free_unref_page+0x283/0x650
     ? kfree+0x274/0x3a0
     ? kfree+0x274/0x3a0
     ? kfree+0x274/0x3a0
     ? load_module+0xf2e/0x1130
     ? __kmalloc_cache_noprof+0x12a/0x2e0
     do_init_module+0x7d/0x240
     __se_sys_init_module+0x19e/0x220
     do_syscall_64+0x8a/0x150
     ? __irq_exit_rcu+0x5e/0x100
     entry_SYSCALL_64_after_hwframe+0x76/0x7e
    RIP: 0033:0x7fe6bb5980ee
    Code: 48 8b 0d 3d ed 12 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 49 89 ca b8 af 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 0a ed 12 00 f7 d8 64 89 01 48
    RSP: 002b:00007ffd462219d8 EFLAGS: 00000206 ORIG_RAX: 00000000000000af
    RAX: ffffffffffffffda RBX: 0000556caf0d0670 RCX: 00007fe6bb5980ee
    RDX: 0000556caf0d3080 RSI: 0000000002893458 RDI: 00007fe6b3400010
    RBP: 0000000000020000 R08: 0000000000020010 R09: 0000000000000080
    R10: c26073c166186e00 R11: 0000000000000206 R12: 0000556caf0d3430
    R13: 0000556caf0d0670 R14: 0000556caf0d3080 R15: 0000556caf0ce700
     </TASK>
    Modules linked in: amdgpu(+) i915(+) drm_suballoc_helper intel_gtt drm_exec drm_buddy iTCO_wdt i2c_algo_bit intel_pmc_bxt drm_display_helper iTCO_vendor_support gpu_sched drm_ttm_helper cec ttm amdxcp video backlight pinctrl_alderlake nct6775 hwmon_vid nct6775_core coretemp
    CR2: 00000000000000a0
    ---[ end trace 0000000000000000 ]---
    RIP: 0010:dma_addressing_limited+0x53/0xa0
    Code: 8b 93 48 02 00 00 48 39 d1 49 89 d6 4c 0f 42 f1 48 85 d2 4c 0f 44 f1 f6 83 fc 02 00 00 40 75 0a 48 89 df e8 1f 09 00 00 eb 24 <4c> 8b 1c 25 a0 00 00 00 4d 85 db 74 17 48 89 df 41 ba 8b 84 2d 55
    RSP: 0018:ffffa8d2c12cf740 EFLAGS: 00010202
    RAX: 00000000ffffffff RBX: ffff8948820220c8 RCX: 000000ffffffffff
    RDX: 0000000000000000 RSI: ffffffffc124dc6d RDI: ffff8948820220c8
    RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000000 R12: ffff894883c3f040
    R13: ffff89488dac8828 R14: 000000ffffffffff R15: ffff8948820220c8
    FS:  00007fe6ba881900(0000) GS:ffff894fdf700000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00000000000000a0 CR3: 0000000111984000 CR4: 0000000000f50ef0
    PKRU: 55555554

    Fixes: b5c58b2fdc42 ("dma-mapping: direct calls for dma-iommu")
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219292
    Reported-by: Niklāvs Koļesņikovs <pinkflames.linux@gmail.com>
    Signed-off-by: Leon Romanovsky <leon@kernel.org>
    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Tested-by: Niklāvs Koļesņikovs <pinkflames.linux@gmail.com>

(cherry picked from commit b348b6d17fd1d5d89b86db602f02bea54a754bd8)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-11-04 08:57:41 -07:00
Jerry Snitselaar 8d0026d876 dma-mapping: fix vmap and mmap of noncontiougs allocations
JIRA: https://issues.redhat.com/browse/RHEL-61942
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit bb0e391975f8da826305cbaa3e3d34b03c47e2a6
Author: Christoph Hellwig <hch@lst.de>
Date:   Sun Sep 22 09:10:17 2024 +0200

    dma-mapping: fix vmap and mmap of noncontiougs allocations

    Commit b5c58b2fdc42 ("dma-mapping: direct calls for dma-iommu") switched
    to use direct calls to dma-iommu, but missed the dma_vmap_noncontiguous,
    dma_vunmap_noncontiguous and dma_mmap_noncontiguous behavior keyed off the
    presence of the alloc_noncontiguous method.

    Fix this by removing the now unused alloc_noncontiguous and
    free_noncontiguous methods and moving the vmapping and mmaping of the
    noncontiguous allocations into the iommu code, as it is the only provider
    of actually noncontiguous allocations.

    Fixes: b5c58b2fdc42 ("dma-mapping: direct calls for dma-iommu")
    Reported-by: Xi Ruoyao <xry111@xry111.site>
    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Reviewed-by: Leon Romanovsky <leon@kernel.org>
    Tested-by: Xi Ruoyao <xry111@xry111.site>

(cherry picked from commit bb0e391975f8da826305cbaa3e3d34b03c47e2a6)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-11-04 08:57:41 -07:00
Jerry Snitselaar d7b1a448aa dma-mapping: reflow dma_supported
JIRA: https://issues.redhat.com/browse/RHEL-61942
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit a5fb217f13f74b2af2ab366ffad522bae717f93c
Author: Christoph Hellwig <hch@lst.de>
Date:   Thu Sep 12 09:21:18 2024 +0200

    dma-mapping: reflow dma_supported

    dma_supported has become too much spaghetti for my taste.  Reflow it to
    remove the duplicate use_dma_iommu condition and make the main path more
    obvious.

    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Reviewed-by: Leon Romanovsky <leon@kernel.org>

(cherry picked from commit a5fb217f13f74b2af2ab366ffad522bae717f93c)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-11-04 08:57:40 -07:00
Jerry Snitselaar acf7087404 dma-mapping: reliably inform about DMA support for IOMMU
JIRA: https://issues.redhat.com/browse/RHEL-61942
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit f45cfab28fcd5ac67a38750b6c68316b26d35ac8
Author: Leon Romanovsky <leon@kernel.org>
Date:   Wed Sep 11 13:15:00 2024 +0300

    dma-mapping: reliably inform about DMA support for IOMMU

    If the DMA IOMMU path is going to be used, the appropriate check should
    return that DMA is supported.

    Fixes: b5c58b2fdc42 ("dma-mapping: direct calls for dma-iommu")
    Closes: https://lore.kernel.org/all/181e06ff-35a3-434f-b505-672f430bd1cb@notapiano
    Reported-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> #KernelCI
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Reviewed-by: Robin Murphy <robin.murphy@arm.com>
    Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit f45cfab28fcd5ac67a38750b6c68316b26d35ac8)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-11-04 08:57:40 -07:00
Jerry Snitselaar 824f914266 dma-mapping: add tracing for dma-mapping API calls
JIRA: https://issues.redhat.com/browse/RHEL-61942
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Conflicts: __assign_str takes 2 arguments. 2c92ca849fcc ("tracing/treewide: Remove second parameter of __assign_str()")
           not backported yet.

commit 038eb433dc1474c4bc7d33188294e3d4778efdfd
Author: Sean Anderson <sean.anderson@linux.dev>
Date:   Fri Sep 6 17:54:34 2024 -0400

    dma-mapping: add tracing for dma-mapping API calls

    When debugging drivers, it can often be useful to trace when memory gets
    (un)mapped for DMA (and can be accessed by the device). Add some
    tracepoints for this purpose.

    Use u64 instead of phys_addr_t and dma_addr_t (and similarly %llx instead
    of %pa) because libtraceevent can't handle typedefs in all cases.

    Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit 038eb433dc1474c4bc7d33188294e3d4778efdfd)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-11-04 08:57:39 -07:00
Jerry Snitselaar 9fe0e7992a dma-mapping: use IOMMU DMA calls for common alloc/free page calls
JIRA: https://issues.redhat.com/browse/RHEL-61942
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 19156263cb1f24128a9ba6ef7340be5cbacc3d22
Author: Leon Romanovsky <leon@kernel.org>
Date:   Thu Sep 5 10:14:05 2024 +0300

    dma-mapping: use IOMMU DMA calls for common alloc/free page calls

    Common alloca and free pages routines are called when IOMMU DMA is used,
    and internally it calls to DMA ops structure which is not available for
    default IOMMU. This patch adds necessary if checks to call IOMMU DMA.

    It fixes the following crash:

     Unable to handle kernel NULL pointer dereference at virtual address 0000000000000040
     Mem abort info:
       ESR = 0x0000000096000006
       EC = 0x25: DABT (current EL), IL = 32 bits
       SET = 0, FnV = 0
       EA = 0, S1PTW = 0
       FSC = 0x06: level 2 translation fault
     Data abort info:
       ISV = 0, ISS = 0x00000006, ISS2 = 0x00000000
       CM = 0, WnR = 0, TnD = 0, TagAccess = 0
       GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
     user pgtable: 4k pages, 48-bit VAs, pgdp=00000000d20bb000
     [0000000000000040] pgd=08000000d20c1003
     , p4d=08000000d20c1003
     , pud=08000000d20c2003, pmd=0000000000000000
     Internal error: Oops: 0000000096000006 [#1] PREEMPT SMP
     Modules linked in: ipv6 hci_uart venus_core btqca
    v4l2_mem2mem btrtl qcom_spmi_adc5 sbs_battery btbcm qcom_vadc_common
    cros_ec_typec videobuf2_v4l2 leds_cros_ec cros_kbd_led_backlight
    cros_ec_chardev videodev elan_i2c
    videobuf2_common qcom_stats mc bluetooth coresight_stm stm_core
    ecdh_generic ecc pwrseq_core panel_edp icc_bwmon ath10k_snoc ath10k_core
    ath mac80211 phy_qcom_qmp_combo aux_bridge libarc4 coresight_replicator
    coresight_etm4x coresight_tmc
    coresight_funnel cfg80211 rfkill coresight qcom_wdt cbmem ramoops
    reed_solomon pwm_bl coreboot_table backlight crct10dif_ce
     CPU: 7 UID: 0 PID: 70 Comm: kworker/u32:4 Not tainted 6.11.0-rc6-next-20240903-00003-gdfc6015d0711 #660
     Hardware name: Google Lazor Limozeen without Touchscreen (rev5 - rev8) (DT)
     Workqueue: events_unbound deferred_probe_work_func
     hub 2-1:1.0: 4 ports detected

     pstate: 80400009 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
     pc : dma_common_alloc_pages+0x54/0x1b4
     lr : dma_common_alloc_pages+0x4c/0x1b4
     sp : ffff8000807d3730
     x29: ffff8000807d3730 x28: ffff02a7d312f880 x27: 0000000000000001
     x26: 000000000000c000 x25: 0000000000000000 x24: 0000000000000001
     x23: ffff02a7d23b6898 x22: 0000000000006cc0 x21: 000000000000c000
     x20: ffff02a7858bf410 x19: fffffe0a60006000 x18: 0000000000000001
     x17: 00000000000000d5 x16: 1fffe054f0bcc261 x15: 0000000000000001
     x14: ffff02a7844dc680 x13: 0000000000100180 x12: dead000000000100
     x11: dead000000000122 x10: 00000000001001ff x9 : ffff02a87f7b7b00
     x8 : ffff02a87f7b7b00 x7 : ffff405977d6b000 x6 : ffff8000807d3310
     x5 : ffff02a87f6b6398 x4 : 0000000000000001 x3 : ffff405977d6b000
     x2 : ffff02a7844dc600 x1 : 0000000100000000 x0 : fffffe0a60006000
     Call trace:
      dma_common_alloc_pages+0x54/0x1b4
      __dma_alloc_pages+0x68/0x90
      dma_alloc_pages+0x10/0x1c
      snd_dma_noncoherent_alloc+0x28/0x8c
      __snd_dma_alloc_pages+0x30/0x50
      snd_dma_alloc_dir_pages+0x40/0x80
      do_alloc_pages+0xb8/0x13c
      preallocate_pcm_pages+0x6c/0xf8
      preallocate_pages+0x160/0x1a4
      snd_pcm_set_managed_buffer_all+0x64/0xb0
      lpass_platform_pcm_new+0xc0/0xe8
      snd_soc_pcm_component_new+0x3c/0xc8
      soc_new_pcm+0x4fc/0x668
      snd_soc_bind_card+0xabc/0xbac
      snd_soc_register_card+0xf0/0x108
      devm_snd_soc_register_card+0x4c/0xa4
      sc7180_snd_platform_probe+0x180/0x224
      platform_probe+0x68/0xc0
      really_probe+0xbc/0x298
      __driver_probe_device+0x78/0x12c
      driver_probe_device+0x3c/0x15c
      __device_attach_driver+0xb8/0x134
      bus_for_each_drv+0x84/0xe0
      __device_attach+0x9c/0x188
      device_initial_probe+0x14/0x20
      bus_probe_device+0xac/0xb0
      deferred_probe_work_func+0x88/0xc0
      process_one_work+0x14c/0x28c
      worker_thread+0x2cc/0x3d4
      kthread+0x114/0x118
      ret_from_fork+0x10/0x20
     Code: f9411c19 940000c9 aa0003f3 b4000460 (f9402326)
     ---[ end trace 0000000000000000 ]---

    Fixes: b5c58b2fdc42 ("dma-mapping: direct calls for dma-iommu")
    Closes: https://lore.kernel.org/all/10431dfd-ce04-4e0f-973b-c78477303c18@notapiano
    Reported-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> #KernelCI
    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit 19156263cb1f24128a9ba6ef7340be5cbacc3d22)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-11-04 08:57:39 -07:00
Jerry Snitselaar 3133d6592c dma-mapping: direct calls for dma-iommu
JIRA: https://issues.redhat.com/browse/RHEL-61942
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Conflicts: Context diff due to IA64 removal commits not being backported to RHEL

commit b5c58b2fdc427e7958412ecb2de2804a1f7c1572
Author: Leon Romanovsky <leon@kernel.org>
Date:   Wed Jul 24 21:04:49 2024 +0300

    dma-mapping: direct calls for dma-iommu

    Directly call into dma-iommu just like we have been doing for dma-direct
    for a while.  This avoids the indirect call overhead for IOMMU ops and
    removes the need to have DMA ops entirely for many common configurations.

    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Leon Romanovsky <leon@kernel.org>
    Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Acked-by: Robin Murphy <robin.murphy@arm.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit b5c58b2fdc427e7958412ecb2de2804a1f7c1572)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-11-04 08:57:36 -07:00
Jerry Snitselaar 5cd5cf3439 dma-mapping: call ->unmap_page and ->unmap_sg unconditionally
JIRA: https://issues.redhat.com/browse/RHEL-61942
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit f69e342eec008e1bab772d3963c3dd9979293e13
Author: Leon Romanovsky <leon@kernel.org>
Date:   Wed Jul 24 21:04:48 2024 +0300

    dma-mapping: call ->unmap_page and ->unmap_sg unconditionally

    Almost all instances of the dma_map_ops ->map_page()/map_sg() methods
    implement ->unmap_page()/unmap_sg() too.  The once instance which doesn't
    dma_dummy_ops which is used to fail the DMA mapping and thus there won't
    be any calls to ->unmap_page()/unmap_sg().

    Remove the checks for ->unmap_page()/unmap_sg() and call them directly to
    create an interface that is symmetrical to ->map_page()/map_sg().

    Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
    Signed-off-by: Leon Romanovsky <leon@kernel.org>
    Reviewed-by: Robin Murphy <robin.murphy@arm.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit f69e342eec008e1bab772d3963c3dd9979293e13)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-11-04 08:57:35 -07:00
Rado Vrbovsky a5ea1cdd29 Merge: 9.6 IOMMU and DMA api updates
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5113

# Merge Request Required Information

JIRA: https://issues.redhat.com/browse/RHEL-36247  
JIRA: https://issues.redhat.com/browse/RHEL-54186  
JIRA: https://issues.redhat.com/browse/RHEL-54189    
JIRA: https://issues.redhat.com/browse/RHEL-55199  
JIRA: https://issues.redhat.com/browse/RHEL-55200    
JIRA: https://issues.redhat.com/browse/RHEL-55448  
JIRA: https://issues.redhat.com/browse/RHEL-55450  
JIRA: https://issues.redhat.com/browse/RHEL-55466  
JIRA: https://issues.redhat.com/browse/RHEL-57229  
Upstream: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git  
CVE: CVE-2024-44994  

## Summary of Changes

This brings the IOMMU and DMA api subsystems in line with v6.11. Overall it is smaller than normal, but I expect there will be another MR later on with some things landing in v6.12. In addition to the usual fixes, and cleanups the major changes are:

- iommufd io page fault support
- smmuv3 dirty page tracking support
- vt-d cache tagging support
- iommu memory usage observability support
- Some cleanups from Robin related to dma range calculation, arch setup_dma_ops, and iommu_fwspec_ops
- Another batch of updates to smmuv3 from Jason's reworking of the driver (2b/3)

There also is a rhel only cleanup to deal with a cleanup in the iommufd code by Linus in one of merges that was related to some mm changes at the time, but wasn't dealt with when the iommufd or mm changes were merged to rhel.

Testing:

- kernel-tests iommu new-boot testing
- kernel-tests iommu fio testing
- kernel-tests dmatest and idxd tests
- iommufd kernel selftest
- general cki testing


v5: Added 3 fixes that recently landed upstream.  
v6: Resolve issues raised by Don:  

    - Conflicts note updates  
    - Backport of acpi, and arm7 io-pgtable commit.  
    - While doing this I went through to diff against upstream and cleaned up a couple more merge commit cleanups:  

      * __GFP_ZERO use in amd ppr log alloc code.
      * Line break in swiotlb code.
      * dead config option in drivers/iommu/intel/Kconfig  

    - Hyperv commit that was missed in previous backports.  
v7: Fixed typo from using Conflict instead of Conflicts for tag.  
v8: Fixed borked conflict resolution after adding acpi patch in v6.  
v10: Added dt bindings commit mentioned by Eric.  
v11: Rebase due to merge conflict after acpi MR merged. This also drops a couple acpi commits that were now empty.  

Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>

## Approved Development Ticket
All submissions to CentOS Stream must reference an approved ticket in [Red Hat Jira](https://issues.redhat.com/). Please follow the CentOS Stream [contribution documentation](https://docs.centos.org/en-US/stream-contrib/quickstart/) for how to file this ticket and have it approved.

Approved-by: José Ignacio Tornos Martínez <jtornosm@redhat.com>
Approved-by: Mark Salter <msalter@redhat.com>
Approved-by: Marcelo Ricardo Leitner <mleitner@redhat.com>
Approved-by: Donald Dutile <ddutile@redhat.com>
Approved-by: Steve Best <sbest@redhat.com>
Approved-by: David Arcari <darcari@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2024-10-19 08:07:00 +00:00
Eder Zulian 21d9dc6914 dma: fix call order in dmam_free_coherent
JIRA: https://issues.redhat.com/browse/RHEL-54751
CVE: CVE-2024-43856

commit 28e8b7406d3a1f5329a03aa25a43aa28e087cb20
Author: Lance Richardson <rlance@google.com>
Date:   Thu Jul 18 14:38:24 2024 +0000

    dma: fix call order in dmam_free_coherent

    dmam_free_coherent() frees a DMA allocation, which makes the
    freed vaddr available for reuse, then calls devres_destroy()
    to remove and free the data structure used to track the DMA
    allocation. Between the two calls, it is possible for a
    concurrent task to make an allocation with the same vaddr
    and add it to the devres list.

    If this happens, there will be two entries in the devres list
    with the same vaddr and devres_destroy() can free the wrong
    entry, triggering the WARN_ON() in dmam_match.

    Fix by destroying the devres entry before freeing the DMA
    allocation.

    Tested:
      kokonut //net/encryption
        http://sponge2/b9145fe6-0f72-4325-ac2f-a84d81075b03

    Fixes: 9ac7849e35 ("devres: device resource management")
    Signed-off-by: Lance Richardson <rlance@google.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

Signed-off-by: Eder Zulian <ezulian@redhat.com>
2024-09-26 12:37:18 +02:00
Jerry Snitselaar c6caed2601 change alloc_pages name in dma_map_ops to avoid name conflicts
JIRA: https://issues.redhat.com/browse/RHEL-55466
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Conflicts: Dropped unsupported bits.

commit 8a2f11878771da65b8ac135c73b47dae13afbd62
Author: Suren Baghdasaryan <surenb@google.com>
Date:   Thu Mar 21 09:36:39 2024 -0700

    change alloc_pages name in dma_map_ops to avoid name conflicts

    After redefining alloc_pages, all uses of that name are being replaced.
    Change the conflicting names to prevent preprocessor from replacing them
    when it's not intended.

    Link: https://lkml.kernel.org/r/20240321163705.3067592-18-surenb@google.com
    Signed-off-by: Suren Baghdasaryan <surenb@google.com>
    Tested-by: Kees Cook <keescook@chromium.org>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: Alex Gaynor <alex.gaynor@gmail.com>
    Cc: Alice Ryhl <aliceryhl@google.com>
    Cc: Andreas Hindborg <a.hindborg@samsung.com>
    Cc: Benno Lossin <benno.lossin@proton.me>
    Cc: "Björn Roy Baron" <bjorn3_gh@protonmail.com>
    Cc: Boqun Feng <boqun.feng@gmail.com>
    Cc: Christoph Lameter <cl@linux.com>
    Cc: Dennis Zhou <dennis@kernel.org>
    Cc: Gary Guo <gary@garyguo.net>
    Cc: Kent Overstreet <kent.overstreet@linux.dev>
    Cc: Miguel Ojeda <ojeda@kernel.org>
    Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Tejun Heo <tj@kernel.org>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: Wedson Almeida Filho <wedsonaf@gmail.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

(cherry picked from commit 8a2f11878771da65b8ac135c73b47dae13afbd62)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-09-20 12:29:01 -07:00
Jerry Snitselaar 928815f982 dma: fix DMA sync for drivers not calling dma_set_mask*()
JIRA: https://issues.redhat.com/browse/RHEL-44835
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit a6016aac5252da9d22a4dc0b98121b0acdf6d2f5
Author: Alexander Lobakin <aleksander.lobakin@intel.com>
Date:   Thu May 9 16:46:16 2024 +0200

    dma: fix DMA sync for drivers not calling dma_set_mask*()

    There are several reports that the DMA sync shortcut broke non-coherent
    devices.
    dev->dma_need_sync is false after the &device allocation and if a driver
    didn't call dma_set_mask*(), it will still be false even if the device
    is not DMA-coherent and thus needs synchronizing. Due to historical
    reasons, there's still a lot of drivers not calling it.
    Invert the boolean, so that the sync will be performed by default and
    the shortcut will be enabled only when calling dma_set_mask*().

    Reported-by: Steven Price <steven.price@arm.com>
    Closes: https://lore.kernel.org/lkml/010686f5-3049-46a1-8230-7752a1b433ff@arm.com
    Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
    Closes: https://lore.kernel.org/lkml/46160534-5003-4809-a408-6b3a3f4921e9@samsung.com
    Fixes: f406c8e4b770. ("dma: avoid redundant calls for sync operations")
    Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Tested-by: Steven Price <steven.price@arm.com>
    Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

(cherry picked from commit a6016aac5252da9d22a4dc0b98121b0acdf6d2f5)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-06-25 15:16:44 -07:00
Jerry Snitselaar a04da03030 dma: avoid redundant calls for sync operations
JIRA: https://issues.redhat.com/browse/RHEL-44835
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit f406c8e4b770ca3b0df84a17349e13f2b6b07d10
Author: Alexander Lobakin <aleksander.lobakin@intel.com>
Date:   Tue May 7 13:20:21 2024 +0200

    dma: avoid redundant calls for sync operations

    Quite often, devices do not need dma_sync operations on x86_64 at least.
    Indeed, when dev_is_dma_coherent(dev) is true and
    dev_use_swiotlb(dev) is false, iommu_dma_sync_single_for_cpu()
    and friends do nothing.

    However, indirectly calling them when CONFIG_RETPOLINE=y consumes about
    10% of cycles on a cpu receiving packets from softirq at ~100Gbit rate.
    Even if/when CONFIG_RETPOLINE is not set, there is a cost of about 3%.

    Add dev->need_dma_sync boolean and turn it off during the device
    initialization (dma_set_mask()) depending on the setup:
    dev_is_dma_coherent() for the direct DMA, !(sync_single_for_device ||
    sync_single_for_cpu) or the new dma_map_ops flag, %DMA_F_CAN_SKIP_SYNC,
    advertised for non-NULL DMA ops.
    Then later, if/when swiotlb is used for the first time, the flag
    is reset back to on, from swiotlb_tbl_map_single().

    On iavf, the UDP trafficgen with XDP_DROP in skb mode test shows
    +3-5% increase for direct DMA.

    Suggested-by: Christoph Hellwig <hch@lst.de> # direct DMA shortcut
    Co-developed-by: Eric Dumazet <edumazet@google.com>
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit f406c8e4b770ca3b0df84a17349e13f2b6b07d10)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-06-25 15:16:43 -07:00
Jerry Snitselaar 37627dec92 dma: compile-out DMA sync op calls when not used
JIRA: https://issues.redhat.com/browse/RHEL-44835
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit fe7514b149e0a8a6f3031d286e52d40163b0b11a
Author: Alexander Lobakin <aleksander.lobakin@intel.com>
Date:   Tue May 7 13:20:20 2024 +0200

    dma: compile-out DMA sync op calls when not used

    Some platforms do have DMA, but DMA there is always direct and coherent.
    Currently, even on such platforms DMA sync operations are compiled and
    called.
    Add a new hidden Kconfig symbol, DMA_NEED_SYNC, and set it only when
    either sync operations are needed or there is DMA ops or swiotlb
    or DMA debug is enabled. Compile global dma_sync_*() and dma_need_sync()
    only when it's set, otherwise provide empty inline stubs.
    The change allows for future optimizations of DMA sync calls depending
    on runtime conditions.

    Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit fe7514b149e0a8a6f3031d286e52d40163b0b11a)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-06-25 15:16:43 -07:00
Jerry Snitselaar 478b900bef dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM
JIRA: https://issues.redhat.com/browse/RHEL-28780
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit a409d9600959f3c4b2a48946304c8e01b8d04072
Author: Jia He <justin.he@arm.com>
Date:   Sat Oct 28 10:20:59 2023 +0000

    dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM

    There is an unusual case that the range map covers right up to the top
    of system RAM, but leaves a hole somewhere lower down. Then it prevents
    the nvme device dma mapping in the checking path of phys_to_dma() and
    causes the hangs at boot.

    E.g. On an Armv8 Ampere server, the dsdt ACPI table is:
     Method (_DMA, 0, Serialized)  // _DMA: Direct Memory Access
		{
		    Name (RBUF, ResourceTemplate ()
		    {
			QWordMemory (ResourceConsumer, PosDecode, MinFixed,
    MaxFixed, Cacheable, ReadWrite,
			    0x0000000000000000, // Granularity
			    0x0000000000000000, // Range Minimum
			    0x00000000FFFFFFFF, // Range Maximum
			    0x0000000000000000, // Translation Offset
			    0x0000000100000000, // Length
			    ,, , AddressRangeMemory, TypeStatic)
			QWordMemory (ResourceConsumer, PosDecode, MinFixed,
    MaxFixed, Cacheable, ReadWrite,
			    0x0000000000000000, // Granularity
			    0x0000006010200000, // Range Minimum
			    0x000000602FFFFFFF, // Range Maximum
			    0x0000000000000000, // Translation Offset
			    0x000000001FE00000, // Length
			    ,, , AddressRangeMemory, TypeStatic)
			QWordMemory (ResourceConsumer, PosDecode, MinFixed,
    MaxFixed, Cacheable, ReadWrite,
			    0x0000000000000000, // Granularity
			    0x00000060F0000000, // Range Minimum
			    0x00000060FFFFFFFF, // Range Maximum
			    0x0000000000000000, // Translation Offset
			    0x0000000010000000, // Length
			    ,, , AddressRangeMemory, TypeStatic)
			QWordMemory (ResourceConsumer, PosDecode, MinFixed,
    MaxFixed, Cacheable, ReadWrite,
			    0x0000000000000000, // Granularity
			    0x0000007000000000, // Range Minimum
			    0x000003FFFFFFFFFF, // Range Maximum
			    0x0000000000000000, // Translation Offset
			    0x0000039000000000, // Length
			    ,, , AddressRangeMemory, TypeStatic)
		    })

    But the System RAM ranges are:
    cat /proc/iomem |grep -i ram
    90000000-91ffffff : System RAM
    92900000-fffbffff : System RAM
    880000000-fffffffff : System RAM
    8800000000-bff5990fff : System RAM
    bff59d0000-bff5a4ffff : System RAM
    bff8000000-bfffffffff : System RAM
    So some RAM ranges are out of dma_range_map.

    Fix it by checking whether each of the system RAM resources can be
    properly encompassed within the dma_range_map.

    Signed-off-by: Jia He <justin.he@arm.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit a409d9600959f3c4b2a48946304c8e01b8d04072)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-05-13 08:16:42 -07:00
Jerry Snitselaar 27e0f28524 dma-mapping: move dma_addressing_limited() out of line
JIRA: https://issues.redhat.com/browse/RHEL-28780
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 8ae0e970319ac0b516d285650a744bab4ed3dd37
Author: Jia He <justin.he@arm.com>
Date:   Sat Oct 28 10:20:58 2023 +0000

    dma-mapping: move dma_addressing_limited() out of line

    This patch moves dma_addressing_limited() out of line, serving as a
    preliminary step to prevent the introduction of a new publicly accessible
    low-level helper when validating whether all system RAM is mapped within
    the DMA mapping range.

    Suggested-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Jia He <justin.he@arm.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit 8ae0e970319ac0b516d285650a744bab4ed3dd37)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2024-05-13 08:16:42 -07:00
Chris Leech 3e2dc0427a Reapply "dma-mapping: reject __GFP_COMP in dma_alloc_attrs"
JIRA: https://issues.redhat.com/browse/RHEL-26081
Upstream Status: RHEL Only

This reverts commit e270ee3445.

Signed-off-by: Chris Leech <cleech@redhat.com>
2024-02-19 10:00:36 -08:00
Jerry Snitselaar d749ca4e35 dma-mapping: move arch_dma_set_mask() declaration to header
JIRA: https://issues.redhat.com/browse/RHEL-10094
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 3d6f126b15d9fd8435455fffc912d976973a7a09
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Thu Jul 27 14:25:42 2023 +0200

    dma-mapping: move arch_dma_set_mask() declaration to header

    This function has a __weak definition and an override that is only used on
    freescale powerpc chips. The powerpc definition however does not see the
    declaration that is in a .c file:

    arch/powerpc/kernel/dma-mask.c:7:6: error: no previous prototype for 'arch_dma_set_mask' [-Werror=missing-prototypes]

    Move it into the linux/dma-map-ops.h header where the other arch_dma_* functions
    are declared.

    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit 3d6f126b15d9fd8435455fffc912d976973a7a09)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2023-10-27 01:26:58 -07:00
Jerry Snitselaar 10a880e08a dma-mapping: provide CONFIG_ARCH_DMA_DEFAULT_COHERENT
JIRA: https://issues.redhat.com/browse/RHEL-10094
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 1d3f56b295302fdb4ac9caf6ce09f5ae7d2e651a
Author: Jiaxun Yang <jiaxun.yang@flygoat.com>
Date:   Sat Apr 1 10:15:30 2023 +0100

    dma-mapping: provide CONFIG_ARCH_DMA_DEFAULT_COHERENT

    Provide a kconfig option to allow arches to manipulate default
    value of dma_default_coherent in Kconfig.

    Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit 1d3f56b295302fdb4ac9caf6ce09f5ae7d2e651a)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2023-10-27 01:26:58 -07:00
Jerry Snitselaar 1a32edda5c dma-mapping: provide a fallback dma_default_coherent
JIRA: https://issues.redhat.com/browse/RHEL-10094
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit fe4e5efa401fe15eab9259e358730145449e83a2
Author: Jiaxun Yang <jiaxun.yang@flygoat.com>
Date:   Sat Apr 1 10:15:29 2023 +0100

    dma-mapping: provide a fallback dma_default_coherent

    dma_default_coherent was decleared unconditionally at kernel/dma/mapping.c
    but only decleared when any of non-coherent options is enabled in
    dma-map-ops.h.

    Guard the declaration in mapping.c with non-coherent options and provide
    a fallback definition.

    Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit fe4e5efa401fe15eab9259e358730145449e83a2)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2023-10-27 01:26:58 -07:00
Chris von Recklinghausen 876fba98cd dma: kmsan: unpoison DMA mappings
JIRA: https://issues.redhat.com/browse/RHEL-1848

commit 7ade4f10779cb46f5c29ced9b7a41f68501cf0ed
Author: Alexander Potapenko <glider@google.com>
Date:   Thu Sep 15 17:03:55 2022 +0200

    dma: kmsan: unpoison DMA mappings

    KMSAN doesn't know about DMA memory writes performed by devices.  We
    unpoison such memory when it's mapped to avoid false positive reports.

    Link: https://lkml.kernel.org/r/20220915150417.722975-22-glider@google.com
    Signed-off-by: Alexander Potapenko <glider@google.com>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: Alexei Starovoitov <ast@kernel.org>
    Cc: Andrey Konovalov <andreyknvl@gmail.com>
    Cc: Andrey Konovalov <andreyknvl@google.com>
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Christoph Hellwig <hch@lst.de>
    Cc: Christoph Lameter <cl@linux.com>
    Cc: David Rientjes <rientjes@google.com>
    Cc: Dmitry Vyukov <dvyukov@google.com>
    Cc: Eric Biggers <ebiggers@google.com>
    Cc: Eric Biggers <ebiggers@kernel.org>
    Cc: Eric Dumazet <edumazet@google.com>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Herbert Xu <herbert@gondor.apana.org.au>
    Cc: Ilya Leoshkevich <iii@linux.ibm.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jens Axboe <axboe@kernel.dk>
    Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
    Cc: Kees Cook <keescook@chromium.org>
    Cc: Marco Elver <elver@google.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Michael S. Tsirkin <mst@redhat.com>
    Cc: Pekka Enberg <penberg@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Petr Mladek <pmladek@suse.com>
    Cc: Stephen Rothwell <sfr@canb.auug.org.au>
    Cc: Steven Rostedt <rostedt@goodmis.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Vasily Gorbik <gor@linux.ibm.com>
    Cc: Vegard Nossum <vegard.nossum@oracle.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
2023-10-20 06:14:38 -04:00
Chris Leech e270ee3445 Revert "dma-mapping: reject __GFP_COMP in dma_alloc_attrs"
JIRA: https://issues.redhat.com/browse/RHEL-2542
Upstream Status: RHEL Only

This reverts commit a2cfbf05cd.

bnx2i/cnic currently fails to properly mmap its dma_alloc_coherent
buffers through a uio interface without being able to allocate compound
pages.  Revert this until we can get a better cnic fix.

Signed-off-by: Chris Leech <cleech@redhat.com>
2023-09-27 08:24:24 -07:00
Jerry Snitselaar a2cfbf05cd dma-mapping: reject __GFP_COMP in dma_alloc_attrs
Bugzilla: https://bugzilla.redhat.com/2181354
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit ffcb754584603adf7039d7972564fbf6febdc542
Author: Christoph Hellwig <hch@lst.de>
Date:   Wed Nov 9 08:37:17 2022 +0100

    dma-mapping: reject __GFP_COMP in dma_alloc_attrs

    DMA allocations can never be turned back into a page pointer, so
    requesting compound pages doesn't make sense and it can't even be
    supported at all by various backends.

    Reject __GFP_COMP with a warning in dma_alloc_attrs, and stop clearing
    the flag in the arm dma ops and dma-iommu.

    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>

(cherry picked from commit ffcb754584603adf7039d7972564fbf6febdc542)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2023-05-03 08:22:11 -07:00
Jerry Snitselaar 21db3753ef dma-mapping: reject GFP_COMP for noncoherent allocations
Bugzilla: https://bugzilla.redhat.com/2181354
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 3622b86f49f84e52fb41fee9eb55f9290613dfc3
Author: Christoph Hellwig <hch@lst.de>
Date:   Tue Dec 20 09:08:12 2022 +0100

    dma-mapping: reject GFP_COMP for noncoherent allocations

    While not quite as bogus as for the dma-coherent allocations that were
    fixed earlier, GFP_COMP for these allocations has no benefits for
    the dma-direct case, and can't be supported at all by dma dma-iommu
    backend which splits up allocations into smaller orders.  Due to an
    oversight in ffcb75458460 that flag stopped being cleared for all
    dma allocations, but only got rejected for coherent ones, so fix up
    these callers to not allow __GFP_COMP as well after the sound code
    has been fixed to not ask for it.

    Fixes: ffcb75458460 ("dma-mapping: reject __GFP_COMP in dma_alloc_attrs")
    Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
    Reported-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Acked-by: Takashi Iwai <tiwai@suse.de>
    Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
    Tested-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>

(cherry picked from commit 3622b86f49f84e52fb41fee9eb55f9290613dfc3)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2023-05-03 08:22:11 -07:00
Jerry Snitselaar d5c15ebb6f dma-mapping: mark dma_supported static
Bugzilla: https://bugzilla.redhat.com/2112024
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 9fc18f6d56d5b79d527c17a8100a0965d18345cf
Author: Christoph Hellwig <hch@lst.de>
Date:   Sun Aug 21 16:06:44 2022 +0200

    dma-mapping: mark dma_supported static

    Now that the remaining users in drivers are gone, this function can be
    marked static.

    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit 9fc18f6d56d5b79d527c17a8100a0965d18345cf)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2022-10-27 16:31:40 -07:00
Jerry Snitselaar fd2b922cde dma-mapping: reformat comment to suppress htmldoc warning
Bugzilla: https://bugzilla.redhat.com/2112024
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 8419702489f3be7f9e4fcf12c04d9d3f00114d35
Author: Logan Gunthorpe <logang@deltatee.com>
Date:   Wed Jul 27 13:15:22 2022 -0600

    dma-mapping: reformat comment to suppress htmldoc warning

    make html doc reports a cryptic warning with the commit named below:

      kernel/dma/mapping.c:258: WARNING: Option list ends without a blank
					 line; unexpected unindent.

    Seems the parser is a bit fussy about the tabbing and having a single
    space tab causes the warning. To suppress the warning add another
    tab to the list and reindent everything.

    Fixes: 7c2645a2a30a ("dma-mapping: allow EREMOTEIO return code for P2PDMA transfers")
    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit 8419702489f3be7f9e4fcf12c04d9d3f00114d35)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2022-10-27 16:31:40 -07:00
Jerry Snitselaar ffb9fff73f dma-mapping: add flags to dma_map_ops to indicate PCI P2PDMA support
Bugzilla: https://bugzilla.redhat.com/2112024
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 159bf19270e80b5bc4b13aa88072dcb390b4d297
Author: Logan Gunthorpe <logang@deltatee.com>
Date:   Fri Jul 8 10:50:57 2022 -0600

    dma-mapping: add flags to dma_map_ops to indicate PCI P2PDMA support

    Add a flags member to the dma_map_ops structure with one flag to
    indicate support for PCI P2PDMA.

    Also, add a helper to check if a device supports PCI P2PDMA.

    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit 159bf19270e80b5bc4b13aa88072dcb390b4d297)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2022-10-27 16:31:40 -07:00
Jerry Snitselaar 75d08a3dc0 dma-mapping: allow EREMOTEIO return code for P2PDMA transfers
Bugzilla: https://bugzilla.redhat.com/2112024
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 7c2645a2a30a45d3dc4c98b315a51be44ec69a67
Author: Logan Gunthorpe <logang@deltatee.com>
Date:   Fri Jul 8 10:50:55 2022 -0600

    dma-mapping: allow EREMOTEIO return code for P2PDMA transfers

    Add EREMOTEIO error return to dma_map_sgtable() which will be used
    by .map_sg() implementations that detect P2PDMA pages that the
    underlying DMA device cannot access.

    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit 7c2645a2a30a45d3dc4c98b315a51be44ec69a67)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2022-10-27 16:31:40 -07:00
Jerry Snitselaar ca2381ac0e dma-mapping: add dma_opt_mapping_size()
Bugzilla: https://bugzilla.redhat.com/2112024
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit a229cc14f3395311b899e5e582b71efa8dd01df0
Author: John Garry <john.garry@huawei.com>
Date:   Thu Jul 14 19:15:24 2022 +0800

    dma-mapping: add dma_opt_mapping_size()

    Streaming DMA mapping involving an IOMMU may be much slower for larger
    total mapping size. This is because every IOMMU DMA mapping requires an
    IOVA to be allocated and freed. IOVA sizes above a certain limit are not
    cached, which can have a big impact on DMA mapping performance.

    Provide an API for device drivers to know this "optimal" limit, such that
    they may try to produce mapping which don't exceed it.

    Signed-off-by: John Garry <john.garry@huawei.com>
    Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
    Acked-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit a229cc14f3395311b899e5e582b71efa8dd01df0)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2022-10-27 16:31:40 -07:00
Jerry Snitselaar 4b2e8894c2 ARM: ixp4xx: Drop custom DMA coherency and bouncing
Bugzilla: https://bugzilla.redhat.com/2112024
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Conflict: Drop unsupported bits

commit 00ba9357d18947859b7ef03a82c7f4185567ff0b
Author: Linus Walleij <linus.walleij@linaro.org>
Date:   Fri Feb 11 23:32:36 2022 +0100

    ARM: ixp4xx: Drop custom DMA coherency and bouncing

    The new PCI driver does not need any of this stuff, so just
    drop it.

    Cc: iommu@lists.linux-foundation.org
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
    Link: https://lore.kernel.org/r/20220211223238.648934-12-linus.walleij@linaro.org
    Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

(cherry picked from commit 00ba9357d18947859b7ef03a82c7f4185567ff0b)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2022-10-27 11:31:31 -07:00
Jerry Snitselaar 7212fcccc0 dma-mapping: move pgprot_decrypted out of dma_pgprot
Bugzilla: https://bugzilla.redhat.com/2072170
Upstream Status: kernel/git/torvalds/linux.git

commit 4fe87e818ea492ade079cc01a31d088e445f8539
Author: Christoph Hellwig <hch@lst.de>
Date:   Thu Mar 31 08:01:21 2022 +0200

    dma-mapping: move pgprot_decrypted out of dma_pgprot

    pgprot_decrypted is used by AMD SME systems to allow access to memory
    that was set to not encrypted using set_memory_decrypted.  That only
    happens for dma-direct memory as the IOMMU solves the addressing
    challenges for the encryption bit using its own remapping.

    Move the pgprot_decrypted call out of dma_pgprot which is also used
    by the IOMMU mappings and into dma-direct so that it is only used with
    memory that was set decrypted.

    Fixes: f5ff79fddf0e ("dma-mapping: remove CONFIG_DMA_REMAP")
    Reported-by: Alex Xu (Hello71) <alex_y_xu@yahoo.ca>
    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Tested-by: Alex Xu (Hello71) <alex_y_xu@yahoo.ca>

(cherry picked from commit 4fe87e818ea492ade079cc01a31d088e445f8539)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2022-05-19 10:58:10 -07:00
Jerry Snitselaar be48a3ba4b dma-mapping: remove bogus test for pfn_valid from dma_map_resource
Bugzilla: https://bugzilla.redhat.com/2072170
Upstream Status: kernel/git/torvalds/linux.git

commit a9c38c5d267cb94871dfa2de5539c92025c855d7
Author: Mike Rapoport <rppt@linux.ibm.com>
Date:   Thu Sep 30 04:30:38 2021 +0300

    dma-mapping: remove bogus test for pfn_valid from dma_map_resource

    dma_map_resource() uses pfn_valid() to ensure the range is not RAM.
    However, pfn_valid() only checks for availability of the memory map for a
    PFN but it does not ensure that the PFN is actually backed by RAM.

    As dma_map_resource() is the only method in DMA mapping APIs that has this
    check, simply drop the pfn_valid() test from dma_map_resource().

    Link: https://lore.kernel.org/all/20210824173741.GC623@arm.com/
    Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Acked-by: David Hildenbrand <david@redhat.com>
    Link: https://lore.kernel.org/r/20210930013039.11260-2-rppt@kernel.org
    Signed-off-by: Will Deacon <will@kernel.org>

(cherry picked from commit a9c38c5d267cb94871dfa2de5539c92025c855d7)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2022-05-19 10:56:31 -07:00
Jerry Snitselaar 58cf47e2ec dma-debug: teach add_dma_entry() about DMA_ATTR_SKIP_CPU_SYNC
Bugzilla: https://bugzilla.redhat.com/2004348
Upstream Status: kernel/git/torvalds/linux.git

commit c2bbf9d1e9ac7d4fdd503b190bc1ba8a6302bc49
Author: Hamza Mahfooz <someguy@effective-light.com>
Date:   Tue Oct 12 01:54:03 2021 -0400

    dma-debug: teach add_dma_entry() about DMA_ATTR_SKIP_CPU_SYNC

    Mapping something twice should be possible as long as,
    DMA_ATTR_SKIP_CPU_SYNC is passed to the strictly speaking second relevant
    mapping operation (that attempts to map the same thing). So, don't issue a
    warning if the specified condition is met in add_dma_entry().

    Signed-off-by: Hamza Mahfooz <someguy@effective-light.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit c2bbf9d1e9ac7d4fdd503b190bc1ba8a6302bc49)
Cc: Donald Dutile <ddutile@redhat.com>
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2021-10-27 16:42:13 -07:00
Jerry Snitselaar f37d5ac810 dma-mapping: fix the kerneldoc for dma_map_sgtable()
Bugzilla: https://bugzilla.redhat.com/2004348
Upstream Status: kernel/git/torvalds/linux.git

commit 011a9ce80763141e7fa613934e76bef8948e4a4f
Author: Logan Gunthorpe <logang@deltatee.com>
Date:   Tue Oct 5 10:48:12 2021 -0600

    dma-mapping: fix the kerneldoc for dma_map_sgtable()

    htmldocs began producing the following warnings:

      kernel/dma/mapping.c:256: WARNING: Definition list ends without a
		 blank line; unexpected unindent.
      kernel/dma/mapping.c:257: WARNING: Bullet list ends without a blank
		 line; unexpected unindent.

    Reformatting the list without hyphens fixes the warnings and produces
    both a readable text and HTML output.

    Fixes: fffe3cc8c219 ("dma-mapping: allow map_sg() ops to return negative error code")
    Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit 011a9ce80763141e7fa613934e76bef8948e4a4f)
Cc: Myron Stowe <myron.stowe@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Donald Dutile <ddutile@redhat.com>
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2021-10-27 16:42:12 -07:00
Jerry Snitselaar d60718ebd7 dma-mapping: fix the kerneldoc for dma_map_sg_attrs
Bugzilla: https://bugzilla.redhat.com/2004348
Upstream Status: kernel/git/torvalds/linux.git

commit a61cb6017df0a9be072a35259e6e9ae7aa0ef6b3
Author: Christoph Hellwig <hch@lst.de>
Date:   Mon Sep 6 14:40:00 2021 +0200

    dma-mapping: fix the kerneldoc for dma_map_sg_attrs

    Add the missing description for the nents parameter, and fix a trivial
    misalignment.

    Fixes: fffe3cc8c219 ("dma-mapping: allow map_sg() ops to return negative error codes")
    Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit a61cb6017df0a9be072a35259e6e9ae7aa0ef6b3)
Cc: Donald Dutile <ddutile@redhat.com>
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2021-10-27 16:42:12 -07:00
Jerry Snitselaar 0d183e1b81 dma-mapping: return an unsigned int from dma_map_sg{,_attrs}
Bugzilla: https://bugzilla.redhat.com/2004348
Upstream Status: kernel/git/torvalds/linux.git

commit 2a047e0662aee1bd773e0415accd785ad26a9398
Author: Christoph Hellwig <hch@lst.de>
Date:   Mon Aug 9 17:19:36 2021 +0200

    dma-mapping: return an unsigned int from dma_map_sg{,_attrs}

    These can only return 0 for failure or the number of entries, so turn
    the return value into an unsigned int.

    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Reviewed-by: Logan Gunthorpe <logang@deltatee.com>

(cherry picked from commit 2a047e0662aee1bd773e0415accd785ad26a9398)
Cc: Donald Dutile <ddutile@redhat.com>
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2021-10-27 16:26:02 -07:00
Jerry Snitselaar 153325ca4e dma-mapping: disallow .map_sg operations from returning zero on error
Bugzilla: https://bugzilla.redhat.com/2004348
Upstream Status: kernel/git/torvalds/linux.git

commit d03c54419274f96434e2ad74e59e67ec6d54ca86
Author: Logan Gunthorpe <logang@deltatee.com>
Date:   Mon Aug 9 17:13:31 2021 +0200

    dma-mapping: disallow .map_sg operations from returning zero on error

    Now that all the .map_sg operations have been converted to returning
    proper error codes, drop the code to handle a zero return value,
    add a warning if a zero is returned.

    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit d03c54419274f96434e2ad74e59e67ec6d54ca86)
Cc: Donald Dutile <ddutile@redhat.com>
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2021-10-27 16:26:01 -07:00
Jerry Snitselaar a03def7017 dma-mapping: allow map_sg() ops to return negative error codes
Bugzilla: https://bugzilla.redhat.com/2004348
Upstream Status: kernel/git/torvalds/linux.git

commit fffe3cc8c2194f60c4af4fac7f27d25e8828f001
Author: Logan Gunthorpe <logang@deltatee.com>
Date:   Thu Jul 29 14:15:19 2021 -0600

    dma-mapping: allow map_sg() ops to return negative error codes

    Allow dma_map_sgtable() to pass errors from the map_sg() ops. This
    will be required for returning appropriate error codes when mapping
    P2PDMA memory.

    Introduce __dma_map_sg_attrs() which will return the raw error code
    from the map_sg operation (whether it be negative or zero). Then add a
    dma_map_sg_attrs() wrapper to convert any negative errors to zero to
    satisfy the existing calling convention.

    dma_map_sgtable() defines three error codes that .map_sg implementations
    are allowed to return: -EINVAL, -ENOMEM and -EIO. The latter of which
    is a generic return for cases that are passing DMA_MAPPING_ERROR
    through.

    dma_map_sgtable() will convert a zero error return for old map_sg() ops
    into a -EIO return and return any negative errors as reported.

    This allows map_sg implementations to start returning multiple
    negative error codes. Legacy map_sg implementations can continue
    to return zero until they are all converted.

    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit fffe3cc8c2194f60c4af4fac7f27d25e8828f001)
Cc: Donald Dutile <ddutile@redhat.com>
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2021-10-27 16:25:29 -07:00
Christoph Hellwig 7d5b5738d1 dma-mapping: add a dma_alloc_noncontiguous API
Add a new API that returns a potentiall virtually non-contigous sg_table
and a DMA address.  This API is only properly implemented for dma-iommu
and will simply return a contigious chunk as a fallback.

The intent is that drivers can use this API if either:

 - no kernel mapping or only temporary kernel mappings are required.
   That is as a better replacement for DMA_ATTR_NO_KERNEL_MAPPING
 - a kernel mapping is required for cached and DMA mapped pages, but
   the driver also needs the pages to e.g. map them to userspace.
   In that sense it is a replacement for some aspects of the recently
   removed and never fully implemented DMA_ATTR_NON_CONSISTENT

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Tomasz Figa <tfiga@chromium.org>
Tested-by: Ricardo Ribalda <ribalda@chromium.org>
2021-03-15 10:02:31 +01:00
Christoph Hellwig 198c50e2cc dma-mapping: refactor dma_{alloc,free}_pages
Factour out internal versions without the dma_debug calls in preparation
for callers that will need different dma_debug calls.

Note that this changes the dma_debug calls to get the not page aligned
size values, but as long as alloc and free agree on one variant we are
fine.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Tomasz Figa <tfiga@chromium.org>
Tested-by: Ricardo Ribalda <ribalda@chromium.org>
2021-03-15 10:02:31 +01:00
Christoph Hellwig eedb0b12d0 dma-mapping: add a dma_mmap_pages helper
Add a helper to map memory allocated using dma_alloc_pages into
a user address space, similar to the dma_alloc_attrs function for
coherent allocations.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Tomasz Figa <tfiga@chromium.org>
Tested-by: Ricardo Ribalda <ribalda@chromium.org>
2021-03-15 10:02:31 +01:00
Linus Torvalds a4dec04c7f dma-mapping updates for 5.12:
- add support to emulate processing delays in the DMA API benchmark
    selftest (Barry Song)
  - remove support for non-contiguous noncoherent allocations,
    which aren't used and will be replaced by a different API
 -----BEGIN PGP SIGNATURE-----
 
 iQI/BAABCgApFiEEgdbnc3r/njty3Iq9D55TZVIEUYMFAmA2A7gLHGhjaEBsc3Qu
 ZGUACgkQD55TZVIEUYMebw//bkSZ1v1FvGgMd+AQKKnNz+iNHH0MJAlEDhPCynFM
 QCPg6OtU9IU/5nmyQlO3rgZ1IW+qABCF36TqjPZar6STuTv3dzfvv9xydyOqdPNA
 ekFzc9FnjvWt4wzL+1pXiB/EfjKDudGAjlMyLhghl653HcLnLvE3LxgpfBMrUHbH
 DfSBTXt4fTK4ck8ZO6FW2LXOtLgmJvk+qglO1vs9GQv/zcRHXYkIyvqMYTlHwBlh
 Ltfl+kJzFHQ3taIo3utCeS5Qzctd6tbxy/Me4OHl2VydNAi8awQz4HX4yZyWYxl5
 WpIGhHfD9ROKnGroaEhetUO4OczOXiqYdkt6tt5iAAUW2TFA+mgbvph3+Di/zxgl
 4IxOQyhdWA38IA00YmNsoPafuuqC7WwASUfCufg+30MgHR3bpM7GyY5X84DIh3tm
 wlPJBMl2RqWnfxmmvjPYxV2wtN3TkA8KJN/xVcUE8aWL2mV50l1/nDdlvCbmjg60
 pQt1cGP8A2hODYwLHTzadm67xc0cLrkC8nQbrnDo/FAKGmDD3aHhS95TAIr+ZoeK
 cgSFHNkJ1UcJ6nosCB3/MPlIJo1noAIeJnmuOIfhJn0uIof4CGQ5XQgWmJeHFLqO
 GlwtJAN3F3db4dxMQNn5br049wob7fgFWqMPfTGy51bZ5BClUKWGSpEonavpUMd1
 oKM=
 =papz
 -----END PGP SIGNATURE-----

Merge tag 'dma-mapping-5.12' of git://git.infradead.org/users/hch/dma-mapping

Pull dma-mapping updates from Christoph Hellwig:

 - add support to emulate processing delays in the DMA API benchmark
   selftest (Barry Song)

 - remove support for non-contiguous noncoherent allocations, which
   aren't used and will be replaced by a different API

* tag 'dma-mapping-5.12' of git://git.infradead.org/users/hch/dma-mapping:
  dma-mapping: remove the {alloc,free}_noncoherent methods
  dma-mapping: benchmark: pretend DMA is transmitting
2021-02-24 09:54:24 -08:00
Christoph Hellwig 6d4e9a8efe driver core: lift dma_default_coherent into common code
Lift the dma_default_coherent variable from the mips architecture code
to the driver core.  This allows an architecture to sdefault all device
to be DMA coherent at run time, even if the kernel is build with support
for DMA noncoherent device.  By allowing device_initialize to set the
->dma_coherent field to this default the amount of arch hooks required
for this behavior can be greatly reduced.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
2021-02-13 09:51:45 +01:00
Christoph Hellwig 81d88ce550 dma-mapping: remove the {alloc,free}_noncoherent methods
It turns out allowing non-contigous allocations here was a rather bad
idea, as we'll now need to define ways to get the pages for mmaping
or dma_buf sharing.  Revert this change and stick to the original
concept.  A different API for the use case of non-contigous allocations
will be added back later.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Tomasz Figa <tfiga@chromium.org>
Tested-by: Ricardo Ribalda <ribalda@chromium.org>:wq
2021-02-09 18:01:38 +01:00
Alexey Kardashevskiy 8d8d53cf8f dma-mapping: Allow mixing bypass and mapped DMA operation
At the moment we allow bypassing DMA ops only when we can do this for
the entire RAM. However there are configs with mixed type memory
where we could still allow bypassing IOMMU in most cases;
POWERPC with persistent memory is one example.

This adds an arch hook to determine where bypass can still work and
we invoke direct DMA API. The following patch checks the bus limit
on POWERPC to allow or disallow direct mapping.

This adds a ARCH_HAS_DMA_MAP_DIRECT config option to make the arch_xxxx
hooks no-op by default.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Christoph Hellwig <hch@lst.de>
2020-11-27 10:33:40 +01:00
Christoph Hellwig 19c65c3d30 dma-mapping: move large parts of <linux/dma-direct.h> to kernel/dma
Most of the dma_direct symbols should only be used by direct.c and
mapping.c, so move them to kernel/dma.  In fact more of dma-direct.h
should eventually move, but that will require more coordination with
other subsystems.

Signed-off-by: Christoph Hellwig <hch@lst.de>
2020-10-06 07:07:06 +02:00
Christoph Hellwig a1fd09e8e6 dma-mapping: move dma-debug.h to kernel/dma/
Most of dma-debug.h is not required by anything outside of kernel/dma.
Move the four declarations needed by dma-mappin.h or dma-ops providers
into dma-mapping.h and dma-map-ops.h, and move the remainder of the
file to kernel/dma/debug.h.

Signed-off-by: Christoph Hellwig <hch@lst.de>
2020-10-06 07:07:05 +02:00
Christoph Hellwig 0a0f0d8be7 dma-mapping: split <linux/dma-mapping.h>
Split out all the bits that are purely for dma_map_ops implementations
and related code into a new <linux/dma-map-ops.h> header so that they
don't get pulled into all the drivers.  That also means the architecture
specific <asm/dma-mapping.h> is not pulled in by <linux/dma-mapping.h>
any more, which leads to a missing includes that were pulled in by the
x86 or arm versions in a few not overly portable drivers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
2020-10-06 07:07:03 +02:00
Christoph Hellwig de7cf91776 dma-mapping: add new {alloc,free}_noncoherent dma_map_ops methods
This will allow IOMMU drivers to allocate non-contigous memory and
return a vmapped virtual address.

Signed-off-by: Christoph Hellwig <hch@lst.de>
2020-09-25 06:20:47 +02:00
Christoph Hellwig efa70f2fdc dma-mapping: add a new dma_alloc_pages API
This API is the equivalent of alloc_pages, except that the returned memory
is guaranteed to be DMA addressable by the passed in device.  The
implementation will also be used to provide a more sensible replacement
for DMA_ATTR_NON_CONSISTENT flag.

Additionally dma_alloc_noncoherent is switched over to use dma_alloc_pages
as its backend.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de> (MIPS part)
2020-09-25 06:20:47 +02:00