Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1291928rda; Mon, 23 Oct 2023 08:14:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdmQqKrYOimoeKbGkdnsm+rETbiWuIri4NZBGL7Fz2fEht+IRtpkF7qPM4fbrDKKLoPfA/ X-Received: by 2002:a17:90a:19cb:b0:27d:4b71:ed17 with SMTP id 11-20020a17090a19cb00b0027d4b71ed17mr7237545pjj.29.1698074074493; Mon, 23 Oct 2023 08:14:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698074074; cv=none; d=google.com; s=arc-20160816; b=g/3DzPF5NjAGH0wvhueY/tlF6e+9cOjdYqiEytcCbkqqIr75g0Xz8vMFOVS7OkMZgr A/X2/R3t6oYFuQVWXUq6jQOxGTNfh/jzRmi63aV7uKSZw4br4gSmoZbXDI2KGK56YxIB i26lDPGfGVBc8NPK0NHUGJay2mE7kYDY5E7zfO5WmMu/Xo2veD/zhOWaorQNLBeupzp8 nUjNNQgszVt2RxUk1H+5i2H+TiqH7xbBJi65GaqRMONQ4932UQl+lYZrqoRtlQi8g9bs SD5eezJxjOc22j9jcuwsJ4HekrGsTA/5pgK62D6o8YmDWrPZFKCqqSfccGhKDTJ+1xi9 CiGg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=63ahJT05F/ZrGQ5TMqsUAmjRR9M+pviQlbczcdS3kqc=; fh=g5qm3EvcEddfDirpyLMc7MJe9QOvYDcNxwtLglLkguo=; b=bXpBDKkV4WzPsd2s9p+/rDronly+sQAbhgfEamu6ooiDPLj1r8+HKQatHmJOpWO3l0 0y9fnEKALTWb5lVhobE/+WShE0BwNZo17OhN/Ow0fF2rY6KCVyv62yLesrBGp7ByHA24 F/uASqi3FZEg1pdGqJaPvb8N8YNYBYs4aBDM+vKNm3SUNliVZA8Z0NJZS3lEAjm8DTW3 rqITYu4Mgb+RxZiV5T3NtSb4/9Rvg1FFG5oQPk3Tdc/4vP6dH2jgrzG4MLLwy+o49RLN WdJbeYBD9L8MUNMCnlUt/jgK0aSY6hN5SF8sIGdhYYscpZbyZS9SJXMsKKgzVd7VJrqE oWfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DcPK36cK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id u11-20020a17090282cb00b001ca4dd7b834si3599714plz.309.2023.10.23.08.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 08:14:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DcPK36cK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 B069C806D82E; Mon, 23 Oct 2023 08:14:31 -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 S231317AbjJWPON (ORCPT + 99 others); Mon, 23 Oct 2023 11:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbjJWPOM (ORCPT ); Mon, 23 Oct 2023 11:14:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CD68E8 for ; Mon, 23 Oct 2023 08:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698074007; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=63ahJT05F/ZrGQ5TMqsUAmjRR9M+pviQlbczcdS3kqc=; b=DcPK36cKL15HxDTeoSMpGoToa6qonflMQcJhSMwJZYQX6z72VY9NnTGqxPBLKf41BqBH3s gYyZNA3m0CWupzCR2N9Z6aqpTK+7MgDV/yODH4Hq4jqxB3qP2TCghFwGmOJTvZlcTr9TV/ Ritajo0UVPxzmu3M34ljyBpx8vDKZJo= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-29-VALP-acvM36ODa-63Y9QzA-1; Mon, 23 Oct 2023 11:13:25 -0400 X-MC-Unique: VALP-acvM36ODa-63Y9QzA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-66d040c58eeso51342066d6.3 for ; Mon, 23 Oct 2023 08:13:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698074004; x=1698678804; h=in-reply-to:content-transfer-encoding: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=63ahJT05F/ZrGQ5TMqsUAmjRR9M+pviQlbczcdS3kqc=; b=Gy0NyzARUCS3q4ZBe/WC1rgz4lkgu2rBGVTxIruXfqtPK0b0Y8I1GtANEPoaXl7iP9 qr4B691cN3xd/e3wZCDsmRfTsQaQqFN0v9JqocYXjCr8jOAmqnWul66rH9KNsj5PJqT6 WbOD3mFT78seqbK034sdg1a39woZXNuceLZVkT+HlPbTOcqUIrqfGhQ1fMw4sFL9Yem1 LxoHgraw3yEsljkTQqnsPQKS9HN4aDgHjCY8JxXuKLWeUJs81bV4Egw7ODoZfzdRVIpc nyqW3GTe0150g38DvD2RaEAV5QcQ6ifOD7dt0mfymFaOPSZ3ZU16GqzTDyldG7SlqAyL 7RSw== X-Gm-Message-State: AOJu0YxKWzKS4dwtSxG2Qh87Yc5QO8oOhIHlkbNBf+STw+Hq4wkapS49 +U/CoZgl15/HkKSFtQHn1dXMDpNO69NPK9O40azTrmtvfX7SQV9MQKNH/PQ3sm+SFZgRHkxqol6 b8pOWQobR6cYpvvAqAK0mJa7z X-Received: by 2002:a0c:df92:0:b0:66d:38e3:4ffd with SMTP id w18-20020a0cdf92000000b0066d38e34ffdmr9704298qvl.5.1698074004155; Mon, 23 Oct 2023 08:13:24 -0700 (PDT) X-Received: by 2002:a0c:df92:0:b0:66d:38e3:4ffd with SMTP id w18-20020a0cdf92000000b0066d38e34ffdmr9704288qvl.5.1698074003872; Mon, 23 Oct 2023 08:13:23 -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 ml14-20020a056214584e00b0066d04196c3dsm2939797qvb.49.2023.10.23.08.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 08:13:23 -0700 (PDT) Date: Mon, 23 Oct 2023 17:13:07 +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 v2] vsock/virtio: initialize the_virtio_vsock before using VQs Message-ID: References: <20231023140833.11206-1-alexandru.matei@uipath.com> <2tc56vwgs5xwqzfqbv5vud346uzagwtygdhkngdt3wjqaslbmh@zauky5czyfkg> <0624137c-85cf-4086-8256-af2b8405f434@uipath.com> <632465d0-e04c-4e10-abb9-a740d6e3dc30@uipath.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <632465d0-e04c-4e10-abb9-a740d6e3dc30@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 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]); Mon, 23 Oct 2023 08:14:31 -0700 (PDT) On Mon, Oct 23, 2023 at 05:59:45PM +0300, Alexandru Matei wrote: >On 10/23/2023 5:52 PM, Alexandru Matei wrote: >> On 10/23/2023 5:29 PM, Stefano Garzarella wrote: >>> On Mon, Oct 23, 2023 at 05:08:33PM +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. >>>> >>>> Fixes: 0deab087b16a ("vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock") >>>> Signed-off-by: Alexandru Matei >>>> --- >>>> 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 | 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 e95df847176b..92738d1697c1 100644 >>>> --- a/net/vmw_vsock/virtio_transport.c >>>> +++ b/net/vmw_vsock/virtio_transport.c >>>> @@ -559,6 +559,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) >>> >>> What about renaming this function in virtio_vsock_vqs_start() and move also the setting of `tx_run` here? >> >> It works but in this case we also need to move rcu_assign_pointer in virtio_vsock_vqs_start(), >> the assignment needs to be right after setting tx_run to true and before filling the VQs. Why? If `rx_run` is false, we shouldn't need to send replies to the host IIUC. If we need this instead, please add a comment in the code, but also in the commit, because it's not clear why. >> > >And if we move rcu_assign_pointer then there is no need to split the function in two, >We can move rcu_assign_pointer() directly inside virtio_vsock_vqs_init() after setting tx_run. Yep, this could be another option, but we need to change the name of that function in this case. Stefano > >>> >>> Thanks, >>> Stefano >>> >>>> +{ >>>> ????mutex_lock(&vsock->rx_lock); >>>> ????virtio_vsock_rx_fill(vsock); >>>> ????vsock->rx_run = true; >>>> @@ -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,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); >>>> >>>> @@ -736,6 +740,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); >>>> --? >>>> 2.34.1 >>>> >>> >