From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: <mst@redhat.com>
Cc: <virtualization@lists.linux-foundation.org>,
<linux-kernel@vger.kernel.org>, <xen-devel@lists.xenproject.org>,
<Stefano.Stabellini@eu.citrix.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH RFC 2/3] xen/virtio: allocate a contiguous region to be use as virtio queue
Date: Mon, 7 Dec 2015 16:19:42 +0000 [thread overview]
Message-ID: <1449505183-29740-2-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1512071555590.24652@kaball.uk.xensource.com>
When running on Xen inside as virtual machine (nested virt scenario),
memory allocated by alloc_pages_exact might not actually be contiguous.
Call xen_swiotlb_alloc_coherent instead, which is going to take care of
making the buffer contiguous in machine memory.
No changes in behavior for the non-Xen case.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
Alternatively we could call dma_alloc_coherent in all cases, but that
would make the non-Xen code path more complex.
---
drivers/virtio/virtio_pci_legacy.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
index 48bc979..27359ac 100644
--- a/drivers/virtio/virtio_pci_legacy.c
+++ b/drivers/virtio/virtio_pci_legacy.c
@@ -18,6 +18,8 @@
*/
#include "virtio_pci_common.h"
+#include <xen/xen.h>
+#include <xen/swiotlb-xen.h>
/* virtio config->get_features() implementation */
static u64 vp_get_features(struct virtio_device *vdev)
@@ -122,6 +124,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
unsigned long size;
u16 num;
int err;
+ dma_addr_t dma_addr;
/* Select the queue we're interested in */
iowrite16(index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
@@ -135,12 +138,20 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
info->msix_vector = msix_vec;
size = PAGE_ALIGN(vring_size(num, VIRTIO_PCI_VRING_ALIGN));
- info->queue = alloc_pages_exact(size, GFP_KERNEL|__GFP_ZERO);
+ /* activate the queue */
+ if (xen_domain()) {
+ info->queue = xen_swiotlb_alloc_coherent(NULL,
+ size,
+ &dma_addr,
+ GFP_KERNEL|__GFP_ZERO,
+ NULL);
+ } else {
+ info->queue = alloc_pages_exact(size, GFP_KERNEL|__GFP_ZERO);
+ dma_addr = virt_to_phys(info->queue);
+ }
if (info->queue == NULL)
return ERR_PTR(-ENOMEM);
-
- /* activate the queue */
- iowrite32(virt_to_phys(info->queue) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT,
+ iowrite32(dma_addr >> VIRTIO_PCI_QUEUE_ADDR_SHIFT,
vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
/* create the vring */
--
1.7.10.4
next prev parent reply other threads:[~2015-12-07 16:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-07 16:19 [PATCH RFC 0/3] Xen on Virtio Stefano Stabellini
2015-12-07 16:19 ` [PATCH RFC 1/3] xen: export xen_phys_to_bus, xen_bus_to_phys and xen_virt_to_bus Stefano Stabellini
2015-12-14 14:12 ` [Xen-devel] " David Vrabel
2015-12-07 16:19 ` Stefano Stabellini [this message]
2015-12-07 16:19 ` [PATCH RFC 3/3] xen/virtio_ring: introduce cpu_to_virtio_addr and virtio_addr_to_cpu Stefano Stabellini
2015-12-14 14:00 ` [Xen-devel] [PATCH RFC 0/3] Xen on Virtio David Vrabel
2015-12-14 14:12 ` Michael S. Tsirkin
2015-12-14 18:27 ` Andy Lutomirski
2015-12-15 12:13 ` Stefano Stabellini
2015-12-15 16:45 ` Andy Lutomirski
2015-12-15 20:44 ` Michael S. Tsirkin
2015-12-15 20:40 ` Michael S. Tsirkin
2016-01-11 23:03 ` Andy Lutomirski
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=1449505183-29740-2-git-send-email-stefano.stabellini@eu.citrix.com \
--to=stefano.stabellini@eu.citrix.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xen-devel@lists.xenproject.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®