linux/drivers/staging
Ian Abbott e36472145a staging: comedi: use dma_mmap_coherent for DMA-able buffer mmap
Comedi's acquisition buffer allocation code can allocate the buffer from
normal kernel memory or from DMA coherent memory depending on the
`dma_async_dir` value in the comedi subdevice.  (A value of `DMA_NONE`
causes the buffer to be allocated from normal kernel memory.  Other
values cause the buffer to be allocated from DMA coherent memory.)   The
buffer currently consists of a bunch of page-sized blocks that are
vmap'ed into a contiguous range of virtual addresses. The pages are also
mmap'able into user address space.  For DMA'able buffers, these
page-sized blocks are allocated by `dma_alloc_coherent()`.

For DMA-able buffers, the DMA API is currently abused in various ways,
the most serious abuse being the calling of `virt_to_page()` on the
blocks allocated by `dma_alloc_coherent()` and passing those pages to
`vmap()` (for mapping to the kernels vmalloc address space) and via
`page_to_pfn()` to `remap_pfn_range()` (for mmap'ing to user space).  it
also uses the `__GFP_COMP` flag when allocating the blocks, and marks
the allocated pages as reserved (which is unnecessary for DMA coherent
allocations).

The code can be changed to get rid of the vmap'ed address altogether if
necessary, since there are only a few places in the comedi code that use
the vmap'ed address directly and we also keep a list of the kernel
addresses for the individual pages prior to the vmap operation. This
would add some run-time overhead to buffer accesses.  The real killer is
the mmap operation.

For mmap, the address range specified in the VMA needs to be mmap'ed to
the individually allocated page-sized blocks.  That is not a problem
when the pages are allocated from normal kernel memory as the individual
pages can be remapped by `remap_pfn_range()`, but it is a problem when
the page-sized blocks are allocated by `dma_alloc_coherent()` because
the DMA API currently has no support for splitting a VMA across multiple
blocks of DMA coherent memory (or rather, no support for mapping part of
a VMA range to a single block of DMA coherent memory).

In order to comply with the DMA API and allow the buffer to be mmap'ed,
the buffer needs to be allocated as a single block by a single call to
`dma_alloc_coherent()`, freed by a single call to `dma_free_coherent()`,
and mmap'ed to user space by a single call to `dma_mmap_coherent()`.
This patch changes the buffer allocation, freeing, and mmap'ing code to
do that, with the unfortunate consequence that buffer allocation is more
likely to fail.  It also no longer uses the `__GFP_COMP` flag when
allocating DMA coherent memory, no longer marks the
allocated pages of DMA coherent memory as reserved, and no longer vmap's
the DMA coherent memory pages (since they are contiguous anyway).

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-06-26 09:32:13 +08:00
..
android staging: android: fix style problem 2019-06-15 20:54:27 +02:00
axis-fifo staging: remove redundant 'default n' from Kconfig 2019-04-16 13:39:01 +02:00
board staging: add missing SPDX lines to Makefile files 2019-04-03 11:10:15 +02:00
clocking-wizard staging: add missing SPDX lines to Makefile files 2019-04-03 11:10:15 +02:00
comedi staging: comedi: use dma_mmap_coherent for DMA-able buffer mmap 2019-06-26 09:32:13 +08:00
emxx_udc staging: add missing SPDX lines to Makefile files 2019-04-03 11:10:15 +02:00
erofs staging: erofs: clean up initialization of pointer de 2019-06-18 08:59:40 +02:00
fbtft staging: add missing SPDX lines to Kconfig files 2019-04-03 11:10:15 +02:00
fieldbus staging: fieldbus: Fix build error without CONFIG_REGMAP_MMIO 2019-06-10 16:10:33 +02:00
fsl-dpaa2 staging: fsl-dpaa2/ethsw: fix memory leak of switchdev_work 2019-06-09 13:07:23 +02:00
fwserial staging: add missing SPDX lines to Makefile files 2019-04-03 11:10:15 +02:00
gasket staging/gasket: Fix string split 2019-05-30 14:09:47 -07:00
gdm724x staging: add missing SPDX lines to Kconfig files 2019-04-03 11:10:15 +02:00
goldfish staging: add missing SPDX lines to Makefile files 2019-04-03 11:10:15 +02:00
greybus staging: greybus: power_supply: use struct_size() helper 2019-04-19 15:03:07 +02:00
gs_fpgaboot staging: remove redundant 'default n' from Kconfig 2019-04-16 13:39:01 +02:00
iio Merge 5.2-rc6 into staging-next 2019-06-23 13:29:03 +02:00
kpc2000 Staging: kpc2000: kpc_dma: Fix platform_no_drv_owner.cocci warnings 2019-06-21 16:46:17 +02:00
ks7010 Revert "staging: ks7010: Fix build error" 2019-06-24 16:45:34 +08:00
media media updates for v5.2-rc1 2019-05-16 11:57:16 -07:00
most staging: most: deregister net and video config subsystems with configFS 2019-06-15 20:54:28 +02:00
mt7621-dma staging: mt7621-dma: sizeof via pointer dereference 2019-05-30 17:22:47 -07:00
mt7621-dts staging: mt7621-dts: add gpio perst to pcie bindings node 2019-06-20 14:45:50 +02:00
mt7621-pci staging: mt7621-pci: use 'module_init' instead of 'arch_initcall' 2019-06-21 16:50:10 +02:00
mt7621-pci-phy staging: mt7621-pci-phy: remove disable clock from the phy exit function 2019-06-21 16:50:10 +02:00
mt7621-pinctrl staging: add missing SPDX lines to Makefile files 2019-04-03 11:10:15 +02:00
netlogic staging: add missing SPDX lines to Makefile files 2019-04-03 11:10:15 +02:00
nvec staging: add missing SPDX lines to Kconfig files 2019-04-03 11:10:15 +02:00
octeon Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-05-07 22:03:58 -07:00
octeon-usb staging: octeon-usb: Remove return variable 2019-05-30 14:13:45 -07:00
olpc_dcon - Fix-ups 2019-05-14 10:45:03 -07:00
pi433 staging: pi433: Remove unnecessary variable 2019-05-24 09:00:44 +02:00
ralink-gdma Staging: ralink-gdma: fixed a brace coding style issue 2019-06-09 13:10:28 +02:00
rtl8188eu staging: rtl8188eu: remove unused code 2019-06-20 14:45:04 +02:00
rtl8192e staging: rtl8192e: rtllib_module: Remove redundant memset 2019-06-20 14:39:15 +02:00
rtl8192u staging: rtl8192u: ieee80211: Remove redundant memset 2019-06-20 14:39:15 +02:00
rtl8712 staging: rtl8712: Replace function r8712_init_cmd_priv() 2019-06-21 16:55:23 +02:00
rtl8723bs staging: rtl8723bs: Delete file odm_AntDiv.c 2019-06-21 16:46:17 +02:00
rts5208 staging: rts5208: Remove function soft_reset_sd_card() 2019-06-20 14:45:03 +02:00
sm750fb Staging: sm750fb: Change *array into *const array 2019-04-30 15:03:42 +02:00
speakup staging: speakup: serialio: fix warning linux/serial.h is included more than once 2019-05-30 13:59:16 -07:00
unisys staging: unisys: visornic: Replace GFP_ATOMIC with GFP_KERNEL 2019-05-23 09:23:15 +02:00
vc04_services Staging: vc04_services : vchiq_core: Fix a brace issue 2019-06-09 13:03:51 +02:00
vme staging: add missing SPDX lines to Makefile files 2019-04-03 11:10:15 +02:00
vt6655 staging: Add missing newline at end of file 2019-06-18 08:59:40 +02:00
vt6656 staging: vt6656: fix indentation on break statement 2019-06-20 14:32:07 +02:00
wilc1000 staging: wilc1000: add passive scan support 2019-06-21 16:49:04 +02:00
wlan-ng Merge 5.2-rc3 into staging-next 2019-06-03 07:27:16 +02:00
Kconfig drm pull request for 5.2 2019-05-08 21:35:19 -07:00
Makefile drm pull request for 5.2 2019-05-08 21:35:19 -07:00