Re: [External] Re: [PATCH 0/4] Add multi-cid support for vsock driver

From: Stefano Garzarella
Date: Wed Aug 04 2021 - 11:25:02 EST


On Wed, Aug 04, 2021 at 03:09:41PM +0800, 傅关丞 wrote:
Sorry I cannot figure out a good use case.

It is normal for a host to have multiple ip addresses used for
communication.
So I thought it might be nice to have both host and guest use multiple
CIDs for communication.
I know this is not a very strong argument.

Maybe there could be a use case for guests (which I don't see now), but for the host it seems pointless. The strength of vsock is that the guest knows that using CID=2 always reaches the host.

Moreover we have recently merged VMADDR_FLAG_TO_HOST that when set allows you to forward any packet to the host, regardless of the CID (not yet supported by vhost-vsock).


The vsock driver does not work if one of the two peers doesn't support
multiple CIDs.

This is absolutely to be avoided.

I think the virtio device feature negotiation can help here.


I have a possible solution here, but there may be some problems with it
that I haven't noticed.

Hypervisors will use different ways to send CIDs setup to the kernel based
on their vsock setup.

------For host-------
If host vsock driver supports multi-cid, the hypervisor will use the
modified VHOST_VSOCK_SET_GUEST_CID call to set its CIDs.
Otherwise, the original call is used.

------For guest-------
Now the virtio_vsock_config looks like this:
u64 guest_cid
u32 num_guest_cid;
u32 num_host_cid;
u32 index;
u64 cid;

If the guest vsock driver supports multi-cid, it will read num_guest_cid
and num_host_cid from the device config space.
Then it writes an index register, which is the cid it wants to read. After
hypervisors handle this issue, it can read the cid
from the cid register.

If it does not support multi-cid, it will just read the guest_cid from the
config space, which should work just fine.


Why not add a new device feature to enable or disable multi-cid?



-------Communication--------
For communication issues, we might need to use a new feature bit. Let's
call it VHOST_VSOCK_SUPPORT_MULTI_CID.
The basic idea is that this feature bit is set when both host and guest
support using multiple CIDs. After negotiation, if the feature bit
is set, the host can use all the CIDs specified to communicate with the
guest. Otherwise, the first cid passed in will
be used as the guest_cid to communicate with guests.

I think the same feature bit can be used for the virtio_vsock_config, no?


Also, if the bit is set for guests, all the CIDs can be used to communicate
with the host. Otherwise, the first cid with index 0 will be
used as the guest_cid while the VMADDR_HOST_CID will be used for host cid.

We already have VMADDR_FLAG_TO_HOST to forward all packets to the host, we only need to support in some way in vhost-vsock.

Thanks,
Stefano