From patchwork Sun Mar 19 18:51:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 71846 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp842923wrt; Sun, 19 Mar 2023 12:20:02 -0700 (PDT) X-Google-Smtp-Source: AK7set/RpDeKpI7WbwNSlEXyXTOYbH/SkNK69wR7d+aVJ2IpEIGexZxcjBNvg7rNzYrzAFrh6hVt X-Received: by 2002:a05:6a20:4ca0:b0:ce:2fb4:5fc4 with SMTP id fq32-20020a056a204ca000b000ce2fb45fc4mr14782046pzb.38.1679253602337; Sun, 19 Mar 2023 12:20:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679253602; cv=none; d=google.com; s=arc-20160816; b=aauyOiIeZVVp9Gzs98L4SUgzlHXRoQYq74b1XFKjStUJ1gbf33dWxNL/0MWu8o6YXU cwj/Oo8QlcJSmm4HFc2BZqmvzDcnK1EobvtsFsOmdGbqsFhSWkaD9oIEqdBXuqu4IcJH zqao7r2I7zi/RxsgV1JXVZM1Hpkrjq5o2t6yoxFYx0vV9xUnQ+3uM8ZBp5RrTU+ZCf0b gWb2WdCbqSYo3VaRJd1W+/Lvv2foHD4tAPYnvIbBs11gZcYVdz5syIpxIG+Wn4UDsP+m pKwtzKLG7LH3mCAf3eZPB4UoVg9xsTacqG47Y3cJJyn/IT84VC0tKL1P7e1J8VbP9FkD PCyQ== 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=4xeEPECpVnpzfQf1fesctV2AnA8LeKYtLCBEiuPhocg=; b=ofDqusTZkqTDIXkdmc4BwBod7+psJbWtFYaNalv6rIOFSdVLRLsEhpSSEWB0D0awx/ wRS8N7BzsqNEcrrExS/mmAXJ10yaNmcnrdnSOcH1t15Mb5qhmwFmN7gJ08O4TTuv2lpR DW77ZDSh2vMDG9Kdo08riRd2AVs6G6pSC/acn31p1vD3kg/2Oc8UY0gFCd2mzih/V+wt 7clO7/wgQU6ORsylZOARwvr7MWQUr3TMmbBoNuIyp5ZqHrB/JVu3GpUmjUcLchdu7Vxj qETJ5Ot2b4JwyMQZ88o6+TUpS+Dxtk2pbhMU2R7yKLlU5jUTiKIcae8z1zEZAAEAZFxw 34ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=akgHfvv8; 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 e11-20020a056a001a8b00b005a8bc2293c3si8453090pfv.263.2023.03.19.12.19.48; Sun, 19 Mar 2023 12:20:02 -0700 (PDT) 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=akgHfvv8; 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 S229877AbjCSSyf (ORCPT + 99 others); Sun, 19 Mar 2023 14:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjCSSyd (ORCPT ); Sun, 19 Mar 2023 14:54:33 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 837FB196BE; Sun, 19 Mar 2023 11:54:32 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id D9CD05FD0B; Sun, 19 Mar 2023 21:54:30 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1679252070; bh=4xeEPECpVnpzfQf1fesctV2AnA8LeKYtLCBEiuPhocg=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=akgHfvv8AkVLHgeCDpICG7WM0q3/HjV+IbSmam+sMzpXSE0xxLodG4Y1ZxKLOWZA2 PBhBsJbTchNoIJfSBv45e0YwBoSNjYbrFoM+A9dw5y+dYgSHXOksoyTsSlmgJRhq0t hDPPb27+rrFfkVMqQ52mBFjK/RQ0qo5VBnLqIoU+6FWkJ2aRGddlfQrpqchr895ZVi Kr/Bx5/gMQx9dvMfF+u0SAXCqg7RNrJdxpUrpMuBBfg/LXFCJeGxiHMTPMLvU5FHs4 hRtNG3VjTcbNPqfu6ZTUjjwE8iFGWChJLo6v1Q78dlD8X1qrkniM95ca7qKB9NgV9S AZl93kgvL5/zw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 19 Mar 2023 21:54:30 +0300 (MSK) Message-ID: <63445f2f-a0bb-153c-0e15-74a09ea26dc1@sberdevices.ru> Date: Sun, 19 Mar 2023 21:51:06 +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: To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bobby Eshleman CC: , , , , , , From: Arseniy Krasnov Subject: [RFC PATCH v1 1/3] virtio/vsock: fix header length on skb merging X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) 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/19 16:43:00 #20974059 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760825025658304690?= X-GMAIL-MSGID: =?utf-8?q?1760825025658304690?= This fixes header length calculation of skbuff during data appending to it. When such skbuff is processed in dequeue callbacks, e.g. 'skb_pull()' is called on it, 'skb->len' is dynamic value, so it is impossible to use it in header, because value from header must be permanent for valid credit calculation ('rx_bytes'/'fwd_cnt'). Fixes: 077706165717 ("virtio/vsock: don't use skbuff state to account credit") Signed-off-by: Arseniy Krasnov --- 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 6d15cd4d090a..3c75986e16c2 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -1091,7 +1091,7 @@ virtio_transport_recv_enqueue(struct vsock_sock *vsk, memcpy(skb_put(last_skb, skb->len), skb->data, skb->len); free_pkt = true; last_hdr->flags |= hdr->flags; - last_hdr->len = cpu_to_le32(last_skb->len); + le32_add_cpu(&last_hdr->len, len); goto out; } } From patchwork Sun Mar 19 18:52:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 71842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp835980wrt; Sun, 19 Mar 2023 12:00:08 -0700 (PDT) X-Google-Smtp-Source: AK7set+Hyai8Zs2fZrzeWoDJrOYLBZ4KjhnfPAbgicJjeWf7Jma88HP+9WLNrd+NVA2kTLgGfKwo X-Received: by 2002:a17:902:f34a:b0:1a0:44e7:59dc with SMTP id q10-20020a170902f34a00b001a044e759dcmr11507343ple.40.1679252408179; Sun, 19 Mar 2023 12:00:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679252408; cv=none; d=google.com; s=arc-20160816; b=ad0ibz1+vHrfQ8LNxOGp44kRoCSXLElgHTpgthgSiszHPQwgTK8CysrNs2J3gS3oh1 6BX1Zi4iKCAYWEaSaJJuMp+yBIo1AdO4FPYdH6gLx3oOvfd2hRuq+SC0QxMa232Y/do0 A1ceOYVoQWgva841FAQXMU+qjMd2h/Ss5+0o5tKKB3V1pEN70nHWJrOVgPvQ+tiEP/71 F0NhTAc3TX3mOMgu7DkUyINCHlNDMqGZLnYXUS8GPof/xsMfr3h62epvUENClILyflBr SdM9oFWb8y3M1c6p/yRevBQyNheHaJBXfg508qCDdyxAluLU0DS1pjGSDJ2wgJbhAN7A g6EA== 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=C781NWpzeOK41C9p67pG5T6Jta5orOVTpQeZsJpmG/8=; b=sLvgeGQuWwTsqBBae/2FCycNB2LLCvXyEu84aIttj/Cn5HExiC+MUCYPHuM75uvSRv lgcVPpwxooCoyqKWqm5F9nWLHBlryqiJnu/2I6iSjRLW0NjWLFKiaaym60lBxEmuLsEi Z2xp/3oVWPgGOrWWsI3+dQDjcAavsS7fTO1qmNi3PE+EpiKmw+beMPa0h/lRf7WSTjvx OYVqjYHaiBl7GmBioBr9J2A+yZt34PUJ1/uE3yxUzK1G31cVWK0Wb5iTSYEQ3TIyZVq1 hPwzbpp63IqWmkxF8nMIVSESE7OC8zozA8xGB58KN0d/HgR3pUwwM3JDpnYsvcHT+77y fCiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=Oy80ZgyH; 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 q12-20020a17090311cc00b0019cec510d4csi9539935plh.444.2023.03.19.11.59.52; Sun, 19 Mar 2023 12:00:08 -0700 (PDT) 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=Oy80ZgyH; 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 S229901AbjCSSzn (ORCPT + 99 others); Sun, 19 Mar 2023 14:55:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229889AbjCSSzl (ORCPT ); Sun, 19 Mar 2023 14:55:41 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CB934485; Sun, 19 Mar 2023 11:55:40 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 8A9995FD08; Sun, 19 Mar 2023 21:55:38 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1679252138; bh=C781NWpzeOK41C9p67pG5T6Jta5orOVTpQeZsJpmG/8=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=Oy80ZgyHynh27XtVAJRm3hu4Pm8dP5oed2sCfK9E9/SIcnCtqyNHMWai0IXCAsd6E SDKEThUAF1BD6VQdWAIeXJFdjkp/czlQace9ewICsfAUJB71Z1xWgilOGAylEE0fLg ZiQV27pHtD5ziKQ8z/oijZSI+NVg1Y4JFQGqTmfjGt1VgkKMToSV+osLYP7QZydFgL lTrtlAkiKi00oDxCK17fZG5cZHpAKhg+oOJDqBwUEdFJFT4hlr4JY37vstNGStb7yX qsnxht7tReX2KI0nnCbA6HazNuiTTMT+OADc0oKcX5eIBdvdnwWqtJ+CZESVwjuXXy KXJFR3QAMvNlw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 19 Mar 2023 21:55:38 +0300 (MSK) Message-ID: Date: Sun, 19 Mar 2023 21:52:19 +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: To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bobby Eshleman CC: , , , , , , From: Arseniy Krasnov Subject: [RFC PATCH v1 2/3] virtio/vsock: add WARN() for invalid state of socket X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) 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/19 16:43:00 #20974059 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760823772898571259?= X-GMAIL-MSGID: =?utf-8?q?1760823772898571259?= This prints WARN() and returns from stream dequeue callback when socket's queue is empty, but 'rx_bytes' still non-zero. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 3c75986e16c2..c35b03adad8d 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -388,6 +388,13 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, u32 free_space; spin_lock_bh(&vvs->rx_lock); + + if (skb_queue_empty(&vvs->rx_queue) && vvs->rx_bytes) { + WARN(1, "No skbuffs with non-zero 'rx_bytes'\n"); + spin_unlock_bh(&vvs->rx_lock); + return err; + } + while (total < len && !skb_queue_empty(&vvs->rx_queue)) { skb = skb_peek(&vvs->rx_queue); From patchwork Sun Mar 19 18:53:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 71845 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp842895wrt; Sun, 19 Mar 2023 12:19:57 -0700 (PDT) X-Google-Smtp-Source: AK7set/wBH61Dj0/ngyqMlLPsfDA1aXuIESYKwR+tRObOYE9HNGkPBjP4NFcrmv6JIknHd+N/xlq X-Received: by 2002:a17:902:ebd2:b0:19b:107b:698e with SMTP id p18-20020a170902ebd200b0019b107b698emr13025116plg.14.1679253597403; Sun, 19 Mar 2023 12:19:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679253597; cv=none; d=google.com; s=arc-20160816; b=f0XuH7TsagQeSibJHmtGq7S21VAf1U4UfQ1e29UPwvC5y0EZm5PGYBJnVAus6pUVJ3 nNiym/zbqQw9toCzC+lY9N0wrDutBSnsr/VvbzyJFPXKLlOPYNQm19KzPyaxkiE/mAHk 8Xy/lPUQvUvBcQz0R6hjmA5bpG7zJJruGQYYX3rP5AwFvAkcpABAGC9FnAbyuBfyrZqq y7Ia+yYrzNmh+eP/On3AWMFKgxNiTAywCyh4rhPobI3CxUmP9Z+SokXIlGae+J2dW8sC IrTbHsi6TMepHLj/C4Dc62zTeolsuF9wff4n+f917TuDbPHkBEy/x2sZEzJiu7gbCWYO no1Q== 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=Ur4jg6uAteONoMZU6lu41Y3TNMOYC8XZYn3Gott3yvA=; b=bLRZpsgU+v+0uOb8oJD47hCaSqwES/P4PE5gME9YWLIntbiDNMPnZYSh87Q4RN0mtF 3yzXIyN/H2lrkTrSwdpY8DB9N5UM+fFjgk0HRt09Ah5GoEs2WU6/PFakot14xbbRt+NW 14XDXGmJlE84427YrM+mp3nufNtK6UbDYy9v8X7yVBNp+DMI+Rj7QEmXHuJOpkrnvHNB nNNh1qEsbzLL5RPhIWwIpk/uxoF/ISlU/NopmJCS17RCb3u2l4ZedijWDCrCnrn9gOFa IoP7ubdBlnU4YHYd77sfUyGcboKDFP0gcHz/Rzvny8avAR6PEflgu4pb/aH+huUf9Gf6 qXzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=hYExZj62; 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 q1-20020a170902dac100b001a04202f782si9681360plx.122.2023.03.19.12.19.44; Sun, 19 Mar 2023 12:19:57 -0700 (PDT) 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=hYExZj62; 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 S229924AbjCSS5T (ORCPT + 99 others); Sun, 19 Mar 2023 14:57:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjCSS5Q (ORCPT ); Sun, 19 Mar 2023 14:57:16 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0905EF749; Sun, 19 Mar 2023 11:57:15 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 5A8B35FD08; Sun, 19 Mar 2023 21:57:13 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1679252233; bh=Ur4jg6uAteONoMZU6lu41Y3TNMOYC8XZYn3Gott3yvA=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=hYExZj62rdKq/kQoxBw7vhVqZHzrMPXS1mzbZUM2WEuHSuQ/bJRIYnObuLlGDJCWE RprVYm7OatuydeKkYwb//Xd/1WrhwHmxOtE/vb2wOroGtpRHfJDkmz17mSaZh5MMF0 Rn3QFlZpThxJTfYYb26aF1dYPinMORmCLDncowCImhUZZeT4LvlBA2IsV4B7Vr0Nqt Xr6fg0FEAj0bPrEyYshWwA/7Znku/iattGIP8hLcIMSLejHJw54W70PevOQ9s4OeJw 088jv1DKn99uKPCMdv5/OidUKYx8v+ek+1SECxKtSnqcMW7fQKhKd288HOCaQ4BPYH y2Eh1Vt8bJXJQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 19 Mar 2023 21:57:13 +0300 (MSK) Message-ID: <14ca87d1-3e07-85e9-d11c-39789a9d17d4@sberdevices.ru> Date: Sun, 19 Mar 2023 21:53:54 +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: To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bobby Eshleman CC: , , , , , , From: Arseniy Krasnov Subject: [RFC PATCH v1 3/3] test/vsock: skbuff merging test 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/19 16:43:00 #20974059 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760825020318309621?= X-GMAIL-MSGID: =?utf-8?q?1760825020318309621?= This adds test which checks case when data of newly received skbuff is appended to the last skbuff in the socket's queue. This test is actual only for virtio transport. Signed-off-by: Arseniy Krasnov --- tools/testing/vsock/vsock_test.c | 81 ++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 3de10dbb50f5..00216c52d8b6 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -968,6 +968,82 @@ static void test_seqpacket_inv_buf_server(const struct test_opts *opts) test_inv_buf_server(opts, false); } +static void test_stream_virtio_skb_merge_client(const struct test_opts *opts) +{ + ssize_t res; + int fd; + + fd = vsock_stream_connect(opts->peer_cid, 1234); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + res = send(fd, "HELLO", strlen("HELLO"), 0); + if (res != strlen("HELLO")) { + fprintf(stderr, "unexpected send(2) result %zi\n", res); + exit(EXIT_FAILURE); + } + + control_writeln("SEND0"); + /* Peer reads part of first packet. */ + control_expectln("REPLY0"); + + /* Send second skbuff, it will be merged. */ + res = send(fd, "WORLD", strlen("WORLD"), 0); + if (res != strlen("WORLD")) { + fprintf(stderr, "unexpected send(2) result %zi\n", res); + exit(EXIT_FAILURE); + } + + control_writeln("SEND1"); + /* Peer reads merged skbuff packet. */ + control_expectln("REPLY1"); + + close(fd); +} + +static void test_stream_virtio_skb_merge_server(const struct test_opts *opts) +{ + unsigned char buf[64]; + ssize_t res; + int fd; + + fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + control_expectln("SEND0"); + + /* Read skbuff partially. */ + res = recv(fd, buf, 2, 0); + if (res != 2) { + fprintf(stderr, "expected recv(2) failure, got %zi\n", res); + exit(EXIT_FAILURE); + } + + control_writeln("REPLY0"); + control_expectln("SEND1"); + + res = recv(fd, buf, sizeof(buf), 0); + if (res != 8) { + fprintf(stderr, "expected recv(2) failure, got %zi\n", res); + exit(EXIT_FAILURE); + } + + res = recv(fd, buf, sizeof(buf), MSG_DONTWAIT); + if (res != -1) { + fprintf(stderr, "expected recv(2) success, got %zi\n", res); + exit(EXIT_FAILURE); + } + + control_writeln("REPLY1"); + + close(fd); +} + static struct test_case test_cases[] = { { .name = "SOCK_STREAM connection reset", @@ -1038,6 +1114,11 @@ static struct test_case test_cases[] = { .run_client = test_seqpacket_inv_buf_client, .run_server = test_seqpacket_inv_buf_server, }, + { + .name = "SOCK_STREAM virtio skb merge", + .run_client = test_stream_virtio_skb_merge_client, + .run_server = test_stream_virtio_skb_merge_server, + }, {}, };