[PATCH] [kvmtool]: Use the arch default transport method for network

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Suzuki K. Poulose" <suzuki.poulose@xxxxxxx>

lkvm by default sets up a virtio-pci transport for network, if none is
specified. This can be a problem on archs (e.g ARM64), where virtio-pci is
not supported yet and cause the following warning at exit.

  # KVM compatibility warning.
	virtio-net device was not detected.
	While you have requested a virtio-net device, the guest kernel did not initialize it.
	Please make sure that the guest kernel was compiled with CONFIG_VIRTIO_NET=y enabled in .config.

This patch changes it to make use of the default transport method for the
architecture when none is specified. This will ensure that on every arch
we get the network up by default in the VM.

Applies on top of the kvm/arm branch in Will's kvmtool tree.

Signed-off-by: Suzuki K. Poulose <suzuki.poulose@xxxxxxx>
Acked-by: Will Deacon <will.deacon@xxxxxxx>
---
 tools/kvm/include/kvm/virtio.h |    1 +
 tools/kvm/virtio/core.c        |    9 +++++++++
 tools/kvm/virtio/net.c         |   21 +++++++++++++++------
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
index 8a9eab5..768ee96 100644
--- a/tools/kvm/include/kvm/virtio.h
+++ b/tools/kvm/include/kvm/virtio.h
@@ -160,6 +160,7 @@ int virtio_init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
 		struct virtio_ops *ops, enum virtio_trans trans,
 		int device_id, int subsys_id, int class);
 int virtio_compat_add_message(const char *device, const char *config);
+const char* virtio_trans_name(enum virtio_trans trans);
 
 static inline void *virtio_get_vq(struct kvm *kvm, u32 pfn, u32 page_size)
 {
diff --git a/tools/kvm/virtio/core.c b/tools/kvm/virtio/core.c
index 9ae7887..3b6e4d7 100644
--- a/tools/kvm/virtio/core.c
+++ b/tools/kvm/virtio/core.c
@@ -12,6 +12,15 @@
 #include "kvm/kvm.h"
 
 
+const char* virtio_trans_name(enum virtio_trans trans)
+{
+	if (trans == VIRTIO_PCI)
+		return "pci";
+	else if (trans == VIRTIO_MMIO)
+		return "mmio";
+	return "unknown";
+}
+
 struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 head, u32 len)
 {
 	struct vring_used_elem *used_elem;
diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index c8af385..e9daea4 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -758,6 +758,7 @@ static int virtio_net__init_one(struct virtio_net_params *params)
 	int i, err;
 	struct net_dev *ndev;
 	struct virtio_ops *ops;
+	enum virtio_trans trans = VIRTIO_DEFAULT_TRANS(params->kvm);
 
 	ndev = calloc(1, sizeof(struct net_dev));
 	if (ndev == NULL)
@@ -799,12 +800,20 @@ static int virtio_net__init_one(struct virtio_net_params *params)
 	}
 
 	*ops = net_dev_virtio_ops;
-	if (params->trans && strcmp(params->trans, "mmio") == 0)
-		virtio_init(params->kvm, ndev, &ndev->vdev, ops, VIRTIO_MMIO,
-			    PCI_DEVICE_ID_VIRTIO_NET, VIRTIO_ID_NET, PCI_CLASS_NET);
-	else
-		virtio_init(params->kvm, ndev, &ndev->vdev, ops, VIRTIO_PCI,
-			    PCI_DEVICE_ID_VIRTIO_NET, VIRTIO_ID_NET, PCI_CLASS_NET);
+
+	if (params->trans) {
+		if (strcmp(params->trans, "mmio") == 0)
+			trans = VIRTIO_MMIO;
+		else if (strcmp(params->trans, "pci") == 0)
+			trans = VIRTIO_PCI;
+		else
+			pr_warning("virtio-net: Unknown transport method : %s, " 
+				   "falling back to %s.", params->trans,
+				   virtio_trans_name(trans));
+	}
+
+	virtio_init(params->kvm, ndev, &ndev->vdev, ops, trans,
+		    PCI_DEVICE_ID_VIRTIO_NET, VIRTIO_ID_NET, PCI_CLASS_NET);
 
 	if (params->vhost)
 		virtio_net__vhost_init(params->kvm, ndev);
-- 
1.7.9.5


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux