* [PATCH] hv_sock: Return the readable bytes in hvs_stream_has_data()
@ 2025-06-27 8:44 Dexuan Cui
2025-07-01 13:04 ` Paolo Abeni
0 siblings, 1 reply; 3+ messages in thread
From: Dexuan Cui @ 2025-06-27 8:44 UTC (permalink / raw)
To: niuxuewei97, kys, haiyangz, wei.liu, decui, sgarzare, davem,
edumazet, kuba, pabeni, horms, linux-hyperv, virtualization,
netdev, linux-kernel
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 multpile 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 <decui@microsoft.com>
---
Hi maintainers, please don't take the patch for now.
Hi Xuewei Niu, please help to re-post this patch with the next version
of your patchset "vsock: Introduce SIOCINQ ioctl support". See
https://lore.kernel.org/virtualization/BL1PR21MB3115F69C544B0FAA145FA4EABF7BA@BL1PR21MB3115.namprd21.prod.outlook.com/#t
https://lore.kernel.org/virtualization/20250626050219.1847316-1-niuxuewei.nxw@antgroup.com/
Feel free to add your Signed-off-by, if you need.
net/vmw_vsock/hyperv_transport.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c
index 31342ab502b4..64f1290a9ae7 100644
--- a/net/vmw_vsock/hyperv_transport.c
+++ b/net/vmw_vsock/hyperv_transport.c
@@ -694,15 +694,25 @@ 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 = vsk->trans;
+ bool need_refill = !hvs->recv_desc;
s64 ret;
if (hvs->recv_data_len > 0)
- return 1;
+ return hvs->recv_data_len;
switch (hvs_channel_readable_payload(hvs->chan)) {
case 1:
- ret = 1;
- break;
+ if (!need_refill)
+ return -EIO;
+
+ hvs->recv_desc = hv_pkt_iter_first(hvs->chan);
+ if (!hvs->recv_desc)
+ return -ENOBUFS;
+
+ ret = hvs_update_recv_data(hvs);
+ if (ret)
+ return ret;
+ return hvs->recv_data_len;
case 0:
vsk->peer_shutdown |= SEND_SHUTDOWN;
ret = 0;
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hv_sock: Return the readable bytes in hvs_stream_has_data()
2025-06-27 8:44 [PATCH] hv_sock: Return the readable bytes in hvs_stream_has_data() Dexuan Cui
@ 2025-07-01 13:04 ` Paolo Abeni
2025-07-01 18:37 ` [EXTERNAL] " Dexuan Cui
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Abeni @ 2025-07-01 13:04 UTC (permalink / raw)
To: Dexuan Cui, niuxuewei97, kys, haiyangz, wei.liu, sgarzare, davem,
edumazet, kuba, horms, linux-hyperv, virtualization, netdev,
linux-kernel
On 6/27/25 10:44 AM, Dexuan Cui wrote:
> 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 multpile 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 <decui@microsoft.com>
> ---
>
> Hi maintainers, please don't take the patch for now.
>
> Hi Xuewei Niu, please help to re-post this patch with the next version
> of your patchset "vsock: Introduce SIOCINQ ioctl support". See
> https://lore.kernel.org/virtualization/BL1PR21MB3115F69C544B0FAA145FA4EABF7BA@BL1PR21MB3115.namprd21.prod.outlook.com/#t
> https://lore.kernel.org/virtualization/20250626050219.1847316-1-niuxuewei.nxw@antgroup.com/
> Feel free to add your Signed-off-by, if you need.
>
> net/vmw_vsock/hyperv_transport.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c
> index 31342ab502b4..64f1290a9ae7 100644
> --- a/net/vmw_vsock/hyperv_transport.c
> +++ b/net/vmw_vsock/hyperv_transport.c
> @@ -694,15 +694,25 @@ 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 = vsk->trans;
> + bool need_refill = !hvs->recv_desc;
> s64 ret;
Minor nit: when reposting please respect the reverse christmas tree
order above moving 'need_refill' initialization after the following 'if'
statement.
/P
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [EXTERNAL] Re: [PATCH] hv_sock: Return the readable bytes in hvs_stream_has_data()
2025-07-01 13:04 ` Paolo Abeni
@ 2025-07-01 18:37 ` Dexuan Cui
0 siblings, 0 replies; 3+ messages in thread
From: Dexuan Cui @ 2025-07-01 18:37 UTC (permalink / raw)
To: Paolo Abeni, niuxuewei97@gmail.com, KY Srinivasan, Haiyang Zhang,
wei.liu@kernel.org, sgarzare@redhat.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, horms@kernel.org,
linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
> From: Paolo Abeni <pabeni@redhat.com>
> Sent: Tuesday, July 1, 2025 6:05 AM
> ...
> > static s64 hvs_stream_has_data(struct vsock_sock *vsk)
> > {
> > struct hvsock *hvs = vsk->trans;
> > + bool need_refill = !hvs->recv_desc;
> > s64 ret;
>
> Minor nit: when reposting please respect the reverse christmas tree
> order above moving 'need_refill' initialization after the following 'if'
> statement.
>
> /P
Thanks! Will do.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-01 18:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-27 8:44 [PATCH] hv_sock: Return the readable bytes in hvs_stream_has_data() Dexuan Cui
2025-07-01 13:04 ` Paolo Abeni
2025-07-01 18:37 ` [EXTERNAL] " Dexuan Cui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).