From nobody Tue Oct 7 18:26:08 2025 Received: from out198-25.us.a.mail.aliyun.com (out198-25.us.a.mail.aliyun.com [47.90.198.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABBD42248BE; Tue, 8 Jul 2025 06:36:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=47.90.198.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751956619; cv=none; b=BtfFUelwAWUtnbSK+lGutF6KnIHMihxyGrvEtxJVf2I17nW5Mh04icKKDp3DCP+30kpNrf34+W22GyaGX4f/X8Xinv/PwclCP/4iGtNXrSbbxio9jnlLR17GIAj+0IiTPaNj4hTY3JeQJkV8Y9Me5xgbfaa/Nsw807cdSaD5dM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751956619; c=relaxed/simple; bh=/smSTVBOTYXd206lVwYMeJLOzk2Z6oW8Q2vy5QxlzrA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LKUIGBYjCgWWubx/hislOjnb4eXuXhKeXuOsZ8c5O/ew2rYG776TP/CkVrhGbjZVhg7iTJC1LtumJ1HX0FPKOYxYZx3S7l3evpW13d3dLok/NkcrPzt2sElxO0C6KvGv9J+q+/8/s0fw1H2aIzxwA6uVPvvyInO7I1d7BXCQr/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=AF3fixyn; arc=none smtp.client-ip=47.90.198.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="AF3fixyn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1751956603; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=BWrbRfuOAO4JIUdkE1HlpoBHmDvPPs8uqWlIP2joYso=; b=AF3fixynQCtgGLiCbQh54F9QWqaniJh5/Oa1MNV91PxOheAb6CyM1xgcSPRlG0dHmgeG64ZzBwSdiPj5AElSm9kdRqr6+09oFqhll0O2wZ3KilJi70zuRP0WS4/kz30nm7DS058xbWEzdZcFzp/Z2ia0AdCU2wOqWG9uz01bTnY= Received: from 127.0.0.1(mailfrom:niuxuewei.nxw@antgroup.com fp:SMTPD_---.dhGPAbr_1751956601 cluster:ay29) by smtp.aliyun-inc.com; Tue, 08 Jul 2025 14:36:43 +0800 From: Xuewei Niu Date: Tue, 08 Jul 2025 14:36:11 +0800 Subject: [PATCH net-next v6 1/4] hv_sock: Return the readable bytes in hvs_stream_has_data() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250708-siocinq-v6-1-3775f9a9e359@antgroup.com> References: <20250708-siocinq-v6-0-3775f9a9e359@antgroup.com> In-Reply-To: <20250708-siocinq-v6-0-3775f9a9e359@antgroup.com> To: "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Xuewei Niu , niuxuewei97@gmail.com X-Mailer: b4 0.14.2 From: Dexuan Cui When hv_sock was originally added, __vsock_stream_recvmsg() and vsock_stream_has_data() actually only needed to know whether there is any readable data or not, so hvs_stream_has_data() was written to return 1 or 0 for simplicity. However, now hvs_stream_has_data() should return the readable bytes because vsock_data_ready() -> vsock_stream_has_data() needs to know the actual bytes rather than a boolean value of 1 or 0. The SIOCINQ ioctl support also needs hvs_stream_has_data() to return the readable bytes. Let hvs_stream_has_data() return the readable bytes of the payload in the next host-to-guest VMBus hv_sock packet. Note: there may be multiple incoming hv_sock packets pending in the VMBus channel's ringbuffer, but so far there is not a VMBus API that allows us to know all the readable bytes in total without reading and caching the payload of the multiple packets, so let's just return the readable bytes of the next single packet. In the future, we'll either add a VMBus API that allows us to know the total readable bytes without touching the data in the ringbuffer, or the hv_sock driver needs to understand the VMBus packet format and parse the packets directly. Signed-off-by: Dexuan Cui Signed-off-by: Xuewei Niu Acked-by: Stefano Garzarella Acked-by: Wei Liu --- net/vmw_vsock/hyperv_transport.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transp= ort.c index 31342ab502b4fc35feb812d2c94e0e35ded73771..432fcbbd14d4f44bd2550be8376= e42ce65122758 100644 --- a/net/vmw_vsock/hyperv_transport.c +++ b/net/vmw_vsock/hyperv_transport.c @@ -694,15 +694,26 @@ static ssize_t hvs_stream_enqueue(struct vsock_sock *= vsk, struct msghdr *msg, static s64 hvs_stream_has_data(struct vsock_sock *vsk) { struct hvsock *hvs =3D vsk->trans; + bool need_refill; s64 ret; =20 if (hvs->recv_data_len > 0) - return 1; + return hvs->recv_data_len; =20 switch (hvs_channel_readable_payload(hvs->chan)) { case 1: - ret =3D 1; - break; + need_refill =3D !hvs->recv_desc; + if (!need_refill) + return -EIO; + + hvs->recv_desc =3D hv_pkt_iter_first(hvs->chan); + if (!hvs->recv_desc) + return -ENOBUFS; + + ret =3D hvs_update_recv_data(hvs); + if (ret) + return ret; + return hvs->recv_data_len; case 0: vsk->peer_shutdown |=3D SEND_SHUTDOWN; ret =3D 0; --=20 2.34.1 From nobody Tue Oct 7 18:26:08 2025 Received: from out28-73.mail.aliyun.com (out28-73.mail.aliyun.com [115.124.28.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B54811E48A; Tue, 8 Jul 2025 06:36:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751956610; cv=none; b=poRUIEIIakfq46pBUxeEcbmJ85N//lwkTZE0Upu1/ZagBUO7PgfU85cv/7n2UJPdTlXTJDqcPf2VRXuXlCXV3qkjfFrSOtlM9Gp/kDJfF8hajBD74xhVamCm32Qqshb3Y4Og8DijKEGc8BaNMKz4Ab2TTGACDlQAQEBhCfsCZmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751956610; c=relaxed/simple; bh=lrNsByWI4+JZUOhPSorgBp0TBt5xNkaU5kzScC5uvPo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sfTXSjFFjwTR84i2KMzEP3MBxPudinvo27hZxafo9LBTNI2g5cxppgBwO0/Byd01JwwFbnPcR+RlGfkP7O8xSUfQPwka6tb0z+mVbUxFJEWZ9SDK7woy6EVmBVGyLqjdN3+DeKZjD6R4zZHtUAddB2cJ0joWKbt+js1o0Z9k8JI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=H+8QSoGf; arc=none smtp.client-ip=115.124.28.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="H+8QSoGf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1751956605; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=enAMJL6mb/z9WNfWVziA8KCdR5RF2FfP9GwDXl38f/E=; b=H+8QSoGfmlSGIIxJeJ7pYnYimR+DcyuUI9Fd2F39PUDxk8fu1TO5DxD0Thn/Fv/HX97NCpIZm08Ebytje96Bg/dyKu6L7qU1YcnxODl4Cu617wk1gUnFZ0F/gOQ8n6IGyUt1jkcCW7uhfq33uijmm3JABNV/XP/a78Wj1BBIueU= Received: from 127.0.0.1(mailfrom:niuxuewei.nxw@antgroup.com fp:SMTPD_---.dhGPAe-_1751956603 cluster:ay29) by smtp.aliyun-inc.com; Tue, 08 Jul 2025 14:36:44 +0800 From: Xuewei Niu Date: Tue, 08 Jul 2025 14:36:12 +0800 Subject: [PATCH net-next v6 2/4] vsock: Add support for SIOCINQ ioctl Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250708-siocinq-v6-2-3775f9a9e359@antgroup.com> References: <20250708-siocinq-v6-0-3775f9a9e359@antgroup.com> In-Reply-To: <20250708-siocinq-v6-0-3775f9a9e359@antgroup.com> To: "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Xuewei Niu , niuxuewei97@gmail.com X-Mailer: b4 0.14.2 Add support for SIOCINQ ioctl, indicating the length of bytes unread in the socket. The value is obtained from `vsock_stream_has_data()`. Signed-off-by: Xuewei Niu Reviewed-by: Luigi Leonardi Reviewed-by: Stefano Garzarella --- net/vmw_vsock/af_vsock.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 2e7a3034e965db30b6ee295370d866e6d8b1c341..bae6b89bb5fb7dd7a3a378f9209= 7561a98a0c814 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1389,6 +1389,28 @@ static int vsock_do_ioctl(struct socket *sock, unsig= ned int cmd, vsk =3D vsock_sk(sk); =20 switch (cmd) { + case SIOCINQ: { + ssize_t n_bytes; + + if (!vsk->transport) { + ret =3D -EOPNOTSUPP; + break; + } + + if (sock_type_connectible(sk->sk_type) && + sk->sk_state =3D=3D TCP_LISTEN) { + ret =3D -EINVAL; + break; + } + + n_bytes =3D vsock_stream_has_data(vsk); + if (n_bytes < 0) { + ret =3D n_bytes; + break; + } + ret =3D put_user(n_bytes, arg); + break; + } case SIOCOUTQ: { ssize_t n_bytes; =20 --=20 2.34.1 From nobody Tue Oct 7 18:26:08 2025 Received: from out28-173.mail.aliyun.com (out28-173.mail.aliyun.com [115.124.28.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3831E1E48A; Tue, 8 Jul 2025 06:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751956617; cv=none; b=Bk4G/DIlhBFkvQGPvnQnEFqFSs4q3oxZi3oElxXbye46xpjT04+xJr6zvYoSHEIxZu0bcVzhfwz9HVfcH+8DGzQrX8sk3O7PXDSo3AMIp21lgJ9yDNc5aUv86yar8YVsA91ljf4KCTEEXriyInGZd6SzQ261T53BlcAvvJIMS7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751956617; c=relaxed/simple; bh=e6+A6V/GIHjY2NtS85toohY3fDmWeS+De+ENSmkaW48=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iIAJDGlP2fFLOwiP1JjGOp0ykKSsA89EWYfxIIUEYISkXjhFF1J7JXv7nhYLfKf7hUPXLJcJo+wnhvMAhxsQ+x21oiQYxPJD22P3X0h8t9fg8mtSa5Mw0dRnh5WBjgYD0P4YHj9vXhYgnVBfhnbpBcXyonVrtrszKNne+UzAC1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=Bygch159; arc=none smtp.client-ip=115.124.28.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="Bygch159" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1751956607; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=+Adkwaehj8WQlyxe1tcyATntmfd0OiZXAi1oQdyK2Hg=; b=Bygch159+jT2UvdH3IEyBuVtOG/tTZ+scNwiJRNh5pGfgQu/ZnvJsz692D2JBB8nv/svJ6482ufRaLWEbIs+09tVTNXQniGphK1tcJOQ4rjDDiSC7o3CpEHnmjVTs101O0LpMbUYloI5iWkoK7ZNVOsCUkIVOus1ZqPckw+1OW0= Received: from 127.0.0.1(mailfrom:niuxuewei.nxw@antgroup.com fp:SMTPD_---.dhGPAgC_1751956605 cluster:ay29) by smtp.aliyun-inc.com; Tue, 08 Jul 2025 14:36:46 +0800 From: Xuewei Niu Date: Tue, 08 Jul 2025 14:36:13 +0800 Subject: [PATCH net-next v6 3/4] test/vsock: Add retry mechanism to ioctl wrapper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250708-siocinq-v6-3-3775f9a9e359@antgroup.com> References: <20250708-siocinq-v6-0-3775f9a9e359@antgroup.com> In-Reply-To: <20250708-siocinq-v6-0-3775f9a9e359@antgroup.com> To: "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Xuewei Niu , niuxuewei97@gmail.com X-Mailer: b4 0.14.2 Wrap the ioctl in `ioctl_int()`, which takes a pointer to the actual int value and an expected int value. The function will not return until either the ioctl returns the expected value or a timeout occurs, thus avoiding immediate failure. Signed-off-by: Xuewei Niu Reviewed-by: Luigi Leonardi Reviewed-by: Stefano Garzarella --- tools/testing/vsock/util.c | 30 +++++++++++++++++++++--------- tools/testing/vsock/util.h | 1 + 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index 803f1e075b62228c25f9dffa1eff131b8072a06a..1e65c5abd85b8bcf5886272de15= 437d7be13eb89 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include =20 @@ -101,28 +102,39 @@ void vsock_wait_remote_close(int fd) close(epollfd); } =20 -/* Wait until transport reports no data left to be sent. - * Return false if transport does not implement the unsent_bytes() callbac= k. +/* Wait until ioctl gives an expected int value. + * Return false if the op is not supported. */ -bool vsock_wait_sent(int fd) +bool vsock_ioctl_int(int fd, unsigned long op, int expected) { - int ret, sock_bytes_unsent; + int actual, ret; + char name[32]; + + snprintf(name, sizeof(name), "ioctl(%lu)", op); =20 timeout_begin(TIMEOUT); do { - ret =3D ioctl(fd, SIOCOUTQ, &sock_bytes_unsent); + ret =3D ioctl(fd, op, &actual); if (ret < 0) { if (errno =3D=3D EOPNOTSUPP) break; =20 - perror("ioctl(SIOCOUTQ)"); + perror(name); exit(EXIT_FAILURE); } - timeout_check("SIOCOUTQ"); - } while (sock_bytes_unsent !=3D 0); + timeout_check(name); + } while (actual !=3D expected); timeout_end(); =20 - return !ret; + return ret >=3D 0; +} + +/* Wait until transport reports no data left to be sent. + * Return false if transport does not implement the unsent_bytes() callbac= k. + */ +bool vsock_wait_sent(int fd) +{ + return vsock_ioctl_int(fd, SIOCOUTQ, 0); } =20 /* Create socket , bind to . diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index fdd4649fe2d49f57c93c4aa5dfbb37b710c65918..142c02a6834acb7117aca485b66= 1332b73754b63 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -87,6 +87,7 @@ int vsock_stream_listen(unsigned int cid, unsigned int po= rt); int vsock_seqpacket_accept(unsigned int cid, unsigned int port, struct sockaddr_vm *clientaddrp); void vsock_wait_remote_close(int fd); +bool vsock_ioctl_int(int fd, unsigned long op, int expected); bool vsock_wait_sent(int fd); void send_buf(int fd, const void *buf, size_t len, int flags, ssize_t expected_ret); --=20 2.34.1 From nobody Tue Oct 7 18:26:08 2025 Received: from out28-122.mail.aliyun.com (out28-122.mail.aliyun.com [115.124.28.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3CEC221FC4; Tue, 8 Jul 2025 06:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751956615; cv=none; b=Btm4/TBITxCqXFgG1yqv78drpbuyYPenyL85Dh8ll8uiMgIR1fxGhHmP5xOXBnwRUGQZfY8+2sQUTb9pZix2uuXO+u8VGVw655oxbnUAE8ezJxM8bIw0t8BQXKG/XycESpfdOcy0INgSRXcUxdZFooG1V5o64FHHs+XbB2TNGdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751956615; c=relaxed/simple; bh=Doct89OeyNO072Y2Ys7bCVOd+ekwZZ2v2r0ziNK3ALY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R91C0W3kCHVHeB9UzuYUhWsemb+/B6CgqI3thHnvwB/d83JXJ6wkrK6uhbORfbxFXii+FNHQCO2CRhwDAzLdfF70l8E+HmAlGAIWHpE+0u8wXZdERZmEXRfRYJugHhK1FmJ5zKfv6IJmEIbMf3OhuWYDA5UfrdDXMRrf1VjK16M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=cmeibjdk; arc=none smtp.client-ip=115.124.28.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="cmeibjdk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1751956608; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=78u4kXViM2gstT6OJkwZc50WiKMJcTjBxWIBBOazpAI=; b=cmeibjdkP9EQ1RwR+kof7rvFNA+zQFsricBfe2XGnwbeX4wVicBks/7CbjltCABC7X33Oi1NY3XNGodHrZf22TEX6uwGq2wocHxCPfncFxB3YKH9VcUmteuQ59j/DC1EVqsuaFukEoP2WR5TEQFicLwzRlaolclsKaOkO7pdnpQ= Received: from 127.0.0.1(mailfrom:niuxuewei.nxw@antgroup.com fp:SMTPD_---.dhGPAi9_1751956606 cluster:ay29) by smtp.aliyun-inc.com; Tue, 08 Jul 2025 14:36:48 +0800 From: Xuewei Niu Date: Tue, 08 Jul 2025 14:36:14 +0800 Subject: [PATCH net-next v6 4/4] test/vsock: Add ioctl SIOCINQ tests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250708-siocinq-v6-4-3775f9a9e359@antgroup.com> References: <20250708-siocinq-v6-0-3775f9a9e359@antgroup.com> In-Reply-To: <20250708-siocinq-v6-0-3775f9a9e359@antgroup.com> To: "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Xuewei Niu , niuxuewei97@gmail.com X-Mailer: b4 0.14.2 Add SIOCINQ ioctl tests for both SOCK_STREAM and SOCK_SEQPACKET. The client waits for the server to send data, and checks if the SIOCINQ ioctl value matches the data size. After consuming the data, the client checks if the SIOCINQ value is 0. Signed-off-by: Xuewei Niu Reviewed-by: Luigi Leonardi Reviewed-by: Stefano Garzarella Tested-by: Luigi Leonardi --- tools/testing/vsock/vsock_test.c | 79 ++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 79 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index be6ce764f69480c0f9c3e2288fc19cd2e74be148..a66d2360133dd0e36940a590767= 9aeacc8af7714 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -24,6 +24,7 @@ #include #include #include +#include =20 #include "vsock_test_zerocopy.h" #include "timeout.h" @@ -1307,6 +1308,54 @@ static void test_unsent_bytes_client(const struct te= st_opts *opts, int type) close(fd); } =20 +static void test_unread_bytes_server(const struct test_opts *opts, int typ= e) +{ + unsigned char buf[MSG_BUF_IOCTL_LEN]; + int client_fd; + + client_fd =3D vsock_accept(VMADDR_CID_ANY, opts->peer_port, NULL, type); + if (client_fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + for (int i =3D 0; i < sizeof(buf); i++) + buf[i] =3D rand() & 0xFF; + + send_buf(client_fd, buf, sizeof(buf), 0, sizeof(buf)); + control_writeln("SENT"); + + close(client_fd); +} + +static void test_unread_bytes_client(const struct test_opts *opts, int typ= e) +{ + unsigned char buf[MSG_BUF_IOCTL_LEN]; + int fd; + + fd =3D vsock_connect(opts->peer_cid, opts->peer_port, type); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + control_expectln("SENT"); + /* The data has arrived but has not been read. The expected is + * MSG_BUF_IOCTL_LEN. + */ + if (!vsock_ioctl_int(fd, SIOCINQ, MSG_BUF_IOCTL_LEN)) { + fprintf(stderr, "Test skipped, SIOCINQ not supported.\n"); + goto out; + } + + recv_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); + /* All data has been consumed, so the expected is 0. */ + vsock_ioctl_int(fd, SIOCINQ, 0); + +out: + close(fd); +} + static void test_stream_unsent_bytes_client(const struct test_opts *opts) { test_unsent_bytes_client(opts, SOCK_STREAM); @@ -1327,6 +1376,26 @@ static void test_seqpacket_unsent_bytes_server(const= struct test_opts *opts) test_unsent_bytes_server(opts, SOCK_SEQPACKET); } =20 +static void test_stream_unread_bytes_client(const struct test_opts *opts) +{ + test_unread_bytes_client(opts, SOCK_STREAM); +} + +static void test_stream_unread_bytes_server(const struct test_opts *opts) +{ + test_unread_bytes_server(opts, SOCK_STREAM); +} + +static void test_seqpacket_unread_bytes_client(const struct test_opts *opt= s) +{ + test_unread_bytes_client(opts, SOCK_SEQPACKET); +} + +static void test_seqpacket_unread_bytes_server(const struct test_opts *opt= s) +{ + test_unread_bytes_server(opts, SOCK_SEQPACKET); +} + #define RCVLOWAT_CREDIT_UPD_BUF_SIZE (1024 * 128) /* This define is the same as in 'include/linux/virtio_vsock.h': * it is used to decide when to send credit update message during @@ -2276,6 +2345,16 @@ static struct test_case test_cases[] =3D { .run_client =3D test_stream_transport_change_client, .run_server =3D test_stream_transport_change_server, }, + { + .name =3D "SOCK_STREAM ioctl(SIOCINQ) functionality", + .run_client =3D test_stream_unread_bytes_client, + .run_server =3D test_stream_unread_bytes_server, + }, + { + .name =3D "SOCK_SEQPACKET ioctl(SIOCINQ) functionality", + .run_client =3D test_seqpacket_unread_bytes_client, + .run_server =3D test_seqpacket_unread_bytes_server, + }, {}, }; =20 --=20 2.34.1