Skip to contentSkip to conversation

PPC: sPAPR: Only use getpagesize() when we run with kvm

PATCH In review Alexander Graf 2 participants 5 messages Feb 21, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PPC: sPAPR: Only use getpagesize() when we run with kvm

We currently size the msi window trap page according to the host's page size so that we poke a working hole into a memory slot in case we overlap.

However, this is only ever necessary with KVM active. Without KVM, we should rather try to be host platform agnostic and use a constant size: 4k.

This fixes a build breakage on win32 hosts.

---
 hw/ppc/spapr_pci.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
hw/ppc/spapr_pci.c +10 -1
index 66ddf10..a3af75c 100644
@@ -469,6 +469,8 @@ static const MemoryRegionOps spapr_msi_ops = {
 
 void spapr_pci_msi_init(sPAPREnvironment *spapr, hwaddr addr)
 {
+    uint64_t window_size = 4096;
+
     /*
      * As MSI/MSIX interrupts trigger by writing at MSI/MSIX vectors,
      * we need to allocate some memory to catch those writes coming
@@ -476,10 +478,17 @@ void spapr_pci_msi_init(sPAPREnvironment *spapr, hwaddr addr)
      * As MSIMessage:addr is going to be the same and MSIMessage:data
      * is going to be a VIRQ number, 4 bytes of the MSI MR will only
      * be used.
+     *
+     * For KVM we want to ensure that this memory is a full page so that
+     * our memory slot is of page size granularity.
      */
+    if (kvm_enabled()) {
+        window_size = getpagesize();
+    }
+
     spapr->msi_win_addr = addr;
     memory_region_init_io(&spapr->msiwindow, NULL, &spapr_msi_ops, spapr,
-                          "msi", getpagesize());
+                          "msi", window_size);
     memory_region_add_subregion(get_system_memory(), spapr->msi_win_addr,
                                 &spapr->msiwindow);
 }
Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 7 lines · Alexander Graf

We currently size the msi window trap page according to the host's page size so that we poke a working hole into a memory slot in case we overlap.

However, this is only ever necessary with KVM active. Without KVM, we should rather try to be host platform agnostic and use a constant size: 4k.

This fixes a build breakage on win32 hosts.

Unfortunately it doesn't:

cam-vm-266:precise:qemu$ make -C build/w32
make: Entering directory `/home/petmay01/linaro/qemu-from-laptop/qemu/build/w32'
CC ppc64-softmmu/hw/ppc/spapr_pci.o
cc1: warnings being treated as errors /home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c: In function ‘spapr_pci_msi_init’:
/home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c:486:
warning: implicit declaration of function ‘getpagesize’ /home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c:486:
warning: nested extern declaration of ‘getpagesize’

The compiler complains that there's no declaration of the function you're trying to call before it gets around to deciding whether it can eliminate the code as unreachable.

thanks
-- PMM

#2 lore raw
Quoted 22 lines · Peter Maydell
Quoted 7 lines · Alexander Graf

We currently size the msi window trap page according to the host's page size so that we poke a working hole into a memory slot in case we overlap.

However, this is only ever necessary with KVM active. Without KVM, we should rather try to be host platform agnostic and use a constant size: 4k.

This fixes a build breakage on win32 hosts.

Unfortunately it doesn't:

cam-vm-266:precise:qemu$ make -C build/w32
make: Entering directory `/home/petmay01/linaro/qemu-from-laptop/qemu/build/w32'
CC ppc64-softmmu/hw/ppc/spapr_pci.o
cc1: warnings being treated as errors /home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c: In function ‘spapr_pci_msi_init’:
/home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c:486:
warning: implicit declaration of function ‘getpagesize’ /home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c:486:
warning: nested extern declaration of ‘getpagesize’

Quoted 4 lines

The compiler complains that there's no declaration of the function you're trying to call before it gets around to deciding whether it can eliminate the code as unreachable.

Meh. How about this?

Alex

hw/ppc/spapr_pci.c +12 -1
index 66ddf10..5f302ba 100644
@@ -469,6 +469,8 @@ static const MemoryRegionOps spapr_msi_ops = {
 
 void spapr_pci_msi_init(sPAPREnvironment *spapr, hwaddr addr)
 {
+    uint64_t window_size = 4096;
+
     /*
      * As MSI/MSIX interrupts trigger by writing at MSI/MSIX vectors,
      * we need to allocate some memory to catch those writes coming
@@ -476,10 +478,19 @@ void spapr_pci_msi_init(sPAPREnvironment *spapr, hwaddr addr)
      * As MSIMessage:addr is going to be the same and MSIMessage:data
      * is going to be a VIRQ number, 4 bytes of the MSI MR will only
      * be used.
+     *
+     * For KVM we want to ensure that this memory is a full page so that
+     * our memory slot is of page size granularity.
      */
+#ifdef CONFIG_KVM
+    if (kvm_enabled()) {
+        window_size = getpagesize();
+    }
+#endif
+
     spapr->msi_win_addr = addr;
     memory_region_init_io(&spapr->msiwindow, NULL, &spapr_msi_ops, spapr,
-                          "msi", getpagesize());
+                          "msi", window_size);
     memory_region_add_subregion(get_system_memory(), spapr->msi_win_addr,
                                 &spapr->msiwindow);
 }
#3 lore raw
Quoted 19 lines · Alexander Graf
Quoted 16 lines · Peter Maydell
Quoted 1 line · Alexander Graf

This fixes a build breakage on win32 hosts.

Unfortunately it doesn't:

cam-vm-266:precise:qemu$ make -C build/w32
make: Entering directory `/home/petmay01/linaro/qemu-from-laptop/qemu/build/w32'
CC ppc64-softmmu/hw/ppc/spapr_pci.o
cc1: warnings being treated as errors /home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c: In function ‘spapr_pci_msi_init’:
/home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c:486:
warning: implicit declaration of function ‘getpagesize’ /home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c:486:
warning: nested extern declaration of ‘getpagesize’

Quoted 6 lines
Quoted 4 lines

The compiler complains that there's no declaration of the function you're trying to call before it gets around to deciding whether it can eliminate the code as unreachable.

Meh. How about this?

Yep, CONFIG_KVM is a sufficiently big hammer to fix this :-)

thanks
-- PMM

#4 lore raw
Quoted 24 lines

Am 21.02.2014 um 11:56 schrieb Peter Maydell <[email protected]>:

Quoted 20 lines · Alexander Graf
Quoted 19 lines · Peter Maydell
Quoted 3 lines · Alexander Graf

This fixes a build breakage on win32 hosts.

Unfortunately it doesn't:

cam-vm-266:precise:qemu$ make -C build/w32
make: Entering directory `/home/petmay01/linaro/qemu-from-laptop/qemu/build/w32'
CC ppc64-softmmu/hw/ppc/spapr_pci.o
cc1: warnings being treated as errors /home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c: In function �espapr_pci_msi_init�f:
/home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c:486:
warning: implicit declaration of function �egetpagesize�f /home/petmay01/linaro/qemu-from-laptop/qemu/hw/ppc/spapr_pci.c:486:
warning: nested extern declaration of �egetpagesize�f

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

The compiler complains that there's no declaration of the function you're trying to call before it gets around to deciding whether it can eliminate the code as unreachable.

Meh. How about this?

Yep, CONFIG_KVM is a sufficiently big hammer to fix this :-)

Awesome. Queued to ppc-next.

Alex

Quoted 3 lines

thanks
-- PMM