Re: [kvm-devel] [PATCH/RFC 4/9] Basic guest virtual devices infrastructure

2007-05-14 Thread Carsten Otte
Avi Kivity wrote:
> Interesting.  We could use a variation this for x86 as well, but I'm not 
> sure how easy it is to integrate it into closed source OSes (Windows).  
> The diag instruction could be replaced by a hypercall which would make 
> the code generic.
I think we need to freeze the hypercall API at some time, and consider 
it a stable kernel external API. We do then need to document these 
calls, and non-GPL hypervisors can implement it. We could eventually 
have a similar situation with one of the other non-GPL hypervisors on 
s390 that run Linux.

so long,
Carsten

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH/RFC 4/9] Basic guest virtual devices infrastructure

2007-05-14 Thread Avi Kivity
Carsten Otte wrote:
> From: Carsten Otte <[EMAIL PROTECTED]>
>
> This patch adds support for a new bus type that manages paravirtualized 
> devices. The bus uses the s390 diagnose instruction to query devices, and
> match them with the corresponding drivers.
> Future enhancements should include hotplug and hotremoval of virtual devices
> triggered by the host, and supend/resume of virtual devices for migration.
>
>   

Interesting.  We could use a variation this for x86 as well, but I'm not 
sure how easy it is to integrate it into closed source OSes (Windows).  
The diag instruction could be replaced by a hypercall which would make 
the code generic.

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


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH/RFC 4/9] Basic guest virtual devices infrastructure

2007-05-11 Thread Arnd Bergmann
On Friday 11 May 2007, Carsten Otte wrote:

> This patch adds support for a new bus type that manages paravirtualized
> devices. The bus uses the s390 diagnose instruction to query devices, and
> match them with the corresponding drivers.

It seems that the diagnose instruction is really the only s390 specific
thing in here, right? I guess this part of your series is the first one
that we should have in an architecture independent way.

There may also be the chance of merging this with existing virtual
buses like the one for the ps3, which also just exists using
hypercalls.

> +int vdev_match(struct device * dev, struct device_driver *drv)
> +{
> + struct vdev *vdev = to_vdev(dev);
> + struct vdev_driver *vdrv = to_vdrv(drv);
> +
> + if (vdev->vdev_type == vdrv->vdev_type)
> + return 1;
> +
> + return 0;
> +}

Why invent device type numbers? On open firmware, we just do a string compare,
which more intuitive, and means you don't need any further 

> +int vdev_probe(struct device * dev)
> +{
> + struct vdev *vdev = to_vdev(dev);
> + struct vdev_driver *vdrv = to_vdrv(dev->driver);
> +
> + return vdrv->probe(vdev);
> +}

This abstraction is unnecessary, just do the do_vdev() conversion inside
of the individual drivers.

> +
> +struct device vdev_bus = {
> + .bus_id  = "vdev0",
> + .release = vdev_bus_release
> +};
> 
> +static void vdev_bus_release (struct device *device)
> +{
> + /* noop, static bus object */
> +}

Just make the root of your devices a platform_device, then you don't need
to do dirty tricks like this.

> +static int vdev_scan_coldplug(void)
> +{
> + int rc;
> + struct vdev *device;
> +
> + do {
> + device = kzalloc(sizeof(struct vdev), GFP_ATOMIC);
> + if (!device) {
> + rc = -ENOMEM;
> + goto out;
> + }
> + rc = vdev_diag_hotplug(device->symname, device->hostid);
> + if (rc == -ENODEV)
> + break;
> + if (rc < 0) {
> + printk (KERN_WARNING "vdev: error %d detecting" \
> + " initial devices\n", rc);
> + break;
> + }
> + device->vdev_type = rc;
> +
> + //sanity: are strings terminated?
> + if ((strnlen(device->symname, 128) == 128) ||
> + (strnlen(device->hostid, 128) == 128)) {
> + // warn and discard device
> + printk ("vdev: illegal device entry received\n");
> + break;
> + }
> +
> + rc = vdevice_register(device);
> + if (rc) {
> + kfree(device);
> + } else
> + switch (device->vdev_type) {
> + case VDEV_TYPE_DISK:
> + printk (KERN_INFO "vdev: storage device " \
> + "detected: %s\n", device->symname);
> + break;
> + case VDEV_TYPE_NET:
> + printk (KERN_INFO "vdev: network device " \
> + "detected: %s\n", device->symname);
> + break;
> + default:
> + printk (KERN_INFO "vdev: unknown device " \
> + "detected: %s\n", device->symname);
> + }
> + } while(1);
> + kfree (device);
> + out:
> + return 0;
> +}

Interesting concept of probing the bus -- so you just ask if there are
any new devices, right?

> +#define VDEV_TYPE_DISK 0
> +#define VDEV_TYPE_NET  1
> +
> +struct vdev {
> + unsigned intvdev_type;
> + charsymname[128];
> + charhostid[128];
> + struct vdev_driver *driver;
> + struct device   dev;
> + void*drv_private;
> +};

You shouldn't need the driver and drv_private fields -- they are already
present in struct device.

Arnd <><

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH/RFC 4/9] Basic guest virtual devices infrastructure

2007-05-11 Thread Carsten Otte
From: Carsten Otte <[EMAIL PROTECTED]>

This patch adds support for a new bus type that manages paravirtualized 
devices. The bus uses the s390 diagnose instruction to query devices, and
match them with the corresponding drivers.
Future enhancements should include hotplug and hotremoval of virtual devices
triggered by the host, and supend/resume of virtual devices for migration.

This code is s390 architecture specific, please review.

Signed-off-by: Carsten Otte <[EMAIL PROTECTED]>

---
 arch/s390/Kconfig|6 +
 drivers/s390/Makefile|2 
 drivers/s390/guest/Makefile  |6 +
 drivers/s390/guest/vdev.c|  158 +++
 drivers/s390/guest/vdev_device.c |   50 
 include/asm-s390/vdev.h  |   53 +
 6 files changed, 274 insertions(+), 1 deletion(-)

Index: linux-2.6.21/arch/s390/Kconfig
===
--- linux-2.6.21.orig/arch/s390/Kconfig
+++ linux-2.6.21/arch/s390/Kconfig
@@ -521,6 +521,12 @@ config S390_HOST
select S390_SWITCH_AMODE
help
  Select this option if you want to host guest Linux images
+
+config S390_GUEST
+   bool "s390 guest support (EXPERIMENTAL)"
+   depends on 64BIT && EXPERIMENTAL
+   help
+ Select this option if you want to run the kernel under s390 linux
 endmenu
 
 source "net/Kconfig"
Index: linux-2.6.21/drivers/s390/Makefile
===
--- linux-2.6.21.orig/drivers/s390/Makefile
+++ linux-2.6.21/drivers/s390/Makefile
@@ -5,7 +5,7 @@
 CFLAGS_sysinfo.o += -Iinclude/math-emu -Iarch/s390/math-emu -w
 
 obj-y += s390mach.o sysinfo.o s390_rdev.o
-obj-y += cio/ block/ char/ crypto/ net/ scsi/
+obj-y += cio/ block/ char/ crypto/ net/ scsi/ guest/
 
 drivers-y += drivers/s390/built-in.o
 
Index: linux-2.6.21/drivers/s390/guest/Makefile
===
--- /dev/null
+++ linux-2.6.21/drivers/s390/guest/Makefile
@@ -0,0 +1,6 @@
+#
+# s390 Linux virtual environment
+#
+
+obj-$(CONFIG_S390_GUEST) += vdev.o vdev_device.o
+
Index: linux-2.6.21/drivers/s390/guest/vdev.c
===
--- /dev/null
+++ linux-2.6.21/drivers/s390/guest/vdev.c
@@ -0,0 +1,158 @@
+/*
+ *  vdev - guest os layer for device virtualization
+ *
+ *  Copyright IBM Corp. 2007
+ *  Author: Carsten Otte <[EMAIL PROTECTED]>
+ *
+ */
+
+#include 
+
+static void vdev_bus_release(struct device *);
+
+struct bus_type vdev_bus_type = {
+   .name= "vdev",
+   .match   = vdev_match,
+   .probe   = vdev_probe,
+};
+
+struct device vdev_bus = {
+   .bus_id  = "vdev0",
+   .release = vdev_bus_release
+};
+
+int vdev_match(struct device * dev, struct device_driver *drv)
+{
+   struct vdev *vdev = to_vdev(dev);
+   struct vdev_driver *vdrv = to_vdrv(drv);
+
+   if (vdev->vdev_type == vdrv->vdev_type)
+   return 1;
+
+   return 0;
+}
+
+int vdev_probe(struct device * dev)
+{
+   struct vdev *vdev = to_vdev(dev);
+   struct vdev_driver *vdrv = to_vdrv(dev->driver);
+
+   return vdrv->probe(vdev);
+}
+
+static void vdev_bus_release (struct device *device)
+{
+   /* noop, static bus object */
+}
+
+static inline int vdev_diag_hotplug(char symname[128], char hostid[128])
+{
+   register char * __arg1 asm("2") = symname;
+   register char * __arg2 asm("3") = hostid;
+   register int __svcres asm("2");
+   int __res;
+
+   __asm__ __volatile__ (
+   "diag 0,0,0x1e"
+   : "=d" (__svcres)
+   : "0" (__arg1),
+ "d" (__arg2)
+   : "cc", "memory");
+   __res = __svcres;
+   return __res;
+}
+
+
+static int vdev_scan_coldplug(void)
+{
+   int rc;
+   struct vdev *device;
+
+   do {
+   device = kzalloc(sizeof(struct vdev), GFP_ATOMIC);
+   if (!device) {
+   rc = -ENOMEM;
+   goto out;
+   }
+   rc = vdev_diag_hotplug(device->symname, device->hostid);
+   if (rc == -ENODEV)
+   break;
+   if (rc < 0) {
+   printk (KERN_WARNING "vdev: error %d detecting" \
+   " initial devices\n", rc);
+   break;
+   }
+   device->vdev_type = rc;
+
+   //sanity: are strings terminated?
+   if ((strnlen(device->symname, 128) == 128) ||
+   (strnlen(device->hostid, 128) == 128)) {
+   // warn and discard device
+   printk ("vdev: illegal device entry received\n");
+   break;
+   }
+
+   rc = vdevice_register(device);
+   if (rc) {
+   kfree(device);
+   } else
+