diff mbox series

[RFC,v2,3/4] virtio/vsock: free skb on data copy failure

Message ID ef98aad4-f86d-fe60-9a35-792363a78a68@sberdevices.ru (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series virtio/vsock: fix credit update logic | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
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 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning CHECK: From:/Signed-off-by: email comments mismatch: 'From: Arseniy Krasnov <avkrasnov@sberdevices.ru>' != 'Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>'
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Arseniy Krasnov March 5, 2023, 8:08 p.m. UTC
This fixes two things in case when 'memcpy_to_msg()' fails:
1) Update credit parameters of the socket, like this skbuff was
   copied to user successfully. This is needed because when skbuff was
   received it's length was used to update 'rx_bytes', thus when we drop
   skbuff here, we must account rest of it's data in 'rx_bytes'.
2) Free skbuff which was removed from socket's queue.

Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff")
Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
---
 net/vmw_vsock/virtio_transport_common.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Stefano Garzarella March 6, 2023, 12:07 p.m. UTC | #1
On Sun, Mar 05, 2023 at 11:08:38PM +0300, Arseniy Krasnov wrote:
>This fixes two things in case when 'memcpy_to_msg()' fails:
>1) Update credit parameters of the socket, like this skbuff was
>   copied to user successfully. This is needed because when skbuff was
>   received it's length was used to update 'rx_bytes', thus when we drop
>   skbuff here, we must account rest of it's data in 'rx_bytes'.
>2) Free skbuff which was removed from socket's queue.
>
>Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff")
>Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>---
> net/vmw_vsock/virtio_transport_common.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
>diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>index 30b0539990ba..ffb1af4f2b52 100644
>--- a/net/vmw_vsock/virtio_transport_common.c
>+++ b/net/vmw_vsock/virtio_transport_common.c
>@@ -379,8 +379,12 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk,
> 		spin_unlock_bh(&vvs->rx_lock);
>
> 		err = memcpy_to_msg(msg, skb->data, bytes);
>-		if (err)
>+		if (err) {
>+			skb_pull(skb, skb->len);
>+			virtio_transport_dec_rx_pkt(vvs, skb);
>+			consume_skb(skb);

I'm not sure it's the right thing to do, if we fail to copy the content
into the user's buffer, I think we should queue it again.

In fact, before commit 71dc9ec9ac7d ("virtio/vsock: replace
virtio_vsock_pkt with sk_buff"), we used to remove the packet from the
rx_queue, only if memcpy_to_msg() was successful.

Maybe it is better to do as we did before and use skb_peek() at the
beginning of the loop and __skb_unlink() when skb->len == 0.

Thanks,
Stefano

> 			goto out;
>+		}
>
> 		spin_lock_bh(&vvs->rx_lock);
>
>-- 
>2.25.1
>
Arseniy Krasnov March 6, 2023, 3:28 p.m. UTC | #2
On 06.03.2023 15:07, Stefano Garzarella wrote:
> On Sun, Mar 05, 2023 at 11:08:38PM +0300, Arseniy Krasnov wrote:
>> This fixes two things in case when 'memcpy_to_msg()' fails:
>> 1) Update credit parameters of the socket, like this skbuff was
>>   copied to user successfully. This is needed because when skbuff was
>>   received it's length was used to update 'rx_bytes', thus when we drop
>>   skbuff here, we must account rest of it's data in 'rx_bytes'.
>> 2) Free skbuff which was removed from socket's queue.
>>
>> Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff")
>> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>> ---
>> net/vmw_vsock/virtio_transport_common.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>> index 30b0539990ba..ffb1af4f2b52 100644
>> --- a/net/vmw_vsock/virtio_transport_common.c
>> +++ b/net/vmw_vsock/virtio_transport_common.c
>> @@ -379,8 +379,12 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk,
>>         spin_unlock_bh(&vvs->rx_lock);
>>
>>         err = memcpy_to_msg(msg, skb->data, bytes);
>> -        if (err)
>> +        if (err) {
>> +            skb_pull(skb, skb->len);
>> +            virtio_transport_dec_rx_pkt(vvs, skb);
>> +            consume_skb(skb);
> 
> I'm not sure it's the right thing to do, if we fail to copy the content
> into the user's buffer, I think we should queue it again.
> 
> In fact, before commit 71dc9ec9ac7d ("virtio/vsock: replace
> virtio_vsock_pkt with sk_buff"), we used to remove the packet from the
> rx_queue, only if memcpy_to_msg() was successful.
> 
> Maybe it is better to do as we did before and use skb_peek() at the
> beginning of the loop and __skb_unlink() when skb->len == 0.
Yes, i see. I'll also add test to cover this case.
> 
> Thanks,
> Stefano
> 
>>             goto out;
>> +        }
>>
>>         spin_lock_bh(&vvs->rx_lock);
>>
>> -- 
>> 2.25.1
>>
>
diff mbox series

Patch

diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 30b0539990ba..ffb1af4f2b52 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -379,8 +379,12 @@  virtio_transport_stream_do_dequeue(struct vsock_sock *vsk,
 		spin_unlock_bh(&vvs->rx_lock);
 
 		err = memcpy_to_msg(msg, skb->data, bytes);
-		if (err)
+		if (err) {
+			skb_pull(skb, skb->len);
+			virtio_transport_dec_rx_pkt(vvs, skb);
+			consume_skb(skb);
 			goto out;
+		}
 
 		spin_lock_bh(&vvs->rx_lock);