diff mbox series

[RFC,v1,2/3] virtio/vsock: use 'target' in notify_poll_in, callback.

Message ID 358f8d52-fd88-ad2e-87e2-c64bfa516a58@sberdevices.ru (mailing list archive)
State RFC
Headers show
Series virtio/vsock: use SO_RCVLOWAT to set POLLIN/POLLRDNORM | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Arseniy Krasnov July 18, 2022, 8:17 a.m. UTC
This callback controls setting of POLLIN,POLLRDNORM output bits
of poll() syscall,but in some cases,it is incorrectly to set it,
when socket has at least 1 bytes of available data. Use 'target'
which is already exists and equal to sk_rcvlowat in this case.

Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
---
 net/vmw_vsock/virtio_transport_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Garzarella July 19, 2022, 12:48 p.m. UTC | #1
On Mon, Jul 18, 2022 at 08:17:31AM +0000, Arseniy Krasnov wrote:
>This callback controls setting of POLLIN,POLLRDNORM output bits
>of poll() syscall,but in some cases,it is incorrectly to set it,
>when socket has at least 1 bytes of available data. Use 'target'
>which is already exists and equal to sk_rcvlowat in this case.
>
>Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>---
> net/vmw_vsock/virtio_transport_common.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>index ec2c2afbf0d0..591908740992 100644
>--- a/net/vmw_vsock/virtio_transport_common.c
>+++ b/net/vmw_vsock/virtio_transport_common.c
>@@ -634,7 +634,7 @@ virtio_transport_notify_poll_in(struct vsock_sock *vsk,
> 				size_t target,
> 				bool *data_ready_now)
> {
>-	if (vsock_stream_has_data(vsk))
>+	if (vsock_stream_has_data(vsk) >= target)
> 		*data_ready_now = true;
> 	else
> 		*data_ready_now = false;

Perhaps we can take the opportunity to clean up the code in this way:

	*data_ready_now = vsock_stream_has_data(vsk) >= target;

Anyway, I think we also need to fix the other transports (vmci and 
hyperv), what do you think?

Thanks,
Stefano
Arseniy Krasnov July 20, 2022, 5:38 a.m. UTC | #2
On 19.07.2022 15:48, Stefano Garzarella wrote:
> On Mon, Jul 18, 2022 at 08:17:31AM +0000, Arseniy Krasnov wrote:
>> This callback controls setting of POLLIN,POLLRDNORM output bits
>> of poll() syscall,but in some cases,it is incorrectly to set it,
>> when socket has at least 1 bytes of available data. Use 'target'
>> which is already exists and equal to sk_rcvlowat in this case.
>>
>> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>> ---
>> net/vmw_vsock/virtio_transport_common.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>> index ec2c2afbf0d0..591908740992 100644
>> --- a/net/vmw_vsock/virtio_transport_common.c
>> +++ b/net/vmw_vsock/virtio_transport_common.c
>> @@ -634,7 +634,7 @@ virtio_transport_notify_poll_in(struct vsock_sock *vsk,
>>                 size_t target,
>>                 bool *data_ready_now)
>> {
>> -    if (vsock_stream_has_data(vsk))
>> +    if (vsock_stream_has_data(vsk) >= target)
>>         *data_ready_now = true;
>>     else
>>         *data_ready_now = false;
> 
> Perhaps we can take the opportunity to clean up the code in this way:
> 
>     *data_ready_now = vsock_stream_has_data(vsk) >= target;
Ack
> 
> Anyway, I think we also need to fix the other transports (vmci and hyperv), what do you think?
For vmci it is look clear to fix it. For hyperv i need to check it more, because it already
uses some internal target value.
> 
> Thanks,
> Stefano
>
Stefano Garzarella July 20, 2022, 8:23 a.m. UTC | #3
On Wed, Jul 20, 2022 at 05:38:03AM +0000, Arseniy Krasnov wrote:
>On 19.07.2022 15:48, Stefano Garzarella wrote:
>> On Mon, Jul 18, 2022 at 08:17:31AM +0000, Arseniy Krasnov wrote:
>>> This callback controls setting of POLLIN,POLLRDNORM output bits
>>> of poll() syscall,but in some cases,it is incorrectly to set it,
>>> when socket has at least 1 bytes of available data. Use 'target'
>>> which is already exists and equal to sk_rcvlowat in this case.
>>>
>>> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>>> ---
>>> net/vmw_vsock/virtio_transport_common.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>>> index ec2c2afbf0d0..591908740992 100644
>>> --- a/net/vmw_vsock/virtio_transport_common.c
>>> +++ b/net/vmw_vsock/virtio_transport_common.c
>>> @@ -634,7 +634,7 @@ virtio_transport_notify_poll_in(struct vsock_sock *vsk,
>>>                 size_t target,
>>>                 bool *data_ready_now)
>>> {
>>> -    if (vsock_stream_has_data(vsk))
>>> +    if (vsock_stream_has_data(vsk) >= target)
>>>         *data_ready_now = true;
>>>     else
>>>         *data_ready_now = false;
>>
>> Perhaps we can take the opportunity to clean up the code in this way:
>>
>>     *data_ready_now = vsock_stream_has_data(vsk) >= target;
>Ack
>>
>> Anyway, I think we also need to fix the other transports (vmci and hyperv), what do you think?
>For vmci it is look clear to fix it. For hyperv i need to check it more, because it already
>uses some internal target value.

Yep, I see. Maybe you can pass `target` to hvs_channel_readable() and 
use it as parameter of HVS_PKT_LEN().

@Dexuan what do you think?

Thanks,
Stefano
Dexuan Cui July 20, 2022, 6:54 p.m. UTC | #4
> From: Stefano Garzarella <sgarzare@redhat.com>
> Sent: Wednesday, July 20, 2022 1:23 AM
> ...
> On Wed, Jul 20, 2022 at 05:38:03AM +0000, Arseniy Krasnov wrote:
> >On 19.07.2022 15:48, Stefano Garzarella wrote:
> >> On Mon, Jul 18, 2022 at 08:17:31AM +0000, Arseniy Krasnov wrote:
> >>> This callback controls setting of POLLIN,POLLRDNORM output bits
> >>> of poll() syscall,but in some cases,it is incorrectly to set it,
> >>> when socket has at least 1 bytes of available data. Use 'target'
> >>> which is already exists and equal to sk_rcvlowat in this case.
> >>>
> >>> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
> >>> ---
> >>> net/vmw_vsock/virtio_transport_common.c | 2 +-
> >>> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/net/vmw_vsock/virtio_transport_common.c
> b/net/vmw_vsock/virtio_transport_common.c
> >>> index ec2c2afbf0d0..591908740992 100644
> >>> --- a/net/vmw_vsock/virtio_transport_common.c
> >>> +++ b/net/vmw_vsock/virtio_transport_common.c
> >>> @@ -634,7 +634,7 @@ virtio_transport_notify_poll_in(struct vsock_sock
> *vsk,
> >>>                 size_t target,
> >>>                 bool *data_ready_now)
> >>> {
> >>> -    if (vsock_stream_has_data(vsk))
> >>> +    if (vsock_stream_has_data(vsk) >= target)
> >>>         *data_ready_now = true;
> >>>     else
> >>>         *data_ready_now = false;
> >>
> >> Perhaps we can take the opportunity to clean up the code in this way:
> >>
> >>     *data_ready_now = vsock_stream_has_data(vsk) >= target;
> >Ack
> >>
> >> Anyway, I think we also need to fix the other transports (vmci and hyperv),
> >> what do you think?
> >For vmci it is look clear to fix it. For hyperv i need to check it more, because it
> > already uses some internal target value.
> 
> Yep, I see. Maybe you can pass `target` to hvs_channel_readable() and
> use it as parameter of HVS_PKT_LEN().
> 
> @Dexuan what do you think?
> 
> Thanks,
> Stefano

Can we return "not supported" to set_rcvlowat for Hyper-V vsock? :-)

For Hyper-V vsock, it's easy to tell if there is at least 1 byte to read: 
please refer to hvs_channel_readable(), but it's difficult to figure out
exactly how many bytes can be read. 

In hvs_channel_readable(), hv_get_bytes_to_read() returns the total 
bytes of 0, 1 or multiple Hyper-V vsock packets: each packet has a
24-byte header (see HVS_HEADER_LEN), the payload, some padding
bytes (if the payload length is not a multiple of 8), and 8 trailing
useless bytes.

It's hard to get the total payload length because there is no API in
include/linux/hyperv.h, drivers/hv/channel.c and 
drivers/hv/ring_buffer.c that allows us to peek at the data in the
VMBus channel's ringbuffer. 

We could add such a "peek" API in drivers/hv/channel.c (see the
non-peek version of the APIs in hvs_stream_dequeue(): 
hv_pkt_iter_first() and hv_pkt_iter_next()), and examine the whole
ringbuffe to figure out the exact total payload length, but I feel it may 
not be worth the non-trivial complexity just to be POSIX-compliant --
nobody ever complained about this for the past 5 years :-) So I'm
wondering if we should allow Hyper-V vsock to not support the 
set_rcvlowat op?

Thanks,
-- Dexuan
Arseniy Krasnov July 21, 2022, 6:02 a.m. UTC | #5
On 20.07.2022 21:54, Dexuan Cui wrote:
>> From: Stefano Garzarella <sgarzare@redhat.com>
>> Sent: Wednesday, July 20, 2022 1:23 AM
>> ...
>> On Wed, Jul 20, 2022 at 05:38:03AM +0000, Arseniy Krasnov wrote:
>>> On 19.07.2022 15:48, Stefano Garzarella wrote:
>>>> On Mon, Jul 18, 2022 at 08:17:31AM +0000, Arseniy Krasnov wrote:
>>>>> This callback controls setting of POLLIN,POLLRDNORM output bits
>>>>> of poll() syscall,but in some cases,it is incorrectly to set it,
>>>>> when socket has at least 1 bytes of available data. Use 'target'
>>>>> which is already exists and equal to sk_rcvlowat in this case.
>>>>>
>>>>> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>>>>> ---
>>>>> net/vmw_vsock/virtio_transport_common.c | 2 +-
>>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/net/vmw_vsock/virtio_transport_common.c
>> b/net/vmw_vsock/virtio_transport_common.c
>>>>> index ec2c2afbf0d0..591908740992 100644
>>>>> --- a/net/vmw_vsock/virtio_transport_common.c
>>>>> +++ b/net/vmw_vsock/virtio_transport_common.c
>>>>> @@ -634,7 +634,7 @@ virtio_transport_notify_poll_in(struct vsock_sock
>> *vsk,
>>>>>                 size_t target,
>>>>>                 bool *data_ready_now)
>>>>> {
>>>>> -    if (vsock_stream_has_data(vsk))
>>>>> +    if (vsock_stream_has_data(vsk) >= target)
>>>>>         *data_ready_now = true;
>>>>>     else
>>>>>         *data_ready_now = false;
>>>>
>>>> Perhaps we can take the opportunity to clean up the code in this way:
>>>>
>>>>     *data_ready_now = vsock_stream_has_data(vsk) >= target;
>>> Ack
>>>>
>>>> Anyway, I think we also need to fix the other transports (vmci and hyperv),
>>>> what do you think?
>>> For vmci it is look clear to fix it. For hyperv i need to check it more, because it
>>> already uses some internal target value.
>>
>> Yep, I see. Maybe you can pass `target` to hvs_channel_readable() and
>> use it as parameter of HVS_PKT_LEN().
>>
>> @Dexuan what do you think?
>>
>> Thanks,
>> Stefano
> 
> Can we return "not supported" to set_rcvlowat for Hyper-V vsock? :-)
> 
> For Hyper-V vsock, it's easy to tell if there is at least 1 byte to read: 
> please refer to hvs_channel_readable(), but it's difficult to figure out
> exactly how many bytes can be read. 
> 
> In hvs_channel_readable(), hv_get_bytes_to_read() returns the total 
> bytes of 0, 1 or multiple Hyper-V vsock packets: each packet has a
> 24-byte header (see HVS_HEADER_LEN), the payload, some padding
> bytes (if the payload length is not a multiple of 8), and 8 trailing
> useless bytes.
> 
> It's hard to get the total payload length because there is no API in
> include/linux/hyperv.h, drivers/hv/channel.c and 
> drivers/hv/ring_buffer.c that allows us to peek at the data in the
> VMBus channel's ringbuffer. 
> 
> We could add such a "peek" API in drivers/hv/channel.c (see the
> non-peek version of the APIs in hvs_stream_dequeue(): 
> hv_pkt_iter_first() and hv_pkt_iter_next()), and examine the whole
> ringbuffe to figure out the exact total payload length, but I feel it may 
> not be worth the non-trivial complexity just to be POSIX-compliant --
> nobody ever complained about this for the past 5 years :-) So I'm
> wondering if we should allow Hyper-V vsock to not support the 
> set_rcvlowat op?
I see, i can prepare patch for this in this patchset in v2. Call to set SO_RCVLOWAT for Hyper-V
transport will return EOPNOTSUPP.

Thank You
> 
> Thanks,
> -- Dexuan
>
diff mbox series

Patch

diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index ec2c2afbf0d0..591908740992 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -634,7 +634,7 @@  virtio_transport_notify_poll_in(struct vsock_sock *vsk,
 				size_t target,
 				bool *data_ready_now)
 {
-	if (vsock_stream_has_data(vsk))
+	if (vsock_stream_has_data(vsk) >= target)
 		*data_ready_now = true;
 	else
 		*data_ready_now = false;