We have a PCIe device that does DMA transfers from device memory to system memory. Our device is 64-bit DMA capable, but fetches DMA descriptors from 32-bit bus addresses (i.e., it requires DMA descriptors to be available at bus addresses below 4GB).
As part of its initialization, the device driver indicates the device is 64-bit DMA capable by calling pci_set_dma_mask(dev, DMA_BIT_MASK(64)) (and checks the return value is 0). Then, it indicates the device can only address 32-bit consistent memory by calling pci_set_consistent_dma_mask(dev, DMA_BIT_MASK(32)) (and also checks the return value is 0).
To setup DMA transfers, the driver allocates one or more 4kB pages in consistent memory: pci_alloc_consistent(dev, size, &dmaAddress).
One of our customers is reporting issues on an NVIDIA Xavier module (Linux kernel 4.9.108-tegra). Our investigations have shown that the dmaAddress obtained from pci_alloc_consistent is above 4GB (e.g. 0x0000_0004_fdff_f000). Considering that pci_set_consistent_dma_mask(dev, DMA_BIT_MASK(32)) was successful, this should not happen. DMA addresses obtained from pci_alloc_consistent should be less than 4GB.
We are still investigating the issue.
Meanwhile, can you please use the following change to limit IOVA addresses to come from within 32-bit addressable region?
We checked internally and this kind of issue is not observed.
Can you please confirm that you are checking DMA/bus address (IOVA) and not CPU_VA returned by pci_alloc_consistent() API?
We have the same issue on the Jetson TX2 with R32.1 (kernel 4.9) so we thought it could be useful to share this information.
With R28.1 (kernel 4.4) there is no issue on the TX2.
Following the suggestion for the Xavier, we could work around the problem on the TX2 with R32.1 by limiting pcie_as.iova-start value to <0x0 0x7fffffff> in the device-tree.
This means these kernel allocation functions rely on the size of the region and do not always take into account the coherent_dma_mask the user could set.
On R32.1 we have the following sequence:
pci_alloc_consistent()
dma_alloc_coherent()
dma_alloc_attrs()
__iommu_alloc_attrs(): coherent_dma_mask is not always deeper taken into account
We investigated the issue on Jetson-Xavier but couldn’t repro it. @grrrr1433, Can you please try with the following patch on your system to see if you could hit the error case? You can just put this at the start/appropriate place in your device driver
We investigated the issue on Jetson-Xavier but couldn’t repro it. @grrrr1433, Can you please try with the following patch on your system to see if you could hit the error case? You can just put this at the start/appropriate place in your device driver
We investigated the issue on Jetson-Xavier but couldn’t repro it. @grrrr1433, Can you please try with the following patch on your system to see if you could hit the error case? You can just put this at the start/appropriate place in your device driver