Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5862667rdb; Thu, 14 Dec 2023 01:28:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVto6cg1vAkz+2rg74xkbYS00hWlTDUS2Gw//4/OJvjBmKZabBDZvf4UP/1IgfQV+2pp78 X-Received: by 2002:a05:6a00:608b:b0:6ce:f735:11f4 with SMTP id fp11-20020a056a00608b00b006cef73511f4mr3722447pfb.0.1702546124770; Thu, 14 Dec 2023 01:28:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702546124; cv=none; d=google.com; s=arc-20160816; b=KulQRS/fKXOUmAbSc2pbd8WwkPsSUOIw4J35tBXLY0dxH3UCby30N9WFX/DaxZrogb U14sXZ+7r2jXuOtuOBUGYwIlnxzo5rSloIGgMhYXNtCBZOY8lVnkrYUmy94l18i3bIsC EOgN5Xag3l+TUMpP3ymQlL5JRYihs+LAv8DCTw5ZEF1zVi29lWWJfCYtgUnWrbstK+VV YoxgCuOUva+C5L21RSFMskJPE19Z4MhaFpWmnPaAPDPUSUh2JEEOCWEop+J8IbV1IAwL dzYNxaekAEEyFy7KB6CozeAf8PPOqreYn2gQ83WxsULZu/JdDTyB+y9u/Jgv8qjZE6on 434A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=zcEvNIjBsCBhtUr7ZdFOfNL0OnIE9Ua1XraGXth61Iw=; fh=wIHqZpOIuzcidDZ82yQbOZuyHJty7uvaWDEh/efoVzA=; b=LM6wIDK+3FMwOja/e/d7h8HuujwboxnUqh8QC5YyQIHIQONonsNr8UUvuq3dF8aSgz yCxrXSQ2e2ng1xuT0ixFn6MWlW5aDh2u1MbJEGxGJghy/rbXw+GD2eHpbK5TO5/BRtWD +PURQi7ZY/N7jmRG9fheF4Gq3DcjE8Ah7f5bGsL64eZWM7+bHt5jlOwxCu/BgJs6iz0d jxx7qtL3TyD4pB+lbqYTCOapA8LrT5YBTizX9ae6s+1eeinmFNnlbohqLvAw2w5SoYzo osAxNUk/GgrcV1J+foxPqcKO9ly2uBUonSTZ/n5Kowgiqqrlr+NmNYt1OA16kjtigD2T BzVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=RIK3+7IX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=salutedevices.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id 6-20020a630f46000000b005c6251da182si10832300pgp.226.2023.12.14.01.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 01:28:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=RIK3+7IX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=salutedevices.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7FEC9802926B; Thu, 14 Dec 2023 01:28:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235589AbjLNJ21 (ORCPT + 99 others); Thu, 14 Dec 2023 04:28:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235430AbjLNJ2T (ORCPT ); Thu, 14 Dec 2023 04:28:19 -0500 Received: from mx1.sberdevices.ru (mx1.sberdevices.ru [37.18.73.165]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AF76115; Thu, 14 Dec 2023 01:28:24 -0800 (PST) Received: from p-infra-ksmg-sc-msk01 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id D4CB210006C; Thu, 14 Dec 2023 12:28:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru D4CB210006C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1702546102; bh=zcEvNIjBsCBhtUr7ZdFOfNL0OnIE9Ua1XraGXth61Iw=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=RIK3+7IXynz0In7EQzqZyVoVu6B8cw9/G6kZw0XJghhgGMwxCRmvtQBdeJlYEryWh R8nI2ki12yD1fQ8ec5Bhr6BThC6GbJg2LrsJPPe9tG4q1l1wBjs410dNIHAg65cQza QP5FeOK/uAbrurmEl50yhlFpIt344KSNiCmVuadaPIaIdqUY5jk5vnJRamRYZO5sO0 R38ItM4WRMxx8pea1cvtUEvzDzaTHUEO25LzJwNR8gQocCx/s5pOUWRyX1M/6oCY3h rW03wPLlGLTDis5m5ZNEeIPCJbLwNMsqpnMVEt4mMiiQc9mzFxfo5czu3/7ztoM7Qo SgDebept7cskw== Received: from smtp.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Thu, 14 Dec 2023 12:28:22 +0300 (MSK) Received: from localhost.localdomain (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 14 Dec 2023 12:28:21 +0300 From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , Subject: [PATCH net-next v9 1/4] virtio/vsock: fix logic which reduces credit update messages Date: Thu, 14 Dec 2023 12:19:44 +0300 Message-ID: <20231214091947.395892-2-avkrasnov@salutedevices.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20231214091947.395892-1-avkrasnov@salutedevices.com> References: <20231214091947.395892-1-avkrasnov@salutedevices.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 182105 [Dec 14 2023] X-KSMG-AntiSpam-Version: 6.1.0.3 X-KSMG-AntiSpam-Envelope-From: avkrasnov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 7 0.3.7 6d6bf5bd8eea7373134f756a2fd73e9456bb7d1a, {Tracking_from_domain_doesnt_match_to}, d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;smtp.sberdevices.ru:5.0.1,7.1.1;100.64.160.123:7.1.2;salutedevices.com:7.1.1;127.0.0.199:7.1.2, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2023/12/14 08:33:00 #22688916 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_NONE, T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Dec 2023 01:28:43 -0800 (PST) Add one more condition for sending credit update during dequeue from stream socket: when number of bytes in the rx queue is smaller than SO_RCVLOWAT value of the socket. This is actual for non-default value of SO_RCVLOWAT (e.g. not 1) - idea is to "kick" peer to continue data transmission, because we need at least SO_RCVLOWAT bytes in our rx queue to wake up user for reading data (in corner case it is also possible to stuck both tx and rx sides, this is why 'Fixes' is used). Fixes: b89d882dc9fc ("vsock/virtio: reduce credit update messages") Signed-off-by: Arseniy Krasnov Reviewed-by: Stefano Garzarella Acked-by: Michael S. Tsirkin --- Changelog: v6 -> v7: * Handle wrap of 'fwd_cnt'. * Do to send credit update when 'fwd_cnt' == 'last_fwd_cnt'. v7 -> v8: * Remove unneeded/wrong handling of wrap for 'fwd_cnt'. net/vmw_vsock/virtio_transport_common.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index c8e162c9d1df..7eabe5219ef7 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -557,6 +557,8 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, struct virtio_vsock_sock *vvs = vsk->trans; size_t bytes, total = 0; struct sk_buff *skb; + u32 fwd_cnt_delta; + bool low_rx_bytes; int err = -EFAULT; u32 free_space; @@ -600,7 +602,10 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, } } - free_space = vvs->buf_alloc - (vvs->fwd_cnt - vvs->last_fwd_cnt); + fwd_cnt_delta = vvs->fwd_cnt - vvs->last_fwd_cnt; + free_space = vvs->buf_alloc - fwd_cnt_delta; + low_rx_bytes = (vvs->rx_bytes < + sock_rcvlowat(sk_vsock(vsk), 0, INT_MAX)); spin_unlock_bh(&vvs->rx_lock); @@ -610,9 +615,11 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, * too high causes extra messages. Too low causes transmitter * stalls. As stalls are in theory more expensive than extra * messages, we set the limit to a high value. TODO: experiment - * with different values. + * with different values. Also send credit update message when + * number of bytes in rx queue is not enough to wake up reader. */ - if (free_space < VIRTIO_VSOCK_MAX_PKT_BUF_SIZE) + if (fwd_cnt_delta && + (free_space < VIRTIO_VSOCK_MAX_PKT_BUF_SIZE || low_rx_bytes)) virtio_transport_send_credit_update(vsk); return total; -- 2.25.1