From patchwork Wed Mar 23 08:49:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12789553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA0F2C433F5 for ; Wed, 23 Mar 2022 08:50:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242927AbiCWIvj (ORCPT ); Wed, 23 Mar 2022 04:51:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242907AbiCWIvg (ORCPT ); Wed, 23 Mar 2022 04:51:36 -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 ESMTP id DED4073072 for ; Wed, 23 Mar 2022 01:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648025405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VkoZGCDazaob935cf0K6/xqwp1grV8y7vA1EUagsdw8=; b=E2BLsoaRp7bqL5g54mC9rJgYyG8Oreov6JgY9i+5FDTRrV+kHKiIcDKJ8ZJyPagL61l0D1 1xArt7LRazHcNe9GEXeMdblW98ye7B4P08ek/rNVNy0WmeShhXdbC573wSRc6MGJrPvdCE +9+j9S6w/mWpmmOn7rFPIum5tl+4ZYE= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-581-Ar_OCb_XM3exiIlU4yy1JA-1; Wed, 23 Mar 2022 04:50:05 -0400 X-MC-Unique: Ar_OCb_XM3exiIlU4yy1JA-1 Received: by mail-qk1-f200.google.com with SMTP id q5-20020a05620a0d8500b004738c1b48beso561330qkl.7 for ; Wed, 23 Mar 2022 01:50:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VkoZGCDazaob935cf0K6/xqwp1grV8y7vA1EUagsdw8=; b=52tIPf2fTHpWU5y59CQewrBvXaiKDF0S5hGJjx9JTSsTR4C84B48b5NZ5BN/y0g4jS k4nuxmif3Nr4hdie2z6xkVZUwt9pJGIGFpQwBosCcx89Ix0wBY+gZe1KW9iWJOdnKsZG KNyyv7i4b+OU7eSAySE/2t3/TXJ055qsPhqgMeXN6x15rlnhTgzmUioYvjcb7SOYaWN3 0gQWwC28S/4zRxrYIFI0WTVqIoZMZfavE7KIAmkAA/1mT4vBszP0r7aNOmR2VhizWDfr /RNUr7SlU5uCorkqpeAGBt9Dr2HWLP13LugeEKcLGHMmgcMRr92yL4r2qHlW/6F4o4ZH JSvQ== X-Gm-Message-State: AOAM532zCv9xXdJybQq/AZKMDhH5u77hM7qBJg2LXm7jGB4kUQdqdOVW HMU4ZlHGPL/5mmX3uBpCQ+0D0o+AhWdmU//Z7+jr/nxtqAA/acFs8HME9DnzHIHp7/EyXQ/OPz5 Jq0yF2HpCMA/+ X-Received: by 2002:a05:620a:1a92:b0:67d:b2c2:8311 with SMTP id bl18-20020a05620a1a9200b0067db2c28311mr17908326qkb.594.1648025404183; Wed, 23 Mar 2022 01:50:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylURIbsHFC5CVM0PxCcg9Ie4RCz+seln0B3QhsU0NKbzEwgOSb1+E5im+z84ivzzgUFUDiHg== X-Received: by 2002:a05:620a:1a92:b0:67d:b2c2:8311 with SMTP id bl18-20020a05620a1a9200b0067db2c28311mr17908319qkb.594.1648025404003; Wed, 23 Mar 2022 01:50:04 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-114.business.telecomitalia.it. [87.12.25.114]) by smtp.gmail.com with ESMTPSA id j188-20020a3755c5000000b0067d1c76a09fsm10640609qkb.74.2022.03.23.01.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 01:50:03 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Stefan Hajnoczi , Paolo Abeni , Arseny Krasnov , "David S. Miller" , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Stefano Garzarella , "Michael S. Tsirkin" , Asias He , Jakub Kicinski Subject: [PATCH net v2 1/3] vsock/virtio: enable VQs early on probe Date: Wed, 23 Mar 2022 09:49:52 +0100 Message-Id: <20220323084954.11769-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323084954.11769-1-sgarzare@redhat.com> References: <20220323084954.11769-1-sgarzare@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org virtio spec requires drivers to set DRIVER_OK before using VQs. This is set automatically after probe returns, but virtio-vsock driver uses VQs in the probe function to fill rx and event VQs with new buffers. Let's fix this, calling virtio_device_ready() before using VQs in the probe function. Fixes: 0ea9e1d3a9e3 ("VSOCK: Introduce virtio_transport.ko") Signed-off-by: Stefano Garzarella --- net/vmw_vsock/virtio_transport.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index 5afc194a58bb..b1962f8cd502 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -622,6 +622,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev) INIT_WORK(&vsock->event_work, virtio_transport_event_work); INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work); + virtio_device_ready(vdev); + mutex_lock(&vsock->tx_lock); vsock->tx_run = true; mutex_unlock(&vsock->tx_lock); From patchwork Wed Mar 23 08:49:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12789554 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B21FC433FE for ; Wed, 23 Mar 2022 08:50:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242957AbiCWIvs (ORCPT ); Wed, 23 Mar 2022 04:51:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242925AbiCWIvj (ORCPT ); Wed, 23 Mar 2022 04:51:39 -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 ESMTP id 34B49710EE for ; Wed, 23 Mar 2022 01:50:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648025409; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2tskzl0i4fBaGQ2SA9UFWp+uERMa68xRFlfoMwtqOtQ=; b=Zbp8kpDdjaNxqZi1Ay1Lkf9KDWQ2lHvcHPcpS6GqhaIlZEwXtjSZ+4NU3fhEq4MGkRi8m9 raZeFLG4GnImxL1ncqr3LgMkHSL1ilLtdx1laXTVql2mpLrZcgCIIYnGq1hhy8NSmwMTrT SCNWj8pMFLt0PdaSsh9tv8mKCd16oTE= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-562-MkfE6rOANYW04Pw-BXuWGA-1; Wed, 23 Mar 2022 04:50:08 -0400 X-MC-Unique: MkfE6rOANYW04Pw-BXuWGA-1 Received: by mail-qk1-f200.google.com with SMTP id b133-20020a37678b000000b0067d24942b91so553662qkc.12 for ; Wed, 23 Mar 2022 01:50:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2tskzl0i4fBaGQ2SA9UFWp+uERMa68xRFlfoMwtqOtQ=; b=l8xdba2HWXeehXDsSwB1DZBbNadrtmXurpHShe3CUU5Fgab/AdGsmbuO3aeuEni4nR NY7J7CTuLE3Qn6o3LjTd2Y0fAmF4SGMg6DhYaIgyUFrU9yMUvUli4GND9I8HCk8hcn/a 9+b12JfIjjlEflG3Zj5jFobtpYLfDVocTIEa51AhGiMfz8YGPdwyY4Zm9RrmKw6rxXLw hxIei4YAmdqkUiTiOIYeyCcU2oS8njKLi/uRjfAX5b9nI8zO2lSdZ4hIDDLMxOAzj143 phU5fWee7NHOfJluk3mCGzVmN5IHM3Wy/2B7mRHZ7wK5MvB7GWLOKa9WNS1/wrTRkmqa +C0g== X-Gm-Message-State: AOAM530pECgSwsSuCG9+/M9EoKz2rhNlb1MHqTZ7Qf0StEuiv1AyRu3K B0bEwL9qJiDuUVweH8xa5oWLCcbqbMxPkwhr4Giea/KhXjW8FRYfzhyQKrdSTIADoZdPICmldAQ DT935b3YLWgoP X-Received: by 2002:a05:620a:24cd:b0:67d:5f50:ef41 with SMTP id m13-20020a05620a24cd00b0067d5f50ef41mr18012806qkn.568.1648025407750; Wed, 23 Mar 2022 01:50:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwKKClidIuo6B0OT0d5+9jRGkHIXrwcI73KaPwBD6CWDKidHKCMTHM2A18yH6e8LMQdxDzAg== X-Received: by 2002:a05:620a:24cd:b0:67d:5f50:ef41 with SMTP id m13-20020a05620a24cd00b0067d5f50ef41mr18012795qkn.568.1648025407541; Wed, 23 Mar 2022 01:50:07 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-114.business.telecomitalia.it. [87.12.25.114]) by smtp.gmail.com with ESMTPSA id j188-20020a3755c5000000b0067d1c76a09fsm10640609qkb.74.2022.03.23.01.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 01:50:06 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Stefan Hajnoczi , Paolo Abeni , Arseny Krasnov , "David S. Miller" , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Stefano Garzarella , "Michael S. Tsirkin" , Asias He , Jakub Kicinski Subject: [PATCH net v2 2/3] vsock/virtio: initialize vdev->priv before using VQs Date: Wed, 23 Mar 2022 09:49:53 +0100 Message-Id: <20220323084954.11769-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323084954.11769-1-sgarzare@redhat.com> References: <20220323084954.11769-1-sgarzare@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When we fill VQs with empty buffers and kick the host, it may send an interrupt. `vdev->priv` must be initialized before this since it is used in the virtqueue callback. Fixes: 0deab087b16a ("vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock") Suggested-by: Michael S. Tsirkin Signed-off-by: Stefano Garzarella --- net/vmw_vsock/virtio_transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index b1962f8cd502..fff67ad39087 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -622,6 +622,7 @@ static int virtio_vsock_probe(struct virtio_device *vdev) INIT_WORK(&vsock->event_work, virtio_transport_event_work); INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work); + vdev->priv = vsock; virtio_device_ready(vdev); mutex_lock(&vsock->tx_lock); @@ -641,7 +642,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev) if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET)) vsock->seqpacket_allow = true; - vdev->priv = vsock; rcu_assign_pointer(the_virtio_vsock, vsock); mutex_unlock(&the_virtio_vsock_mutex); From patchwork Wed Mar 23 08:49:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12789555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3A3DC43217 for ; Wed, 23 Mar 2022 08:50:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242982AbiCWIwA (ORCPT ); Wed, 23 Mar 2022 04:52:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242950AbiCWIvr (ORCPT ); Wed, 23 Mar 2022 04:51:47 -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 ESMTP id 5519D75601 for ; Wed, 23 Mar 2022 01:50:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648025413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OgA1lCzF0b4XjouCMdWAekLZD2KK/T/B0hpIucmcAvY=; b=G5g9aOuf91AvVT5T+uTTLilDIoUbYLjkjJyV0aEyoY86InI8mu2COGfW6Lts7fodtXw1fw fAzaEEytZS1m/XFjHZgYYD+xfXn541bVsgzus1C0gz2NZWSf+mgCGla5SgWLOcbNdzKIXa nbHFNrkOclqwR9holmYgd2xNj/an2N4= 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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-493-Gkto_CVKMBO9GQYbFg9sTQ-1; Wed, 23 Mar 2022 04:50:12 -0400 X-MC-Unique: Gkto_CVKMBO9GQYbFg9sTQ-1 Received: by mail-qv1-f70.google.com with SMTP id fw9-20020a056214238900b0043522aa5b81so732565qvb.21 for ; Wed, 23 Mar 2022 01:50:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OgA1lCzF0b4XjouCMdWAekLZD2KK/T/B0hpIucmcAvY=; b=Vps5W+mhuVW1JD1WcLREaO+xnVJXNvT0gNPRrLKrifxBd75nBtAsoIJJbMIw8XG24i oc5+c0x22wRjJEhAtPwpvW+76XZjnPbp/GOCfkl3Xtr65wc63MtrkLtF/f7HmSXDJxlh 7QyLokKGgTZcOqNsUpRou4+nOi1UN9M6pfp68080G5GqCvZALINXc1yfLt2TOiGotW0Y KviWyZ+TCNiG7LxjOyu7Voi7gSlVACSgZ23RizlAnK4nmhSmhf4s63DMXfqLOEjqjHia bDis0lfh0RKMxj69HHlIWtDxCFESltoCltD35TROVPfaIfN6iDj3cu5aE7rxzMzC908E /dzg== X-Gm-Message-State: AOAM532ujzGP0jfbnRib1Hcxj6/dMNhXUq3u+MZRI/+q/h9eyOR2k6u2 7ZyVIGEtMzU2J0mn64StCFXi5eTOwJ8FKV/GObaJBkvwitEnqSxMSiuOm784piVmGz0Ma8j9VNK cZzBfjIqUIXSV X-Received: by 2002:a05:620a:370a:b0:67d:5f35:900f with SMTP id de10-20020a05620a370a00b0067d5f35900fmr17592014qkb.767.1648025411592; Wed, 23 Mar 2022 01:50:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzyPK4ZKA2MkSsVUsQecAaz7gloEHvd5w3N1Q/3d1hjdf5Wr4EaGY3ikaTT6b++I1clHGznQ== X-Received: by 2002:a05:620a:370a:b0:67d:5f35:900f with SMTP id de10-20020a05620a370a00b0067d5f35900fmr17591997qkb.767.1648025411363; Wed, 23 Mar 2022 01:50:11 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-114.business.telecomitalia.it. [87.12.25.114]) by smtp.gmail.com with ESMTPSA id j188-20020a3755c5000000b0067d1c76a09fsm10640609qkb.74.2022.03.23.01.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 01:50:10 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Stefan Hajnoczi , Paolo Abeni , Arseny Krasnov , "David S. Miller" , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Stefano Garzarella , "Michael S. Tsirkin" , Asias He , Jakub Kicinski Subject: [PATCH net v2 3/3] vsock/virtio: read the negotiated features before using VQs Date: Wed, 23 Mar 2022 09:49:54 +0100 Message-Id: <20220323084954.11769-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323084954.11769-1-sgarzare@redhat.com> References: <20220323084954.11769-1-sgarzare@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Complete the driver configuration, reading the negotiated features, before using the VQs and tell the device that the driver is ready in the virtio_vsock_probe(). Fixes: 53efbba12cc7 ("virtio/vsock: enable SEQPACKET for transport") Suggested-by: Michael S. Tsirkin Signed-off-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi --- net/vmw_vsock/virtio_transport.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index fff67ad39087..1244e7cf585b 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -622,6 +622,9 @@ static int virtio_vsock_probe(struct virtio_device *vdev) INIT_WORK(&vsock->event_work, virtio_transport_event_work); INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work); + if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET)) + vsock->seqpacket_allow = true; + vdev->priv = vsock; virtio_device_ready(vdev); @@ -639,9 +642,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev) vsock->event_run = true; mutex_unlock(&vsock->event_lock); - if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET)) - vsock->seqpacket_allow = true; - rcu_assign_pointer(the_virtio_vsock, vsock); mutex_unlock(&the_virtio_vsock_mutex);