From patchwork Fri Sep 9 10:14:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 667951 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sVtQB3n5kz9s2G for ; Fri, 9 Sep 2016 20:16:02 +1000 (AEST) Received: from localhost ([::1]:56956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biIql-0005gt-3j for incoming@patchwork.ozlabs.org; Fri, 09 Sep 2016 06:15:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47856) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biIpY-0004lr-H0 for qemu-devel@nongnu.org; Fri, 09 Sep 2016 06:14:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1biIpV-0000Ld-60 for qemu-devel@nongnu.org; Fri, 09 Sep 2016 06:14:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58782) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biIpV-0000LW-1I; Fri, 09 Sep 2016 06:14:41 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0ABF8124D; Fri, 9 Sep 2016 10:14:40 +0000 (UTC) Received: from max-t460s.redhat.com (vpn1-4-133.ams2.redhat.com [10.36.4.133]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u89AEYA9003785; Fri, 9 Sep 2016 06:14:39 -0400 From: Maxime Coquelin To: mst@redhat.com, qemu-devel@nongnu.org Date: Fri, 9 Sep 2016 12:14:32 +0200 Message-Id: <1473416072-7063-3-git-send-email-maxime.coquelin@redhat.com> In-Reply-To: <1473416072-7063-1-git-send-email-maxime.coquelin@redhat.com> References: <1473416072-7063-1-git-send-email-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 09 Sep 2016 10:14:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] virtio-pci: Disable modern interface if backend without VIRTIO_F_VERSION_1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcel@redhat.com, vkaplans@redhat.com, Maxime Coquelin , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch makes pci devices plugging more robust, by not confusing guest with modern interface when the backend doesn't support VIRTIO_F_VERSION_1. Cc: Marcel Apfelbaum Cc: Michael S. Tsirkin Cc: qemu-stable@nongnu.org Signed-off-by: Maxime Coquelin --- hw/virtio/virtio-pci.c | 15 +++++++++++++++ hw/virtio/virtio-pci.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 755f921..0e5d59c 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1581,6 +1581,21 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) uint32_t size; VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); + /* + * Virtio capabilities present without + * VIRTIO_F_VERSION_1 confuses guests + */ + if (!virtio_test_backend_feature(vdev, VIRTIO_F_VERSION_1, errp)) { + virtio_pci_disable_modern(proxy); + } + + legacy = virtio_pci_legacy(proxy); + modern = virtio_pci_modern(proxy); + if (!legacy && !modern) { + error_setg(errp, "PCI device is neither legacy nor modern."); + return; + } + config = proxy->pci_dev.config; if (proxy->class_code) { pci_config_set_class(config, proxy->class_code); diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index 25fbf8a..4e976b3 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -172,6 +172,11 @@ static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy) proxy->disable_legacy = ON_OFF_AUTO_ON; } +static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy) +{ + proxy->disable_modern = true; +} + /* * virtio-scsi-pci: This extends VirtioPCIProxy. */