Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4745332rdb; Tue, 12 Dec 2023 08:11:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEvhPEtrCqKQRFpVjpvz1mykY+77THaONMFH04CSGTfKkR/vJ6nl9nCOMsreew/WTzj9rx X-Received: by 2002:a05:6a20:1445:b0:190:cbe:9edd with SMTP id a5-20020a056a20144500b001900cbe9eddmr3694438pzi.54.1702397512048; Tue, 12 Dec 2023 08:11:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702397512; cv=none; d=google.com; s=arc-20160816; b=Y19UsZ/bOtizw+iEU9ktVwS9M+cLsNkyhHkgdQ42btFOaigriiIRbzZurh0knUnB8P tRCtmGmFOb1JkSO/p1SLWnISfRVPLjnbOjqTumksTfObcrnOADC8kIJz4nWanuP7+V9C G1TTC73AIOF2JnI4lwZLWlZQHz1XjRlWB5Oqrk9+z0k35e1IiFl7UT+NiXcWtEIMPJFY hI7ebWJvsOW/oYgh4+INQZXIK9F1ZHVemYHFDdtiiZET0CJaNYeIJrpUDl4qdE2iYKd4 dclX7fjQMVzY/yHTRxr/sLWp71hjioEdaTE+3DQhWBLsMETM92zlC9FgcvUJF0Pml69l 26Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=gDJ4BJvrh413d67atQh4JmcBdn9fiHCIFP3pSXKUEOs=; fh=mgDOnflgqBhki4srQQbjlV/AUGmKs0Gt5yx+zXhaHYo=; b=aP/rfLQ6DtOdreUtjAKGzxCFcpnRvzevHqi6ltBkSMUSJwP3uF0wPd+gNc6uekv1xk C9Hyqn+uqTRYc2VTNuYYUHhG3F3HnreDWxah3+N5SLvpGvjn9xAwuj5gYIbo8qZ0szQy U5P/DBE9+IQTQrNE/HO3aVKTeQeDFNMe8+2HQdRryALKLNLLUVagrDuCoywvzcbapYlS /C4EfarLE2uljWIXSz1PDU/vjm2EaTKtbOB9/qlSBWDAlen0QAivMGlJCOl+DTylgTTA PGuDH4xva5nIcMSvKY8pxCk9nCNoTGmXEeGHQVLyDoPrSusOFLIyNl78tddYEr2iQgEk Wayw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aok3d51H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id j4-20020a654304000000b005c677a35320si7753699pgq.479.2023.12.12.08.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 08:11:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aok3d51H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 3743580268DD; Tue, 12 Dec 2023 08:11:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346578AbjLLQLY (ORCPT + 99 others); Tue, 12 Dec 2023 11:11:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346676AbjLLQLW (ORCPT ); Tue, 12 Dec 2023 11:11:22 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB86F129 for ; Tue, 12 Dec 2023 08:11:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702397482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gDJ4BJvrh413d67atQh4JmcBdn9fiHCIFP3pSXKUEOs=; b=aok3d51Hgnyi+IImkwUue9qKWQrbtwRRIRrzdobGkEjB6q9MgiLr+apqHj4oZAPqiblVZZ y0/6gR+hPYc8upeUQTl0sbUI2WiZ+8HT7Qzzid4lI+VagKnf/q7QJXWIdJP+MPFoxKmdM8 g/2BI5I7iEJ6WXlkNTwXwdoVCvZEJCk= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-408-Ld2XKuVVMzCL65MCojZMtw-1; Tue, 12 Dec 2023 11:11:19 -0500 X-MC-Unique: Ld2XKuVVMzCL65MCojZMtw-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a1d03a03bc9so332501266b.0 for ; Tue, 12 Dec 2023 08:11:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702397478; x=1703002278; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gDJ4BJvrh413d67atQh4JmcBdn9fiHCIFP3pSXKUEOs=; b=N2jmYPgurQIWNQKzXvvDV5TJcaNLCc8qOaE0AgVVzfs6buWmcU9uK0CSWNwzxzWGhp Ck9GaNlh0az//oiONQolcT/I8ieWwqpKvAX+bxbxFs6fzbR9ark1Np3Itsa4FmhEVNSx pH64L/oCyr8rqU52QokxP74cJKuQVxLkB2R/s6n9QY5lRhgrtkglngs10C8rk4XVhCNd smr4kDR1gqr8dvQB2M6YdPo6AIH25vBz9KvGE8PQCzgecOHPzv+qUbPInWj+Gl5+E1tI oVR/Q46suAHpj7y5W95Xv8TclztHFcmAkpfDzf2bHDpuvTj/6321Zn63+JM5uenOFl9C ovAw== X-Gm-Message-State: AOJu0Yy2ULyc3APTE5WYS0sZLNK8Z3PAjFKH/fDILMT2QE69xAbS2c2P 5PR3J0zpBk9E2YoPLbVwwJVS724ZfHia4aalbblYZoz8E9NnDzzIEgxtfemRT2gYFKTRPUkSDOG UbdFQmOJcE4BPArfzM1nRr6Ht X-Received: by 2002:a17:907:948f:b0:a04:4b57:8f27 with SMTP id dm15-20020a170907948f00b00a044b578f27mr3729867ejc.60.1702397478652; Tue, 12 Dec 2023 08:11:18 -0800 (PST) X-Received: by 2002:a17:907:948f:b0:a04:4b57:8f27 with SMTP id dm15-20020a170907948f00b00a044b578f27mr3729847ejc.60.1702397478298; Tue, 12 Dec 2023 08:11:18 -0800 (PST) Received: from redhat.com ([2.52.23.105]) by smtp.gmail.com with ESMTPSA id ld4-20020a1709079c0400b009a19701e7b5sm6464141ejc.96.2023.12.12.08.11.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 08:11:17 -0800 (PST) Date: Tue, 12 Dec 2023 11:11:13 -0500 From: "Michael S. Tsirkin" To: Arseniy Krasnov Cc: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jason Wang , Bobby Eshleman , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@sberdevices.ru, oxffffaa@gmail.com Subject: Re: [PATCH net-next v8 3/4] virtio/vsock: fix logic which reduces credit update messages Message-ID: <20231212110953-mutt-send-email-mst@kernel.org> References: <20231211211658.2904268-1-avkrasnov@salutedevices.com> <20231211211658.2904268-4-avkrasnov@salutedevices.com> <20231212105322-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Tue, 12 Dec 2023 08:11:45 -0800 (PST) On Tue, Dec 12, 2023 at 06:50:39PM +0300, Arseniy Krasnov wrote: > > > On 12.12.2023 18:54, Michael S. Tsirkin wrote: > > On Tue, Dec 12, 2023 at 12:16:57AM +0300, Arseniy Krasnov wrote: > >> 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). > > > > I don't get what does "to stuck both tx and rx sides" mean. > > I meant situation when tx waits for the free space, while rx doesn't send > credit update, just waiting for more data. Sorry for my English :) > > > Besides being agrammatical, is there a way to do this without > > playing with SO_RCVLOWAT? > > No, this may happen only with non-default SO_RCVLOWAT values (e.g. != 1) > > Thanks, Arseniy I am split on whether we need the Fixes tag. I guess if the other side is vhost with SO_RCVLOWAT then it might be stuck and it might apply without SO_RCVLOWAT on the local kernel? > > > >> > >> Fixes: b89d882dc9fc ("vsock/virtio: reduce credit update messages") > >> Signed-off-by: Arseniy Krasnov > >> --- > >> 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 e137d740804e..8572f94bba88 100644 > >> --- a/net/vmw_vsock/virtio_transport_common.c > >> +++ b/net/vmw_vsock/virtio_transport_common.c > >> @@ -558,6 +558,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; > >> > >> @@ -601,7 +603,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); > >> > >> @@ -611,9 +616,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 > >