Skip to contentSkip to conversation

Support Xen versions up to xen-4.1

PATCH Superseded Petr Tesarik 1 participant 10 messages Aug 21, 2012

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Support Xen versions up to xen-4.1

Hello everybody,

I have finally found the time to augment my patch set with the previous work done by Norbert Trapp and clean it up. I didn't include Norbert's performance improvements, because I believe they constitute an independent change (and we may even want to add generic infrastructure to be used by all architectures).

I have tested this patch set with:

- Xen-3.2.3 - WORKS
- Xen-4.0.1 - WORKS (only with --xen-syms)
- Xen-4.0.2 - WORKS
- Xen-4.1.2 - WORKS

Filtering free pages doesn't work (even after I manually provide the missing "max_pfn" symbol), but that seems unrelated, so I'm going to address it in a subsequent patch set.

Petr Tesarik
SUSE Linux

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#1 lore raw

PATCH 1/9 Make max_pfn symbol optional for Xen dumps

After commit ec5b5835a113cf62a168d4a7354564a38de6b52c, makedumpfile fails on Xen dumps unless the "max_pfn" symbol is known. This happens even when the dump level is 0 and 1, where it worked previously. This is especially bad for kernels which do not put the "max_pfn" symbol into its VMCOREINFO.

With this patch, the "max_pfn" symbol is required only if the specified dump level needs it.

Note that we cannot call get_dom0_mapnr() from initial_xen(), because "max_pfn" is a Linux symbol, which means that:
1. its address is determined in initial() (called after initial_xen)
2. it tries to read a Dom0 symbol, and Dom0 physical->machine mapping is initialized in get_machdep_info (called from initial).

---
 makedumpfile.c |   34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)
makedumpfile.c +20 -14
@@ -143,13 +143,15 @@ get_dom0_mapnr()
 {
 	unsigned long max_pfn;
 
-	if (SYMBOL(max_pfn) == NOT_FOUND_SYMBOL)
-		return FALSE;
-
-	if (!readmem(VADDR, SYMBOL(max_pfn), &max_pfn, sizeof max_pfn))
-		return FALSE;
+	if (SYMBOL(max_pfn) != NOT_FOUND_SYMBOL) {
+		if (!readmem(VADDR, SYMBOL(max_pfn), &max_pfn, sizeof max_pfn)) {
+			ERRMSG("Can't read domain-0 max_pfn.\n");
+			return FALSE;
+		}
 
-	info->dom0_mapnr = max_pfn;
+		info->dom0_mapnr = max_pfn;
+		DEBUG_MSG("domain-0 pfn : %llx\n", info->dom0_mapnr);
+	}
 
 	return TRUE;
 }
@@ -2430,14 +2432,6 @@ get_mem_map(void)
 {
 	int ret;
 
-	if (is_xen_memory()) {
-		if (!get_dom0_mapnr()) {
-			ERRMSG("Can't domain-0 pfn.\n");
-			return FALSE;
-		}
-		DEBUG_MSG("domain-0 pfn : %llx\n", info->dom0_mapnr);
-	}
-
 	switch (get_mem_type()) {
 	case SPARSEMEM:
 		DEBUG_MSG("\n");
@@ -2706,6 +2700,9 @@ out:
 			return FALSE;
 	}
 
+	if (is_xen_memory() && !get_dom0_mapnr())
+		return FALSE;
+
 	return TRUE;
 }
 
@@ -3475,6 +3472,10 @@ exclude_free_page(void)
 		ERRMSG("Can't get necessary structures for excluding free pages.\n");
 		return FALSE;
 	}
+	if (is_xen_memory() && !info->dom0_mapnr) {
+		ERRMSG("Can't get max domain-0 PFN for excluding free pages.\n");
+		return FALSE;
+	}
 
 	/*
 	 * Detect free pages and update 2nd-bitmap.
@@ -3749,6 +3750,11 @@ exclude_unnecessary_pages(void)
 	struct mem_map_data *mmd;
 	struct timeval tv_start;
 
+	if (is_xen_memory() && !info->dom0_mapnr) {
+		ERRMSG("Can't get max domain-0 PFN for excluding pages.\n");
+		return FALSE;
+	}
+
 	gettimeofday(&tv_start, NULL);
 
 	for (mm = 0; mm < info->num_mem_map; mm++) {

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw

PATCH 2/9 Xen: Fix the offset of the _domain field in struct page_info

In reply to Petr Tesarik

The page_info structure was re-arranged in Xen-3.4 (with changeset 162cdb596b9a), and the _domain field moved from union "u" to union "v" on x86 and x86_64.

By using OFFSET_IN_UNION_INIT we can cover all cases:

1. old placement in union "u"
2. new placement in union "v" on x86 and x86_64
3. unmodified placement in union "u" on ia64

Unfortunately, the re-arrangement was not reflected in xen/common/kexec.c, so the page_info _domain offset was still set with:

    VMCOREINFO_OFFSET_ALIAS(page_info, u, _domain);

The bug was spotted during Xen-4.1 development (changeset cb756381087c), and all Xen-4.1 releases are fixed like this:

    #ifdef __ia64__
	VMCOREINFO_OFFSET_SUB(page_info, u.inuse, _domain);
    #else
	VMCOREINFO_OFFSET_SUB(page_info, v.inuse, _domain);
    #endif

This changeset was also backported to Xen-4.0 branch as changeset 3b90a5353f20, which first went into Xen-4.0.2.
For Xen-3.4, this bug was never fixed.

To sum it up:
1. Xen versions up to and including Xen-3.3 output the correct offset
2. Xen-4.1 and above is also correct
3. Xen-4.0 is broken up to 4.0.2
4. Xen-3.4 is always broken

Some OS vendors may also have backported the patch to an otherwise broken version, so the above summary may not be reliable.

Anyway, the VMCOREINFO produced by some Xen versions is wrong, and makedumpfile will behave incorrectly. Adding a workaround to makedumpfile for a bug in another package is wrong, because:

A. Self-reliant users should upgrade Xen.
B. Users of distro packages should report it as a bug to their vendor, and
the vendor should backport the patch.
C. Users who need an immediate workaround should generate a vmcoreinfo file
using makedumpfile, which will be correct after applying this patch.

---
 makedumpfile.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
makedumpfile.c +1 -4
@@ -5306,10 +5306,7 @@ get_structure_info_xen(void)
 {
 	SIZE_INIT(page_info, "page_info");
 	OFFSET_INIT(page_info.count_info, "page_info", "count_info");
-	/*
-	 * _domain is the first member of union u
-	 */
-	OFFSET_INIT(page_info._domain, "page_info", "u");
+	OFFSET_IN_UNION_INIT(page_info._domain, "page_info", "_domain");
 
 	SIZE_INIT(domain, "domain");
 	OFFSET_INIT(domain.domain_id, "domain", "domain_id");

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw

PATCH 3/9 Read the Xen crash ELF note into memory at startup

In reply to Petr Tesarik

Instead of seeking individual fields inside the ELF note, copy the corresponding struct type from the Xen sources, so people can understand why the code does what it does.

This is mainly a cleanup patch to improve maintainability, but it also simplifies reusing the crash note data from other places.

---
 arch/x86_64.c  |   24 ++++++++++++++--
 elf_info.c     |   25 -----------------
 elf_info.h     |    2 -
 makedumpfile.c |   82 ++++++++++++++++++++++++++++++++++++++++++---------------
 makedumpfile.h |   49 ++++++++++++++++++++++++++++++++--
 5 files changed, 130 insertions(+), 52 deletions(-)
elf_info.c +1 -24
@@ -88,7 +88,6 @@ static unsigned long		size_eraseinfo;
  */
 static off_t			offset_xen_crash_info;
 static unsigned long		size_xen_crash_info;
-static unsigned long		xen_p2m_mfn;
 
 
 /*
@@ -292,8 +291,7 @@ static int
 get_pt_note_info(void)
 {
 	int n_type, size_desc;
-	unsigned long p2m_mfn;
-	off_t offset, offset_desc, off_p2m = 0;
+	off_t offset, offset_desc;
 	char buf[VMCOREINFO_XEN_NOTE_NAME_BYTES];
 	char note[MAX_SIZE_NHDR];
 
@@ -349,21 +347,6 @@ get_pt_note_info(void)
 			offset_xen_crash_info = offset_desc;
 			size_xen_crash_info   = size_desc;
 
-			off_p2m = offset + offset_next_note(note)
-					 - sizeof(p2m_mfn);
-			if (lseek(fd_memory, off_p2m, SEEK_SET) < 0){
-				ERRMSG("Can't seek the dump memory(%s). %s\n",
-				    name_memory, strerror(errno));
-				return FALSE;
-			}
-			if (read(fd_memory, &p2m_mfn, sizeof(p2m_mfn))
-			     != sizeof(p2m_mfn)) {
-				ERRMSG("Can't read the dump memory(%s). %s\n",
-				    name_memory, strerror(errno));
-				return FALSE;
-			}
-			xen_p2m_mfn = p2m_mfn;
-
 		/*
 		 * Check whether a source dumpfile contains eraseinfo.
 		 *   /proc/vmcore does not contain eraseinfo, because eraseinfo
@@ -859,9 +842,3 @@ set_eraseinfo(off_t offset, unsigned lon
 	size_eraseinfo   = size;
 }
 
-unsigned long
-get_xen_p2m_mfn(void)
-{
-	return xen_p2m_mfn;
-}
-
elf_info.h +0 -2
@@ -68,8 +68,6 @@ int has_eraseinfo(void);
 void get_eraseinfo(off_t *offset, unsigned long *size);
 void set_eraseinfo(off_t offset, unsigned long size);
 
-unsigned long get_xen_p2m_mfn(void);
-
 #endif  /* ELF_INFO_H */
 
 
makedumpfile.c +61 -21

105 lines not on this page · raw message

makedumpfile.h +47 -2

67 lines not on this page · raw message

arch/x86_64.c +21 -3
@@ -30,6 +30,18 @@ is_vmalloc_addr(ulong vaddr)
 	    || (vaddr >= MODULES_VADDR && vaddr <= MODULES_END));
 }
 
+static unsigned long
+get_xen_p2m_mfn(void)
+{
+	if (info->xen_crash_info_v >= 2)
+		return info->xen_crash_info.v2->
+			dom0_pfn_to_mfn_frame_list_list;
+	if (info->xen_crash_info_v >= 1)
+		return info->xen_crash_info.v1->
+			dom0_pfn_to_mfn_frame_list_list;
+	return NOT_FOUND_LONG_VALUE;
+}
+
 int
 get_phys_base_x86_64(void)
 {
@@ -59,6 +71,7 @@ get_phys_base_x86_64(void)
 int
 get_machdep_info_x86_64(void)
 {
+	unsigned long p2m_mfn;
 	int i, j, mfns[MAX_X86_64_FRAMES];
 	unsigned long frame_mfn[MAX_X86_64_FRAMES];
 	unsigned long buf[MFNS_PER_FRAME];
@@ -72,9 +85,14 @@ get_machdep_info_x86_64(void)
 	 * Get the information for translating domain-0's physical
 	 * address into machine address.
 	 */
-	if (!readmem(MADDR_XEN, pfn_to_paddr(get_xen_p2m_mfn()),
-					 &frame_mfn, PAGESIZE())) {
-		ERRMSG("Can't get p2m_mfn.\n");
+	p2m_mfn = get_xen_p2m_mfn();
+	if (p2m_mfn == (unsigned long)NOT_FOUND_LONG_VALUE) {
+		ERRMSG("Can't get p2m_mfn address.\n");
+		return FALSE;
+	}
+	if (!readmem(MADDR_XEN, pfn_to_paddr(p2m_mfn),
+		     &frame_mfn, PAGESIZE())) {
+		ERRMSG("Can't read p2m_mfn.\n");
 		return FALSE;
 	}
 

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw

PATCH 4/9 Split Xen setup into early and late

In reply to Petr Tesarik

Previously, get_xen_info_arch() was called after initializing the generic Xen variables. This is necessary, because the arch-specific code translates domain addresses to pickled domain IDs, and the domain list is initialized by the generic code.

Now, the virtual memory layout on x86_64 was changed in Xen4, and this initialization should ideally be done in the arch-specific code. Unfortunately, the generic code must know the virtual address space to perform readmem of type XEN_VADDR, so there is no working ordering, and instead we must provide hooks for "early" arch-specific initialization to set up data needed by the generic code, and "late" arch-specific initialization to do stuff that depends on data set by the generic code (currently only the domain_list).

---
 arch/ia64.c    |   14 +++++++++++---
 arch/x86.c     |   10 ++++++++--
 arch/x86_64.c  |   10 ++++++++--
 makedumpfile.c |    6 ++++++
 makedumpfile.h |    9 +++++++++
 5 files changed, 42 insertions(+), 7 deletions(-)
arch/x86.c +8 -2
@@ -291,11 +291,10 @@ kvtop_xen_x86(unsigned long kvaddr)
 	return entry;
 }
 
-int get_xen_info_x86(void)
+int get_xen_basic_info_x86(void)
 {
 	unsigned long frame_table_vaddr;
 	unsigned long xen_end;
-	int i;
 
 	if (SYMBOL(pgd_l2) == NOT_FOUND_SYMBOL &&
 	    SYMBOL(pgd_l3) == NOT_FOUND_SYMBOL) {
@@ -331,6 +330,13 @@ int get_xen_info_x86(void)
 	info->xen_heap_start = 0;
 	info->xen_heap_end   = paddr_to_pfn(xen_end);
 
+	return TRUE;
+}
+
+int get_xen_info_x86(void)
+{
+	int i;
+
 	/*
 	 * pickled_id == domain addr for x86
 	 */
arch/x86_64.c +8 -2
@@ -356,11 +356,10 @@ kvtop_xen_x86_64(unsigned long kvaddr)
 	return entry;
 }
 
-int get_xen_info_x86_64(void)
+int get_xen_basic_info_x86_64(void)
 {
 	unsigned long frame_table_vaddr;
 	unsigned long xen_end;
-	int i;
 
 	if (SYMBOL(pgd_l4) == NOT_FOUND_SYMBOL) {
 		ERRMSG("Can't get pml4.\n");
@@ -390,6 +389,13 @@ int get_xen_info_x86_64(void)
 	info->xen_heap_start = 0;
 	info->xen_heap_end   = paddr_to_pfn(xen_end);
 
+	return TRUE;
+}
+
+int get_xen_info_x86_64(void)
+{
+	int i;
+
 	/*
 	 * pickled_id == domain addr for x86_64
 	 */
makedumpfile.c +6 -0
@@ -5385,6 +5385,12 @@ get_xen_info(void)
 	unsigned int domain_id;
 	int num_domain;
 
+	/*
+	 * Get architecture specific basic data
+	 */
+	if (!get_xen_basic_info_arch())
+		return FALSE;
+
 	if (SYMBOL(alloc_bitmap) == NOT_FOUND_SYMBOL) {
 		ERRMSG("Can't get the symbol of alloc_bitmap.\n");
 		return FALSE;
makedumpfile.h +9 -0
@@ -1321,6 +1321,7 @@ struct domain_list {
 
 #ifdef __arm__
 #define kvtop_xen(X)	FALSE
+#define get_xen_basic_info_arch(X) FALSE
 #define get_xen_info_arch(X) FALSE
 #endif	/* arm */
 
@@ -1339,6 +1340,8 @@ struct domain_list {
 unsigned long long kvtop_xen_x86(unsigned long kvaddr);
 #define kvtop_xen(X)	kvtop_xen_x86(X)
 
+int get_xen_basic_info_x86(void);
+#define get_xen_basic_info_arch(X) get_xen_basic_info_x86(X)
 int get_xen_info_x86(void);
 #define get_xen_info_arch(X) get_xen_info_x86(X)
 
@@ -1366,6 +1369,8 @@ int get_xen_info_x86(void);
 unsigned long long kvtop_xen_x86_64(unsigned long kvaddr);
 #define kvtop_xen(X)	kvtop_xen_x86_64(X)
 
+int get_xen_basic_info_x86_64(void);
+#define get_xen_basic_info_arch(X) get_xen_basic_info_x86_64(X)
 int get_xen_info_x86_64(void);
 #define get_xen_info_arch(X) get_xen_info_x86_64(X)
 
@@ -1401,6 +1406,8 @@ int get_xen_info_x86_64(void);
 unsigned long long kvtop_xen_ia64(unsigned long kvaddr);
 #define kvtop_xen(X)	kvtop_xen_ia64(X)
 
+int get_xen_basic_info_ia64(void);
+#define get_xen_basic_info_arch(X) get_xen_basic_info_ia64(X)
 int get_xen_info_ia64(void);
 #define get_xen_info_arch(X) get_xen_info_ia64(X)
 
@@ -1408,11 +1415,13 @@ int get_xen_info_ia64(void);
 
 #if defined(__powerpc64__) || defined(__powerpc32__) /* powerpcXX */
 #define kvtop_xen(X)	FALSE
+#define get_xen_basic_info_arch(X) FALSE
 #define get_xen_info_arch(X) FALSE
 #endif	/* powerpcXX */
 
 #ifdef __s390x__ /* s390x */
 #define kvtop_xen(X)	FALSE
+#define get_xen_basic_info_arch(X) FALSE
 #define get_xen_info_arch(X) FALSE
 #endif	/* s390x */
 
arch/ia64.c +11 -3
@@ -329,10 +329,9 @@ kvtop_xen_ia64(unsigned long kvaddr)
 }
 
 int
-get_xen_info_ia64(void)
+get_xen_basic_info_ia64(void)
 {
-	unsigned long xen_start, xen_end, xen_heap_start;
-	int i;
+	unsigned long xen_start, xen_end;
 
 	info->frame_table_vaddr = VIRT_FRAME_TABLE_ADDR; /* "frame_table" is same value */
 
@@ -357,6 +356,15 @@ get_xen_info_ia64(void)
 	info->xen_heap_start = paddr_to_pfn(xen_start);
 	info->xen_heap_end   = paddr_to_pfn(xen_end);
 
+	return TRUE;
+}
+
+int
+get_xen_info_ia64(void)
+{
+	unsigned long xen_heap_start;
+	int i;
+
 	if (SYMBOL(xen_heap_start) == NOT_FOUND_SYMBOL) {
 		ERRMSG("Can't get the symbol of xen_heap_start.\n");
 		return FALSE;

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#5 lore raw

PATCH 5/9 Initialize phys_start during early Xen setup

In reply to Petr Tesarik

With early Xen setup, we can move the initialization of xen_phys_start to the setup routine. This is cleaner, as we can get rid of ifdef'ed arch-specific code in makedumpfile.c (which should IMO stay generic).

---
 arch/x86.c     |    9 +++++++++
 arch/x86_64.c  |    9 +++++++++
 makedumpfile.c |   16 ----------------
 3 files changed, 18 insertions(+), 16 deletions(-)
arch/x86.c +9 -0
@@ -296,6 +296,15 @@ int get_xen_basic_info_x86(void)
 	unsigned long frame_table_vaddr;
 	unsigned long xen_end;
 
+	if (!info->xen_phys_start) {
+		if (info->xen_crash_info_v < 2) {
+			ERRMSG("Can't get Xen physical start address.\n"
+			       "Please use the --xen_phys_start option.");
+			return FALSE;
+		}
+		info->xen_phys_start = info->xen_crash_info.v2->xen_phys_start;
+	}
+
 	if (SYMBOL(pgd_l2) == NOT_FOUND_SYMBOL &&
 	    SYMBOL(pgd_l3) == NOT_FOUND_SYMBOL) {
 		ERRMSG("Can't get pgd.\n");
arch/x86_64.c +9 -0
@@ -361,6 +361,15 @@ int get_xen_basic_info_x86_64(void)
 	unsigned long frame_table_vaddr;
 	unsigned long xen_end;
 
+ 	if (!info->xen_phys_start) {
+		if (info->xen_crash_info_v < 2) {
+			ERRMSG("Can't get Xen physical start address.\n"
+			       "Please use the --xen_phys_start option.");
+			return FALSE;
+		}
+		info->xen_phys_start = info->xen_crash_info.v2->xen_phys_start;
+	}
+
 	if (SYMBOL(pgd_l4) == NOT_FOUND_SYMBOL) {
 		ERRMSG("Can't get pml4.\n");
 		return FALSE;
makedumpfile.c +0 -16
@@ -5365,20 +5365,6 @@ init_xen_crash_info(void)
 }
 
 int
-get_xen_phys_start(void)
-{
-	if (info->xen_phys_start)
-		return TRUE;
-
-#if defined(__x86__) || defined(__x86_64__)
-	if (info->xen_crash_info_v >= 2)
-		info->xen_phys_start = info->xen_crash_info.v2->xen_phys_start;
-#endif
-
-	return TRUE;
-}
-
-int
 get_xen_info(void)
 {
 	unsigned long domain;
@@ -5877,8 +5863,6 @@ initial_xen(void)
 		if (!read_vmcoreinfo_from_vmcore(offset, size, TRUE))
 			return FALSE;
 	}
-	if (!get_xen_phys_start())
-		return FALSE;
 	if (!get_xen_info())
 		return FALSE;
 

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw

PATCH 6/9 Fix domain pickled_id computation for xen-3.4+

In reply to Petr Tesarik

Originally, Xen stored the 32-bit address of the domain structure in struct page_info. On x86-64, the physical address was stored, but since all heap objects were allocated in the 1:1 mapping which started at 0xffff830000000000, the end result was the same as if we simply chopped off the high bits (actual implementation in makedumpfile).

Then, during the development of Xen-3.4, this logic was changed several times for x86-64:

changeset 39517e863cc8 widened the _domain field to 64 bits and stored the
virtual address of struct domain instead of physical address
changeset beba88f6f90d removed the pickle/unpickle macros changeset 0858f961c77a changed _domain back from unsigned long to u32,
*and* stores the MFN of struct domain instead

All the above changes went into Xen-3.4, and the relation between a domain address and the contents of the _domain field hasn't changed since then. That means, when the MADDR space was compressed in Xen-4.0, the type of the _domain field was changed to _pdx_t, which was specifically invented to preserve its calculation from the struct domain address.

To sum it up:

1. For all Xen versions before Xen-3.4, the _domain field contains the address of struct domain (with high bits chopped for x86-64).
2. For all Xen versions starting with Xen-3.4, the _domain field can be computed from struct domain address as:
(addr - DIRECTMAP_VIRT_START) >> PAGE_SHIFT

---
 arch/x86_64.c |   26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
arch/x86_64.c +20 -6
@@ -405,12 +405,26 @@ int get_xen_info_x86_64(void)
 {
 	int i;
 
-	/*
-	 * pickled_id == domain addr for x86_64
-	 */
-	for (i = 0; i < info->num_domain; i++) {
-		info->domain_list[i].pickled_id =
-			info->domain_list[i].domain_addr;
+	if (info->xen_crash_info.com &&
+	    (info->xen_crash_info.com->xen_major_version >= 4 ||
+	     (info->xen_crash_info.com->xen_major_version == 3 &&
+	      info->xen_crash_info.com->xen_minor_version >= 4))) {
+		/*
+		 * cf. changeset 0858f961c77a
+		 */
+		for (i = 0; i < info->num_domain; i++) {
+			info->domain_list[i].pickled_id =
+				(info->domain_list[i].domain_addr -
+				 DIRECTMAP_VIRT_START) >> PAGESHIFT();
+		}
+	} else {
+		/*
+		 * pickled_id == domain addr for x86_64
+		 */
+		for (i = 0; i < info->num_domain; i++) {
+			info->domain_list[i].pickled_id =
+				info->domain_list[i].domain_addr;
+		}
 	}
 
 	return TRUE;

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#7 lore raw

PATCH 7/9 Support Xen4 virtuall address space layout

In reply to Petr Tesarik

Starting with Xen-4.0.0, the virtual memory layout on x86_64 has changed. To support both Xen3 and Xen4, some of the former constants have to be converted to a variable.

Note the addition of XEN_VIRT_END - even though the location of Xen code and data changed, its size stayed at 1G, so we can compute the end of this portion from the start point with the same formula for both versions.

A side-by-side comparison of the virtual address space for Xen3 and Xen4:

Range | Xen3 | Xen4
------------------+------------------------------+-----------------------------
0xffff800000000000|[256G] Read-only machine-to-phys translation table
0xffff803fffffffff| (GUEST ACCESSIBLE)
------------------+------------------------------------------------------------
0xffff804000000000|[256G] Reserved for future shared info with the guest OS
0xffff807fffffffff| (GUEST ACCESSIBLE)
------------------+------------------------------+-----------------------------

0xffff808000000000|[512G] Reserved for future use|[512G] ioremap for PCI
0xffff80ffffffffff|                              | mmconfig space

------------------+------------------------------+-----------------------------
0xffff810000000000|[512G] Guest linear page table 0xffff817fffffffff|
------------------+------------------------------------------------------------
0xffff818000000000|[512G] Shadow linear page table 0xffff81ffffffffff|
------------------+------------------------------------------------------------
0xffff820000000000|[512G] Per-domain mappings (e.g., GDT, LDT) 0xffff827fffffffff|
------------------+------------------------------------------------------------
0xffff828000000000|[16G] Machine-to-phys 0xffff8283ffffffff| translation table
------------------+------------------------------------------------------------
0xffff828400000000|[16G] Page-frame information 0xffff8287ffffffff| array
------------------+------------------------------------------------------------
0xffff828800000000|[16G] ioremap()/fixmap area 0xffff828bffffffff|
------------------+------------------------------+-----------------------------

0xffff828c00000000|[1G] Compatibility            |
0xffff828c3fffffff| machine-to-phys translation  |
                  | table                        |
------------------+------------------------------+
0xffff828c40000000|[1G] High read-only compat    |
0xffff828c7fffffff| machine-to-phys translation  |[256G] Machine-to-phys
                  | table                        |translation table
------------------+------------------------------+
0xffff828c80000000|[1G] Xen text, static data,   |
0xffff828cbfffffff| bss                          |
------------------+------------------------------+
0xffff828cc0000000|                              |
0xffff82bfffffffff|                              |
------------------+                              +-----------------------------
0xffff82c000000000|                              |[16G] ioremap()/fixmap area
0xffff82c3ffffffff|                              |
------------------+                              +-----------------------------
0xffff82c400000000|                              |[1G] Compatibility
0xffff82c43fffffff|                              | machine-to-phys translation
                  |                              | table
------------------+                              +-----------------------------
0xffff82c440000000|[461G] Reserved for future use|[1G] High read-only compat
0xffff82c47fffffff|                              | machine-to-phys translation
                  |                              | table
------------------+                              +-----------------------------
0xffff82c480000000|                              |[1G] Xen text, static data,
0xffff82c4bfffffff|                              | bss
------------------+                              +-----------------------------
0xffff82c4c0000000|                              |[197G] Reserved for future
0xffff82f5ffffffff|                              | use
------------------+                              +-----------------------------
0xffff82f600000000|                              |[40G] Page-frame information
0xffff82ffffffffff|                              | array
------------------+------------------------------+-----------------------------
0xffff830000000000|[1T] 1:1 direct mapping of all|
0xffff83ffffffffff| physical memory              |[5T] 1:1 direct mapping of
------------------+------------------------------+ all physical memory
0xffff840000000000|[4T] Reserved for future use  |
0xffff87ffffffffff|                              |

------------------+------------------------------+-----------------------------

---
 arch/x86_64.c  |    9 +++++++++
 makedumpfile.h |   17 ++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
makedumpfile.h +14 -3
@@ -962,6 +962,10 @@ struct DumpInfo {
 	unsigned long *p2m_mfn_frame_list;
 	int	num_domain;
 	struct domain_list *domain_list;
+#if defined(__x86_64__)
+	unsigned long xen_virt_start;
+	unsigned long directmap_virt_end;
+#endif
 
 	/*
 	 * for splitting
@@ -1331,6 +1335,7 @@ struct domain_list {
 #define HYPERVISOR_VIRT_END		(0xFFFFFFFFUL)
 #define DIRECTMAP_VIRT_START		(0xFF000000UL)
 #define DIRECTMAP_VIRT_END		(0xFFC00000UL)
+#define FRAMETABLE_VIRT_START		(0xF6800000UL)
 
 #define is_xen_vaddr(x) \
 	((x) >= HYPERVISOR_VIRT_START_PAE && (x) < HYPERVISOR_VIRT_END)
@@ -1356,15 +1361,21 @@ int get_xen_info_x86(void);
 #define HYPERVISOR_VIRT_START (0xffff800000000000)
 #define HYPERVISOR_VIRT_END   (0xffff880000000000)
 #define DIRECTMAP_VIRT_START  (0xffff830000000000)
-#define DIRECTMAP_VIRT_END    (0xffff840000000000)
-#define XEN_VIRT_START        (0xffff828c80000000)
+#define DIRECTMAP_VIRT_END_V3 (0xffff840000000000)
+#define DIRECTMAP_VIRT_END_V4 (0xffff880000000000)
+#define DIRECTMAP_VIRT_END    (info->directmap_virt_end)
+#define XEN_VIRT_START_V3     (0xffff828c80000000)
+#define XEN_VIRT_START_V4     (0xffff82c480000000)
+#define XEN_VIRT_START        (info->xen_virt_start)
+#define XEN_VIRT_END          (XEN_VIRT_START + (1UL << 30))
+#define FRAMETABLE_VIRT_START 0xffff82f600000000
 
 #define is_xen_vaddr(x) \
 	((x) >= HYPERVISOR_VIRT_START && (x) < HYPERVISOR_VIRT_END)
 #define is_direct(x) \
 	((x) >= DIRECTMAP_VIRT_START && (x) < DIRECTMAP_VIRT_END)
 #define is_xen_text(x) \
-	((x) >= XEN_VIRT_START && (x) < DIRECTMAP_VIRT_START)
+	((x) >= XEN_VIRT_START && (x) < XEN_VIRT_END)
 
 unsigned long long kvtop_xen_x86_64(unsigned long kvaddr);
 #define kvtop_xen(X)	kvtop_xen_x86_64(X)
arch/x86_64.c +9 -0
@@ -370,6 +370,15 @@ int get_xen_basic_info_x86_64(void)
 		info->xen_phys_start = info->xen_crash_info.v2->xen_phys_start;
 	}
 
+	if (info->xen_crash_info.com &&
+	    info->xen_crash_info.com->xen_major_version >= 4) {
+		info->xen_virt_start = XEN_VIRT_START_V4;
+		info->directmap_virt_end = DIRECTMAP_VIRT_END_V4;
+	} else {
+		info->xen_virt_start = XEN_VIRT_START_V3;
+		info->directmap_virt_end = DIRECTMAP_VIRT_END_V3;
+	}
+
 	if (SYMBOL(pgd_l4) == NOT_FOUND_SYMBOL) {
 		ERRMSG("Can't get pml4.\n");
 		return FALSE;

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#8 lore raw

PATCH 8/9 Add support for filtering out user pages under Xen4

In reply to Petr Tesarik

In Xen-4.0+, usage of a page must be determined from its PGC_xxx flags, which are stored in the highest bits of the _count field of struct page_info.

Let's keep the original function for Xen3 only and add a new function for walking the pages under Xen4. This avoids adding many new conditionals to the inner loop and also makes the logic easier to follow for all Xen versions.

---
 makedumpfile.c |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 makedumpfile.h |   25 +++++++++++++
 2 files changed, 122 insertions(+), 6 deletions(-)
makedumpfile.h +25 -0
@@ -78,6 +78,31 @@ int get_mem_type(void);
 #define LSEEKED_PDATA	(3)
 
 /*
+ * Xen page flags
+ */
+#define BITS_PER_BYTE (8)
+#define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long))
+#define PG_shift(idx)	(BITS_PER_LONG - (idx))
+#define PG_mask(x, idx)	(x ## UL << PG_shift(idx))
+ /* Cleared when the owning guest 'frees' this page. */
+#define PGC_allocated       PG_mask(1, 1)
+ /* Page is Xen heap? */
+#define PGC_xen_heap        PG_mask(1, 2)
+ /* Page is broken? */
+#define PGC_broken          PG_mask(1, 7)
+ /* Mutually-exclusive page states: { inuse, offlining, offlined, free }. */
+#define PGC_state           PG_mask(3, 9)
+#define PGC_state_inuse     PG_mask(0, 9)
+#define PGC_state_offlining PG_mask(1, 9)
+#define PGC_state_offlined  PG_mask(2, 9)
+#define PGC_state_free      PG_mask(3, 9)
+#define page_state_is(ci, st) (((ci)&PGC_state) == PGC_state_##st)
+
+ /* Count of references to this frame. */
+#define PGC_count_width   PG_shift(9)
+#define PGC_count_mask    ((1UL<<PGC_count_width)-1)
+
+/*
  * Memory flags
  */
 #define MEMORY_PAGETABLE_4L	(1 << 0)
makedumpfile.c +97 -6

126 lines not on this page · raw message

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#9 lore raw

PATCH 9/9 Do not fail for symbols removed in Xen4

In reply to Petr Tesarik

Xen-4.0+ removes some of the symbols that were necessary to process dump files on Xen-3, and makedumpfile fails if they are not found.

Since most of these symbols are not needed for Xen4, we can simply remove the checks. The only exception is "frame_table". This used to be a global variable holding the address of the array of struct page_info. In Xen-4.0 the array is always located at a fixed address in virtual address space. Xen adds a compatibility symbol for VMCOREINFO, but a "frame_table" symbol does not exist as such, so we must use the fixed address instead.

---
 arch/ia64.c    |   41 ++++++++++++++++++++++-------------------
 arch/x86.c     |   49 ++++++++++++++++++++++++++-----------------------
 arch/x86_64.c  |   49 ++++++++++++++++++++++++++-----------------------
 makedumpfile.c |   37 ++++++++++++++++++++-----------------
 4 files changed, 94 insertions(+), 82 deletions(-)
makedumpfile.c +20 -17
@@ -5377,23 +5377,26 @@ get_xen_info(void)
 	if (!get_xen_basic_info_arch())
 		return FALSE;
 
-	if (SYMBOL(alloc_bitmap) == NOT_FOUND_SYMBOL) {
-		ERRMSG("Can't get the symbol of alloc_bitmap.\n");
-		return FALSE;
-	}
-	if (!readmem(VADDR_XEN, SYMBOL(alloc_bitmap), &info->alloc_bitmap,
-	      sizeof(info->alloc_bitmap))) {
-		ERRMSG("Can't get the value of alloc_bitmap.\n");
-		return FALSE;
-	}
-	if (SYMBOL(max_page) == NOT_FOUND_SYMBOL) {
-		ERRMSG("Can't get the symbol of max_page.\n");
-		return FALSE;
-	}
-	if (!readmem(VADDR_XEN, SYMBOL(max_page), &info->max_page,
-	    sizeof(info->max_page))) {
-		ERRMSG("Can't get the value of max_page.\n");
-		return FALSE;
+	if (!info->xen_crash_info.com ||
+	    info->xen_crash_info.com->xen_major_version < 4) {
+		if (SYMBOL(alloc_bitmap) == NOT_FOUND_SYMBOL) {
+			ERRMSG("Can't get the symbol of alloc_bitmap.\n");
+			return FALSE;
+		}
+		if (!readmem(VADDR_XEN, SYMBOL(alloc_bitmap), &info->alloc_bitmap,
+		      sizeof(info->alloc_bitmap))) {
+			ERRMSG("Can't get the value of alloc_bitmap.\n");
+			return FALSE;
+		}
+		if (SYMBOL(max_page) == NOT_FOUND_SYMBOL) {
+			ERRMSG("Can't get the symbol of max_page.\n");
+			return FALSE;
+		}
+		if (!readmem(VADDR_XEN, SYMBOL(max_page), &info->max_page,
+		    sizeof(info->max_page))) {
+			ERRMSG("Can't get the value of max_page.\n");
+			return FALSE;
+		}
 	}
 
 	/*
arch/ia64.c +22 -19

48 lines not on this page · raw message

arch/x86_64.c +26 -23

63 lines not on this page · raw message

arch/x86.c +26 -23

63 lines not on this page · raw message

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec