DMA Mapping Error Analysis

From Linux Driver Project
mediawiki

Revision as of 14:47, 6 September 2012 by Shuahkhan (Talk | contribs)


Jump to: navigation, search
mediawiki
mediawiki
mediawiki

I analyzed current calls to dma_map_single() and dma_map_page() in the kernel to see if dma mapping errors are checked after mapping routines return.

Reference linux-next August 6 2012.

The goal of this analysis is to find drivers that don't currently check dma mapping errors and fix them. I did a grep for dma_map_single() and dma_map_page() and looked at the code that calls these routines. I classified the results of dma mapping error check status as follows:

Broken:

  1. No error checks
  2. Partial checks - In that source file, not all calls are followed by checks.
  3. Checks dma mapping errors, doesn't unmap already mapped pages when mapping error occurs in the middle of a multiple mapping attempt.

The first two categories are classified as broken and need fixing. The third one needs fixing, since it leaves dangling mapped pages, and holds on to them which is equivalent to memory leak. Some drivers release all mapped pages when the device closes, but others don't. Not doing unmap might be harmless on some architectures going by the comments I found in some source files.

Good:

  1. Checks dma mapping errors and unmaps already mapped pages when mapping error occurs in the middle of a multiple mapping attempt.
  2. Checks dma mapping errors without unlikely()
  3. Checks dma mapping errors with unlikely()

I lumped the above three cases as good cases. Using unlikely() is icing on the cake, and something we need to be concerned about compared to other problems in this area.

dmap_map_single() - results

  • No error checks - 195 (46%)
  • Partial checks - 46 (11%)
  • Doesn't unmap: 26 (6%)
  • Good: 147 (35%)

dma_map_page() - results

  • No error checks: 61 (59%)
  • Partial checks: 7 (.06%)
  • Doesn't unmap: 15 (14.5%)
  • Good: 20 (19%)

In summary a large % of the cases (> 50%) go unchecked. That raises the following questions:

  • When do mapping errors get detected?
  • How often do these errors occur?
  • Why don't we see failures related to missing dma mapping error checks?
  • Are they silent failures?

However I propose the following to gather more information:

  • Ehnance swiotlb or dma-debug infrastructure to track how often overflow buffer is triggered. I am working on this change.
  • Enhance dma-debug infrastructure to track dma map and unmap errors - I am working on this change.

Detailed Analysis

The following is the detailed information on the nature of problems with dma mapping error checking, ranging from not checking mapping errors to not unmapping etc.

Link title===== dma_map_single() usages without dma mapping error checks =====

The following table lists the source files that call dma_map_single() without a dma mapping error check on the return address. These instances are broken and need fixing.

File Name # of calls Status Notes
arch/arm/mach-rpc/dma.c 1 Broken
arch/arm/kernel/dma-isa.c 1 Broken
drivers/parport/parport_pc.c 1 Broken
drivers/parport/parport_ip32.c 1 Broken
drivers/infiniband/core/mad.c 3 Broken
drivers/infiniband/ulp/iser/iser_verbs.c 2 Unmap Broken
drivers/tty/serial/msm_serial_hs.c 5 Broken
drivers/tty/serial/atmel_serial.c 2 Broken
drivers/tty/serial/mfd.c 2 Broken
drivers/spi/spi-stmp.c 1 Broken
drivers/dma/mv_xor.c 2 Broken
drivers/dma/dmaengine.c 3 Broken
drivers/dma/iop-adma.c 2 Broken
drivers/dma/dw_dmac.c 1 Broken
drivers/dma/ioat/dma.c 2 Broken
drivers/dma/dmatest.c 2 Broken
drivers/dma/txx9dmac.c 1 Broken
drivers/mtd/nand/fsmc_nand.c 1 Broken
drivers/scsi/initio.c 1 Broken
drivers/scsi/isci/request.c 1 Broken
drivers/scsi/sgiwd93.c 1 Broken
drivers/scsi/sun_esp.c 1 Broken
drivers/scsi/jazz_esp.c 1 Broken
drivers/scsi/53c700.c 2 Broken
drivers/scsi/sun3x_esp.c 1 Broken
drivers/scsi/advansys.c 2 Partial Broken
drivers/scsi/qla4xxx/ql4_os.c 1 Broken
drivers/usb/host/whci/qset.c 3 Broken
drivers/usb/musb/tusb6010_omap.c 2 Broken
drivers/usb/musb/musb_gadget.c 1 Broken
drivers/usb/core/usb.c 1 Broken
drivers/usb/gadget/atmel_usba_udc.c 1 Broken
drivers/usb/gadget/mv_udc_core.c 2 Broken
drivers/usb/gadget/fsl_udc_core.c 3 Broken
drivers/usb/gadget/lpc32xx_udc.c 1 Broken
drivers/usb/gadget/mv_u3d_core.c 1 Broken
drivers/usb/gadget/pch_udc.c 5 Broken
drivers/usb/gadget/fsl_qe_udc.c 3 Broken
drivers/video/grvga.c 1 Broken
drivers/staging/et131x/et131x.c 9 Broken
drivers/mmc/host/mmc_spi.c 2 Broken
drivers/mmc/host/wbsd.c 1 Partial Broken
drivers/media/video/vino.c 3 Broken
drivers/gpu/drm/via/via_dmablit.c 1 Broken
drivers/vme/bridges/vme_tsi148.c 2 Broken
drivers/message/i2o/memory.c 4 Broken
drivers/net/wireless/rt2x00/rt2x00queue.c 2 Broken
drivers/net/wireless/brcm80211/brcmsmac/dma.c 2 Broken
drivers/net/ethernet/ibm/emac/core.c 6 Broken
drivers/net/ethernet/ibm/ibmveth.c 6 Unmap Broken
drivers/net/ethernet/sun/sunbmac.c 3 Broken
drivers/net/ethernet/sun/niu.c 1 Broken
drivers/net/ethernet/sun/sunhme.c 5 Broken
drivers/net/ethernet/xscale/ixp4xx_eth.c 3 Unmap Broken
drivers/net/ethernet/sgi/meth.c 5 Broken
drivers/net/ethernet/smsc/smc91x.h 2 Broken
drivers/net/ethernet/smsc/smc911x.h 2 Broken
drivers/net/ethernet/tundra/tsi108_eth.c 2 Broken
drivers/net/ethernet/stmicro/stmmac/ring_mode.c 3 Broken
drivers/net/ethernet/stmicro/stmmac/chain_mode.c 3 Broken
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 3 Broken
drivers/net/ethernet/brocade/bna/bnad.c 2 Broken
drivers/net/ethernet/ti/cpmac.c 3 Broken
drivers/net/ethernet/ti/davinci_cpdma.c 1 Broken
drivers/net/ethernet/mellanox/mlx4/en_tx.c 1 Broken
drivers/net/ethernet/seeq/sgiseeq.c 3 Broken
drivers/net/ethernet/intel/e1000e/netdev.c 3 Unmap Broken
drivers/net/ethernet/intel/ixgb/ixgb_main.c 2 Partial Broken
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c 2 Partial Broken
drivers/net/ethernet/intel/e1000/e1000_ethtool.c 2 Broken
drivers/net/ethernet/freescale/fec_mpc52xx.c 2 Broken
drivers/net/ethernet/freescale/fec.c 3 Broken
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c 4 Broken
drivers/net/ethernet/freescale/ucc_geth.c 2 Broken
drivers/net/ethernet/freescale/gianfar.c 2 Broken
drivers/net/ethernet/xilinx/ll_temac_main.c 4 Broken
drivers/net/ethernet/xilinx/xilinx_axienet_main.c 4 Broken
drivers/net/ethernet/lantiq_etop.c 2 Broken
drivers/net/ethernet/renesas/sh_eth.c 3 Broken
drivers/net/ethernet/realtek/8139cp.c 5 Broken
drivers/net/ethernet/sfc/rx.c 1 Unmap Broken
drivers/net/ethernet/marvell/mv643xx_eth.c 2 Broken
drivers/net/ethernet/marvell/pxa168_eth.c 2 Broken
drivers/net/ethernet/cadence/at91_ether.c 1 Broken
drivers/net/ethernet/cadence/macb.c 1 Broken
drivers/net/ethernet/dec/tulip/de4x5.c 1 Broken
drivers/net/ethernet/i825xx/lib82596.c 3 Broken
drivers/net/ethernet/calxeda/xgmac.c 2 Partial Broken
drivers/net/ethernet/octeon/octeon_mgmt.c 4 Broken
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c 2 Unmap Broken
drivers/net/ethernet/broadcom/bcm63xx_enet.c 2 Broken
drivers/net/wan/ixp4xx_hss.c 3 Unmap Broken
drivers/net/fddi/defxx.c 3 Broken
drivers/crypto/talitos.c 3 Broken
drivers/crypto/ixp4xx_crypto.c 1 Broken
drivers/crypto/picoxcell_crypto.c 1 Broken
drivers/crypto/bfin_crc.c 2 Broken
drivers/crypto/caam/ctrl.c 1 Broken
drivers/crypto/caam/caamhash.c 20 Partial Broken
drivers/crypto/caam/caamrng.c 2 Broken
drivers/crypto/caam/caamalg.c 13 Partial Broken
include/asm-generic/pci-dma-compat.h 1 Broken pci_map_single() callers need to check
net/sunrpc/xprtrdma/verbs.c 1 Partial Broken
sound/soc/sh/fsi.c 1 Broken
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox