All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 for-4.11] libxl: fix memory map reported to PVH guests
@ 2018-04-20 14:57 Roger Pau Monne
  2018-04-20 15:00 ` Juergen Gross
  2018-04-23  8:34 ` Wei Liu
  0 siblings, 2 replies; 3+ messages in thread
From: Roger Pau Monne @ 2018-04-20 14:57 UTC (permalink / raw)
  To: xen-devel; +Cc: Juergen Gross, Wei Liu, Ian Jackson, Roger Pau Monne

PVH guests with 4GB of RAM or more get a memory map like the
following:

0x00000000000000 - 0x000000fee00000 RAM
0x000000fee00000 - 0x00000100000000 RESERVED
0x000000fc009000 - 0x000000fc009040 ACPI
0x000000fc000000 - 0x000000fc001000 ACPI
0x000000fc001000 - 0x000000fc009000 ACPI
0x00000100000000 - 0x000001fb200400 RAM

This is wrong because ACPI regions overlap with RAM regions. The cause
of this issue is not setting a big enough MMIO hole and marking the
whole MMIO hole as reserved, when it actually contains several pieces:

 - local APIC page.
 - ACPI tables.
 - HVM special pages.

Of those items only HVM special pages need to be marked as reserved in
order to advise the guest against using them for example for memory
hotplug.

After the fix the layout reported for the same guest is:

0x00000000000000 - 0x000000fc000000 RAM
0x000000feff8000 - 0x000000ff000000 RESERVED
0x000000fc009000 - 0x000000fc009040 ACPI
0x000000fc000000 - 0x000000fc001000 ACPI
0x000000fc001000 - 0x000000fc009000 ACPI
0x00000100000000 - 0x000001fe000400 RAM

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Juergen Gross <jgross@suse.com>
---
Changes since v1:
 - Only mark HVM special pages as reserved, in order to avoid overlap
   of the memory map regions.
---
 tools/libxl/libxl_arch.h     |  1 +
 tools/libxl/libxl_dom.c      | 20 +++++++++++---------
 tools/libxl/libxl_x86.c      | 13 +++++++------
 tools/libxl/libxl_x86_acpi.c |  1 -
 4 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index 318c111bb4..74a5af3cf3 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -76,6 +76,7 @@ int libxl__arch_extra_memory(libxl__gc *gc,
 #if defined(__i386__) || defined(__x86_64__)
 
 #define LAPIC_BASE_ADDRESS  0xfee00000
+#define ACPI_INFO_PHYSICAL_ADDRESS 0xfc000000
 
 int libxl__dom_load_acpi(libxl__gc *gc,
                          const libxl_domain_build_info *b_info,
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 8c3607b0f5..f0fd5fd3a3 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -1229,15 +1229,17 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
         dom->mmio_size = HVM_BELOW_4G_MMIO_LENGTH;
     else if (dom->mmio_size == 0 && !device_model) {
 #if defined(__i386__) || defined(__x86_64__)
-        if (libxl_defbool_val(info->apic)) {
-            /* Make sure LAPIC_BASE_ADDRESS is below special pages */
-            assert(((((X86_HVM_END_SPECIAL_REGION - X86_HVM_NR_SPECIAL_PAGES)
-                      << XC_PAGE_SHIFT) - LAPIC_BASE_ADDRESS)) >= XC_PAGE_SIZE);
-            dom->mmio_size = GB(4) - LAPIC_BASE_ADDRESS;
-        } else
-            dom->mmio_size = GB(4) -
-                ((X86_HVM_END_SPECIAL_REGION - X86_HVM_NR_SPECIAL_PAGES)
-                 << XC_PAGE_SHIFT);
+        /*
+         * Make sure the local APIC page, the ACPI tables and the special pages
+         * are inside the MMIO hole.
+         */
+        xen_paddr_t start =
+            (X86_HVM_END_SPECIAL_REGION - X86_HVM_NR_SPECIAL_PAGES) <<
+            XC_PAGE_SHIFT;
+
+        start = min_t(xen_paddr_t, start, LAPIC_BASE_ADDRESS);
+        start = min_t(xen_paddr_t, start, ACPI_INFO_PHYSICAL_ADDRESS);
+        dom->mmio_size = GB(4) - start;
 #else
         assert(1);
 #endif
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index 4573d6764d..ab88562619 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -512,8 +512,8 @@ static int domain_construct_memmap(libxl__gc *gc,
         if (d_config->rdms[i].policy != LIBXL_RDM_RESERVE_POLICY_INVALID)
             e820_entries++;
 
-    /* Add mmio entry for PVH. */
-    if (dom->mmio_size && d_config->b_info.type == LIBXL_DOMAIN_TYPE_PVH)
+    /* Add the HVM special pages to PVH memmap as RESERVED. */
+    if (d_config->b_info.type == LIBXL_DOMAIN_TYPE_PVH)
         e820_entries++;
 
     /* If we should have a highmem range. */
@@ -549,10 +549,11 @@ static int domain_construct_memmap(libxl__gc *gc,
         nr++;
     }
 
-    /* mmio area */
-    if (dom->mmio_size && d_config->b_info.type == LIBXL_DOMAIN_TYPE_PVH) {
-        e820[nr].addr = dom->mmio_start;
-        e820[nr].size = dom->mmio_size;
+    /* HVM special pages */
+    if (d_config->b_info.type == LIBXL_DOMAIN_TYPE_PVH) {
+        e820[nr].addr = (X86_HVM_END_SPECIAL_REGION - X86_HVM_NR_SPECIAL_PAGES)
+                        << XC_PAGE_SHIFT;
+        e820[nr].size = X86_HVM_NR_SPECIAL_PAGES << XC_PAGE_SHIFT;
         e820[nr].type = E820_RESERVED;
         nr++;
     }
diff --git a/tools/libxl/libxl_x86_acpi.c b/tools/libxl/libxl_x86_acpi.c
index 143ce66644..ed6610c84e 100644
--- a/tools/libxl/libxl_x86_acpi.c
+++ b/tools/libxl/libxl_x86_acpi.c
@@ -22,7 +22,6 @@
 
  /* Number of pages holding ACPI tables */
 #define NUM_ACPI_PAGES 16
-#define ACPI_INFO_PHYSICAL_ADDRESS 0xfc000000
 
 struct libxl_acpi_ctxt {
     struct acpi_ctxt c;
-- 
2.17.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 for-4.11] libxl: fix memory map reported to PVH guests
  2018-04-20 14:57 [PATCH v2 for-4.11] libxl: fix memory map reported to PVH guests Roger Pau Monne
@ 2018-04-20 15:00 ` Juergen Gross
  2018-04-23  8:34 ` Wei Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Juergen Gross @ 2018-04-20 15:00 UTC (permalink / raw)
  To: Roger Pau Monne, xen-devel; +Cc: Wei Liu, Ian Jackson

On 20/04/18 16:57, Roger Pau Monne wrote:
> PVH guests with 4GB of RAM or more get a memory map like the
> following:
> 
> 0x00000000000000 - 0x000000fee00000 RAM
> 0x000000fee00000 - 0x00000100000000 RESERVED
> 0x000000fc009000 - 0x000000fc009040 ACPI
> 0x000000fc000000 - 0x000000fc001000 ACPI
> 0x000000fc001000 - 0x000000fc009000 ACPI
> 0x00000100000000 - 0x000001fb200400 RAM
> 
> This is wrong because ACPI regions overlap with RAM regions. The cause
> of this issue is not setting a big enough MMIO hole and marking the
> whole MMIO hole as reserved, when it actually contains several pieces:
> 
>  - local APIC page.
>  - ACPI tables.
>  - HVM special pages.
> 
> Of those items only HVM special pages need to be marked as reserved in
> order to advise the guest against using them for example for memory
> hotplug.
> 
> After the fix the layout reported for the same guest is:
> 
> 0x00000000000000 - 0x000000fc000000 RAM
> 0x000000feff8000 - 0x000000ff000000 RESERVED
> 0x000000fc009000 - 0x000000fc009040 ACPI
> 0x000000fc000000 - 0x000000fc001000 ACPI
> 0x000000fc001000 - 0x000000fc009000 ACPI
> 0x00000100000000 - 0x000001fe000400 RAM
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

You could have kept my Rab.

Release-acked-by: Juergen Gross <jgross@suse.com>


Juergen

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 for-4.11] libxl: fix memory map reported to PVH guests
  2018-04-20 14:57 [PATCH v2 for-4.11] libxl: fix memory map reported to PVH guests Roger Pau Monne
  2018-04-20 15:00 ` Juergen Gross
@ 2018-04-23  8:34 ` Wei Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Wei Liu @ 2018-04-23  8:34 UTC (permalink / raw)
  To: Roger Pau Monne; +Cc: Juergen Gross, xen-devel, Ian Jackson, Wei Liu

On Fri, Apr 20, 2018 at 03:57:19PM +0100, Roger Pau Monne wrote:
> PVH guests with 4GB of RAM or more get a memory map like the
> following:
> 
> 0x00000000000000 - 0x000000fee00000 RAM
> 0x000000fee00000 - 0x00000100000000 RESERVED
> 0x000000fc009000 - 0x000000fc009040 ACPI
> 0x000000fc000000 - 0x000000fc001000 ACPI
> 0x000000fc001000 - 0x000000fc009000 ACPI
> 0x00000100000000 - 0x000001fb200400 RAM
> 
> This is wrong because ACPI regions overlap with RAM regions. The cause
> of this issue is not setting a big enough MMIO hole and marking the
> whole MMIO hole as reserved, when it actually contains several pieces:
> 
>  - local APIC page.
>  - ACPI tables.
>  - HVM special pages.
> 
> Of those items only HVM special pages need to be marked as reserved in
> order to advise the guest against using them for example for memory
> hotplug.
> 
> After the fix the layout reported for the same guest is:
> 
> 0x00000000000000 - 0x000000fc000000 RAM
> 0x000000feff8000 - 0x000000ff000000 RESERVED
> 0x000000fc009000 - 0x000000fc009040 ACPI
> 0x000000fc000000 - 0x000000fc001000 ACPI
> 0x000000fc001000 - 0x000000fc009000 ACPI
> 0x00000100000000 - 0x000001fe000400 RAM
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>


Acked-by: Wei Liu <wei.liu2@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-23  8:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-20 14:57 [PATCH v2 for-4.11] libxl: fix memory map reported to PVH guests Roger Pau Monne
2018-04-20 15:00 ` Juergen Gross
2018-04-23  8:34 ` Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.