Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1712148rda; Tue, 24 Oct 2023 00:23:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWudKQpAHKwAbIVkymiApHZpffoKb/NMMp5JfPQCmsegsXGbnSPC1jDHPsip3Zin0d5zXC X-Received: by 2002:a17:903:84f:b0:1c9:d25c:17c6 with SMTP id ks15-20020a170903084f00b001c9d25c17c6mr8802688plb.1.1698132223170; Tue, 24 Oct 2023 00:23:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698132223; cv=none; d=google.com; s=arc-20160816; b=zWvtVKhUdSXKSJxegUfKbJu+Cgv3XuNuPPgd6cEjWlavpBWkocilcasv4Rgob7JLl9 7GKj4rEl6W6cXrIcnw0quEphKBuj3Xj2s8YuetxReteeaDNeLuTMQ/HeIhkIZtEJnv7q SNHRJ9FaRUPDUj0BsCZaRswBcrt4yheJSf7BIHy19lFVpcXrqyJ5fLhAcbeT3j7IDx+g b4GpQd+TlynYiui6Fu5HreyJ26Oh2oZHMzbO8IeFfkb9juABRdvGUhGaNAX7yE92VPTX OD9q0nqco8NyWdeUym5gVGhXIS+0+nwmfgsxBKpa7iknx7CjgEPIddI0UNbMn2bdojAc lEbA== 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=rv0SpeFLc8EPDyVFSHvu8ODjo19NeLRxyGY2cziN3BQ=; fh=g5qm3EvcEddfDirpyLMc7MJe9QOvYDcNxwtLglLkguo=; b=w1S1qXqop/UDLzfg3zSj7mmJ83t38erwyo+nZFbptzGi6GE0kKRZ81dAc/wUnU5s9e HxPUSPDQkepgVcl2kt2LtxXnMDqOzL1kmh+KR+y/yPLQbLX3m+LRVK11cj2adqyK6awr zYoqz5+uCiKX/BdcpLCTQq9/99L/JiZtwIxncG8CUjaUjSkosyb8/292x9zG2o7AhuAs hIWuySp4tOxfMYPnvdVTP0tW6zY+vk2+/gwt4jMHD2f9UHs8XP5vFjuZc2e36KtgBrfD C/gBhL9ke/cte1X7wnTpv6hmfiZzixUa5tPuM40MusUbemW5XfPVm5ael2aICY0wIQ54 AGeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VOP7ZdKY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id u11-20020a17090282cb00b001ca4dd7b834si4896703plz.309.2023.10.24.00.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 00:23:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VOP7ZdKY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id A3382802F6AE; Tue, 24 Oct 2023 00:23:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232805AbjJXHXd (ORCPT + 99 others); Tue, 24 Oct 2023 03:23:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232503AbjJXHXc (ORCPT ); Tue, 24 Oct 2023 03:23:32 -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 EE599110 for ; Tue, 24 Oct 2023 00:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698132167; 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=rv0SpeFLc8EPDyVFSHvu8ODjo19NeLRxyGY2cziN3BQ=; b=VOP7ZdKYocMvqXbyEYvH1Nf9SwC/Vd2Yc/ssNQg3zzlvlWq2AMrXtLlT5W9NrRX7tBBoeD CG5xiqao0XPgey+cunthgbfJrpb8DKV5FiK30myG1I0rWVnYnFRA8YZE48pXEMyBKJpJyM uN8QOPByg5pdOIijLhzzJz+/o2OFCSQ= Received: from mail-vs1-f70.google.com (mail-vs1-f70.google.com [209.85.217.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-kIimnQOwNZmF4tS5ZBbbVw-1; Tue, 24 Oct 2023 03:22:45 -0400 X-MC-Unique: kIimnQOwNZmF4tS5ZBbbVw-1 Received: by mail-vs1-f70.google.com with SMTP id ada2fe7eead31-457dc2691afso1926419137.3 for ; Tue, 24 Oct 2023 00:22:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698132165; x=1698736965; 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=rv0SpeFLc8EPDyVFSHvu8ODjo19NeLRxyGY2cziN3BQ=; b=aZ+cKsXQdJCXUYF7fMpKmqO+nkU43p2NAHJ9k+DQYz4W+9+KWSaKFsey+DYaBErRlO GA1tDpgUjAiNn//ey3eQI+AJJ+lQnK+DzhoE7dTEViRs0azIozgck3pAuRsSv1Mwl6xU qt8ECyRtW1e5Di0X2I/5/GVARCtF1XKbOkLpMfcwmf3BIBLaYnK3VkPX2dGWEWLCz7tm d4p2z7iDEmIk2PXepGayizWw+KccXpt3/5G1w1lWLyOFLxSjszm2TypDoyJ5aNvWQ1EQ BWiw1PdKqlPNVVHLU9nWzaE2/NwtTY7O9guW9P8nYsfpmXJgKPZHIXZ+Lf6AbUJDTHsn 2ZcQ== X-Gm-Message-State: AOJu0Yz0PLeRWPoqx1O3Qq577D6HKBTJBHCEetzY/Cxv55lg4SrMeoJg qUTJ4NlXv/TTvaouGOzVgFEQneHhsR059Xr3CLMeaCIF+624C1Q5DFt1irO7ZVhkyPaDHxMzJRc HuNUSuOqwGHupjH9QmKjAN6N3 X-Received: by 2002:a05:6102:2092:b0:450:8e58:2de4 with SMTP id h18-20020a056102209200b004508e582de4mr9896259vsr.7.1698132165216; Tue, 24 Oct 2023 00:22:45 -0700 (PDT) X-Received: by 2002:a05:6102:2092:b0:450:8e58:2de4 with SMTP id h18-20020a056102209200b004508e582de4mr9896248vsr.7.1698132164898; Tue, 24 Oct 2023 00:22:44 -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 g24-20020a37e218000000b007671b599cf5sm3263591qki.40.2023.10.24.00.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 00:22:44 -0700 (PDT) Date: Tue, 24 Oct 2023 09:22:30 +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 v3] vsock/virtio: initialize the_virtio_vsock before using VQs Message-ID: References: <20231023192207.1804-1-alexandru.matei@uipath.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20231023192207.1804-1-alexandru.matei@uipath.com> 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 24 Oct 2023 00:23:40 -0700 (PDT) On Mon, Oct 23, 2023 at 10:22:07PM +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. > >virtio_transport_send_pkt() can queue packets once the_virtio_vsock is >set, but they won't be processed until vsock->tx_run is set to true. We >queue vsock->send_pkt_work when initialization finishes to send those >packets queued earlier. > >Fixes: 0deab087b16a ("vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock") >Signed-off-by: Alexandru Matei >--- >v3: >- renamed vqs_fill to vqs_start and moved tx_run initialization to it >- queued send_pkt_work at the end of initialization to send packets queued earlier >v2: >- split virtio_vsock_vqs_init in vqs_init and vqs_fill and moved > the_virtio_vsock initialization after vqs_init > > net/vmw_vsock/virtio_transport.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > >diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c >index e95df847176b..c0333f9a8002 100644 >--- a/net/vmw_vsock/virtio_transport.c >+++ b/net/vmw_vsock/virtio_transport.c >@@ -555,6 +555,11 @@ static int virtio_vsock_vqs_init(struct virtio_vsock *vsock) > > virtio_device_ready(vdev); > >+ return 0; >+} >+ >+static void virtio_vsock_vqs_start(struct virtio_vsock *vsock) >+{ > mutex_lock(&vsock->tx_lock); > vsock->tx_run = true; > mutex_unlock(&vsock->tx_lock); >@@ -568,8 +573,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) >@@ -664,6 +667,9 @@ static int virtio_vsock_probe(struct virtio_device *vdev) > goto out; > > rcu_assign_pointer(the_virtio_vsock, vsock); >+ virtio_vsock_vqs_start(vsock); >+ >+ queue_work(virtio_vsock_workqueue, &vsock->send_pkt_work); I would move this call in virtio_vsock_vqs_start() adding also a comment on top, bringing back what you wrote in the commit. Something like this: /* virtio_transport_send_pkt() can queue packets once * the_virtio_vsock is set, but they won't be processed until * vsock->tx_run is set to true. We queue vsock->send_pkt_work * when initialization finishes to send those packets queued * earlier. */ Just as a consideration, we don't need to queue the other workers (rx, event) because as long as we don't fill the queues with empty buffers, the host can't send us any notification. (We could add it in the comment if you want). The rest LGTM! Thanks, Stefano > > mutex_unlock(&the_virtio_vsock_mutex); > >@@ -736,6 +742,9 @@ static int virtio_vsock_restore(struct virtio_device *vdev) > goto out; > > rcu_assign_pointer(the_virtio_vsock, vsock); >+ virtio_vsock_vqs_start(vsock); >+ >+ queue_work(virtio_vsock_workqueue, &vsock->send_pkt_work); > > out: > mutex_unlock(&the_virtio_vsock_mutex); >-- >2.25.1 >