Skip to content

Commit 408624a

Browse files
stefano-garzarelladavem330
authored andcommitted
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>
1 parent 077263f commit 408624a

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

‎net/vmw_vsock/af_vsock.c‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,21 @@ void vsock_enqueue_accept(struct sock *listener, struct sock *connected)
388388
}
389389
EXPORT_SYMBOL_GPL(vsock_enqueue_accept);
390390

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+
391406
static void vsock_deassign_transport(struct vsock_sock *vsk)
392407
{
393408
if (!vsk->transport)
@@ -404,9 +419,9 @@ static void vsock_deassign_transport(struct vsock_sock *vsk)
404419
* (e.g. during the connect() or when a connection request on a listener
405420
* socket is received).
406421
* The vsk->remote_addr is used to decide which transport to use:
422+
* - remote CID == VMADDR_CID_LOCAL or g2h->local_cid or VMADDR_CID_HOST if
423+
* g2h is not loaded, will use local transport;
407424
* - remote CID <= VMADDR_CID_HOST will use guest->host transport;
408-
* - remote CID == local_cid (guest->host transport) will use guest->host
409-
* transport for loopback (host->guest transports don't support loopback);
410425
* - remote CID > VMADDR_CID_HOST will use host->guest transport;
411426
*/
412427
int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
@@ -421,9 +436,9 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
421436
new_transport = transport_dgram;
422437
break;
423438
case SOCK_STREAM:
424-
if (remote_cid <= VMADDR_CID_HOST ||
425-
(transport_g2h &&
426-
remote_cid == transport_g2h->get_local_cid()))
439+
if (vsock_use_local_transport(remote_cid))
440+
new_transport = transport_local;
441+
else if (remote_cid <= VMADDR_CID_HOST)
427442
new_transport = transport_g2h;
428443
else
429444
new_transport = transport_h2g;
@@ -466,6 +481,9 @@ bool vsock_find_cid(unsigned int cid)
466481
if (transport_h2g && cid == VMADDR_CID_HOST)
467482
return true;
468483

484+
if (transport_local && cid == VMADDR_CID_LOCAL)
485+
return true;
486+
469487
return false;
470488
}
471489
EXPORT_SYMBOL_GPL(vsock_find_cid);

0 commit comments

Comments
 (0)