From patchwork Sat Aug 6 07:28:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1041012 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p767Ts4A003719 for ; Sat, 6 Aug 2011 07:29:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751018Ab1HFH3E (ORCPT ); Sat, 6 Aug 2011 03:29:04 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:42324 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750803Ab1HFH3B (ORCPT ); Sat, 6 Aug 2011 03:29:01 -0400 Received: by wyf22 with SMTP id 22so1651299wyf.19 for ; Sat, 06 Aug 2011 00:29:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=G4EAmGVmuIXk7T9+wVp8ep0kt3KWdTssLsf+vWLazgM=; b=r6RAsvM1jy821doJbpHVOAgOWiEqW/A/sDk47pglvcxMe3rpf/rXggKItMickrjPf5 7PJ0WMvKvHPhiMxZOU3fCCLj7KmNfIyeru0uXoHy1GqL8/SM/lud1w6diQ/JmtGRkIRg JdWQH/d7mLxFWroCGeOQYT7rHFSbY46aFPjDg= Received: by 10.216.8.85 with SMTP id 63mr162463weq.29.1312615740588; Sat, 06 Aug 2011 00:29:00 -0700 (PDT) Received: from localhost.localdomain (bzq-79-176-218-143.red.bezeqint.net [79.176.218.143]) by mx.google.com with ESMTPS id a43sm2258263wed.4.2011.08.06.00.28.58 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 06 Aug 2011 00:29:00 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: evensky@dancer.ca.sandia.gov, kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, Sasha Levin Subject: [PATCH v3] kvm tools: Fix PCI masking on probes Date: Sat, 6 Aug 2011 10:28:04 +0300 Message-Id: <1312615684-21450-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.6 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]); Sat, 06 Aug 2011 07:29:55 +0000 (UTC) This patch adds a missing check of mask during probing of PCI BARs. The missing check manifested in wrong address values for the BARs after the initial probe. Reported-by: David Evensky Signed-off-by: Sasha Levin --- tools/kvm/hw/vesa.c | 1 + tools/kvm/include/kvm/pci.h | 4 +++- tools/kvm/pci.c | 11 ++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/kvm/hw/vesa.c b/tools/kvm/hw/vesa.c index 032e630..2af08df 100644 --- a/tools/kvm/hw/vesa.c +++ b/tools/kvm/hw/vesa.c @@ -56,6 +56,7 @@ struct framebuffer *vesa__init(struct kvm *kvm) vesa_pci_device.irq_line = line; vesa_base_addr = ioport__register(IOPORT_EMPTY, &vesa_io_ops, IOPORT_SIZE, NULL); vesa_pci_device.bar[0] = vesa_base_addr | PCI_BASE_ADDRESS_SPACE_IO; + vesa_pci_device.bar_size[0] = VESA_MEM_SIZE; pci__register(&vesa_pci_device, dev); mem = mmap(NULL, VESA_MEM_SIZE, PROT_RW, MAP_ANON_NORESERVE, -1, 0); diff --git a/tools/kvm/include/kvm/pci.h b/tools/kvm/include/kvm/pci.h index 27fa349..2ab5291 100644 --- a/tools/kvm/include/kvm/pci.h +++ b/tools/kvm/include/kvm/pci.h @@ -36,7 +36,7 @@ struct msix_cap { u8 next; u16 table_size; u32 table_offset; - struct msix_table table[3 * PCI_MSIX_ENTRY_SIZE]; + struct msix_table table[3]; }; struct pci_device_header { @@ -63,6 +63,8 @@ struct pci_device_header { u8 min_gnt; u8 max_lat; struct msix_cap msix; + u8 empty[136]; /* Rest of PCI config space */ + u32 bar_size[6]; }; void pci__init(void); diff --git a/tools/kvm/pci.c b/tools/kvm/pci.c index 3b92ea4..fd19b73 100644 --- a/tools/kvm/pci.c +++ b/tools/kvm/pci.c @@ -95,20 +95,25 @@ static bool pci_config_data_out(struct ioport *ioport, struct kvm *kvm, u16 port offset = start + (pci_config_address.register_number << 2); if (offset < sizeof(struct pci_device_header)) { void *p = pci_devices[dev_num]; + u8 bar = offset - PCI_BAR_OFFSET(0); u32 sz = PCI_IO_SIZE; + if (bar < 6 && pci_devices[dev_num]->bar_size[bar]) + sz = pci_devices[dev_num]->bar_size[bar]; + /* * If the kernel masks the BAR it would expect to find the * size of the BAR there next time it reads from it. * When the kernel got the size it would write the address * back. */ - if (*(u32 *)(p + offset)) { + if (ioport__read32(p + offset)) { /* See if kernel tries to mask one of the BARs */ if ((offset >= PCI_BAR_OFFSET(0)) && - (offset <= PCI_BAR_OFFSET(6))) + (offset <= PCI_BAR_OFFSET(6)) && + (ioport__read32(data) == 0xFFFFFFFF)) memcpy(p + offset, &sz, sizeof(sz)); - else + else memcpy(p + offset, data, size); } }