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: 12790011 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 502DFC433EF for ; Wed, 23 Mar 2022 17:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237520AbiCWRiO (ORCPT ); Wed, 23 Mar 2022 13:38:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343740AbiCWRiI (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 AC0A67EB03 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=1648056997; 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=QKHyfpuRSUuiZJtghqAfKumY87h4n23tRuTtMD6kWlm1KMgNuIscxae+pxJ05Vv/aAs6Mu MSMUOzUBCf0YJuorfzB6UMoINsDOCPxpG36Rddji/EyGNMoakqzvKt/7ZqVMlqSchW3Se4 uN9kzc9f7i+MwHc+d8fnZbFE0YEt+vA= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-581-ZaefITVGMMK6zv1jGaihJg-1; Wed, 23 Mar 2022 13:36:36 -0400 X-MC-Unique: ZaefITVGMMK6zv1jGaihJg-1 Received: by mail-qt1-f198.google.com with SMTP id k11-20020ac8604b000000b002e1a4109edeso1737447qtm.15 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=bCn4SB1hcQhpRNbqV/hrQ3PJ8OqnosFxw6PTZ7egMQ+hh5jCmKWymqBcrLRdIOL5cf MUqdh6wNkxewo2FjfaqfGuf/cCWCac9NSB3mQEzZt6YLvVYUbJ0JJeirKD5LpswUAbMg OvgfEzjlxWvq1QnoqScvRkDLh3SCX4lu00PnIdodwkzM+1JDlObZm84Pr21o2UkX6zPs 2JriR0Bwv5l+rFYmBZ2UNoNToYEANlXOd4JL1Pdkd3cSPKG9z8x4Uw2F19FnMF+8xJzT lxkDIgmbw7y54WQ2hNdezBB3mj2xnjQ4A+1F7Ca/1B2jhsqDaSboroMyg1utdeUyKS9J JnaA== X-Gm-Message-State: AOAM531yYwZ1Z9pairHKXkTNgJ/sHf3q6M7AViiQfvb+WO63I23RzF/D nMAPyTNyWYE8Yin84sHQr7I3X+CWLTqzRX7TqnnFxtfr7mkdZv40Vq6lljy+H0NhV1Ka5SoOKwX 2F1liNezpj0sw X-Received: by 2002:a05:620a:15cf:b0:67d:f378:5cf8 with SMTP id o15-20020a05620a15cf00b0067df3785cf8mr745277qkm.354.1648056995704; 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: 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 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: 12790010 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 D2DF0C433EF for ; Wed, 23 Mar 2022 17:36:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239655AbiCWRiN (ORCPT ); Wed, 23 Mar 2022 13:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343772AbiCWRiM (ORCPT ); Wed, 23 Mar 2022 13:38: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 ESMTP id 1FA9A7EA00 for ; Wed, 23 Mar 2022 10:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648057001; 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=YgCi3ETzvVxKO7J3Ij6LTWXsFJo8aOInV3YUPVz8C/1+JEhDwHKpHHbLFUbYIhul0eK1eP h3398XS2R5DFnn/JebuJ/IVtKubEhT6dwQ3hl5ZonhFxvv2DQ6F5xRv+v+BDX1P+MErPKS JzYmJuMGaR+R38XbZMG1wDgHylexshU= 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-363-CxAlzDXoPjquNMnOn_kM4Q-1; Wed, 23 Mar 2022 13:36:40 -0400 X-MC-Unique: CxAlzDXoPjquNMnOn_kM4Q-1 Received: by mail-qv1-f70.google.com with SMTP id g2-20020a0562141cc200b004123b0abe18so1793019qvd.2 for ; Wed, 23 Mar 2022 10:36:39 -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=wdQ3AioBVRnK2B9rDDx9+H4tkzv69S35GbCAhfaP02fWTjFAktQgyBKk79mqGVCcqT JCrICpdjp5ijrGD3QTVz7CjJGKc5ENRRdcKPgkhYriGLqYWS0vcNbAdhsQghGRaf98do wKmPn9o3hvc78h1ktPz3B4XniulNr1ekiHx14LJBLAhQCDFgpsOe0dp9lNFgNgQb+wMI hL5e0lASwh3ncCAxtDZFenswztkxDa+8AKVsa44C4B7wlwADPZuec0WVF2Mr8xJqwtzz c1EbYpH5VW3AFocvb990piDnIWS68eYdegQc6g6fcbODI08LH1psZI0An+NjNGGIlO1J WZ8A== X-Gm-Message-State: AOAM533i0W1gCpMf2Rm7N77HkqAXdoTcRRKCIovkEierA2JV+UxuU+ca Z6bAJOZEN91B+jjRY49txk8eS2dHJkWra51RJcLSVq5p4ebOB4wGITzSON2iJkvXBQq8eUChzW2 ZUJnBnaOSHYXm X-Received: by 2002:ae9:ed96:0:b0:67e:c89e:480a with SMTP id c144-20020ae9ed96000000b0067ec89e480amr718874qkg.274.1648056999445; 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: kvm@vger.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: 12790013 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 B9D9FC433F5 for ; Wed, 23 Mar 2022 17:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343697AbiCWRid (ORCPT ); Wed, 23 Mar 2022 13:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343652AbiCWRiP (ORCPT ); Wed, 23 Mar 2022 13:38:15 -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 CA95C7EB0F for ; Wed, 23 Mar 2022 10:36:45 -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-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-336-G_wt_iBJN0u2gBC_mxGtxg-1; Wed, 23 Mar 2022 13:36:43 -0400 X-MC-Unique: G_wt_iBJN0u2gBC_mxGtxg-1 Received: by mail-qv1-f71.google.com with SMTP id o1-20020a0c9001000000b00440e415a3a2so1768567qvo.13 for ; Wed, 23 Mar 2022 10:36:43 -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=PTEauOKMBtg1iINzQeCU5DaIZE9xgPTc85AcXiGXoJLo3RcquUxejFIPskW+mpCi69 v1xnrwERTnOQloa6DyKCrIZUbVTxL1izC5kFuFiU/KlxodLUQ5YXucsaM+6wORIDPl6N 8qLa3eKu3PfQCQ+sq+Fy8bSpXpC0uNdt0q3iWW9S4ricoCCp+PObg5xQPc9Ej69NVuwM y7Ixd5bzT3dU6elnfK4YjLTW3M6GirJ8oVo3hNgaQG2Lc1Cqb+C0DTD7O/A2NxDnLU93 I/LSR52bmKR5t3J7oxHQBm8irU3pYeQeTOOBm+/AysW7APIcR9BU9+yNxVC90DZVGhWT zJXw== X-Gm-Message-State: AOAM5313+LQ5vYfORbwuqEUJIGHwsdUZI1OMe8C4P9/F6FnDnShJuSyL i2ZmqVrcPaw+qQALyFEz294tTUv0M2nXhpgn/Ho9Y13VA0ijrHmtngVo58OKbGIt6PKW5l1glPp YurvVl/ER/WaK X-Received: by 2002:ac8:5dcf:0:b0:2e1:baf1:502d with SMTP id e15-20020ac85dcf000000b002e1baf1502dmr806273qtx.635.1648057003041; 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: 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 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);