Thirty Two Bit Device

A driver on a 64 GiB machine allocates a buffer for a device whose DMA engine drives 32 address lines. It uses a plain kmalloc(size, GFP_KERNEL), and the device silently reads garbage on maybe one boot in ten.

What is happening, and what is the fix?

A

The buffer was allocated in a user-facing zone. The driver must request kernel-only memory so the device is not blocked by page protections.

B

The allocation can land anywhere in physical memory, including above 4 GiB, which the device cannot address. The driver must allocate from the zone capped at 4 GiB, with GFP_DMA32.

C

The buffer can be swapped out while the transfer is in flight. The driver must pin it before starting the DMA.

D

The buffer can straddle a page boundary, and DMA requires physically contiguous memory. The driver must allocate whole pages.