Skip to contentSkip to conversation

detect Xen dom0 properly to avoid conflict with pv_on_hvm domU

PATCH In review Olaf Hering 2 participants 4 messages May 4, 2011 – May 6, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 detect Xen dom0 properly to avoid conflict with pv_on_hvm domU

A Xen HVM guest with PV drivers loaded has also a /proc/xen directory. But such a guest is an ordinary PC and the special handling for dom0 breaks kdump in this environment.
Test for /proc/xen/capabilities instead and cache the result.

Also make two variables static, they are only used in this file.

---
 kexec/crashdump-xen.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
kexec/crashdump-xen.c +10 -5
Index: kexec-tools-0.8.15/kexec/crashdump-xen.c
===================================================================
@@ -25,14 +25,19 @@ struct crash_note_info {
 	unsigned long length;
 };
 
-int xen_phys_cpus = 0;
-struct crash_note_info *xen_phys_notes;
+static int xen_phys_cpus;
+static struct crash_note_info *xen_phys_notes;
+static int is_dom0;
 
 int xen_present(void)
 {
-	struct stat buf;
-
-	return stat("/proc/xen", &buf) == 0;
+	if (!is_dom0) {
+		if (access("/proc/xen/capabilities", F_OK) == 0)
+			is_dom0 = 1;
+		else
+			is_dom0 = -1;
+	}
+	return is_dom0 > 0;
 }
 
 unsigned long xen_architecture(struct crash_elf_info *elf_info)

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

#1 lore raw
Quoted 18 lines · Olaf Hering

A Xen HVM guest with PV drivers loaded has also a /proc/xen directory. But such a guest is an ordinary PC and the special handling for dom0 breaks kdump in this environment.
Test for /proc/xen/capabilities instead and cache the result.

Also make two variables static, they are only used in this file.

---
 kexec/crashdump-xen.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Index: kexec-tools-0.8.15/kexec/crashdump-xen.c
===================================================================

kexec/crashdump-xen.c struct crash_note_info { · line 30

Quoted 8 lines
kexec/crashdump-xen.c +3 -2
@@ -25,14 +25,19 @@ struct crash_note_info {
 	unsigned long length;
 };
 
-int xen_phys_cpus = 0;
-struct crash_note_info *xen_phys_notes;
+static int xen_phys_cpus;
+static struct crash_note_info *xen_phys_notes;
+static int is_dom0;

I think you need to explicitly initialise is_dom0 to 0.

Alternatively, is it really such a burden to call access() each time xen_present() is called? (I'm ambivalent with regards to this).

Quoted 17 lines
kexec/crashdump-xen.c +7 -3
 int xen_present(void)
 {
-	struct stat buf;
-
-	return stat("/proc/xen", &buf) == 0;
+	if (!is_dom0) {
+		if (access("/proc/xen/capabilities", F_OK) == 0)
+			is_dom0 = 1;
+		else
+			is_dom0 = -1;
+	}
+	return is_dom0 > 0;
 }
 
 unsigned long xen_architecture(struct crash_elf_info *elf_info)
 
Quoted 5 lines

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

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

#2 lore raw
Quoted 5 lines · Simon Horman
Quoted 1 line · Olaf Hering

+static int is_dom0;

I think you need to explicitly initialise is_dom0 to 0.

Globals are always initialized to zero, its a C language thing.

Quoted 2 lines

Alternatively, is it really such a burden to call access() each time xen_present() is called? (I'm ambivalent with regards to this).

Probably not, its called a dozen times in my testing.

Olaf

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

#3 lore raw
Quoted 9 lines · Olaf Hering
Quoted 5 lines · Simon Horman
Quoted 1 line · Olaf Hering

+static int is_dom0;

I think you need to explicitly initialise is_dom0 to 0.

Globals are always initialized to zero, its a C language thing.

Point taken :^)

Quoted 4 lines
Quoted 2 lines

Alternatively, is it really such a burden to call access() each time xen_present() is called? (I'm ambivalent with regards to this).

Probably not, its called a dozen times in my testing.

As we already have the code it seems that we may as well use it.

I've merged your patch as-is.

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