Conversation
stefano-garzarella
left a comment
There was a problem hiding this comment.
Thanks for this PR, I did a quick review and left some comments.
I'll think a bit more about Transport implementation and Vsock, since I'd like to have more abstraction (e.g. be ready to support a new driver for HyperV vsock)
e0d157e to
82976c4
Compare
|
v2:
TODO:
|
82976c4 to
08ff85f
Compare
|
v3:
TODO:
|
08ff85f to
9f5553e
Compare
|
v4:
TODO:
|
ca7e076 to
3bc1d0b
Compare
|
v5:
TODO:
|
|
Looks like CI runner fails to create a vsock listening socket using ncat |
3bc1d0b to
f9a59be
Compare
|
Fixed CI failure. |
f9a59be to
31df19c
Compare
|
161527b to
ef04aef
Compare
|
|
@luigix25 since we merged #948 , can you rebase this and check Merging main or rebasing on it, produces this error (I guess related to #948 changes): |
ef04aef to
a14dca2
Compare
|
Addressed all @stefano-garzarella comments:
|
| for _ in 0..MAX_RETRIES { | ||
| let candidate_port = | ||
| self.first_free_port | ||
| .fetch_update(Ordering::Relaxed, Ordering::Relaxed, |port| { |
There was a problem hiding this comment.
I'm not sure about this, I'd like some feedback from someone with more experience
kernel/src/vsock/mod.rs
Outdated
| if port >= u32::MAX - 1 { | ||
| Some(VSOCK_MIN_PORT) | ||
| } else { | ||
| Some(port + 1) | ||
| } |
There was a problem hiding this comment.
could you explain this logic?, is the port u32::MAX reserved?, and if all the ports are assigned, so I'll assume that also VSOCK_MIN_PORT is already assigned why is re-assigned. It's just confusing because that closure never fails (returning None I mean)
There was a problem hiding this comment.
could you explain this logic?, is the port u32::MAX reserved?
correct!
so I'll assume that also VSOCK_MIN_PORT is already assigned why is re-assigned. It's just confusing >because that closure never fails (returning None I mean)
Ports can be reused. The idea is that we use the ports sequentially up to u32::MAX, then we start again from VSOCK_MIN_PORT. So yes, in theory port 1024 can be still in use, this is why there is a check and a retry mechanism. But in the meanwhile the connection on those ports could be ended, and it could be used again.
There was a problem hiding this comment.
up to u32::MAX
sorry, just to confirm, can you have an u32::MAX port?
There was a problem hiding this comment.
u32::MAX is reserved
There was a problem hiding this comment.
IIRC in Linux we defined VMADDR_PORT_ANY for that, can we define here those well-know port/cid and use them, instead of hard coding their values ?
a14dca2 to
0dd8620
Compare
|
Define a VsockTransport trait to abstract vsock operations and enable multiple backend implementations. Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Commit c4719d3 dropped driver support for virtio-vsock because it was not being used. This reverts this commit because we are introducing vsock support. This revert does not add back the examples/aarch64/main.rs file as it is not needed. Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Apply lints suggested by clippy. Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
The connection status is not tracked in the `Connection` struct, so there is no way to check whether the handshake has completed. Introduce the `established` field and set it when a `Connected` or `ConnectionRequest` event is successfully handled. Expose it via `is_connection_established()`. Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
`send()` and `update_credit()` do not check whether the peer has requested shutdown, allowing operations on a connection that the peer considers closed. Check `peer_requested_shutdown` before proceeding in both methods. Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Add a function that checks if a local port is in use, either for listening or for a connection. This will be used by VsockDriver to allocate local ports when creating new streams. Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Add a virtio-vsock wrapper around virtio-drivers. It provides blocking functions for connect, send, recv, shutdown and force_shutdown. To use it you need the `vsock` feature. Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Add VsockStream struct that provides a high-level stream-oriented interface over the vsock driver API. Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Add an optional `--vsock cid` parameter. This will attach a virtio-vsock device to the VM. Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
0dd8620 to
3dcc259
Compare
In preparation to vsock support, QEMU needs to be configured with vhost support enabled. Without the flag `--enable-vhost-kernel`, QEMU would fail to launch with error: `qemu-system-x86_64: -device vhost-vsock-device,guest-cid=3: 'vhost-vsock-device' is not a valid device model name` This flag is disabled by default because of `--without-default-features` Because no-cc is run as non-root, this causes QEMU to fail with the error: `vhost-vsock: failed to open vhost device: Permission denied"` To fix this, setup permissions to /dev/vhost-vsock for non-root. Add the flag to enable support for vsock in QEMU and install netcat Co-Developed-by: Luigi Leonardi <leonardi@redhat.com> Signed-off-by: Luigi Leonardi <leonardi@redhat.com> Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Add a test that performs some basic checks on vsock functionalities: - double connection - recv a buffer from the host - send a buffer to the host - recv a buffer after local shutdown - send a buffer after local shutdown The vsock server is created on the host using ncat. Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
3dcc259 to
831ed1c
Compare
|
Fixed CI failure because no-cc by default is now run as non-root and |
This PR introduces a wrapper to the virtio-drivers crate like what has been done for virtio-blk. This provides blocking calls to
connectclosesendandrecv.Vsock is more flexible than the serial port as it has the concept of port, and we can reuse vsock for anything else.
I had to make 2 changes to the virtio-drivers crate, the idea is to open a PR in that repo. Before proceeding with the PR, I'd like to take some feedback here, maybe more changes are needed.
To compile it you need to enable the feature
vsockandvirtio-drivers.To test it you can use
make test-in-svsmNote: If a vsock device is not attached, svsm will not crash.