From 5105b1d8c2d1ad4a25b8806e86c0f012936b2eed Mon Sep 17 00:00:00 2001 From: David Marchand Date: Tue, 16 Jun 2015 17:43:34 +0200 Subject: ivshmem: add check on protocol version in QEMU MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Send a protocol version as the first message from server, clients must close communication if they don't support this protocol version. Older QEMUs should be fine with this change in the protocol since they overrides their own vm_id on reception of an id associated to no eventfd. Signed-off-by: David Marchand Signed-off-by: Marc-André Lureau [use fifo_update_and_get()] Reviewed-by: Claudio Fontana --- hw/misc/ivshmem.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'hw/misc/ivshmem.c') diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 0dd8da197a..cf774ea92e 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -27,6 +27,8 @@ #include "qemu/fifo8.h" #include "sysemu/char.h" +#include "hw/misc/ivshmem.h" + #include #include #include @@ -596,6 +598,31 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) } } +static void ivshmem_check_version(void *opaque, const uint8_t * buf, int size) +{ + IVShmemState *s = opaque; + int tmp; + long version; + + if (!fifo_update_and_get(s, buf, size, + &version, sizeof(version))) { + return; + } + + tmp = qemu_chr_fe_get_msgfd(s->server_chr); + if (tmp != -1 || version != IVSHMEM_PROTOCOL_VERSION) { + fprintf(stderr, "incompatible version, you are connecting to a ivshmem-" + "server using a different protocol please check your setup\n"); + qemu_chr_delete(s->server_chr); + s->server_chr = NULL; + return; + } + + IVSHMEM_DPRINTF("version check ok, switch to real chardev handler\n"); + qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, ivshmem_read, + ivshmem_event, s); +} + /* Select the MSI-X vectors used by device. * ivshmem maps events to vectors statically, so * we just enable all vectors on init and after reset. */ @@ -769,8 +796,8 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp) s->eventfd_chr = g_malloc0(s->vectors * sizeof(CharDriverState *)); - qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, ivshmem_read, - ivshmem_event, s); + qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, + ivshmem_check_version, ivshmem_event, s); } else { /* just map the file immediately, we're not using a server */ int fd; -- cgit 1.4.1