mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Amit Shah <amit.shah@qumranet.com>
To: kvm-devel@lists.sourceforge.net
Cc: virtualization@lists.linux-foundation.org, muli@il.ibm.com,
	BENAMI@il.ibm.com, gcosta@redhat.com, chrisw@redhat.com,
	dor.laor@qumranet.com, allen.m.kay@intel.com, avi@qumranet.com,
	linux-kernel@vger.kernel.org, Amit Shah <amit.shah@qumranet.com>
Subject: [PATCH] x86 DMA: Handle devices assigned to the guest by the host
Date: Tue, 29 Apr 2008 13:37:29 +0300	[thread overview]
Message-ID: <1209465451-3758-2-git-send-email-amit.shah@qumranet.com> (raw)
In-Reply-To: <1209465451-3758-1-git-send-email-amit.shah@qumranet.com>

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@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


  reply	other threads:[~2008-04-29 10:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-29 10:37 PV DMA for PCI passthrough devices for KVM Amit Shah
2008-04-29 10:37 ` Amit Shah [this message]
2008-04-29 10:37   ` [PATCH] KVM x86: Handle hypercalls for assigned PCI devices Amit Shah
2008-04-29 10:37     ` [PATCH] KVM PV Guest: Implement paravirtualized DMA Amit Shah
2008-04-29 13:31       ` Andi Kleen
2008-04-29 13:59         ` Amit Shah
2008-04-29 14:44     ` [PATCH] KVM x86: Handle hypercalls for assigned PCI devices Glauber Costa
2008-04-29 15:58       ` Amit Shah
2008-04-29 22:48         ` Avi Kivity
2008-04-30  6:05           ` Muli Ben-Yehuda
2008-05-01 13:18         ` Amit Shah
2008-04-29 13:14   ` [PATCH] x86 DMA: Handle devices assigned to the guest by the host Andi Kleen
2008-04-29 13:49     ` Amit Shah
2008-04-30  6:29   ` Muli Ben-Yehuda
2008-04-29 13:15 ` PV DMA for PCI passthrough devices for KVM Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1209465451-3758-2-git-send-email-amit.shah@qumranet.com \
    --to=amit.shah@qumranet.com \
    --cc=BENAMI@il.ibm.com \
    --cc=allen.m.kay@intel.com \
    --cc=avi@qumranet.com \
    --cc=chrisw@redhat.com \
    --cc=dor.laor@qumranet.com \
    --cc=gcosta@redhat.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=muli@il.ibm.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®