Skip to content

Commit

Permalink
um: drivers: Add virtio vhost-user driver
Browse files Browse the repository at this point in the history
This module allows virtio devices to be used over a vhost-user socket.

Signed-off-by: Erel Geron <erelx.geron@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
  • Loading branch information
Erel Geron authored and richardweinberger committed Sep 15, 2019
1 parent 851b6cb commit 5d38f32
Show file tree
Hide file tree
Showing 11 changed files with 1,169 additions and 2 deletions.
7 changes: 7 additions & 0 deletions arch/um/drivers/Kconfig
Expand Up @@ -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.
1 change: 1 addition & 0 deletions arch/um/drivers/Makefile
Expand Up @@ -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
Expand Down
102 changes: 102 additions & 0 deletions arch/um/drivers/vhost_user.h
@@ -0,0 +1,102 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/* Vhost-user protocol */

#ifndef __VHOST_USER_H__
#define __VHOST_USER_H__

/* Message flags */
#define VHOST_USER_FLAG_REPLY BIT(2)
/* Feature bits */
#define VHOST_USER_F_PROTOCOL_FEATURES 30
/* Protocol feature bits */
#define VHOST_USER_PROTOCOL_F_CONFIG 9
/* Vring state index masks */
#define VHOST_USER_VRING_INDEX_MASK 0xff
#define VHOST_USER_VRING_POLL_MASK BIT(8)

/* Supported version */
#define VHOST_USER_VERSION 1
/* Supported transport features */
#define VHOST_USER_SUPPORTED_F BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES)
/* Supported protocol features */
#define VHOST_USER_SUPPORTED_PROTOCOL_F BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG)

enum vhost_user_request {
VHOST_USER_GET_FEATURES = 1,
VHOST_USER_SET_FEATURES = 2,
VHOST_USER_SET_OWNER = 3,
VHOST_USER_RESET_OWNER = 4,
VHOST_USER_SET_MEM_TABLE = 5,
VHOST_USER_SET_LOG_BASE = 6,
VHOST_USER_SET_LOG_FD = 7,
VHOST_USER_SET_VRING_NUM = 8,
VHOST_USER_SET_VRING_ADDR = 9,
VHOST_USER_SET_VRING_BASE = 10,
VHOST_USER_GET_VRING_BASE = 11,
VHOST_USER_SET_VRING_KICK = 12,
VHOST_USER_SET_VRING_CALL = 13,
VHOST_USER_SET_VRING_ERR = 14,
VHOST_USER_GET_PROTOCOL_FEATURES = 15,
VHOST_USER_SET_PROTOCOL_FEATURES = 16,
VHOST_USER_GET_QUEUE_NUM = 17,
VHOST_USER_SET_VRING_ENABLE = 18,
VHOST_USER_SEND_RARP = 19,
VHOST_USER_NET_SEND_MTU = 20,
VHOST_USER_SET_SLAVE_REQ_FD = 21,
VHOST_USER_IOTLB_MSG = 22,
VHOST_USER_SET_VRING_ENDIAN = 23,
VHOST_USER_GET_CONFIG = 24,
VHOST_USER_SET_CONFIG = 25,
};

struct vhost_user_header {
u32 request; /* Use enum vhost_user_request */
u32 flags;
u32 size;
} __packed;

struct vhost_user_config {
u32 offset;
u32 size;
u32 flags;
u8 payload[0]; /* Variable length */
} __packed;

struct vhost_user_vring_state {
u32 index;
u32 num;
} __packed;

struct vhost_user_vring_addr {
u32 index;
u32 flags;
u64 desc, used, avail, log;
} __packed;

struct vhost_user_mem_region {
u64 guest_addr;
u64 size;
u64 user_addr;
u64 mmap_offset;
} __packed;

struct vhost_user_mem_regions {
u32 num;
u32 padding;
struct vhost_user_mem_region regions[2]; /* Currently supporting 2 */
} __packed;

union vhost_user_payload {
u64 integer;
struct vhost_user_config config;
struct vhost_user_vring_state vring_state;
struct vhost_user_vring_addr vring_addr;
struct vhost_user_mem_regions mem_regions;
};

struct vhost_user_msg {
struct vhost_user_header header;
union vhost_user_payload payload;
} __packed;

#endif

0 comments on commit 5d38f32

Please sign in to comment.