All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/4] s390: virtio-ccw guest kernel support.
@ 2012-08-07 14:52 ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-07 14:52 UTC (permalink / raw)
  To: KVM, linux-s390, qemu-devel
  Cc: Avi Kivity, Marcelo Tosatti, Anthony Liguori, Rusty Russell,
	Christian Borntraeger, Carsten Otte, Alexander Graf,
	Heiko Carstens, Martin Schwidefsky, Sebastian Ott

Hi,

the following patches are for Linux running as a guest under a
host with virtio-ccw support.

Patch 1 makes the kvm_virtio driver exit gracefully if the page
containing s390-virtio information it expects is not present; it
could probably go in seperately from the other patches.

Patch 2 exports a needed interface.

Patch 3 adds a driver handling virtio-ccw devices. The virtual
subchannels have ccw devices with a special CU id this driver
matches for. The virtio_ccw driver handles configuration and
operation via the special new channel commands.

Patch 4 is a split out of common code.

Cornelia Huck (4):
  s390/kvm: Handle hosts not supporting s390-virtio.
  s390: Add a mechanism to get the subchannel id.
  s390/kvm: Add a channel I/O based virtio transport driver.
  s390/kvm: Split out early console code.

 arch/s390/include/asm/ccwdev.h  |   5 +
 arch/s390/include/asm/irq.h     |   1 +
 arch/s390/kernel/irq.c          |   1 +
 drivers/s390/cio/device_ops.c   |  10 +
 drivers/s390/kvm/Makefile       |   2 +-
 drivers/s390/kvm/early_printk.c |  42 +++
 drivers/s390/kvm/kvm_virtio.c   |  46 ++-
 drivers/s390/kvm/virtio_ccw.c   | 760 ++++++++++++++++++++++++++++++++++++++++
 8 files changed, 841 insertions(+), 26 deletions(-)
 create mode 100644 drivers/s390/kvm/early_printk.c
 create mode 100644 drivers/s390/kvm/virtio_ccw.c

-- 
1.7.11.4

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

* [Qemu-devel] [RFC PATCH 0/4] s390: virtio-ccw guest kernel support.
@ 2012-08-07 14:52 ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-07 14:52 UTC (permalink / raw)
  To: KVM, linux-s390, qemu-devel
  Cc: Carsten Otte, Anthony Liguori, Rusty Russell, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

Hi,

the following patches are for Linux running as a guest under a
host with virtio-ccw support.

Patch 1 makes the kvm_virtio driver exit gracefully if the page
containing s390-virtio information it expects is not present; it
could probably go in seperately from the other patches.

Patch 2 exports a needed interface.

Patch 3 adds a driver handling virtio-ccw devices. The virtual
subchannels have ccw devices with a special CU id this driver
matches for. The virtio_ccw driver handles configuration and
operation via the special new channel commands.

Patch 4 is a split out of common code.

Cornelia Huck (4):
  s390/kvm: Handle hosts not supporting s390-virtio.
  s390: Add a mechanism to get the subchannel id.
  s390/kvm: Add a channel I/O based virtio transport driver.
  s390/kvm: Split out early console code.

 arch/s390/include/asm/ccwdev.h  |   5 +
 arch/s390/include/asm/irq.h     |   1 +
 arch/s390/kernel/irq.c          |   1 +
 drivers/s390/cio/device_ops.c   |  10 +
 drivers/s390/kvm/Makefile       |   2 +-
 drivers/s390/kvm/early_printk.c |  42 +++
 drivers/s390/kvm/kvm_virtio.c   |  46 ++-
 drivers/s390/kvm/virtio_ccw.c   | 760 ++++++++++++++++++++++++++++++++++++++++
 8 files changed, 841 insertions(+), 26 deletions(-)
 create mode 100644 drivers/s390/kvm/early_printk.c
 create mode 100644 drivers/s390/kvm/virtio_ccw.c

-- 
1.7.11.4

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

* [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
  2012-08-07 14:52 ` [Qemu-devel] " Cornelia Huck
@ 2012-08-07 14:52   ` Cornelia Huck
  -1 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-07 14:52 UTC (permalink / raw)
  To: KVM, linux-s390, qemu-devel
  Cc: Avi Kivity, Marcelo Tosatti, Anthony Liguori, Rusty Russell,
	Christian Borntraeger, Carsten Otte, Alexander Graf,
	Heiko Carstens, Martin Schwidefsky, Sebastian Ott

Running under a kvm host does not necessarily imply the presence of
a page mapped above the main memory with the virtio information;
however, the code includes a hard coded access to that page.

Instead, check for the presence of the page and exit gracefully
before we hit an addressing exception if it does not exist.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 drivers/s390/kvm/kvm_virtio.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 47cccd5..408447c 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -418,6 +418,21 @@ static void kvm_extint_handler(struct ext_code ext_code,
 	}
 }
 
+static int __init test_devices_support(void)
+{
+	int ccode = -EIO;
+
+	asm volatile(
+		"0:	cli	0(%1),0\n"
+		"	ipm	%0\n"
+		"	srl	%0,28\n"
+		"1:\n"
+		EX_TABLE(0b,1b)
+		: "+d" (ccode)
+		: "a" (kvm_devices)
+		: "cc");
+	return ccode;
+}
 /*
  * Init function for virtio
  * devices are in a single page above top of "normal" mem
@@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
 	}
 
 	kvm_devices = (void *) real_memory_size;
+	if (test_devices_support() < 0) {
+		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
+		root_device_unregister(kvm_root);
+		/* No error. */
+		return 0;
+	}
 
 	INIT_WORK(&hotplug_work, hotplug_devices);
 
-- 
1.7.11.4

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

* [Qemu-devel] [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
@ 2012-08-07 14:52   ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-07 14:52 UTC (permalink / raw)
  To: KVM, linux-s390, qemu-devel
  Cc: Carsten Otte, Anthony Liguori, Rusty Russell, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

Running under a kvm host does not necessarily imply the presence of
a page mapped above the main memory with the virtio information;
however, the code includes a hard coded access to that page.

Instead, check for the presence of the page and exit gracefully
before we hit an addressing exception if it does not exist.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 drivers/s390/kvm/kvm_virtio.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 47cccd5..408447c 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -418,6 +418,21 @@ static void kvm_extint_handler(struct ext_code ext_code,
 	}
 }
 
+static int __init test_devices_support(void)
+{
+	int ccode = -EIO;
+
+	asm volatile(
+		"0:	cli	0(%1),0\n"
+		"	ipm	%0\n"
+		"	srl	%0,28\n"
+		"1:\n"
+		EX_TABLE(0b,1b)
+		: "+d" (ccode)
+		: "a" (kvm_devices)
+		: "cc");
+	return ccode;
+}
 /*
  * Init function for virtio
  * devices are in a single page above top of "normal" mem
@@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
 	}
 
 	kvm_devices = (void *) real_memory_size;
+	if (test_devices_support() < 0) {
+		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
+		root_device_unregister(kvm_root);
+		/* No error. */
+		return 0;
+	}
 
 	INIT_WORK(&hotplug_work, hotplug_devices);
 
-- 
1.7.11.4

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

* [PATCH 2/4] s390: Add a mechanism to get the subchannel id.
  2012-08-07 14:52 ` [Qemu-devel] " Cornelia Huck
@ 2012-08-07 14:52   ` Cornelia Huck
  -1 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-07 14:52 UTC (permalink / raw)
  To: KVM, linux-s390, qemu-devel
  Cc: Avi Kivity, Marcelo Tosatti, Anthony Liguori, Rusty Russell,
	Christian Borntraeger, Carsten Otte, Alexander Graf,
	Heiko Carstens, Martin Schwidefsky, Sebastian Ott

This will be needed by the new virtio-ccw transport.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 arch/s390/include/asm/ccwdev.h |  5 +++++
 drivers/s390/cio/device_ops.c  | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/arch/s390/include/asm/ccwdev.h b/arch/s390/include/asm/ccwdev.h
index 1cb4bb3..9ad79f7 100644
--- a/arch/s390/include/asm/ccwdev.h
+++ b/arch/s390/include/asm/ccwdev.h
@@ -18,6 +18,9 @@ struct irb;
 struct ccw1;
 struct ccw_dev_id;
 
+/* from asm/schid.h */
+struct subchannel_id;
+
 /* simplified initializers for struct ccw_device:
  * CCW_DEVICE and CCW_DEVICE_DEVTYPE initialize one
  * entry in your MODULE_DEVICE_TABLE and set the match_flag correctly */
@@ -226,5 +229,7 @@ int ccw_device_siosl(struct ccw_device *);
 // FIXME: these have to go
 extern int _ccw_device_get_subchannel_number(struct ccw_device *);
 
+extern void ccw_device_get_schid(struct ccw_device *, struct subchannel_id *);
+
 extern void *ccw_device_get_chp_desc(struct ccw_device *, int);
 #endif /* _S390_CCWDEV_H_ */
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index ec7fb6d..a93f4a0 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -763,6 +763,16 @@ _ccw_device_get_subchannel_number(struct ccw_device *cdev)
 	return cdev->private->schid.sch_no;
 }
 
+/**
+ * ccw_device_get_schid - obtain a subchannel id
+ * @cdev: device to obtain the id for
+ * @schid: where to fill in the values
+ */
+void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
+{
+	*schid = cdev->private->schid;
+}
+EXPORT_SYMBOL(ccw_device_get_schid);
 
 MODULE_LICENSE("GPL");
 EXPORT_SYMBOL(ccw_device_set_options_mask);
-- 
1.7.11.4

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

* [Qemu-devel] [PATCH 2/4] s390: Add a mechanism to get the subchannel id.
@ 2012-08-07 14:52   ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-07 14:52 UTC (permalink / raw)
  To: KVM, linux-s390, qemu-devel
  Cc: Carsten Otte, Anthony Liguori, Rusty Russell, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

This will be needed by the new virtio-ccw transport.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 arch/s390/include/asm/ccwdev.h |  5 +++++
 drivers/s390/cio/device_ops.c  | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/arch/s390/include/asm/ccwdev.h b/arch/s390/include/asm/ccwdev.h
index 1cb4bb3..9ad79f7 100644
--- a/arch/s390/include/asm/ccwdev.h
+++ b/arch/s390/include/asm/ccwdev.h
@@ -18,6 +18,9 @@ struct irb;
 struct ccw1;
 struct ccw_dev_id;
 
+/* from asm/schid.h */
+struct subchannel_id;
+
 /* simplified initializers for struct ccw_device:
  * CCW_DEVICE and CCW_DEVICE_DEVTYPE initialize one
  * entry in your MODULE_DEVICE_TABLE and set the match_flag correctly */
@@ -226,5 +229,7 @@ int ccw_device_siosl(struct ccw_device *);
 // FIXME: these have to go
 extern int _ccw_device_get_subchannel_number(struct ccw_device *);
 
+extern void ccw_device_get_schid(struct ccw_device *, struct subchannel_id *);
+
 extern void *ccw_device_get_chp_desc(struct ccw_device *, int);
 #endif /* _S390_CCWDEV_H_ */
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index ec7fb6d..a93f4a0 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -763,6 +763,16 @@ _ccw_device_get_subchannel_number(struct ccw_device *cdev)
 	return cdev->private->schid.sch_no;
 }
 
+/**
+ * ccw_device_get_schid - obtain a subchannel id
+ * @cdev: device to obtain the id for
+ * @schid: where to fill in the values
+ */
+void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
+{
+	*schid = cdev->private->schid;
+}
+EXPORT_SYMBOL(ccw_device_get_schid);
 
 MODULE_LICENSE("GPL");
 EXPORT_SYMBOL(ccw_device_set_options_mask);
-- 
1.7.11.4

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

* [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
  2012-08-07 14:52 ` [Qemu-devel] " Cornelia Huck
@ 2012-08-07 14:52   ` Cornelia Huck
  -1 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-07 14:52 UTC (permalink / raw)
  To: KVM, linux-s390, qemu-devel
  Cc: Avi Kivity, Marcelo Tosatti, Anthony Liguori, Rusty Russell,
	Christian Borntraeger, Carsten Otte, Alexander Graf,
	Heiko Carstens, Martin Schwidefsky, Sebastian Ott

Add a driver for kvm guests that matches virtual ccw devices provided
by the host as virtio bridge devices.

These virtio-ccw devices use a special set of channel commands in order
to perform virtio functions.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 arch/s390/include/asm/irq.h   |   1 +
 arch/s390/kernel/irq.c        |   1 +
 drivers/s390/kvm/Makefile     |   2 +-
 drivers/s390/kvm/virtio_ccw.c | 761 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 764 insertions(+), 1 deletion(-)
 create mode 100644 drivers/s390/kvm/virtio_ccw.c

diff --git a/arch/s390/include/asm/irq.h b/arch/s390/include/asm/irq.h
index 2b9d418..b4bea53 100644
--- a/arch/s390/include/asm/irq.h
+++ b/arch/s390/include/asm/irq.h
@@ -31,6 +31,7 @@ enum interruption_class {
 	IOINT_CTC,
 	IOINT_APB,
 	IOINT_CSC,
+	IOINT_VIR,
 	NMI_NMI,
 	NR_IRQS,
 };
diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
index dd7630d..2cc7eed 100644
--- a/arch/s390/kernel/irq.c
+++ b/arch/s390/kernel/irq.c
@@ -56,6 +56,7 @@ static const struct irq_class intrclass_names[] = {
 	{.name = "CTC", .desc = "[I/O] CTC" },
 	{.name = "APB", .desc = "[I/O] AP Bus" },
 	{.name = "CSC", .desc = "[I/O] CHSC Subchannel" },
+	{.name = "VIR", .desc = "[I/O] Virtual I/O Devices" },
 	{.name = "NMI", .desc = "[NMI] Machine Check" },
 };
 
diff --git a/drivers/s390/kvm/Makefile b/drivers/s390/kvm/Makefile
index 0815690..241891a 100644
--- a/drivers/s390/kvm/Makefile
+++ b/drivers/s390/kvm/Makefile
@@ -6,4 +6,4 @@
 # it under the terms of the GNU General Public License (version 2 only)
 # as published by the Free Software Foundation.
 
-obj-$(CONFIG_S390_GUEST) += kvm_virtio.o
+obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o
diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
new file mode 100644
index 0000000..df0f994
--- /dev/null
+++ b/drivers/s390/kvm/virtio_ccw.c
@@ -0,0 +1,761 @@
+/*
+ * ccw based virtio transport
+ *
+ * Copyright IBM Corp. 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *    Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
+ */
+
+#include <linux/kernel_stat.h>
+#include <linux/init.h>
+#include <linux/bootmem.h>
+#include <linux/err.h>
+#include <linux/virtio.h>
+#include <linux/virtio_config.h>
+#include <linux/slab.h>
+#include <linux/virtio_console.h>
+#include <linux/interrupt.h>
+#include <linux/virtio_ring.h>
+#include <linux/pfn.h>
+#include <linux/async.h>
+#include <linux/wait.h>
+#include <linux/list.h>
+#include <linux/bitops.h>
+#include <linux/module.h>
+#include <asm/io.h>
+#include <asm/kvm_para.h>
+#include <asm/setup.h>
+#include <asm/irq.h>
+#include <asm/cio.h>
+#include <asm/ccwdev.h>
+
+/*
+ * virtio related functions
+ */
+
+struct vq_config_block {
+	__u16 index;
+	__u16 num;
+} __attribute__ ((packed));
+
+#define VIRTIO_CCW_CONFIG_SIZE 0x100
+/* same as PCI config space size, should be enough for all drivers */
+
+struct virtio_ccw_device {
+	struct virtio_device vdev;
+	__u8 status;
+	__u8 config[VIRTIO_CCW_CONFIG_SIZE];
+	struct ccw_device *cdev;
+	struct ccw1 ccw;
+	__u32 area;
+	__u32 curr_io;
+	int err;
+	wait_queue_head_t wait_q;
+	spinlock_t lock;
+	struct list_head virtqueues;
+	unsigned long indicators; /* XXX - works because we're under 64 bit */
+	struct vq_config_block *config_block;
+};
+
+struct vq_info_block {
+	__u64 queue;
+	__u16 num;
+} __attribute__ ((packed));
+
+struct virtio_ccw_vq_info {
+	struct virtqueue *vq;
+	int num;
+	int queue_index;
+	void *queue;
+	struct vq_info_block *info_block;
+	struct list_head node;
+};
+
+#define KVM_VIRTIO_CCW_RING_ALIGN 4096
+
+#define CCW_CMD_SET_VQ 0x13
+#define CCW_CMD_VDEV_RESET 0x33
+#define CCW_CMD_SET_IND 0x43
+#define CCW_CMD_READ_FEAT 0x12
+#define CCW_CMD_WRITE_FEAT 0x11
+#define CCW_CMD_READ_CONF 0x22
+#define CCW_CMD_WRITE_CONF 0x21
+#define CCW_CMD_WRITE_STATUS 0x31
+#define CCW_CMD_READ_VQ_CONF 0x32
+
+#define VIRTIO_CCW_DOING_SET_VQ 0x00010000
+#define VIRTIO_CCW_DOING_RESET 0x00040000
+#define VIRTIO_CCW_DOING_READ_FEAT 0x00080000
+#define VIRTIO_CCW_DOING_WRITE_FEAT 0x00100000
+#define VIRTIO_CCW_DOING_READ_CONFIG 0x00200000
+#define VIRTIO_CCW_DOING_WRITE_CONFIG 0x00400000
+#define VIRTIO_CCW_DOING_WRITE_STATUS 0x00800000
+#define VIRTIO_CCW_DOING_SET_IND 0x01000000
+#define VIRTIO_CCW_DOING_READ_VQ_CONF 0x02000000
+#define VIRTIO_CCW_INTPARM_MASK 0xffff0000
+
+static struct virtio_ccw_device *to_vc_device(struct virtio_device *vdev)
+{
+	return container_of(vdev, struct virtio_ccw_device, vdev);
+}
+
+static int doing_io(struct virtio_ccw_device *vcdev, __u32 flag)
+{
+	unsigned long flags;
+	__u32 ret;
+
+	spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
+	if (vcdev->err)
+		ret = vcdev->err;
+	else
+		ret = vcdev->curr_io & flag;
+	spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
+	return ret;
+}
+
+static int ccw_io_helper(struct virtio_ccw_device *vcdev, __u32 intparm)
+{
+	int ret;
+	unsigned long flags;
+	int flag = intparm & VIRTIO_CCW_INTPARM_MASK;
+
+	spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
+	ret = ccw_device_start(vcdev->cdev, &vcdev->ccw, intparm, 0, 0);
+	if (!ret)
+		vcdev->curr_io |= flag;
+	spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
+	wait_event(vcdev->wait_q, doing_io(vcdev, flag) == 0);
+	return ret ? ret : vcdev->err;
+}
+
+static void virtio_ccw_kvm_notify(struct virtqueue *vq)
+{
+	struct virtio_ccw_vq_info *info = vq->priv;
+	struct virtio_ccw_device *vcdev;
+	struct subchannel_id schid;
+	__u32 reg2;
+
+	vcdev = to_vc_device(info->vq->vdev);
+	ccw_device_get_schid(vcdev->cdev, &schid);
+	reg2 = *(__u32 *)&schid;
+	kvm_hypercall2(3 /* CCW_NOTIFY */, reg2, info->queue_index);
+}
+
+static int virtio_ccw_read_vq_conf(struct virtio_ccw_device *vcdev, int index)
+{
+	vcdev->config_block->index = index;
+	vcdev->ccw.cmd_code = CCW_CMD_READ_VQ_CONF;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(struct vq_config_block);
+	vcdev->ccw.cda = (__u32)(unsigned long)(vcdev->config_block);
+	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_VQ_CONF);
+	return vcdev->config_block->num;
+}
+
+static void virtio_ccw_del_vq(struct virtqueue *vq)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev);
+	struct virtio_ccw_vq_info *info = vq->priv;
+	unsigned long flags;
+	unsigned long size;
+	int ret;
+
+	/* Remove from our list. */
+	spin_lock_irqsave(&vcdev->lock, flags);
+	list_del(&info->node);
+	spin_unlock_irqrestore(&vcdev->lock, flags);
+
+	/* Release from host. */
+	info->info_block->queue = 0;
+	info->info_block->num = info->queue_index;
+	vcdev->ccw.cmd_code = CCW_CMD_SET_VQ;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(*info->info_block);
+	vcdev->ccw.cda = (__u32)(unsigned long)(info->info_block);
+	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_VQ | info->queue_index);
+	if (ret)
+		dev_warn(&vq->vdev->dev, "Error %x while deleting queue %d",
+			 ret, info->queue_index);
+
+	vring_del_virtqueue(vq);
+	size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
+	free_pages_exact(info->queue, size);
+	kfree(info->info_block);
+	kfree(info);
+}
+
+static void virtio_ccw_del_vqs(struct virtio_device *vdev)
+{
+	struct virtqueue *vq, *n;
+
+	list_for_each_entry_safe(vq, n, &vdev->vqs, list)
+		virtio_ccw_del_vq(vq);
+}
+
+static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
+					     int i, vq_callback_t *callback,
+					     const char *name)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+	int err;
+	struct virtqueue *vq;
+	struct virtio_ccw_vq_info *info;
+	unsigned long size;
+	unsigned long flags;
+
+	/* Allocate queue. */
+	info = kzalloc(sizeof(struct virtio_ccw_vq_info), GFP_KERNEL);
+	if (!info) {
+		dev_warn(&vcdev->cdev->dev, "no info\n");
+		err = -ENOMEM;
+		goto out_err;
+	}
+	info->info_block = kzalloc(sizeof(*info->info_block),
+				   GFP_DMA | GFP_KERNEL);
+	if (!info->info_block) {
+		dev_warn(&vcdev->cdev->dev, "no info block\n");
+		err = -ENOMEM;
+		goto out_err;
+	}
+	info->queue_index = i;
+	info->num = virtio_ccw_read_vq_conf(vcdev, i);
+	size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
+	info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
+	if (info->queue == NULL) {
+		dev_warn(&vcdev->cdev->dev, "no queue\n");
+		err = -ENOMEM;
+		goto out_err;
+	}
+	vq = vring_new_virtqueue(info->num, KVM_VIRTIO_CCW_RING_ALIGN, vdev,
+				 true, info->queue, virtio_ccw_kvm_notify,
+				 callback, name);
+	if (!vq) {
+		dev_warn(&vcdev->cdev->dev, "no vq\n");
+		err = -ENOMEM;
+		free_pages_exact(info->queue, size);
+		goto out_err;
+	}
+	info->vq = vq;
+	vq->priv = info;
+
+	/* Register it with the host. */
+	info->info_block->queue = (__u64)info->queue;
+	info->info_block->num = info->queue_index;
+	vcdev->ccw.cmd_code = CCW_CMD_SET_VQ;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(*info->info_block);
+	vcdev->ccw.cda = (__u32)(unsigned long)(info->info_block);
+	err = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_VQ | info->queue_index);
+	if (err) {
+		dev_warn(&vcdev->cdev->dev, "SET_VQ failed\n");
+		free_pages_exact(info->queue, size);
+		info->vq = NULL;
+		vq->priv = NULL;
+		goto out_err;
+	}
+
+	/* Save it to our list. */
+	spin_lock_irqsave(&vcdev->lock, flags);
+	list_add(&info->node, &vcdev->virtqueues);
+	spin_unlock_irqrestore(&vcdev->lock, flags);
+
+	return vq;
+
+out_err:
+	if (info)
+		kfree(info->info_block);
+	kfree(info);
+	return ERR_PTR(err);
+}
+
+static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,
+			       struct virtqueue *vqs[],
+			       vq_callback_t *callbacks[],
+			       const char *names[])
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+	int ret, i;
+
+	for (i = 0; i < nvqs; ++i) {
+		vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i]);
+		if (IS_ERR(vqs[i])) {
+			ret = PTR_ERR(vqs[i]);
+			vqs[i] = NULL;
+			goto out;
+		}
+	}
+	/* Register queue indicators with host. */
+	vcdev->indicators = 0;
+	vcdev->ccw.cmd_code = CCW_CMD_SET_IND;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(vcdev->indicators);
+	vcdev->ccw.cda = (__u32)(unsigned long)(&vcdev->indicators);
+	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_IND);
+	if (ret)
+		goto out;
+	return 0;
+out:
+	virtio_ccw_del_vqs(vdev);
+	return ret;
+}
+
+static void virtio_ccw_reset(struct virtio_device *vdev)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+
+	/* Send a reset ccw on device. */
+	vcdev->ccw.cmd_code = CCW_CMD_VDEV_RESET;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = 0;
+	vcdev->ccw.cda = 0;
+	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_RESET);
+}
+
+static u32 virtio_ccw_get_features(struct virtio_device *vdev)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+	u32 features;
+	int ret;
+
+	/* Read the feature bits from the host. */
+	vcdev->ccw.cmd_code = CCW_CMD_READ_FEAT;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(features);
+	vcdev->ccw.cda = vcdev->area;
+	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_FEAT);
+	if (ret)
+		return 0;
+
+	memcpy(&features, (void *)(unsigned long)vcdev->area,
+	       sizeof(features));
+	return le32_to_cpu(features);
+}
+
+static void virtio_ccw_finalize_features(struct virtio_device *vdev)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+
+	/* Give virtio_ring a chance to accept features. */
+	vring_transport_features(vdev);
+
+	memcpy((void *)(unsigned long)vcdev->area, vdev->features,
+	       sizeof(*vdev->features));
+	/* Write the feature bits to the host. */
+	vcdev->ccw.cmd_code = CCW_CMD_WRITE_FEAT;
+	/* Sigh. The kernel's features may be longer than the host's. */
+	vcdev->ccw.flags = CCW_FLAG_SLI;
+	vcdev->ccw.count = sizeof(*vdev->features);
+	vcdev->ccw.cda = vcdev->area;
+	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_FEAT);
+}
+
+static void virtio_ccw_get_config(struct virtio_device *vdev,
+				  unsigned int offset, void *buf, unsigned len)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+	int ret;
+
+	/* Read the config area from the host. */
+	vcdev->ccw.cmd_code = CCW_CMD_READ_CONF;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = offset + len;
+	vcdev->ccw.cda = vcdev->area;
+	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_CONFIG);
+	if (ret)
+		return;
+
+	memcpy(vcdev->config, (void *)(unsigned long)vcdev->area,
+	       sizeof(vcdev->config));
+	memcpy(buf, &vcdev->config[offset], len);
+}
+
+static void virtio_ccw_set_config(struct virtio_device *vdev,
+				  unsigned int offset, const void *buf,
+				  unsigned len)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+
+	memcpy(&vcdev->config[offset], buf, len);
+	/* Write the config area to the host. */
+	memcpy((void *)(unsigned long)vcdev->area, vcdev->config,
+	       sizeof(vcdev->config));
+	vcdev->ccw.cmd_code = CCW_CMD_WRITE_CONF;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = offset + len;
+	vcdev->ccw.cda = vcdev->area;
+	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_CONFIG);
+}
+
+static u8 virtio_ccw_get_status(struct virtio_device *vdev)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+
+	return vcdev->status;
+}
+
+static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+
+	/* Write the status to the host. */
+	vcdev->status = status;
+	memcpy((void *)(unsigned long)vcdev->area, &status, sizeof(status));
+	vcdev->ccw.cmd_code = CCW_CMD_WRITE_STATUS;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(status);
+	vcdev->ccw.cda = vcdev->area;
+	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_STATUS);
+}
+
+static struct virtio_config_ops virtio_ccw_config_ops = {
+	.get_features = virtio_ccw_get_features,
+	.finalize_features = virtio_ccw_finalize_features,
+	.get = virtio_ccw_get_config,
+	.set = virtio_ccw_set_config,
+	.get_status = virtio_ccw_get_status,
+	.set_status = virtio_ccw_set_status,
+	.reset = virtio_ccw_reset,
+	.find_vqs = virtio_ccw_find_vqs,
+	.del_vqs = virtio_ccw_del_vqs,
+};
+
+
+/*
+ * ccw bus driver related functions
+ */
+
+static void virtio_ccw_release_dev(struct device *_d)
+{
+	struct virtio_device *dev = container_of(_d, struct virtio_device,
+						 dev);
+	struct virtio_ccw_device *vcdev = to_vc_device(dev);
+
+	kfree((void *)(unsigned long)vcdev->area);
+	kfree(vcdev->config_block);
+	kfree(vcdev);
+}
+
+static int irb_is_error(struct irb *irb)
+{
+	if (scsw_cstat(&irb->scsw) != 0)
+		return 1;
+	if (scsw_dstat(&irb->scsw) & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))
+		return 1;
+	if (scsw_cc(&irb->scsw) != 0)
+		return 1;
+	return 0;
+}
+
+static struct virtqueue *virtio_ccw_vq_by_ind(struct virtio_ccw_device *vcdev,
+					      int index)
+{
+	struct virtio_ccw_vq_info *info;
+	unsigned long flags;
+	struct virtqueue *vq;
+
+	vq = NULL;
+	spin_lock_irqsave(&vcdev->lock, flags);
+	list_for_each_entry(info, &vcdev->virtqueues, node) {
+		if (info->queue_index == index) {
+			vq = info->vq;
+			break;
+		}
+	}
+	spin_unlock_irqrestore(&vcdev->lock, flags);
+	return vq;
+}
+
+static void virtio_ccw_int_handler(struct ccw_device *cdev,
+				   unsigned long intparm,
+				   struct irb *irb)
+{
+	__u32 activity = intparm & VIRTIO_CCW_INTPARM_MASK;
+	struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
+	int i;
+	struct virtqueue *vq;
+
+	/* Check if it's a notification from the host. */
+	if ((intparm == 0) &&
+	    (scsw_stctl(&irb->scsw) ==
+	     (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))) {
+		/* OK */
+	}
+	if (irb_is_error(irb))
+		vcdev->err = -EIO; /* XXX - use real error */
+	if (vcdev->curr_io & activity) {
+		switch (activity) {
+		case VIRTIO_CCW_DOING_READ_FEAT:
+		case VIRTIO_CCW_DOING_WRITE_FEAT:
+		case VIRTIO_CCW_DOING_READ_CONFIG:
+		case VIRTIO_CCW_DOING_WRITE_CONFIG:
+		case VIRTIO_CCW_DOING_WRITE_STATUS:
+		case VIRTIO_CCW_DOING_SET_VQ:
+		case VIRTIO_CCW_DOING_SET_IND:
+		case VIRTIO_CCW_DOING_RESET:
+		case VIRTIO_CCW_DOING_READ_VQ_CONF:
+			vcdev->curr_io &= ~activity;
+			wake_up(&vcdev->wait_q);
+			break;
+		default:
+			/* don't know what to do... */
+			dev_warn(&cdev->dev, "Suspicious activity '%08x'\n",
+				 activity);
+			WARN_ON(1);
+			break;
+		}
+	}
+	for_each_set_bit(i, &vcdev->indicators,
+			 sizeof(vcdev->indicators)) {
+		vq = virtio_ccw_vq_by_ind(vcdev, i);
+		vring_interrupt(0, vq);
+		clear_bit(i, &vcdev->indicators);
+	}
+}
+
+/*
+ * We usually want to autoonline all devices, but give the admin
+ * a way to exempt devices from this.
+ */
+#define __DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
+		     (8*sizeof(long)))
+static unsigned long devs_no_auto[__MAX_SSID + 1][__DEV_WORDS];
+
+static char *no_auto = "";
+
+module_param(no_auto, charp, 0444);
+MODULE_PARM_DESC(no_auto, "list of ccw bus id ranges not to be auto-onlined");
+
+static int virtio_ccw_check_autoonline(struct ccw_device *cdev)
+{
+	struct ccw_dev_id id;
+
+	ccw_device_get_id(cdev, &id);
+	if (test_bit(id.devno, devs_no_auto[id.ssid]))
+		return 0;
+	return 1;
+}
+
+static void virtio_ccw_auto_online(void *data, async_cookie_t cookie)
+{
+	struct ccw_device *cdev = data;
+	int ret;
+
+	ret = ccw_device_set_online(cdev);
+	if (ret)
+		dev_warn(&cdev->dev, "Failed to set online: %d\n", ret);
+}
+
+static int virtio_ccw_probe(struct ccw_device *cdev)
+{
+	cdev->handler = virtio_ccw_int_handler;
+
+	if (virtio_ccw_check_autoonline(cdev))
+		async_schedule(virtio_ccw_auto_online, cdev);
+	return 0;
+}
+
+static void virtio_ccw_remove(struct ccw_device *cdev)
+{
+	cdev->handler = NULL;
+}
+
+static int virtio_ccw_offline(struct ccw_device *cdev)
+{
+	struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
+
+	unregister_virtio_device(&vcdev->vdev);
+	dev_set_drvdata(&cdev->dev, NULL);
+	return 0;
+}
+
+
+/* Area needs to be big enough to fit status, features or configuration. */
+#define VIRTIO_AREA_SIZE VIRTIO_CCW_CONFIG_SIZE /* biggest possible use */
+
+static int virtio_ccw_online(struct ccw_device *cdev)
+{
+	int ret;
+	struct virtio_ccw_device *vcdev;
+
+	vcdev = kzalloc(sizeof(*vcdev), GFP_KERNEL);
+	if (!vcdev) {
+		dev_warn(&cdev->dev, "Could not get memory for virtio\n");
+		ret = -ENOMEM;
+		goto out_free;
+	}
+	vcdev->area = (__u32)(unsigned long)kzalloc(VIRTIO_AREA_SIZE,
+						    GFP_DMA | GFP_KERNEL);
+	if (!vcdev->area) {
+		dev_warn(&cdev->dev, "Cound not get memory for virtio\n");
+		ret = -ENOMEM;
+		goto out_free;
+	}
+	vcdev->config_block = kzalloc(sizeof(*vcdev->config_block),
+				   GFP_DMA | GFP_KERNEL);
+	if (!vcdev->config_block) {
+		ret = -ENOMEM;
+		goto out_free;
+	}
+	vcdev->vdev.dev.parent = &cdev->dev;
+	vcdev->vdev.dev.release = virtio_ccw_release_dev;
+	vcdev->vdev.config = &virtio_ccw_config_ops;
+	vcdev->cdev = cdev;
+	init_waitqueue_head(&vcdev->wait_q);
+	INIT_LIST_HEAD(&vcdev->virtqueues);
+
+	dev_set_drvdata(&cdev->dev, vcdev);
+	vcdev->vdev.id.vendor = cdev->id.cu_type;
+	vcdev->vdev.id.device = cdev->id.cu_model;
+	ret = register_virtio_device(&vcdev->vdev);
+	if (ret) {
+		dev_warn(&cdev->dev, "Failed to register virtio device: %d\n",
+			 ret);
+		goto out_put;
+	}
+	return 0;
+out_put:
+	dev_set_drvdata(&cdev->dev, NULL);
+	put_device(&vcdev->vdev.dev);
+	return ret;
+out_free:
+	if (vcdev) {
+		kfree((void *)(unsigned long)vcdev->area);
+		kfree(vcdev->config_block);
+	}
+	kfree(vcdev);
+	return ret;
+}
+
+static int virtio_ccw_cio_notify(struct ccw_device *cdev, int event)
+{
+	/* TODO: Check whether we need special handling here. */
+	return 0;
+}
+
+static struct ccw_device_id virtio_ids[] = {
+	{ CCW_DEVICE(0x3832, 0) },
+	{},
+};
+MODULE_DEVICE_TABLE(ccw, virtio_ids);
+
+static struct ccw_driver virtio_ccw_driver = {
+	.driver = {
+		.owner = THIS_MODULE,
+		.name = "virtio_ccw",
+	},
+	.ids = virtio_ids,
+	.probe = virtio_ccw_probe,
+	.remove = virtio_ccw_remove,
+	.set_offline = virtio_ccw_offline,
+	.set_online = virtio_ccw_online,
+	.notify = virtio_ccw_cio_notify,
+	.int_class = IOINT_VIR,
+};
+
+static int __init pure_hex(char **cp, unsigned int *val, int min_digit,
+			   int max_digit, int max_val)
+{
+	int diff;
+
+	diff = 0;
+	*val = 0;
+
+	while (diff <= max_digit) {
+		int value = hex_to_bin(**cp);
+
+		if (value < 0)
+			break;
+		*val = *val * 16 + value;
+		(*cp)++;
+		diff++;
+	}
+
+	if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
+		return 1;
+
+	return 0;
+}
+
+static int __init parse_busid(char *str, unsigned int *cssid,
+			      unsigned int *ssid, unsigned int *devno)
+{
+	char *str_work;
+	int rc, ret;
+
+	rc = 1;
+
+	if (*str == '\0')
+		goto out;
+
+	str_work = str;
+	ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
+	if (ret || (str_work[0] != '.'))
+		goto out;
+	str_work++;
+	ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
+	if (ret || (str_work[0] != '.'))
+		goto out;
+	str_work++;
+	ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
+	if (ret || (str_work[0] != '\0'))
+		goto out;
+
+	rc = 0;
+out:
+	return rc;
+}
+
+static void __init no_auto_parse(void)
+{
+	unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
+	char *parm, *str;
+	int rc;
+
+	str = no_auto;
+	while ((parm = strsep(&str, ","))) {
+		rc = parse_busid(strsep(&parm, "-"), &from_cssid,
+				 &from_ssid, &from);
+		if (rc)
+			continue;
+		if (parm != NULL) {
+			rc = parse_busid(parm, &to_cssid,
+					 &to_ssid, &to);
+			if ((from_ssid > to_ssid) ||
+			    ((from_ssid == to_ssid) && (from > to)))
+				rc = -EINVAL;
+		} else {
+			to_cssid = from_cssid;
+			to_ssid = from_ssid;
+			to = from;
+		}
+		if (rc)
+			continue;
+		while ((from_ssid < to_ssid) ||
+		       ((from_ssid == to_ssid) && (from <= to))) {
+			set_bit(from, devs_no_auto[from_ssid]);
+			from++;
+			if (from > __MAX_SUBCHANNEL) {
+				from_ssid++;
+				from = 0;
+			}
+		}
+	}
+}
+
+static int __init virtio_ccw_init(void)
+{
+	/* parse no_auto string before we do anything further */
+	no_auto_parse();
+	return ccw_driver_register(&virtio_ccw_driver);
+}
+module_init(virtio_ccw_init);
+
+static void __exit virtio_ccw_exit(void)
+{
+	ccw_driver_unregister(&virtio_ccw_driver);
+}
+module_exit(virtio_ccw_exit);
-- 
1.7.11.4

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

* [Qemu-devel] [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
@ 2012-08-07 14:52   ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-07 14:52 UTC (permalink / raw)
  To: KVM, linux-s390, qemu-devel
  Cc: Carsten Otte, Anthony Liguori, Rusty Russell, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

Add a driver for kvm guests that matches virtual ccw devices provided
by the host as virtio bridge devices.

These virtio-ccw devices use a special set of channel commands in order
to perform virtio functions.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 arch/s390/include/asm/irq.h   |   1 +
 arch/s390/kernel/irq.c        |   1 +
 drivers/s390/kvm/Makefile     |   2 +-
 drivers/s390/kvm/virtio_ccw.c | 761 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 764 insertions(+), 1 deletion(-)
 create mode 100644 drivers/s390/kvm/virtio_ccw.c

diff --git a/arch/s390/include/asm/irq.h b/arch/s390/include/asm/irq.h
index 2b9d418..b4bea53 100644
--- a/arch/s390/include/asm/irq.h
+++ b/arch/s390/include/asm/irq.h
@@ -31,6 +31,7 @@ enum interruption_class {
 	IOINT_CTC,
 	IOINT_APB,
 	IOINT_CSC,
+	IOINT_VIR,
 	NMI_NMI,
 	NR_IRQS,
 };
diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
index dd7630d..2cc7eed 100644
--- a/arch/s390/kernel/irq.c
+++ b/arch/s390/kernel/irq.c
@@ -56,6 +56,7 @@ static const struct irq_class intrclass_names[] = {
 	{.name = "CTC", .desc = "[I/O] CTC" },
 	{.name = "APB", .desc = "[I/O] AP Bus" },
 	{.name = "CSC", .desc = "[I/O] CHSC Subchannel" },
+	{.name = "VIR", .desc = "[I/O] Virtual I/O Devices" },
 	{.name = "NMI", .desc = "[NMI] Machine Check" },
 };
 
diff --git a/drivers/s390/kvm/Makefile b/drivers/s390/kvm/Makefile
index 0815690..241891a 100644
--- a/drivers/s390/kvm/Makefile
+++ b/drivers/s390/kvm/Makefile
@@ -6,4 +6,4 @@
 # it under the terms of the GNU General Public License (version 2 only)
 # as published by the Free Software Foundation.
 
-obj-$(CONFIG_S390_GUEST) += kvm_virtio.o
+obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o
diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
new file mode 100644
index 0000000..df0f994
--- /dev/null
+++ b/drivers/s390/kvm/virtio_ccw.c
@@ -0,0 +1,761 @@
+/*
+ * ccw based virtio transport
+ *
+ * Copyright IBM Corp. 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *    Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
+ */
+
+#include <linux/kernel_stat.h>
+#include <linux/init.h>
+#include <linux/bootmem.h>
+#include <linux/err.h>
+#include <linux/virtio.h>
+#include <linux/virtio_config.h>
+#include <linux/slab.h>
+#include <linux/virtio_console.h>
+#include <linux/interrupt.h>
+#include <linux/virtio_ring.h>
+#include <linux/pfn.h>
+#include <linux/async.h>
+#include <linux/wait.h>
+#include <linux/list.h>
+#include <linux/bitops.h>
+#include <linux/module.h>
+#include <asm/io.h>
+#include <asm/kvm_para.h>
+#include <asm/setup.h>
+#include <asm/irq.h>
+#include <asm/cio.h>
+#include <asm/ccwdev.h>
+
+/*
+ * virtio related functions
+ */
+
+struct vq_config_block {
+	__u16 index;
+	__u16 num;
+} __attribute__ ((packed));
+
+#define VIRTIO_CCW_CONFIG_SIZE 0x100
+/* same as PCI config space size, should be enough for all drivers */
+
+struct virtio_ccw_device {
+	struct virtio_device vdev;
+	__u8 status;
+	__u8 config[VIRTIO_CCW_CONFIG_SIZE];
+	struct ccw_device *cdev;
+	struct ccw1 ccw;
+	__u32 area;
+	__u32 curr_io;
+	int err;
+	wait_queue_head_t wait_q;
+	spinlock_t lock;
+	struct list_head virtqueues;
+	unsigned long indicators; /* XXX - works because we're under 64 bit */
+	struct vq_config_block *config_block;
+};
+
+struct vq_info_block {
+	__u64 queue;
+	__u16 num;
+} __attribute__ ((packed));
+
+struct virtio_ccw_vq_info {
+	struct virtqueue *vq;
+	int num;
+	int queue_index;
+	void *queue;
+	struct vq_info_block *info_block;
+	struct list_head node;
+};
+
+#define KVM_VIRTIO_CCW_RING_ALIGN 4096
+
+#define CCW_CMD_SET_VQ 0x13
+#define CCW_CMD_VDEV_RESET 0x33
+#define CCW_CMD_SET_IND 0x43
+#define CCW_CMD_READ_FEAT 0x12
+#define CCW_CMD_WRITE_FEAT 0x11
+#define CCW_CMD_READ_CONF 0x22
+#define CCW_CMD_WRITE_CONF 0x21
+#define CCW_CMD_WRITE_STATUS 0x31
+#define CCW_CMD_READ_VQ_CONF 0x32
+
+#define VIRTIO_CCW_DOING_SET_VQ 0x00010000
+#define VIRTIO_CCW_DOING_RESET 0x00040000
+#define VIRTIO_CCW_DOING_READ_FEAT 0x00080000
+#define VIRTIO_CCW_DOING_WRITE_FEAT 0x00100000
+#define VIRTIO_CCW_DOING_READ_CONFIG 0x00200000
+#define VIRTIO_CCW_DOING_WRITE_CONFIG 0x00400000
+#define VIRTIO_CCW_DOING_WRITE_STATUS 0x00800000
+#define VIRTIO_CCW_DOING_SET_IND 0x01000000
+#define VIRTIO_CCW_DOING_READ_VQ_CONF 0x02000000
+#define VIRTIO_CCW_INTPARM_MASK 0xffff0000
+
+static struct virtio_ccw_device *to_vc_device(struct virtio_device *vdev)
+{
+	return container_of(vdev, struct virtio_ccw_device, vdev);
+}
+
+static int doing_io(struct virtio_ccw_device *vcdev, __u32 flag)
+{
+	unsigned long flags;
+	__u32 ret;
+
+	spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
+	if (vcdev->err)
+		ret = vcdev->err;
+	else
+		ret = vcdev->curr_io & flag;
+	spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
+	return ret;
+}
+
+static int ccw_io_helper(struct virtio_ccw_device *vcdev, __u32 intparm)
+{
+	int ret;
+	unsigned long flags;
+	int flag = intparm & VIRTIO_CCW_INTPARM_MASK;
+
+	spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
+	ret = ccw_device_start(vcdev->cdev, &vcdev->ccw, intparm, 0, 0);
+	if (!ret)
+		vcdev->curr_io |= flag;
+	spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
+	wait_event(vcdev->wait_q, doing_io(vcdev, flag) == 0);
+	return ret ? ret : vcdev->err;
+}
+
+static void virtio_ccw_kvm_notify(struct virtqueue *vq)
+{
+	struct virtio_ccw_vq_info *info = vq->priv;
+	struct virtio_ccw_device *vcdev;
+	struct subchannel_id schid;
+	__u32 reg2;
+
+	vcdev = to_vc_device(info->vq->vdev);
+	ccw_device_get_schid(vcdev->cdev, &schid);
+	reg2 = *(__u32 *)&schid;
+	kvm_hypercall2(3 /* CCW_NOTIFY */, reg2, info->queue_index);
+}
+
+static int virtio_ccw_read_vq_conf(struct virtio_ccw_device *vcdev, int index)
+{
+	vcdev->config_block->index = index;
+	vcdev->ccw.cmd_code = CCW_CMD_READ_VQ_CONF;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(struct vq_config_block);
+	vcdev->ccw.cda = (__u32)(unsigned long)(vcdev->config_block);
+	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_VQ_CONF);
+	return vcdev->config_block->num;
+}
+
+static void virtio_ccw_del_vq(struct virtqueue *vq)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev);
+	struct virtio_ccw_vq_info *info = vq->priv;
+	unsigned long flags;
+	unsigned long size;
+	int ret;
+
+	/* Remove from our list. */
+	spin_lock_irqsave(&vcdev->lock, flags);
+	list_del(&info->node);
+	spin_unlock_irqrestore(&vcdev->lock, flags);
+
+	/* Release from host. */
+	info->info_block->queue = 0;
+	info->info_block->num = info->queue_index;
+	vcdev->ccw.cmd_code = CCW_CMD_SET_VQ;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(*info->info_block);
+	vcdev->ccw.cda = (__u32)(unsigned long)(info->info_block);
+	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_VQ | info->queue_index);
+	if (ret)
+		dev_warn(&vq->vdev->dev, "Error %x while deleting queue %d",
+			 ret, info->queue_index);
+
+	vring_del_virtqueue(vq);
+	size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
+	free_pages_exact(info->queue, size);
+	kfree(info->info_block);
+	kfree(info);
+}
+
+static void virtio_ccw_del_vqs(struct virtio_device *vdev)
+{
+	struct virtqueue *vq, *n;
+
+	list_for_each_entry_safe(vq, n, &vdev->vqs, list)
+		virtio_ccw_del_vq(vq);
+}
+
+static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
+					     int i, vq_callback_t *callback,
+					     const char *name)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+	int err;
+	struct virtqueue *vq;
+	struct virtio_ccw_vq_info *info;
+	unsigned long size;
+	unsigned long flags;
+
+	/* Allocate queue. */
+	info = kzalloc(sizeof(struct virtio_ccw_vq_info), GFP_KERNEL);
+	if (!info) {
+		dev_warn(&vcdev->cdev->dev, "no info\n");
+		err = -ENOMEM;
+		goto out_err;
+	}
+	info->info_block = kzalloc(sizeof(*info->info_block),
+				   GFP_DMA | GFP_KERNEL);
+	if (!info->info_block) {
+		dev_warn(&vcdev->cdev->dev, "no info block\n");
+		err = -ENOMEM;
+		goto out_err;
+	}
+	info->queue_index = i;
+	info->num = virtio_ccw_read_vq_conf(vcdev, i);
+	size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
+	info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
+	if (info->queue == NULL) {
+		dev_warn(&vcdev->cdev->dev, "no queue\n");
+		err = -ENOMEM;
+		goto out_err;
+	}
+	vq = vring_new_virtqueue(info->num, KVM_VIRTIO_CCW_RING_ALIGN, vdev,
+				 true, info->queue, virtio_ccw_kvm_notify,
+				 callback, name);
+	if (!vq) {
+		dev_warn(&vcdev->cdev->dev, "no vq\n");
+		err = -ENOMEM;
+		free_pages_exact(info->queue, size);
+		goto out_err;
+	}
+	info->vq = vq;
+	vq->priv = info;
+
+	/* Register it with the host. */
+	info->info_block->queue = (__u64)info->queue;
+	info->info_block->num = info->queue_index;
+	vcdev->ccw.cmd_code = CCW_CMD_SET_VQ;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(*info->info_block);
+	vcdev->ccw.cda = (__u32)(unsigned long)(info->info_block);
+	err = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_VQ | info->queue_index);
+	if (err) {
+		dev_warn(&vcdev->cdev->dev, "SET_VQ failed\n");
+		free_pages_exact(info->queue, size);
+		info->vq = NULL;
+		vq->priv = NULL;
+		goto out_err;
+	}
+
+	/* Save it to our list. */
+	spin_lock_irqsave(&vcdev->lock, flags);
+	list_add(&info->node, &vcdev->virtqueues);
+	spin_unlock_irqrestore(&vcdev->lock, flags);
+
+	return vq;
+
+out_err:
+	if (info)
+		kfree(info->info_block);
+	kfree(info);
+	return ERR_PTR(err);
+}
+
+static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,
+			       struct virtqueue *vqs[],
+			       vq_callback_t *callbacks[],
+			       const char *names[])
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+	int ret, i;
+
+	for (i = 0; i < nvqs; ++i) {
+		vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i]);
+		if (IS_ERR(vqs[i])) {
+			ret = PTR_ERR(vqs[i]);
+			vqs[i] = NULL;
+			goto out;
+		}
+	}
+	/* Register queue indicators with host. */
+	vcdev->indicators = 0;
+	vcdev->ccw.cmd_code = CCW_CMD_SET_IND;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(vcdev->indicators);
+	vcdev->ccw.cda = (__u32)(unsigned long)(&vcdev->indicators);
+	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_IND);
+	if (ret)
+		goto out;
+	return 0;
+out:
+	virtio_ccw_del_vqs(vdev);
+	return ret;
+}
+
+static void virtio_ccw_reset(struct virtio_device *vdev)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+
+	/* Send a reset ccw on device. */
+	vcdev->ccw.cmd_code = CCW_CMD_VDEV_RESET;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = 0;
+	vcdev->ccw.cda = 0;
+	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_RESET);
+}
+
+static u32 virtio_ccw_get_features(struct virtio_device *vdev)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+	u32 features;
+	int ret;
+
+	/* Read the feature bits from the host. */
+	vcdev->ccw.cmd_code = CCW_CMD_READ_FEAT;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(features);
+	vcdev->ccw.cda = vcdev->area;
+	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_FEAT);
+	if (ret)
+		return 0;
+
+	memcpy(&features, (void *)(unsigned long)vcdev->area,
+	       sizeof(features));
+	return le32_to_cpu(features);
+}
+
+static void virtio_ccw_finalize_features(struct virtio_device *vdev)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+
+	/* Give virtio_ring a chance to accept features. */
+	vring_transport_features(vdev);
+
+	memcpy((void *)(unsigned long)vcdev->area, vdev->features,
+	       sizeof(*vdev->features));
+	/* Write the feature bits to the host. */
+	vcdev->ccw.cmd_code = CCW_CMD_WRITE_FEAT;
+	/* Sigh. The kernel's features may be longer than the host's. */
+	vcdev->ccw.flags = CCW_FLAG_SLI;
+	vcdev->ccw.count = sizeof(*vdev->features);
+	vcdev->ccw.cda = vcdev->area;
+	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_FEAT);
+}
+
+static void virtio_ccw_get_config(struct virtio_device *vdev,
+				  unsigned int offset, void *buf, unsigned len)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+	int ret;
+
+	/* Read the config area from the host. */
+	vcdev->ccw.cmd_code = CCW_CMD_READ_CONF;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = offset + len;
+	vcdev->ccw.cda = vcdev->area;
+	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_CONFIG);
+	if (ret)
+		return;
+
+	memcpy(vcdev->config, (void *)(unsigned long)vcdev->area,
+	       sizeof(vcdev->config));
+	memcpy(buf, &vcdev->config[offset], len);
+}
+
+static void virtio_ccw_set_config(struct virtio_device *vdev,
+				  unsigned int offset, const void *buf,
+				  unsigned len)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+
+	memcpy(&vcdev->config[offset], buf, len);
+	/* Write the config area to the host. */
+	memcpy((void *)(unsigned long)vcdev->area, vcdev->config,
+	       sizeof(vcdev->config));
+	vcdev->ccw.cmd_code = CCW_CMD_WRITE_CONF;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = offset + len;
+	vcdev->ccw.cda = vcdev->area;
+	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_CONFIG);
+}
+
+static u8 virtio_ccw_get_status(struct virtio_device *vdev)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+
+	return vcdev->status;
+}
+
+static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status)
+{
+	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
+
+	/* Write the status to the host. */
+	vcdev->status = status;
+	memcpy((void *)(unsigned long)vcdev->area, &status, sizeof(status));
+	vcdev->ccw.cmd_code = CCW_CMD_WRITE_STATUS;
+	vcdev->ccw.flags = 0;
+	vcdev->ccw.count = sizeof(status);
+	vcdev->ccw.cda = vcdev->area;
+	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_STATUS);
+}
+
+static struct virtio_config_ops virtio_ccw_config_ops = {
+	.get_features = virtio_ccw_get_features,
+	.finalize_features = virtio_ccw_finalize_features,
+	.get = virtio_ccw_get_config,
+	.set = virtio_ccw_set_config,
+	.get_status = virtio_ccw_get_status,
+	.set_status = virtio_ccw_set_status,
+	.reset = virtio_ccw_reset,
+	.find_vqs = virtio_ccw_find_vqs,
+	.del_vqs = virtio_ccw_del_vqs,
+};
+
+
+/*
+ * ccw bus driver related functions
+ */
+
+static void virtio_ccw_release_dev(struct device *_d)
+{
+	struct virtio_device *dev = container_of(_d, struct virtio_device,
+						 dev);
+	struct virtio_ccw_device *vcdev = to_vc_device(dev);
+
+	kfree((void *)(unsigned long)vcdev->area);
+	kfree(vcdev->config_block);
+	kfree(vcdev);
+}
+
+static int irb_is_error(struct irb *irb)
+{
+	if (scsw_cstat(&irb->scsw) != 0)
+		return 1;
+	if (scsw_dstat(&irb->scsw) & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))
+		return 1;
+	if (scsw_cc(&irb->scsw) != 0)
+		return 1;
+	return 0;
+}
+
+static struct virtqueue *virtio_ccw_vq_by_ind(struct virtio_ccw_device *vcdev,
+					      int index)
+{
+	struct virtio_ccw_vq_info *info;
+	unsigned long flags;
+	struct virtqueue *vq;
+
+	vq = NULL;
+	spin_lock_irqsave(&vcdev->lock, flags);
+	list_for_each_entry(info, &vcdev->virtqueues, node) {
+		if (info->queue_index == index) {
+			vq = info->vq;
+			break;
+		}
+	}
+	spin_unlock_irqrestore(&vcdev->lock, flags);
+	return vq;
+}
+
+static void virtio_ccw_int_handler(struct ccw_device *cdev,
+				   unsigned long intparm,
+				   struct irb *irb)
+{
+	__u32 activity = intparm & VIRTIO_CCW_INTPARM_MASK;
+	struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
+	int i;
+	struct virtqueue *vq;
+
+	/* Check if it's a notification from the host. */
+	if ((intparm == 0) &&
+	    (scsw_stctl(&irb->scsw) ==
+	     (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))) {
+		/* OK */
+	}
+	if (irb_is_error(irb))
+		vcdev->err = -EIO; /* XXX - use real error */
+	if (vcdev->curr_io & activity) {
+		switch (activity) {
+		case VIRTIO_CCW_DOING_READ_FEAT:
+		case VIRTIO_CCW_DOING_WRITE_FEAT:
+		case VIRTIO_CCW_DOING_READ_CONFIG:
+		case VIRTIO_CCW_DOING_WRITE_CONFIG:
+		case VIRTIO_CCW_DOING_WRITE_STATUS:
+		case VIRTIO_CCW_DOING_SET_VQ:
+		case VIRTIO_CCW_DOING_SET_IND:
+		case VIRTIO_CCW_DOING_RESET:
+		case VIRTIO_CCW_DOING_READ_VQ_CONF:
+			vcdev->curr_io &= ~activity;
+			wake_up(&vcdev->wait_q);
+			break;
+		default:
+			/* don't know what to do... */
+			dev_warn(&cdev->dev, "Suspicious activity '%08x'\n",
+				 activity);
+			WARN_ON(1);
+			break;
+		}
+	}
+	for_each_set_bit(i, &vcdev->indicators,
+			 sizeof(vcdev->indicators)) {
+		vq = virtio_ccw_vq_by_ind(vcdev, i);
+		vring_interrupt(0, vq);
+		clear_bit(i, &vcdev->indicators);
+	}
+}
+
+/*
+ * We usually want to autoonline all devices, but give the admin
+ * a way to exempt devices from this.
+ */
+#define __DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
+		     (8*sizeof(long)))
+static unsigned long devs_no_auto[__MAX_SSID + 1][__DEV_WORDS];
+
+static char *no_auto = "";
+
+module_param(no_auto, charp, 0444);
+MODULE_PARM_DESC(no_auto, "list of ccw bus id ranges not to be auto-onlined");
+
+static int virtio_ccw_check_autoonline(struct ccw_device *cdev)
+{
+	struct ccw_dev_id id;
+
+	ccw_device_get_id(cdev, &id);
+	if (test_bit(id.devno, devs_no_auto[id.ssid]))
+		return 0;
+	return 1;
+}
+
+static void virtio_ccw_auto_online(void *data, async_cookie_t cookie)
+{
+	struct ccw_device *cdev = data;
+	int ret;
+
+	ret = ccw_device_set_online(cdev);
+	if (ret)
+		dev_warn(&cdev->dev, "Failed to set online: %d\n", ret);
+}
+
+static int virtio_ccw_probe(struct ccw_device *cdev)
+{
+	cdev->handler = virtio_ccw_int_handler;
+
+	if (virtio_ccw_check_autoonline(cdev))
+		async_schedule(virtio_ccw_auto_online, cdev);
+	return 0;
+}
+
+static void virtio_ccw_remove(struct ccw_device *cdev)
+{
+	cdev->handler = NULL;
+}
+
+static int virtio_ccw_offline(struct ccw_device *cdev)
+{
+	struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
+
+	unregister_virtio_device(&vcdev->vdev);
+	dev_set_drvdata(&cdev->dev, NULL);
+	return 0;
+}
+
+
+/* Area needs to be big enough to fit status, features or configuration. */
+#define VIRTIO_AREA_SIZE VIRTIO_CCW_CONFIG_SIZE /* biggest possible use */
+
+static int virtio_ccw_online(struct ccw_device *cdev)
+{
+	int ret;
+	struct virtio_ccw_device *vcdev;
+
+	vcdev = kzalloc(sizeof(*vcdev), GFP_KERNEL);
+	if (!vcdev) {
+		dev_warn(&cdev->dev, "Could not get memory for virtio\n");
+		ret = -ENOMEM;
+		goto out_free;
+	}
+	vcdev->area = (__u32)(unsigned long)kzalloc(VIRTIO_AREA_SIZE,
+						    GFP_DMA | GFP_KERNEL);
+	if (!vcdev->area) {
+		dev_warn(&cdev->dev, "Cound not get memory for virtio\n");
+		ret = -ENOMEM;
+		goto out_free;
+	}
+	vcdev->config_block = kzalloc(sizeof(*vcdev->config_block),
+				   GFP_DMA | GFP_KERNEL);
+	if (!vcdev->config_block) {
+		ret = -ENOMEM;
+		goto out_free;
+	}
+	vcdev->vdev.dev.parent = &cdev->dev;
+	vcdev->vdev.dev.release = virtio_ccw_release_dev;
+	vcdev->vdev.config = &virtio_ccw_config_ops;
+	vcdev->cdev = cdev;
+	init_waitqueue_head(&vcdev->wait_q);
+	INIT_LIST_HEAD(&vcdev->virtqueues);
+
+	dev_set_drvdata(&cdev->dev, vcdev);
+	vcdev->vdev.id.vendor = cdev->id.cu_type;
+	vcdev->vdev.id.device = cdev->id.cu_model;
+	ret = register_virtio_device(&vcdev->vdev);
+	if (ret) {
+		dev_warn(&cdev->dev, "Failed to register virtio device: %d\n",
+			 ret);
+		goto out_put;
+	}
+	return 0;
+out_put:
+	dev_set_drvdata(&cdev->dev, NULL);
+	put_device(&vcdev->vdev.dev);
+	return ret;
+out_free:
+	if (vcdev) {
+		kfree((void *)(unsigned long)vcdev->area);
+		kfree(vcdev->config_block);
+	}
+	kfree(vcdev);
+	return ret;
+}
+
+static int virtio_ccw_cio_notify(struct ccw_device *cdev, int event)
+{
+	/* TODO: Check whether we need special handling here. */
+	return 0;
+}
+
+static struct ccw_device_id virtio_ids[] = {
+	{ CCW_DEVICE(0x3832, 0) },
+	{},
+};
+MODULE_DEVICE_TABLE(ccw, virtio_ids);
+
+static struct ccw_driver virtio_ccw_driver = {
+	.driver = {
+		.owner = THIS_MODULE,
+		.name = "virtio_ccw",
+	},
+	.ids = virtio_ids,
+	.probe = virtio_ccw_probe,
+	.remove = virtio_ccw_remove,
+	.set_offline = virtio_ccw_offline,
+	.set_online = virtio_ccw_online,
+	.notify = virtio_ccw_cio_notify,
+	.int_class = IOINT_VIR,
+};
+
+static int __init pure_hex(char **cp, unsigned int *val, int min_digit,
+			   int max_digit, int max_val)
+{
+	int diff;
+
+	diff = 0;
+	*val = 0;
+
+	while (diff <= max_digit) {
+		int value = hex_to_bin(**cp);
+
+		if (value < 0)
+			break;
+		*val = *val * 16 + value;
+		(*cp)++;
+		diff++;
+	}
+
+	if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
+		return 1;
+
+	return 0;
+}
+
+static int __init parse_busid(char *str, unsigned int *cssid,
+			      unsigned int *ssid, unsigned int *devno)
+{
+	char *str_work;
+	int rc, ret;
+
+	rc = 1;
+
+	if (*str == '\0')
+		goto out;
+
+	str_work = str;
+	ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
+	if (ret || (str_work[0] != '.'))
+		goto out;
+	str_work++;
+	ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
+	if (ret || (str_work[0] != '.'))
+		goto out;
+	str_work++;
+	ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
+	if (ret || (str_work[0] != '\0'))
+		goto out;
+
+	rc = 0;
+out:
+	return rc;
+}
+
+static void __init no_auto_parse(void)
+{
+	unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
+	char *parm, *str;
+	int rc;
+
+	str = no_auto;
+	while ((parm = strsep(&str, ","))) {
+		rc = parse_busid(strsep(&parm, "-"), &from_cssid,
+				 &from_ssid, &from);
+		if (rc)
+			continue;
+		if (parm != NULL) {
+			rc = parse_busid(parm, &to_cssid,
+					 &to_ssid, &to);
+			if ((from_ssid > to_ssid) ||
+			    ((from_ssid == to_ssid) && (from > to)))
+				rc = -EINVAL;
+		} else {
+			to_cssid = from_cssid;
+			to_ssid = from_ssid;
+			to = from;
+		}
+		if (rc)
+			continue;
+		while ((from_ssid < to_ssid) ||
+		       ((from_ssid == to_ssid) && (from <= to))) {
+			set_bit(from, devs_no_auto[from_ssid]);
+			from++;
+			if (from > __MAX_SUBCHANNEL) {
+				from_ssid++;
+				from = 0;
+			}
+		}
+	}
+}
+
+static int __init virtio_ccw_init(void)
+{
+	/* parse no_auto string before we do anything further */
+	no_auto_parse();
+	return ccw_driver_register(&virtio_ccw_driver);
+}
+module_init(virtio_ccw_init);
+
+static void __exit virtio_ccw_exit(void)
+{
+	ccw_driver_unregister(&virtio_ccw_driver);
+}
+module_exit(virtio_ccw_exit);
-- 
1.7.11.4

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

* [PATCH 4/4] s390/kvm: Split out early console code.
  2012-08-07 14:52 ` [Qemu-devel] " Cornelia Huck
@ 2012-08-07 14:52   ` Cornelia Huck
  -1 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-07 14:52 UTC (permalink / raw)
  To: KVM, linux-s390, qemu-devel
  Cc: Avi Kivity, Marcelo Tosatti, Anthony Liguori, Rusty Russell,
	Christian Borntraeger, Carsten Otte, Alexander Graf,
	Heiko Carstens, Martin Schwidefsky, Sebastian Ott

This code is transport agnostic and can be used by both the legacy
virtio code and virtio_ccw.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 drivers/s390/kvm/Makefile       |  2 +-
 drivers/s390/kvm/early_printk.c | 42 +++++++++++++++++++++++++++++++++++++++++
 drivers/s390/kvm/kvm_virtio.c   | 29 ++--------------------------
 drivers/s390/kvm/virtio_ccw.c   |  1 -
 4 files changed, 45 insertions(+), 29 deletions(-)
 create mode 100644 drivers/s390/kvm/early_printk.c

diff --git a/drivers/s390/kvm/Makefile b/drivers/s390/kvm/Makefile
index 241891a..a3c8fc4 100644
--- a/drivers/s390/kvm/Makefile
+++ b/drivers/s390/kvm/Makefile
@@ -6,4 +6,4 @@
 # it under the terms of the GNU General Public License (version 2 only)
 # as published by the Free Software Foundation.
 
-obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o
+obj-$(CONFIG_S390_GUEST) += kvm_virtio.o early_printk.o virtio_ccw.o
diff --git a/drivers/s390/kvm/early_printk.c b/drivers/s390/kvm/early_printk.c
new file mode 100644
index 0000000..7831530
--- /dev/null
+++ b/drivers/s390/kvm/early_printk.c
@@ -0,0 +1,42 @@
+/*
+ * early_printk.c - code for early console output with virtio_console
+ * split off from kvm_virtio.c
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *    Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
+ */
+
+#include <linux/kernel_stat.h>
+#include <linux/init.h>
+#include <linux/err.h>
+#include <linux/virtio_console.h>
+#include <asm/kvm_para.h>
+#include <asm/kvm_virtio.h>
+#include <asm/setup.h>
+#include <asm/sclp.h>
+
+static __init int early_put_chars(u32 vtermno, const char *buf, int count)
+{
+	char scratch[17];
+	unsigned int len = count;
+
+	if (len > sizeof(scratch) - 1)
+		len = sizeof(scratch) - 1;
+	scratch[len] = '\0';
+	memcpy(scratch, buf, len);
+	kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, __pa(scratch));
+	return len;
+}
+
+static int __init s390_virtio_console_init(void)
+{
+	if (sclp_has_vt220() || sclp_has_linemode())
+		return -ENODEV;
+	return virtio_cons_early_init(early_put_chars);
+}
+console_initcall(s390_virtio_console_init);
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 408447c..c693548 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -17,7 +17,6 @@
 #include <linux/virtio.h>
 #include <linux/virtio_config.h>
 #include <linux/slab.h>
-#include <linux/virtio_console.h>
 #include <linux/interrupt.h>
 #include <linux/virtio_ring.h>
 #include <linux/export.h>
@@ -25,9 +24,9 @@
 #include <asm/io.h>
 #include <asm/kvm_para.h>
 #include <asm/kvm_virtio.h>
-#include <asm/sclp.h>
 #include <asm/setup.h>
 #include <asm/irq.h>
+#include <asm/sclp.h>
 
 #define VIRTIO_SUBCODE_64 0x0D00
 
@@ -461,8 +460,7 @@ static int __init kvm_devices_init(void)
 	if (test_devices_support() < 0) {
 		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
 		root_device_unregister(kvm_root);
-		/* No error. */
-		return 0;
+		return -ENODEV;
 	}
 
 	INIT_WORK(&hotplug_work, hotplug_devices);
@@ -474,29 +472,6 @@ static int __init kvm_devices_init(void)
 	return 0;
 }
 
-/* code for early console output with virtio_console */
-static __init int early_put_chars(u32 vtermno, const char *buf, int count)
-{
-	char scratch[17];
-	unsigned int len = count;
-
-	if (len > sizeof(scratch) - 1)
-		len = sizeof(scratch) - 1;
-	scratch[len] = '\0';
-	memcpy(scratch, buf, len);
-	kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, __pa(scratch));
-	return len;
-}
-
-static int __init s390_virtio_console_init(void)
-{
-	if (sclp_has_vt220() || sclp_has_linemode())
-		return -ENODEV;
-	return virtio_cons_early_init(early_put_chars);
-}
-console_initcall(s390_virtio_console_init);
-
-
 /*
  * We do this after core stuff, but before the drivers.
  */
diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
index df0f994..c3d07db 100644
--- a/drivers/s390/kvm/virtio_ccw.c
+++ b/drivers/s390/kvm/virtio_ccw.c
@@ -17,7 +17,6 @@
 #include <linux/virtio.h>
 #include <linux/virtio_config.h>
 #include <linux/slab.h>
-#include <linux/virtio_console.h>
 #include <linux/interrupt.h>
 #include <linux/virtio_ring.h>
 #include <linux/pfn.h>
-- 
1.7.11.4

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

* [Qemu-devel] [PATCH 4/4] s390/kvm: Split out early console code.
@ 2012-08-07 14:52   ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-07 14:52 UTC (permalink / raw)
  To: KVM, linux-s390, qemu-devel
  Cc: Carsten Otte, Anthony Liguori, Rusty Russell, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

This code is transport agnostic and can be used by both the legacy
virtio code and virtio_ccw.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 drivers/s390/kvm/Makefile       |  2 +-
 drivers/s390/kvm/early_printk.c | 42 +++++++++++++++++++++++++++++++++++++++++
 drivers/s390/kvm/kvm_virtio.c   | 29 ++--------------------------
 drivers/s390/kvm/virtio_ccw.c   |  1 -
 4 files changed, 45 insertions(+), 29 deletions(-)
 create mode 100644 drivers/s390/kvm/early_printk.c

diff --git a/drivers/s390/kvm/Makefile b/drivers/s390/kvm/Makefile
index 241891a..a3c8fc4 100644
--- a/drivers/s390/kvm/Makefile
+++ b/drivers/s390/kvm/Makefile
@@ -6,4 +6,4 @@
 # it under the terms of the GNU General Public License (version 2 only)
 # as published by the Free Software Foundation.
 
-obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o
+obj-$(CONFIG_S390_GUEST) += kvm_virtio.o early_printk.o virtio_ccw.o
diff --git a/drivers/s390/kvm/early_printk.c b/drivers/s390/kvm/early_printk.c
new file mode 100644
index 0000000..7831530
--- /dev/null
+++ b/drivers/s390/kvm/early_printk.c
@@ -0,0 +1,42 @@
+/*
+ * early_printk.c - code for early console output with virtio_console
+ * split off from kvm_virtio.c
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *    Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
+ */
+
+#include <linux/kernel_stat.h>
+#include <linux/init.h>
+#include <linux/err.h>
+#include <linux/virtio_console.h>
+#include <asm/kvm_para.h>
+#include <asm/kvm_virtio.h>
+#include <asm/setup.h>
+#include <asm/sclp.h>
+
+static __init int early_put_chars(u32 vtermno, const char *buf, int count)
+{
+	char scratch[17];
+	unsigned int len = count;
+
+	if (len > sizeof(scratch) - 1)
+		len = sizeof(scratch) - 1;
+	scratch[len] = '\0';
+	memcpy(scratch, buf, len);
+	kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, __pa(scratch));
+	return len;
+}
+
+static int __init s390_virtio_console_init(void)
+{
+	if (sclp_has_vt220() || sclp_has_linemode())
+		return -ENODEV;
+	return virtio_cons_early_init(early_put_chars);
+}
+console_initcall(s390_virtio_console_init);
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 408447c..c693548 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -17,7 +17,6 @@
 #include <linux/virtio.h>
 #include <linux/virtio_config.h>
 #include <linux/slab.h>
-#include <linux/virtio_console.h>
 #include <linux/interrupt.h>
 #include <linux/virtio_ring.h>
 #include <linux/export.h>
@@ -25,9 +24,9 @@
 #include <asm/io.h>
 #include <asm/kvm_para.h>
 #include <asm/kvm_virtio.h>
-#include <asm/sclp.h>
 #include <asm/setup.h>
 #include <asm/irq.h>
+#include <asm/sclp.h>
 
 #define VIRTIO_SUBCODE_64 0x0D00
 
@@ -461,8 +460,7 @@ static int __init kvm_devices_init(void)
 	if (test_devices_support() < 0) {
 		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
 		root_device_unregister(kvm_root);
-		/* No error. */
-		return 0;
+		return -ENODEV;
 	}
 
 	INIT_WORK(&hotplug_work, hotplug_devices);
@@ -474,29 +472,6 @@ static int __init kvm_devices_init(void)
 	return 0;
 }
 
-/* code for early console output with virtio_console */
-static __init int early_put_chars(u32 vtermno, const char *buf, int count)
-{
-	char scratch[17];
-	unsigned int len = count;
-
-	if (len > sizeof(scratch) - 1)
-		len = sizeof(scratch) - 1;
-	scratch[len] = '\0';
-	memcpy(scratch, buf, len);
-	kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, __pa(scratch));
-	return len;
-}
-
-static int __init s390_virtio_console_init(void)
-{
-	if (sclp_has_vt220() || sclp_has_linemode())
-		return -ENODEV;
-	return virtio_cons_early_init(early_put_chars);
-}
-console_initcall(s390_virtio_console_init);
-
-
 /*
  * We do this after core stuff, but before the drivers.
  */
diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
index df0f994..c3d07db 100644
--- a/drivers/s390/kvm/virtio_ccw.c
+++ b/drivers/s390/kvm/virtio_ccw.c
@@ -17,7 +17,6 @@
 #include <linux/virtio.h>
 #include <linux/virtio_config.h>
 #include <linux/slab.h>
-#include <linux/virtio_console.h>
 #include <linux/interrupt.h>
 #include <linux/virtio_ring.h>
 #include <linux/pfn.h>
-- 
1.7.11.4

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

* Re: [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
  2012-08-07 14:52   ` [Qemu-devel] " Cornelia Huck
@ 2012-08-08  4:22     ` Rusty Russell
  -1 siblings, 0 replies; 48+ messages in thread
From: Rusty Russell @ 2012-08-08  4:22 UTC (permalink / raw)
  To: Cornelia Huck, KVM, linux-s390, qemu-devel
  Cc: Carsten Otte, Anthony Liguori, Sebastian Ott, Marcelo Tosatti,
	Heiko Carstens, Alexander Graf, Christian Borntraeger,
	Avi Kivity, Martin Schwidefsky

On Tue,  7 Aug 2012 16:52:47 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> Add a driver for kvm guests that matches virtual ccw devices provided
> by the host as virtio bridge devices.

Hi Cornelia,

        OK, this is a good opportunity to fix some limitations, just as
we did for virtio_mmio (drivers/virtio/virtio_mmio.c).

1) Please don't limit yourself to 32 feature bits!  If you look at how
   virtio_mmio does it, they use a selector to index into a
   theoretically-infinite array of feature bits:

 * 0x010  R  HostFeatures     Features supported by the host
 * 0x014  W  HostFeaturesSel  Set of host features to access via HostFeatures
 *
 * 0x020  W  GuestFeatures    Features activated by the guest
 * 0x024  W  GuestFeaturesSel Set of activated features to set via GuestFeatures

2) Please also allow the guest to set the alignment for virtio ring
   layout (it controls the spacing between the rings), eg:

 * 0x03c  W  QueueAlign       Used Ring alignment for the current queue

3) Finally, make sure the guest can set the size of the queue, in case
   it can't allocate the size the host suggests, eg:

 * 0x034  R  QueueNumMax      Maximum size of the currently selected queue
 * 0x038  W  QueueNum         Queue size for the currently selected queue

   This means the host can suggest huge queues, knowing the guest won't
   simply fail if it does so.

Note that we're also speculating a move to a new vring format, which
will probably be little-endian.  But you probably want a completely new
ccw code for that anyway.

Cheers,
Rusty.

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

* Re: [Qemu-devel] [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
@ 2012-08-08  4:22     ` Rusty Russell
  0 siblings, 0 replies; 48+ messages in thread
From: Rusty Russell @ 2012-08-08  4:22 UTC (permalink / raw)
  To: Cornelia Huck, KVM, linux-s390, qemu-devel
  Cc: Carsten Otte, Anthony Liguori, Sebastian Ott, Marcelo Tosatti,
	Heiko Carstens, Alexander Graf, Christian Borntraeger,
	Avi Kivity, Martin Schwidefsky

On Tue,  7 Aug 2012 16:52:47 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> Add a driver for kvm guests that matches virtual ccw devices provided
> by the host as virtio bridge devices.

Hi Cornelia,

        OK, this is a good opportunity to fix some limitations, just as
we did for virtio_mmio (drivers/virtio/virtio_mmio.c).

1) Please don't limit yourself to 32 feature bits!  If you look at how
   virtio_mmio does it, they use a selector to index into a
   theoretically-infinite array of feature bits:

 * 0x010  R  HostFeatures     Features supported by the host
 * 0x014  W  HostFeaturesSel  Set of host features to access via HostFeatures
 *
 * 0x020  W  GuestFeatures    Features activated by the guest
 * 0x024  W  GuestFeaturesSel Set of activated features to set via GuestFeatures

2) Please also allow the guest to set the alignment for virtio ring
   layout (it controls the spacing between the rings), eg:

 * 0x03c  W  QueueAlign       Used Ring alignment for the current queue

3) Finally, make sure the guest can set the size of the queue, in case
   it can't allocate the size the host suggests, eg:

 * 0x034  R  QueueNumMax      Maximum size of the currently selected queue
 * 0x038  W  QueueNum         Queue size for the currently selected queue

   This means the host can suggest huge queues, knowing the guest won't
   simply fail if it does so.

Note that we're also speculating a move to a new vring format, which
will probably be little-endian.  But you probably want a completely new
ccw code for that anyway.

Cheers,
Rusty.

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

* Re: [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
  2012-08-07 14:52   ` [Qemu-devel] " Cornelia Huck
@ 2012-08-09 10:03     ` Avi Kivity
  -1 siblings, 0 replies; 48+ messages in thread
From: Avi Kivity @ 2012-08-09 10:03 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Sebastian Ott, Marcelo Tosatti, Heiko Carstens, qemu-devel,
	Alexander Graf, Christian Borntraeger, Martin Schwidefsky

On 08/07/2012 05:52 PM, Cornelia Huck wrote:
> Running under a kvm host does not necessarily imply the presence of
> a page mapped above the main memory with the virtio information;
> however, the code includes a hard coded access to that page.
> 
> Instead, check for the presence of the page and exit gracefully
> before we hit an addressing exception if it does not exist.
> 
>  /*
>   * Init function for virtio
>   * devices are in a single page above top of "normal" mem
> @@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
>  	}
>  
>  	kvm_devices = (void *) real_memory_size;
> +	if (test_devices_support() < 0) {
> +		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
> +		root_device_unregister(kvm_root);
> +		/* No error. */
> +		return 0;
> +	}
>  

Cleaner to defer root_device_register() until after the mapping has been
verified.


-- 
error compiling committee.c: too many arguments to function

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

* Re: [Qemu-devel] [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
@ 2012-08-09 10:03     ` Avi Kivity
  0 siblings, 0 replies; 48+ messages in thread
From: Avi Kivity @ 2012-08-09 10:03 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Sebastian Ott, Marcelo Tosatti, Heiko Carstens, qemu-devel,
	Alexander Graf, Christian Borntraeger, Martin Schwidefsky

On 08/07/2012 05:52 PM, Cornelia Huck wrote:
> Running under a kvm host does not necessarily imply the presence of
> a page mapped above the main memory with the virtio information;
> however, the code includes a hard coded access to that page.
> 
> Instead, check for the presence of the page and exit gracefully
> before we hit an addressing exception if it does not exist.
> 
>  /*
>   * Init function for virtio
>   * devices are in a single page above top of "normal" mem
> @@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
>  	}
>  
>  	kvm_devices = (void *) real_memory_size;
> +	if (test_devices_support() < 0) {
> +		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
> +		root_device_unregister(kvm_root);
> +		/* No error. */
> +		return 0;
> +	}
>  

Cleaner to defer root_device_register() until after the mapping has been
verified.


-- 
error compiling committee.c: too many arguments to function

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

* Re: [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
  2012-08-09 10:03     ` [Qemu-devel] " Avi Kivity
@ 2012-08-09 10:41       ` Cornelia Huck
  -1 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-09 10:41 UTC (permalink / raw)
  To: Avi Kivity
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Sebastian Ott, Marcelo Tosatti, Heiko Carstens, qemu-devel,
	Alexander Graf, Christian Borntraeger, Martin Schwidefsky

On Thu, 09 Aug 2012 13:03:57 +0300
Avi Kivity <avi@redhat.com> wrote:

> On 08/07/2012 05:52 PM, Cornelia Huck wrote:
> > Running under a kvm host does not necessarily imply the presence of
> > a page mapped above the main memory with the virtio information;
> > however, the code includes a hard coded access to that page.
> > 
> > Instead, check for the presence of the page and exit gracefully
> > before we hit an addressing exception if it does not exist.
> > 
> >  /*
> >   * Init function for virtio
> >   * devices are in a single page above top of "normal" mem
> > @@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
> >  	}
> >  
> >  	kvm_devices = (void *) real_memory_size;
> > +	if (test_devices_support() < 0) {
> > +		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
> > +		root_device_unregister(kvm_root);
> > +		/* No error. */
> > +		return 0;
> > +	}
> >  
> 
> Cleaner to defer root_device_register() until after the mapping has been
> verified.

OK, will reorder.

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

* Re: [Qemu-devel] [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
@ 2012-08-09 10:41       ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-09 10:41 UTC (permalink / raw)
  To: Avi Kivity
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Sebastian Ott, Marcelo Tosatti, Heiko Carstens, qemu-devel,
	Alexander Graf, Christian Borntraeger, Martin Schwidefsky

On Thu, 09 Aug 2012 13:03:57 +0300
Avi Kivity <avi@redhat.com> wrote:

> On 08/07/2012 05:52 PM, Cornelia Huck wrote:
> > Running under a kvm host does not necessarily imply the presence of
> > a page mapped above the main memory with the virtio information;
> > however, the code includes a hard coded access to that page.
> > 
> > Instead, check for the presence of the page and exit gracefully
> > before we hit an addressing exception if it does not exist.
> > 
> >  /*
> >   * Init function for virtio
> >   * devices are in a single page above top of "normal" mem
> > @@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
> >  	}
> >  
> >  	kvm_devices = (void *) real_memory_size;
> > +	if (test_devices_support() < 0) {
> > +		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
> > +		root_device_unregister(kvm_root);
> > +		/* No error. */
> > +		return 0;
> > +	}
> >  
> 
> Cleaner to defer root_device_register() until after the mapping has been
> verified.

OK, will reorder.

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

* Re: [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
  2012-08-07 14:52   ` [Qemu-devel] " Cornelia Huck
@ 2012-08-09 23:09     ` Alexander Graf
  -1 siblings, 0 replies; 48+ messages in thread
From: Alexander Graf @ 2012-08-09 23:09 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Sebastian Ott, Marcelo Tosatti, Heiko Carstens, qemu-devel,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky


On 07.08.2012, at 16:52, Cornelia Huck wrote:

> Running under a kvm host does not necessarily imply the presence of
> a page mapped above the main memory with the virtio information;
> however, the code includes a hard coded access to that page.
> 
> Instead, check for the presence of the page and exit gracefully
> before we hit an addressing exception if it does not exist.
> 
> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> ---
> drivers/s390/kvm/kvm_virtio.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
> index 47cccd5..408447c 100644
> --- a/drivers/s390/kvm/kvm_virtio.c
> +++ b/drivers/s390/kvm/kvm_virtio.c
> @@ -418,6 +418,21 @@ static void kvm_extint_handler(struct ext_code ext_code,
> 	}
> }
> 
> +static int __init test_devices_support(void)

Today we know what this function does, but the next person running into it has no clue. Maybe add a nice description here that you're trying to access memory above ram? (is this even what you're doing here? my s390 asm is slightly rusty) :)

Alex

> +{
> +	int ccode = -EIO;
> +
> +	asm volatile(
> +		"0:	cli	0(%1),0\n"
> +		"	ipm	%0\n"
> +		"	srl	%0,28\n"
> +		"1:\n"
> +		EX_TABLE(0b,1b)
> +		: "+d" (ccode)
> +		: "a" (kvm_devices)
> +		: "cc");
> +	return ccode;
> +}
> /*
>  * Init function for virtio
>  * devices are in a single page above top of "normal" mem
> @@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
> 	}
> 
> 	kvm_devices = (void *) real_memory_size;
> +	if (test_devices_support() < 0) {
> +		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
> +		root_device_unregister(kvm_root);
> +		/* No error. */
> +		return 0;
> +	}
> 
> 	INIT_WORK(&hotplug_work, hotplug_devices);
> 
> -- 
> 1.7.11.4
> 

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

* Re: [Qemu-devel] [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
@ 2012-08-09 23:09     ` Alexander Graf
  0 siblings, 0 replies; 48+ messages in thread
From: Alexander Graf @ 2012-08-09 23:09 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Sebastian Ott, Marcelo Tosatti, Heiko Carstens, qemu-devel,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky


On 07.08.2012, at 16:52, Cornelia Huck wrote:

> Running under a kvm host does not necessarily imply the presence of
> a page mapped above the main memory with the virtio information;
> however, the code includes a hard coded access to that page.
> 
> Instead, check for the presence of the page and exit gracefully
> before we hit an addressing exception if it does not exist.
> 
> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> ---
> drivers/s390/kvm/kvm_virtio.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
> index 47cccd5..408447c 100644
> --- a/drivers/s390/kvm/kvm_virtio.c
> +++ b/drivers/s390/kvm/kvm_virtio.c
> @@ -418,6 +418,21 @@ static void kvm_extint_handler(struct ext_code ext_code,
> 	}
> }
> 
> +static int __init test_devices_support(void)

Today we know what this function does, but the next person running into it has no clue. Maybe add a nice description here that you're trying to access memory above ram? (is this even what you're doing here? my s390 asm is slightly rusty) :)

Alex

> +{
> +	int ccode = -EIO;
> +
> +	asm volatile(
> +		"0:	cli	0(%1),0\n"
> +		"	ipm	%0\n"
> +		"	srl	%0,28\n"
> +		"1:\n"
> +		EX_TABLE(0b,1b)
> +		: "+d" (ccode)
> +		: "a" (kvm_devices)
> +		: "cc");
> +	return ccode;
> +}
> /*
>  * Init function for virtio
>  * devices are in a single page above top of "normal" mem
> @@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
> 	}
> 
> 	kvm_devices = (void *) real_memory_size;
> +	if (test_devices_support() < 0) {
> +		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
> +		root_device_unregister(kvm_root);
> +		/* No error. */
> +		return 0;
> +	}
> 
> 	INIT_WORK(&hotplug_work, hotplug_devices);
> 
> -- 
> 1.7.11.4
> 

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

* Re: [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
  2012-08-09 23:09     ` [Qemu-devel] " Alexander Graf
@ 2012-08-10  7:45       ` Cornelia Huck
  -1 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-10  7:45 UTC (permalink / raw)
  To: Alexander Graf
  Cc: KVM, linux-s390, qemu-devel, Avi Kivity, Marcelo Tosatti,
	Anthony Liguori, Rusty Russell, Christian Borntraeger,
	Carsten Otte, Heiko Carstens, Martin Schwidefsky, Sebastian Ott

On Fri, 10 Aug 2012 01:09:15 +0200
Alexander Graf <agraf@suse.de> wrote:

> 
> On 07.08.2012, at 16:52, Cornelia Huck wrote:
> 
> > Running under a kvm host does not necessarily imply the presence of
> > a page mapped above the main memory with the virtio information;
> > however, the code includes a hard coded access to that page.
> > 
> > Instead, check for the presence of the page and exit gracefully
> > before we hit an addressing exception if it does not exist.
> > 
> > Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> > ---
> > drivers/s390/kvm/kvm_virtio.c | 21 +++++++++++++++++++++
> > 1 file changed, 21 insertions(+)
> > 
> > diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
> > index 47cccd5..408447c 100644
> > --- a/drivers/s390/kvm/kvm_virtio.c
> > +++ b/drivers/s390/kvm/kvm_virtio.c
> > @@ -418,6 +418,21 @@ static void kvm_extint_handler(struct ext_code ext_code,
> > 	}
> > }
> > 
> > +static int __init test_devices_support(void)
> 
> Today we know what this function does, but the next person running into it has no clue. Maybe add a nice description here that you're trying to access memory above ram? (is this even what you're doing here? my s390 asm is slightly rusty) :)

Good point, will add a comment.

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

* Re: [Qemu-devel] [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
@ 2012-08-10  7:45       ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-10  7:45 UTC (permalink / raw)
  To: Alexander Graf
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Sebastian Ott, Marcelo Tosatti, Heiko Carstens, qemu-devel,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Fri, 10 Aug 2012 01:09:15 +0200
Alexander Graf <agraf@suse.de> wrote:

> 
> On 07.08.2012, at 16:52, Cornelia Huck wrote:
> 
> > Running under a kvm host does not necessarily imply the presence of
> > a page mapped above the main memory with the virtio information;
> > however, the code includes a hard coded access to that page.
> > 
> > Instead, check for the presence of the page and exit gracefully
> > before we hit an addressing exception if it does not exist.
> > 
> > Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> > ---
> > drivers/s390/kvm/kvm_virtio.c | 21 +++++++++++++++++++++
> > 1 file changed, 21 insertions(+)
> > 
> > diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
> > index 47cccd5..408447c 100644
> > --- a/drivers/s390/kvm/kvm_virtio.c
> > +++ b/drivers/s390/kvm/kvm_virtio.c
> > @@ -418,6 +418,21 @@ static void kvm_extint_handler(struct ext_code ext_code,
> > 	}
> > }
> > 
> > +static int __init test_devices_support(void)
> 
> Today we know what this function does, but the next person running into it has no clue. Maybe add a nice description here that you're trying to access memory above ram? (is this even what you're doing here? my s390 asm is slightly rusty) :)

Good point, will add a comment.

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

* Re: [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
  2012-08-09 10:41       ` [Qemu-devel] " Cornelia Huck
@ 2012-08-10  8:42         ` Heiko Carstens
  -1 siblings, 0 replies; 48+ messages in thread
From: Heiko Carstens @ 2012-08-10  8:42 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: Avi Kivity, KVM, linux-s390, qemu-devel, Marcelo Tosatti,
	Anthony Liguori, Rusty Russell, Christian Borntraeger,
	Carsten Otte, Alexander Graf, Martin Schwidefsky, Sebastian Ott

On Thu, Aug 09, 2012 at 12:41:57PM +0200, Cornelia Huck wrote:
> On Thu, 09 Aug 2012 13:03:57 +0300
> Avi Kivity <avi@redhat.com> wrote:
> 
> > On 08/07/2012 05:52 PM, Cornelia Huck wrote:
> > > Running under a kvm host does not necessarily imply the presence of
> > > a page mapped above the main memory with the virtio information;
> > > however, the code includes a hard coded access to that page.
> > > 
> > > Instead, check for the presence of the page and exit gracefully
> > > before we hit an addressing exception if it does not exist.
> > > 
> > >  /*
> > >   * Init function for virtio
> > >   * devices are in a single page above top of "normal" mem
> > > @@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
> > >  	}
> > >  
> > >  	kvm_devices = (void *) real_memory_size;
> > > +	if (test_devices_support() < 0) {
> > > +		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
> > > +		root_device_unregister(kvm_root);
> > > +		/* No error. */
> > > +		return 0;
> > > +	}
> > >  
> > 
> > Cleaner to defer root_device_register() until after the mapping has been
> > verified.
> 
> OK, will reorder.

Please use the "lura" instruction to figure out if the guest real page
even exists _before_ creating the mapping.
That way you don't need all the code afterwards.

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

* Re: [Qemu-devel] [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
@ 2012-08-10  8:42         ` Heiko Carstens
  0 siblings, 0 replies; 48+ messages in thread
From: Heiko Carstens @ 2012-08-10  8:42 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Marcelo Tosatti, Sebastian Ott, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Thu, Aug 09, 2012 at 12:41:57PM +0200, Cornelia Huck wrote:
> On Thu, 09 Aug 2012 13:03:57 +0300
> Avi Kivity <avi@redhat.com> wrote:
> 
> > On 08/07/2012 05:52 PM, Cornelia Huck wrote:
> > > Running under a kvm host does not necessarily imply the presence of
> > > a page mapped above the main memory with the virtio information;
> > > however, the code includes a hard coded access to that page.
> > > 
> > > Instead, check for the presence of the page and exit gracefully
> > > before we hit an addressing exception if it does not exist.
> > > 
> > >  /*
> > >   * Init function for virtio
> > >   * devices are in a single page above top of "normal" mem
> > > @@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
> > >  	}
> > >  
> > >  	kvm_devices = (void *) real_memory_size;
> > > +	if (test_devices_support() < 0) {
> > > +		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
> > > +		root_device_unregister(kvm_root);
> > > +		/* No error. */
> > > +		return 0;
> > > +	}
> > >  
> > 
> > Cleaner to defer root_device_register() until after the mapping has been
> > verified.
> 
> OK, will reorder.

Please use the "lura" instruction to figure out if the guest real page
even exists _before_ creating the mapping.
That way you don't need all the code afterwards.

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

* Re: [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
  2012-08-10  8:42         ` [Qemu-devel] " Heiko Carstens
@ 2012-08-10 11:03           ` Cornelia Huck
  -1 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-10 11:03 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Avi Kivity, KVM, linux-s390, qemu-devel, Marcelo Tosatti,
	Anthony Liguori, Rusty Russell, Christian Borntraeger,
	Carsten Otte, Alexander Graf, Martin Schwidefsky, Sebastian Ott

On Fri, 10 Aug 2012 10:42:48 +0200
Heiko Carstens <heiko.carstens@de.ibm.com> wrote:

> On Thu, Aug 09, 2012 at 12:41:57PM +0200, Cornelia Huck wrote:
> > On Thu, 09 Aug 2012 13:03:57 +0300
> > Avi Kivity <avi@redhat.com> wrote:
> > 
> > > On 08/07/2012 05:52 PM, Cornelia Huck wrote:
> > > > Running under a kvm host does not necessarily imply the presence of
> > > > a page mapped above the main memory with the virtio information;
> > > > however, the code includes a hard coded access to that page.
> > > > 
> > > > Instead, check for the presence of the page and exit gracefully
> > > > before we hit an addressing exception if it does not exist.
> > > > 
> > > >  /*
> > > >   * Init function for virtio
> > > >   * devices are in a single page above top of "normal" mem
> > > > @@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
> > > >  	}
> > > >  
> > > >  	kvm_devices = (void *) real_memory_size;
> > > > +	if (test_devices_support() < 0) {
> > > > +		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
> > > > +		root_device_unregister(kvm_root);
> > > > +		/* No error. */
> > > > +		return 0;
> > > > +	}
> > > >  
> > > 
> > > Cleaner to defer root_device_register() until after the mapping has been
> > > verified.
> > 
> > OK, will reorder.
> 
> Please use the "lura" instruction to figure out if the guest real page
> even exists _before_ creating the mapping.
> That way you don't need all the code afterwards.

New instruction of the day ;)

Indeed, this makes the code look nicer.

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

* Re: [Qemu-devel] [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio.
@ 2012-08-10 11:03           ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-10 11:03 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Marcelo Tosatti, Sebastian Ott, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Fri, 10 Aug 2012 10:42:48 +0200
Heiko Carstens <heiko.carstens@de.ibm.com> wrote:

> On Thu, Aug 09, 2012 at 12:41:57PM +0200, Cornelia Huck wrote:
> > On Thu, 09 Aug 2012 13:03:57 +0300
> > Avi Kivity <avi@redhat.com> wrote:
> > 
> > > On 08/07/2012 05:52 PM, Cornelia Huck wrote:
> > > > Running under a kvm host does not necessarily imply the presence of
> > > > a page mapped above the main memory with the virtio information;
> > > > however, the code includes a hard coded access to that page.
> > > > 
> > > > Instead, check for the presence of the page and exit gracefully
> > > > before we hit an addressing exception if it does not exist.
> > > > 
> > > >  /*
> > > >   * Init function for virtio
> > > >   * devices are in a single page above top of "normal" mem
> > > > @@ -443,6 +458,12 @@ static int __init kvm_devices_init(void)
> > > >  	}
> > > >  
> > > >  	kvm_devices = (void *) real_memory_size;
> > > > +	if (test_devices_support() < 0) {
> > > > +		vmem_remove_mapping(real_memory_size, PAGE_SIZE);
> > > > +		root_device_unregister(kvm_root);
> > > > +		/* No error. */
> > > > +		return 0;
> > > > +	}
> > > >  
> > > 
> > > Cleaner to defer root_device_register() until after the mapping has been
> > > verified.
> > 
> > OK, will reorder.
> 
> Please use the "lura" instruction to figure out if the guest real page
> even exists _before_ creating the mapping.
> That way you don't need all the code afterwards.

New instruction of the day ;)

Indeed, this makes the code look nicer.

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

* Re: [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
  2012-08-08  4:22     ` [Qemu-devel] " Rusty Russell
@ 2012-08-13  8:56       ` Cornelia Huck
  -1 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-13  8:56 UTC (permalink / raw)
  To: Rusty Russell
  Cc: KVM, linux-s390, qemu-devel, Avi Kivity, Marcelo Tosatti,
	Anthony Liguori, Christian Borntraeger, Carsten Otte,
	Alexander Graf, Heiko Carstens, Martin Schwidefsky,
	Sebastian Ott

On Wed, 08 Aug 2012 13:52:57 +0930
Rusty Russell <rusty@rustcorp.com.au> wrote:

> On Tue,  7 Aug 2012 16:52:47 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> > Add a driver for kvm guests that matches virtual ccw devices provided
> > by the host as virtio bridge devices.
> 
> Hi Cornelia,
> 
>         OK, this is a good opportunity to fix some limitations, just as
> we did for virtio_mmio (drivers/virtio/virtio_mmio.c).
> 
> 1) Please don't limit yourself to 32 feature bits!  If you look at how
>    virtio_mmio does it, they use a selector to index into a
>    theoretically-infinite array of feature bits:
> 
>  * 0x010  R  HostFeatures     Features supported by the host
>  * 0x014  W  HostFeaturesSel  Set of host features to access via HostFeatures
>  *
>  * 0x020  W  GuestFeatures    Features activated by the guest
>  * 0x024  W  GuestFeaturesSel Set of activated features to set via GuestFeatures

It should be easy to extend the data processed by the feature ccws to a
feature/index combination. Would it be practical to limit the index to
an 8 bit value?

> 
> 2) Please also allow the guest to set the alignment for virtio ring
>    layout (it controls the spacing between the rings), eg:
> 
>  * 0x03c  W  QueueAlign       Used Ring alignment for the current queue

I think the set_vq ccw could be extended with that info.

> 
> 3) Finally, make sure the guest can set the size of the queue, in case
>    it can't allocate the size the host suggests, eg:
> 
>  * 0x034  R  QueueNumMax      Maximum size of the currently selected queue
>  * 0x038  W  QueueNum         Queue size for the currently selected queue
> 
>    This means the host can suggest huge queues, knowing the guest won't
>    simply fail if it does so.

Makes sense, I didn't like just failing to allocate either. The actual
size could probably go into the set_vq ccw as well.

> 
> Note that we're also speculating a move to a new vring format, which
> will probably be little-endian.  But you probably want a completely new
> ccw code for that anyway.

Do you have a pointer to that discussion handy?

If the host may support different vring formats, I'll probably want to
add some kind of discovery mechanism for that as well (what discovery
mechanism depends on whether this would be per-device or per-machine).

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

* Re: [Qemu-devel] [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
@ 2012-08-13  8:56       ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-13  8:56 UTC (permalink / raw)
  To: Rusty Russell
  Cc: linux-s390, Anthony Liguori, KVM, Carsten Otte, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Wed, 08 Aug 2012 13:52:57 +0930
Rusty Russell <rusty@rustcorp.com.au> wrote:

> On Tue,  7 Aug 2012 16:52:47 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> > Add a driver for kvm guests that matches virtual ccw devices provided
> > by the host as virtio bridge devices.
> 
> Hi Cornelia,
> 
>         OK, this is a good opportunity to fix some limitations, just as
> we did for virtio_mmio (drivers/virtio/virtio_mmio.c).
> 
> 1) Please don't limit yourself to 32 feature bits!  If you look at how
>    virtio_mmio does it, they use a selector to index into a
>    theoretically-infinite array of feature bits:
> 
>  * 0x010  R  HostFeatures     Features supported by the host
>  * 0x014  W  HostFeaturesSel  Set of host features to access via HostFeatures
>  *
>  * 0x020  W  GuestFeatures    Features activated by the guest
>  * 0x024  W  GuestFeaturesSel Set of activated features to set via GuestFeatures

It should be easy to extend the data processed by the feature ccws to a
feature/index combination. Would it be practical to limit the index to
an 8 bit value?

> 
> 2) Please also allow the guest to set the alignment for virtio ring
>    layout (it controls the spacing between the rings), eg:
> 
>  * 0x03c  W  QueueAlign       Used Ring alignment for the current queue

I think the set_vq ccw could be extended with that info.

> 
> 3) Finally, make sure the guest can set the size of the queue, in case
>    it can't allocate the size the host suggests, eg:
> 
>  * 0x034  R  QueueNumMax      Maximum size of the currently selected queue
>  * 0x038  W  QueueNum         Queue size for the currently selected queue
> 
>    This means the host can suggest huge queues, knowing the guest won't
>    simply fail if it does so.

Makes sense, I didn't like just failing to allocate either. The actual
size could probably go into the set_vq ccw as well.

> 
> Note that we're also speculating a move to a new vring format, which
> will probably be little-endian.  But you probably want a completely new
> ccw code for that anyway.

Do you have a pointer to that discussion handy?

If the host may support different vring formats, I'll probably want to
add some kind of discovery mechanism for that as well (what discovery
mechanism depends on whether this would be per-device or per-machine).

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

* Re: [PATCH 2/4] s390: Add a mechanism to get the subchannel id.
  2012-08-07 14:52   ` [Qemu-devel] " Cornelia Huck
@ 2012-08-13 17:16     ` Sebastian Ott
  -1 siblings, 0 replies; 48+ messages in thread
From: Sebastian Ott @ 2012-08-13 17:16 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: KVM, linux-s390, qemu-devel, Avi Kivity, Marcelo Tosatti,
	Anthony Liguori, Rusty Russell, Christian Borntraeger,
	Carsten Otte, Alexander Graf, Heiko Carstens, Martin Schwidefsky

On Tue, 7 Aug 2012, Cornelia Huck wrote:
> This will be needed by the new virtio-ccw transport.

We already have ccw_device_get_subchannel_id which is currently used by
qdio only and thus buried in an internal header file. So it would be
better to just clean up this one and make it available to virtio-ccw.
The function looks a little different to what you suggested by it should
do the trick.

---
 arch/s390/include/asm/ccwdev.h |    2 ++
 drivers/s390/cio/device.c      |   11 -----------
 drivers/s390/cio/device.h      |    2 --
 drivers/s390/cio/device_ops.c  |   13 +++++++++++++
 4 files changed, 15 insertions(+), 13 deletions(-)

--- a/arch/s390/include/asm/ccwdev.h
+++ b/arch/s390/include/asm/ccwdev.h
@@ -10,6 +10,7 @@
 
 #include <linux/device.h>
 #include <linux/mod_devicetable.h>
+#include <asm/schid.h>
 #include <asm/fcx.h>
 #include <asm/irq.h>
 
@@ -226,5 +227,6 @@ int ccw_device_siosl(struct ccw_device *
 // FIXME: these have to go
 extern int _ccw_device_get_subchannel_number(struct ccw_device *);
 
+extern struct subchannel_id ccw_device_get_subchannel_id(struct ccw_device *);
 extern void *ccw_device_get_chp_desc(struct ccw_device *, int);
 #endif /* _S390_CCWDEV_H_ */
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -2037,16 +2037,6 @@ void ccw_driver_unregister(struct ccw_dr
 	driver_unregister(&cdriver->driver);
 }
 
-/* Helper func for qdio. */
-struct subchannel_id
-ccw_device_get_subchannel_id(struct ccw_device *cdev)
-{
-	struct subchannel *sch;
-
-	sch = to_subchannel(cdev->dev.parent);
-	return sch->schid;
-}
-
 static void ccw_device_todo(struct work_struct *work)
 {
 	struct ccw_device_private *priv;
@@ -2139,4 +2129,3 @@ EXPORT_SYMBOL(ccw_device_set_offline);
 EXPORT_SYMBOL(ccw_driver_register);
 EXPORT_SYMBOL(ccw_driver_unregister);
 EXPORT_SYMBOL(get_ccwdev_by_busid);
-EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);
--- a/drivers/s390/cio/device.h
+++ b/drivers/s390/cio/device.h
@@ -142,9 +142,7 @@ int ccw_device_notify(struct ccw_device 
 void ccw_device_set_disconnected(struct ccw_device *cdev);
 void ccw_device_set_notoper(struct ccw_device *cdev);
 
-/* qdio needs this. */
 void ccw_device_set_timeout(struct ccw_device *, int);
-extern struct subchannel_id ccw_device_get_subchannel_id(struct ccw_device *);
 
 /* Channel measurement facility related */
 void retry_set_schib(struct ccw_device *cdev);
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -763,6 +763,19 @@ _ccw_device_get_subchannel_number(struct
 	return cdev->private->schid.sch_no;
 }
 
+/**
+ * ccw_device_get_subchannel_id - obtain a subchannel id
+ * @cdev: device to obtain the id for
+ * Return struct subchannel_id of the parent subchannel.
+ */
+struct subchannel_id ccw_device_get_subchannel_id(struct ccw_device *cdev)
+{
+	struct subchannel *sch;
+
+	sch = to_subchannel(cdev->dev.parent);
+	return sch->schid;
+}
+EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);
 
 MODULE_LICENSE("GPL");
 EXPORT_SYMBOL(ccw_device_set_options_mask);

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

* Re: [Qemu-devel] [PATCH 2/4] s390: Add a mechanism to get the subchannel id.
@ 2012-08-13 17:16     ` Sebastian Ott
  0 siblings, 0 replies; 48+ messages in thread
From: Sebastian Ott @ 2012-08-13 17:16 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Tue, 7 Aug 2012, Cornelia Huck wrote:
> This will be needed by the new virtio-ccw transport.

We already have ccw_device_get_subchannel_id which is currently used by
qdio only and thus buried in an internal header file. So it would be
better to just clean up this one and make it available to virtio-ccw.
The function looks a little different to what you suggested by it should
do the trick.

---
 arch/s390/include/asm/ccwdev.h |    2 ++
 drivers/s390/cio/device.c      |   11 -----------
 drivers/s390/cio/device.h      |    2 --
 drivers/s390/cio/device_ops.c  |   13 +++++++++++++
 4 files changed, 15 insertions(+), 13 deletions(-)

--- a/arch/s390/include/asm/ccwdev.h
+++ b/arch/s390/include/asm/ccwdev.h
@@ -10,6 +10,7 @@
 
 #include <linux/device.h>
 #include <linux/mod_devicetable.h>
+#include <asm/schid.h>
 #include <asm/fcx.h>
 #include <asm/irq.h>
 
@@ -226,5 +227,6 @@ int ccw_device_siosl(struct ccw_device *
 // FIXME: these have to go
 extern int _ccw_device_get_subchannel_number(struct ccw_device *);
 
+extern struct subchannel_id ccw_device_get_subchannel_id(struct ccw_device *);
 extern void *ccw_device_get_chp_desc(struct ccw_device *, int);
 #endif /* _S390_CCWDEV_H_ */
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -2037,16 +2037,6 @@ void ccw_driver_unregister(struct ccw_dr
 	driver_unregister(&cdriver->driver);
 }
 
-/* Helper func for qdio. */
-struct subchannel_id
-ccw_device_get_subchannel_id(struct ccw_device *cdev)
-{
-	struct subchannel *sch;
-
-	sch = to_subchannel(cdev->dev.parent);
-	return sch->schid;
-}
-
 static void ccw_device_todo(struct work_struct *work)
 {
 	struct ccw_device_private *priv;
@@ -2139,4 +2129,3 @@ EXPORT_SYMBOL(ccw_device_set_offline);
 EXPORT_SYMBOL(ccw_driver_register);
 EXPORT_SYMBOL(ccw_driver_unregister);
 EXPORT_SYMBOL(get_ccwdev_by_busid);
-EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);
--- a/drivers/s390/cio/device.h
+++ b/drivers/s390/cio/device.h
@@ -142,9 +142,7 @@ int ccw_device_notify(struct ccw_device 
 void ccw_device_set_disconnected(struct ccw_device *cdev);
 void ccw_device_set_notoper(struct ccw_device *cdev);
 
-/* qdio needs this. */
 void ccw_device_set_timeout(struct ccw_device *, int);
-extern struct subchannel_id ccw_device_get_subchannel_id(struct ccw_device *);
 
 /* Channel measurement facility related */
 void retry_set_schib(struct ccw_device *cdev);
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -763,6 +763,19 @@ _ccw_device_get_subchannel_number(struct
 	return cdev->private->schid.sch_no;
 }
 
+/**
+ * ccw_device_get_subchannel_id - obtain a subchannel id
+ * @cdev: device to obtain the id for
+ * Return struct subchannel_id of the parent subchannel.
+ */
+struct subchannel_id ccw_device_get_subchannel_id(struct ccw_device *cdev)
+{
+	struct subchannel *sch;
+
+	sch = to_subchannel(cdev->dev.parent);
+	return sch->schid;
+}
+EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);
 
 MODULE_LICENSE("GPL");
 EXPORT_SYMBOL(ccw_device_set_options_mask);

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

* Re: [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
  2012-08-13  8:56       ` [Qemu-devel] " Cornelia Huck
@ 2012-08-14  0:10         ` Rusty Russell
  -1 siblings, 0 replies; 48+ messages in thread
From: Rusty Russell @ 2012-08-14  0:10 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, KVM, Carsten Otte, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Mon, 13 Aug 2012 10:56:38 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> On Wed, 08 Aug 2012 13:52:57 +0930
> Rusty Russell <rusty@rustcorp.com.au> wrote:
> 
> > On Tue,  7 Aug 2012 16:52:47 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> > 1) Please don't limit yourself to 32 feature bits!  If you look at how
> >    virtio_mmio does it, they use a selector to index into a
> >    theoretically-infinite array of feature bits:
> 
> It should be easy to extend the data processed by the feature ccws to a
> feature/index combination. Would it be practical to limit the index to
> an 8 bit value?

256 feature bits?  That seems like it could one day be limiting.  Or an
8 bit accessor into feature words?  8192 seems enough for anyone sane.

> > Note that we're also speculating a move to a new vring format, which
> > will probably be little-endian.  But you probably want a completely new
> > ccw code for that anyway.
> 
> Do you have a pointer to that discussion handy?
> 
> If the host may support different vring formats, I'll probably want to
> add some kind of discovery mechanism for that as well (what discovery
> mechanism depends on whether this would be per-device or per-machine).

It would be per-machine; per-device would be a bit crazy.  We'd
deprecate the old ring format.

There's been no consistent thread on the ideas for a ring change,
unfortunately, but you can find interesting parts here, off this thread:

Message-ID: <8762gj6q5r.fsf@rustcorp.com.au>
Subject: Re: [RFC 7/11] virtio_pci: new, capability-aware driver.

Cheers,
Rusty.

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

* Re: [Qemu-devel] [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
@ 2012-08-14  0:10         ` Rusty Russell
  0 siblings, 0 replies; 48+ messages in thread
From: Rusty Russell @ 2012-08-14  0:10 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, KVM, Carsten Otte, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Mon, 13 Aug 2012 10:56:38 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> On Wed, 08 Aug 2012 13:52:57 +0930
> Rusty Russell <rusty@rustcorp.com.au> wrote:
> 
> > On Tue,  7 Aug 2012 16:52:47 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> > 1) Please don't limit yourself to 32 feature bits!  If you look at how
> >    virtio_mmio does it, they use a selector to index into a
> >    theoretically-infinite array of feature bits:
> 
> It should be easy to extend the data processed by the feature ccws to a
> feature/index combination. Would it be practical to limit the index to
> an 8 bit value?

256 feature bits?  That seems like it could one day be limiting.  Or an
8 bit accessor into feature words?  8192 seems enough for anyone sane.

> > Note that we're also speculating a move to a new vring format, which
> > will probably be little-endian.  But you probably want a completely new
> > ccw code for that anyway.
> 
> Do you have a pointer to that discussion handy?
> 
> If the host may support different vring formats, I'll probably want to
> add some kind of discovery mechanism for that as well (what discovery
> mechanism depends on whether this would be per-device or per-machine).

It would be per-machine; per-device would be a bit crazy.  We'd
deprecate the old ring format.

There's been no consistent thread on the ideas for a ring change,
unfortunately, but you can find interesting parts here, off this thread:

Message-ID: <8762gj6q5r.fsf@rustcorp.com.au>
Subject: Re: [RFC 7/11] virtio_pci: new, capability-aware driver.

Cheers,
Rusty.

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

* Re: [PATCH 2/4] s390: Add a mechanism to get the subchannel id.
  2012-08-07 14:52   ` [Qemu-devel] " Cornelia Huck
@ 2012-08-14  8:52     ` Sebastian Ott
  -1 siblings, 0 replies; 48+ messages in thread
From: Sebastian Ott @ 2012-08-14  8:52 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: KVM, linux-s390, qemu-devel, Avi Kivity, Marcelo Tosatti,
	Anthony Liguori, Rusty Russell, Christian Borntraeger,
	Carsten Otte, Alexander Graf, Heiko Carstens, Martin Schwidefsky


On Tue, 7 Aug 2012, Cornelia Huck wrote:
> +/**
> + * ccw_device_get_schid - obtain a subchannel id
> + * @cdev: device to obtain the id for
> + * @schid: where to fill in the values
> + */
> +void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
> +{
> +	*schid = cdev->private->schid;
> +}
> +EXPORT_SYMBOL(ccw_device_get_schid);

After I gave this some thought I like your version of this function
better. But please use the id of the parent subchannel instead of the
copy in cdev->private (since this will be removed soon). I'll do a
cleanup patch to convert the internal users of the old function to use
the one above.

Regards,
Sebastian

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

* Re: [Qemu-devel] [PATCH 2/4] s390: Add a mechanism to get the subchannel id.
@ 2012-08-14  8:52     ` Sebastian Ott
  0 siblings, 0 replies; 48+ messages in thread
From: Sebastian Ott @ 2012-08-14  8:52 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky


On Tue, 7 Aug 2012, Cornelia Huck wrote:
> +/**
> + * ccw_device_get_schid - obtain a subchannel id
> + * @cdev: device to obtain the id for
> + * @schid: where to fill in the values
> + */
> +void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
> +{
> +	*schid = cdev->private->schid;
> +}
> +EXPORT_SYMBOL(ccw_device_get_schid);

After I gave this some thought I like your version of this function
better. But please use the id of the parent subchannel instead of the
copy in cdev->private (since this will be removed soon). I'll do a
cleanup patch to convert the internal users of the old function to use
the one above.

Regards,
Sebastian

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

* Re: [PATCH 2/4] s390: Add a mechanism to get the subchannel id.
  2012-08-14  8:52     ` [Qemu-devel] " Sebastian Ott
@ 2012-08-14 10:38       ` Cornelia Huck
  -1 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-14 10:38 UTC (permalink / raw)
  To: Sebastian Ott
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Tue, 14 Aug 2012 10:52:09 +0200 (CEST)
Sebastian Ott <sebott@linux.vnet.ibm.com> wrote:

> 
> On Tue, 7 Aug 2012, Cornelia Huck wrote:
> > +/**
> > + * ccw_device_get_schid - obtain a subchannel id
> > + * @cdev: device to obtain the id for
> > + * @schid: where to fill in the values
> > + */
> > +void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
> > +{
> > +	*schid = cdev->private->schid;
> > +}
> > +EXPORT_SYMBOL(ccw_device_get_schid);
> 
> After I gave this some thought I like your version of this function
> better. But please use the id of the parent subchannel instead of the
> copy in cdev->private (since this will be removed soon). I'll do a
> cleanup patch to convert the internal users of the old function to use
> the one above.

Good, will change that (I think we can rely on a ccw device always
having either a real subchannel or the orphanage pseudo subchannel as
parent).

Small taste question: EXPORT_SYMBOL vs EXPORT_SYMBOL_GPL?

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

* Re: [Qemu-devel] [PATCH 2/4] s390: Add a mechanism to get the subchannel id.
@ 2012-08-14 10:38       ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-14 10:38 UTC (permalink / raw)
  To: Sebastian Ott
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Tue, 14 Aug 2012 10:52:09 +0200 (CEST)
Sebastian Ott <sebott@linux.vnet.ibm.com> wrote:

> 
> On Tue, 7 Aug 2012, Cornelia Huck wrote:
> > +/**
> > + * ccw_device_get_schid - obtain a subchannel id
> > + * @cdev: device to obtain the id for
> > + * @schid: where to fill in the values
> > + */
> > +void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
> > +{
> > +	*schid = cdev->private->schid;
> > +}
> > +EXPORT_SYMBOL(ccw_device_get_schid);
> 
> After I gave this some thought I like your version of this function
> better. But please use the id of the parent subchannel instead of the
> copy in cdev->private (since this will be removed soon). I'll do a
> cleanup patch to convert the internal users of the old function to use
> the one above.

Good, will change that (I think we can rely on a ccw device always
having either a real subchannel or the orphanage pseudo subchannel as
parent).

Small taste question: EXPORT_SYMBOL vs EXPORT_SYMBOL_GPL?

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

* Re: [PATCH 2/4] s390: Add a mechanism to get the subchannel id.
  2012-08-14 10:38       ` [Qemu-devel] " Cornelia Huck
@ 2012-08-14 10:53         ` Sebastian Ott
  -1 siblings, 0 replies; 48+ messages in thread
From: Sebastian Ott @ 2012-08-14 10:53 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky


On Tue, 14 Aug 2012, Cornelia Huck wrote:
> Sebastian Ott <sebott@linux.vnet.ibm.com> wrote:
> > On Tue, 7 Aug 2012, Cornelia Huck wrote:
> > > +/**
> > > + * ccw_device_get_schid - obtain a subchannel id
> > > + * @cdev: device to obtain the id for
> > > + * @schid: where to fill in the values
> > > + */
> > > +void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
> > > +{
> > > +	*schid = cdev->private->schid;
> > > +}
> > > +EXPORT_SYMBOL(ccw_device_get_schid);
> > 
> > After I gave this some thought I like your version of this function
> > better. But please use the id of the parent subchannel instead of the
> > copy in cdev->private (since this will be removed soon). I'll do a
> > cleanup patch to convert the internal users of the old function to use
> > the one above.
> 
> Good, will change that (I think we can rely on a ccw device always
> having either a real subchannel or the orphanage pseudo subchannel as
> parent).

Yes you can rely on that.

> 
> Small taste question: EXPORT_SYMBOL vs EXPORT_SYMBOL_GPL?

get_subchannel_id was EXPORT_SYMBOL_GPL since its going to replace this
let's use the _GPL variant.

Regards,
Sebastian

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

* Re: [Qemu-devel] [PATCH 2/4] s390: Add a mechanism to get the subchannel id.
@ 2012-08-14 10:53         ` Sebastian Ott
  0 siblings, 0 replies; 48+ messages in thread
From: Sebastian Ott @ 2012-08-14 10:53 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, Rusty Russell, KVM, Carsten Otte,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky


On Tue, 14 Aug 2012, Cornelia Huck wrote:
> Sebastian Ott <sebott@linux.vnet.ibm.com> wrote:
> > On Tue, 7 Aug 2012, Cornelia Huck wrote:
> > > +/**
> > > + * ccw_device_get_schid - obtain a subchannel id
> > > + * @cdev: device to obtain the id for
> > > + * @schid: where to fill in the values
> > > + */
> > > +void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
> > > +{
> > > +	*schid = cdev->private->schid;
> > > +}
> > > +EXPORT_SYMBOL(ccw_device_get_schid);
> > 
> > After I gave this some thought I like your version of this function
> > better. But please use the id of the parent subchannel instead of the
> > copy in cdev->private (since this will be removed soon). I'll do a
> > cleanup patch to convert the internal users of the old function to use
> > the one above.
> 
> Good, will change that (I think we can rely on a ccw device always
> having either a real subchannel or the orphanage pseudo subchannel as
> parent).

Yes you can rely on that.

> 
> Small taste question: EXPORT_SYMBOL vs EXPORT_SYMBOL_GPL?

get_subchannel_id was EXPORT_SYMBOL_GPL since its going to replace this
let's use the _GPL variant.

Regards,
Sebastian

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

* Re: [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
  2012-08-14  0:10         ` [Qemu-devel] " Rusty Russell
@ 2012-08-14 11:03           ` Cornelia Huck
  -1 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-14 11:03 UTC (permalink / raw)
  To: Rusty Russell
  Cc: KVM, linux-s390, qemu-devel, Avi Kivity, Marcelo Tosatti,
	Anthony Liguori, Christian Borntraeger, Carsten Otte,
	Alexander Graf, Heiko Carstens, Martin Schwidefsky,
	Sebastian Ott

On Tue, 14 Aug 2012 09:40:01 +0930
Rusty Russell <rusty@rustcorp.com.au> wrote:

> On Mon, 13 Aug 2012 10:56:38 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> > On Wed, 08 Aug 2012 13:52:57 +0930
> > Rusty Russell <rusty@rustcorp.com.au> wrote:
> > 
> > > On Tue,  7 Aug 2012 16:52:47 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> > > 1) Please don't limit yourself to 32 feature bits!  If you look at how
> > >    virtio_mmio does it, they use a selector to index into a
> > >    theoretically-infinite array of feature bits:
> > 
> > It should be easy to extend the data processed by the feature ccws to a
> > feature/index combination. Would it be practical to limit the index to
> > an 8 bit value?
> 
> 256 feature bits?  That seems like it could one day be limiting.  Or an
> 8 bit accessor into feature words?  8192 seems enough for anyone sane.

An 8 bit accessor. I hope everybody stays on the sane side :)

> 
> > > Note that we're also speculating a move to a new vring format, which
> > > will probably be little-endian.  But you probably want a completely new
> > > ccw code for that anyway.
> > 
> > Do you have a pointer to that discussion handy?
> > 
> > If the host may support different vring formats, I'll probably want to
> > add some kind of discovery mechanism for that as well (what discovery
> > mechanism depends on whether this would be per-device or per-machine).
> 
> It would be per-machine; per-device would be a bit crazy.  We'd
> deprecate the old ring format.
> 
> There's been no consistent thread on the ideas for a ring change,
> unfortunately, but you can find interesting parts here, off this thread:
> 
> Message-ID: <8762gj6q5r.fsf@rustcorp.com.au>
> Subject: Re: [RFC 7/11] virtio_pci: new, capability-aware driver.

I've read a bit through this and it looks like this is really virtio-2
or so. How about discoverability by the guest? Guests will likely have
to support both formats, and forcing them to look at the feature bits
for each device in order to figure out the queue format feels wrong if
it is going to be the same format for the whole machine anyway.

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

* Re: [Qemu-devel] [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
@ 2012-08-14 11:03           ` Cornelia Huck
  0 siblings, 0 replies; 48+ messages in thread
From: Cornelia Huck @ 2012-08-14 11:03 UTC (permalink / raw)
  To: Rusty Russell
  Cc: linux-s390, Anthony Liguori, KVM, Carsten Otte, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Tue, 14 Aug 2012 09:40:01 +0930
Rusty Russell <rusty@rustcorp.com.au> wrote:

> On Mon, 13 Aug 2012 10:56:38 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> > On Wed, 08 Aug 2012 13:52:57 +0930
> > Rusty Russell <rusty@rustcorp.com.au> wrote:
> > 
> > > On Tue,  7 Aug 2012 16:52:47 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> > > 1) Please don't limit yourself to 32 feature bits!  If you look at how
> > >    virtio_mmio does it, they use a selector to index into a
> > >    theoretically-infinite array of feature bits:
> > 
> > It should be easy to extend the data processed by the feature ccws to a
> > feature/index combination. Would it be practical to limit the index to
> > an 8 bit value?
> 
> 256 feature bits?  That seems like it could one day be limiting.  Or an
> 8 bit accessor into feature words?  8192 seems enough for anyone sane.

An 8 bit accessor. I hope everybody stays on the sane side :)

> 
> > > Note that we're also speculating a move to a new vring format, which
> > > will probably be little-endian.  But you probably want a completely new
> > > ccw code for that anyway.
> > 
> > Do you have a pointer to that discussion handy?
> > 
> > If the host may support different vring formats, I'll probably want to
> > add some kind of discovery mechanism for that as well (what discovery
> > mechanism depends on whether this would be per-device or per-machine).
> 
> It would be per-machine; per-device would be a bit crazy.  We'd
> deprecate the old ring format.
> 
> There's been no consistent thread on the ideas for a ring change,
> unfortunately, but you can find interesting parts here, off this thread:
> 
> Message-ID: <8762gj6q5r.fsf@rustcorp.com.au>
> Subject: Re: [RFC 7/11] virtio_pci: new, capability-aware driver.

I've read a bit through this and it looks like this is really virtio-2
or so. How about discoverability by the guest? Guests will likely have
to support both formats, and forcing them to look at the feature bits
for each device in order to figure out the queue format feels wrong if
it is going to be the same format for the whole machine anyway.

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

* Re: [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
  2012-08-07 14:52   ` [Qemu-devel] " Cornelia Huck
@ 2012-08-14 19:56     ` Anthony Liguori
  -1 siblings, 0 replies; 48+ messages in thread
From: Anthony Liguori @ 2012-08-14 19:56 UTC (permalink / raw)
  To: Cornelia Huck, KVM, linux-s390, qemu-devel
  Cc: Avi Kivity, Marcelo Tosatti, Rusty Russell,
	Christian Borntraeger, Carsten Otte, Alexander Graf,
	Heiko Carstens, Martin Schwidefsky, Sebastian Ott

Cornelia Huck <cornelia.huck@de.ibm.com> writes:

> Add a driver for kvm guests that matches virtual ccw devices provided
> by the host as virtio bridge devices.
>
> These virtio-ccw devices use a special set of channel commands in order
> to perform virtio functions.
>
> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>

Hi,

Have you written an appendix for the virtio specification for
virtio-ccw?  I think it would be good to include in this series for the
purposes of review.

Regards,

Anthony Liguori

> ---
>  arch/s390/include/asm/irq.h   |   1 +
>  arch/s390/kernel/irq.c        |   1 +
>  drivers/s390/kvm/Makefile     |   2 +-
>  drivers/s390/kvm/virtio_ccw.c | 761 ++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 764 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/s390/kvm/virtio_ccw.c
>
> diff --git a/arch/s390/include/asm/irq.h b/arch/s390/include/asm/irq.h
> index 2b9d418..b4bea53 100644
> --- a/arch/s390/include/asm/irq.h
> +++ b/arch/s390/include/asm/irq.h
> @@ -31,6 +31,7 @@ enum interruption_class {
>  	IOINT_CTC,
>  	IOINT_APB,
>  	IOINT_CSC,
> +	IOINT_VIR,
>  	NMI_NMI,
>  	NR_IRQS,
>  };
> diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
> index dd7630d..2cc7eed 100644
> --- a/arch/s390/kernel/irq.c
> +++ b/arch/s390/kernel/irq.c
> @@ -56,6 +56,7 @@ static const struct irq_class intrclass_names[] = {
>  	{.name = "CTC", .desc = "[I/O] CTC" },
>  	{.name = "APB", .desc = "[I/O] AP Bus" },
>  	{.name = "CSC", .desc = "[I/O] CHSC Subchannel" },
> +	{.name = "VIR", .desc = "[I/O] Virtual I/O Devices" },
>  	{.name = "NMI", .desc = "[NMI] Machine Check" },
>  };
>  
> diff --git a/drivers/s390/kvm/Makefile b/drivers/s390/kvm/Makefile
> index 0815690..241891a 100644
> --- a/drivers/s390/kvm/Makefile
> +++ b/drivers/s390/kvm/Makefile
> @@ -6,4 +6,4 @@
>  # it under the terms of the GNU General Public License (version 2 only)
>  # as published by the Free Software Foundation.
>  
> -obj-$(CONFIG_S390_GUEST) += kvm_virtio.o
> +obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o
> diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
> new file mode 100644
> index 0000000..df0f994
> --- /dev/null
> +++ b/drivers/s390/kvm/virtio_ccw.c
> @@ -0,0 +1,761 @@
> +/*
> + * ccw based virtio transport
> + *
> + * Copyright IBM Corp. 2012
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License (version 2 only)
> + * as published by the Free Software Foundation.
> + *
> + *    Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
> + */
> +
> +#include <linux/kernel_stat.h>
> +#include <linux/init.h>
> +#include <linux/bootmem.h>
> +#include <linux/err.h>
> +#include <linux/virtio.h>
> +#include <linux/virtio_config.h>
> +#include <linux/slab.h>
> +#include <linux/virtio_console.h>
> +#include <linux/interrupt.h>
> +#include <linux/virtio_ring.h>
> +#include <linux/pfn.h>
> +#include <linux/async.h>
> +#include <linux/wait.h>
> +#include <linux/list.h>
> +#include <linux/bitops.h>
> +#include <linux/module.h>
> +#include <asm/io.h>
> +#include <asm/kvm_para.h>
> +#include <asm/setup.h>
> +#include <asm/irq.h>
> +#include <asm/cio.h>
> +#include <asm/ccwdev.h>
> +
> +/*
> + * virtio related functions
> + */
> +
> +struct vq_config_block {
> +	__u16 index;
> +	__u16 num;
> +} __attribute__ ((packed));
> +
> +#define VIRTIO_CCW_CONFIG_SIZE 0x100
> +/* same as PCI config space size, should be enough for all drivers */
> +
> +struct virtio_ccw_device {
> +	struct virtio_device vdev;
> +	__u8 status;
> +	__u8 config[VIRTIO_CCW_CONFIG_SIZE];
> +	struct ccw_device *cdev;
> +	struct ccw1 ccw;
> +	__u32 area;
> +	__u32 curr_io;
> +	int err;
> +	wait_queue_head_t wait_q;
> +	spinlock_t lock;
> +	struct list_head virtqueues;
> +	unsigned long indicators; /* XXX - works because we're under 64 bit */
> +	struct vq_config_block *config_block;
> +};
> +
> +struct vq_info_block {
> +	__u64 queue;
> +	__u16 num;
> +} __attribute__ ((packed));
> +
> +struct virtio_ccw_vq_info {
> +	struct virtqueue *vq;
> +	int num;
> +	int queue_index;
> +	void *queue;
> +	struct vq_info_block *info_block;
> +	struct list_head node;
> +};
> +
> +#define KVM_VIRTIO_CCW_RING_ALIGN 4096
> +
> +#define CCW_CMD_SET_VQ 0x13
> +#define CCW_CMD_VDEV_RESET 0x33
> +#define CCW_CMD_SET_IND 0x43
> +#define CCW_CMD_READ_FEAT 0x12
> +#define CCW_CMD_WRITE_FEAT 0x11
> +#define CCW_CMD_READ_CONF 0x22
> +#define CCW_CMD_WRITE_CONF 0x21
> +#define CCW_CMD_WRITE_STATUS 0x31
> +#define CCW_CMD_READ_VQ_CONF 0x32
> +
> +#define VIRTIO_CCW_DOING_SET_VQ 0x00010000
> +#define VIRTIO_CCW_DOING_RESET 0x00040000
> +#define VIRTIO_CCW_DOING_READ_FEAT 0x00080000
> +#define VIRTIO_CCW_DOING_WRITE_FEAT 0x00100000
> +#define VIRTIO_CCW_DOING_READ_CONFIG 0x00200000
> +#define VIRTIO_CCW_DOING_WRITE_CONFIG 0x00400000
> +#define VIRTIO_CCW_DOING_WRITE_STATUS 0x00800000
> +#define VIRTIO_CCW_DOING_SET_IND 0x01000000
> +#define VIRTIO_CCW_DOING_READ_VQ_CONF 0x02000000
> +#define VIRTIO_CCW_INTPARM_MASK 0xffff0000
> +
> +static struct virtio_ccw_device *to_vc_device(struct virtio_device *vdev)
> +{
> +	return container_of(vdev, struct virtio_ccw_device, vdev);
> +}
> +
> +static int doing_io(struct virtio_ccw_device *vcdev, __u32 flag)
> +{
> +	unsigned long flags;
> +	__u32 ret;
> +
> +	spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
> +	if (vcdev->err)
> +		ret = vcdev->err;
> +	else
> +		ret = vcdev->curr_io & flag;
> +	spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
> +	return ret;
> +}
> +
> +static int ccw_io_helper(struct virtio_ccw_device *vcdev, __u32 intparm)
> +{
> +	int ret;
> +	unsigned long flags;
> +	int flag = intparm & VIRTIO_CCW_INTPARM_MASK;
> +
> +	spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
> +	ret = ccw_device_start(vcdev->cdev, &vcdev->ccw, intparm, 0, 0);
> +	if (!ret)
> +		vcdev->curr_io |= flag;
> +	spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
> +	wait_event(vcdev->wait_q, doing_io(vcdev, flag) == 0);
> +	return ret ? ret : vcdev->err;
> +}
> +
> +static void virtio_ccw_kvm_notify(struct virtqueue *vq)
> +{
> +	struct virtio_ccw_vq_info *info = vq->priv;
> +	struct virtio_ccw_device *vcdev;
> +	struct subchannel_id schid;
> +	__u32 reg2;
> +
> +	vcdev = to_vc_device(info->vq->vdev);
> +	ccw_device_get_schid(vcdev->cdev, &schid);
> +	reg2 = *(__u32 *)&schid;
> +	kvm_hypercall2(3 /* CCW_NOTIFY */, reg2, info->queue_index);
> +}
> +
> +static int virtio_ccw_read_vq_conf(struct virtio_ccw_device *vcdev, int index)
> +{
> +	vcdev->config_block->index = index;
> +	vcdev->ccw.cmd_code = CCW_CMD_READ_VQ_CONF;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(struct vq_config_block);
> +	vcdev->ccw.cda = (__u32)(unsigned long)(vcdev->config_block);
> +	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_VQ_CONF);
> +	return vcdev->config_block->num;
> +}
> +
> +static void virtio_ccw_del_vq(struct virtqueue *vq)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev);
> +	struct virtio_ccw_vq_info *info = vq->priv;
> +	unsigned long flags;
> +	unsigned long size;
> +	int ret;
> +
> +	/* Remove from our list. */
> +	spin_lock_irqsave(&vcdev->lock, flags);
> +	list_del(&info->node);
> +	spin_unlock_irqrestore(&vcdev->lock, flags);
> +
> +	/* Release from host. */
> +	info->info_block->queue = 0;
> +	info->info_block->num = info->queue_index;
> +	vcdev->ccw.cmd_code = CCW_CMD_SET_VQ;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(*info->info_block);
> +	vcdev->ccw.cda = (__u32)(unsigned long)(info->info_block);
> +	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_VQ | info->queue_index);
> +	if (ret)
> +		dev_warn(&vq->vdev->dev, "Error %x while deleting queue %d",
> +			 ret, info->queue_index);
> +
> +	vring_del_virtqueue(vq);
> +	size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
> +	free_pages_exact(info->queue, size);
> +	kfree(info->info_block);
> +	kfree(info);
> +}
> +
> +static void virtio_ccw_del_vqs(struct virtio_device *vdev)
> +{
> +	struct virtqueue *vq, *n;
> +
> +	list_for_each_entry_safe(vq, n, &vdev->vqs, list)
> +		virtio_ccw_del_vq(vq);
> +}
> +
> +static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
> +					     int i, vq_callback_t *callback,
> +					     const char *name)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +	int err;
> +	struct virtqueue *vq;
> +	struct virtio_ccw_vq_info *info;
> +	unsigned long size;
> +	unsigned long flags;
> +
> +	/* Allocate queue. */
> +	info = kzalloc(sizeof(struct virtio_ccw_vq_info), GFP_KERNEL);
> +	if (!info) {
> +		dev_warn(&vcdev->cdev->dev, "no info\n");
> +		err = -ENOMEM;
> +		goto out_err;
> +	}
> +	info->info_block = kzalloc(sizeof(*info->info_block),
> +				   GFP_DMA | GFP_KERNEL);
> +	if (!info->info_block) {
> +		dev_warn(&vcdev->cdev->dev, "no info block\n");
> +		err = -ENOMEM;
> +		goto out_err;
> +	}
> +	info->queue_index = i;
> +	info->num = virtio_ccw_read_vq_conf(vcdev, i);
> +	size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
> +	info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
> +	if (info->queue == NULL) {
> +		dev_warn(&vcdev->cdev->dev, "no queue\n");
> +		err = -ENOMEM;
> +		goto out_err;
> +	}
> +	vq = vring_new_virtqueue(info->num, KVM_VIRTIO_CCW_RING_ALIGN, vdev,
> +				 true, info->queue, virtio_ccw_kvm_notify,
> +				 callback, name);
> +	if (!vq) {
> +		dev_warn(&vcdev->cdev->dev, "no vq\n");
> +		err = -ENOMEM;
> +		free_pages_exact(info->queue, size);
> +		goto out_err;
> +	}
> +	info->vq = vq;
> +	vq->priv = info;
> +
> +	/* Register it with the host. */
> +	info->info_block->queue = (__u64)info->queue;
> +	info->info_block->num = info->queue_index;
> +	vcdev->ccw.cmd_code = CCW_CMD_SET_VQ;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(*info->info_block);
> +	vcdev->ccw.cda = (__u32)(unsigned long)(info->info_block);
> +	err = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_VQ | info->queue_index);
> +	if (err) {
> +		dev_warn(&vcdev->cdev->dev, "SET_VQ failed\n");
> +		free_pages_exact(info->queue, size);
> +		info->vq = NULL;
> +		vq->priv = NULL;
> +		goto out_err;
> +	}
> +
> +	/* Save it to our list. */
> +	spin_lock_irqsave(&vcdev->lock, flags);
> +	list_add(&info->node, &vcdev->virtqueues);
> +	spin_unlock_irqrestore(&vcdev->lock, flags);
> +
> +	return vq;
> +
> +out_err:
> +	if (info)
> +		kfree(info->info_block);
> +	kfree(info);
> +	return ERR_PTR(err);
> +}
> +
> +static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,
> +			       struct virtqueue *vqs[],
> +			       vq_callback_t *callbacks[],
> +			       const char *names[])
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +	int ret, i;
> +
> +	for (i = 0; i < nvqs; ++i) {
> +		vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i]);
> +		if (IS_ERR(vqs[i])) {
> +			ret = PTR_ERR(vqs[i]);
> +			vqs[i] = NULL;
> +			goto out;
> +		}
> +	}
> +	/* Register queue indicators with host. */
> +	vcdev->indicators = 0;
> +	vcdev->ccw.cmd_code = CCW_CMD_SET_IND;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(vcdev->indicators);
> +	vcdev->ccw.cda = (__u32)(unsigned long)(&vcdev->indicators);
> +	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_IND);
> +	if (ret)
> +		goto out;
> +	return 0;
> +out:
> +	virtio_ccw_del_vqs(vdev);
> +	return ret;
> +}
> +
> +static void virtio_ccw_reset(struct virtio_device *vdev)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +
> +	/* Send a reset ccw on device. */
> +	vcdev->ccw.cmd_code = CCW_CMD_VDEV_RESET;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = 0;
> +	vcdev->ccw.cda = 0;
> +	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_RESET);
> +}
> +
> +static u32 virtio_ccw_get_features(struct virtio_device *vdev)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +	u32 features;
> +	int ret;
> +
> +	/* Read the feature bits from the host. */
> +	vcdev->ccw.cmd_code = CCW_CMD_READ_FEAT;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(features);
> +	vcdev->ccw.cda = vcdev->area;
> +	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_FEAT);
> +	if (ret)
> +		return 0;
> +
> +	memcpy(&features, (void *)(unsigned long)vcdev->area,
> +	       sizeof(features));
> +	return le32_to_cpu(features);
> +}
> +
> +static void virtio_ccw_finalize_features(struct virtio_device *vdev)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +
> +	/* Give virtio_ring a chance to accept features. */
> +	vring_transport_features(vdev);
> +
> +	memcpy((void *)(unsigned long)vcdev->area, vdev->features,
> +	       sizeof(*vdev->features));
> +	/* Write the feature bits to the host. */
> +	vcdev->ccw.cmd_code = CCW_CMD_WRITE_FEAT;
> +	/* Sigh. The kernel's features may be longer than the host's. */
> +	vcdev->ccw.flags = CCW_FLAG_SLI;
> +	vcdev->ccw.count = sizeof(*vdev->features);
> +	vcdev->ccw.cda = vcdev->area;
> +	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_FEAT);
> +}
> +
> +static void virtio_ccw_get_config(struct virtio_device *vdev,
> +				  unsigned int offset, void *buf, unsigned len)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +	int ret;
> +
> +	/* Read the config area from the host. */
> +	vcdev->ccw.cmd_code = CCW_CMD_READ_CONF;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = offset + len;
> +	vcdev->ccw.cda = vcdev->area;
> +	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_CONFIG);
> +	if (ret)
> +		return;
> +
> +	memcpy(vcdev->config, (void *)(unsigned long)vcdev->area,
> +	       sizeof(vcdev->config));
> +	memcpy(buf, &vcdev->config[offset], len);
> +}
> +
> +static void virtio_ccw_set_config(struct virtio_device *vdev,
> +				  unsigned int offset, const void *buf,
> +				  unsigned len)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +
> +	memcpy(&vcdev->config[offset], buf, len);
> +	/* Write the config area to the host. */
> +	memcpy((void *)(unsigned long)vcdev->area, vcdev->config,
> +	       sizeof(vcdev->config));
> +	vcdev->ccw.cmd_code = CCW_CMD_WRITE_CONF;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = offset + len;
> +	vcdev->ccw.cda = vcdev->area;
> +	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_CONFIG);
> +}
> +
> +static u8 virtio_ccw_get_status(struct virtio_device *vdev)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +
> +	return vcdev->status;
> +}
> +
> +static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +
> +	/* Write the status to the host. */
> +	vcdev->status = status;
> +	memcpy((void *)(unsigned long)vcdev->area, &status, sizeof(status));
> +	vcdev->ccw.cmd_code = CCW_CMD_WRITE_STATUS;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(status);
> +	vcdev->ccw.cda = vcdev->area;
> +	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_STATUS);
> +}
> +
> +static struct virtio_config_ops virtio_ccw_config_ops = {
> +	.get_features = virtio_ccw_get_features,
> +	.finalize_features = virtio_ccw_finalize_features,
> +	.get = virtio_ccw_get_config,
> +	.set = virtio_ccw_set_config,
> +	.get_status = virtio_ccw_get_status,
> +	.set_status = virtio_ccw_set_status,
> +	.reset = virtio_ccw_reset,
> +	.find_vqs = virtio_ccw_find_vqs,
> +	.del_vqs = virtio_ccw_del_vqs,
> +};
> +
> +
> +/*
> + * ccw bus driver related functions
> + */
> +
> +static void virtio_ccw_release_dev(struct device *_d)
> +{
> +	struct virtio_device *dev = container_of(_d, struct virtio_device,
> +						 dev);
> +	struct virtio_ccw_device *vcdev = to_vc_device(dev);
> +
> +	kfree((void *)(unsigned long)vcdev->area);
> +	kfree(vcdev->config_block);
> +	kfree(vcdev);
> +}
> +
> +static int irb_is_error(struct irb *irb)
> +{
> +	if (scsw_cstat(&irb->scsw) != 0)
> +		return 1;
> +	if (scsw_dstat(&irb->scsw) & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))
> +		return 1;
> +	if (scsw_cc(&irb->scsw) != 0)
> +		return 1;
> +	return 0;
> +}
> +
> +static struct virtqueue *virtio_ccw_vq_by_ind(struct virtio_ccw_device *vcdev,
> +					      int index)
> +{
> +	struct virtio_ccw_vq_info *info;
> +	unsigned long flags;
> +	struct virtqueue *vq;
> +
> +	vq = NULL;
> +	spin_lock_irqsave(&vcdev->lock, flags);
> +	list_for_each_entry(info, &vcdev->virtqueues, node) {
> +		if (info->queue_index == index) {
> +			vq = info->vq;
> +			break;
> +		}
> +	}
> +	spin_unlock_irqrestore(&vcdev->lock, flags);
> +	return vq;
> +}
> +
> +static void virtio_ccw_int_handler(struct ccw_device *cdev,
> +				   unsigned long intparm,
> +				   struct irb *irb)
> +{
> +	__u32 activity = intparm & VIRTIO_CCW_INTPARM_MASK;
> +	struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
> +	int i;
> +	struct virtqueue *vq;
> +
> +	/* Check if it's a notification from the host. */
> +	if ((intparm == 0) &&
> +	    (scsw_stctl(&irb->scsw) ==
> +	     (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))) {
> +		/* OK */
> +	}
> +	if (irb_is_error(irb))
> +		vcdev->err = -EIO; /* XXX - use real error */
> +	if (vcdev->curr_io & activity) {
> +		switch (activity) {
> +		case VIRTIO_CCW_DOING_READ_FEAT:
> +		case VIRTIO_CCW_DOING_WRITE_FEAT:
> +		case VIRTIO_CCW_DOING_READ_CONFIG:
> +		case VIRTIO_CCW_DOING_WRITE_CONFIG:
> +		case VIRTIO_CCW_DOING_WRITE_STATUS:
> +		case VIRTIO_CCW_DOING_SET_VQ:
> +		case VIRTIO_CCW_DOING_SET_IND:
> +		case VIRTIO_CCW_DOING_RESET:
> +		case VIRTIO_CCW_DOING_READ_VQ_CONF:
> +			vcdev->curr_io &= ~activity;
> +			wake_up(&vcdev->wait_q);
> +			break;
> +		default:
> +			/* don't know what to do... */
> +			dev_warn(&cdev->dev, "Suspicious activity '%08x'\n",
> +				 activity);
> +			WARN_ON(1);
> +			break;
> +		}
> +	}
> +	for_each_set_bit(i, &vcdev->indicators,
> +			 sizeof(vcdev->indicators)) {
> +		vq = virtio_ccw_vq_by_ind(vcdev, i);
> +		vring_interrupt(0, vq);
> +		clear_bit(i, &vcdev->indicators);
> +	}
> +}
> +
> +/*
> + * We usually want to autoonline all devices, but give the admin
> + * a way to exempt devices from this.
> + */
> +#define __DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
> +		     (8*sizeof(long)))
> +static unsigned long devs_no_auto[__MAX_SSID + 1][__DEV_WORDS];
> +
> +static char *no_auto = "";
> +
> +module_param(no_auto, charp, 0444);
> +MODULE_PARM_DESC(no_auto, "list of ccw bus id ranges not to be auto-onlined");
> +
> +static int virtio_ccw_check_autoonline(struct ccw_device *cdev)
> +{
> +	struct ccw_dev_id id;
> +
> +	ccw_device_get_id(cdev, &id);
> +	if (test_bit(id.devno, devs_no_auto[id.ssid]))
> +		return 0;
> +	return 1;
> +}
> +
> +static void virtio_ccw_auto_online(void *data, async_cookie_t cookie)
> +{
> +	struct ccw_device *cdev = data;
> +	int ret;
> +
> +	ret = ccw_device_set_online(cdev);
> +	if (ret)
> +		dev_warn(&cdev->dev, "Failed to set online: %d\n", ret);
> +}
> +
> +static int virtio_ccw_probe(struct ccw_device *cdev)
> +{
> +	cdev->handler = virtio_ccw_int_handler;
> +
> +	if (virtio_ccw_check_autoonline(cdev))
> +		async_schedule(virtio_ccw_auto_online, cdev);
> +	return 0;
> +}
> +
> +static void virtio_ccw_remove(struct ccw_device *cdev)
> +{
> +	cdev->handler = NULL;
> +}
> +
> +static int virtio_ccw_offline(struct ccw_device *cdev)
> +{
> +	struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
> +
> +	unregister_virtio_device(&vcdev->vdev);
> +	dev_set_drvdata(&cdev->dev, NULL);
> +	return 0;
> +}
> +
> +
> +/* Area needs to be big enough to fit status, features or configuration. */
> +#define VIRTIO_AREA_SIZE VIRTIO_CCW_CONFIG_SIZE /* biggest possible use */
> +
> +static int virtio_ccw_online(struct ccw_device *cdev)
> +{
> +	int ret;
> +	struct virtio_ccw_device *vcdev;
> +
> +	vcdev = kzalloc(sizeof(*vcdev), GFP_KERNEL);
> +	if (!vcdev) {
> +		dev_warn(&cdev->dev, "Could not get memory for virtio\n");
> +		ret = -ENOMEM;
> +		goto out_free;
> +	}
> +	vcdev->area = (__u32)(unsigned long)kzalloc(VIRTIO_AREA_SIZE,
> +						    GFP_DMA | GFP_KERNEL);
> +	if (!vcdev->area) {
> +		dev_warn(&cdev->dev, "Cound not get memory for virtio\n");
> +		ret = -ENOMEM;
> +		goto out_free;
> +	}
> +	vcdev->config_block = kzalloc(sizeof(*vcdev->config_block),
> +				   GFP_DMA | GFP_KERNEL);
> +	if (!vcdev->config_block) {
> +		ret = -ENOMEM;
> +		goto out_free;
> +	}
> +	vcdev->vdev.dev.parent = &cdev->dev;
> +	vcdev->vdev.dev.release = virtio_ccw_release_dev;
> +	vcdev->vdev.config = &virtio_ccw_config_ops;
> +	vcdev->cdev = cdev;
> +	init_waitqueue_head(&vcdev->wait_q);
> +	INIT_LIST_HEAD(&vcdev->virtqueues);
> +
> +	dev_set_drvdata(&cdev->dev, vcdev);
> +	vcdev->vdev.id.vendor = cdev->id.cu_type;
> +	vcdev->vdev.id.device = cdev->id.cu_model;
> +	ret = register_virtio_device(&vcdev->vdev);
> +	if (ret) {
> +		dev_warn(&cdev->dev, "Failed to register virtio device: %d\n",
> +			 ret);
> +		goto out_put;
> +	}
> +	return 0;
> +out_put:
> +	dev_set_drvdata(&cdev->dev, NULL);
> +	put_device(&vcdev->vdev.dev);
> +	return ret;
> +out_free:
> +	if (vcdev) {
> +		kfree((void *)(unsigned long)vcdev->area);
> +		kfree(vcdev->config_block);
> +	}
> +	kfree(vcdev);
> +	return ret;
> +}
> +
> +static int virtio_ccw_cio_notify(struct ccw_device *cdev, int event)
> +{
> +	/* TODO: Check whether we need special handling here. */
> +	return 0;
> +}
> +
> +static struct ccw_device_id virtio_ids[] = {
> +	{ CCW_DEVICE(0x3832, 0) },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(ccw, virtio_ids);
> +
> +static struct ccw_driver virtio_ccw_driver = {
> +	.driver = {
> +		.owner = THIS_MODULE,
> +		.name = "virtio_ccw",
> +	},
> +	.ids = virtio_ids,
> +	.probe = virtio_ccw_probe,
> +	.remove = virtio_ccw_remove,
> +	.set_offline = virtio_ccw_offline,
> +	.set_online = virtio_ccw_online,
> +	.notify = virtio_ccw_cio_notify,
> +	.int_class = IOINT_VIR,
> +};
> +
> +static int __init pure_hex(char **cp, unsigned int *val, int min_digit,
> +			   int max_digit, int max_val)
> +{
> +	int diff;
> +
> +	diff = 0;
> +	*val = 0;
> +
> +	while (diff <= max_digit) {
> +		int value = hex_to_bin(**cp);
> +
> +		if (value < 0)
> +			break;
> +		*val = *val * 16 + value;
> +		(*cp)++;
> +		diff++;
> +	}
> +
> +	if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
> +		return 1;
> +
> +	return 0;
> +}
> +
> +static int __init parse_busid(char *str, unsigned int *cssid,
> +			      unsigned int *ssid, unsigned int *devno)
> +{
> +	char *str_work;
> +	int rc, ret;
> +
> +	rc = 1;
> +
> +	if (*str == '\0')
> +		goto out;
> +
> +	str_work = str;
> +	ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
> +	if (ret || (str_work[0] != '.'))
> +		goto out;
> +	str_work++;
> +	ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
> +	if (ret || (str_work[0] != '.'))
> +		goto out;
> +	str_work++;
> +	ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
> +	if (ret || (str_work[0] != '\0'))
> +		goto out;
> +
> +	rc = 0;
> +out:
> +	return rc;
> +}
> +
> +static void __init no_auto_parse(void)
> +{
> +	unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
> +	char *parm, *str;
> +	int rc;
> +
> +	str = no_auto;
> +	while ((parm = strsep(&str, ","))) {
> +		rc = parse_busid(strsep(&parm, "-"), &from_cssid,
> +				 &from_ssid, &from);
> +		if (rc)
> +			continue;
> +		if (parm != NULL) {
> +			rc = parse_busid(parm, &to_cssid,
> +					 &to_ssid, &to);
> +			if ((from_ssid > to_ssid) ||
> +			    ((from_ssid == to_ssid) && (from > to)))
> +				rc = -EINVAL;
> +		} else {
> +			to_cssid = from_cssid;
> +			to_ssid = from_ssid;
> +			to = from;
> +		}
> +		if (rc)
> +			continue;
> +		while ((from_ssid < to_ssid) ||
> +		       ((from_ssid == to_ssid) && (from <= to))) {
> +			set_bit(from, devs_no_auto[from_ssid]);
> +			from++;
> +			if (from > __MAX_SUBCHANNEL) {
> +				from_ssid++;
> +				from = 0;
> +			}
> +		}
> +	}
> +}
> +
> +static int __init virtio_ccw_init(void)
> +{
> +	/* parse no_auto string before we do anything further */
> +	no_auto_parse();
> +	return ccw_driver_register(&virtio_ccw_driver);
> +}
> +module_init(virtio_ccw_init);
> +
> +static void __exit virtio_ccw_exit(void)
> +{
> +	ccw_driver_unregister(&virtio_ccw_driver);
> +}
> +module_exit(virtio_ccw_exit);
> -- 
> 1.7.11.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [Qemu-devel] [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
@ 2012-08-14 19:56     ` Anthony Liguori
  0 siblings, 0 replies; 48+ messages in thread
From: Anthony Liguori @ 2012-08-14 19:56 UTC (permalink / raw)
  To: Cornelia Huck, KVM, linux-s390, qemu-devel
  Cc: Carsten Otte, Marcelo Tosatti, Sebastian Ott, Rusty Russell,
	Heiko Carstens, Alexander Graf, Christian Borntraeger,
	Avi Kivity, Martin Schwidefsky

Cornelia Huck <cornelia.huck@de.ibm.com> writes:

> Add a driver for kvm guests that matches virtual ccw devices provided
> by the host as virtio bridge devices.
>
> These virtio-ccw devices use a special set of channel commands in order
> to perform virtio functions.
>
> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>

Hi,

Have you written an appendix for the virtio specification for
virtio-ccw?  I think it would be good to include in this series for the
purposes of review.

Regards,

Anthony Liguori

> ---
>  arch/s390/include/asm/irq.h   |   1 +
>  arch/s390/kernel/irq.c        |   1 +
>  drivers/s390/kvm/Makefile     |   2 +-
>  drivers/s390/kvm/virtio_ccw.c | 761 ++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 764 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/s390/kvm/virtio_ccw.c
>
> diff --git a/arch/s390/include/asm/irq.h b/arch/s390/include/asm/irq.h
> index 2b9d418..b4bea53 100644
> --- a/arch/s390/include/asm/irq.h
> +++ b/arch/s390/include/asm/irq.h
> @@ -31,6 +31,7 @@ enum interruption_class {
>  	IOINT_CTC,
>  	IOINT_APB,
>  	IOINT_CSC,
> +	IOINT_VIR,
>  	NMI_NMI,
>  	NR_IRQS,
>  };
> diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
> index dd7630d..2cc7eed 100644
> --- a/arch/s390/kernel/irq.c
> +++ b/arch/s390/kernel/irq.c
> @@ -56,6 +56,7 @@ static const struct irq_class intrclass_names[] = {
>  	{.name = "CTC", .desc = "[I/O] CTC" },
>  	{.name = "APB", .desc = "[I/O] AP Bus" },
>  	{.name = "CSC", .desc = "[I/O] CHSC Subchannel" },
> +	{.name = "VIR", .desc = "[I/O] Virtual I/O Devices" },
>  	{.name = "NMI", .desc = "[NMI] Machine Check" },
>  };
>  
> diff --git a/drivers/s390/kvm/Makefile b/drivers/s390/kvm/Makefile
> index 0815690..241891a 100644
> --- a/drivers/s390/kvm/Makefile
> +++ b/drivers/s390/kvm/Makefile
> @@ -6,4 +6,4 @@
>  # it under the terms of the GNU General Public License (version 2 only)
>  # as published by the Free Software Foundation.
>  
> -obj-$(CONFIG_S390_GUEST) += kvm_virtio.o
> +obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o
> diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
> new file mode 100644
> index 0000000..df0f994
> --- /dev/null
> +++ b/drivers/s390/kvm/virtio_ccw.c
> @@ -0,0 +1,761 @@
> +/*
> + * ccw based virtio transport
> + *
> + * Copyright IBM Corp. 2012
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License (version 2 only)
> + * as published by the Free Software Foundation.
> + *
> + *    Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
> + */
> +
> +#include <linux/kernel_stat.h>
> +#include <linux/init.h>
> +#include <linux/bootmem.h>
> +#include <linux/err.h>
> +#include <linux/virtio.h>
> +#include <linux/virtio_config.h>
> +#include <linux/slab.h>
> +#include <linux/virtio_console.h>
> +#include <linux/interrupt.h>
> +#include <linux/virtio_ring.h>
> +#include <linux/pfn.h>
> +#include <linux/async.h>
> +#include <linux/wait.h>
> +#include <linux/list.h>
> +#include <linux/bitops.h>
> +#include <linux/module.h>
> +#include <asm/io.h>
> +#include <asm/kvm_para.h>
> +#include <asm/setup.h>
> +#include <asm/irq.h>
> +#include <asm/cio.h>
> +#include <asm/ccwdev.h>
> +
> +/*
> + * virtio related functions
> + */
> +
> +struct vq_config_block {
> +	__u16 index;
> +	__u16 num;
> +} __attribute__ ((packed));
> +
> +#define VIRTIO_CCW_CONFIG_SIZE 0x100
> +/* same as PCI config space size, should be enough for all drivers */
> +
> +struct virtio_ccw_device {
> +	struct virtio_device vdev;
> +	__u8 status;
> +	__u8 config[VIRTIO_CCW_CONFIG_SIZE];
> +	struct ccw_device *cdev;
> +	struct ccw1 ccw;
> +	__u32 area;
> +	__u32 curr_io;
> +	int err;
> +	wait_queue_head_t wait_q;
> +	spinlock_t lock;
> +	struct list_head virtqueues;
> +	unsigned long indicators; /* XXX - works because we're under 64 bit */
> +	struct vq_config_block *config_block;
> +};
> +
> +struct vq_info_block {
> +	__u64 queue;
> +	__u16 num;
> +} __attribute__ ((packed));
> +
> +struct virtio_ccw_vq_info {
> +	struct virtqueue *vq;
> +	int num;
> +	int queue_index;
> +	void *queue;
> +	struct vq_info_block *info_block;
> +	struct list_head node;
> +};
> +
> +#define KVM_VIRTIO_CCW_RING_ALIGN 4096
> +
> +#define CCW_CMD_SET_VQ 0x13
> +#define CCW_CMD_VDEV_RESET 0x33
> +#define CCW_CMD_SET_IND 0x43
> +#define CCW_CMD_READ_FEAT 0x12
> +#define CCW_CMD_WRITE_FEAT 0x11
> +#define CCW_CMD_READ_CONF 0x22
> +#define CCW_CMD_WRITE_CONF 0x21
> +#define CCW_CMD_WRITE_STATUS 0x31
> +#define CCW_CMD_READ_VQ_CONF 0x32
> +
> +#define VIRTIO_CCW_DOING_SET_VQ 0x00010000
> +#define VIRTIO_CCW_DOING_RESET 0x00040000
> +#define VIRTIO_CCW_DOING_READ_FEAT 0x00080000
> +#define VIRTIO_CCW_DOING_WRITE_FEAT 0x00100000
> +#define VIRTIO_CCW_DOING_READ_CONFIG 0x00200000
> +#define VIRTIO_CCW_DOING_WRITE_CONFIG 0x00400000
> +#define VIRTIO_CCW_DOING_WRITE_STATUS 0x00800000
> +#define VIRTIO_CCW_DOING_SET_IND 0x01000000
> +#define VIRTIO_CCW_DOING_READ_VQ_CONF 0x02000000
> +#define VIRTIO_CCW_INTPARM_MASK 0xffff0000
> +
> +static struct virtio_ccw_device *to_vc_device(struct virtio_device *vdev)
> +{
> +	return container_of(vdev, struct virtio_ccw_device, vdev);
> +}
> +
> +static int doing_io(struct virtio_ccw_device *vcdev, __u32 flag)
> +{
> +	unsigned long flags;
> +	__u32 ret;
> +
> +	spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
> +	if (vcdev->err)
> +		ret = vcdev->err;
> +	else
> +		ret = vcdev->curr_io & flag;
> +	spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
> +	return ret;
> +}
> +
> +static int ccw_io_helper(struct virtio_ccw_device *vcdev, __u32 intparm)
> +{
> +	int ret;
> +	unsigned long flags;
> +	int flag = intparm & VIRTIO_CCW_INTPARM_MASK;
> +
> +	spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
> +	ret = ccw_device_start(vcdev->cdev, &vcdev->ccw, intparm, 0, 0);
> +	if (!ret)
> +		vcdev->curr_io |= flag;
> +	spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
> +	wait_event(vcdev->wait_q, doing_io(vcdev, flag) == 0);
> +	return ret ? ret : vcdev->err;
> +}
> +
> +static void virtio_ccw_kvm_notify(struct virtqueue *vq)
> +{
> +	struct virtio_ccw_vq_info *info = vq->priv;
> +	struct virtio_ccw_device *vcdev;
> +	struct subchannel_id schid;
> +	__u32 reg2;
> +
> +	vcdev = to_vc_device(info->vq->vdev);
> +	ccw_device_get_schid(vcdev->cdev, &schid);
> +	reg2 = *(__u32 *)&schid;
> +	kvm_hypercall2(3 /* CCW_NOTIFY */, reg2, info->queue_index);
> +}
> +
> +static int virtio_ccw_read_vq_conf(struct virtio_ccw_device *vcdev, int index)
> +{
> +	vcdev->config_block->index = index;
> +	vcdev->ccw.cmd_code = CCW_CMD_READ_VQ_CONF;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(struct vq_config_block);
> +	vcdev->ccw.cda = (__u32)(unsigned long)(vcdev->config_block);
> +	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_VQ_CONF);
> +	return vcdev->config_block->num;
> +}
> +
> +static void virtio_ccw_del_vq(struct virtqueue *vq)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev);
> +	struct virtio_ccw_vq_info *info = vq->priv;
> +	unsigned long flags;
> +	unsigned long size;
> +	int ret;
> +
> +	/* Remove from our list. */
> +	spin_lock_irqsave(&vcdev->lock, flags);
> +	list_del(&info->node);
> +	spin_unlock_irqrestore(&vcdev->lock, flags);
> +
> +	/* Release from host. */
> +	info->info_block->queue = 0;
> +	info->info_block->num = info->queue_index;
> +	vcdev->ccw.cmd_code = CCW_CMD_SET_VQ;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(*info->info_block);
> +	vcdev->ccw.cda = (__u32)(unsigned long)(info->info_block);
> +	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_VQ | info->queue_index);
> +	if (ret)
> +		dev_warn(&vq->vdev->dev, "Error %x while deleting queue %d",
> +			 ret, info->queue_index);
> +
> +	vring_del_virtqueue(vq);
> +	size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
> +	free_pages_exact(info->queue, size);
> +	kfree(info->info_block);
> +	kfree(info);
> +}
> +
> +static void virtio_ccw_del_vqs(struct virtio_device *vdev)
> +{
> +	struct virtqueue *vq, *n;
> +
> +	list_for_each_entry_safe(vq, n, &vdev->vqs, list)
> +		virtio_ccw_del_vq(vq);
> +}
> +
> +static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
> +					     int i, vq_callback_t *callback,
> +					     const char *name)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +	int err;
> +	struct virtqueue *vq;
> +	struct virtio_ccw_vq_info *info;
> +	unsigned long size;
> +	unsigned long flags;
> +
> +	/* Allocate queue. */
> +	info = kzalloc(sizeof(struct virtio_ccw_vq_info), GFP_KERNEL);
> +	if (!info) {
> +		dev_warn(&vcdev->cdev->dev, "no info\n");
> +		err = -ENOMEM;
> +		goto out_err;
> +	}
> +	info->info_block = kzalloc(sizeof(*info->info_block),
> +				   GFP_DMA | GFP_KERNEL);
> +	if (!info->info_block) {
> +		dev_warn(&vcdev->cdev->dev, "no info block\n");
> +		err = -ENOMEM;
> +		goto out_err;
> +	}
> +	info->queue_index = i;
> +	info->num = virtio_ccw_read_vq_conf(vcdev, i);
> +	size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
> +	info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
> +	if (info->queue == NULL) {
> +		dev_warn(&vcdev->cdev->dev, "no queue\n");
> +		err = -ENOMEM;
> +		goto out_err;
> +	}
> +	vq = vring_new_virtqueue(info->num, KVM_VIRTIO_CCW_RING_ALIGN, vdev,
> +				 true, info->queue, virtio_ccw_kvm_notify,
> +				 callback, name);
> +	if (!vq) {
> +		dev_warn(&vcdev->cdev->dev, "no vq\n");
> +		err = -ENOMEM;
> +		free_pages_exact(info->queue, size);
> +		goto out_err;
> +	}
> +	info->vq = vq;
> +	vq->priv = info;
> +
> +	/* Register it with the host. */
> +	info->info_block->queue = (__u64)info->queue;
> +	info->info_block->num = info->queue_index;
> +	vcdev->ccw.cmd_code = CCW_CMD_SET_VQ;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(*info->info_block);
> +	vcdev->ccw.cda = (__u32)(unsigned long)(info->info_block);
> +	err = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_VQ | info->queue_index);
> +	if (err) {
> +		dev_warn(&vcdev->cdev->dev, "SET_VQ failed\n");
> +		free_pages_exact(info->queue, size);
> +		info->vq = NULL;
> +		vq->priv = NULL;
> +		goto out_err;
> +	}
> +
> +	/* Save it to our list. */
> +	spin_lock_irqsave(&vcdev->lock, flags);
> +	list_add(&info->node, &vcdev->virtqueues);
> +	spin_unlock_irqrestore(&vcdev->lock, flags);
> +
> +	return vq;
> +
> +out_err:
> +	if (info)
> +		kfree(info->info_block);
> +	kfree(info);
> +	return ERR_PTR(err);
> +}
> +
> +static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,
> +			       struct virtqueue *vqs[],
> +			       vq_callback_t *callbacks[],
> +			       const char *names[])
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +	int ret, i;
> +
> +	for (i = 0; i < nvqs; ++i) {
> +		vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i]);
> +		if (IS_ERR(vqs[i])) {
> +			ret = PTR_ERR(vqs[i]);
> +			vqs[i] = NULL;
> +			goto out;
> +		}
> +	}
> +	/* Register queue indicators with host. */
> +	vcdev->indicators = 0;
> +	vcdev->ccw.cmd_code = CCW_CMD_SET_IND;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(vcdev->indicators);
> +	vcdev->ccw.cda = (__u32)(unsigned long)(&vcdev->indicators);
> +	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_SET_IND);
> +	if (ret)
> +		goto out;
> +	return 0;
> +out:
> +	virtio_ccw_del_vqs(vdev);
> +	return ret;
> +}
> +
> +static void virtio_ccw_reset(struct virtio_device *vdev)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +
> +	/* Send a reset ccw on device. */
> +	vcdev->ccw.cmd_code = CCW_CMD_VDEV_RESET;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = 0;
> +	vcdev->ccw.cda = 0;
> +	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_RESET);
> +}
> +
> +static u32 virtio_ccw_get_features(struct virtio_device *vdev)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +	u32 features;
> +	int ret;
> +
> +	/* Read the feature bits from the host. */
> +	vcdev->ccw.cmd_code = CCW_CMD_READ_FEAT;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(features);
> +	vcdev->ccw.cda = vcdev->area;
> +	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_FEAT);
> +	if (ret)
> +		return 0;
> +
> +	memcpy(&features, (void *)(unsigned long)vcdev->area,
> +	       sizeof(features));
> +	return le32_to_cpu(features);
> +}
> +
> +static void virtio_ccw_finalize_features(struct virtio_device *vdev)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +
> +	/* Give virtio_ring a chance to accept features. */
> +	vring_transport_features(vdev);
> +
> +	memcpy((void *)(unsigned long)vcdev->area, vdev->features,
> +	       sizeof(*vdev->features));
> +	/* Write the feature bits to the host. */
> +	vcdev->ccw.cmd_code = CCW_CMD_WRITE_FEAT;
> +	/* Sigh. The kernel's features may be longer than the host's. */
> +	vcdev->ccw.flags = CCW_FLAG_SLI;
> +	vcdev->ccw.count = sizeof(*vdev->features);
> +	vcdev->ccw.cda = vcdev->area;
> +	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_FEAT);
> +}
> +
> +static void virtio_ccw_get_config(struct virtio_device *vdev,
> +				  unsigned int offset, void *buf, unsigned len)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +	int ret;
> +
> +	/* Read the config area from the host. */
> +	vcdev->ccw.cmd_code = CCW_CMD_READ_CONF;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = offset + len;
> +	vcdev->ccw.cda = vcdev->area;
> +	ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_CONFIG);
> +	if (ret)
> +		return;
> +
> +	memcpy(vcdev->config, (void *)(unsigned long)vcdev->area,
> +	       sizeof(vcdev->config));
> +	memcpy(buf, &vcdev->config[offset], len);
> +}
> +
> +static void virtio_ccw_set_config(struct virtio_device *vdev,
> +				  unsigned int offset, const void *buf,
> +				  unsigned len)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +
> +	memcpy(&vcdev->config[offset], buf, len);
> +	/* Write the config area to the host. */
> +	memcpy((void *)(unsigned long)vcdev->area, vcdev->config,
> +	       sizeof(vcdev->config));
> +	vcdev->ccw.cmd_code = CCW_CMD_WRITE_CONF;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = offset + len;
> +	vcdev->ccw.cda = vcdev->area;
> +	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_CONFIG);
> +}
> +
> +static u8 virtio_ccw_get_status(struct virtio_device *vdev)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +
> +	return vcdev->status;
> +}
> +
> +static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status)
> +{
> +	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> +
> +	/* Write the status to the host. */
> +	vcdev->status = status;
> +	memcpy((void *)(unsigned long)vcdev->area, &status, sizeof(status));
> +	vcdev->ccw.cmd_code = CCW_CMD_WRITE_STATUS;
> +	vcdev->ccw.flags = 0;
> +	vcdev->ccw.count = sizeof(status);
> +	vcdev->ccw.cda = vcdev->area;
> +	ccw_io_helper(vcdev, VIRTIO_CCW_DOING_WRITE_STATUS);
> +}
> +
> +static struct virtio_config_ops virtio_ccw_config_ops = {
> +	.get_features = virtio_ccw_get_features,
> +	.finalize_features = virtio_ccw_finalize_features,
> +	.get = virtio_ccw_get_config,
> +	.set = virtio_ccw_set_config,
> +	.get_status = virtio_ccw_get_status,
> +	.set_status = virtio_ccw_set_status,
> +	.reset = virtio_ccw_reset,
> +	.find_vqs = virtio_ccw_find_vqs,
> +	.del_vqs = virtio_ccw_del_vqs,
> +};
> +
> +
> +/*
> + * ccw bus driver related functions
> + */
> +
> +static void virtio_ccw_release_dev(struct device *_d)
> +{
> +	struct virtio_device *dev = container_of(_d, struct virtio_device,
> +						 dev);
> +	struct virtio_ccw_device *vcdev = to_vc_device(dev);
> +
> +	kfree((void *)(unsigned long)vcdev->area);
> +	kfree(vcdev->config_block);
> +	kfree(vcdev);
> +}
> +
> +static int irb_is_error(struct irb *irb)
> +{
> +	if (scsw_cstat(&irb->scsw) != 0)
> +		return 1;
> +	if (scsw_dstat(&irb->scsw) & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))
> +		return 1;
> +	if (scsw_cc(&irb->scsw) != 0)
> +		return 1;
> +	return 0;
> +}
> +
> +static struct virtqueue *virtio_ccw_vq_by_ind(struct virtio_ccw_device *vcdev,
> +					      int index)
> +{
> +	struct virtio_ccw_vq_info *info;
> +	unsigned long flags;
> +	struct virtqueue *vq;
> +
> +	vq = NULL;
> +	spin_lock_irqsave(&vcdev->lock, flags);
> +	list_for_each_entry(info, &vcdev->virtqueues, node) {
> +		if (info->queue_index == index) {
> +			vq = info->vq;
> +			break;
> +		}
> +	}
> +	spin_unlock_irqrestore(&vcdev->lock, flags);
> +	return vq;
> +}
> +
> +static void virtio_ccw_int_handler(struct ccw_device *cdev,
> +				   unsigned long intparm,
> +				   struct irb *irb)
> +{
> +	__u32 activity = intparm & VIRTIO_CCW_INTPARM_MASK;
> +	struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
> +	int i;
> +	struct virtqueue *vq;
> +
> +	/* Check if it's a notification from the host. */
> +	if ((intparm == 0) &&
> +	    (scsw_stctl(&irb->scsw) ==
> +	     (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))) {
> +		/* OK */
> +	}
> +	if (irb_is_error(irb))
> +		vcdev->err = -EIO; /* XXX - use real error */
> +	if (vcdev->curr_io & activity) {
> +		switch (activity) {
> +		case VIRTIO_CCW_DOING_READ_FEAT:
> +		case VIRTIO_CCW_DOING_WRITE_FEAT:
> +		case VIRTIO_CCW_DOING_READ_CONFIG:
> +		case VIRTIO_CCW_DOING_WRITE_CONFIG:
> +		case VIRTIO_CCW_DOING_WRITE_STATUS:
> +		case VIRTIO_CCW_DOING_SET_VQ:
> +		case VIRTIO_CCW_DOING_SET_IND:
> +		case VIRTIO_CCW_DOING_RESET:
> +		case VIRTIO_CCW_DOING_READ_VQ_CONF:
> +			vcdev->curr_io &= ~activity;
> +			wake_up(&vcdev->wait_q);
> +			break;
> +		default:
> +			/* don't know what to do... */
> +			dev_warn(&cdev->dev, "Suspicious activity '%08x'\n",
> +				 activity);
> +			WARN_ON(1);
> +			break;
> +		}
> +	}
> +	for_each_set_bit(i, &vcdev->indicators,
> +			 sizeof(vcdev->indicators)) {
> +		vq = virtio_ccw_vq_by_ind(vcdev, i);
> +		vring_interrupt(0, vq);
> +		clear_bit(i, &vcdev->indicators);
> +	}
> +}
> +
> +/*
> + * We usually want to autoonline all devices, but give the admin
> + * a way to exempt devices from this.
> + */
> +#define __DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
> +		     (8*sizeof(long)))
> +static unsigned long devs_no_auto[__MAX_SSID + 1][__DEV_WORDS];
> +
> +static char *no_auto = "";
> +
> +module_param(no_auto, charp, 0444);
> +MODULE_PARM_DESC(no_auto, "list of ccw bus id ranges not to be auto-onlined");
> +
> +static int virtio_ccw_check_autoonline(struct ccw_device *cdev)
> +{
> +	struct ccw_dev_id id;
> +
> +	ccw_device_get_id(cdev, &id);
> +	if (test_bit(id.devno, devs_no_auto[id.ssid]))
> +		return 0;
> +	return 1;
> +}
> +
> +static void virtio_ccw_auto_online(void *data, async_cookie_t cookie)
> +{
> +	struct ccw_device *cdev = data;
> +	int ret;
> +
> +	ret = ccw_device_set_online(cdev);
> +	if (ret)
> +		dev_warn(&cdev->dev, "Failed to set online: %d\n", ret);
> +}
> +
> +static int virtio_ccw_probe(struct ccw_device *cdev)
> +{
> +	cdev->handler = virtio_ccw_int_handler;
> +
> +	if (virtio_ccw_check_autoonline(cdev))
> +		async_schedule(virtio_ccw_auto_online, cdev);
> +	return 0;
> +}
> +
> +static void virtio_ccw_remove(struct ccw_device *cdev)
> +{
> +	cdev->handler = NULL;
> +}
> +
> +static int virtio_ccw_offline(struct ccw_device *cdev)
> +{
> +	struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
> +
> +	unregister_virtio_device(&vcdev->vdev);
> +	dev_set_drvdata(&cdev->dev, NULL);
> +	return 0;
> +}
> +
> +
> +/* Area needs to be big enough to fit status, features or configuration. */
> +#define VIRTIO_AREA_SIZE VIRTIO_CCW_CONFIG_SIZE /* biggest possible use */
> +
> +static int virtio_ccw_online(struct ccw_device *cdev)
> +{
> +	int ret;
> +	struct virtio_ccw_device *vcdev;
> +
> +	vcdev = kzalloc(sizeof(*vcdev), GFP_KERNEL);
> +	if (!vcdev) {
> +		dev_warn(&cdev->dev, "Could not get memory for virtio\n");
> +		ret = -ENOMEM;
> +		goto out_free;
> +	}
> +	vcdev->area = (__u32)(unsigned long)kzalloc(VIRTIO_AREA_SIZE,
> +						    GFP_DMA | GFP_KERNEL);
> +	if (!vcdev->area) {
> +		dev_warn(&cdev->dev, "Cound not get memory for virtio\n");
> +		ret = -ENOMEM;
> +		goto out_free;
> +	}
> +	vcdev->config_block = kzalloc(sizeof(*vcdev->config_block),
> +				   GFP_DMA | GFP_KERNEL);
> +	if (!vcdev->config_block) {
> +		ret = -ENOMEM;
> +		goto out_free;
> +	}
> +	vcdev->vdev.dev.parent = &cdev->dev;
> +	vcdev->vdev.dev.release = virtio_ccw_release_dev;
> +	vcdev->vdev.config = &virtio_ccw_config_ops;
> +	vcdev->cdev = cdev;
> +	init_waitqueue_head(&vcdev->wait_q);
> +	INIT_LIST_HEAD(&vcdev->virtqueues);
> +
> +	dev_set_drvdata(&cdev->dev, vcdev);
> +	vcdev->vdev.id.vendor = cdev->id.cu_type;
> +	vcdev->vdev.id.device = cdev->id.cu_model;
> +	ret = register_virtio_device(&vcdev->vdev);
> +	if (ret) {
> +		dev_warn(&cdev->dev, "Failed to register virtio device: %d\n",
> +			 ret);
> +		goto out_put;
> +	}
> +	return 0;
> +out_put:
> +	dev_set_drvdata(&cdev->dev, NULL);
> +	put_device(&vcdev->vdev.dev);
> +	return ret;
> +out_free:
> +	if (vcdev) {
> +		kfree((void *)(unsigned long)vcdev->area);
> +		kfree(vcdev->config_block);
> +	}
> +	kfree(vcdev);
> +	return ret;
> +}
> +
> +static int virtio_ccw_cio_notify(struct ccw_device *cdev, int event)
> +{
> +	/* TODO: Check whether we need special handling here. */
> +	return 0;
> +}
> +
> +static struct ccw_device_id virtio_ids[] = {
> +	{ CCW_DEVICE(0x3832, 0) },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(ccw, virtio_ids);
> +
> +static struct ccw_driver virtio_ccw_driver = {
> +	.driver = {
> +		.owner = THIS_MODULE,
> +		.name = "virtio_ccw",
> +	},
> +	.ids = virtio_ids,
> +	.probe = virtio_ccw_probe,
> +	.remove = virtio_ccw_remove,
> +	.set_offline = virtio_ccw_offline,
> +	.set_online = virtio_ccw_online,
> +	.notify = virtio_ccw_cio_notify,
> +	.int_class = IOINT_VIR,
> +};
> +
> +static int __init pure_hex(char **cp, unsigned int *val, int min_digit,
> +			   int max_digit, int max_val)
> +{
> +	int diff;
> +
> +	diff = 0;
> +	*val = 0;
> +
> +	while (diff <= max_digit) {
> +		int value = hex_to_bin(**cp);
> +
> +		if (value < 0)
> +			break;
> +		*val = *val * 16 + value;
> +		(*cp)++;
> +		diff++;
> +	}
> +
> +	if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
> +		return 1;
> +
> +	return 0;
> +}
> +
> +static int __init parse_busid(char *str, unsigned int *cssid,
> +			      unsigned int *ssid, unsigned int *devno)
> +{
> +	char *str_work;
> +	int rc, ret;
> +
> +	rc = 1;
> +
> +	if (*str == '\0')
> +		goto out;
> +
> +	str_work = str;
> +	ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
> +	if (ret || (str_work[0] != '.'))
> +		goto out;
> +	str_work++;
> +	ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
> +	if (ret || (str_work[0] != '.'))
> +		goto out;
> +	str_work++;
> +	ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
> +	if (ret || (str_work[0] != '\0'))
> +		goto out;
> +
> +	rc = 0;
> +out:
> +	return rc;
> +}
> +
> +static void __init no_auto_parse(void)
> +{
> +	unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
> +	char *parm, *str;
> +	int rc;
> +
> +	str = no_auto;
> +	while ((parm = strsep(&str, ","))) {
> +		rc = parse_busid(strsep(&parm, "-"), &from_cssid,
> +				 &from_ssid, &from);
> +		if (rc)
> +			continue;
> +		if (parm != NULL) {
> +			rc = parse_busid(parm, &to_cssid,
> +					 &to_ssid, &to);
> +			if ((from_ssid > to_ssid) ||
> +			    ((from_ssid == to_ssid) && (from > to)))
> +				rc = -EINVAL;
> +		} else {
> +			to_cssid = from_cssid;
> +			to_ssid = from_ssid;
> +			to = from;
> +		}
> +		if (rc)
> +			continue;
> +		while ((from_ssid < to_ssid) ||
> +		       ((from_ssid == to_ssid) && (from <= to))) {
> +			set_bit(from, devs_no_auto[from_ssid]);
> +			from++;
> +			if (from > __MAX_SUBCHANNEL) {
> +				from_ssid++;
> +				from = 0;
> +			}
> +		}
> +	}
> +}
> +
> +static int __init virtio_ccw_init(void)
> +{
> +	/* parse no_auto string before we do anything further */
> +	no_auto_parse();
> +	return ccw_driver_register(&virtio_ccw_driver);
> +}
> +module_init(virtio_ccw_init);
> +
> +static void __exit virtio_ccw_exit(void)
> +{
> +	ccw_driver_unregister(&virtio_ccw_driver);
> +}
> +module_exit(virtio_ccw_exit);
> -- 
> 1.7.11.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
  2012-08-14 11:03           ` [Qemu-devel] " Cornelia Huck
@ 2012-08-15  3:15             ` Rusty Russell
  -1 siblings, 0 replies; 48+ messages in thread
From: Rusty Russell @ 2012-08-15  3:15 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, KVM, Carsten Otte, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Tue, 14 Aug 2012 13:03:34 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> > It would be per-machine; per-device would be a bit crazy.  We'd
> > deprecate the old ring format.
> > 
> > There's been no consistent thread on the ideas for a ring change,
> > unfortunately, but you can find interesting parts here, off this thread:
> > 
> > Message-ID: <8762gj6q5r.fsf@rustcorp.com.au>
> > Subject: Re: [RFC 7/11] virtio_pci: new, capability-aware driver.
> 
> I've read a bit through this and it looks like this is really virtio-2
> or so. How about discoverability by the guest? Guests will likely have
> to support both formats, and forcing them to look at the feature bits
> for each device in order to figure out the queue format feels wrong if
> it is going to be the same format for the whole machine anyway.

Yes, it needs some out-of-band acknowledgement mechanism by the guest.
Might be worth putting a max version number somewhere, which the guest
writes to acknowledge (ie. currently it would be 1, and the guest would
always write a 1).

Cheers,
Rusty.

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

* Re: [Qemu-devel] [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
@ 2012-08-15  3:15             ` Rusty Russell
  0 siblings, 0 replies; 48+ messages in thread
From: Rusty Russell @ 2012-08-15  3:15 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Anthony Liguori, KVM, Carsten Otte, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Christian Borntraeger, Avi Kivity, Martin Schwidefsky

On Tue, 14 Aug 2012 13:03:34 +0200, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> > It would be per-machine; per-device would be a bit crazy.  We'd
> > deprecate the old ring format.
> > 
> > There's been no consistent thread on the ideas for a ring change,
> > unfortunately, but you can find interesting parts here, off this thread:
> > 
> > Message-ID: <8762gj6q5r.fsf@rustcorp.com.au>
> > Subject: Re: [RFC 7/11] virtio_pci: new, capability-aware driver.
> 
> I've read a bit through this and it looks like this is really virtio-2
> or so. How about discoverability by the guest? Guests will likely have
> to support both formats, and forcing them to look at the feature bits
> for each device in order to figure out the queue format feels wrong if
> it is going to be the same format for the whole machine anyway.

Yes, it needs some out-of-band acknowledgement mechanism by the guest.
Might be worth putting a max version number somewhere, which the guest
writes to acknowledge (ie. currently it would be 1, and the guest would
always write a 1).

Cheers,
Rusty.

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

* Re: [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
  2012-08-14 19:56     ` [Qemu-devel] " Anthony Liguori
@ 2012-08-15  7:28       ` Rusty Russell
  -1 siblings, 0 replies; 48+ messages in thread
From: Rusty Russell @ 2012-08-15  7:28 UTC (permalink / raw)
  To: Anthony Liguori, Cornelia Huck, KVM, linux-s390, qemu-devel
  Cc: Carsten Otte, Sebastian Ott, Marcelo Tosatti, Heiko Carstens,
	Alexander Graf, Christian Borntraeger, Avi Kivity,
	Martin Schwidefsky

On Tue, 14 Aug 2012 14:56:07 -0500, Anthony Liguori <aliguori@us.ibm.com> wrote:
> Cornelia Huck <cornelia.huck@de.ibm.com> writes:
> 
> > Add a driver for kvm guests that matches virtual ccw devices provided
> > by the host as virtio bridge devices.
> >
> > These virtio-ccw devices use a special set of channel commands in order
> > to perform virtio functions.
> >
> > Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> 
> Hi,
> 
> Have you written an appendix for the virtio specification for
> virtio-ccw?  I think it would be good to include in this series for the
> purposes of review.

Might be nice, but don't get fancy about it.  Text will be fine and I
can cut & paste it in once it's finalized.

Cheers,
Rusty.

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

* Re: [Qemu-devel] [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
@ 2012-08-15  7:28       ` Rusty Russell
  0 siblings, 0 replies; 48+ messages in thread
From: Rusty Russell @ 2012-08-15  7:28 UTC (permalink / raw)
  To: Anthony Liguori, Cornelia Huck, KVM, linux-s390, qemu-devel
  Cc: Carsten Otte, Sebastian Ott, Marcelo Tosatti, Heiko Carstens,
	Alexander Graf, Christian Borntraeger, Avi Kivity,
	Martin Schwidefsky

On Tue, 14 Aug 2012 14:56:07 -0500, Anthony Liguori <aliguori@us.ibm.com> wrote:
> Cornelia Huck <cornelia.huck@de.ibm.com> writes:
> 
> > Add a driver for kvm guests that matches virtual ccw devices provided
> > by the host as virtio bridge devices.
> >
> > These virtio-ccw devices use a special set of channel commands in order
> > to perform virtio functions.
> >
> > Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> 
> Hi,
> 
> Have you written an appendix for the virtio specification for
> virtio-ccw?  I think it would be good to include in this series for the
> purposes of review.

Might be nice, but don't get fancy about it.  Text will be fine and I
can cut & paste it in once it's finalized.

Cheers,
Rusty.

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

* Re: [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
  2012-08-15  7:28       ` [Qemu-devel] " Rusty Russell
@ 2012-08-15  7:48         ` Christian Borntraeger
  -1 siblings, 0 replies; 48+ messages in thread
From: Christian Borntraeger @ 2012-08-15  7:48 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Anthony Liguori, Cornelia Huck, KVM, linux-s390, qemu-devel,
	Avi Kivity, Marcelo Tosatti, Carsten Otte, Alexander Graf,
	Heiko Carstens, Martin Schwidefsky, Sebastian Ott

>> Have you written an appendix for the virtio specification for
>> virtio-ccw?  I think it would be good to include in this series for the
>> purposes of review.
> 
> Might be nice, but don't get fancy about it.  Text will be fine and I
> can cut & paste it in once it's finalized.

There was a patch against the virtio spec in the patch series. Did it not
make it to you?

But Anthony is right, the spec is important, because the two main things 
that we need to get right are the 2 interfaces
guest<->host and userspace(qemu)<->kvm.
Everything else is not an ABI and can be fixed later on if necessary. 

Regarding the guest<->host interface a lot of things are mandated by the 
channel-IO architecture. We have also reserved some IDs for virtio 
(control unit type 0x3832, channel path type 0x32 and channel subsystem id 0xfe)
so we just have to focus on the virtio part (thanks Rusty for the good feedback
already).

Regarding the qemu<->kvm interface it is important to have an interface that
- allows us to be architectural compliant
- which is fast
- which must not prevent features like vhost
- which allows to implement live migration
- ...?

Christian

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

* Re: [Qemu-devel] [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
@ 2012-08-15  7:48         ` Christian Borntraeger
  0 siblings, 0 replies; 48+ messages in thread
From: Christian Borntraeger @ 2012-08-15  7:48 UTC (permalink / raw)
  To: Rusty Russell
  Cc: linux-s390, Anthony Liguori, KVM, Carsten Otte, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Martin Schwidefsky, Avi Kivity, Cornelia Huck

>> Have you written an appendix for the virtio specification for
>> virtio-ccw?  I think it would be good to include in this series for the
>> purposes of review.
> 
> Might be nice, but don't get fancy about it.  Text will be fine and I
> can cut & paste it in once it's finalized.

There was a patch against the virtio spec in the patch series. Did it not
make it to you?

But Anthony is right, the spec is important, because the two main things 
that we need to get right are the 2 interfaces
guest<->host and userspace(qemu)<->kvm.
Everything else is not an ABI and can be fixed later on if necessary. 

Regarding the guest<->host interface a lot of things are mandated by the 
channel-IO architecture. We have also reserved some IDs for virtio 
(control unit type 0x3832, channel path type 0x32 and channel subsystem id 0xfe)
so we just have to focus on the virtio part (thanks Rusty for the good feedback
already).

Regarding the qemu<->kvm interface it is important to have an interface that
- allows us to be architectural compliant
- which is fast
- which must not prevent features like vhost
- which allows to implement live migration
- ...?

Christian

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

* Re: [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
  2012-08-15  7:48         ` [Qemu-devel] " Christian Borntraeger
@ 2012-08-21  5:35           ` Rusty Russell
  -1 siblings, 0 replies; 48+ messages in thread
From: Rusty Russell @ 2012-08-21  5:35 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: linux-s390, Anthony Liguori, KVM, Carsten Otte, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Martin Schwidefsky, Avi Kivity, Cornelia Huck

On Wed, 15 Aug 2012 09:48:44 +0200, Christian Borntraeger <borntraeger@de.ibm.com> wrote:
> >> Have you written an appendix for the virtio specification for
> >> virtio-ccw?  I think it would be good to include in this series for the
> >> purposes of review.
> > 
> > Might be nice, but don't get fancy about it.  Text will be fine and I
> > can cut & paste it in once it's finalized.
> 
> There was a patch against the virtio spec in the patch series. Did it not
> make it to you?

Yes, I got it, thanks (not in this thread, but that's OK).  Will hold
off until finalized.

Cheers,
Rusty.

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

* Re: [Qemu-devel] [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
@ 2012-08-21  5:35           ` Rusty Russell
  0 siblings, 0 replies; 48+ messages in thread
From: Rusty Russell @ 2012-08-21  5:35 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: linux-s390, Anthony Liguori, KVM, Carsten Otte, Sebastian Ott,
	Marcelo Tosatti, Heiko Carstens, qemu-devel, Alexander Graf,
	Martin Schwidefsky, Avi Kivity, Cornelia Huck

On Wed, 15 Aug 2012 09:48:44 +0200, Christian Borntraeger <borntraeger@de.ibm.com> wrote:
> >> Have you written an appendix for the virtio specification for
> >> virtio-ccw?  I think it would be good to include in this series for the
> >> purposes of review.
> > 
> > Might be nice, but don't get fancy about it.  Text will be fine and I
> > can cut & paste it in once it's finalized.
> 
> There was a patch against the virtio spec in the patch series. Did it not
> make it to you?

Yes, I got it, thanks (not in this thread, but that's OK).  Will hold
off until finalized.

Cheers,
Rusty.

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

end of thread, other threads:[~2012-08-21 23:42 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-07 14:52 [RFC PATCH 0/4] s390: virtio-ccw guest kernel support Cornelia Huck
2012-08-07 14:52 ` [Qemu-devel] " Cornelia Huck
2012-08-07 14:52 ` [PATCH 1/4] s390/kvm: Handle hosts not supporting s390-virtio Cornelia Huck
2012-08-07 14:52   ` [Qemu-devel] " Cornelia Huck
2012-08-09 10:03   ` Avi Kivity
2012-08-09 10:03     ` [Qemu-devel] " Avi Kivity
2012-08-09 10:41     ` Cornelia Huck
2012-08-09 10:41       ` [Qemu-devel] " Cornelia Huck
2012-08-10  8:42       ` Heiko Carstens
2012-08-10  8:42         ` [Qemu-devel] " Heiko Carstens
2012-08-10 11:03         ` Cornelia Huck
2012-08-10 11:03           ` [Qemu-devel] " Cornelia Huck
2012-08-09 23:09   ` Alexander Graf
2012-08-09 23:09     ` [Qemu-devel] " Alexander Graf
2012-08-10  7:45     ` Cornelia Huck
2012-08-10  7:45       ` [Qemu-devel] " Cornelia Huck
2012-08-07 14:52 ` [PATCH 2/4] s390: Add a mechanism to get the subchannel id Cornelia Huck
2012-08-07 14:52   ` [Qemu-devel] " Cornelia Huck
2012-08-13 17:16   ` Sebastian Ott
2012-08-13 17:16     ` [Qemu-devel] " Sebastian Ott
2012-08-14  8:52   ` Sebastian Ott
2012-08-14  8:52     ` [Qemu-devel] " Sebastian Ott
2012-08-14 10:38     ` Cornelia Huck
2012-08-14 10:38       ` [Qemu-devel] " Cornelia Huck
2012-08-14 10:53       ` Sebastian Ott
2012-08-14 10:53         ` [Qemu-devel] " Sebastian Ott
2012-08-07 14:52 ` [PATCH 3/4] s390/kvm: Add a channel I/O based virtio transport driver Cornelia Huck
2012-08-07 14:52   ` [Qemu-devel] " Cornelia Huck
2012-08-08  4:22   ` Rusty Russell
2012-08-08  4:22     ` [Qemu-devel] " Rusty Russell
2012-08-13  8:56     ` Cornelia Huck
2012-08-13  8:56       ` [Qemu-devel] " Cornelia Huck
2012-08-14  0:10       ` Rusty Russell
2012-08-14  0:10         ` [Qemu-devel] " Rusty Russell
2012-08-14 11:03         ` Cornelia Huck
2012-08-14 11:03           ` [Qemu-devel] " Cornelia Huck
2012-08-15  3:15           ` Rusty Russell
2012-08-15  3:15             ` [Qemu-devel] " Rusty Russell
2012-08-14 19:56   ` Anthony Liguori
2012-08-14 19:56     ` [Qemu-devel] " Anthony Liguori
2012-08-15  7:28     ` Rusty Russell
2012-08-15  7:28       ` [Qemu-devel] " Rusty Russell
2012-08-15  7:48       ` Christian Borntraeger
2012-08-15  7:48         ` [Qemu-devel] " Christian Borntraeger
2012-08-21  5:35         ` Rusty Russell
2012-08-21  5:35           ` [Qemu-devel] " Rusty Russell
2012-08-07 14:52 ` [PATCH 4/4] s390/kvm: Split out early console code Cornelia Huck
2012-08-07 14:52   ` [Qemu-devel] " Cornelia Huck

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.