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: 9322847 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 E317760231 for ; Fri, 9 Sep 2016 10:15:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D604529CAA for ; Fri, 9 Sep 2016 10:15:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAD7B29CFD; Fri, 9 Sep 2016 10:15:16 +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 B7B7329CBD for ; Fri, 9 Sep 2016 10:15:13 +0000 (UTC) Received: from localhost ([::1]:56945 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biIq0-0004mk-US for patchwork-qemu-devel@patchwork.kernel.org; Fri, 09 Sep 2016 06:15:12 -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+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: 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. */