Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vsock: Implement sibling VM communication #370

Merged
merged 4 commits into from
Jul 3, 2023

Conversation

techiepriyansh
Copy link
Contributor

Adds support for communication between sibling VMs that use the vhost-user-vsock devices from the same vhost-user-vsock application.

Copy link
Member

@stefano-garzarella stefano-garzarella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

I left several minor comments. I recommend that you add an example of how you tested the patch in the commit message.

Another thing I think we should put in is something to decide whether 2 VMs should communicate or not.
One idea would be to add a new "group" parameter to each VM and have only the VMs in the same "group" communicate.

Obviously we can do that later, but I wanted to tell you before I forget.

crates/vsock/src/main.rs Outdated Show resolved Hide resolved
crates/vsock/src/main.rs Outdated Show resolved Hide resolved
crates/vsock/src/main.rs Outdated Show resolved Hide resolved
crates/vsock/src/thread_backend.rs Show resolved Hide resolved
crates/vsock/src/thread_backend.rs Outdated Show resolved Hide resolved
crates/vsock/src/vhu_vsock.rs Outdated Show resolved Hide resolved
crates/vsock/src/vhu_vsock.rs Outdated Show resolved Hide resolved
crates/vsock/src/vhu_vsock_thread.rs Outdated Show resolved Hide resolved
crates/vsock/src/vhu_vsock_thread.rs Outdated Show resolved Hide resolved
@stefano-garzarella
Copy link
Member

Ah I think we should extend the README and say if you add more VMs they can communicate with each other.

Another thing I have to check now that we have more VMs, is that the packets received from a VM have the right src_cid, otherwise one might impersonate another.

I think we didn't have this check before, but now we should since we have more VMs.

@techiepriyansh techiepriyansh force-pushed the sibling-vm-communication branch 2 times, most recently from 214a648 to 4477490 Compare June 23, 2023 08:29
@techiepriyansh
Copy link
Contributor Author

I recommend that you add an example of how you tested the patch in the commit message.

For testing, I used https://github.com/stefanha/nc-vsock/blob/master/nc-vsock.c with this patch:

diff --git a/nc-vsock.c b/nc-vsock.c
index 1704151..beda0fc 100644
--- a/nc-vsock.c
+++ b/nc-vsock.c
@@ -146,6 +146,7 @@ static int vsock_connect(const char *cid_str, const char *port_str)
 	int port;
 	struct sockaddr_vm sa = {
 		.svm_family = AF_VSOCK,
+		.svm_flags = VMADDR_FLAG_TO_HOST,
 	};
 
 	cid = parse_cid(cid_str);

Should I mention all this in the commit message, or should I make a fork with this patch applied and then link to it?

@stefano-garzarella
Copy link
Member

I recommend that you add an example of how you tested the patch in the commit message.

Should I mention all this in the commit message, or should I make a fork with this patch applied and then link to it?

Should be fine something like:

Tested with nc-vsock patched to set `.svm_flags = VMADDR_FLAG_TO_HOST`:
  host$ ./vhost-user-vsock .....
  
  vm1$ nc-vsock ...
  vm2$ nc-vsock ...

@techiepriyansh
Copy link
Contributor Author

I am getting a cargo audit error in the checks. Should I commit the rebuilt cargo lock file by running cargo generate-lockfile in this PR itself?

@stefano-garzarella
Copy link
Member

I am getting a cargo audit error in the checks. Should I commit the rebuilt cargo lock file by running cargo generate-lockfile in this PR itself?

Do you have the same issue on the main branch?

If it is the case, will be better to have another PR.
Instead, if it is related to these changes, it is fine to do in this PR.

@techiepriyansh
Copy link
Contributor Author

Do you have the same issue on the main branch?

Yes

If it is the case, will be better to have another PR.

Okay

@techiepriyansh
Copy link
Contributor Author

I've created the PR fixing cargo audit errors over at #371.

@techiepriyansh techiepriyansh force-pushed the sibling-vm-communication branch 2 times, most recently from fee5af1 to 43d8514 Compare June 23, 2023 14:27
@techiepriyansh
Copy link
Contributor Author

Rebased over main now that #371 has been merged.

@stefano-garzarella
Copy link
Member

@techiepriyansh the final result LGTM!

The only thing I'd suggest is to reorganize the commits, I'd move the new 2 commits, before the one that adds support for communication between multiple VMs, so we don't add code (e.g. cid_map) that we edit right after that.

@techiepriyansh
Copy link
Contributor Author

I've now moved the commit handling the single VM case same as multiple VMs before the commit implementing sibling VM communication. I've not moved the commit checking the packet source CID yet because I think it makes more sense to put it afterwards, but do let me know if I need to move it back too.

@stefano-garzarella
Copy link
Member

I've now moved the commit handling the single VM case same as multiple VMs before the commit implementing sibling VM communication. I've not moved the commit checking the packet source CID yet because I think it makes more sense to put it afterwards, but do let me know if I need to move it back too.

LGTM!

In future, we could add the ability to change the configuration at runtime
and allow new guests to be added even without having to restart the
daemon. So it is reasonable to not differentiate between the single and
multiple VM cases, even with only one guest.

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
Adds support for communication between sibling VMs that use the
vhost-user-vsock devices from the same vhost-user-vsock application.

Tested with nc-vsock patched to set `.svm_flags = VMADDR_FLAG_TO_HOST`:

host$ vhost-user-vsock \
      --vm guest-cid=3,uds-path=/tmp/vm3.vsock,socket=/tmp/vhost3.socket \
      --vm guest-cid=4,uds-path=/tmp/vm4.vsock,socket=/tmp/vhost4.socket

vm_cid3$ nc-vsock -l 1234
vm_cid4$ nc-vsock 3 1234

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
Cross-check the packet `src_cid` with the CID configured for the guest.
This will forbid a VM from impersonating another.

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
@vireshk vireshk enabled auto-merge (rebase) July 3, 2023 05:59
@vireshk vireshk merged commit 4346438 into rust-vmm:main Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants