Skip to content

Commit 5d38f32

Browse files
Erel Geronrichardweinberger
authored andcommitted
um: drivers: Add virtio vhost-user driver
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>
1 parent 851b6cb commit 5d38f32

File tree

11 files changed

+1169
-2
lines changed

11 files changed

+1169
-2
lines changed

arch/um/drivers/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,10 @@ config UML_NET_SLIRP
335335
Startup example: "eth0=slirp,FE:FD:01:02:03:04,/usr/local/bin/slirp"
336336

337337
endmenu
338+
339+
config VIRTIO_UML
340+
tristate "UML driver for virtio devices"
341+
select VIRTIO
342+
help
343+
This driver provides support for virtio based paravirtual device
344+
drivers over vhost-user sockets.

arch/um/drivers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ obj-$(CONFIG_XTERM_CHAN) += xterm.o xterm_kern.o
6161
obj-$(CONFIG_UML_WATCHDOG) += harddog.o
6262
obj-$(CONFIG_BLK_DEV_COW_COMMON) += cow_user.o
6363
obj-$(CONFIG_UML_RANDOM) += random.o
64+
obj-$(CONFIG_VIRTIO_UML) += virtio_uml.o
6465

6566
# pcap_user.o must be added explicitly.
6667
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

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/* Vhost-user protocol */
3+
4+
#ifndef __VHOST_USER_H__
5+
#define __VHOST_USER_H__
6+
7+
/* Message flags */
8+
#define VHOST_USER_FLAG_REPLY BIT(2)
9+
/* Feature bits */
10+
#define VHOST_USER_F_PROTOCOL_FEATURES 30
11+
/* Protocol feature bits */
12+
#define VHOST_USER_PROTOCOL_F_CONFIG 9
13+
/* Vring state index masks */
14+
#define VHOST_USER_VRING_INDEX_MASK 0xff
15+
#define VHOST_USER_VRING_POLL_MASK BIT(8)
16+
17+
/* Supported version */
18+
#define VHOST_USER_VERSION 1
19+
/* Supported transport features */
20+
#define VHOST_USER_SUPPORTED_F BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES)
21+
/* Supported protocol features */
22+
#define VHOST_USER_SUPPORTED_PROTOCOL_F BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG)
23+
24+
enum vhost_user_request {
25+
VHOST_USER_GET_FEATURES = 1,
26+
VHOST_USER_SET_FEATURES = 2,
27+
VHOST_USER_SET_OWNER = 3,
28+
VHOST_USER_RESET_OWNER = 4,
29+
VHOST_USER_SET_MEM_TABLE = 5,
30+
VHOST_USER_SET_LOG_BASE = 6,
31+
VHOST_USER_SET_LOG_FD = 7,
32+
VHOST_USER_SET_VRING_NUM = 8,
33+
VHOST_USER_SET_VRING_ADDR = 9,
34+
VHOST_USER_SET_VRING_BASE = 10,
35+
VHOST_USER_GET_VRING_BASE = 11,
36+
VHOST_USER_SET_VRING_KICK = 12,
37+
VHOST_USER_SET_VRING_CALL = 13,
38+
VHOST_USER_SET_VRING_ERR = 14,
39+
VHOST_USER_GET_PROTOCOL_FEATURES = 15,
40+
VHOST_USER_SET_PROTOCOL_FEATURES = 16,
41+
VHOST_USER_GET_QUEUE_NUM = 17,
42+
VHOST_USER_SET_VRING_ENABLE = 18,
43+
VHOST_USER_SEND_RARP = 19,
44+
VHOST_USER_NET_SEND_MTU = 20,
45+
VHOST_USER_SET_SLAVE_REQ_FD = 21,
46+
VHOST_USER_IOTLB_MSG = 22,
47+
VHOST_USER_SET_VRING_ENDIAN = 23,
48+
VHOST_USER_GET_CONFIG = 24,
49+
VHOST_USER_SET_CONFIG = 25,
50+
};
51+
52+
struct vhost_user_header {
53+
u32 request; /* Use enum vhost_user_request */
54+
u32 flags;
55+
u32 size;
56+
} __packed;
57+
58+
struct vhost_user_config {
59+
u32 offset;
60+
u32 size;
61+
u32 flags;
62+
u8 payload[0]; /* Variable length */
63+
} __packed;
64+
65+
struct vhost_user_vring_state {
66+
u32 index;
67+
u32 num;
68+
} __packed;
69+
70+
struct vhost_user_vring_addr {
71+
u32 index;
72+
u32 flags;
73+
u64 desc, used, avail, log;
74+
} __packed;
75+
76+
struct vhost_user_mem_region {
77+
u64 guest_addr;
78+
u64 size;
79+
u64 user_addr;
80+
u64 mmap_offset;
81+
} __packed;
82+
83+
struct vhost_user_mem_regions {
84+
u32 num;
85+
u32 padding;
86+
struct vhost_user_mem_region regions[2]; /* Currently supporting 2 */
87+
} __packed;
88+
89+
union vhost_user_payload {
90+
u64 integer;
91+
struct vhost_user_config config;
92+
struct vhost_user_vring_state vring_state;
93+
struct vhost_user_vring_addr vring_addr;
94+
struct vhost_user_mem_regions mem_regions;
95+
};
96+
97+
struct vhost_user_msg {
98+
struct vhost_user_header header;
99+
union vhost_user_payload payload;
100+
} __packed;
101+
102+
#endif

0 commit comments

Comments
 (0)