Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vsock: use local transport when it is loaded

Now that we have a transport that can handle the local communication,
we can use it when it is loaded.

A socket will use the local transport (loopback) when the remote
CID is:
- equal to VMADDR_CID_LOCAL
- or equal to transport_g2h->get_local_cid(), if transport_g2h
is loaded (this allows us to keep the same behavior implemented
by virtio and vmci transports)
- or equal to VMADDR_CID_HOST, if transport_g2h is not loaded

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Stefano Garzarella and committed by
David S. Miller
408624af 077263fb

+23 -5
+23 -5
net/vmw_vsock/af_vsock.c
··· 388 388 } 389 389 EXPORT_SYMBOL_GPL(vsock_enqueue_accept); 390 390 391 + static bool vsock_use_local_transport(unsigned int remote_cid) 392 + { 393 + if (!transport_local) 394 + return false; 395 + 396 + if (remote_cid == VMADDR_CID_LOCAL) 397 + return true; 398 + 399 + if (transport_g2h) { 400 + return remote_cid == transport_g2h->get_local_cid(); 401 + } else { 402 + return remote_cid == VMADDR_CID_HOST; 403 + } 404 + } 405 + 391 406 static void vsock_deassign_transport(struct vsock_sock *vsk) 392 407 { 393 408 if (!vsk->transport) ··· 419 404 * (e.g. during the connect() or when a connection request on a listener 420 405 * socket is received). 421 406 * The vsk->remote_addr is used to decide which transport to use: 407 + * - remote CID == VMADDR_CID_LOCAL or g2h->local_cid or VMADDR_CID_HOST if 408 + * g2h is not loaded, will use local transport; 422 409 * - remote CID <= VMADDR_CID_HOST will use guest->host transport; 423 - * - remote CID == local_cid (guest->host transport) will use guest->host 424 - * transport for loopback (host->guest transports don't support loopback); 425 410 * - remote CID > VMADDR_CID_HOST will use host->guest transport; 426 411 */ 427 412 int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk) ··· 436 421 new_transport = transport_dgram; 437 422 break; 438 423 case SOCK_STREAM: 439 - if (remote_cid <= VMADDR_CID_HOST || 440 - (transport_g2h && 441 - remote_cid == transport_g2h->get_local_cid())) 424 + if (vsock_use_local_transport(remote_cid)) 425 + new_transport = transport_local; 426 + else if (remote_cid <= VMADDR_CID_HOST) 442 427 new_transport = transport_g2h; 443 428 else 444 429 new_transport = transport_h2g; ··· 479 464 return true; 480 465 481 466 if (transport_h2g && cid == VMADDR_CID_HOST) 467 + return true; 468 + 469 + if (transport_local && cid == VMADDR_CID_LOCAL) 482 470 return true; 483 471 484 472 return false;