Message ID | dfadea17-a91e-105f-c213-a73f9731c8bd@sberdevices.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1519063wrd; Sun, 5 Mar 2023 12:29:34 -0800 (PST) X-Google-Smtp-Source: AK7set9MdRFuHfFXeE974He/R/edyi5FFPqJrqLFk90CS++gsuArbrCm9g0v3Lp+8Y7zdQJiLGvP X-Received: by 2002:a17:907:5cb:b0:8b1:3a23:8ec7 with SMTP id wg11-20020a17090705cb00b008b13a238ec7mr11214526ejb.43.1678048174107; Sun, 05 Mar 2023 12:29:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678048174; cv=none; d=google.com; s=arc-20160816; b=XSp8GLwex78YTnueD9OTM+YjRv3F0VXHYJPt0vAint//VTiyURy7R6SU8JrQ+XPt/S uOhuUgG/4uJbuXkippeTOqIwo/ns8nPWfTjdxWz0Tmk/kGNKgYBew33RVz5MwcZff8RX 2s0kXuD4h53Rg5+r0BqqfX0PA3C6HvmEWmchU01rfo1PtX4mjQ5OzM9O633LG7dsySp5 34x6fx5eQQ/olCIIwc+oW1k9CerISctSkbEm2DKxTQB14DtA9CQ10g9p/K6jULqyPnMm x/J3Jp/tRyDpGWq9VEBoyywqmqB1vzkNWSEvtA7xNKWXtZgak1JfaEAi7GVFFTBYWSVu M7aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:cc:to :in-reply-to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=B1csgoVu7NP3tPpJfIEd1Is03PuaIF7WOwsc6mPxpMo=; b=BypCA8CgTEIm+LiPD14J7cQf+rtshzUCPe0CP8WUtD87k4O/tz/mOe36H1UgJYmSbu /gULHqHnCMRQMljeliJXtvQ+rUObzUySjaGwTBpl0Xl2tjz1gq+SRYuEUMDPKDOCtjKE aJa8/LV3scrplpEJ4JBJnCEfUMHDud2eCTyCyvv+VOY7afoNrCZznwbmnRSZiSAtfDhL GZVrVVICmNa6M0SEKtKQ9SEjsfqXoX1sdFQ6LkvHMXfIM+Bn5yEmx3M/+mW6cQIo2QkA Cx5MbMBql1cx3yAVjosYjHAXLoiirhVpVA+l1SX7dzalK67ob723gcvB7w92gtegwnUp Q+nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=fVvC+MKy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w22-20020aa7d296000000b004c0cee0afb2si9033830edq.536.2023.03.05.12.29.10; Sun, 05 Mar 2023 12:29:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=fVvC+MKy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229671AbjCEUKg (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Sun, 5 Mar 2023 15:10:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229494AbjCEUKe (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 5 Mar 2023 15:10:34 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30A2710AAE; Sun, 5 Mar 2023 12:10:33 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 8E2FF5FD04; Sun, 5 Mar 2023 23:10:31 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1678047031; bh=B1csgoVu7NP3tPpJfIEd1Is03PuaIF7WOwsc6mPxpMo=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=fVvC+MKyIZIBUwCzPm2zEXoiwyd8w/QY/cclz8FOwtxtnXszutBjkx1wN6ZMznZj4 +fruQpxq8fHvs3lr9H8eppemU45eIWUbLxt0lGlaOC3uDc1KXIZ9kqJFiaK1T+EOLn WE1Myu76V+gulNQGeL4/Np7FDfShWKxYtZIURCJVYH0a0Nb8SCdhbJo8vlLKo2uWic ZJUcsi49mTEXxiuZjBrFi8xT/7sU1XdvKEU6gxE0/PIM2+ds89uwYIbIUlOro5PBkA 7RylTG0PXAIVLfXtM8NoFOq901Fj4KTlKGdboetrSRmk4fMkGI1vMZnczkvkx4lFoZ joyzO4NT1unLQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 5 Mar 2023 23:10:31 +0300 (MSK) Message-ID: <dfadea17-a91e-105f-c213-a73f9731c8bd@sberdevices.ru> Date: Sun, 5 Mar 2023 23:07:37 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Content-Language: en-US In-Reply-To: <a7ab414b-5e41-c7b6-250b-e8401f335859@sberdevices.ru> To: Stefan Hajnoczi <stefanha@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Bobby Eshleman <bobby.eshleman@bytedance.com> CC: <kvm@vger.kernel.org>, <virtualization@lists.linux-foundation.org>, <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <kernel@sberdevices.ru>, <oxffffaa@gmail.com>, <avkrasnov@sberdevices.ru> From: Arseniy Krasnov <avkrasnov@sberdevices.ru> Subject: [RFC PATCH v2 2/4] virtio/vsock: remove all data from sk_buff Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/03/05 16:13:00 #20917262 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759561042313815067?= X-GMAIL-MSGID: =?utf-8?q?1759561042313815067?= |
Series |
virtio/vsock: fix credit update logic
|
|
Commit Message
Arseniy Krasnov
March 5, 2023, 8:07 p.m. UTC
In case of SOCK_SEQPACKET all sk_buffs are used once - after read some
data from it, it will be removed, so user will never read rest of the
data. Thus we need to update credit parameters of the socket like whole
sk_buff is read - so call 'skb_pull()' for the whole buffer.
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 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Sun, Mar 05, 2023 at 11:07:37PM +0300, Arseniy Krasnov wrote: >In case of SOCK_SEQPACKET all sk_buffs are used once - after read some >data from it, it will be removed, so user will never read rest of the >data. Thus we need to update credit parameters of the socket like whole >sk_buff is read - so call 'skb_pull()' for the whole buffer. > >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 | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Maybe we could avoid this patch if we directly use pkt_len as I suggested in the previous patch. Thanks, Stefano > >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c >index 2e2a773df5c1..30b0539990ba 100644 >--- a/net/vmw_vsock/virtio_transport_common.c >+++ b/net/vmw_vsock/virtio_transport_common.c >@@ -466,7 +466,6 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, > dequeued_len = err; > } else { > user_buf_len -= bytes_to_copy; >- skb_pull(skb, bytes_to_copy); > } > > spin_lock_bh(&vvs->rx_lock); >@@ -484,6 +483,7 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, > msg->msg_flags |= MSG_EOR; > } > >+ skb_pull(skb, skb->len); > virtio_transport_dec_rx_pkt(vvs, skb); > kfree_skb(skb); > } >-- >2.25.1 >
On 06.03.2023 15:08, Stefano Garzarella wrote: > On Sun, Mar 05, 2023 at 11:07:37PM +0300, Arseniy Krasnov wrote: >> In case of SOCK_SEQPACKET all sk_buffs are used once - after read some >> data from it, it will be removed, so user will never read rest of the >> data. Thus we need to update credit parameters of the socket like whole >> sk_buff is read - so call 'skb_pull()' for the whole buffer. >> >> 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 | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) > > Maybe we could avoid this patch if we directly use pkt_len as I > suggested in the previous patch. Hm, may be we can avoid calling 'skb_pull()' here if 'virtio_transport_dec_rx_pkt()' will use integer argument? Just call 'virtio_transport_dec_rx_pkt(skb->len)'. skb is never returned to queue to read it again, so i think may be there is no sense for extra call 'skb_pull'? Thanks, Arseniy > > Thanks, > Stefano > >> >> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c >> index 2e2a773df5c1..30b0539990ba 100644 >> --- a/net/vmw_vsock/virtio_transport_common.c >> +++ b/net/vmw_vsock/virtio_transport_common.c >> @@ -466,7 +466,6 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, >> dequeued_len = err; >> } else { >> user_buf_len -= bytes_to_copy; >> - skb_pull(skb, bytes_to_copy); >> } >> >> spin_lock_bh(&vvs->rx_lock); >> @@ -484,6 +483,7 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, >> msg->msg_flags |= MSG_EOR; >> } >> >> + skb_pull(skb, skb->len); >> virtio_transport_dec_rx_pkt(vvs, skb); >> kfree_skb(skb); >> } >> -- >> 2.25.1 >> >
On Mon, Mar 06, 2023 at 06:31:22PM +0300, Arseniy Krasnov wrote: > > >On 06.03.2023 15:08, Stefano Garzarella wrote: >> On Sun, Mar 05, 2023 at 11:07:37PM +0300, Arseniy Krasnov wrote: >>> In case of SOCK_SEQPACKET all sk_buffs are used once - after read some >>> data from it, it will be removed, so user will never read rest of the >>> data. Thus we need to update credit parameters of the socket like whole >>> sk_buff is read - so call 'skb_pull()' for the whole buffer. >>> >>> 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 | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> Maybe we could avoid this patch if we directly use pkt_len as I >> suggested in the previous patch. >Hm, may be we can avoid calling 'skb_pull()' here if 'virtio_transport_dec_rx_pkt()' >will use integer argument? Yep, exactly! >Just call 'virtio_transport_dec_rx_pkt(skb->len)'. skb It depends on how we call virtio_transport_inc_rx_pkt(). If we use hdr->len there I would use the same to avoid confusion. Plus that's the value the other peer sent us, so definitely the right value to increase fwd_cnt with. But if skb->len always reflects it, then that's fine. >is never returned to queue to read it again, so i think may be there is no sense for >extra call 'skb_pull'? Right! Thanks, Stefano
On 06.03.2023 18:51, Stefano Garzarella wrote: > On Mon, Mar 06, 2023 at 06:31:22PM +0300, Arseniy Krasnov wrote: >> >> >> On 06.03.2023 15:08, Stefano Garzarella wrote: >>> On Sun, Mar 05, 2023 at 11:07:37PM +0300, Arseniy Krasnov wrote: >>>> In case of SOCK_SEQPACKET all sk_buffs are used once - after read some >>>> data from it, it will be removed, so user will never read rest of the >>>> data. Thus we need to update credit parameters of the socket like whole >>>> sk_buff is read - so call 'skb_pull()' for the whole buffer. >>>> >>>> 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 | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> Maybe we could avoid this patch if we directly use pkt_len as I >>> suggested in the previous patch. >> Hm, may be we can avoid calling 'skb_pull()' here if 'virtio_transport_dec_rx_pkt()' >> will use integer argument? > > Yep, exactly! > >> Just call 'virtio_transport_dec_rx_pkt(skb->len)'. skb > > It depends on how we call virtio_transport_inc_rx_pkt(). If we use > hdr->len there I would use the same to avoid confusion. Plus that's the > value the other peer sent us, so definitely the right value to increase > fwd_cnt with. But if skb->len always reflects it, then that's fine. i've checked 'virtio_transport_rx_work()', it calls 'virtio_vsock_skb_rx_put()' which sets 'skb->len'. Value is used from header, so seems 'skb->len' == 'hdr->len' in this case. > >> is never returned to queue to read it again, so i think may be there is no sense for >> extra call 'skb_pull'? > > Right! > > Thanks, > Stefano >
On Mon, Mar 06, 2023 at 07:00:10PM +0300, Arseniy Krasnov wrote: > > >On 06.03.2023 18:51, Stefano Garzarella wrote: >> On Mon, Mar 06, 2023 at 06:31:22PM +0300, Arseniy Krasnov wrote: >>> >>> >>> On 06.03.2023 15:08, Stefano Garzarella wrote: >>>> On Sun, Mar 05, 2023 at 11:07:37PM +0300, Arseniy Krasnov wrote: >>>>> In case of SOCK_SEQPACKET all sk_buffs are used once - after read some >>>>> data from it, it will be removed, so user will never read rest of the >>>>> data. Thus we need to update credit parameters of the socket like whole >>>>> sk_buff is read - so call 'skb_pull()' for the whole buffer. >>>>> >>>>> 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 | 2 +- >>>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> Maybe we could avoid this patch if we directly use pkt_len as I >>>> suggested in the previous patch. >>> Hm, may be we can avoid calling 'skb_pull()' here if 'virtio_transport_dec_rx_pkt()' >>> will use integer argument? >> >> Yep, exactly! >> >>> Just call 'virtio_transport_dec_rx_pkt(skb->len)'. skb >> >> It depends on how we call virtio_transport_inc_rx_pkt(). If we use >> hdr->len there I would use the same to avoid confusion. Plus that's the >> value the other peer sent us, so definitely the right value to increase >> fwd_cnt with. But if skb->len always reflects it, then that's fine. >i've checked 'virtio_transport_rx_work()', it calls 'virtio_vsock_skb_rx_put()' which >sets 'skb->len'. Value is used from header, so seems 'skb->len' == 'hdr->len' in this >case. Thank you for checking it. However, I still think it is better to use `hdr->len` (we have to assign it to `pkt_len` anyway, as in the proposal I sent for patch 1), otherwise we have to go every time to check if skb_* functions touch skb->len. E.g. skb_pull() decrease skb->len, so I'm not sure we can call virtio_transport_dec_rx_pkt(skb->len) if we don't remove `skb_pull(skb, bytes_to_copy);` inside the loop. Thanks, Stefano
On Mon, Mar 06, 2023 at 05:18:52PM +0100, Stefano Garzarella wrote: > On Mon, Mar 06, 2023 at 07:00:10PM +0300, Arseniy Krasnov wrote: > > > > > > On 06.03.2023 18:51, Stefano Garzarella wrote: > > > On Mon, Mar 06, 2023 at 06:31:22PM +0300, Arseniy Krasnov wrote: > > > > > > > > > > > > On 06.03.2023 15:08, Stefano Garzarella wrote: > > > > > On Sun, Mar 05, 2023 at 11:07:37PM +0300, Arseniy Krasnov wrote: > > > > > > In case of SOCK_SEQPACKET all sk_buffs are used once - after read some > > > > > > data from it, it will be removed, so user will never read rest of the > > > > > > data. Thus we need to update credit parameters of the socket like whole > > > > > > sk_buff is read - so call 'skb_pull()' for the whole buffer. > > > > > > > > > > > > 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 | 2 +- > > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > Maybe we could avoid this patch if we directly use pkt_len as I > > > > > suggested in the previous patch. > > > > Hm, may be we can avoid calling 'skb_pull()' here if 'virtio_transport_dec_rx_pkt()' > > > > will use integer argument? > > > > > > Yep, exactly! > > > > > > > Just call 'virtio_transport_dec_rx_pkt(skb->len)'. skb > > > > > > It depends on how we call virtio_transport_inc_rx_pkt(). If we use > > > hdr->len there I would use the same to avoid confusion. Plus that's the > > > value the other peer sent us, so definitely the right value to increase > > > fwd_cnt with. But if skb->len always reflects it, then that's fine. > > i've checked 'virtio_transport_rx_work()', it calls 'virtio_vsock_skb_rx_put()' which > > sets 'skb->len'. Value is used from header, so seems 'skb->len' == 'hdr->len' in this > > case. > > Thank you for checking it. > > However, I still think it is better to use `hdr->len` (we have to assign it > to `pkt_len` anyway, as in the proposal I sent for patch 1), otherwise we > have to go every time to check if skb_* functions touch skb->len. > > E.g. skb_pull() decrease skb->len, so I'm not sure we can call > virtio_transport_dec_rx_pkt(skb->len) if we don't remove `skb_pull(skb, > bytes_to_copy);` inside the loop. > I think it does make reasoning about the bytes accounting easier if it is based off of the non-mutating hdr->len. Especially if vsock does ever support tunneling (e.g., through virtio-net) or some future feature that makes the skb->len more dynamic. Best, Bobby
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 2e2a773df5c1..30b0539990ba 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -466,7 +466,6 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, dequeued_len = err; } else { user_buf_len -= bytes_to_copy; - skb_pull(skb, bytes_to_copy); } spin_lock_bh(&vvs->rx_lock); @@ -484,6 +483,7 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, msg->msg_flags |= MSG_EOR; } + skb_pull(skb, skb->len); virtio_transport_dec_rx_pkt(vvs, skb); kfree_skb(skb); }