|
|
8be556 |
From 7a67550485c32b2516750c4179b7a27a79e8146b Mon Sep 17 00:00:00 2001
|
|
|
8be556 |
From: Xiao Wang <jasowang@redhat.com>
|
|
|
8be556 |
Date: Thu, 18 Jun 2015 06:11:46 +0200
|
|
|
8be556 |
Subject: [PATCH 025/217] pci: remove hard-coded bar size in
|
|
|
8be556 |
msix_init_exclusive_bar()
|
|
|
8be556 |
|
|
|
8be556 |
Message-id: <1434607916-15166-11-git-send-email-jasowang@redhat.com>
|
|
|
8be556 |
Patchwork-id: 66315
|
|
|
8be556 |
O-Subject: [RHEL7.2 qemu-kvm-rhev PATCH 10/20] pci: remove hard-coded bar size in msix_init_exclusive_bar()
|
|
|
8be556 |
Bugzilla: 1231610
|
|
|
8be556 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
8be556 |
RH-Acked-by: Vlad Yasevich <vyasevic@redhat.com>
|
|
|
8be556 |
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
8be556 |
|
|
|
8be556 |
This patch lets msix_init_exclusive_bar() can calculate the bar and
|
|
|
8be556 |
pba size based on the number of MSI-X vectors other than using a
|
|
|
8be556 |
hard-coded limit 4096. This is needed to allow device to have more
|
|
|
8be556 |
than 128 MSI_X vectors. To keep migration compatibility, keep using
|
|
|
8be556 |
4096 as bar size and 2048 for pba offset.
|
|
|
8be556 |
|
|
|
8be556 |
Notes: We don't care about the case that using vectors > 128 for
|
|
|
8be556 |
legacy machine type. Since we limit the queue max to 64, so vectors >=
|
|
|
8be556 |
65 is meaningless.
|
|
|
8be556 |
|
|
|
8be556 |
Virtio device will be the first user for this.
|
|
|
8be556 |
|
|
|
8be556 |
Cc: Keith Busch <keith.busch@intel.com>
|
|
|
8be556 |
Cc: Kevin Wolf <kwolf@redhat.com>
|
|
|
8be556 |
Cc: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
8be556 |
Cc: Michael S. Tsirkin <mst@redhat.com>
|
|
|
8be556 |
Signed-off-by: Jason Wang <jasowang@redhat.com>
|
|
|
8be556 |
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
8be556 |
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
8be556 |
(cherry picked from commit a0ccd2123ee2f83a1f081e4c39013c3316f9ec7a)
|
|
|
8be556 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
8be556 |
---
|
|
|
8be556 |
hw/pci/msix.c | 30 +++++++++++++++++++-----------
|
|
|
8be556 |
1 file changed, 19 insertions(+), 11 deletions(-)
|
|
|
8be556 |
|
|
|
8be556 |
diff --git a/hw/pci/msix.c b/hw/pci/msix.c
|
|
|
8be556 |
index 24de260..f8748cf 100644
|
|
|
8be556 |
--- a/hw/pci/msix.c
|
|
|
8be556 |
+++ b/hw/pci/msix.c
|
|
|
8be556 |
@@ -295,29 +295,37 @@ int msix_init_exclusive_bar(PCIDevice *dev, unsigned short nentries,
|
|
|
8be556 |
{
|
|
|
8be556 |
int ret;
|
|
|
8be556 |
char *name;
|
|
|
8be556 |
+ uint32_t bar_size = 4096;
|
|
|
8be556 |
+ uint32_t bar_pba_offset = bar_size / 2;
|
|
|
8be556 |
+ uint32_t bar_pba_size = (nentries / 8 + 1) * 8;
|
|
|
8be556 |
|
|
|
8be556 |
/*
|
|
|
8be556 |
* Migration compatibility dictates that this remains a 4k
|
|
|
8be556 |
* BAR with the vector table in the lower half and PBA in
|
|
|
8be556 |
- * the upper half. Do not use these elsewhere!
|
|
|
8be556 |
+ * the upper half for nentries which is lower or equal to 128.
|
|
|
8be556 |
+ * No need to care about using more than 65 entries for legacy
|
|
|
8be556 |
+ * machine types who has at most 64 queues.
|
|
|
8be556 |
*/
|
|
|
8be556 |
-#define MSIX_EXCLUSIVE_BAR_SIZE 4096
|
|
|
8be556 |
-#define MSIX_EXCLUSIVE_BAR_TABLE_OFFSET 0
|
|
|
8be556 |
-#define MSIX_EXCLUSIVE_BAR_PBA_OFFSET (MSIX_EXCLUSIVE_BAR_SIZE / 2)
|
|
|
8be556 |
-#define MSIX_EXCLUSIVE_CAP_OFFSET 0
|
|
|
8be556 |
+ if (nentries * PCI_MSIX_ENTRY_SIZE > bar_pba_offset) {
|
|
|
8be556 |
+ bar_pba_offset = nentries * PCI_MSIX_ENTRY_SIZE;
|
|
|
8be556 |
+ }
|
|
|
8be556 |
|
|
|
8be556 |
- if (nentries * PCI_MSIX_ENTRY_SIZE > MSIX_EXCLUSIVE_BAR_PBA_OFFSET) {
|
|
|
8be556 |
- return -EINVAL;
|
|
|
8be556 |
+ if (bar_pba_offset + bar_pba_size > 4096) {
|
|
|
8be556 |
+ bar_size = bar_pba_offset + bar_pba_size;
|
|
|
8be556 |
+ }
|
|
|
8be556 |
+
|
|
|
8be556 |
+ if (bar_size & (bar_size - 1)) {
|
|
|
8be556 |
+ bar_size = 1 << qemu_fls(bar_size);
|
|
|
8be556 |
}
|
|
|
8be556 |
|
|
|
8be556 |
name = g_strdup_printf("%s-msix", dev->name);
|
|
|
8be556 |
- memory_region_init(&dev->msix_exclusive_bar, OBJECT(dev), name, MSIX_EXCLUSIVE_BAR_SIZE);
|
|
|
8be556 |
+ memory_region_init(&dev->msix_exclusive_bar, OBJECT(dev), name, bar_size);
|
|
|
8be556 |
g_free(name);
|
|
|
8be556 |
|
|
|
8be556 |
ret = msix_init(dev, nentries, &dev->msix_exclusive_bar, bar_nr,
|
|
|
8be556 |
- MSIX_EXCLUSIVE_BAR_TABLE_OFFSET, &dev->msix_exclusive_bar,
|
|
|
8be556 |
- bar_nr, MSIX_EXCLUSIVE_BAR_PBA_OFFSET,
|
|
|
8be556 |
- MSIX_EXCLUSIVE_CAP_OFFSET);
|
|
|
8be556 |
+ 0, &dev->msix_exclusive_bar,
|
|
|
8be556 |
+ bar_nr, bar_pba_offset,
|
|
|
8be556 |
+ 0);
|
|
|
8be556 |
if (ret) {
|
|
|
8be556 |
return ret;
|
|
|
8be556 |
}
|
|
|
8be556 |
--
|
|
|
8be556 |
1.8.3.1
|
|
|
8be556 |
|