@@ -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"
@@ -68,6 +69,7 @@ static const struct option long_options[] = {
6869 { "passt-socket" , required_argument , NULL , 'P' },
6970 { "vhost-user-rng" , required_argument , NULL , 'V' },
7071 { "vhost-user-snd" , required_argument , NULL , 'S' },
72+ { "vhost-user-vsock" , required_argument , NULL , 'K' },
7173 { NULL , 0 , NULL , 0 }
7274};
7375
@@ -79,6 +81,7 @@ struct cmdline {
7981 char const * passt_socket_path ;
8082 char const * vhost_user_rng_socket ;
8183 char const * vhost_user_snd_socket ;
84+ char const * vhost_user_vsock_socket ;
8285 char const * new_root ;
8386 char * const * guest_argv ;
8487};
@@ -107,6 +110,7 @@ bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
107110 .passt_socket_path = NULL ,
108111 .vhost_user_rng_socket = NULL ,
109112 .vhost_user_snd_socket = NULL ,
113+ .vhost_user_vsock_socket = NULL ,
110114 .new_root = NULL ,
111115 .guest_argv = NULL ,
112116 .log_target = KRUN_LOG_TARGET_DEFAULT ,
@@ -148,6 +152,9 @@ bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
148152 case 'S' :
149153 cmdline -> vhost_user_snd_socket = optarg ;
150154 break ;
155+ case 'K' :
156+ cmdline -> vhost_user_vsock_socket = optarg ;
157+ break ;
151158 case '?' :
152159 return false;
153160 default :
@@ -298,6 +305,24 @@ int main(int argc, char *const argv[])
298305 printf ("Using vhost-user sound backend at %s\n" , cmdline .vhost_user_snd_socket );
299306 }
300307
308+ // Configure vhost-user vsock if requested
309+ if (cmdline .vhost_user_vsock_socket != NULL ) {
310+ // Disable the implicit vsock device to avoid conflict
311+ if (!check_krun_error (krun_disable_implicit_vsock (ctx_id ),
312+ "Error disabling implicit vsock" )) {
313+ return -1 ;
314+ }
315+
316+ if (!check_krun_error (krun_add_vhost_user_device (ctx_id , KRUN_VIRTIO_DEVICE_VSOCK ,
317+ cmdline .vhost_user_vsock_socket , NULL ,
318+ KRUN_VHOST_USER_VSOCK_NUM_QUEUES ,
319+ KRUN_VHOST_USER_VSOCK_QUEUE_SIZES ),
320+ "Error adding vhost-user vsock device" )) {
321+ return -1 ;
322+ }
323+ printf ("Using vhost-user vsock backend at %s\n" , cmdline .vhost_user_vsock_socket );
324+ }
325+
301326 // Raise RLIMIT_NOFILE to the maximum allowed to create some room for virtio-fs
302327 getrlimit (RLIMIT_NOFILE , & rlim );
303328 rlim .rlim_cur = rlim .rlim_max ;
@@ -318,7 +343,8 @@ int main(int argc, char *const argv[])
318343 }
319344
320345 // Map port 18000 in the host to 8000 in the guest (if networking uses TSI)
321- if (cmdline .net_mode == NET_MODE_TSI ) {
346+ // Skip port mapping when using vhost-user-vsock (TSI requires built-in vsock)
347+ if (cmdline .net_mode == NET_MODE_TSI && cmdline .vhost_user_vsock_socket == NULL ) {
322348 if (err = krun_set_port_map (ctx_id , & port_map [0 ])) {
323349 errno = - err ;
324350 perror ("Error configuring port map" );
0 commit comments