[Patch V6 15/16] xen: allow more than 512 GB of RAM for 64 bit pv-domains

2015-07-16 Thread Juergen Gross
64 bit pv-domains under Xen are limited to 512 GB of RAM today. The
main reason has been the 3 level p2m tree, which was replaced by the
virtual mapped linear p2m list. Parallel to the p2m list which is
being used by the kernel itself there is a 3 level mfn tree for usage
by the Xen tools and eventually for crash dump analysis. For this tree
the linear p2m list can serve as a replacement, too. As the kernel
can't know whether the tools are capable of dealing with the p2m list
instead of the mfn tree, the limit of 512 GB can't be dropped in all
cases.

This patch replaces the hard limit by a kernel parameter which tells
the kernel to obey the 512 GB limit or not. The default is selected by
a configuration parameter which specifies whether the 512 GB limit
should be active per default for domUs (domain save/restore/migration
and crash dump analysis are affected).

Memory above the domain limit is returned to the hypervisor instead of
being identity mapped, which was wrong anyway.

The kernel configuration parameter to specify the maximum size of a
domain can be deleted, as it is not relevant any more.

Signed-off-by: Juergen Gross 
Acked-by: Konrad Rzeszutek Wilk 
---
 Documentation/kernel-parameters.txt |  7 +
 arch/x86/include/asm/xen/page.h |  4 ---
 arch/x86/xen/Kconfig| 20 -
 arch/x86/xen/p2m.c  | 10 +++
 arch/x86/xen/setup.c| 59 +++--
 5 files changed, 73 insertions(+), 27 deletions(-)

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index 1d6f045..47f7b98 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -4078,6 +4078,13 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
plus one apbt timer for broadcast timer.
x86_intel_mid_timer=apbt_only | lapic_and_apbt
 
+   xen_512gb_limit [KNL,X86-64,XEN]
+   Restricts the kernel running paravirtualized under Xen
+   to use only up to 512 GB of RAM. The reason to do so is
+   crash analysis tools and Xen tools for doing domain
+   save/restore/migration must be enabled to handle larger
+   domains.
+
xen_emul_unplug=[HW,X86,XEN]
Unplug Xen emulated devices
Format: [unplug0,][unplug1]
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index c44a5d5..10ef14b 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -35,10 +35,6 @@ typedef struct xpaddr {
 #define FOREIGN_FRAME(m)   ((m) | FOREIGN_FRAME_BIT)
 #define IDENTITY_FRAME(m)  ((m) | IDENTITY_FRAME_BIT)
 
-/* Maximum amount of memory we can handle in a domain in pages */
-#define MAX_DOMAIN_PAGES   \
-((unsigned long)((u64)CONFIG_XEN_MAX_DOMAIN_MEMORY * 1024 * 1024 * 1024 / 
PAGE_SIZE))
-
 extern unsigned long *machine_to_phys_mapping;
 extern unsigned long  machine_to_phys_nr;
 extern unsigned long *xen_p2m_addr;
diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
index e88fda8..7bcf21b 100644
--- a/arch/x86/xen/Kconfig
+++ b/arch/x86/xen/Kconfig
@@ -23,14 +23,18 @@ config XEN_PVHVM
def_bool y
depends on XEN && PCI && X86_LOCAL_APIC
 
-config XEN_MAX_DOMAIN_MEMORY
-   int
-   default 500 if X86_64
-   default 64 if X86_32
-   depends on XEN
-   help
- This only affects the sizing of some bss arrays, the unused
- portions of which are freed.
+config XEN_512GB
+   bool "Limit Xen pv-domain memory to 512GB"
+   depends on XEN && X86_64
+   default y
+   help
+ Limit paravirtualized user domains to 512GB of RAM.
+
+ The Xen tools and crash dump analysis tools might not support
+ pv-domains with more than 512 GB of RAM. This option controls the
+ default setting of the kernel to use only up to 512 GB or more.
+ It is always possible to change the default via specifying the
+ boot parameter "xen_512gb_limit".
 
 config XEN_SAVE_RESTORE
bool
diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c
index c719f7c..c059ca1c8 100644
--- a/arch/x86/xen/p2m.c
+++ b/arch/x86/xen/p2m.c
@@ -517,7 +517,7 @@ static pte_t *alloc_p2m_pmd(unsigned long addr, pte_t 
*pte_pg)
  */
 static bool alloc_p2m(unsigned long pfn)
 {
-   unsigned topidx, mididx;
+   unsigned topidx;
unsigned long *top_mfn_p, *mid_mfn;
pte_t *ptep, *pte_pg;
unsigned int level;
@@ -525,9 +525,6 @@ static bool alloc_p2m(unsigned long pfn)
unsigned long addr = (unsigned long)(xen_p2m_addr + pfn);
unsigned long p2m_pfn;
 
-   topidx = p2m_top_index(pfn);
-   mididx = p2m_mid_index(pfn);
-
ptep = lookup_address(addr, );
   

[Patch V6 15/16] xen: allow more than 512 GB of RAM for 64 bit pv-domains

2015-07-16 Thread Juergen Gross
64 bit pv-domains under Xen are limited to 512 GB of RAM today. The
main reason has been the 3 level p2m tree, which was replaced by the
virtual mapped linear p2m list. Parallel to the p2m list which is
being used by the kernel itself there is a 3 level mfn tree for usage
by the Xen tools and eventually for crash dump analysis. For this tree
the linear p2m list can serve as a replacement, too. As the kernel
can't know whether the tools are capable of dealing with the p2m list
instead of the mfn tree, the limit of 512 GB can't be dropped in all
cases.

This patch replaces the hard limit by a kernel parameter which tells
the kernel to obey the 512 GB limit or not. The default is selected by
a configuration parameter which specifies whether the 512 GB limit
should be active per default for domUs (domain save/restore/migration
and crash dump analysis are affected).

Memory above the domain limit is returned to the hypervisor instead of
being identity mapped, which was wrong anyway.

The kernel configuration parameter to specify the maximum size of a
domain can be deleted, as it is not relevant any more.

Signed-off-by: Juergen Gross jgr...@suse.com
Acked-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
---
 Documentation/kernel-parameters.txt |  7 +
 arch/x86/include/asm/xen/page.h |  4 ---
 arch/x86/xen/Kconfig| 20 -
 arch/x86/xen/p2m.c  | 10 +++
 arch/x86/xen/setup.c| 59 +++--
 5 files changed, 73 insertions(+), 27 deletions(-)

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index 1d6f045..47f7b98 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -4078,6 +4078,13 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
plus one apbt timer for broadcast timer.
x86_intel_mid_timer=apbt_only | lapic_and_apbt
 
+   xen_512gb_limit [KNL,X86-64,XEN]
+   Restricts the kernel running paravirtualized under Xen
+   to use only up to 512 GB of RAM. The reason to do so is
+   crash analysis tools and Xen tools for doing domain
+   save/restore/migration must be enabled to handle larger
+   domains.
+
xen_emul_unplug=[HW,X86,XEN]
Unplug Xen emulated devices
Format: [unplug0,][unplug1]
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index c44a5d5..10ef14b 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -35,10 +35,6 @@ typedef struct xpaddr {
 #define FOREIGN_FRAME(m)   ((m) | FOREIGN_FRAME_BIT)
 #define IDENTITY_FRAME(m)  ((m) | IDENTITY_FRAME_BIT)
 
-/* Maximum amount of memory we can handle in a domain in pages */
-#define MAX_DOMAIN_PAGES   \
-((unsigned long)((u64)CONFIG_XEN_MAX_DOMAIN_MEMORY * 1024 * 1024 * 1024 / 
PAGE_SIZE))
-
 extern unsigned long *machine_to_phys_mapping;
 extern unsigned long  machine_to_phys_nr;
 extern unsigned long *xen_p2m_addr;
diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
index e88fda8..7bcf21b 100644
--- a/arch/x86/xen/Kconfig
+++ b/arch/x86/xen/Kconfig
@@ -23,14 +23,18 @@ config XEN_PVHVM
def_bool y
depends on XEN  PCI  X86_LOCAL_APIC
 
-config XEN_MAX_DOMAIN_MEMORY
-   int
-   default 500 if X86_64
-   default 64 if X86_32
-   depends on XEN
-   help
- This only affects the sizing of some bss arrays, the unused
- portions of which are freed.
+config XEN_512GB
+   bool Limit Xen pv-domain memory to 512GB
+   depends on XEN  X86_64
+   default y
+   help
+ Limit paravirtualized user domains to 512GB of RAM.
+
+ The Xen tools and crash dump analysis tools might not support
+ pv-domains with more than 512 GB of RAM. This option controls the
+ default setting of the kernel to use only up to 512 GB or more.
+ It is always possible to change the default via specifying the
+ boot parameter xen_512gb_limit.
 
 config XEN_SAVE_RESTORE
bool
diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c
index c719f7c..c059ca1c8 100644
--- a/arch/x86/xen/p2m.c
+++ b/arch/x86/xen/p2m.c
@@ -517,7 +517,7 @@ static pte_t *alloc_p2m_pmd(unsigned long addr, pte_t 
*pte_pg)
  */
 static bool alloc_p2m(unsigned long pfn)
 {
-   unsigned topidx, mididx;
+   unsigned topidx;
unsigned long *top_mfn_p, *mid_mfn;
pte_t *ptep, *pte_pg;
unsigned int level;
@@ -525,9 +525,6 @@ static bool alloc_p2m(unsigned long pfn)
unsigned long addr = (unsigned long)(xen_p2m_addr + pfn);
unsigned long p2m_pfn;
 
-   topidx = p2m_top_index(pfn);
-   mididx = p2m_mid_index(pfn);
-
ptep =