From nobody Mon Sep 16 19:17:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1721752857; cv=none; d=zohomail.com; s=zohoarc; b=OV6p78aGMKGvRp6mdq7smIgeNTUdF7zUkmG7ud7S8dHjBMj4QEJrv0jBOfg5jtDe1uRY1GcNiNw0HTHNNh++pDtt7QKhvb5b05YcSzzHukcf6wwnTKvbNX1Ko7fcw29tMKQ3CBivForyC1Wu0f68Xr38xBqaSgE70gvp63rnagI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721752857; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GFVhOh7SmpXOJwo7bOzKTSdDE/PawzWv7qmTvXMjT7Y=; b=geeXb5HNURCtCnUV3+sJ0ahBt9zqneiWEMySDcTD61RctIWnjyoSg8yTPRk/+T5XysXMDUKwuudObXmYWkBgaiqf51GWNJrx60jONr3PXqAXnSFh5XEfDCzSge8pib7AlxjqI1THMNylRac0igiVqMacY38Wt5mXft0rKPNIdCY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1721752857867595.9178267878139; Tue, 23 Jul 2024 09:40:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWIYe-0006nu-Ql; Tue, 23 Jul 2024 12:40:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWIYa-0006mr-Sm for qemu-devel@nongnu.org; Tue, 23 Jul 2024 12:40:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWIYX-0001YK-2m for qemu-devel@nongnu.org; Tue, 23 Jul 2024 12:40:08 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-N2oKFPUoMJuIq-i84U-H_g-1; Tue, 23 Jul 2024 12:39:58 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-42794cb8251so45690555e9.2 for ; Tue, 23 Jul 2024 09:39:58 -0700 (PDT) Received: from localhost (p200300cfd74b1cd04af1f18b763c5dac.dip0.t-ipconnect.de. [2003:cf:d74b:1cd0:4af1:f18b:763c:5dac]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3687868b24csm11973636f8f.25.2024.07.23.09.39.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 09:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721752800; 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=GFVhOh7SmpXOJwo7bOzKTSdDE/PawzWv7qmTvXMjT7Y=; b=NYHd9rhX6ZqjlGL0UqR2LKRkEJZsh7lsfuZYfaz2u8euZP2XiLdJgv6cozJxA1D5FbAs1S EHOm951tLeqtXzmhNlpvhE4kl7pJyMlE7AHNj/phzTqqOBVZ88VKN6rQZdOE2VpCGwchUW 7MNd9pDw995gkmCdZ+7joC3gNZMd0lc= X-MC-Unique: N2oKFPUoMJuIq-i84U-H_g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721752795; x=1722357595; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GFVhOh7SmpXOJwo7bOzKTSdDE/PawzWv7qmTvXMjT7Y=; b=Ur5DxaUWRby3wRNXP/N3siZG665MVcuXTkdDpWRir1iTyQJOMypx3x8/MfijakMeaG ko8g4rlTMrZB3XFCdwRAkYab8T3JewB4uVXzNk6scw0aw+KprvsJg8408qbis6oHGiOt eJsMfFx+ggRlgm7++W155gDpbSpOl9W0sCC9cvqU/slkEIodPc/v+N6oQVNNzGMpaeus 3rdsk8ZL4CPrwp0ldedUNeGN9q6mBnc9qc8TrWJjbGJtk+IL57NWmnPutiSZxjW7lrXK A8EYm//jlmGR033yG5Veacr67WioX93KQX3ZVDbS+fwYx5iGdcN3FzfyqkkFeF2vmnj3 mP2Q== X-Gm-Message-State: AOJu0YyJDI2PgU1D/aWQbs4X/vlVt+3N4ju/DqA6trCA19YES/6ZFrcn lDbp898og7RxEKoMWepQuaDPFFDT+003SF3MdlW22/b8PJaqY1i9Vb9lhslNQDlYeON56+Ukw1L yDFoUZiLSDm9HozHrf2gagnzV2Zr7ZM+w18lDHTqx8dq5en4aau0dKQKzQgkm8cCPycLVbRIz7b alnBS9nQ8pYceNg5L3qNMBChg1jG/iDPpR+w== X-Received: by 2002:a05:600c:699b:b0:426:549b:dd7a with SMTP id 5b1f17b1804b1-427daa67f25mr63873865e9.36.1721752795430; Tue, 23 Jul 2024 09:39:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJGMdeh6v3/qV/USaEeLJGGeIGF48IjFCcSgX5h8oN9unFj7+vqB7W4nGQQiKbe106MZ606A== X-Received: by 2002:a05:600c:699b:b0:426:549b:dd7a with SMTP id 5b1f17b1804b1-427daa67f25mr63873675e9.36.1721752794857; Tue, 23 Jul 2024 09:39:54 -0700 (PDT) From: Hanna Czenczek To: qemu-devel@nongnu.org Cc: Hanna Czenczek , Stefan Hajnoczi , "Michael S . Tsirkin" Subject: [PATCH v2 1/2] virtio: Allow .get_vhost() without vhost_started Date: Tue, 23 Jul 2024 18:39:39 +0200 Message-ID: <20240723163941.48775-2-hreitz@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240723163941.48775-1-hreitz@redhat.com> References: <20240723163941.48775-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.133, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1721752859005116600 Content-Type: text/plain; charset="utf-8" Historically, .get_vhost() was probably only called when vdev->vhost_started is true. However, we now decidedly want to call it also when vhost_started is false, specifically so we can issue a reset to the vhost back-end while device operation is stopped. Some .get_vhost() implementations dereference some pointers (or return offsets from them) that are probably guaranteed to be non-NULL when vhost_started is true, but not necessarily otherwise. This patch makes all such implementations check all such pointers, returning NULL if any is NULL. Signed-off-by: Hanna Czenczek Reviewed-by: Stefan Hajnoczi --- include/hw/virtio/virtio.h | 1 + hw/display/vhost-user-gpu.c | 2 +- hw/net/virtio-net.c | 19 +++++++++++++++++-- hw/virtio/virtio-crypto.c | 18 +++++++++++++++--- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 7512afbc84..ff29088232 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -221,6 +221,7 @@ struct VirtioDeviceClass { int (*post_load)(VirtIODevice *vdev); const VMStateDescription *vmsd; bool (*primary_unplug_pending)(void *opaque); + /* May be called even when vdev->vhost_started is false */ struct vhost_dev *(*get_vhost)(VirtIODevice *vdev); void (*toggle_device_iotlb)(VirtIODevice *vdev); }; diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 63c64ddde6..5056ffd618 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -642,7 +642,7 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error = **errp) static struct vhost_dev *vhost_user_gpu_get_vhost(VirtIODevice *vdev) { VhostUserGPU *g =3D VHOST_USER_GPU(vdev); - return &g->vhost->dev; + return g->vhost ? &g->vhost->dev : NULL; } =20 static Property vhost_user_gpu_properties[] =3D { diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 8f30972708..874ed9c032 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3890,8 +3890,23 @@ static bool dev_unplug_pending(void *opaque) static struct vhost_dev *virtio_net_get_vhost(VirtIODevice *vdev) { VirtIONet *n =3D VIRTIO_NET(vdev); - NetClientState *nc =3D qemu_get_queue(n->nic); - struct vhost_net *net =3D get_vhost_net(nc->peer); + NetClientState *nc; + struct vhost_net *net; + + if (!n->nic) { + return NULL; + } + + nc =3D qemu_get_queue(n->nic); + if (!nc) { + return NULL; + } + + net =3D get_vhost_net(nc->peer); + if (!net) { + return NULL; + } + return &net->dev; } =20 diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index bbe8aa4b99..3296b7f219 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -1247,9 +1247,21 @@ static bool virtio_crypto_guest_notifier_pending(Vir= tIODevice *vdev, int idx) static struct vhost_dev *virtio_crypto_get_vhost(VirtIODevice *vdev) { VirtIOCrypto *vcrypto =3D VIRTIO_CRYPTO(vdev); - CryptoDevBackend *b =3D vcrypto->cryptodev; - CryptoDevBackendClient *cc =3D b->conf.peers.ccs[0]; - CryptoDevBackendVhost *vhost_crypto =3D cryptodev_get_vhost(cc, b, 0); + CryptoDevBackend *b; + CryptoDevBackendClient *cc; + CryptoDevBackendVhost *vhost_crypto; + + b =3D vcrypto->cryptodev; + if (!b) { + return NULL; + } + + cc =3D b->conf.peers.ccs[0]; + vhost_crypto =3D cryptodev_get_vhost(cc, b, 0); + if (!vhost_crypto) { + return NULL; + } + return &vhost_crypto->dev; } =20 --=20 2.45.2 From nobody Mon Sep 16 19:17:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1721752863; cv=none; d=zohomail.com; s=zohoarc; b=g3wO2IHCb06/faBhQdpBbTc+N+21PQN/GwJtZOn6lfKa2zvVrUPkUWNqtnDqD2Snr/JurkvPhcGAFBp56D3lCxskgsRtln+/xfnkdoH+JrlXB4O7QpfeGAPDnchkaV2u4bFSbNO2Rs1pfCtwDni17iDFBmbYls9InSM+ojNqzuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721752863; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zZkNsRazCJZZPQZc0vMKv6cPyzjVC9m4rB51zqNztNA=; b=X5WQUJ+RVPEpl7lifNsZGmMGKFwzy/H/hHXlV6rYU77T3/PDV63THFdt70byOLjJAMd1Puf8ULWloZws9JaQQCb5Y+On4/1i0z68v2UFXB9W9MbpFUZPEA30SXQHD+rPYI+vfE4Uq6hDEeYM9wlEB0BqrNip0f/dHiDRrygDH2I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1721752863723471.3263670207092; Tue, 23 Jul 2024 09:41:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWIYg-0006uL-P4; Tue, 23 Jul 2024 12:40:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWIYa-0006mq-SI for qemu-devel@nongnu.org; Tue, 23 Jul 2024 12:40:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWIYY-0001ZG-Ir for qemu-devel@nongnu.org; Tue, 23 Jul 2024 12:40:08 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-267-UhwoFS1ZPeub8Z_HjQPsXQ-1; Tue, 23 Jul 2024 12:40:01 -0400 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-36873a449dfso9697f8f.0 for ; Tue, 23 Jul 2024 09:40:01 -0700 (PDT) Received: from localhost (p200300cfd74b1cd04af1f18b763c5dac.dip0.t-ipconnect.de. [2003:cf:d74b:1cd0:4af1:f18b:763c:5dac]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a9466bsm208158025e9.41.2024.07.23.09.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 09:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721752803; 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=zZkNsRazCJZZPQZc0vMKv6cPyzjVC9m4rB51zqNztNA=; b=O6Mmeg6+tSluN4UXbk0HcgDYQgSvYbgRcxkHIJYTFUUC0FP1VXYQYrZJH3UsQMi7AhGpPG epJEJuUixnSUlVcxcJK67cxWylf6a61hM7rYOvJESp63Mkt93HBCoeeO2iFmLjk6gxnWkA uuVUJYmn/Er6WBf10C7fFrEOqFMTEK0= X-MC-Unique: UhwoFS1ZPeub8Z_HjQPsXQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721752799; x=1722357599; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zZkNsRazCJZZPQZc0vMKv6cPyzjVC9m4rB51zqNztNA=; b=iShMagqdaxVM+OV2iqbBEH/vpBa7PnH6Cdfnoq3q9carfy1GffC7Lkm1ek3Q3cOI6N tT3GUk80LKPSZ0NIDSVAYtTK3dvEKxi7IFjb0bqnZEBxYgfHi8/qxuxUV8vOSEhXEgRl KGe5XvySW4f2JF7NS9yVlWxTJpZKVuVGVTwBKJ3WErLu1whcmf++zibGWBk2N7Sf3QDe 0lAaq4D0CjVRigEJ7PKMD3oRqol7X5SkX95dYZhXle9r00GFRlNvlx4jepen570cfWk5 Lgnm2TCiHiny+6y43fFn9vx7colYliZjVuknU8j5nL3yQtKvNsfcHvsQtDApudngTlRO IOjQ== X-Gm-Message-State: AOJu0YxKn1TWs7e0OjNsM91lBE0eSG0GU/oF7Zc6urm5X296YBTAGgH1 gwFocvDEf8ngQeGgWAM5dWO0ihAzAaw/SCnD+4ZnqQ66y+TvSANrdFQvNQdV7b5EoEmr2mrF3us 2TYd+H72rKnyy1jKfQfMqbEBAE1XFpyFU9yrBVLeeg672kNtRZH3TUlfQDxqGZmJVwBUfzAwVif ft1p4U4LgTpS1M9ifl2qC2iYfDR8OWUcRUjg== X-Received: by 2002:adf:fc81:0:b0:366:dee6:a9ea with SMTP id ffacd0b85a97d-369e3f110d7mr1667190f8f.26.1721752799495; Tue, 23 Jul 2024 09:39:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF25MuBu/BdiagYbUaDvtsF9v4p2Z9x2bII98AIeHY+t7t7ZPc8XDwNF2wsfMJIYD+juP+Ydg== X-Received: by 2002:adf:fc81:0:b0:366:dee6:a9ea with SMTP id ffacd0b85a97d-369e3f110d7mr1667172f8f.26.1721752798757; Tue, 23 Jul 2024 09:39:58 -0700 (PDT) From: Hanna Czenczek To: qemu-devel@nongnu.org Cc: Hanna Czenczek , Stefan Hajnoczi , "Michael S . Tsirkin" Subject: [PATCH v2 2/2] virtio: Always reset vhost devices Date: Tue, 23 Jul 2024 18:39:40 +0200 Message-ID: <20240723163941.48775-3-hreitz@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240723163941.48775-1-hreitz@redhat.com> References: <20240723163941.48775-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.133, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1721752865112116600 Content-Type: text/plain; charset="utf-8" Requiring `vhost_started` to be true for resetting vhost devices in `virtio_reset()` seems like the wrong condition: Most importantly, the preceding `virtio_set_status(vdev, 0)` call will (for vhost devices) end up in `vhost_dev_stop()` (through vhost devices' `.set_status` implementations), setting `vdev->vhost_started =3D false`. Therefore, the gated `vhost_reset_device()` call is unreachable. `vhost_started` is not documented, so it is hard to say what exactly it is supposed to mean, but judging from the fact that `vhost_dev_start()` sets it and `vhost_dev_stop()` clears it, it seems like it indicates whether there is a vhost back-end, and whether that back-end is currently running and processing virtio requests. Making a reset conditional on whether the vhost back-end is processing virtio requests seems wrong; in fact, it is probably better to reset it only when it is not currently processing requests, which is exactly the current order of operations in `virtio_reset()`: First, the back-end is stopped through `virtio_set_status(vdev, 0)`, then we want to send a reset. Therefore, we should drop the `vhost_started` condition, but in its stead we then have to verify that we can indeed send a reset to this vhost device, by not just checking `k->get_vhost !=3D NULL` (introduced by commit 95e1019a4a9), but also that the vhost back-end is connected (`hdev =3D k->get_vhost(); hdev !=3D NULL && hdev->vhost_ops !=3D NULL`). Reviewed-by: Stefan Hajnoczi Reviewed-by: Michael S. Tsirkin Signed-off-by: Hanna Czenczek --- hw/virtio/virtio.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 583a224163..35dfc01074 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2150,8 +2150,12 @@ void virtio_reset(void *opaque) vdev->device_endian =3D virtio_default_endian(); } =20 - if (vdev->vhost_started && k->get_vhost) { - vhost_reset_device(k->get_vhost(vdev)); + if (k->get_vhost) { + struct vhost_dev *hdev =3D k->get_vhost(vdev); + /* Only reset when vhost back-end is connected */ + if (hdev && hdev->vhost_ops) { + vhost_reset_device(hdev); + } } =20 if (k->reset) { --=20 2.45.2