Linux-HyperV List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sergio Lopez" <slp@redhat.com>
Cc: virtualization@lists.linux.dev, kvm@vger.kernel.org,
	bpf@vger.kernel.org, linux-hyperv@vger.kernel.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH RFC v4 8/8] vsock: add datagram tests to vsock_test
Date: Tue, 24 Nov 2026 12:47:32 +0000	[thread overview]
Message-ID: <sashiko-outbox-231174@kernel.org> (raw)
In-Reply-To: <20261124-vsock-dgram-support-v4-8-3607484e85e8@redhat.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] vsock_test: vsock_dgram_check_vmci_host() skips when
  vhost_vsock is unloaded
- [Medium] vsock_test: local CID tests fail when VMCI coexists with
  vhost and loopback
--

commit 792ed67e2ec454b7d9e33e144a3b395a0eb9843c
Author: Sergio Lopez <slp@redhat.com>

vsock: add datagram tests to vsock_test

This commit adds SOCK_DGRAM test cases to vsock_test covering local
loopback semantics, host/guest transfers, transport routing, and queue
accounting, along with capability-based skip checks and a --local mode.

> diff --git a/tools/testing/vsock/vsock_test_dgram.c b/tools/testing/vsock/vsock_test_dgram.c
> new file mode 100644
> index 0000000000000..16c3a6e59f792
> --- /dev/null
> +++ b/tools/testing/vsock/vsock_test_dgram.c

[ ... ]

> +static bool usable_local_cid(void)
> +{
> +	unsigned int cid;
> +	int fd, ret;
> +
> +	fd = open("/dev/vsock", O_RDONLY | O_CLOEXEC);
> +	if (fd < 0)
> +		return false;
> +	ret = ioctl(fd, IOCTL_VM_SOCKETS_GET_LOCAL_CID, &cid);
> +	close(fd);
> +	return ret == 0 && cid != VMADDR_CID_ANY && cid > VMADDR_CID_LOCAL;
> +}

[Severity: Medium]
Can usable_local_cid() enable the local-CID loopback tests when VMCI owns
VMADDR_CID_HOST?

When vhost_vsock, vsock_loopback, and vmw_vsock_vmci_transport are loaded
together in a global namespace without a guest-to-host transport,
IOCTL_VM_SOCKETS_GET_LOCAL_CID returns VMADDR_CID_HOST (from vhost_vsock),
so vsock_dgram_check_local_cid() enables test_dgram_bound_lookup() and
test_dgram_connected_cid().  However, VMCI is the datagram owner in a
global namespace and its local CID is also VMADDR_CID_HOST, so
vsock_select_transport() routes packets addressed to VMADDR_CID_HOST
through vmci_transport instead of vsock_loopback.

As a result, test_dgram_bound_lookup() fails with EADDRNOTAVAIL when
sending from a socket bound to VMADDR_CID_LOCAL to one bound to
VMADDR_CID_HOST, and test_dgram_connected_cid() times out because the
receiver connects to VMADDR_CID_HOST (selecting vmci_transport) while the
packet arrives over loopback_transport and is dropped by
virtio_transport_dgram_source_allow().

[ ... ]

> +const char *vsock_dgram_check_vmci_host(const struct test_opts *opts)
> +{
> +	unsigned int caps = dgram_capabilities(opts, 0);
> +	unsigned int cid;
> +	char mode[16];
> +	FILE *file;
> +	int fd;
> +
> +	if (!(caps & DGRAM_SOCKET))
> +		return "datagrams unavailable locally";
> +	if (!(caps & DGRAM_VMCI_MODULE))
> +		return "requires VMCI datagram transport";
> +
> +	file = fopen("/proc/sys/net/vsock/ns_mode", "r");
> +	if (!file)
> +		return "requires a mounted vsock namespace sysctl";
> +	if (!fgets(mode, sizeof(mode), file)) {
> +		fclose(file);
> +		return "cannot read vsock namespace mode";
> +	}
> +	fclose(file);
> +	if (strncmp(mode, "global", 6))
> +		return "requires a global vsock namespace";
> +
> +	fd = open("/dev/vsock", O_RDONLY | O_CLOEXEC);
> +	if (fd < 0)
> +		return "cannot open /dev/vsock";
> +	if (ioctl(fd, IOCTL_VM_SOCKETS_GET_LOCAL_CID, &cid)) {
> +		close(fd);
> +		return "cannot read local CID";
> +	}
> +	close(fd);
> +	if (cid != VMADDR_CID_HOST)
> +		return "requires VMCI host CID without an active guest CID";
> +	return NULL;
> +}

[Severity: Medium]
Does checking IOCTL_VM_SOCKETS_GET_LOCAL_CID == VMADDR_CID_HOST skip
test_dgram_vmci_host_routes() whenever vhost_vsock is unloaded and no
/dev/vmci host context is active?

Loading vmw_vsock_vmci_transport only registers transport_dgram_fallback;
vmci_register_vsock_callback() registers transport_h2g only while
vmci_host_users() > 0.  Because vsock_dev_do_ioctl() queries only
transport_g2h, transport_h2g, and transport_local for
IOCTL_VM_SOCKETS_GET_LOCAL_CID (never transport_dgram_fallback), the ioctl
returns VMADDR_CID_ANY or VMADDR_CID_LOCAL when vhost_vsock is not loaded,
causing vsock_dgram_check_vmci_host() to skip the test even though VMCI
host datagram sockets can bind and send to VMADDR_CID_HOST.

Instead of requiring the ioctl to return VMADDR_CID_HOST, could this verify
that the ioctl does not return a guest CID (> VMADDR_CID_HOST) and probe
binding a datagram socket to VMADDR_CID_HOST?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-vsock-dgram-support-v4-0-3607484e85e8@redhat.com?part=8

      reply	other threads:[~2026-11-24 12:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 12:20 [PATCH RFC v4 0/8] vsock: add datagram support to virtio and vhost Sergio Lopez
2026-11-24 12:20 ` [PATCH RFC v4 1/8] vsock: expose the core port allocator to transports Sergio Lopez
2026-11-24 12:20 ` [PATCH RFC v4 2/8] vsock: report datagram receive and send queue state Sergio Lopez
2026-11-24 12:20 ` [PATCH RFC v4 3/8] vsock/virtio: implement the datagram data path Sergio Lopez
2026-11-24 12:20 ` [PATCH RFC v4 4/8] vsock/virtio: negotiate datagram support on the guest Sergio Lopez
2026-11-24 12:20 ` [PATCH RFC v4 5/8] vhost/vsock: negotiate datagram support with guests Sergio Lopez
2026-11-24 12:20 ` [PATCH RFC v4 6/8] vsock: allow datagrams to use directional transports Sergio Lopez
2026-11-24 12:44   ` sashiko-bot
2026-11-24 12:20 ` [PATCH RFC v4 7/8] vsock: fragment datagrams across receive buffers Sergio Lopez
2026-11-24 12:20 ` [PATCH RFC v4 8/8] vsock: add datagram tests to vsock_test Sergio Lopez
2026-11-24 12:47   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-231174@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=eperezma@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=slp@redhat.com \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox