This patchset implements PVDMA for handling DMA requests from devices assigned to the guest from the host machine. They're also available from git-pull git://git.kernel.org/pub/scm/linux/kernel/git/amit/kvm.git pvdma These patches are based on my pci-passthrough tree, which is available from git-pull git://git.kernel.org/pub/scm/linux/kernel/git/amit/kvm.git and the userspace from git-pull git://git.kernel.org/pub/scm/linux/kernel/git/amit/kvm-userspace.git The first and the third patch in this series is needed on the guest (with some bits from the 2nd as well). The 2nd patch is meant for the host kernel. Amit.
Amit Shah
2008-Apr-29 10:37 UTC
[PATCH] x86 DMA: Handle devices assigned to the guest by the host
dma_alloc_coherent() doesn't call dma_ops->alloc_coherent in case no IOMMU translations are necessary. However, if the device doing the DMA is a physical device assigned to the guest OS by the host, we need to map all the DMA addresses to the host machine addresses. This is done via hypercalls to the host. In KVM, with pci passthrough support, we can assign actual devices to the guest OS which need this functionality. Signed-off-by: Amit Shah <amit.shah at qumranet.com> --- arch/x86/kernel/pci-dma.c | 11 +++++++++++ include/asm-x86/dma-mapping.h | 2 ++ 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index 388b113..678cafb 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c @@ -443,6 +443,17 @@ dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, memset(memory, 0, size); if (!mmu) { *dma_handle = bus; + if (unlikely(dma_ops->is_pv_device) && + unlikely(dma_ops->is_pv_device(dev, dev->bus_id))) { + void *r; + r = dma_ops->alloc_coherent(dev, size, + dma_handle, gfp); + if (r == NULL) { + free_pages((unsigned long)memory, + get_order(size)); + memory = NULL; + } + } return memory; } } diff --git a/include/asm-x86/dma-mapping.h b/include/asm-x86/dma-mapping.h index a1a4dc7..b9c6a39 100644 --- a/include/asm-x86/dma-mapping.h +++ b/include/asm-x86/dma-mapping.h @@ -55,6 +55,8 @@ struct dma_mapping_ops { int direction); int (*dma_supported)(struct device *hwdev, u64 mask); int is_phys; + /* Is this a physical device in a paravirtualized guest? */ + int (*is_pv_device)(struct device *hwdev, const char *name); }; extern const struct dma_mapping_ops *dma_ops; -- 1.5.4.3
Amit Shah <amit.shah at qumranet.com> writes:> This patchset implements PVDMA for handling DMA requests from > devices assigned to the guest from the host machine.You forgot to post a high level design overview of how this works, what it is good for, what are the design trade offs etc.? Include that in the first patch. -Andi