From patchwork Tue Nov 12 18:53:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 290743 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 492512C0095 for ; Wed, 13 Nov 2013 05:53:56 +1100 (EST) Received: from localhost ([::1]:44666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgJ62-0005aW-4c for incoming@patchwork.ozlabs.org; Tue, 12 Nov 2013 13:53:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgJ5g-0005aG-Tx for qemu-devel@nongnu.org; Tue, 12 Nov 2013 13:53:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VgJ5b-000656-Tm for qemu-devel@nongnu.org; Tue, 12 Nov 2013 13:53:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43113) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgJ5b-000652-Kx; Tue, 12 Nov 2013 13:53:27 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rACIrPOw022185 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 12 Nov 2013 13:53:25 -0500 Received: from bling.home (ovpn-113-87.phx2.redhat.com [10.3.113.87]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rACIrOP6019422; Tue, 12 Nov 2013 13:53:24 -0500 To: qemu-devel@nongnu.org, anthony@codemonkey.ws From: Alex Williamson Date: Tue, 12 Nov 2013 11:53:24 -0700 Message-ID: <20131112185059.7262.33780.stgit@bling.home> User-Agent: StGit/0.16 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: bsd@redhat.com, qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH for-1.7] vfio-pci: Fix multifunction=on X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When an assigned device is initialized it copies the device config space into the emulated config space. Unfortunately multifunction is setup prior to the device initfn and gets clobbered. We need to restore it just like pci-assign does. Signed-off-by: Alex Williamson Cc: qemu-stable@nongnu.org Reviewed-by: Bandan Das --- Anthony, please apply directly or let me know if you'd prefer a pull request. Thanks hw/misc/vfio.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c index fe95e03..f7f8a19 100644 --- a/hw/misc/vfio.c +++ b/hw/misc/vfio.c @@ -3568,6 +3568,13 @@ static int vfio_initfn(PCIDevice *pdev) vdev->emulated_config_bits[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_MULTI_FUNCTION; + /* Restore or clear multifunction, this is always controlled by QEMU */ + if (vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) { + vdev->pdev.config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION; + } else { + vdev->pdev.config[PCI_HEADER_TYPE] &= ~PCI_HEADER_TYPE_MULTI_FUNCTION; + } + /* * Clear host resource mapping info. If we choose not to register a * BAR, such as might be the case with the option ROM, we can get