From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olaf Hering Subject: Re: [PATCH biosdevname]: handle dom0 on AMD systems Date: Tue, 14 Feb 2017 17:30:35 +0100 Message-ID: <20170214163035.GA14299@aepfle.de> References: <20160817103050.GA10246@aepfle.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8604221327575891827==" Return-path: In-Reply-To: <20160817103050.GA10246@aepfle.de> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: Jordan_Hargrave@dell.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org --===============8604221327575891827== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="zYM0uCDKw75PZbzx" Content-Disposition: inline --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > Signed-off-by: Olaf Hering >=20 > --- > src/bios_dev_name.c | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) >=20 > --- 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) > } > =20 > /* > + 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 =3D 0; > + char buf[16]; > + FILE *f =3D fopen("/proc/xen/capabilities", "r"); > + > + if (!f) > + return 0; > + memset(buf, 0, sizeof(buf)); > + len =3D fread(&buf, 1, sizeof(buf) - 1, f); > + fclose(f); > + while(len && --len && len < sizeof(buf)) { > + if (buf[len] =3D=3D '\n') > + buf[len] =3D '\0'; > + } > + len =3D !strcmp("control_d", buf); > + return len; > +} > + > +/* > Algorithm suggested by: > http://kb.vmware.com/selfservice/microsites/search.do?language=3Den_US= &cmd=3DdisplayKC&externalId=3D1009458 > */ > @@ -144,7 +171,11 @@ running_in_virtual_machine (void) > =20 > ecx =3D cpuid (eax, ecx); > if (ecx & 0x80000000U) > + { > + if (running_in_dom0()) > + return 0; > return 1; > + } > return 0; > } > =20 --zYM0uCDKw75PZbzx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQSkRyP6Rn//f03pRUBdQqD6ppg2fgUCWKMwqwAKCRBdQqD6ppg2 fmiqAKCTA3nK5BgGWFXbc2ZWdEiGW5r6PQCdFTo98IMfbNqtt3Btgr70NRrmPJg= =cBF5 -----END PGP SIGNATURE----- --zYM0uCDKw75PZbzx-- --===============8604221327575891827== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --===============8604221327575891827==--