From patchwork Wed Mar 23 17:36:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12789998 X-Patchwork-Delegate: kuba@kernel.org 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 24B00C433F5 for ; Wed, 23 Mar 2022 17:36:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239677AbiCWRiN (ORCPT ); Wed, 23 Mar 2022 13:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343744AbiCWRiI (ORCPT ); Wed, 23 Mar 2022 13:38:08 -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 E30BE7E0A7 for ; Wed, 23 Mar 2022 10:36:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648056998; 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=B/auHUunRKmj44ZRhZ4Uljn8hCNOGxN6qXBgu6Qo8Sg=; b=GmrP1M1VeUHnFBJYOjSDMc1Ilqa/Gcs6pdJWjTR20S+ndY9g2SPIt0YdeKg4uj7xjOGr3C BQkrKpt7sjfvcbl1Y+VRqBwW0s8QeaPP1a44EWWBVMnCbRGatZf8OngkbFM6exvr+p40ka p9LN64jZsV19WxIbgbbnfawsgSo7tf8= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-1-LgWrVa7sNt6ttg4Adefxgg-1; Wed, 23 Mar 2022 13:36:36 -0400 X-MC-Unique: LgWrVa7sNt6ttg4Adefxgg-1 Received: by mail-qt1-f197.google.com with SMTP id f3-20020ac84983000000b002e22396acfbso1731737qtq.18 for ; Wed, 23 Mar 2022 10:36:36 -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=B/auHUunRKmj44ZRhZ4Uljn8hCNOGxN6qXBgu6Qo8Sg=; b=KnTByhG4xG80csdTSf/ApB2w6GMxEt8VjT/W3afBlrtBKGMjoRd4LK3HcUcDi2qN/T MW++hSVHGUyeTTuriGKegJ2RXQCihwKSmMjl/HK2Be+oAHG+vf7fqWJYJwx2kfoJrxgl +wqx2u7bBliHftdBj2RGqB+1BlUP5vOHT8e882lcs4VuGeQlNtL5JvVkco5lVMc1ePjP cDvmI4A2EIalO+ylWO7vNKJRwD94XEo8Rst/xQqDZDvZK/w37+zsnu8hhmaSeZzi1DNd XEt/0acV4EMk7Tj2M02HMldquxdGx5+IT/pHU0VKuqFaKyjHtoCX7+NAEHTt/sN77/qU dibA== X-Gm-Message-State: AOAM533E+Vug0n734Zc0boAMfHYZjofy16HjRu5I8f96/vl8ibU2b/8p ft62b8dQ2t6uZjpN732fR+Csbmh4W/ty5/aIbQJ17ILLG//aRcPKoz0sTUC8/mH6ypY0yWrh1KY YL15SwKSBsFr8VL26yNvd3OVmGNb7DAzIzAhP9qgkha0rZJqvk4rtB/lZoZBrM4HNl9hw X-Received: by 2002:a05:620a:15cf:b0:67d:f378:5cf8 with SMTP id o15-20020a05620a15cf00b0067df3785cf8mr745295qkm.354.1648056995866; Wed, 23 Mar 2022 10:36:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTUiRkn6eha8XU1o1IqDFFHEY3objSBoDDAqSNfC0KM2Zb1piJWjlVMzOTuJp+NKhZ0Bg0SA== X-Received: by 2002:a05:620a:15cf:b0:67d:f378:5cf8 with SMTP id o15-20020a05620a15cf00b0067df3785cf8mr745251qkm.354.1648056995111; Wed, 23 Mar 2022 10:36:35 -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 h14-20020a05622a170e00b002e1a65754d8sm476127qtk.91.2022.03.23.10.36.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 10:36:34 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Jakub Kicinski , "Michael S. Tsirkin" , Asias He , Arseny Krasnov , Stefan Hajnoczi , Paolo Abeni , linux-kernel@vger.kernel.org, Stefano Garzarella , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, "David S. Miller" Subject: [PATCH net v3 1/3] vsock/virtio: initialize vdev->priv before using VQs Date: Wed, 23 Mar 2022 18:36:23 +0100 Message-Id: <20220323173625.91119-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323173625.91119-1-sgarzare@redhat.com> References: <20220323173625.91119-1-sgarzare@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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 callbacks. 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index 5afc194a58bb..3e5513934c9f 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); + vdev->priv = vsock; + mutex_lock(&vsock->tx_lock); vsock->tx_run = true; mutex_unlock(&vsock->tx_lock); @@ -639,7 +641,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 17:36:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12790000 X-Patchwork-Delegate: kuba@kernel.org 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 7DDD2C433F5 for ; Wed, 23 Mar 2022 17:36:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343671AbiCWRiR (ORCPT ); Wed, 23 Mar 2022 13:38:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239664AbiCWRiN (ORCPT ); Wed, 23 Mar 2022 13:38:13 -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 D03B17E0A7 for ; Wed, 23 Mar 2022 10:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648057003; 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=badQ4iNux1pPz/7wSA5tFhWc+QQEkhPUp5sQLckQMkQ=; b=RNMluBOK2QIn8XJRtFsM28fsA+xO0J3SwSJFVRKCoWnDLKH7PJfUXGGmNBOtqylORwyJos XO/OTOT+/mOGJK8fjXuC8/2d8E45OOq62CK6jGQ5wTC2eirlJiOmFs+O0E7iYu+sFCEO+i LCILXKH0MmkTtviW2u7Gz1m4Mald3uE= 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-413-DX-Gm5rzPJ6V3i56sSJAbg-1; Wed, 23 Mar 2022 13:36:40 -0400 X-MC-Unique: DX-Gm5rzPJ6V3i56sSJAbg-1 Received: by mail-qk1-f200.google.com with SMTP id i2-20020a05620a248200b0067b51fa1269so1454748qkn.19 for ; Wed, 23 Mar 2022 10:36:40 -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=badQ4iNux1pPz/7wSA5tFhWc+QQEkhPUp5sQLckQMkQ=; b=7lfMWw7Vho+/NOxo5drcKyHttZStAkQZWq/z0D9+0fIOFmVzfYDxFZUwfMjNUoWsfC BhCVhHNK+PTt1FeUTrU5scsi4YvXVB5SMxifQNAxdiz2/pwr9dgIx7W74t0++KhQc427 m6+jSpxft6skXP3Mp/koz09xVydXNBcV6MmrUTQPbrcni97lRRuU+oqWbLm6S7qyqE74 uJuChntBBwZrfRu0rkq92wFVFptMU9gDKmbZOPiOALvGXkT6LlPGvvlw7AYtBuC4pYJY ewQDmvHshGI8OohMv2svK8ddIOBZVSE8jPkTxLeRg5rv53B+rPW+D8CB/haP9STPmTYr +1cA== X-Gm-Message-State: AOAM53094sU5LMDVKzSyspjSNKxPIrrAH637r/F4N5I4NxCPOPjqwqlx HHCKTGmKlRvkKEcHuTjz5KefKmpYR5kv4+f4XM3aEpS6XXptzg79gP2Ny3doqIbIF8gix7f+zKV nvrfqpRbozPGZmAdNzt0NouBjZbJSnR4DrVlM6oRLpzdPT7yeQRYEcOp8xcCDpLM+qN5z X-Received: by 2002:ae9:ed96:0:b0:67e:c89e:480a with SMTP id c144-20020ae9ed96000000b0067ec89e480amr718890qkg.274.1648056999515; Wed, 23 Mar 2022 10:36:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydhjsyMjk7m4UHfPJYXhDmCRpm61QiwyPkqiHwWTFXbdWyL3aM7kxuaIS4gs2HZKKewMIaMg== X-Received: by 2002:ae9:ed96:0:b0:67e:c89e:480a with SMTP id c144-20020ae9ed96000000b0067ec89e480amr718839qkg.274.1648056998815; Wed, 23 Mar 2022 10:36:38 -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 h14-20020a05622a170e00b002e1a65754d8sm476127qtk.91.2022.03.23.10.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 10:36:38 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Jakub Kicinski , "Michael S. Tsirkin" , Asias He , Arseny Krasnov , Stefan Hajnoczi , Paolo Abeni , linux-kernel@vger.kernel.org, Stefano Garzarella , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, "David S. Miller" Subject: [PATCH net v3 2/3] vsock/virtio: read the negotiated features before using VQs Date: Wed, 23 Mar 2022 18:36:24 +0100 Message-Id: <20220323173625.91119-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323173625.91119-1-sgarzare@redhat.com> References: <20220323173625.91119-1-sgarzare@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Complete the driver configuration, reading the negotiated features, before using the VQs in the virtio_vsock_probe(). Fixes: 53efbba12cc7 ("virtio/vsock: enable SEQPACKET for transport") Suggested-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- 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 3e5513934c9f..3954d3be9083 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; mutex_lock(&vsock->tx_lock); @@ -638,9 +641,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); From patchwork Wed Mar 23 17:36:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12790001 X-Patchwork-Delegate: kuba@kernel.org 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 E59ADC4332F for ; Wed, 23 Mar 2022 17:37:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343699AbiCWRid (ORCPT ); Wed, 23 Mar 2022 13:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343654AbiCWRiQ (ORCPT ); Wed, 23 Mar 2022 13:38:16 -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 3B5A38021C for ; Wed, 23 Mar 2022 10:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648057005; 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=xWGdi1UqdjNcgIoNh0luPYt8s0RItagontqZa8O7xH4=; b=DNWJKdZiCyrL5IIAvSeVGoH5AkolypKMjOjAedZiKbeaQuQXDZF7I6lZN4P5jMiMnup0C0 iYCDw3FrKxsfuCs9oFV8YgEy7G9z+cKJCwnfcsVJh5F4KW/wRL0lcKQNW0s+QzbiA3wKlF ynyht0H8sDHgikusV77QxtwxrHmxOJA= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-140-Kcgvw4BUNq6RqRFo_ao2aw-1; Wed, 23 Mar 2022 13:36:44 -0400 X-MC-Unique: Kcgvw4BUNq6RqRFo_ao2aw-1 Received: by mail-qv1-f72.google.com with SMTP id fw9-20020a056214238900b0043522aa5b81so1749032qvb.21 for ; Wed, 23 Mar 2022 10:36:44 -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=xWGdi1UqdjNcgIoNh0luPYt8s0RItagontqZa8O7xH4=; b=MMHvFbgM/IZWaKKyLUVWmc0UDf3WY418jdg02zVSUuKyvOMra2fDcSbVhpdkJGrik5 uqv1ypKYKe5QT6QyiTeam21QxCapitjMkCzlSv8v/2tT7AgYESKIyyH8e3v9hVv1NXZP 5eizCTn6WBABaw63jtQtmQgdrcxhtwmXI4IIqKoRU9SRBQiK7oGbXRe+ELzoOBTVcLq/ i1UatPBa4TCv8FLiLLlclJ8w0e/9rhgzM5ve4jQRQSEQLDLLGdAARG2nt1epDG/kXCzs KmVDo068SYg0I5Q/y76EYaf2eBsNItd3cl8thVLFPtJvprBxm1KJZZi18Vy0VEODwxEF Cw+w== X-Gm-Message-State: AOAM533bIwkngBLd77A56auro+1S/dAdiF37+AAikwbOdQhcBK2tlDDi W/5yKMpjtjA3OoHBv91X8VmZPhkj/QhJMGL8mRH1fShe7h9dBiDl6B4uu0FDis/xIm+r/IlpdNI /LRYkgs0rj9ot79yumSEPW4yixaR9r8sJX9AOhOo146PapfvlaCIinpZAQzt7FKBBvoaH X-Received: by 2002:ac8:5dcf:0:b0:2e1:baf1:502d with SMTP id e15-20020ac85dcf000000b002e1baf1502dmr806279qtx.635.1648057003109; Wed, 23 Mar 2022 10:36:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTpPllZkLf2utvzNGXglhcnTlOLeIMc4F/54ZX4LmPDik4Rh6CKZ6+/p5IKQ52dEZjvQk8DA== X-Received: by 2002:ac8:5dcf:0:b0:2e1:baf1:502d with SMTP id e15-20020ac85dcf000000b002e1baf1502dmr806235qtx.635.1648057002476; Wed, 23 Mar 2022 10:36:42 -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 h14-20020a05622a170e00b002e1a65754d8sm476127qtk.91.2022.03.23.10.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 10:36:41 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Jakub Kicinski , "Michael S. Tsirkin" , Asias He , Arseny Krasnov , Stefan Hajnoczi , Paolo Abeni , linux-kernel@vger.kernel.org, Stefano Garzarella , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, "David S. Miller" Subject: [PATCH net v3 3/3] vsock/virtio: enable VQs early on probe Date: Wed, 23 Mar 2022 18:36:25 +0100 Message-Id: <20220323173625.91119-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323173625.91119-1-sgarzare@redhat.com> References: <20220323173625.91119-1-sgarzare@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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 3954d3be9083..ba1c8cc0c467 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -627,6 +627,8 @@ static int virtio_vsock_probe(struct virtio_device *vdev) vdev->priv = vsock; + virtio_device_ready(vdev); + mutex_lock(&vsock->tx_lock); vsock->tx_run = true; mutex_unlock(&vsock->tx_lock);