Skip to contentSkip to conversation

: handle dom0 on AMD systems

PATCH In review Olaf Hering 3 participants 4 messages Aug 17, 2016 – Feb 14, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : handle dom0 on AMD systems

Starting with xen-4.7 cpuid() will return with the hypervisor bit set in a dom0 when running on an AMD system. As a result biosdevname thinks it runs in a guest and does nothing. Detect a dom0 by looking into xenfs. This works with classic xenlinux based kernels and with pvops based kernels.

---
 src/bios_dev_name.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
src/bios_dev_name.c +29 -0
@@ -133,6 +133,31 @@ cpuid (u_int32_t eax, u_int32_t ecx)
 }
 
 /*
+  Starting with xen-4.7 cpuid will return with the hypervisor bit set
+  on AMD systems. This breaks biosdevname and network interface names.
+  Instead of relying on cpuid check for dom0 in xenfs.
+*/
+static int
+running_in_dom0(void)
+{
+    size_t len = 0;
+    char buf[16];
+    FILE *f = fopen("/proc/xen/capabilities", "r");
+
+    if (!f)
+        return 0;
+    memset(buf, 0, sizeof(buf));
+    len = fread(&buf, 1, sizeof(buf) - 1, f);
+    fclose(f);
+    while(len && --len && len < sizeof(buf)) {
+        if (buf[len] == '\n')
+            buf[len] = '\0';
+    }
+    len = !strcmp("control_d", buf);
+    return len;
+}
+
+/*
   Algorithm suggested by:
   http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1009458
 */
@@ -144,7 +171,11 @@ running_in_virtual_machine (void)
 
     ecx = cpuid (eax, ecx);
     if (ecx & 0x80000000U)
+    {
+       if (running_in_dom0())
+           return 0;
        return 1;
+    }
     return 0;
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw

src/bios_dev_name.c running_in_virtual_machine (void) · line 180

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 12:30, <[email protected]> wrote:
src/bios_dev_name.c +4 -0
@@ -144,7 +171,11 @@ running_in_virtual_machine (void)
 
     ecx = cpuid (eax, ecx);
     if (ecx & 0x80000000U)
+    {
+       if (running_in_dom0())
+           return 0;
        return 1;
+    }
     return 0;
 }

Isn't this backwards? Dom0 _is_ a virtual machine.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 13 lines · Jan Beulich

src/bios_dev_name.c running_in_virtual_machine (void) · line 180

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 12:30, <[email protected]> wrote:
src/bios_dev_name.c +4 -0
@@ -144,7 +171,11 @@ running_in_virtual_machine (void)
 
     ecx = cpuid (eax, ecx);
     if (ecx & 0x80000000U)
+    {
+       if (running_in_dom0())
+           return 0;
        return 1;
+    }
     return 0;
 }

Isn't this backwards? Dom0 _is_ a virtual machine.

biosdevname uses it as a "I should silently exit and do nothing" check.

This is unhelpful behaviour as dom0 is responsible for the real hardware.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
In reply to Olaf Hering

Hello,

and ping.

Olaf

Quoted 48 lines · Olaf Hering

Starting with xen-4.7 cpuid() will return with the hypervisor bit set in a dom0 when running on an AMD system. As a result biosdevname thinks it runs in a guest and does nothing. Detect a dom0 by looking into xenfs. This works with classic xenlinux based kernels and with pvops based kernels.

---
 src/bios_dev_name.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
src/bios_dev_name.c +25 -0
@@ -133,6 +133,31 @@ cpuid (u_int32_t eax, u_int32_t ecx)
 }
 
 /*
+  Starting with xen-4.7 cpuid will return with the hypervisor bit set
+  on AMD systems. This breaks biosdevname and network interface names.
+  Instead of relying on cpuid check for dom0 in xenfs.
+*/
+static int
+running_in_dom0(void)
+{
+    size_t len = 0;
+    char buf[16];
+    FILE *f = fopen("/proc/xen/capabilities", "r");
+
+    if (!f)
+        return 0;
+    memset(buf, 0, sizeof(buf));
+    len = fread(&buf, 1, sizeof(buf) - 1, f);
+    fclose(f);
+    while(len && --len && len < sizeof(buf)) {
+        if (buf[len] == '\n')
+            buf[len] = '\0';
+    }
+    len = !strcmp("control_d", buf);
+    return len;
+}
+
+/*
   Algorithm suggested by:
   http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1009458
 */
@@ -144,7 +171,11 @@ running_in_virtual_machine (void)
 

src/bios_dev_name.c running_in_virtual_machine (void) · line 181

Quoted 10 lines
src/bios_dev_name.c +4 -0
     ecx = cpuid (eax, ecx);
     if (ecx & 0x80000000U)
+    {
+       if (running_in_dom0())
+           return 0;
        return 1;
+    }
     return 0;
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel