29 Apr, 2020

1 commit

  • [ Upstream commit cdcda0d1f8f4ab84efe7cd9921c98364398aefd7 ]

    The upper 32-bit physical address gets truncated inadvertently
    when dma_direct_get_required_mask() invokes phys_to_dma_direct().
    This results in dma_addressing_limited() return incorrect value
    when used in platforms with LPAE enabled.
    Fix it here by explicitly type casting 'max_pfn' to phys_addr_t
    in order to prevent overflow of intermediate value while evaluating
    '(max_pfn - 1) << PAGE_SHIFT'.

    Signed-off-by: Kishon Vijay Abraham I
    Signed-off-by: Christoph Hellwig
    Signed-off-by: Sasha Levin

    Kishon Vijay Abraham I
     

23 Apr, 2020

2 commits

  • commit 9bb50ed7470944238ec8e30a94ef096caf9056ee upstream.

    The commit 2e05ea5cdc1a ("dma-mapping: implement dma_map_single_attrs using
    dma_map_page_attrs") removed "dma_debug_page" enum, but missed to update
    type2name string table. This causes incorrect displaying of dma allocation
    type.
    Fix it by removing "page" string from type2name string table and switch to
    use named initializers.

    Before (dma_alloc_coherent()):
    k3-ringacc 4b800000.ringacc: scather-gather idx 2208 P=d1140000 N=d114 D=d1140000 L=40 DMA_BIDIRECTIONAL dma map error check not applicable
    k3-ringacc 4b800000.ringacc: scather-gather idx 2216 P=d1150000 N=d115 D=d1150000 L=40 DMA_BIDIRECTIONAL dma map error check not applicable

    After:
    k3-ringacc 4b800000.ringacc: coherent idx 2208 P=d1140000 N=d114 D=d1140000 L=40 DMA_BIDIRECTIONAL dma map error check not applicable
    k3-ringacc 4b800000.ringacc: coherent idx 2216 P=d1150000 N=d115 D=d1150000 L=40 DMA_BIDIRECTIONAL dma map error check not applicable

    Fixes: 2e05ea5cdc1a ("dma-mapping: implement dma_map_single_attrs using dma_map_page_attrs")
    Signed-off-by: Grygorii Strashko
    Signed-off-by: Christoph Hellwig
    Signed-off-by: Greg Kroah-Hartman

    Grygorii Strashko
     
  • [ Upstream commit 286c21de32b904131f8cf6a36ce40b8b0c9c5da3 ]

    pageno is an int and the PAGE_SHIFT shift is done on an int,
    overflowing if the memory is bigger than 2G

    This can be reproduced using for example a reserved-memory of 4G

    reserved-memory {
    #address-cells = ;
    #size-cells = ;
    ranges;

    reserved_dma: buffer@0 {
    compatible = "shared-dma-pool";
    no-map;
    reg = ;
    };
    };

    Signed-off-by: Kevin Grandemange
    Signed-off-by: Christoph Hellwig
    Signed-off-by: Sasha Levin

    Kevin Grandemange
     

17 Apr, 2020

1 commit

  • [ Upstream commit 17c4a2ae15a7aaefe84bdb271952678c5c9cd8e1 ]

    When dma_mmap_coherent() sets up a mapping to unencrypted coherent memory
    under SEV encryption and sometimes under SME encryption, it will actually
    set up an encrypted mapping rather than an unencrypted, causing devices
    that DMAs from that memory to read encrypted contents. Fix this.

    When force_dma_unencrypted() returns true, the linear kernel map of the
    coherent pages have had the encryption bit explicitly cleared and the
    page content is unencrypted. Make sure that any additional PTEs we set
    up to these pages also have the encryption bit cleared by having
    dma_pgprot() return a protection with the encryption bit cleared in this
    case.

    Signed-off-by: Thomas Hellstrom
    Signed-off-by: Borislav Petkov
    Reviewed-by: Christoph Hellwig
    Acked-by: Tom Lendacky
    Link: https://lkml.kernel.org/r/20200304114527.3636-3-thomas_os@shipmail.org
    Signed-off-by: Sasha Levin

    Thomas Hellstrom
     

26 Jan, 2020

1 commit

  • [ Upstream commit 4268ac6ae5870af10a7417b22990d615f72f77e2 ]

    When mapping resources we can't just use swiotlb ram for bounce
    buffering. Switch to a direct dma_capable check instead.

    Fixes: cfced786969c ("dma-mapping: remove the default map_resource implementation")
    Reported-by: Robin Murphy
    Signed-off-by: Christoph Hellwig
    Acked-by: Marek Szyprowski
    Tested-by: Marek Szyprowski
    Signed-off-by: Sasha Levin

    Christoph Hellwig
     

05 Jan, 2020

2 commits

  • [ Upstream commit a445e940ea686fc60475564009821010eb213be3 ]

    Daniele reported that issue previously fixed in c41f9ea998f3
    ("drivers: dma-coherent: Account dma_pfn_offset when used with device
    tree") reappear shortly after 43fc509c3efb ("dma-coherent: introduce
    interface for default DMA pool") where fix was accidentally dropped.

    Lets put fix back in place and respect dma-ranges for reserved memory.

    Fixes: 43fc509c3efb ("dma-coherent: introduce interface for default DMA pool")

    Reported-by: Daniele Alessandrelli
    Tested-by: Daniele Alessandrelli
    Tested-by: Alexandre Torgue
    Signed-off-by: Vladimir Murzin
    Signed-off-by: Christoph Hellwig
    Signed-off-by: Sasha Levin

    Vladimir Murzin
     
  • [ Upstream commit 9ff6aa027dbb98755f0265695354f2dd07c0d1ce ]

    debug_dma_dump_mappings() can take a lot of cpu cycles :

    lpk43:/# time wc -l /sys/kernel/debug/dma-api/dump
    163435 /sys/kernel/debug/dma-api/dump

    real 0m0.463s
    user 0m0.003s
    sys 0m0.459s

    Let's add a cond_resched() to avoid holding cpu for too long.

    Signed-off-by: Eric Dumazet
    Cc: Corentin Labbe
    Cc: Christoph Hellwig
    Cc: Marek Szyprowski
    Signed-off-by: Christoph Hellwig
    Signed-off-by: Sasha Levin

    Eric Dumazet
     

05 Oct, 2019

1 commit

  • Commit 5cf4537975bb ("dma-mapping: introduce a dma_common_find_pages
    helper") changed invalid input check in dma_common_free_remap() from:

    if (!area || !area->flags != VM_DMA_COHERENT)

    to

    if (!area || !area->flags != VM_DMA_COHERENT || !area->pages)

    which seem to produce false positives for memory obtained via
    dma_common_contiguous_remap()

    This triggers the following warning message when doing "reboot" on ZII
    VF610 Dev Board Rev B:

    WARNING: CPU: 0 PID: 1 at kernel/dma/remap.c:112 dma_common_free_remap+0x88/0x8c
    trying to free invalid coherent area: 9ef82980
    Modules linked in:
    CPU: 0 PID: 1 Comm: systemd-shutdow Not tainted 5.3.0-rc6-next-20190820 #119
    Hardware name: Freescale Vybrid VF5xx/VF6xx (Device Tree)
    Backtrace:
    [] (dump_backtrace) from [] (show_stack+0x20/0x24)
    r7:8015ed78 r6:00000009 r5:00000000 r4:9f4d9b14
    [] (show_stack) from [] (dump_stack+0x24/0x28)
    [] (dump_stack) from [] (__warn.part.3+0xcc/0xe4)
    [] (__warn.part.3) from [] (warn_slowpath_fmt+0x78/0x94)
    r6:00000070 r5:808e540c r4:81c03048
    [] (warn_slowpath_fmt) from [] (dma_common_free_remap+0x88/0x8c)
    r3:9ef82980 r2:808e53e0
    r7:00001000 r6:a0b1e000 r5:a0b1e000 r4:00001000
    [] (dma_common_free_remap) from [] (remap_allocator_free+0x60/0x68)
    r5:81c03048 r4:9f4d9b78
    [] (remap_allocator_free) from [] (__arm_dma_free.constprop.3+0xf8/0x148)
    r5:81c03048 r4:9ef82900
    [] (__arm_dma_free.constprop.3) from [] (arm_dma_free+0x24/0x2c)
    r5:9f563410 r4:80110120
    [] (arm_dma_free) from [] (dma_free_attrs+0xa0/0xdc)
    [] (dma_free_attrs) from [] (dma_pool_destroy+0xc0/0x154)
    r8:9efa8860 r7:808f02f0 r6:808f02d0 r5:9ef82880 r4:9ef82780
    [] (dma_pool_destroy) from [] (ehci_mem_cleanup+0x6c/0x150)
    r7:9f563410 r6:9efa8810 r5:00000000 r4:9efd0148
    [] (ehci_mem_cleanup) from [] (ehci_stop+0xac/0xc0)
    r5:9efd0148 r4:9efd0000
    [] (ehci_stop) from [] (usb_remove_hcd+0xf4/0x1b0)
    r7:9f563410 r6:9efd0074 r5:81c03048 r4:9efd0000
    [] (usb_remove_hcd) from [] (host_stop+0x48/0xb8)
    r7:9f563410 r6:9efd0000 r5:9f5f4040 r4:9f5f5040
    [] (host_stop) from [] (ci_hdrc_host_destroy+0x34/0x38)
    r7:9f563410 r6:9f5f5040 r5:9efa8800 r4:9f5f4040
    [] (ci_hdrc_host_destroy) from [] (ci_hdrc_remove+0x50/0x10c)
    [] (ci_hdrc_remove) from [] (platform_drv_remove+0x34/0x4c)
    r7:9f563410 r6:81c4f99c r5:9efa8810 r4:9efa8810
    [] (platform_drv_remove) from [] (device_release_driver_internal+0xec/0x19c)
    r5:00000000 r4:9efa8810
    [] (device_release_driver_internal) from [] (device_release_driver+0x20/0x24)
    r7:9f563410 r6:81c41ed0 r5:9efa8810 r4:9f4a1dac
    [] (device_release_driver) from [] (bus_remove_device+0xdc/0x108)
    [] (bus_remove_device) from [] (device_del+0x150/0x36c)
    r7:9f563410 r6:81c03048 r5:9efa8854 r4:9efa8810
    [] (device_del) from [] (platform_device_del.part.2+0x20/0x84)
    r10:9f563414 r9:809177e0 r8:81cb07dc r7:81c78320 r6:9f563454 r5:9efa8800
    r4:9efa8800
    [] (platform_device_del.part.2) from [] (platform_device_unregister+0x28/0x34)
    r5:9f563400 r4:9efa8800
    [] (platform_device_unregister) from [] (ci_hdrc_remove_device+0x1c/0x30)
    r5:9f563400 r4:00000001
    [] (ci_hdrc_remove_device) from [] (ci_hdrc_imx_remove+0x38/0x118)
    r7:81c78320 r6:9f563454 r5:9f563410 r4:9f541010
    [] (ci_hdrc_imx_shutdown) from [] (platform_drv_shutdown+0x2c/0x30)
    [] (platform_drv_shutdown) from [] (device_shutdown+0x158/0x1f0)
    [] (device_shutdown) from [] (kernel_restart_prepare+0x44/0x48)
    r10:00000058 r9:9f4d8000 r8:fee1dead r7:379ce700 r6:81c0b280 r5:81c03048
    r4:00000000
    [] (kernel_restart_prepare) from [] (kernel_restart+0x1c/0x60)
    [] (kernel_restart) from [] (__do_sys_reboot+0xe0/0x1d8)
    r5:81c03048 r4:00000000
    [] (__do_sys_reboot) from [] (sys_reboot+0x18/0x1c)
    r8:80101204 r7:00000058 r6:00000000 r5:00000000 r4:00000000
    [] (sys_reboot) from [] (ret_fast_syscall+0x0/0x54)
    Exception stack(0x9f4d9fa8 to 0x9f4d9ff0)
    9fa0: 00000000 00000000 fee1dead 28121969 01234567 379ce700
    9fc0: 00000000 00000000 00000000 00000058 00000000 00000000 00000000 00016d04
    9fe0: 00028e0c 7ec87c64 000135ec 76c1f410

    Restore original invalid input check in dma_common_free_remap() to
    avoid this problem.

    Fixes: 5cf4537975bb ("dma-mapping: introduce a dma_common_find_pages helper")
    Signed-off-by: Andrey Smirnov
    [hch: just revert the offending hunk instead of creating a new helper]
    Signed-off-by: Christoph Hellwig

    Andrey Smirnov
     

21 Sep, 2019

1 commit

  • Pull powerpc updates from Michael Ellerman:
    "This is a bit late, partly due to me travelling, and partly due to a
    power outage knocking out some of my test systems *while* I was
    travelling.

    - Initial support for running on a system with an Ultravisor, which
    is software that runs below the hypervisor and protects guests
    against some attacks by the hypervisor.

    - Support for building the kernel to run as a "Secure Virtual
    Machine", ie. as a guest capable of running on a system with an
    Ultravisor.

    - Some changes to our DMA code on bare metal, to allow devices with
    medium sized DMA masks (> 32 && < 59 bits) to use more than 2GB of
    DMA space.

    - Support for firmware assisted crash dumps on bare metal (powernv).

    - Two series fixing bugs in and refactoring our PCI EEH code.

    - A large series refactoring our exception entry code to use gas
    macros, both to make it more readable and also enable some future
    optimisations.

    As well as many cleanups and other minor features & fixups.

    Thanks to: Adam Zerella, Alexey Kardashevskiy, Alistair Popple, Andrew
    Donnellan, Aneesh Kumar K.V, Anju T Sudhakar, Anshuman Khandual,
    Balbir Singh, Benjamin Herrenschmidt, Cédric Le Goater, Christophe
    JAILLET, Christophe Leroy, Christopher M. Riedl, Christoph Hellwig,
    Claudio Carvalho, Daniel Axtens, David Gibson, David Hildenbrand,
    Desnes A. Nunes do Rosario, Ganesh Goudar, Gautham R. Shenoy, Greg
    Kurz, Guerney Hunt, Gustavo Romero, Halil Pasic, Hari Bathini, Joakim
    Tjernlund, Jonathan Neuschafer, Jordan Niethe, Leonardo Bras, Lianbo
    Jiang, Madhavan Srinivasan, Mahesh Salgaonkar, Mahesh Salgaonkar,
    Masahiro Yamada, Maxiwell S. Garcia, Michael Anderson, Nathan
    Chancellor, Nathan Lynch, Naveen N. Rao, Nicholas Piggin, Oliver
    O'Halloran, Qian Cai, Ram Pai, Ravi Bangoria, Reza Arbab, Ryan Grimm,
    Sam Bobroff, Santosh Sivaraj, Segher Boessenkool, Sukadev Bhattiprolu,
    Thiago Bauermann, Thiago Jung Bauermann, Thomas Gleixner, Tom
    Lendacky, Vasant Hegde"

    * tag 'powerpc-5.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (264 commits)
    powerpc/mm/mce: Keep irqs disabled during lockless page table walk
    powerpc: Use ftrace_graph_ret_addr() when unwinding
    powerpc/ftrace: Enable HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
    ftrace: Look up the address of return_to_handler() using helpers
    powerpc: dump kernel log before carrying out fadump or kdump
    docs: powerpc: Add missing documentation reference
    powerpc/xmon: Fix output of XIVE IPI
    powerpc/xmon: Improve output of XIVE interrupts
    powerpc/mm/radix: remove useless kernel messages
    powerpc/fadump: support holes in kernel boot memory area
    powerpc/fadump: remove RMA_START and RMA_END macros
    powerpc/fadump: update documentation about option to release opalcore
    powerpc/fadump: consider f/w load area
    powerpc/opalcore: provide an option to invalidate /sys/firmware/opal/core file
    powerpc/opalcore: export /sys/firmware/opal/core for analysing opal crashes
    powerpc/fadump: update documentation about CONFIG_PRESERVE_FA_DUMP
    powerpc/fadump: add support to preserve crash data on FADUMP disabled kernel
    powerpc/fadump: improve how crashed kernel's memory is reserved
    powerpc/fadump: consider reserved ranges while releasing memory
    powerpc/fadump: make crash memory ranges array allocation generic
    ...

    Linus Torvalds
     

20 Sep, 2019

1 commit

  • Pull dma-mapping updates from Christoph Hellwig:

    - add dma-mapping and block layer helpers to take care of IOMMU merging
    for mmc plus subsequent fixups (Yoshihiro Shimoda)

    - rework handling of the pgprot bits for remapping (me)

    - take care of the dma direct infrastructure for swiotlb-xen (me)

    - improve the dma noncoherent remapping infrastructure (me)

    - better defaults for ->mmap, ->get_sgtable and ->get_required_mask
    (me)

    - cleanup mmaping of coherent DMA allocations (me)

    - various misc cleanups (Andy Shevchenko, me)

    * tag 'dma-mapping-5.4' of git://git.infradead.org/users/hch/dma-mapping: (41 commits)
    mmc: renesas_sdhi_internal_dmac: Add MMC_CAP2_MERGE_CAPABLE
    mmc: queue: Fix bigger segments usage
    arm64: use asm-generic/dma-mapping.h
    swiotlb-xen: merge xen_unmap_single into xen_swiotlb_unmap_page
    swiotlb-xen: simplify cache maintainance
    swiotlb-xen: use the same foreign page check everywhere
    swiotlb-xen: remove xen_swiotlb_dma_mmap and xen_swiotlb_dma_get_sgtable
    xen: remove the exports for xen_{create,destroy}_contiguous_region
    xen/arm: remove xen_dma_ops
    xen/arm: simplify dma_cache_maint
    xen/arm: use dev_is_dma_coherent
    xen/arm: consolidate page-coherent.h
    xen/arm: use dma-noncoherent.h calls for xen-swiotlb cache maintainance
    arm: remove wrappers for the generic dma remap helpers
    dma-mapping: introduce a dma_common_find_pages helper
    dma-mapping: always use VM_DMA_COHERENT for generic DMA remap
    vmalloc: lift the arm flag for coherent mappings to common code
    dma-mapping: provide a better default ->get_required_mask
    dma-mapping: remove the dma_declare_coherent_memory export
    remoteproc: don't allow modular build
    ...

    Linus Torvalds
     

11 Sep, 2019

2 commits


04 Sep, 2019

10 commits


03 Sep, 2019

1 commit

  • This patch adds a new DMA API "dma_get_merge_boundary". This function
    returns the DMA merge boundary if the DMA layer can merge the segments.
    This patch also adds the implementation for a new dma_map_ops pointer.

    Signed-off-by: Yoshihiro Shimoda
    Reviewed-by: Simon Horman
    Signed-off-by: Christoph Hellwig

    Yoshihiro Shimoda
     

29 Aug, 2019

2 commits

  • The memory allocated for the atomic pool needs to have the same
    mapping attributes that we use for remapping, so use
    pgprot_dmacoherent instead of open coding it. Also deduct a
    suitable zone to allocate the memory from based on the presence
    of the DMA zones.

    Signed-off-by: Christoph Hellwig

    Christoph Hellwig
     
  • arch_dma_mmap_pgprot is used for two things:

    1) to override the "normal" uncached page attributes for mapping
    memory coherent to devices that can't snoop the CPU caches
    2) to provide the special DMA_ATTR_WRITE_COMBINE semantics on older
    arm systems and some mips platforms

    Replace one with the pgprot_dmacoherent macro that is already provided
    by arm and much simpler to use, and lift the DMA_ATTR_WRITE_COMBINE
    handling to common code with an explicit arch opt-in.

    Signed-off-by: Christoph Hellwig
    Acked-by: Geert Uytterhoeven # m68k
    Acked-by: Paul Burton # mips

    Christoph Hellwig
     

21 Aug, 2019

1 commit

  • The new dma_alloc_contiguous hides if we allocate CMA or regular
    pages, and thus fails to retry a ZONE_NORMAL allocation if the CMA
    allocation succeeds but isn't addressable. That means we either fail
    outright or dip into a small zone that might not succeed either.

    Thanks to Hillf Danton for debugging this issue.

    Fixes: b1d2dc009dec ("dma-contiguous: add dma_{alloc,free}_contiguous() helpers")
    Reported-by: Tobias Klausmann
    Signed-off-by: Christoph Hellwig
    Tested-by: Tobias Klausmann

    Christoph Hellwig
     

11 Aug, 2019

3 commits

  • All the way back to introducing dma_common_mmap we've defaulted to mark
    the pages as uncached. But this is wrong for DMA coherent devices.
    Later on DMA_ATTR_WRITE_COMBINE also got incorrect treatment as that
    flag is only treated special on the alloc side for non-coherent devices.

    Introduce a new dma_pgprot helper that deals with the check for coherent
    devices so that only the remapping cases ever reach arch_dma_mmap_pgprot
    and we thus ensure no aliasing of page attributes happens, which makes
    the powerpc version of arch_dma_mmap_pgprot obsolete and simplifies the
    remaining ones.

    Note that this means arch_dma_mmap_pgprot is a bit misnamed now, but
    we'll phase it out soon.

    Fixes: 64ccc9c033c6 ("common: dma-mapping: add support for generic dma_mmap_* calls")
    Reported-by: Shawn Anastasio
    Reported-by: Gavin Li
    Signed-off-by: Christoph Hellwig
    Acked-by: Catalin Marinas # arm64

    Christoph Hellwig
     
  • The dma required_mask needs to reflect the actual addressing capabilities
    needed to handle the whole system RAM. When truncated down to the bus
    addressing capabilities dma_addressing_limited() will incorrectly signal
    no limitations for devices which are restricted by the bus_dma_mask.

    Fixes: b4ebe6063204 (dma-direct: implement complete bus_dma_mask handling)
    Signed-off-by: Lucas Stach
    Tested-by: Atish Patra
    Signed-off-by: Christoph Hellwig

    Lucas Stach
     
  • The new DMA_ATTR_NO_KERNEL_MAPPING needs to actually assign
    a dma_addr to work. Also skip it if the architecture needs
    forced decryption handling, as that needs a kernel virtual
    address.

    Fixes: d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
    Signed-off-by: Christoph Hellwig
    Reviewed-by: Lucas Stach

    Christoph Hellwig
     

09 Aug, 2019

2 commits

  • sme_active() is an x86-specific function so it's better not to call it from
    generic code. Christoph Hellwig mentioned that "There is no reason why we
    should have a special debug printk just for one specific reason why there
    is a requirement for a large DMA mask.", so just remove dma_check_mask().

    Signed-off-by: Thiago Jung Bauermann
    Reviewed-by: Christoph Hellwig
    Reviewed-by: Tom Lendacky
    Signed-off-by: Michael Ellerman
    Link: https://lore.kernel.org/r/20190806044919.10622-4-bauerman@linux.ibm.com

    Thiago Jung Bauermann
     
  • sme_active() is an x86-specific function so it's better not to call it from
    generic code.

    There's no need to mention which memory encryption feature is active, so
    just use a more generic message. Besides, other architectures will have
    different names for similar technology.

    Signed-off-by: Thiago Jung Bauermann
    Reviewed-by: Christoph Hellwig
    Reviewed-by: Tom Lendacky
    Signed-off-by: Michael Ellerman
    Link: https://lore.kernel.org/r/20190806044919.10622-3-bauerman@linux.ibm.com

    Thiago Jung Bauermann
     

02 Aug, 2019

1 commit

  • Pull arm swiotlb support from Christoph Hellwig:
    "This fixes a cascade of regressions that originally started with the
    addition of the ia64 port, but only got fatal once we removed most
    uses of block layer bounce buffering in Linux 4.18.

    The reason is that while the original i386/PAE code that was the first
    architecture that supported > 4GB of memory without an iommu decided
    to leave bounce buffering to the subsystems, which in those days just
    mean block and networking as no one else consumed arbitrary userspace
    memory.

    Later with ia64, x86_64 and other ports we assumed that either an
    iommu or something that fakes it up ("software IOTLB" in beautiful
    Intel speak) is present and that subsystems can rely on that for
    dealing with addressing limitations in devices. Except that the ARM
    LPAE scheme that added larger physical address to 32-bit ARM did not
    follow that scheme and thus only worked by chance and only for block
    and networking I/O directly to highmem.

    Long story, short fix - add swiotlb support to arm when build for LPAE
    platforms, which actuallys turns out to be pretty trivial with the
    modern dma-direct / swiotlb code to fix the Linux 4.18-ish regression"

    * tag 'arm-swiotlb-5.3' of git://git.infradead.org/users/hch/dma-mapping:
    arm: use swiotlb for bounce buffering on LPAE configs
    dma-mapping: check pfn validity in dma_common_{mmap,get_sgtable}

    Linus Torvalds
     

29 Jul, 2019

2 commits

  • According to the original dma_direct_alloc_pages() code:
    {
    unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;

    if (!dma_release_from_contiguous(dev, page, count))
    __free_pages(page, get_order(size));
    }

    The count parameter for dma_release_from_contiguous() was page
    aligned before the right-shifting operation, while the new API
    dma_free_contiguous() forgets to have PAGE_ALIGN() at the size.

    So this patch simply adds it to prevent any corner case.

    Fixes: fdaeec198ada ("dma-contiguous: add dma_{alloc,free}_contiguous() helpers")
    Signed-off-by: Nicolin Chen
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Christoph Hellwig

    Nicolin Chen
     
  • The dma_alloc_contiguous() limits align at CONFIG_CMA_ALIGNMENT for
    cma_alloc() however it does not restore it for the fallback routine.
    This will result in a size mismatch between the allocation and free
    when running into the fallback routines after cma_alloc() fails, if
    the align is larger than CONFIG_CMA_ALIGNMENT.

    This patch adds a cma_align to take care of cma_alloc() and prevent
    the align from being overwritten.

    Fixes: fdaeec198ada ("dma-contiguous: add dma_{alloc,free}_contiguous() helpers")
    Reported-by: Dafna Hirschfeld
    Signed-off-by: Nicolin Chen
    Signed-off-by: Christoph Hellwig

    Nicolin Chen
     

24 Jul, 2019

1 commit


21 Jul, 2019

1 commit

  • Pull dma-mapping fixes from Christoph Hellwig:
    "Fix various regressions:

    - force unencrypted dma-coherent buffers if encryption bit can't fit
    into the dma coherent mask (Tom Lendacky)

    - avoid limiting request size if swiotlb is not used (me)

    - fix swiotlb handling in dma_direct_sync_sg_for_cpu/device (Fugang
    Duan)"

    * tag 'dma-mapping-5.3-1' of git://git.infradead.org/users/hch/dma-mapping:
    dma-direct: correct the physical addr in dma_direct_sync_sg_for_cpu/device
    dma-direct: only limit the mapping size if swiotlb could be used
    dma-mapping: add a dma_addressing_limited helper
    dma-direct: Force unencrypted DMA under SME for certain DMA masks

    Linus Torvalds
     

19 Jul, 2019

2 commits

  • dma_map_sg() may use swiotlb buffer when the kernel command line includes
    "swiotlb=force" or the dma_addr is out of dev->dma_mask range. After
    DMA complete the memory moving from device to memory, then user call
    dma_sync_sg_for_cpu() to sync with DMA buffer, and copy the original
    virtual buffer to other space.

    So dma_direct_sync_sg_for_cpu() should use swiotlb physical addr, not
    the original physical addr from sg_phys(sg).

    dma_direct_sync_sg_for_device() also has the same issue, correct it as
    well.

    Fixes: 55897af63091("dma-direct: merge swiotlb_dma_ops into the dma_direct code")
    Signed-off-by: Fugang Duan
    Reviewed-by: Robin Murphy
    Signed-off-by: Christoph Hellwig

    Fugang Duan
     
  • Pull swiotlb updates from Konrad Rzeszutek Wilk:
    "One compiler fix, and a bug-fix in swiotlb_nr_tbl() and
    swiotlb_max_segment() to check also for no_iotlb_memory"

    * 'for-linus-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb:
    swiotlb: fix phys_addr_t overflow warning
    swiotlb: Return consistent SWIOTLB segments/nr_tbl
    swiotlb: Group identical cleanup in swiotlb_cleanup()

    Linus Torvalds
     

17 Jul, 2019

2 commits

  • Don't just check for a swiotlb buffer, but also if buffering might
    be required for this particular device.

    Fixes: 133d624b1cee ("dma: Introduce dma_max_mapping_size()")
    Reported-by: Benjamin Herrenschmidt
    Signed-off-by: Christoph Hellwig
    Tested-by: Benjamin Herrenschmidt

    Christoph Hellwig
     
  • If a device doesn't support DMA to a physical address that includes the
    encryption bit (currently bit 47, so 48-bit DMA), then the DMA must
    occur to unencrypted memory. SWIOTLB is used to satisfy that requirement
    if an IOMMU is not active (enabled or configured in passthrough mode).

    However, commit fafadcd16595 ("swiotlb: don't dip into swiotlb pool for
    coherent allocations") modified the coherent allocation support in
    SWIOTLB to use the DMA direct coherent allocation support. When an IOMMU
    is not active, this resulted in dma_alloc_coherent() failing for devices
    that didn't support DMA addresses that included the encryption bit.

    Addressing this requires changes to the force_dma_unencrypted() function
    in kernel/dma/direct.c. Since the function is now non-trivial and
    SME/SEV specific, update the DMA direct support to add an arch override
    for the force_dma_unencrypted() function. The arch override is selected
    when CONFIG_AMD_MEM_ENCRYPT is set. The arch override function resides in
    the arch/x86/mm/mem_encrypt.c file and forces unencrypted DMA when either
    SEV is active or SME is active and the device does not support DMA to
    physical addresses that include the encryption bit.

    Fixes: fafadcd16595 ("swiotlb: don't dip into swiotlb pool for coherent allocations")
    Suggested-by: Christoph Hellwig
    Signed-off-by: Tom Lendacky
    Acked-by: Thomas Gleixner
    [hch: moved the force_dma_unencrypted declaration to dma-mapping.h,
    fold the s390 fix from Halil Pasic]
    Signed-off-by: Christoph Hellwig

    Tom Lendacky