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

Add AF_VSOCK support #47

Merged
merged 11 commits into from Oct 7, 2021
Merged

Add AF_VSOCK support #47

merged 11 commits into from Oct 7, 2021

Conversation

stefano-garzarella
Copy link
Contributor

The VSOCK address family facilitates communication between virtual machines and the host they are running on.
AF_VSOCK currently support STREAM, SEQPACKET. DGRAM support is WiP.

The addressing is formed by 2 integers: <CID, port>

  • CID: Context ID, it is the ID assigned to the VM
    0, 1, 2 CIDs are reserved:
    0 - hypervisor CID (rarely used)
    1 - local communication (loopback)
    2 - host CID (the guest can always reach the host using CID=2)

  • port: port number on 32bit to reach a specific process

Added also tests using the vsock_loopback kernel module on a single host.
This module (Linux v5.8+) allows to use AF_VSOCK on a single host, without spawning a VM.

Other info and examples of AF_VSOCK (socat, iperf, python, etc.) are summarized in this 2 talks:

@realneel
Copy link
Collaborator

@stefano-garzarella Thanks for the PR.

@tuexen Do you have some time to review this?

@tuexen
Copy link
Collaborator

tuexen commented Sep 27, 2021

@stefano-garzarella Thanks for the PR.

@tuexen Do you have some time to review this?

I can take a look at it next week or so, but I'm no familiar with Linux and VSOCK in particular.

@ldoktor
Copy link

ldoktor commented Sep 29, 2021

Thanks @stefano-garzarella for adding the support for vsock to uperf I mean to use it in our testing. I gave it a quick functional try and following setup worked well for me:

Note the opposite direction (running -s on host) failed with 2 says: Error creating ports: Interrupted system call (full details sent directly to Stefano) so beware of this limitation while reviewing this PR. Anyway function-wise this PR seems to work well for me and I am really interested in getting this to the mainline.

@stefano-garzarella
Copy link
Contributor Author

@ldoktor thanks for testing and reporting the issues.

Note the opposite direction (running -s on host) failed with 2 says: Error creating ports: Interrupted system call (full details sent directly to Stefano) so beware of this limitation while reviewing this PR. Anyway function-wise this PR seems to work well for me and I am really interested in getting this to the mainline.

I should fixed this one, the problem was that vsock uses unsigned int port numbers, so uperf can fail with "Error creating ports:" error message also if everything is fine.
The last commit of this PR should fix the issues checking UPERF_FAILURE (-1) instead of negative return value for p->listen(). This should work well, since we always return that value on failure and vsock ports -1 is reserved (VMADDR_PORT_ANY).

@ldoktor
Copy link

ldoktor commented Sep 29, 2021

@stefano-garzarella thank you, this version seem to address the issue mentioned earlier.

Copy link
Collaborator

@realneel realneel left a comment

Choose a reason for hiding this comment

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

Looks good to me

src/main.c Outdated Show resolved Hide resolved
src/vsock.c Outdated Show resolved Hide resolved
src/vsock.c Outdated Show resolved Hide resolved
The new `-S` command line option, allow to specify the protocol type
to use for the control socket.

This is necessary for vsock, where we don't have TCP available to
connect to the remote host.
The  VSOCK  address family facilitates communication between virtual
machines and the host they are running on.

The addressing is formed by 2 integers: <CID, port>
- CID: Context ID, it is the ID assigned to the VM
  0, 1, 2 CIDs are reserved:
  0 - hypervisor CID (rarely used)
  1 - local communication (loopback)
  2 - host CID (the guest can always reach the host using CID=2)

- port: port number on 32bit to reach a specific process
vsock tests don't support h="localhost" and need to use vsock
also for the control socket.

We enable these things for all tests that end with *.vsock.xml
You have to run also `uperf -s -S vsock` in the background before
running `make check` when vsock is enabled.
vsock uses unsigned int port numbers, so uperf can fail with
"Error creating ports:" error message also if everything is
fine.

Let's check UPERF_FAILURE (-1) instead of negative return value,
since we always return that value on failure and vsock ports -1
is reserved (VMADDR_PORT_ANY).

Reported-by: Lukáš Doktor <ldoktor@redhat.com>
@stefano-garzarella
Copy link
Contributor Author

@tuexen thanks for the review! I just pushed the fixes.

@tuexen tuexen merged commit 87a0468 into uperf:master Oct 7, 2021
@tuexen
Copy link
Collaborator

tuexen commented Oct 7, 2021

Merged. Thanks for addressing my issues.

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.

None yet

4 participants