On Wed, Apr 12, 2023 at 10:03:46AM +0800, Xuan Zhuo wrote: > We discusses this question last at [1]. We planned to pass one device to xsk. > Then xsk can use the DMA API on this device. The device can be one hw > device(such as PCI, mmio) or virtio device. If it is one hw device, no problem. What do you mean with one here? A virtio device should never be baken by more than one hardware device. > If it is one virtio device, then we expect that DMA API on that will return > direct dma map, because the dma_ops of the virtio device is NULL. But on some > platform such as sparc64 or some case of x86, the arch has own dma_ops. So we > wrong. No, you can't expect a device to use any particular dma ops. Most platforms support either the direct mapping or some form of IOMMU. But for virtio thinks are even more complicated - unless VIRTIO_F_ACCESS_PLATFORM is set (which really must be set for all real hardware devices for them to work), the DMA API isn't even used at all. That means the virtual platform (i.e.g qemu) does DMA based on physical addresses and virtio ignores all the plaform DMA setup. > And as the discuss of this thread, we cannot get direct dma address from > virtio device by DMA API. So, we need xsk to expose the DMA ops to the > virtio-net driver when virtio core can not use the DMA API. > > All the processing of dma inside xsk: > 1. map/unmap at enable/disable > 2. dma sync For the VIRTIO_F_ACCESS_PLATFORM you can just use the DMA API like any other device, but this really should be done inside virtio instead of an upper layer. For the !VIRTIO_F_ACCESS_PLATFORM case there is no need to sync, and the dma mapping is a simple virt_to_phys or page_to_phys, so there's no real need to premap to start with. _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization