Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

virtio: allow caller to override device DMA mask in vp_modern

To add a bit of vendor flexibility with various virtio based devices,
allow the caller to specify a different DMA mask. This adds a dma_mask
field to struct virtio_pci_modern_device. If defined by the driver,
this mask will be used in a call to dma_set_mask_and_coherent() instead
of the traditional DMA_BIT_MASK(64). This allows limiting the DMA space
on vendor devices with address limitations.

Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20230519215632.12343-3-shannon.nelson@amd.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Shannon Nelson and committed by
Michael S. Tsirkin
5d7d82d3 a37c0191

+5 -1
+2 -1
drivers/virtio/virtio_pci_modern_dev.c
··· 268 268 return -EINVAL; 269 269 } 270 270 271 - err = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(64)); 271 + err = dma_set_mask_and_coherent(&pci_dev->dev, 272 + mdev->dma_mask ? : DMA_BIT_MASK(64)); 272 273 if (err) 273 274 err = dma_set_mask_and_coherent(&pci_dev->dev, 274 275 DMA_BIT_MASK(32));
+3
include/linux/virtio_pci_modern.h
··· 41 41 42 42 /* optional check for vendor virtio device, returns dev_id or -ERRNO */ 43 43 int (*device_id_check)(struct pci_dev *pdev); 44 + 45 + /* optional mask for devices with limited DMA space */ 46 + u64 dma_mask; 44 47 }; 45 48 46 49 /*