From 9a82446bd269b130a9ac270e720e65c3843d4d0c Mon Sep 17 00:00:00 2001 From: Amit Shah Date: Tue, 23 Mar 2010 18:23:09 +0530 Subject: MAINTAINERS: Put the virtio-console entry in correct alphabetical order Move around the entry for virtio-console to keep the file sorted. Signed-off-by: Amit Shah Signed-off-by: Rusty Russell diff --git a/MAINTAINERS b/MAINTAINERS index 3d29fa3..7a9ccda 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2474,12 +2474,6 @@ L: linuxppc-dev@ozlabs.org S: Odd Fixes F: drivers/char/hvc_* -VIRTIO CONSOLE DRIVER -M: Amit Shah -L: virtualization@lists.linux-foundation.org -S: Maintained -F: drivers/char/virtio_console.c - iSCSI BOOT FIRMWARE TABLE (iBFT) DRIVER M: Peter Jones M: Konrad Rzeszutek Wilk @@ -5971,6 +5965,13 @@ S: Maintained F: Documentation/filesystems/vfat.txt F: fs/fat/ +VIRTIO CONSOLE DRIVER +M: Amit Shah +L: virtualization@lists.linux-foundation.org +S: Maintained +F: drivers/char/virtio_console.c +F: include/linux/virtio_console.h + VIRTIO HOST (VHOST) M: "Michael S. Tsirkin" L: kvm@vger.kernel.org -- cgit v0.10.2 From 162a689a13ed61c0752726edb75427b2cd4186c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Diakhat=C3=A9?= Date: Tue, 23 Mar 2010 18:23:15 +0530 Subject: virtio: console: Fix early_put_chars usage Currently early_put_chars is not used by virtio_console because it can only be used once a port has been found, at which point it's too late because it is no longer needed. This patch should fix it. Acked-by: Christian Borntraeger Signed-off-by: Amit Shah Signed-off-by: Rusty Russell diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 026ea6c..48306bc 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -646,13 +646,13 @@ static int put_chars(u32 vtermno, const char *buf, int count) { struct port *port; + if (unlikely(early_put_chars)) + return early_put_chars(vtermno, buf, count); + port = find_port_by_vtermno(vtermno); if (!port) return 0; - if (unlikely(early_put_chars)) - return early_put_chars(vtermno, buf, count); - return send_buf(port, (void *)buf, count); } -- cgit v0.10.2 From 9ff4cfab82d27e9fda72315f911bbaa9516e04bc Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 8 Apr 2010 09:46:16 -0600 Subject: virtio: console makes incorrect assumption about virtio API The get_buf() API sets the second arg to the number of bytes *written* by the other side; in this case it should be zero as these are output buffers. lguest gets this right (obviously kvm's console doesn't), resulting in continual buildup of console writes. Signed-off-by: Rusty Russell Acked-by: Amit Shah diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 48306bc..86e9011 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -416,20 +416,16 @@ static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count) out_vq->vq_ops->kick(out_vq); if (ret < 0) { - len = 0; + in_count = 0; goto fail; } - /* - * Wait till the host acknowledges it pushed out the data we - * sent. Also ensure we return to userspace the number of - * bytes that were successfully consumed by the host. - */ + /* Wait till the host acknowledges it pushed out the data we sent. */ while (!out_vq->vq_ops->get_buf(out_vq, &len)) cpu_relax(); fail: /* We're expected to return the amount of data we wrote */ - return len; + return in_count; } /* -- cgit v0.10.2 From b7a413015d2986edf020fba765c906cc9cbcbfc9 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Wed, 31 Mar 2010 21:56:42 +0300 Subject: virtio: disable multiport console support. Move MULTIPORT feature and related config changes out of exported headers, and disable the feature at runtime. At this point, it seems less risky to keep code around until we can enable it than rip it out completely. Signed-off-by: Michael S. Tsirkin Signed-off-by: Rusty Russell diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 86e9011..196428c 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -33,6 +33,35 @@ #include #include "hvc_console.h" +/* Moved here from .h file in order to disable MULTIPORT. */ +#define VIRTIO_CONSOLE_F_MULTIPORT 1 /* Does host provide multiple ports? */ + +struct virtio_console_multiport_conf { + struct virtio_console_config config; + /* max. number of ports this device can hold */ + __u32 max_nr_ports; + /* number of ports added so far */ + __u32 nr_ports; +} __attribute__((packed)); + +/* + * A message that's passed between the Host and the Guest for a + * particular port. + */ +struct virtio_console_control { + __u32 id; /* Port number */ + __u16 event; /* The kind of control event (see below) */ + __u16 value; /* Extra information for the key */ +}; + +/* Some events for control messages */ +#define VIRTIO_CONSOLE_PORT_READY 0 +#define VIRTIO_CONSOLE_CONSOLE_PORT 1 +#define VIRTIO_CONSOLE_RESIZE 2 +#define VIRTIO_CONSOLE_PORT_OPEN 3 +#define VIRTIO_CONSOLE_PORT_NAME 4 +#define VIRTIO_CONSOLE_PORT_REMOVE 5 + /* * This is a global struct for storing common data for all the devices * this driver handles. @@ -121,7 +150,7 @@ struct ports_device { spinlock_t cvq_lock; /* The current config space is stored here */ - struct virtio_console_config config; + struct virtio_console_multiport_conf config; /* The virtio device we're associated with */ struct virtio_device *vdev; @@ -1214,7 +1243,7 @@ fail: */ static void config_work_handler(struct work_struct *work) { - struct virtio_console_config virtconconf; + struct virtio_console_multiport_conf virtconconf; struct ports_device *portdev; struct virtio_device *vdev; int err; @@ -1223,7 +1252,8 @@ static void config_work_handler(struct work_struct *work) vdev = portdev->vdev; vdev->config->get(vdev, - offsetof(struct virtio_console_config, nr_ports), + offsetof(struct virtio_console_multiport_conf, + nr_ports), &virtconconf.nr_ports, sizeof(virtconconf.nr_ports)); @@ -1415,16 +1445,19 @@ static int __devinit virtcons_probe(struct virtio_device *vdev) multiport = false; portdev->config.nr_ports = 1; portdev->config.max_nr_ports = 1; +#if 0 /* Multiport is not quite ready yet --RR */ if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT)) { multiport = true; vdev->features[0] |= 1 << VIRTIO_CONSOLE_F_MULTIPORT; - vdev->config->get(vdev, offsetof(struct virtio_console_config, - nr_ports), + vdev->config->get(vdev, + offsetof(struct virtio_console_multiport_conf, + nr_ports), &portdev->config.nr_ports, sizeof(portdev->config.nr_ports)); - vdev->config->get(vdev, offsetof(struct virtio_console_config, - max_nr_ports), + vdev->config->get(vdev, + offsetof(struct virtio_console_multiport_conf, + max_nr_ports), &portdev->config.max_nr_ports, sizeof(portdev->config.max_nr_ports)); if (portdev->config.nr_ports > portdev->config.max_nr_ports) { @@ -1440,6 +1473,7 @@ static int __devinit virtcons_probe(struct virtio_device *vdev) /* Let the Host know we support multiple ports.*/ vdev->config->finalize_features(vdev); +#endif err = init_vqs(portdev); if (err < 0) { @@ -1522,7 +1556,6 @@ static struct virtio_device_id id_table[] = { static unsigned int features[] = { VIRTIO_CONSOLE_F_SIZE, - VIRTIO_CONSOLE_F_MULTIPORT, }; static struct virtio_driver virtio_console = { diff --git a/include/linux/virtio_console.h b/include/linux/virtio_console.h index ae4f039..92228a8 100644 --- a/include/linux/virtio_console.h +++ b/include/linux/virtio_console.h @@ -12,37 +12,14 @@ /* Feature bits */ #define VIRTIO_CONSOLE_F_SIZE 0 /* Does host provide console size? */ -#define VIRTIO_CONSOLE_F_MULTIPORT 1 /* Does host provide multiple ports? */ struct virtio_console_config { /* colums of the screens */ __u16 cols; /* rows of the screens */ __u16 rows; - /* max. number of ports this device can hold */ - __u32 max_nr_ports; - /* number of ports added so far */ - __u32 nr_ports; } __attribute__((packed)); -/* - * A message that's passed between the Host and the Guest for a - * particular port. - */ -struct virtio_console_control { - __u32 id; /* Port number */ - __u16 event; /* The kind of control event (see below) */ - __u16 value; /* Extra information for the key */ -}; - -/* Some events for control messages */ -#define VIRTIO_CONSOLE_PORT_READY 0 -#define VIRTIO_CONSOLE_CONSOLE_PORT 1 -#define VIRTIO_CONSOLE_RESIZE 2 -#define VIRTIO_CONSOLE_PORT_OPEN 3 -#define VIRTIO_CONSOLE_PORT_NAME 4 -#define VIRTIO_CONSOLE_PORT_REMOVE 5 - #ifdef __KERNEL__ int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int)); #endif /* __KERNEL__ */ -- cgit v0.10.2 From 320718ee074acce5ffced6506cb51af1388942aa Mon Sep 17 00:00:00 2001 From: Anton Blanchard Date: Tue, 6 Apr 2010 21:42:38 +1000 Subject: hvc_console: Fix race between hvc_close and hvc_remove I don't claim to understand the tty layer, but it seems like hvc_open and hvc_close should be balanced in their kref reference counting. Right now we get a kref every call to hvc_open: if (hp->count++ > 0) { tty_kref_get(tty); <----- here spin_unlock_irqrestore(&hp->lock, flags); hvc_kick(); return 0; } /* else count == 0 */ tty->driver_data = hp; hp->tty = tty_kref_get(tty); <------ or here if hp->count was 0 But hvc_close has: tty_kref_get(tty); if (--hp->count == 0) { ... /* Put the ref obtained in hvc_open() */ tty_kref_put(tty); ... } tty_kref_put(tty); Since the outside kref get/put balance we only do a single kref_put when count reaches 0. The patch below changes things to call tty_kref_put once for every hvc_close call, and with that my machine boots fine. Signed-off-by: Anton Blanchard Acked-by: Amit Shah Signed-off-by: Rusty Russell diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c index d3890e8..35cca4c 100644 --- a/drivers/char/hvc_console.c +++ b/drivers/char/hvc_console.c @@ -368,16 +368,12 @@ static void hvc_close(struct tty_struct *tty, struct file * filp) hp = tty->driver_data; spin_lock_irqsave(&hp->lock, flags); - tty_kref_get(tty); if (--hp->count == 0) { /* We are done with the tty pointer now. */ hp->tty = NULL; spin_unlock_irqrestore(&hp->lock, flags); - /* Put the ref obtained in hvc_open() */ - tty_kref_put(tty); - if (hp->ops->notifier_del) hp->ops->notifier_del(hp, hp->data); -- cgit v0.10.2