From: George Dunlap <george.dunlap@eu.citrix.com>
To: xen-devel@lists.xen.org
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
Ian Jackson <ian.jackson@citrix.com>,
Stefano Stabellini <stefano.stabellini@citrix.com>,
Ian Campbell <ian.campbell@citrix.com>,
Hanweidong <hanweidong@huawei.com>
Subject: [PATCH v2 5/5] libxl, hvmloader: Don't relocate memory for MMIO hole
Date: Tue, 18 Jun 2013 17:46:24 +0100 [thread overview]
Message-ID: <1371573984-28514-5-git-send-email-george.dunlap@eu.citrix.com> (raw)
In-Reply-To: <1371573984-28514-1-git-send-email-george.dunlap@eu.citrix.com>
At the moment, qemu-xen can't handle memory being relocated by
hvmloader. This may happen if a device with a large enough memory
region is passed through to the guest. At the moment, if this
happens, then at some point in the future qemu will crash and the
domain will hang. (qemu-traditional is fine.)
It's too late in the release to do a proper fix, so we try to do
damage control.
hvmloader already has mechanisms to relocate memory to 64-bit space
if it can't make a big enough MMIO hole. By default this is 2GiB; if
we just refuse to make the hole bigger if it will overlap with guest
memory, then the relocation will happen by default.
v2:
- style fixes
- fix and expand comment on the MMIO hole loop
- use "%d" rather than "%s" -> (...)?"1":"0"
- use bool instead of uint8_t
- Move 64-bit bar relocate detection to another patch
- Add more diagnostic messages
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
CC: Ian Campbell <ian.campbell@citrix.com>
CC: Ian Jackson <ian.jackson@citrix.com>
CC: Stefano Stabellini <stefano.stabellini@citrix.com>
CC: Hanweidong <hanweidong@huawei.com>
---
tools/firmware/hvmloader/pci.c | 41 ++++++++++++++++++++++++++++---
tools/libxl/libxl_dm.c | 6 +++++
xen/include/public/hvm/hvm_xs_strings.h | 1 +
3 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
index 63d79a2..1ab5124 100644
--- a/tools/firmware/hvmloader/pci.c
+++ b/tools/firmware/hvmloader/pci.c
@@ -27,6 +27,8 @@
#include <xen/memory.h>
#include <xen/hvm/ioreq.h>
+#include <xen/hvm/hvm_xs_strings.h>
+#include <stdbool.h>
unsigned long pci_mem_start = PCI_MEM_START;
unsigned long pci_mem_end = PCI_MEM_END;
@@ -58,6 +60,15 @@ void pci_setup(void)
} *bars = (struct bars *)scratch_start;
unsigned int i, nr_bars = 0;
+ const char *s;
+ bool allow_memory_relocate = 1;
+
+ s = xenstore_read(HVM_XS_ALLOW_MEMORY_RELOCATE, NULL);
+ if ( s )
+ allow_memory_relocate = (bool)strtoll(s, NULL, 0);
+ printf("Relocating guest memory for lowmem MMIO space %s\n",
+ allow_memory_relocate?"enabled":"disabled");
+
/* Program PCI-ISA bridge with appropriate link routes. */
isa_irq = 0;
for ( link = 0; link < 4; link++ )
@@ -209,14 +220,38 @@ void pci_setup(void)
pci_writew(devfn, PCI_COMMAND, cmd);
}
- while ( (mmio_total > (pci_mem_end - pci_mem_start)) &&
- ((pci_mem_start << 1) != 0) )
+ /*
+ * At the moment qemu-xen can't deal with relocated memory regions.
+ * It's too close to the release to make a proper fix; for now,
+ * only allow the MMIO hole to grow large enough to move guest memory
+ * if we're running qemu-traditional. Items that don't fit will be
+ * relocated into the 64-bit address space.
+ *
+ * This loop now does the following:
+ * - If allow_memory_relocate, increase the MMIO hole until it's
+ * big enough, or until it's 2GiB
+ * - If !allow_memory_relocate, increase the MMIO hole until it's
+ * big enough, or until it's 2GiB, or until it overlaps guest
+ * memory
+ */
+ while ( (mmio_total > (pci_mem_end - pci_mem_start))
+ && ((pci_mem_start << 1) != 0)
+ && (allow_memory_relocate
+ || (((pci_mem_start << 1) >> PAGE_SHIFT)
+ < hvm_info->low_mem_pgend)) )
pci_mem_start <<= 1;
- if ( mmio_total > (pci_mem_end - pci_mem_start) )
+ if ( mmio_total > (pci_mem_end - pci_mem_start) ) {
+ printf("<4GiB MMIO hole not large enough,"
+ " relocating some BARs to 64-bit\n");
bar64_relocate = 1;
+ }
/* Relocate RAM that overlaps PCI space (in 64k-page chunks). */
+ if ( (pci_mem_start >> PAGE_SHIFT) < hvm_info->low_mem_pgend )
+ printf("Relocating 0x%lx pages to highmem for lowmem MMIO hole\n",
+ hvm_info->low_mem_pgend - (pci_mem_start >> PAGE_SHIFT));
+
while ( (pci_mem_start >> PAGE_SHIFT) < hvm_info->low_mem_pgend )
{
struct xen_add_to_physmap xatp;
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index ac1f90e..342d2ce 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -1154,6 +1154,12 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
libxl__xs_write(gc, XBT_NULL,
libxl__sprintf(gc, "%s/hvmloader/bios", path),
"%s", libxl_bios_type_to_string(b_info->u.hvm.bios));
+ /* Disable relocating memory to make the MMIO hole larger
+ * unless we're running qemu-traditional */
+ libxl__xs_write(gc, XBT_NULL,
+ libxl__sprintf(gc, "%s/hvmloader/allow-memory-relocate", path),
+ "%d",
+ b_info->device_model_version==LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL);
free(path);
}
diff --git a/xen/include/public/hvm/hvm_xs_strings.h b/xen/include/public/hvm/hvm_xs_strings.h
index 9042303..4de5881 100644
--- a/xen/include/public/hvm/hvm_xs_strings.h
+++ b/xen/include/public/hvm/hvm_xs_strings.h
@@ -28,6 +28,7 @@
#define HVM_XS_HVMLOADER "hvmloader"
#define HVM_XS_BIOS "hvmloader/bios"
#define HVM_XS_GENERATION_ID_ADDRESS "hvmloader/generation-id-address"
+#define HVM_XS_ALLOW_MEMORY_RELOCATE "hvmloader/allow-memory-relocate"
/* The following values allow additional ACPI tables to be added to the
* virtual ACPI BIOS that hvmloader constructs. The values specify the guest
--
1.7.9.5
next prev parent reply other threads:[~2013-06-18 16:46 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-18 16:46 [PATCH v2 1/5] hvmloader: Correct bug in low mmio region accounting George Dunlap
2013-06-18 16:46 ` [PATCH v2 2/5] hvmloader: Load large devices into high MMIO space as needed George Dunlap
2013-06-19 17:18 ` Stefano Stabellini
2013-06-20 9:23 ` George Dunlap
2013-06-20 9:47 ` Jan Beulich
2013-06-18 16:46 ` [PATCH v2 3/5] hvmloader: Remove minimum size for BARs to relocate to 64-bit space George Dunlap
2013-06-19 17:18 ` Stefano Stabellini
2013-06-19 21:14 ` Wei Liu
2013-06-20 9:01 ` George Dunlap
2013-06-20 9:48 ` Jan Beulich
2013-06-18 16:46 ` [PATCH v2 4/5] hvmloader: Fix check for needing a 64-bit bar George Dunlap
2013-06-19 17:18 ` Stefano Stabellini
2013-06-20 10:01 ` Jan Beulich
2013-06-20 10:21 ` George Dunlap
2013-06-18 16:46 ` George Dunlap [this message]
2013-06-18 17:16 ` [PATCH v2 5/5] libxl, hvmloader: Don't relocate memory for MMIO hole George Dunlap
2013-06-19 17:18 ` Stefano Stabellini
2013-06-20 9:22 ` George Dunlap
2013-06-20 10:12 ` Jan Beulich
2013-06-20 10:20 ` George Dunlap
2013-06-20 10:29 ` Stefano Stabellini
2013-06-20 10:56 ` Jan Beulich
2013-06-20 10:59 ` George Dunlap
2013-06-20 11:01 ` George Dunlap
2013-06-20 13:35 ` Ian Jackson
2013-06-20 14:06 ` George Dunlap
2013-06-20 10:37 ` Ian Jackson
2013-06-20 10:44 ` George Dunlap
2013-06-20 10:52 ` Jan Beulich
2013-06-20 10:49 ` Stefano Stabellini
2013-06-25 9:56 ` Ian Campbell
2013-06-25 10:15 ` George Dunlap
2013-06-18 16:53 ` [PATCH v2 1/5] hvmloader: Correct bug in low mmio region accounting George Dunlap
2013-06-19 17:18 ` Stefano Stabellini
2013-06-20 8:56 ` George Dunlap
2013-06-20 10:40 ` Stefano Stabellini
2013-06-20 10:43 ` George Dunlap
2013-06-20 9:36 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1371573984-28514-5-git-send-email-george.dunlap@eu.citrix.com \
--to=george.dunlap@eu.citrix.com \
--cc=hanweidong@huawei.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@citrix.com \
--cc=stefano.stabellini@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).