* [PATCH biosdevname]: handle dom0 on AMD systems
@ 2016-08-17 10:30 Olaf Hering
2016-08-17 11:51 ` Jan Beulich
2017-02-14 16:30 ` Olaf Hering
0 siblings, 2 replies; 4+ messages in thread
From: Olaf Hering @ 2016-08-17 10:30 UTC (permalink / raw)
To: Jordan_Hargrave, xen-devel
[-- Attachment #1.1: Type: text/plain, Size: 1615 bytes --]
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.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
src/bios_dev_name.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
--- a/src/bios_dev_name.c
+++ b/src/bios_dev_name.c
@@ -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;
}
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
[-- Attachment #2: Type: text/plain, Size: 127 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH biosdevname]: handle dom0 on AMD systems
2016-08-17 10:30 [PATCH biosdevname]: handle dom0 on AMD systems Olaf Hering
@ 2016-08-17 11:51 ` Jan Beulich
2016-08-17 11:56 ` Andrew Cooper
2017-02-14 16:30 ` Olaf Hering
1 sibling, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2016-08-17 11:51 UTC (permalink / raw)
To: Olaf Hering; +Cc: Jordan_Hargrave, xen-devel
>>> On 17.08.16 at 12:30, <olaf@aepfle.de> wrote:
> @@ -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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH biosdevname]: handle dom0 on AMD systems
2016-08-17 11:51 ` Jan Beulich
@ 2016-08-17 11:56 ` Andrew Cooper
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Cooper @ 2016-08-17 11:56 UTC (permalink / raw)
To: Jan Beulich, Olaf Hering; +Cc: Jordan_Hargrave, xen-devel
On 17/08/16 12:51, Jan Beulich wrote:
>>>> On 17.08.16 at 12:30, <olaf@aepfle.de> wrote:
>> @@ -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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH biosdevname]: handle dom0 on AMD systems
2016-08-17 10:30 [PATCH biosdevname]: handle dom0 on AMD systems Olaf Hering
2016-08-17 11:51 ` Jan Beulich
@ 2017-02-14 16:30 ` Olaf Hering
1 sibling, 0 replies; 4+ messages in thread
From: Olaf Hering @ 2017-02-14 16:30 UTC (permalink / raw)
To: Jordan_Hargrave, xen-devel
[-- Attachment #1.1: Type: text/plain, Size: 1806 bytes --]
Hello,
and ping.
Olaf
On Wed, Aug 17, Olaf Hering wrote:
> 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.
>
> Signed-off-by: Olaf Hering <olaf@aepfle.de>
>
> ---
> src/bios_dev_name.c | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> --- a/src/bios_dev_name.c
> +++ b/src/bios_dev_name.c
> @@ -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;
> }
>
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 127 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-02-14 16:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-17 10:30 [PATCH biosdevname]: handle dom0 on AMD systems Olaf Hering
2016-08-17 11:51 ` Jan Beulich
2016-08-17 11:56 ` Andrew Cooper
2017-02-14 16:30 ` Olaf Hering
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.