From patchwork Wed Aug 17 10:30:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 9285559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BE53360459 for ; Wed, 17 Aug 2016 10:33:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD72B288CC for ; Wed, 17 Aug 2016 10:33:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A223B288FE; Wed, 17 Aug 2016 10:33:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B088A288CC for ; Wed, 17 Aug 2016 10:33:44 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZy7c-0001uT-U1; Wed, 17 Aug 2016 10:30:56 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZy7b-0001uN-58 for xen-devel@lists.xen.org; Wed, 17 Aug 2016 10:30:55 +0000 Received: from [85.158.139.211] by server-16.bemta-5.messagelabs.com id 28/A8-26103-EDC34B75; Wed, 17 Aug 2016 10:30:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBIsWRWlGSWpSXmKPExsUSuHLSQt27Nlv CDbqnilos+biYxYHR4+ju30wBjFGsmXlJ+RUJrBnXtx9hL7jKX3GjZRZLA+Mtni5GTg4WgT5m icanJSC2hICvxOT5fYxdjBxAtojEk/9pXYxcHEICj5kkZsz4zw5SIySQLrHv1AZGiF5ViTubV 7OC2GwCShJ7Dx4Hi4sImEpMWPGPBcQWFrCQuNr1DqyXV0BP4sza26wQtqDEyZlPwGqYBYolev 9OYQPZyywgLbH8HwdIWFRAVmJy2zv2CYx8s5B0zELSMQuhAyKsLvFn3iVmDGFtiWULXzND2LY S69a9Z1nAyL6KUaM4tagstUjXyEgvqSgzPaMkNzEzR9fQwFQvN7W4ODE9NScxqVgvOT93EyMw jOsZGBh3MO5p9zvEKMnBpCTKO3PixnAhvqT8lMqMxOKM+KLSnNTiQ4waHBwCm9euvsAoxZKXn 5eqJMG733pLuJBgUWp6akVaZg4w0mBKJTh4lER4l4GkeYsLEnOLM9MhUqcYjTm2LLixlolj27 y9V5iEwCZJifMuBykVACnNKM2DGwRLAJcYZaWEeRkZGBiEeApSi3IzS1DlXzGKczAqCfMuBpn Ck5lXArfvFdApTECn8PKDnVKSiJCSamBUedX78so08a9uh/iXWWiy//Z53DhN6wTHD+2tHz3l +kzZ7vD8Vy5bteFcyPmNr0RW/9b/bHjqzKef55wOKu/QX+d0UO31Bbblx/Lq9qZGMG76d3/3X DfmSa6CXLzn2O6uDeWelGt4ivPVpxX/ghXVo8JzdDY0R76O9XFjq5qzU2VHyMllDdeTlViKMx INtZiLihMBSsc8qfsCAAA= X-Env-Sender: olaf@aepfle.de X-Msg-Ref: server-8.tower-206.messagelabs.com!1471429853!54744595!1 X-Originating-IP: [81.169.146.161] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: QmFkIElQOiA4MS4xNjkuMTQ2LjE2MSA9PiA1ODk3MjY=\n,sa_preprocessor: QmFkIElQOiA4MS4xNjkuMTQ2LjE2MSA9PiA1ODk3MjY=\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 64205 invoked from network); 17 Aug 2016 10:30:53 -0000 Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.161) by server-8.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Aug 2016 10:30:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1471429853; l=1976; s=domk; d=aepfle.de; h=Content-Disposition:Content-Type:MIME-Version:Subject:To:From:Date; bh=iLl6uqbEujtk90jLS7m0WoYt57uzWxqJg6zQM3Hhsjg=; b=M77k45+5X1Tkhyt+pZTf2TNYV8QFrkj3KlqFWf9zAP1siD4UeDAqhDN/rYYBzqxdElg Tf++lmblnKBKdXYEaRhS8h13KyFUGxeSjTXJS7gCaqOMjpxTGRbqE4yfQj9ApJy06Il78 GDJ0gvyl9lvBe4U9btoUA0Yvwy+RitFJH8I= X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+yackYocTD1iAi8x+OWtqWFmrC5F/k8z92bfikQ== X-RZG-CLASS-ID: mo00 Received: from probook (aftr-185-17-206-159.dynamic.mnet-online.de [185.17.206.159]) by smtp.strato.de (RZmta 38.13 DYNA|AUTH) with ESMTPSA id j0a9ees7HAUqQxb (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Wed, 17 Aug 2016 12:30:52 +0200 (CEST) Received: by probook (Postfix, from userid 1000) id 5427F50BBA; Wed, 17 Aug 2016 12:30:51 +0200 (CEST) Date: Wed, 17 Aug 2016 12:30:50 +0200 From: Olaf Hering To: Jordan_Hargrave@dell.com, xen-devel@lists.xen.org Message-ID: <20160817103050.GA10246@aepfle.de> MIME-Version: 1.0 User-Agent: Mutt/1.6.2 (6759) Subject: [Xen-devel] [PATCH biosdevname]: handle dom0 on AMD systems X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; }