From patchwork Sat Jun 18 20:42:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Yariv X-Patchwork-Id: 9185863 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 406E06075F for ; Sat, 18 Jun 2016 21:18:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EE4B27C2C for ; Sat, 18 Jun 2016 21:18:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23B7127E71; Sat, 18 Jun 2016 21:18:35 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 DBF7127DD0 for ; Sat, 18 Jun 2016 21:18:33 +0000 (UTC) Received: from localhost ([::1]:36458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bENdR-0005oi-2E for patchwork-qemu-devel@patchwork.kernel.org; Sat, 18 Jun 2016 17:18:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEN4r-0007cp-Bf for qemu-devel@nongnu.org; Sat, 18 Jun 2016 16:42:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bEN4l-0002lQ-DE for qemu-devel@nongnu.org; Sat, 18 Jun 2016 16:42:48 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:33741) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEN4l-0002lL-33 for qemu-devel@nongnu.org; Sat, 18 Jun 2016 16:42:43 -0400 Received: by mail-pf0-x243.google.com with SMTP id c74so8609016pfb.0 for ; Sat, 18 Jun 2016 13:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wizery-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=+6c7pXa69fxGNy3oQqD1uvGFNbvB9lyQmgcuQVSNFoM=; b=Rijh8SiljoffisUPFr7Mrikde/UrV/TA7t/rfDw+Gfr/wNvFZJbBNUiPGCLZ9nW5rO qX02p/g0vNQwrXf5fHDWsa8AA/LnseJc4xnsN8epnOnd7lD0Ta1nO6f8KI+CvrFo0ttX FShHcE4i0XyqSQ3g+LBX31/B/XQikFovp9AZIasvDlzvwH0/YJy2sbkewtt3kR7jUy5c 5jMw5bFC8Ft/c4UjlvrrZgmaHYm5B44+T4fcU1/sXJXTE2q5lf2vwi3btPqCd/deM1VV +q18WvDMla5Gdp5uTUxchdhSM44tS4Ve1p6J9CjKs/ebkYUcBr9gvQHYkzj9wROtWVBi TW6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+6c7pXa69fxGNy3oQqD1uvGFNbvB9lyQmgcuQVSNFoM=; b=Jr6c/Ws8o085NOb57HfAIbL8R+9wefyKauFjHH9DDqI8GdrtShplDRx00XKk0JCmMm 0lzHWUwa1C5lLam18lyKLv96pgDdMGmOO+skpPNyn2MrTSbHPtr78ZBVpnHZNuBHHg/n +njWrdlMoDtvodZXw0fQdroDdw0zOtgjbyhQGOJxO2lNvxzvzc/9lynzMyXA96+owJYf q+MG0Wt3yUcjqrIYJwY02DdmOZDv6fOHhRMr5P371ckCrlZl2z72b/pFXxzHliB5Lt8b lgrJJcujxO/uByyjaYrir4YqOD8W72ioSqMYnS7KE/uUvQWklLq/mxqME26rAIi6wrdp t0TA== X-Gm-Message-State: ALyK8tKAYJyFFmOqUPuj46IBnEa2j6eG0kFkIg+oaM/qz5PbwZjtgdAMQL4jqhDIYMqtnw== X-Received: by 10.98.14.140 with SMTP id 12mr10990968pfo.68.1466282561766; Sat, 18 Jun 2016 13:42:41 -0700 (PDT) Received: from WorkStation.amr.corp.intel.com (fmdmzpr03-ext.fm.intel.com. [192.55.54.38]) by smtp.gmail.com with ESMTPSA id b67sm26189143pfg.85.2016.06.18.13.42.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Jun 2016 13:42:41 -0700 (PDT) From: Ido Yariv To: qemu-devel@nongnu.org Date: Sat, 18 Jun 2016 16:42:05 -0400 Message-Id: <1466282525-3018-1-git-send-email-ido@wizery.com> X-Mailer: git-send-email 2.5.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::243 X-Mailman-Approved-At: Sat, 18 Jun 2016 17:16:22 -0400 Subject: [Qemu-devel] [PATCH] i386: pci-assign: Fix MSI-X table size 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: Paolo Bonzini , Richard Henderson , Ido Yariv , Eduardo Habkost , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The current code creates a whole page mmio region for the MSI-X table size. However, the page containing the MSI-X table may contain other registers not related to MSI-X. Creating an mmio region for the whole page masks such registers and may break drivers in the guest OS. Since maximal number of entries is known, use that instead to deduce the table size when setting up the mmio region. Signed-off-by: Ido Yariv Reviewed-by: Michael S. Tsirkin --- hw/i386/kvm/pci-assign.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c index f9c9014..98997d1 100644 --- a/hw/i386/kvm/pci-assign.c +++ b/hw/i386/kvm/pci-assign.c @@ -36,8 +36,6 @@ #include "kvm_i386.h" #include "hw/pci/pci-assign.h" -#define MSIX_PAGE_SIZE 0x1000 - /* From linux/ioport.h */ #define IORESOURCE_IO 0x00000100 /* Resource type */ #define IORESOURCE_MEM 0x00000200 @@ -122,6 +120,7 @@ typedef struct AssignedDevice { int *msi_virq; MSIXTableEntry *msix_table; hwaddr msix_table_addr; + uint16_t msix_table_size; uint16_t msix_max; MemoryRegion mmio; char *configfd_name; @@ -1310,6 +1309,7 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev, Error **errp) bar_nr = msix_table_entry & PCI_MSIX_FLAGS_BIRMASK; msix_table_entry &= ~PCI_MSIX_FLAGS_BIRMASK; dev->msix_table_addr = pci_region[bar_nr].base_addr + msix_table_entry; + dev->msix_table_size = msix_max * sizeof(MSIXTableEntry); dev->msix_max = msix_max; } @@ -1633,7 +1633,7 @@ static void assigned_dev_msix_reset(AssignedDevice *dev) return; } - memset(dev->msix_table, 0, MSIX_PAGE_SIZE); + memset(dev->msix_table, 0, dev->msix_table_size); for (i = 0, entry = dev->msix_table; i < dev->msix_max; i++, entry++) { entry->ctrl = cpu_to_le32(0x1); /* Masked */ @@ -1642,8 +1642,8 @@ static void assigned_dev_msix_reset(AssignedDevice *dev) static void assigned_dev_register_msix_mmio(AssignedDevice *dev, Error **errp) { - dev->msix_table = mmap(NULL, MSIX_PAGE_SIZE, PROT_READ|PROT_WRITE, - MAP_ANONYMOUS|MAP_PRIVATE, 0, 0); + dev->msix_table = mmap(NULL, dev->msix_table_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); if (dev->msix_table == MAP_FAILED) { error_setg_errno(errp, errno, "failed to allocate msix_table"); dev->msix_table = NULL; @@ -1653,7 +1653,7 @@ static void assigned_dev_register_msix_mmio(AssignedDevice *dev, Error **errp) assigned_dev_msix_reset(dev); memory_region_init_io(&dev->mmio, OBJECT(dev), &assigned_dev_msix_mmio_ops, - dev, "assigned-dev-msix", MSIX_PAGE_SIZE); + dev, "assigned-dev-msix", dev->msix_table_size); } static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev) @@ -1662,7 +1662,7 @@ static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev) return; } - if (munmap(dev->msix_table, MSIX_PAGE_SIZE) == -1) { + if (munmap(dev->msix_table, dev->msix_table_size) == -1) { error_report("error unmapping msix_table! %s", strerror(errno)); } dev->msix_table = NULL;