Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp843625rdb; Fri, 20 Oct 2023 00:25:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDtrJVLL6xaP/mbm4+COZPyAv/Vu9vnoE/KeMzV2/39n2rL6KO+P3lHXSO0XO8zglz/KOV X-Received: by 2002:a17:90a:f691:b0:27d:153a:8894 with SMTP id cl17-20020a17090af69100b0027d153a8894mr1032135pjb.45.1697786702126; Fri, 20 Oct 2023 00:25:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697786702; cv=none; d=google.com; s=arc-20160816; b=EVgQScKd9TJmi1nlSiuxJCaYbV9I1V5PxnuKOD6bLT01sOOQJ4aOQJKKR4+0DOWXdJ gjV6ReKlm7IfCwfll1t6OglxKol7/8AEJvlsmb5FYgPbxE/L/R9eaWIJwlIg/HTWjtia VSXzrH4L2Fsm2nysbsPUdm0M+Jizl4Gre5G8/2FiSwN8bChL3xlhgx57Xh+mJx9HufDV +B3DV8nVPxOSp1aO27xfQRvzj5NQDbqdFtrax5+naZzRxLRFgE0GLXeOwyNn4kMX65J2 UGAR6zz7Mynn8kjyHOkXGd+ywTzqD3ffYKnfZFHRBgtqH/4Gm39Ov8m7tPdixeBemz2t fe0g== 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=9ps48hhG6wzB4Y+L3PoxO3ps+/OQgTevPQsiK41ym/g=; fh=g5qm3EvcEddfDirpyLMc7MJe9QOvYDcNxwtLglLkguo=; b=js++Z0OytSsk9+lvuZxLj5fdnATAI7cOHmpEwlVexhgF4DUeinmRZD/NzTdFOGU456 Qz+T+m8e31bKW4VV5MPhMtM6zUqPvvitytVE1xdRItVMM+JyS5gESuNWX2qioUJ1tBP1 5ut9f9cSi8qHoTZwUInafXUPM040ROwFAPEHNIuWT62cqvjwOe7xVWmmWxGivZ0UoO9Y I2JoZ/5GSApo46HZ5zyYHNVpHJHwdpmXarl+B7gDY19FxkyGGCL6kO7Bi7j867zEKXor 2e1EucuaKFpBV4WGw89XqzkL0g7P/iiQqiMDTk4OHjU2qqG2pPW5drj+6XrmmU44lWKR XxFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="TX75/Qy5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id m12-20020a17090a71cc00b00274d5eb88c4si1305270pjs.90.2023.10.20.00.25.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 00:25:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="TX75/Qy5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id B523883B2E4F; Fri, 20 Oct 2023 00:24:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376396AbjJTHYy (ORCPT + 99 others); Fri, 20 Oct 2023 03:24:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376359AbjJTHYx (ORCPT ); Fri, 20 Oct 2023 03:24:53 -0400 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 87A641733 for ; Fri, 20 Oct 2023 00:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697786630; 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=9ps48hhG6wzB4Y+L3PoxO3ps+/OQgTevPQsiK41ym/g=; b=TX75/Qy51C9q15LQPdZc5GIFR3rj6VVFvcwLfLYKwALGFdZj+aValLlF7Lv5twCrJFkrbs 1SgjkAgJIBllJayFF60xkAlgoal9ZdGeZ0OJVABQk0K6kZ7kQUSIsDxiM/K6tAX8TRurfe Z4+F7892GBNz1TasFMpEUrrqdxWbZDs= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-Ffsvw09dOYmrFf124ig7cA-1; Fri, 20 Oct 2023 03:23:49 -0400 X-MC-Unique: Ffsvw09dOYmrFf124ig7cA-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-9b822f5c156so36686966b.3 for ; Fri, 20 Oct 2023 00:23:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697786627; x=1698391427; 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=9ps48hhG6wzB4Y+L3PoxO3ps+/OQgTevPQsiK41ym/g=; b=mx6TkQwT2bCcVYnv5HSe4pcNVr5rOBQUTMSVGwwBV09TMS265Ll3gqCbH8LrzWP/2d Xv7XAndgeG12II9goWBeCaREi3KoAjq0BW8JG4rDznkq3WOfOKUYOnDIyWgBur+JJijB I6FOlRD1TIu2l9RjTpXmkJkXN9l5HYpxnw8dqE0URfud3qHKHgdom8aEUf9taV7ppLyv U5nfvctiEz1yRyJHNdAsnzyo9mcAOSLiUUsd/UNRK6MnF/hpi66EvmsFDGUe/2NknSIY nHGiQuqTDcD4BbN0QpnqO0ZfWtprkPyIWGbqxuoRjs5Xf2F+eReB8jcXw2Xc2zlxGuux rJSA== X-Gm-Message-State: AOJu0YyBkqhkGvxbSBwY4x+LsbKsG6Q68OeFJL40oGvZUjxBwjc7iqpU UgM+InUJumDI9VNYXUOUpfxlvNX2dBABn/mGzCJbcfjZSPtIBMHTjjz0QN9XdlvadrqS+dcIG5m x+krascJ9pfWz1hFPHLLAdF/NgT/Wxui1 X-Received: by 2002:a17:907:d9f:b0:9bd:d1e8:57f1 with SMTP id go31-20020a1709070d9f00b009bdd1e857f1mr730064ejc.50.1697786627588; Fri, 20 Oct 2023 00:23:47 -0700 (PDT) X-Received: by 2002:a17:907:d9f:b0:9bd:d1e8:57f1 with SMTP id go31-20020a1709070d9f00b009bdd1e857f1mr730049ejc.50.1697786627165; Fri, 20 Oct 2023 00:23:47 -0700 (PDT) Received: from sgarzare-redhat (host-87-12-185-56.business.telecomitalia.it. [87.12.185.56]) by smtp.gmail.com with ESMTPSA id e27-20020a170906749b00b0097404f4a124sm935380ejl.2.2023.10.20.00.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 00:23:46 -0700 (PDT) Date: Fri, 20 Oct 2023 09:23:31 +0200 From: Stefano Garzarella To: Alexandru Matei Cc: Stefan Hajnoczi , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Mihai Petrisor , Viorel Canja Subject: Re: [PATCH] vsock: initialize the_virtio_vsock before using VQs Message-ID: References: <20231018183247.1827-1-alexandru.matei@uipath.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 00:24:59 -0700 (PDT) On Fri, Oct 20, 2023 at 12:12:04AM +0300, Alexandru Matei wrote: >On 10/19/2023 11:54 AM, Stefano Garzarella wrote: >> On Wed, Oct 18, 2023 at 09:32:47PM +0300, Alexandru Matei wrote: >>> Once VQs are filled with empty buffers and we kick the host, it can send >>> connection requests. If 'the_virtio_vsock' is not initialized before, >>> replies are silently dropped and do not reach the host. >> >> Are replies really dropped or we just miss the notification? >> >> Could the reverse now happen, i.e., the guest wants to send a connection request, finds the pointer assigned but can't use virtqueues because they haven't been initialized yet? >> >> Perhaps to avoid your problem, we could just queue vsock->rx_work at the bottom of the probe to see if anything was queued in the meantime. >> >> Nit: please use "vsock/virtio" to point out that this problem is of the virtio transport. >> >> Thanks, >> Stefano > >The replies are dropped , the scenario goes like this: > > Once rx_run is set to true and rx queue is filled with empty buffers, the host sends a connection request. Oh, I see now, I thought virtio_transport_rx_work() returned early if 'the_virtio_vsock' was not set. > The request is processed in virtio_transport_recv_pkt(), and since there is no bound socket, it calls virtio_transport_reset_no_sock() which tries to send a reset packet. > In virtio_transport_send_pkt() it checks 'the_virtio_vsock' and because it is null it exits with -ENODEV, basically dropping the packet. > >I looked on your scenario and there is an issue from the moment we set the_virtio_vsock (in this patch) up until vsock->tx_run is set to TRUE. >virtio_transport_send_pkt() will queue the packet, but virtio_transport_send_pkt_work() will exit because tx_run is FALSE. This could be fixed by moving rcu_assign_pointer() after tx_run is set to TRUE. >virtio_transport_cancel_pkt() uses the rx virtqueue once the_virtio_vsock is set, so rcu_assign_pointer() should be moved after virtio_find_vqs() is called. > >I think the way to go is to split virtio_vsock_vqs_init() in two: >virtio_vsock_vqs_init() and virtio_vsock_vqs_fill(), as Vadim >suggested. This should fix all the cases: Yep, LGTM! Thank you both for the fix, please send a v2 with this approach! Stefano > >--- > net/vmw_vsock/virtio_transport.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > >diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c >index ad64f403536a..1f95f98ddd3f 100644 >--- a/net/vmw_vsock/virtio_transport.c >+++ b/net/vmw_vsock/virtio_transport.c >@@ -594,6 +594,11 @@ static int virtio_vsock_vqs_init(struct virtio_vsock *vsock) > vsock->tx_run = true; > mutex_unlock(&vsock->tx_lock); > >+ return 0; >+} >+ >+static void virtio_vsock_vqs_fill(struct virtio_vsock *vsock) >+{ > mutex_lock(&vsock->rx_lock); > virtio_vsock_rx_fill(vsock); > vsock->rx_run = true; >@@ -603,8 +608,6 @@ static int virtio_vsock_vqs_init(struct virtio_vsock *vsock) > virtio_vsock_event_fill(vsock); > vsock->event_run = true; > mutex_unlock(&vsock->event_lock); >- >- return 0; > } > > static void virtio_vsock_vqs_del(struct virtio_vsock *vsock) >@@ -707,6 +710,7 @@ static int virtio_vsock_probe(struct virtio_device *vdev) > goto out; > > rcu_assign_pointer(the_virtio_vsock, vsock); >+ virtio_vsock_vqs_fill(vsock); > > mutex_unlock(&the_virtio_vsock_mutex); > >@@ -779,6 +783,7 @@ static int virtio_vsock_restore(struct virtio_device *vdev) > goto out; > > rcu_assign_pointer(the_virtio_vsock, vsock); >+ virtio_vsock_vqs_fill(vsock); > > out: > mutex_unlock(&the_virtio_vsock_mutex); >-- >