From patchwork Wed Jul 27 15:56:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 593749 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp479457maz; Wed, 27 Jul 2022 09:09:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vYdBzEhFHlzm/P3ENT/YMvv6P8rMYF4+b2tYQxIaP9im9MqQSM7SskAHoFS3D8+3WOrHt0 X-Received: by 2002:a67:bc10:0:b0:358:5fbd:79e7 with SMTP id t16-20020a67bc10000000b003585fbd79e7mr4947977vsn.24.1658938177373; Wed, 27 Jul 2022 09:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658938177; cv=none; d=google.com; s=arc-20160816; b=dBXR1+oGGmjZ+CkEGZdBlh1k0tFaV5HSXQ1fC47UNtxPKzTzmSL3Iu/O1fyiYiXb57 Ros1fYcUgBUINlos5Cob1406rTwZ6cYTkeBbyzHajCuJqiR9oJV10ORwfEfniaftKnqH gpsai0NS4JKBcTaNQ8tXt+sgI9OGgM9OpEujIJiKHY2ZcbXZbgl2c4yJLPoWcOoD7ijI g8Ey7bRJ25tZk/gI1r7LxBhq44REA47igTVR5rTjiWXlCXiQ5E9p+RgTK8Smio0D8RV+ mNrYlCpg/D8bNxwatFNEovHGxbR72ulbrRqT5c6fh5qS9+RqTWK4asBp/kT7QionJK87 Ck/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s3nGxeo53LwaMo+sziN/l2Vq3ARUUV/BFGaJ8lB68So=; b=eOPky/xbpeGZMpQBZ6Zok/5phv1cvKNON4GavaNPAYBPCH+XB7Ui6wbiVELxjx36vJ C7ljALLK/H1rFbGoBcn1eQ+ugrUAqpum95c9n5tyiWUpJvnQvTTKaLmpnIBK67ReNbWa bPbk4r75tsipJ6KW9XLpJv/sf/UBYnUa1nLekB/V+XlJkY/DC/PjLpD86erFXypp4+HU W6jBWL/HwjiqP2oeSuDZrd/338+sZRUhX9sLNcVo1u4A426i3fWUkexGSh+AQ2TwIB7v YoXaaqIJt865yMlaR+bQsXprg+CCVOVKZigsoIS/KJtAowCOXORna5RLQHBffT238z2e 5Hdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MPXPZjDP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v63-20020a676142000000b003586d3bea81si754272vsb.357.2022.07.27.09.09.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 Jul 2022 09:09:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MPXPZjDP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGjbM-0005QI-Su for patch@linaro.org; Wed, 27 Jul 2022 12:09:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGjPC-00025n-Bc for qemu-devel@nongnu.org; Wed, 27 Jul 2022 11:57:02 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:45612) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oGjPA-0001sf-MK for qemu-devel@nongnu.org; Wed, 27 Jul 2022 11:57:02 -0400 Received: by mail-wr1-x42e.google.com with SMTP id v13so17284387wru.12 for ; Wed, 27 Jul 2022 08:57:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=s3nGxeo53LwaMo+sziN/l2Vq3ARUUV/BFGaJ8lB68So=; b=MPXPZjDPRWub//Lbn5Vl/VWbjqy0626GIuRBfMBkJiE5lCqJA48YGwDM8c9BY8u4cl FRIx5Z7Ns30kG8v5HYbAHgzJRSKwFEXCe+EUmrfhWqODXOXysLIo3dGWelPIk3Hv15HF aMeCQJChIFkuMBtAfa8qntLcctZ8o/izXobOHshci31ZknqsM5WBkwpzw4nwhNA3hIrm llMMU4GPNJrsI49xqthkB13FyX0wwbhivUc1JgzKI5+jFhQNLdYNs8uwMvCVG/l1UQua 7uIdOK8fU3l926gYAGmEjaOa5IgUvI/LcxTQ3VIreN3p2Sn85izstGxZ50hNB+yvKHgM XZhg== 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=s3nGxeo53LwaMo+sziN/l2Vq3ARUUV/BFGaJ8lB68So=; b=OmVN6U70SZe80vCB87iJVUs0HPKeUlu+OcYX/+ZDUJL68B70RJUNvNZL604ZC4NsTL X8yPvkvcMpS8WB//41qrj3v+ZArcx0+NZg++4eiiE1HweDKkjbdsFD3nfSDY3CVM+++F oif31hCTF/A30Em6Dx5YzDX9Ot+boevy8DnD9e5PIn3Bw4zxZUwT1abb4puOxpk75Wn1 EzS2gfy48F8UXR6xLV8UK83EC5LUXsmgBA34gqTTrndlMdqL17cbD+mqkUfiD7+YbpSc nE0h+6jFTt6rrJHzHvB/M2+FBZwX3s4/n47TEiDPFMj0sh5Oq+WoQSTH+Zm48uj5QnKv 3Pvg== X-Gm-Message-State: AJIora9eoSjulwC9ZO4OUEAqL5Xw8dTadu6gZeUAZRwEnYW9G+7JBceJ xfwmx/SJrIxi0goX2UhxSqHuDg== X-Received: by 2002:a05:600c:4f4f:b0:3a3:3cb5:c02d with SMTP id m15-20020a05600c4f4f00b003a33cb5c02dmr3642025wmq.198.1658937419222; Wed, 27 Jul 2022 08:56:59 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id r8-20020adfdc88000000b0021e13efa17esm17254702wrj.70.2022.07.27.08.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jul 2022 08:56:55 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A3A391FFBB; Wed, 27 Jul 2022 16:56:53 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: mst@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v1 3/5] hw/virtio: gracefully handle unset vhost_dev vdev Date: Wed, 27 Jul 2022 16:56:51 +0100 Message-Id: <20220727155653.3974426-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220727155653.3974426-1-alex.bennee@linaro.org> References: <20220727155653.3974426-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" I've noticed asserts firing because we query the status of vdev after a vhost connection is closed down. Rather than faulting on the NULL indirect just quietly reply false. Signed-off-by: Alex Bennée Message-Id: <20220726192150.2435175-8-alex.bennee@linaro.org> --- hw/virtio/vhost.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 0827d631c0..f758f177bb 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -306,7 +306,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size) dev->log_size = size; } -static int vhost_dev_has_iommu(struct vhost_dev *dev) +static bool vhost_dev_has_iommu(struct vhost_dev *dev) { VirtIODevice *vdev = dev->vdev; @@ -316,8 +316,12 @@ static int vhost_dev_has_iommu(struct vhost_dev *dev) * does not have IOMMU, there's no need to enable this feature * which may cause unnecessary IOTLB miss/update transactions. */ - return virtio_bus_device_iommu_enabled(vdev) && - virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM); + if (vdev) { + return virtio_bus_device_iommu_enabled(vdev) && + virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM); + } else { + return false; + } } static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr,