From patchwork Fri Sep 9 13:10:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 9323413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 74D8860231 for ; Fri, 9 Sep 2016 13:14:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6736229E9B for ; Fri, 9 Sep 2016 13:14:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BE6329E9E; Fri, 9 Sep 2016 13:14:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BC32629E9B for ; Fri, 9 Sep 2016 13:14:20 +0000 (UTC) Received: from localhost ([::1]:57918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biLdL-0001gS-UM for patchwork-qemu-devel@patchwork.kernel.org; Fri, 09 Sep 2016 09:14:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biLZS-00072z-Dx for qemu-devel@nongnu.org; Fri, 09 Sep 2016 09:10:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1biLZQ-0007Ox-Bp for qemu-devel@nongnu.org; Fri, 09 Sep 2016 09:10:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51170) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biLZQ-0007Od-6P; Fri, 09 Sep 2016 09:10:16 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 9BFBC7F7A4; Fri, 9 Sep 2016 13:10:15 +0000 (UTC) Received: from max-t460s.redhat.com (vpn1-4-173.ams2.redhat.com [10.36.4.173]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u89DA8D9005485; Fri, 9 Sep 2016 09:10:13 -0400 From: Maxime Coquelin To: mst@redhat.com, qemu-devel@nongnu.org, cornelia.huck@de.ibm.com Date: Fri, 9 Sep 2016 15:10:07 +0200 Message-Id: <1473426607-10516-3-git-send-email-maxime.coquelin@redhat.com> In-Reply-To: <1473426607-10516-1-git-send-email-maxime.coquelin@redhat.com> References: <1473426607-10516-1-git-send-email-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 09 Sep 2016 13:10:15 +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 v2 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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: Cornelia Huck 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..9e88d7b 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_virtio_1(vdev, 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. */