Skip to contentSkip to conversation

hv_sock: Report EOF instead of -EIO for FIN

PATCH Superseded Dexuan Cui 2 participants 4 messages Apr 14 – Apr 16

Subsystems (7)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dexuan Cui

author maintainer
#0 lore raw

PATCH 1/1 hv_sock: Report EOF instead of -EIO for FIN

Commit f0c5827d07cb unluckily causes a regression for the FIN packet, and the final read syscall gets an error rather than 0.

Ideally, we would want to fix hvs_channel_readable_payload() so that it could return 0 in the FIN scenario, but it's not good for the hv_sock driver to use the VMBus ringbuffer's cached priv_read_index, which is internal data in the VMBus driver.

Fix the regression in hv_sock by returning 0 rather than -EIO.

Fixes f0c5827d07cb ("hv_sock: Return the readable bytes in hvs_stream_has_data()")
---
 net/vmw_vsock/hyperv_transport.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
net/vmw_vsock/hyperv_transport.c +16 -2
index 069386a74557..63d3549125be 100644
@@ -703,8 +703,22 @@ static s64 hvs_stream_has_data(struct vsock_sock *vsk)
 	switch (hvs_channel_readable_payload(hvs->chan)) {
 	case 1:
 		need_refill = !hvs->recv_desc;
-		if (!need_refill)
-			return -EIO;
+		if (!need_refill) {
+			/* Here hvs->recv_data_len is 0, so hvs->recv_desc must
+			 * be NULL unless it points to the 0-byte-payload FIN
+			 * packet: see hvs_update_recv_data().
+			 *
+			 * Here all the payload has been dequeued, but
+			 * hvs_channel_readable_payload() still returns 1,
+			 * because the VMBus ringbuffer's read_index is not
+			 * updated for the FIN packet: hvs_stream_dequeue() ->
+			 * hv_pkt_iter_next() updates the cached priv_read_index
+			 * but has no opportunity to update the read_index in
+			 * hv_pkt_iter_close() as hvs_stream_has_data() returns
+			 * 0 for the FIN packet, so it won't get dequeued.
+			 */
+			return 0;
+		}
 
 		hvs->recv_desc = hv_pkt_iter_first(hvs->chan);
 		if (!hvs->recv_desc)
Signature · 1 line
2.49.0
#1 lore raw
Quoted 24 lines · Dexuan Cui

Commit f0c5827d07cb unluckily causes a regression for the FIN packet, and the final read syscall gets an error rather than 0.

Ideally, we would want to fix hvs_channel_readable_payload() so that it could return 0 in the FIN scenario, but it's not good for the hv_sock driver to use the VMBus ringbuffer's cached priv_read_index, which is internal data in the VMBus driver.

Fix the regression in hv_sock by returning 0 rather than -EIO.

Fixes f0c5827d07cb ("hv_sock: Return the readable bytes in hvs_stream_has_data()")

---
net/vmw_vsock/hyperv_transport.c | 18 ++++++++++++++++--

1 file changed, 16 insertions(+), 2 deletions(-)
net/vmw_vsock/hyperv_transport.c +0 -0
index 069386a74557..63d3549125be 100644

net/vmw_vsock/hyperv_transport.c static s64 hvs_stream_has_data(struct vsock_sock *vsk) · line 706

Quoted 6 lines
net/vmw_vsock/hyperv_transport.c +1 -2
@@ -703,8 +703,22 @@ static s64 hvs_stream_has_data(struct vsock_sock *vsk)
 	switch (hvs_channel_readable_payload(hvs->chan)) {
 	case 1:
 		need_refill = !hvs->recv_desc;
-		if (!need_refill)
-			return -EIO;
+		if (!need_refill) {

Can we drop need_refill entirly and just check hvs->recv_desc here?

Mainly because now the comment we are adding is confusing me about what need_refill means.

The rest LGTM.

Thanks,
Stefano

Quoted 22 lines
net/vmw_vsock/hyperv_transport.c +15 -0
+			/* Here hvs->recv_data_len is 0, so hvs->recv_desc must
+			 * be NULL unless it points to the 0-byte-payload FIN
+			 * packet: see hvs_update_recv_data().
+			 *
+			 * Here all the payload has been dequeued, but
+			 * hvs_channel_readable_payload() still returns 1,
+			 * because the VMBus ringbuffer's read_index is not
+			 * updated for the FIN packet: hvs_stream_dequeue() ->
+			 * hv_pkt_iter_next() updates the cached priv_read_index
+			 * but has no opportunity to update the read_index in
+			 * hv_pkt_iter_close() as hvs_stream_has_data() returns
+			 * 0 for the FIN packet, so it won't get dequeued.
+			 */
+			return 0;
+		}
 
 		hvs->recv_desc = hv_pkt_iter_first(hvs->chan);
 		if (!hvs->recv_desc)
Signature · 1 line
2.49.0
author maintainer
#2 lore raw
Quoted 4 lines

From: Stefano Garzarella <[email protected]>
Sent: Wednesday, April 15, 2026 3:38 AM

Review static s64 hvs_stream_has_data(struct vsock_sock

Quoted 1 line
(quoted diff) +0 -0
@@ -703,8 +703,22 @@ static s64 hvs_stream_has_data(struct vsock_sock

*vsk)

Quoted 8 lines

net/vmw_vsock/hyperv_transport.c static s64 hvs_stream_has_data(struct vsock_sock *vsk) · line 706

Quoted 6 lines
net/vmw_vsock/hyperv_transport.c +1 -2
 	switch (hvs_channel_readable_payload(hvs->chan)) {
 	case 1:
 		need_refill = !hvs->recv_desc;
-		if (!need_refill)
-			return -EIO;
+		if (!need_refill) {

Can we drop need_refill entirly and just check hvs->recv_desc here?

OK. Will post v2 later today.

Quoted 7 lines

Mainly because now the comment we are adding is confusing me about what need_refill means.

The rest LGTM.

Thanks,
Stefano

Thanks for the review!

author maintainer
#3 lore raw
Quoted 15 lines

From: Dexuan Cui
Sent: Wednesday, April 15, 2026 9:56 AM
To: 'Stefano Garzarella' <[email protected]>

Quoted 2 lines

...
Can we drop need_refill entirly and just check hvs->recv_desc here?

OK. Will post v2 later today.

Quoted 7 lines

Mainly because now the comment we are adding is confusing me about what need_refill means.

The rest LGTM.

Thanks,
Stefano

Hi Stefano, I just posted v2 here:
https://lore.kernel.org/linux-hyperv/[email protected]/T/#u