@@ -41,6 +41,7 @@ static void print_help(char *const name)
4141 " --passt-socket=PATH Instead of starting passt, connect to passt socket at PATH\n"
4242 " --vhost-user-rng=PATH Use vhost-user RNG backend at socket PATH\n"
4343 " --vhost-user-snd=PATH Use vhost-user sound backend at socket PATH\n"
44+ " --vhost-user-vsock=PATH Use vhost-user vsock backend at socket PATH\n"
4445 "NET_MODE can be either TSI (default) or PASST\n"
4546 "\n"
4647 "NEWROOT: the root directory of the vm\n"
@@ -58,6 +59,7 @@ static const struct option long_options[] = {
5859 { "passt-socket" , required_argument , NULL , 'P' },
5960 { "vhost-user-rng" , required_argument , NULL , 'V' },
6061 { "vhost-user-snd" , required_argument , NULL , 'S' },
62+ { "vhost-user-vsock" , required_argument , NULL , 'K' },
6163 { NULL , 0 , NULL , 0 }
6264};
6365
@@ -69,6 +71,7 @@ struct cmdline {
6971 char const * passt_socket_path ;
7072 char const * vhost_user_rng_socket ;
7173 char const * vhost_user_snd_socket ;
74+ char const * vhost_user_vsock_socket ;
7275 char const * new_root ;
7376 char * const * guest_argv ;
7477};
@@ -97,6 +100,7 @@ bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
97100 .passt_socket_path = NULL ,
98101 .vhost_user_rng_socket = NULL ,
99102 .vhost_user_snd_socket = NULL ,
103+ .vhost_user_vsock_socket = NULL ,
100104 .new_root = NULL ,
101105 .guest_argv = NULL ,
102106 .log_target = KRUN_LOG_TARGET_DEFAULT ,
@@ -138,6 +142,9 @@ bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
138142 case 'S' :
139143 cmdline -> vhost_user_snd_socket = optarg ;
140144 break ;
145+ case 'K' :
146+ cmdline -> vhost_user_vsock_socket = optarg ;
147+ break ;
141148 case '?' :
142149 return false;
143150 default :
@@ -290,6 +297,26 @@ int main(int argc, char *const argv[])
290297 printf ("Using vhost-user sound backend at %s\n" , cmdline .vhost_user_snd_socket );
291298 }
292299
300+ // Configure vhost-user vsock if requested
301+ if (cmdline .vhost_user_vsock_socket != NULL ) {
302+ // Disable the implicit vsock device to avoid conflict
303+ if (err = krun_disable_implicit_vsock (ctx_id )) {
304+ errno = - err ;
305+ perror ("Error disabling implicit vsock" );
306+ return -1 ;
307+ }
308+
309+ if (err = krun_add_vhost_user_device (ctx_id , KRUN_VIRTIO_DEVICE_VSOCK ,
310+ cmdline .vhost_user_vsock_socket , NULL ,
311+ KRUN_VHOST_USER_VSOCK_NUM_QUEUES ,
312+ KRUN_VHOST_USER_VSOCK_QUEUE_SIZES )) {
313+ errno = - err ;
314+ perror ("Error adding vhost-user vsock device" );
315+ return -1 ;
316+ }
317+ printf ("Using vhost-user vsock backend at %s\n" , cmdline .vhost_user_vsock_socket );
318+ }
319+
293320 // Raise RLIMIT_NOFILE to the maximum allowed to create some room for virtio-fs
294321 getrlimit (RLIMIT_NOFILE , & rlim );
295322 rlim .rlim_cur = rlim .rlim_max ;
@@ -310,7 +337,8 @@ int main(int argc, char *const argv[])
310337 }
311338
312339 // Map port 18000 in the host to 8000 in the guest (if networking uses TSI)
313- if (cmdline .net_mode == NET_MODE_TSI ) {
340+ // Skip port mapping when using vhost-user-vsock (TSI requires built-in vsock)
341+ if (cmdline .net_mode == NET_MODE_TSI && cmdline .vhost_user_vsock_socket == NULL ) {
314342 if (err = krun_set_port_map (ctx_id , & port_map [0 ])) {
315343 errno = - err ;
316344 perror ("Error configuring port map" );
0 commit comments