Skip to contentSkip to conversation

xen: Switch to virtual mapped linear p2m list

PATCH Superseded Juergen Gross 4 participants 18 messages Oct 27, 2014 – Oct 29, 2014

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Juergen Gross

author maintainer
#0 lore raw

cover xen: Switch to virtual mapped linear p2m list

Paravirtualized kernels running on Xen use a three level tree for translation of guest specific physical addresses to machine global addresses. This p2m tree is used for construction of page table entries, so the p2m tree walk is performance critical.

By using a linear virtual mapped p2m list accesses to p2m elements can be sped up while even simplifying code. To achieve this goal some p2m related initializations have to be performed later in the boot process, as the final p2m list can be set up only after basic memory management functions are available.

The first patch in this series modifies xen specific kernel initialization to be able to switch to the linear mapped p2m list introduced in the sewcond patch.

Juergen Gross (2):
Xen: Delay remapping memory of pv-domain
Xen: switch to linear virtual mapped sparse p2m list

 arch/x86/include/asm/pgtable_types.h |   1 +
 arch/x86/include/asm/xen/page.h      |  31 +-
 arch/x86/mm/pageattr.c               |  20 +
 arch/x86/xen/mmu.c                   |  38 +-
 arch/x86/xen/p2m.c                   | 986 +++++++++++++----------------------
 arch/x86/xen/setup.c                 | 455 ++++++++--------
 arch/x86/xen/xen-ops.h               |   6 +-
 7 files changed, 675 insertions(+), 862 deletions(-)
Signature · 1 line
1.8.4.5
author maintainer
#1 lore raw

PATCH 1/2 Xen: Delay remapping memory of pv-domain

Early in the boot process the memory layout of a pv-domain is changed to match the E820 map (either the host one for Dom0 or the Xen one) regarding placement of RAM and PCI holes. This requires removing memory pages initially located at positions not suitable for RAM and adding them later at higher addresses where no restrictions apply.

To be able to operate on the hypervisor supported p2m list until a virtual mapped linear p2m list can be constructed, remapping must be delayed until virtual memory management is initialized, as the initial p2m list can't be extended unlimited at physical memory initialization time due to it's fixed structure.

A further advantage is the reduction in complexity and code volume as we don't have to be careful regarding memory restrictions during p2m updates.

---
 arch/x86/include/asm/xen/page.h |   1 -
 arch/x86/xen/mmu.c              |   4 +
 arch/x86/xen/p2m.c              | 149 ++++------------
 arch/x86/xen/setup.c            | 382 +++++++++++++++++++---------------------
 arch/x86/xen/xen-ops.h          |   1 +
 5 files changed, 220 insertions(+), 317 deletions(-)
arch/x86/include/asm/xen/page.h +0 -1
index c949923..c29619c 100644
@@ -44,7 +44,6 @@ extern unsigned long  machine_to_phys_nr;
 
 extern unsigned long get_phys_to_machine(unsigned long pfn);
 extern bool set_phys_to_machine(unsigned long pfn, unsigned long mfn);
-extern bool __init early_set_phys_to_machine(unsigned long pfn, unsigned long mfn);
 extern bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
 extern unsigned long set_phys_range_identity(unsigned long pfn_s,
 					     unsigned long pfn_e);
arch/x86/xen/mmu.c +4 -0
index a8a1a3d..d3e492b 100644
@@ -1223,6 +1223,10 @@ static void __init xen_pagetable_init(void)
 	/* Allocate and initialize top and mid mfn levels for p2m structure */
 	xen_build_mfn_list_list();
 
+	/* Remap memory freed because of conflicts with E820 map */
+	if (!xen_feature(XENFEAT_auto_translated_physmap))
+		xen_remap_memory();
+
 	xen_setup_shared_info();
 	xen_post_allocator_init();
 }
arch/x86/xen/p2m.c +33 -116

237 lines not on this page · raw message

arch/x86/xen/setup.c +182 -200

504 lines not on this page · raw message

arch/x86/xen/xen-ops.h +1 -0
index 28c7e0b..5b72a06 100644
@@ -35,6 +35,7 @@ void xen_mm_pin_all(void);
 void xen_mm_unpin_all(void);
 void xen_set_pat(u64);
 
+void __init xen_remap_memory(void);
 char * __init xen_memory_setup(void);
 char * xen_auto_xlated_memory_setup(void);
 void __init xen_arch_setup(void);
Signature · 1 line
1.8.4.5
#2 lore raw

Re: [PATCH 1/2] Xen: Delay remapping memory of pv-domain

Can these patches be split up? They're hard to review as-is. e.g., the changes to page allocation look they could be split out.

Quoted 5 lines · Juergen Gross

Early in the boot process the memory layout of a pv-domain is changed to match the E820 map (either the host one for Dom0 or the Xen one) regarding placement of RAM and PCI holes. This requires removing memory pages initially located at positions not suitable for RAM and adding them later at higher addresses where no restrictions apply.

How does this impact Matt Rushton's recent change to ensure the relocated frames are contiguous?

The change was "xen/setup: Remap Xen Identity Mapped RAM" (4fbb67e3c87).

arch/x86/xen/setup.c static unsigned long __init xen_update_mem_tables(unsigned long pfn, · line 237

Quoted 6 lines
arch/x86/xen/setup.c +6 -0
+	/* Update kernel mapping */
+	if (HYPERVISOR_update_va_mapping((unsigned long)__va(pfn << PAGE_SHIFT),
+					 mfn_pte(mfn, PAGE_KERNEL), 0)) {
+		WARN(1, "Failed to update kernel mapping for mfn=%ld pfn=%ld\n",
+		      mfn, pfn);
+		return 0;

I think you need to check if this is a PFN for a high page before updating the mapping.

David

author maintainer
#3 lore raw

Re: [PATCH 1/2] Xen: Delay remapping memory of pv-domain

Quoted 4 lines · David Vrabel

Can these patches be split up? They're hard to review as-is. e.g., the changes to page allocation look they could be split out.

On 27/10/14 14:52, Juergen Gross wrote:

Quoted 8 lines
Quoted 5 lines

Early in the boot process the memory layout of a pv-domain is changed to match the E820 map (either the host one for Dom0 or the Xen one) regarding placement of RAM and PCI holes. This requires removing memory pages initially located at positions not suitable for RAM and adding them later at higher addresses where no restrictions apply.

How does this impact Matt Rushton's recent change to ensure the relocated frames are contiguous?

It is simplifying it. :-)

The relocated frames are in the same sequence as before, just at another location. As the remapping is done later, I don't have to be careful not to cross a p2m leaf page boundary (allocating a new leaf page is no problem now).

Quoted 12 lines

The change was "xen/setup: Remap Xen Identity Mapped RAM" (4fbb67e3c87).

arch/x86/xen/setup.c static unsigned long __init xen_update_mem_tables(unsigned long pfn, · line 237

Quoted 6 lines
arch/x86/xen/setup.c +6 -0
+	/* Update kernel mapping */
+	if (HYPERVISOR_update_va_mapping((unsigned long)__va(pfn << PAGE_SHIFT),
+					 mfn_pte(mfn, PAGE_KERNEL), 0)) {
+		WARN(1, "Failed to update kernel mapping for mfn=%ld pfn=%ld\n",
+		      mfn, pfn);
+		return 0;

I think you need to check if this is a PFN for a high page before updating the mapping.

Really? I'm not aware of having removed such a check. If it is really necessary it must have been missing before...

Juergen

author maintainer
#4 lore raw

Re: [PATCH 1/2] Xen: Delay remapping memory of pv-domain

Quoted 33 lines · Juergen Gross
Quoted 4 lines · David Vrabel

Can these patches be split up? They're hard to review as-is. e.g., the changes to page allocation look they could be split out.

On 27/10/14 14:52, Juergen Gross wrote:

Quoted 8 lines
Quoted 5 lines

Early in the boot process the memory layout of a pv-domain is changed to match the E820 map (either the host one for Dom0 or the Xen one) regarding placement of RAM and PCI holes. This requires removing memory pages initially located at positions not suitable for RAM and adding them later at higher addresses where no restrictions apply.

How does this impact Matt Rushton's recent change to ensure the relocated frames are contiguous?

It is simplifying it. :-)

The relocated frames are in the same sequence as before, just at another location. As the remapping is done later, I don't have to be careful not to cross a p2m leaf page boundary (allocating a new leaf page is no problem now).

Quoted 12 lines

The change was "xen/setup: Remap Xen Identity Mapped RAM" (4fbb67e3c87).

Quoted 8 lines
(quoted diff) +2 -0
+    /* Update kernel mapping */
+    if (HYPERVISOR_update_va_mapping((unsigned long)__va(pfn <<

PAGE_SHIFT),

(quoted diff) +2 -0
+                     mfn_pte(mfn, PAGE_KERNEL), 0)) {
+        WARN(1, "Failed to update kernel mapping for mfn=%ld

pfn=%ld\n",

arch/x86/xen/setup.c +2 -0
+              mfn, pfn);
+        return 0;
Quoted 5 lines
Quoted 2 lines

I think you need to check if this is a PFN for a high page before updating the mapping.

Really? I'm not aware of having removed such a check. If it is really necessary it must have been missing before...

Wait, now I see my fault: by doing the remapping later I've skipped the highmem check during adding the memory to the system. Okay, I'll update the patch.

Juergen

author maintainer
#5 lore raw

PATCH 2/2 Xen: switch to linear virtual mapped sparse p2m list

In reply to Juergen Gross

At start of the day the Xen hypervisor presents a contiguous mfn list to a pv-domain. In order to support sparse memory this mfn list is accessed via a three level p2m tree built early in the boot process. Whenever the system needs the mfn associated with a pfn this tree is used to find the mfn.

Instead of using a software walked tree for accessing a specific mfn list entry this patch is creating a virtual address area for the entire possible mfn list including memory holes. The holes are covered by mapping a pre-defined page consisting only of "invalid mfn" entries. Access to a mfn entry is possible by just using the virtual base address of the mfn list and the pfn as index into that list. This speeds up the (hot) path of determining the mfn of a pfn.

Kernel build on a Dell Latitude E6440 (2 cores, HT) in 64 bit Dom0 showed following improvements:

Elapsed time: 32:50 ->  32:35
System:       18:07 ->  17:47
User:        104:00 -> 103:30

Tested on 64 bit dom0 and 32 bit domU.

---
 arch/x86/include/asm/pgtable_types.h |   1 +
 arch/x86/include/asm/xen/page.h      |  30 +-
 arch/x86/mm/pageattr.c               |  20 +
 arch/x86/xen/mmu.c                   |  34 +-
 arch/x86/xen/p2m.c                   | 879 ++++++++++++++---------------------
 arch/x86/xen/setup.c                 | 101 ++--
 arch/x86/xen/xen-ops.h               |   5 +-
 7 files changed, 490 insertions(+), 580 deletions(-)
arch/x86/include/asm/pgtable_types.h +1 -0
index 0778964..d83f5e7 100644
@@ -396,6 +396,7 @@ static inline void update_page_count(int level, unsigned long pages) { }
 extern pte_t *lookup_address(unsigned long address, unsigned int *level);
 extern pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address,
 				    unsigned int *level);
+extern pmd_t *lookup_pmd_address(unsigned long address);
 extern phys_addr_t slow_virt_to_phys(void *__address);
 extern int kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
 				   unsigned numpages, unsigned long page_flags);
arch/x86/include/asm/xen/page.h +25 -5
index c29619c..f02236c 100644
@@ -41,6 +41,9 @@ typedef struct xpaddr {
 
 extern unsigned long *machine_to_phys_mapping;
 extern unsigned long  machine_to_phys_nr;
+extern unsigned long *xen_p2m_addr;
+extern unsigned long  xen_p2m_size;
+extern unsigned long  xen_max_p2m_pfn;
 
 extern unsigned long get_phys_to_machine(unsigned long pfn);
 extern bool set_phys_to_machine(unsigned long pfn, unsigned long mfn);
@@ -62,6 +65,23 @@ extern int m2p_remove_override(struct page *page,
 extern struct page *m2p_find_override(unsigned long mfn);
 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
 
+static inline unsigned long __pfn_to_mfn(unsigned long pfn)
+{
+	unsigned long mfn;
+
+	if (pfn < xen_p2m_size)
+		mfn = xen_p2m_addr[pfn];
+	else if (unlikely(pfn < xen_max_p2m_pfn))
+		return get_phys_to_machine(pfn);
+	else
+		return IDENTITY_FRAME(pfn);
+
+	if (unlikely(mfn == INVALID_P2M_ENTRY))
+		return get_phys_to_machine(pfn);
+
+	return mfn;
+}
+
 static inline unsigned long pfn_to_mfn(unsigned long pfn)
 {
 	unsigned long mfn;
@@ -69,7 +89,7 @@ static inline unsigned long pfn_to_mfn(unsigned long pfn)
 	if (xen_feature(XENFEAT_auto_translated_physmap))
 		return pfn;
 
-	mfn = get_phys_to_machine(pfn);
+	mfn = __pfn_to_mfn(pfn);
 
 	if (mfn != INVALID_P2M_ENTRY)
 		mfn &= ~(FOREIGN_FRAME_BIT | IDENTITY_FRAME_BIT);
@@ -82,7 +102,7 @@ static inline int phys_to_machine_mapping_valid(unsigned long pfn)
 	if (xen_feature(XENFEAT_auto_translated_physmap))
 		return 1;
 
-	return get_phys_to_machine(pfn) != INVALID_P2M_ENTRY;
+	return __pfn_to_mfn(pfn) != INVALID_P2M_ENTRY;
 }
 
 static inline unsigned long mfn_to_pfn_no_overrides(unsigned long mfn)
@@ -116,7 +136,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 		return mfn;
 
 	pfn = mfn_to_pfn_no_overrides(mfn);
-	if (get_phys_to_machine(pfn) != mfn) {
+	if (__pfn_to_mfn(pfn) != mfn) {
 		/*
 		 * If this appears to be a foreign mfn (because the pfn
 		 * doesn't map back to the mfn), then check the local override
@@ -133,7 +153,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
 	 * valid entry for it.
 	 */
 	if (pfn == ~0 &&
-			get_phys_to_machine(mfn) == IDENTITY_FRAME(mfn))
+			__pfn_to_mfn(mfn) == IDENTITY_FRAME(mfn))
 		pfn = mfn;
 
 	return pfn;
@@ -179,7 +199,7 @@ static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
 		return mfn;
 
 	pfn = mfn_to_pfn(mfn);
-	if (get_phys_to_machine(pfn) != mfn)
+	if (__pfn_to_mfn(pfn) != mfn)
 		return -1; /* force !pfn_valid() */
 	return pfn;
 }
arch/x86/mm/pageattr.c +20 -0
index ae242a7..8efd31e 100644
@@ -384,6 +384,26 @@ static pte_t *_lookup_address_cpa(struct cpa_data *cpa, unsigned long address,
 }
 
 /*
+ * Lookup the PMD entry for a virtual address. Return a pointer to the entry
+ * or NULL if not present.
+ */
+pmd_t *lookup_pmd_address(unsigned long address)
+{
+	pgd_t *pgd;
+	pud_t *pud;
+
+	pgd = pgd_offset_k(address);
+	if (pgd_none(*pgd))
+		return NULL;
+
+	pud = pud_offset(pgd, address);
+	if (pud_none(*pud) || pud_large(*pud) || !pud_present(*pud))
+		return NULL;
+
+	return pmd_offset(pud, address);
+}
+
+/*
  * This is necessary because __pa() does not work on some
  * kinds of memory, like vmalloc() or the alloc_remap()
  * areas on 32-bit NUMA systems.  The percpu areas can
arch/x86/xen/mmu.c +21 -13
index d3e492b..0b43c45 100644
@@ -387,7 +387,7 @@ static pteval_t pte_pfn_to_mfn(pteval_t val)
 		unsigned long mfn;
 
 		if (!xen_feature(XENFEAT_auto_translated_physmap))
-			mfn = get_phys_to_machine(pfn);
+			mfn = __pfn_to_mfn(pfn);
 		else
 			mfn = pfn;
 		/*
@@ -1158,20 +1158,16 @@ static void __init xen_cleanhighmap(unsigned long vaddr,
 	 * instead of somewhere later and be confusing. */
 	xen_mc_flush();
 }
-static void __init xen_pagetable_p2m_copy(void)
+
+static void __init xen_pagetable_p2m_free(void)
 {
 	unsigned long size;
 	unsigned long addr;
-	unsigned long new_mfn_list;
-
-	if (xen_feature(XENFEAT_auto_translated_physmap))
-		return;
 
 	size = PAGE_ALIGN(xen_start_info->nr_pages * sizeof(unsigned long));
 
-	new_mfn_list = xen_revector_p2m_tree();
 	/* No memory or already called. */
-	if (!new_mfn_list || new_mfn_list == xen_start_info->mfn_list)
+	if ((unsigned long)xen_p2m_addr == xen_start_info->mfn_list)
 		return;
 
 	/* using __ka address and sticking INVALID_P2M_ENTRY! */
@@ -1189,8 +1185,6 @@ static void __init xen_pagetable_p2m_copy(void)
 
 	size = PAGE_ALIGN(xen_start_info->nr_pages * sizeof(unsigned long));
 	memblock_free(__pa(xen_start_info->mfn_list), size);
-	/* And revector! Bye bye old array */
-	xen_start_info->mfn_list = new_mfn_list;
 
 	/* At this stage, cleanup_highmap has already cleaned __ka space
 	 * from _brk_limit way up to the max_pfn_mapped (which is the end of
@@ -1214,12 +1208,26 @@ static void __init xen_pagetable_p2m_copy(void)
 }
 #endif
 
-static void __init xen_pagetable_init(void)
+static void __init xen_pagetable_p2m_setup(void)
 {
-	paging_init();
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return;
+
+	xen_vmalloc_p2m_tree();
+
 #ifdef CONFIG_X86_64
-	xen_pagetable_p2m_copy();
+	xen_pagetable_p2m_free();
 #endif
+	/* And revector! Bye bye old array */
+	xen_start_info->mfn_list = (unsigned long)xen_p2m_addr;
+}
+
+static void __init xen_pagetable_init(void)
+{
+	paging_init();
+
+	xen_pagetable_p2m_setup();
+
 	/* Allocate and initialize top and mid mfn levels for p2m structure */
 	xen_build_mfn_list_list();
 
arch/x86/xen/p2m.c +345 -534

1,169 lines not on this page · raw message

arch/x86/xen/setup.c +75 -26

173 lines not on this page · raw message

arch/x86/xen/xen-ops.h +3 -2
index 5b72a06..f92921f 100644
@@ -29,12 +29,13 @@ void xen_build_mfn_list_list(void);
 void xen_setup_machphys_mapping(void);
 void xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn);
 void xen_reserve_top(void);
-extern unsigned long xen_max_p2m_pfn;
 
 void xen_mm_pin_all(void);
 void xen_mm_unpin_all(void);
 void xen_set_pat(u64);
 
+unsigned long __ref xen_chk_extra_mem(unsigned long pfn);
+void __init xen_inv_extra_mem(void);
 void __init xen_remap_memory(void);
 char * __init xen_memory_setup(void);
 char * xen_auto_xlated_memory_setup(void);
@@ -48,7 +49,7 @@ void xen_hvm_init_shared_info(void);
 void xen_unplug_emulated_devices(void);
 
 void __init xen_build_dynamic_phys_to_machine(void);
-unsigned long __init xen_revector_p2m_tree(void);
+void __init xen_vmalloc_p2m_tree(void);
 
 void xen_init_irq_ops(void);
 void xen_setup_timer(int cpu);
Signature · 1 line
1.8.4.5
#6 lore raw

Re: [PATCH 2/2] Xen: switch to linear virtual mapped sparse p2m list

Quoted 6 lines · Juergen Gross

At start of the day the Xen hypervisor presents a contiguous mfn list to a pv-domain. In order to support sparse memory this mfn list is accessed via a three level p2m tree built early in the boot process. Whenever the system needs the mfn associated with a pfn this tree is used to find the mfn.

Quoted 8 lines

Instead of using a software walked tree for accessing a specific mfn list entry this patch is creating a virtual address area for the entire possible mfn list including memory holes. The holes are covered by mapping a pre-defined page consisting only of "invalid mfn" entries. Access to a mfn entry is possible by just using the virtual base address of the mfn list and the pfn as index into that list. This speeds up the (hot) path of determining the mfn of a pfn.

I'm generally in favour of this I think but this is just too big to review carefully. Is there any way you can split this up? Perhaps with some preparatory patches before the big switch to the linear array?

David

#7 lore raw
In reply to Juergen Gross
Quoted 10 lines · Juergen Gross

Paravirtualized kernels running on Xen use a three level tree for translation of guest specific physical addresses to machine global addresses. This p2m tree is used for construction of page table entries, so the p2m tree walk is performance critical.

By using a linear virtual mapped p2m list accesses to p2m elements can be sped up while even simplifying code. To achieve this goal some p2m related initializations have to be performed later in the boot process, as the final p2m list can be set up only after basic memory management functions are available.

What impact does this have on 32-bit guests which don't have huge amount of virtual address space?

I think a 32-bit guest could have up to 64 GiB of PFNs, which would require a 128 MiB p2m array, which is too large?

David

author maintainer
#8 lore raw
Quoted 12 lines · David Vrabel
Quoted 10 lines · Juergen Gross

Paravirtualized kernels running on Xen use a three level tree for translation of guest specific physical addresses to machine global addresses. This p2m tree is used for construction of page table entries, so the p2m tree walk is performance critical.

By using a linear virtual mapped p2m list accesses to p2m elements can be sped up while even simplifying code. To achieve this goal some p2m related initializations have to be performed later in the boot process, as the final p2m list can be set up only after basic memory management functions are available.

Quoted 5 lines

What impact does this have on 32-bit guests which don't have huge amount of virtual address space?

I think a 32-bit guest could have up to 64 GiB of PFNs, which would require a 128 MiB p2m array, which is too large?

It is 64 MB (one entry on 32 bit is 32 bits :-) ).

With a m2p array of only 16 MB size I doubt a 32 bit guest can be larger than 16 GB, or am I wrong here?

Juergen

#9 lore raw
Quoted 16 lines · Juergen Gross
Quoted 15 lines · David Vrabel
Quoted 10 lines · Juergen Gross

Paravirtualized kernels running on Xen use a three level tree for translation of guest specific physical addresses to machine global addresses. This p2m tree is used for construction of page table entries, so the p2m tree walk is performance critical.

By using a linear virtual mapped p2m list accesses to p2m elements can be sped up while even simplifying code. To achieve this goal some p2m related initializations have to be performed later in the boot process, as the final p2m list can be set up only after basic memory management functions are available.

What impact does this have on 32-bit guests which don't have huge amount of virtual address space?

Quoted 7 lines
Quoted 2 lines

I think a 32-bit guest could have up to 64 GiB of PFNs, which would require a 128 MiB p2m array, which is too large?

It is 64 MB (one entry on 32 bit is 32 bits :-) ).

With a m2p array of only 16 MB size I doubt a 32 bit guest can be larger than 16 GB, or am I wrong here?

I think they can be bigger, the compat r/o m2p is 168MB, since Xen doesn't need to be in the hole as well (like it was with a real 32-bit Xen). There is also some scope for dynamic sizing of the hole (queried via XENMEM_machphys_mapping), I'm not sure if pvops makes use of that though.

In practice a 32-bit kernel starts to get pretty unhappy somewhere between 32 and 64GB because it runs out of low memory for various structures which are sized according to the amount of RAM. Or it did, it's been years since I've tried, maybe things are more able to use highmem now. In any case if you have such large amounts of RAM using a 64-bit kernel would be advisable.

Ian.

#10 lore raw
Quoted 28 lines · Ian Campbell
Quoted 15 lines · Juergen Gross
Quoted 14 lines · David Vrabel
Quoted 10 lines · Juergen Gross

Paravirtualized kernels running on Xen use a three level tree for translation of guest specific physical addresses to machine global addresses. This p2m tree is used for construction of page table entries, so the p2m tree walk is performance critical.

By using a linear virtual mapped p2m list accesses to p2m elements can be sped up while even simplifying code. To achieve this goal some p2m related initializations have to be performed later in the boot process, as the final p2m list can be set up only after basic memory management functions are available.

What impact does this have on 32-bit guests which don't have huge amount of virtual address space?

Quoted 6 lines
Quoted 2 lines

I think a 32-bit guest could have up to 64 GiB of PFNs, which would require a 128 MiB p2m array, which is too large?

It is 64 MB (one entry on 32 bit is 32 bits :-) ).

With a m2p array of only 16 MB size I doubt a 32 bit guest can be larger than 16 GB, or am I wrong here?

I think they can be bigger, the compat r/o m2p is 168MB, since Xen doesn't need to be in the hole as well (like it was with a real 32-bit Xen). There is also some scope for dynamic sizing of the hole (queried via XENMEM_machphys_mapping), I'm not sure if pvops makes use of that though.

Quoted 6 lines

In practice a 32-bit kernel starts to get pretty unhappy somewhere between 32 and 64GB because it runs out of low memory for various structures which are sized according to the amount of RAM. Or it did, it's been years since I've tried, maybe things are more able to use highmem now. In any case if you have such large amounts of RAM using a 64-bit kernel would be advisable.

It is XenServers experience that something (I presume a power-of-two-aligned mapping) cuts off at 128MB of the compat m2p, allowing for 32bit guest pages to exist in the first 128GB of host RAM.

Technically speaking, there is nothing preventing a 32bit PV guest being that large. The traditional issues with 32bit PAE kernels do not apply as Xen is running in long mode, but kernel lowmem will be the limiting factor. Switching to a 2/2 split will help, but it is a loosing battle.

It should be noted that OEL formally supports 64GB 32bit PV VMs, and as a result, the XenServer VM lifecycle tests do test it, and it works.

~Andrew

author maintainer
#11 lore raw
Quoted 40 lines · Andrew Cooper
Quoted 28 lines · Ian Campbell
Quoted 15 lines · Juergen Gross
Quoted 14 lines · David Vrabel
Quoted 10 lines · Juergen Gross

Paravirtualized kernels running on Xen use a three level tree for translation of guest specific physical addresses to machine global addresses. This p2m tree is used for construction of page table entries, so the p2m tree walk is performance critical.

By using a linear virtual mapped p2m list accesses to p2m elements can be sped up while even simplifying code. To achieve this goal some p2m related initializations have to be performed later in the boot process, as the final p2m list can be set up only after basic memory management functions are available.

What impact does this have on 32-bit guests which don't have huge amount of virtual address space?

Quoted 6 lines
Quoted 2 lines

I think a 32-bit guest could have up to 64 GiB of PFNs, which would require a 128 MiB p2m array, which is too large?

It is 64 MB (one entry on 32 bit is 32 bits :-) ).

With a m2p array of only 16 MB size I doubt a 32 bit guest can be larger than 16 GB, or am I wrong here?

I think they can be bigger, the compat r/o m2p is 168MB, since Xen doesn't need to be in the hole as well (like it was with a real 32-bit Xen). There is also some scope for dynamic sizing of the hole (queried via XENMEM_machphys_mapping), I'm not sure if pvops makes use of that though.

Quoted 6 lines

In practice a 32-bit kernel starts to get pretty unhappy somewhere between 32 and 64GB because it runs out of low memory for various structures which are sized according to the amount of RAM. Or it did, it's been years since I've tried, maybe things are more able to use highmem now. In any case if you have such large amounts of RAM using a 64-bit kernel would be advisable.

It is XenServers experience that something (I presume a power-of-two-aligned mapping) cuts off at 128MB of the compat m2p, allowing for 32bit guest pages to exist in the first 128GB of host RAM.

Quoted 7 lines

Technically speaking, there is nothing preventing a 32bit PV guest being that large. The traditional issues with 32bit PAE kernels do not apply as Xen is running in long mode, but kernel lowmem will be the limiting factor. Switching to a 2/2 split will help, but it is a loosing battle.

It should be noted that OEL formally supports 64GB 32bit PV VMs, and as a result, the XenServer VM lifecycle tests do test it, and it works.

Okay, back to the original question: is the (up to) 64 MB virtual mapping of the p2m list on 32-bit pv domains a problem or not?

If yes, the virtual mapped linear p2m list could still be used on 64 bit domains, paving the way for support of more than 512 GB of domain memory. OTOH having to keep the p2m tree coding alive isn't my favorite solution...

Juergen

#12 lore raw
Quoted 3 lines · Juergen Gross

Okay, back to the original question: is the (up to) 64 MB virtual mapping of the p2m list on 32-bit pv domains a problem or not?

I think up-to 64 MiB of vmalloc area is fine. The vmalloc space can be increased with a command line option in the unlikely event that there are domUs that would be affected.

Quoted 4 lines

If yes, the virtual mapped linear p2m list could still be used on 64 bit domains, paving the way for support of more than 512 GB of domain memory. OTOH having to keep the p2m tree coding alive isn't my favorite solution...

Having to keep both the tree and linear p2m code would be awful. Let's not do this!

David

#13 lore raw
Quoted 7 lines · David Vrabel
Quoted 2 lines · Juergen Gross

Okay, back to the original question: is the (up to) 64 MB virtual mapping of the p2m list on 32-bit pv domains a problem or not?

I think up-to 64 MiB of vmalloc area is fine. The vmalloc space can be increased with a command line option in the unlikely event that there are domUs that would be affected.

Quoted 8 lines
Quoted 4 lines

If yes, the virtual mapped linear p2m list could still be used on 64 bit domains, paving the way for support of more than 512 GB of domain memory. OTOH having to keep the p2m tree coding alive isn't my favorite solution...

Having to keep both the tree and linear p2m code would be awful. Let's not do this!

David

How is the toolstack expected to find and mutate this p2m on migrate? The toolstack does not use guest pagetables.

~Andrew

#14 lore raw
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · David Vrabel
Quoted 2 lines · Juergen Gross

Okay, back to the original question: is the (up to) 64 MB virtual mapping of the p2m list on 32-bit pv domains a problem or not?

I think up-to 64 MiB of vmalloc area is fine. The vmalloc space can be increased with a command line option in the unlikely event that there are domUs that would be affected.

Quoted 4 lines

If yes, the virtual mapped linear p2m list could still be used on 64 bit domains, paving the way for support of more than 512 GB of domain memory. OTOH having to keep the p2m tree coding alive isn't my favorite solution...

Quoted 7 lines
Quoted 4 lines

Having to keep both the tree and linear p2m code would be awful. Let's not do this!

David

How is the toolstack expected to find and mutate this p2m on migrate? The toolstack does not use guest pagetables.

The p2m code maintains two trees. One for use by the guest and one for use by the toolstack. This series replaces the first tree with the linear array (at least that's how I understand it -- I've not reviewed the series in detail yet).

David

#15 lore raw
Quoted 16 lines · David Vrabel
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · David Vrabel
Quoted 2 lines · Juergen Gross

Okay, back to the original question: is the (up to) 64 MB virtual mapping of the p2m list on 32-bit pv domains a problem or not?

I think up-to 64 MiB of vmalloc area is fine. The vmalloc space can be increased with a command line option in the unlikely event that there are domUs that would be affected.

Quoted 4 lines

If yes, the virtual mapped linear p2m list could still be used on 64 bit domains, paving the way for support of more than 512 GB of domain memory. OTOH having to keep the p2m tree coding alive isn't my favorite solution...

Having to keep both the tree and linear p2m code would be awful. Let's not do this!

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

David

How is the toolstack expected to find and mutate this p2m on migrate? The toolstack does not use guest pagetables.

The p2m code maintains two trees. One for use by the guest and one for use by the toolstack. This series replaces the first tree with the linear array (at least that's how I understand it -- I've not reviewed the series in detail yet).

Ah - fine (if that is how it works).

~Andrew

author maintainer
#16 lore raw
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · David Vrabel
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · David Vrabel
Quoted 2 lines · Juergen Gross

Okay, back to the original question: is the (up to) 64 MB virtual mapping of the p2m list on 32-bit pv domains a problem or not?

I think up-to 64 MiB of vmalloc area is fine. The vmalloc space can be increased with a command line option in the unlikely event that there are domUs that would be affected.

Quoted 4 lines

If yes, the virtual mapped linear p2m list could still be used on 64 bit domains, paving the way for support of more than 512 GB of domain memory. OTOH having to keep the p2m tree coding alive isn't my favorite solution...

Having to keep both the tree and linear p2m code would be awful. Let's not do this!

David

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

How is the toolstack expected to find and mutate this p2m on migrate? The toolstack does not use guest pagetables.

The p2m code maintains two trees. One for use by the guest and one for use by the toolstack. This series replaces the first tree with the linear array (at least that's how I understand it -- I've not reviewed the series in detail yet).

Ah - fine (if that is how it works).

That's the plan, yes.

Juergen

author maintainer
#17 lore raw
In reply to David Vrabel
Quoted 8 lines · David Vrabel
Quoted 3 lines · Juergen Gross

Okay, back to the original question: is the (up to) 64 MB virtual mapping of the p2m list on 32-bit pv domains a problem or not?

I think up-to 64 MiB of vmalloc area is fine. The vmalloc space can be increased with a command line option in the unlikely event that there are domUs that would be affected.

Okay.

Quoted 8 lines
Quoted 5 lines

If yes, the virtual mapped linear p2m list could still be used on 64 bit domains, paving the way for support of more than 512 GB of domain memory. OTOH having to keep the p2m tree coding alive isn't my favorite solution...

Having to keep both the tree and linear p2m code would be awful. Let's not do this!

Agreed. :-)

Juergen