From patchwork Fri Apr 29 09:05:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 740601 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3T95wuM025563 for ; Fri, 29 Apr 2011 09:05:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755463Ab1D2JFy (ORCPT ); Fri, 29 Apr 2011 05:05:54 -0400 Received: from david.siemens.de ([192.35.17.14]:18847 "EHLO david.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752936Ab1D2JFk (ORCPT ); Fri, 29 Apr 2011 05:05:40 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by david.siemens.de (8.13.6/8.13.6) with ESMTP id p3T95Yh9005222; Fri, 29 Apr 2011 11:05:34 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p3T95XVW011781; Fri, 29 Apr 2011 11:05:34 +0200 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org, Alex Williamson Subject: [PATCH v2 4/6] pci-assign: Properly handle more overlapping accesses Date: Fri, 29 Apr 2011 11:05:31 +0200 Message-Id: X-Mailer: git-send-email 1.7.1 In-Reply-To: References: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 29 Apr 2011 09:05:58 +0000 (UTC) Ensure that accesses exceeding PCI_CAPABILITY_LIST and PCI_INTERRUPT_LINE+PIN hit the real device in areas we do not virtualize. Again, we do not optimize these checks and accesses a lot, they are considered to be slow paths. Signed-off-by: Jan Kiszka --- hw/device-assignment.c | 34 +++++++++++++++++++++++++++++----- 1 files changed, 29 insertions(+), 5 deletions(-) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index cea072e..37c77e3 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -442,7 +442,29 @@ static void assigned_dev_pci_write_config(PCIDevice *d, uint32_t address, ranges_overlap(address, len, PCI_INTERRUPT_LINE, 2)) { /* used for update-mappings (BAR emulation) */ pci_default_write_config(d, address, val, len); - return; + + /* Ensure that writes to overlapping areas we don't virtualize still + * hit the device. */ + switch (address) { + case PCI_CAPABILITY_LIST: + if (len > 1) { + len -= 1; + address += 1; + val >>= 8; + break; /* continue writing to the device */ + } + return; + case PCI_INTERRUPT_LINE: + if (len > 2) { + len -= 2; + address += 2; + val >>= 16; + break; /* continue writing to the device */ + } + return; + default: + return; + } } DEBUG("NON BAR (%x.%x): address=%04x val=0x%08x len=%d\n", @@ -467,7 +489,7 @@ again: static uint32_t assigned_dev_pci_read_config(PCIDevice *d, uint32_t address, int len) { - uint32_t val = 0; + uint32_t val = 0, virt_val; int fd; ssize_t ret; AssignedDevice *pci_dev = DO_UPCAST(AssignedDevice, dev, d); @@ -484,12 +506,10 @@ static uint32_t assigned_dev_pci_read_config(PCIDevice *d, uint32_t address, * - vendor & device ID * - base address registers * - ROM base address & capability pointer - * - interrupt line & pin */ if (ranges_overlap(address, len, PCI_VENDOR_ID, 4) || ranges_overlap(address, len, PCI_BASE_ADDRESS_0, 24) || - ranges_overlap(address, len, PCI_ROM_ADDRESS, 5) || - ranges_overlap(address, len, PCI_INTERRUPT_LINE, 2)) { + ranges_overlap(address, len, PCI_ROM_ADDRESS, 4)) { val = pci_default_read_config(d, address, len); DEBUG("(%x.%x): address=%04x val=0x%08x len=%d\n", (d->devfn >> 3) & 0x1F, (d->devfn & 0x7), address, val, len); @@ -523,6 +543,10 @@ do_log: address, len, PCI_COMMAND, 0xffff); } + virt_val = pci_default_read_config(d, address, len); + val = merge_bits(val, virt_val, address, len, PCI_CAPABILITY_LIST, 0xff); + val = merge_bits(val, virt_val, address, len, PCI_INTERRUPT_LINE, 0xffff); + if (!pci_dev->cap.available) { /* kill the special capabilities */ if (address == PCI_COMMAND && len == 4) {