All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] kvm tools: Guest kernel compatability
@ 2011-08-18 12:18 Sasha Levin
  2011-08-18 12:18 ` [PATCH 2/7] kvm tools: Add guest compatability warning to virtio-rng Sasha Levin
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Sasha Levin @ 2011-08-18 12:18 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

The problem of users running kernel which wasn't built for kvm tools is
somewhat common. Usualy the result is a panic during boot and a user whos'
stuck and doesn't know what to do next.

Compatability checks try to solve this issue by giving the user a meaningfull
error message which can explain whats going on and how he can fix it.

The idea is to register the device during device init and unregister the
device when the device has been 'used'. In case the kernel didn't access
the device before the guest is shut down, the host will notify the user that
something is wrong.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/Makefile                   |    1 +
 tools/kvm/builtin-run.c              |    3 +
 tools/kvm/guest_compat.c             |  104 ++++++++++++++++++++++++++++++++++
 tools/kvm/include/kvm/guest_compat.h |    9 +++
 4 files changed, 117 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/guest_compat.c
 create mode 100644 tools/kvm/include/kvm/guest_compat.h

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 85bbce7..316c2c9 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -33,6 +33,7 @@ OBJS	+= builtin-version.o
 OBJS	+= cpuid.o
 OBJS	+= disk/core.o
 OBJS	+= framebuffer.o
+OBJS	+= guest_compat.o
 OBJS	+= hw/rtc.o
 OBJS	+= hw/serial.o
 OBJS	+= interrupt.o
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 2816774..636f70e 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -27,6 +27,7 @@
 #include "kvm/rtc.h"
 #include "kvm/sdl.h"
 #include "kvm/vnc.h"
+#include "kvm/guest_compat.h"
 
 #include <linux/types.h>
 
@@ -730,6 +731,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 			exit_code = 1;
 	}
 
+	compat__print_all_messages();
+
 	fb__stop();
 
 	virtio_blk__delete_all(kvm);
diff --git a/tools/kvm/guest_compat.c b/tools/kvm/guest_compat.c
new file mode 100644
index 0000000..c5bacb8
--- /dev/null
+++ b/tools/kvm/guest_compat.c
@@ -0,0 +1,104 @@
+#include "kvm/guest_compat.h"
+
+#include "kvm/mutex.h"
+
+#include <linux/kernel.h>
+#include <linux/list.h>
+
+struct compat_message {
+	int id;
+	char *title;
+	char *desc;
+
+	struct list_head list;
+};
+
+static int id;
+static DEFINE_MUTEX(compat_mtx);
+static LIST_HEAD(messages);
+
+int compat__add_message(const char *title, const char *desc)
+{
+	struct compat_message *msg;
+
+	mutex_lock(&compat_mtx);
+	msg = malloc(sizeof(*msg));
+	if (msg == NULL)
+		goto cleanup;
+
+	*msg = (struct compat_message) {
+		.id = id,
+		.title = strdup(title),
+		.desc = strdup(desc),
+	};
+
+	if (msg->title == NULL || msg->desc == NULL)
+		goto cleanup;
+
+	list_add_tail(&msg->list, &messages);
+
+	mutex_unlock(&compat_mtx);
+
+	return id++;
+
+cleanup:
+	if (msg) {
+		free(msg->title);
+		free(msg->desc);
+		free(msg);
+	}
+
+	mutex_unlock(&compat_mtx);
+
+	return -ENOMEM;
+}
+
+static void compat__free(struct compat_message *msg)
+{
+	free(msg->title);
+	free(msg->desc);
+	free(msg);
+}
+
+int compat__remove_message(int id)
+{
+	struct compat_message *pos, *n;
+
+	mutex_lock(&compat_mtx);
+
+	list_for_each_entry_safe(pos, n, &messages, list) {
+		if (pos->id == id) {
+			list_del(&pos->list);
+			compat__free(pos);
+
+			mutex_unlock(&compat_mtx);
+
+			return 0;
+		}
+	}
+
+	mutex_unlock(&compat_mtx);
+
+	return -ENOENT;
+}
+
+int compat__print_all_messages(void)
+{
+	mutex_lock(&compat_mtx);
+
+	while (!list_empty(&messages)) {
+		struct compat_message *msg;
+
+		msg = list_first_entry(&messages, struct compat_message, list);
+
+		printf("\n\n*** Compatability Warning ***\n\n\t%s\n\n%s\n",
+			msg->title, msg->desc);
+
+		list_del(&msg->list);
+		compat__free(msg);
+	}
+
+	mutex_unlock(&compat_mtx);
+
+	return 0;
+}
\ No newline at end of file
diff --git a/tools/kvm/include/kvm/guest_compat.h b/tools/kvm/include/kvm/guest_compat.h
new file mode 100644
index 0000000..ae7abbd
--- /dev/null
+++ b/tools/kvm/include/kvm/guest_compat.h
@@ -0,0 +1,9 @@
+#ifndef KVM__GUEST_COMPAT_H
+#define KVM__GUEST_COMPAT_H
+
+int compat__print_all_messages(void);
+int compat__remove_message(int id);
+int compat__add_message(const char *title, const char *description);
+
+
+#endif
\ No newline at end of file
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/7] kvm tools: Add guest compatability warning to virtio-rng
  2011-08-18 12:18 [PATCH 1/7] kvm tools: Guest kernel compatability Sasha Levin
@ 2011-08-18 12:18 ` Sasha Levin
  2011-08-18 12:18 ` [PATCH 3/7] kvm tools: Add guest compatability warning to virtio-blk Sasha Levin
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2011-08-18 12:18 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/virtio/rng.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/virtio/rng.c b/tools/kvm/virtio/rng.c
index 5f29ded..a540e2e 100644
--- a/tools/kvm/virtio/rng.c
+++ b/tools/kvm/virtio/rng.c
@@ -11,6 +11,7 @@
 #include "kvm/threadpool.h"
 #include "kvm/irq.h"
 #include "kvm/ioeventfd.h"
+#include "kvm/guest_compat.h"
 
 #include <linux/virtio_ring.h>
 #include <linux/virtio_rng.h>
@@ -41,6 +42,7 @@ struct rng_dev {
 	int			fd;
 	u32			vq_vector[NUM_VIRT_QUEUES];
 	u32			msix_io_block;
+	int			compat_id;
 
 	/* virtio queue */
 	u16			queue_selector;
@@ -137,6 +139,8 @@ static bool virtio_rng_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 po
 		struct rng_dev_job *job;
 		void *p;
 
+		compat__remove_message(rdev->compat_id);
+
 		queue			= &rdev->vqs[rdev->queue_selector];
 		queue->pfn		= ioport__read32(data);
 		p			= guest_pfn_to_host(kvm, queue->pfn);
@@ -279,6 +283,12 @@ void virtio_rng__init(struct kvm *kvm)
 
 		ioeventfd__add_event(&ioevent);
 	}
+
+	rdev->compat_id = compat__add_message("virtio-rng device was not detected",
+						"While you have requested a virtio-rng device, "
+						"the guest kernel didn't seem to detect it.\n"
+						"Please make sure that the kernel was compiled"
+						"with CONFIG_HW_RANDOM_VIRTIO.");
 }
 
 void virtio_rng__delete_all(struct kvm *kvm)
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/7] kvm tools: Add guest compatability warning to virtio-blk
  2011-08-18 12:18 [PATCH 1/7] kvm tools: Guest kernel compatability Sasha Levin
  2011-08-18 12:18 ` [PATCH 2/7] kvm tools: Add guest compatability warning to virtio-rng Sasha Levin
@ 2011-08-18 12:18 ` Sasha Levin
  2011-08-18 12:18 ` [PATCH 4/7] kvm tools: Add guest compatability warning to virtio-9p Sasha Levin
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2011-08-18 12:18 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/virtio/blk.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c
index f5ecdd9..856c418 100644
--- a/tools/kvm/virtio/blk.c
+++ b/tools/kvm/virtio/blk.c
@@ -11,6 +11,7 @@
 #include "kvm/pci.h"
 #include "kvm/threadpool.h"
 #include "kvm/ioeventfd.h"
+#include "kvm/guest_compat.h"
 
 #include <linux/virtio_ring.h>
 #include <linux/virtio_blk.h>
@@ -48,6 +49,7 @@ struct blk_dev {
 	u16				config_vector;
 	u8				status;
 	u8				isr;
+	int				compat_id;
 
 	/* virtio queue */
 	u16				queue_selector;
@@ -208,6 +210,8 @@ static bool virtio_blk_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 po
 		struct virt_queue *queue;
 		void *p;
 
+		compat__remove_message(bdev->compat_id);
+
 		queue			= &bdev->vqs[bdev->queue_selector];
 		queue->pfn		= ioport__read32(data);
 		p			= guest_pfn_to_host(kvm, queue->pfn);
@@ -322,6 +326,12 @@ void virtio_blk__init(struct kvm *kvm, struct disk_image *disk)
 
 		ioeventfd__add_event(&ioevent);
 	}
+
+	bdev->compat_id = compat__add_message("virtio-blk device was not detected",
+						"While you have requested a virtio-blk device, "
+						"the guest kernel didn't seem to detect it.\n"
+						"Please make sure that the kernel was compiled"
+						"with CONFIG_VIRTIO_BLK.");
 }
 
 void virtio_blk__init_all(struct kvm *kvm)
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/7] kvm tools: Add guest compatability warning to virtio-9p
  2011-08-18 12:18 [PATCH 1/7] kvm tools: Guest kernel compatability Sasha Levin
  2011-08-18 12:18 ` [PATCH 2/7] kvm tools: Add guest compatability warning to virtio-rng Sasha Levin
  2011-08-18 12:18 ` [PATCH 3/7] kvm tools: Add guest compatability warning to virtio-blk Sasha Levin
@ 2011-08-18 12:18 ` Sasha Levin
  2011-08-18 12:18 ` [PATCH 5/7] kvm tools: Add guest compatability warning to virtio-net Sasha Levin
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2011-08-18 12:18 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/include/kvm/virtio-9p.h |    1 +
 tools/kvm/virtio/9p.c             |    9 +++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/include/kvm/virtio-9p.h b/tools/kvm/include/kvm/virtio-9p.h
index 0e55e5c..70db831 100644
--- a/tools/kvm/include/kvm/virtio-9p.h
+++ b/tools/kvm/include/kvm/virtio-9p.h
@@ -44,6 +44,7 @@ struct p9_dev {
 	u32			features;
 	struct virtio_9p_config	*config;
 	u16			base_addr;
+	int			compat_id;
 
 	/* virtio queue */
 	u16			queue_selector;
diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c
index ca9268a..92fe345 100644
--- a/tools/kvm/virtio/9p.c
+++ b/tools/kvm/virtio/9p.c
@@ -5,6 +5,7 @@
 #include "kvm/ioeventfd.h"
 #include "kvm/irq.h"
 #include "kvm/virtio-9p.h"
+#include "kvm/guest_compat.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -781,6 +782,8 @@ static bool virtio_p9_pci_io_out(struct ioport *ioport, struct kvm *kvm,
 		struct p9_dev_job *job;
 		struct virt_queue *queue;
 
+		compat__remove_message(p9dev->compat_id);
+
 		job			= &p9dev->jobs[p9dev->queue_selector];
 		queue			= &p9dev->vqs[p9dev->queue_selector];
 		queue->pfn		= ioport__read32(data);
@@ -900,6 +903,12 @@ int virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name)
 	};
 	pci__register(&p9dev->pci_hdr, dev);
 
+	p9dev->compat_id = compat__add_message("virtio-9p device was not detected",
+						"While you have requested a virtio-9p device, "
+						"the guest kernel didn't seem to detect it.\n"
+						"Please make sure that the kernel was compiled"
+						"with CONFIG_NET_9P_VIRTIO.");
+
 	return err;
 
 free_p9dev_config:
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/7] kvm tools: Add guest compatability warning to virtio-net
  2011-08-18 12:18 [PATCH 1/7] kvm tools: Guest kernel compatability Sasha Levin
                   ` (2 preceding siblings ...)
  2011-08-18 12:18 ` [PATCH 4/7] kvm tools: Add guest compatability warning to virtio-9p Sasha Levin
@ 2011-08-18 12:18 ` Sasha Levin
  2011-08-18 12:18 ` [PATCH 6/7] kvm tools: Add guest compatability warning to virtio-console Sasha Levin
  2011-08-18 12:18 ` [PATCH 7/7] kvm tools: Add guest compatability warning to virtio-balloon Sasha Levin
  5 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2011-08-18 12:18 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/virtio/net.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index a74f1e7..9a11721 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -10,6 +10,7 @@
 #include "kvm/irq.h"
 #include "kvm/uip.h"
 #include "kvm/ioeventfd.h"
+#include "kvm/guest_compat.h"
 
 #include <linux/virtio_net.h>
 #include <linux/if_tun.h>
@@ -63,6 +64,7 @@ struct net_dev {
 	u32				vq_vector[VIRTIO_NET_NUM_QUEUES];
 	u32				gsis[VIRTIO_NET_NUM_QUEUES];
 	u32				msix_io_block;
+	int				compat_id;
 
 	pthread_t			io_rx_thread;
 	pthread_mutex_t			io_rx_lock;
@@ -265,6 +267,8 @@ static bool virtio_net_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 po
 
 		assert(ndev.queue_selector < VIRTIO_NET_NUM_QUEUES);
 
+		compat__remove_message(ndev.compat_id);
+
 		queue			= &ndev.vqs[ndev.queue_selector];
 		queue->pfn		= ioport__read32(data);
 		p			= guest_pfn_to_host(kvm, queue->pfn);
@@ -520,4 +524,10 @@ void virtio_net__init(const struct virtio_net_parameters *params)
 
 		ioeventfd__add_event(&ioevent);
 	}
+
+	ndev.compat_id = compat__add_message("virtio-net device was not detected",
+						"While you have requested a virtio-net device, "
+						"the guest kernel didn't seem to detect it.\n"
+						"Please make sure that the kernel was compiled"
+						"with CONFIG_VIRTIO_NET.");
 }
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 6/7] kvm tools: Add guest compatability warning to virtio-console
  2011-08-18 12:18 [PATCH 1/7] kvm tools: Guest kernel compatability Sasha Levin
                   ` (3 preceding siblings ...)
  2011-08-18 12:18 ` [PATCH 5/7] kvm tools: Add guest compatability warning to virtio-net Sasha Levin
@ 2011-08-18 12:18 ` Sasha Levin
  2011-08-18 12:18 ` [PATCH 7/7] kvm tools: Add guest compatability warning to virtio-balloon Sasha Levin
  5 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2011-08-18 12:18 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/virtio/console.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c
index e5d59c0..ef9b1fc 100644
--- a/tools/kvm/virtio/console.c
+++ b/tools/kvm/virtio/console.c
@@ -10,6 +10,7 @@
 #include "kvm/pci.h"
 #include "kvm/threadpool.h"
 #include "kvm/irq.h"
+#include "kvm/guest_compat.h"
 
 #include <linux/virtio_console.h>
 #include <linux/virtio_ring.h>
@@ -50,6 +51,7 @@ struct con_dev {
 	u8				isr;
 	u16				queue_selector;
 	u16				base_addr;
+	int				compat_id;
 
 	struct thread_pool__job		jobs[VIRTIO_CONSOLE_NUM_QUEUES];
 };
@@ -196,6 +198,8 @@ static bool virtio_console_pci_io_out(struct ioport *ioport, struct kvm *kvm, u1
 
 		assert(cdev.queue_selector < VIRTIO_CONSOLE_NUM_QUEUES);
 
+		compat__remove_message(cdev.compat_id);
+
 		queue			= &cdev.vqs[cdev.queue_selector];
 		queue->pfn		= ioport__read32(data);
 		p			= guest_pfn_to_host(kvm, queue->pfn);
@@ -254,4 +258,10 @@ void virtio_console__init(struct kvm *kvm)
 	virtio_console_pci_device.bar[0]	= console_base_addr | PCI_BASE_ADDRESS_SPACE_IO;
 	cdev.base_addr				= console_base_addr;
 	pci__register(&virtio_console_pci_device, dev);
+
+	cdev.compat_id = compat__add_message("virtio-console device was not detected",
+						"While you have requested a virtio-console device, "
+						"the guest kernel didn't seem to detect it.\n"
+						"Please make sure that the kernel was compiled"
+						"with CONFIG_VIRTIO_CONSOLE.");
 }
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 7/7] kvm tools: Add guest compatability warning to virtio-balloon
  2011-08-18 12:18 [PATCH 1/7] kvm tools: Guest kernel compatability Sasha Levin
                   ` (4 preceding siblings ...)
  2011-08-18 12:18 ` [PATCH 6/7] kvm tools: Add guest compatability warning to virtio-console Sasha Levin
@ 2011-08-18 12:18 ` Sasha Levin
  5 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2011-08-18 12:18 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/virtio/balloon.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c
index c5853a5..05bb196 100644
--- a/tools/kvm/virtio/balloon.c
+++ b/tools/kvm/virtio/balloon.c
@@ -11,6 +11,7 @@
 #include "kvm/threadpool.h"
 #include "kvm/irq.h"
 #include "kvm/ioeventfd.h"
+#include "kvm/guest_compat.h"
 
 #include <linux/virtio_ring.h>
 #include <linux/virtio_balloon.h>
@@ -48,6 +49,7 @@ struct bln_dev {
 	u16			stat_count;
 	int			stat_waitfd;
 
+	int			compat_id;
 	struct virtio_balloon_config config;
 };
 
@@ -211,6 +213,8 @@ static bool virtio_bln_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 po
 		struct virt_queue *queue;
 		void *p;
 
+		compat__remove_message(bdev.compat_id);
+
 		queue			= &bdev.vqs[bdev.queue_selector];
 		queue->pfn		= ioport__read32(data);
 		p			= guest_pfn_to_host(kvm, queue->pfn);
@@ -366,4 +370,10 @@ void virtio_bln__init(struct kvm *kvm)
 	memset(&bdev.config, 0, sizeof(struct virtio_balloon_config));
 
 	pci__register(&bdev.pci_hdr, dev);
+
+	bdev.compat_id = compat__add_message("virtio-balloon device was not detected",
+						"While you have requested a virtio-balloon device, "
+						"the guest kernel didn't seem to detect it.\n"
+						"Please make sure that the kernel was compiled"
+						"with CONFIG_VIRTIO_BALLOON.");
 }
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-08-18 12:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-18 12:18 [PATCH 1/7] kvm tools: Guest kernel compatability Sasha Levin
2011-08-18 12:18 ` [PATCH 2/7] kvm tools: Add guest compatability warning to virtio-rng Sasha Levin
2011-08-18 12:18 ` [PATCH 3/7] kvm tools: Add guest compatability warning to virtio-blk Sasha Levin
2011-08-18 12:18 ` [PATCH 4/7] kvm tools: Add guest compatability warning to virtio-9p Sasha Levin
2011-08-18 12:18 ` [PATCH 5/7] kvm tools: Add guest compatability warning to virtio-net Sasha Levin
2011-08-18 12:18 ` [PATCH 6/7] kvm tools: Add guest compatability warning to virtio-console Sasha Levin
2011-08-18 12:18 ` [PATCH 7/7] kvm tools: Add guest compatability warning to virtio-balloon Sasha Levin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.