um: drivers: Add virtio vhost-user driver
Johannes Berg
maintainerPATCH v2 1/1 um: drivers: Add virtio vhost-user driver
From: Erel Geron <[email protected]>
This module allows virtio devices to be used over a vhost-user socket.
---
v2:
* remove most WARNings, replace by more precise error messages
* handle short reads/writes on the socket
* remove os_eventfd_read()/write(), eventfd_read()/write() are just glibc helper functions and not really needed
* fix various code style issues
* add __uml_help()
* fix infinite loop in vu_interrupt() on EOF
--- arch/um/drivers/Kconfig | 7 + arch/um/drivers/Makefile | 1 + arch/um/drivers/vhost_user.h | 102 ++++ arch/um/drivers/virtio_uml.c | 953 +++++++++++++++++++++++++++++++++++ arch/um/include/asm/irq.h | 5 +- arch/um/include/shared/os.h | 5 + arch/um/kernel/ksyms.c | 2 + arch/um/kernel/mem.c | 1 + arch/um/kernel/physmem.c | 1 + arch/um/kernel/um_arch.c | 1 + arch/um/os-Linux/file.c | 44 ++ 11 files changed, 1120 insertions(+), 2 deletions(-) create mode 100644 arch/um/drivers/vhost_user.h create mode 100644 arch/um/drivers/virtio_uml.c
arch/um/drivers/Kconfig +7 -0
@@ -335,3 +335,10 @@ config UML_NET_SLIRP Startup example: "eth0=slirp,FE:FD:01:02:03:04,/usr/local/bin/slirp" endmenu + +config VIRTIO_UML + tristate "UML driver for virtio devices" + select VIRTIO + help + This driver provides support for virtio based paravirtual device + drivers over vhost-user sockets.
arch/um/drivers/Makefile +1 -0
@@ -61,6 +61,7 @@ obj-$(CONFIG_XTERM_CHAN) += xterm.o xterm_kern.o obj-$(CONFIG_UML_WATCHDOG) += harddog.o obj-$(CONFIG_BLK_DEV_COW_COMMON) += cow_user.o obj-$(CONFIG_UML_RANDOM) += random.o +obj-$(CONFIG_VIRTIO_UML) += virtio_uml.o # pcap_user.o must be added explicitly. USER_OBJS := fd.o null.o pty.o tty.o xterm.o slip_common.o pcap_user.o vde_user.o vector_user.o
arch/um/drivers/vhost_user.h new file +102 -0
102 lines not on this page · raw message
arch/um/drivers/virtio_uml.c new file +953 -0
953 lines not on this page · raw message
arch/um/include/asm/irq.h +3 -2
@@ -17,17 +17,18 @@#define TELNETD_IRQ 12#define XTERM_IRQ 13#define RANDOM_IRQ 14 +#define VIRTIO_IRQ 15#ifdef CONFIG_UML_NET_VECTOR -#define VECTOR_BASE_IRQ 15 +#define VECTOR_BASE_IRQ (VIRTIO_IRQ + 1)#define VECTOR_IRQ_SPACE 8#define LAST_IRQ (VECTOR_IRQ_SPACE + VECTOR_BASE_IRQ - 1)#else -#define LAST_IRQ RANDOM_IRQ +#define LAST_IRQ VIRTIO_IRQ#endif
arch/um/include/shared/os.h +5 -0
@@ -36,6 +36,8 @@#define OS_LIB_PATH "/usr/lib/"#endif +#define OS_SENDMSG_MAX_FDS 8 +/* * types taken from stat_file() in hostfs_user.c * (if they are wrong here, they are wrong there...).
@@ -176,6 +178,9 @@ extern unsigned os_major(unsigned long long dev);extern unsigned os_minor (unsigned long long dev);extern unsigned long long os_makedev (unsigned major,unsigned minor);extern int os_falloc_punch (int fd,unsigned long long offset,int count); +extern int os_eventfd (unsigned int initval,int flags); +extern int os_sendmsg_fds (int fd,const void *buf,unsigned int len, +const int *fds,unsigned int fds_num);/* start_up.c */ extern void os_early_checks (void );
arch/um/kernel/ksyms.c +2 -0
@@ -38,6 +38,8 @@ EXPORT_SYMBOL(run_helper);EXPORT_SYMBOL (os_major);EXPORT_SYMBOL (os_minor);EXPORT_SYMBOL (os_makedev); +EXPORT_SYMBOL (os_eventfd); +EXPORT_SYMBOL (os_sendmsg_fds);EXPORT_SYMBOL (add_sigio_fd);EXPORT_SYMBOL (ignore_sigio_fd);
arch/um/kernel/mem.c +1 -0
@@ -31,6 +31,7 @@ pgd_t swapper_pg_dir[PTRS_PER_PGD];/* Initialized at boot time, and readonly after that */ unsigned long long highmem; +EXPORT_SYMBOL (highmem);int kmalloc_ok =0 ;/* Used during early boot */
arch/um/kernel/physmem.c +1 -0
@@ -143,6 +143,7 @@ int phys_mapping(unsigned long phys, unsigned long long *offset_out)return fd; } +EXPORT_SYMBOL (phys_mapping);static int __init uml_mem_setup (char *line,int *add) {
arch/um/kernel/um_arch.c +1 -0
@@ -113,6 +113,7 @@ static int have_root __initdata = 0;/* Set in uml_mem_setup and modified in linux_main */ long long physmem_size =32 *1024 *1024 ; +EXPORT_SYMBOL (physmem_size);static const char *usage_string ="User Mode Linux v%s\n"
arch/um/os-Linux/file.c +44 -0
53 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerarch/um/drivers/virtio_uml.c line 643
Quoted 8 lines · Johannes Berg
arch/um/drivers/virtio_uml.c new file +7
-0+static int vu_find_vqs (struct virtio_device *vdev,unsigned nvqs, +struct virtqueue *vqs[],vq_callback_t *callbacks[], +const char *const names[],const bool *ctx, +struct irq_affinity *desc) +{ +struct virtio_uml_device *vu_dev =to_virtio_uml_device (vdev); +int i, queue_idx, rc;
Found another bug - queue_idx needs to be initialized to 0 here, it's only used
arch/um/drivers/virtio_uml.c line 656
Quoted 13 lines
arch/um/drivers/virtio_uml.c new file +13
-0+struct virtqueue *vq; + + rc =vhost_user_set_mem_table (vu_dev); +if (rc) +return rc; + +for (i =0 ; i < nvqs; ++i) { +if (!names[i]) { + vqs[i] =NULL ; +continue ; + } + + vqs[i] = vu_setup_vq(vdev, queue_idx++, callbacks[i], names[i],
here
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um