From patchwork Wed Mar 23 07:50:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 8647421 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CE2B8C0553 for ; Wed, 23 Mar 2016 07:53:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EB176203AA for ; Wed, 23 Mar 2016 07:53:21 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 01BFB2038D for ; Wed, 23 Mar 2016 07:53:21 +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 1aidYj-0000Xg-KD; Wed, 23 Mar 2016 07:50:29 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aidYi-0000Xa-SW for xen-devel@lists.xen.org; Wed, 23 Mar 2016 07:50:28 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 0A/55-02978-3CA42F65; Wed, 23 Mar 2016 07:50:27 +0000 X-Env-Sender: jgross@suse.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1458719427!31095907!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5859 invoked from network); 23 Mar 2016 07:50:27 -0000 Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by server-8.tower-31.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 23 Mar 2016 07:50:27 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0FA2CABED; Wed, 23 Mar 2016 07:50:26 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xen.org Date: Wed, 23 Mar 2016 08:50:24 +0100 Message-Id: <1458719424-1287-1-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.2 Cc: Juergen Gross , wei.liu2@citrix.com, ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH] tools: fix xen-detect to correctly identify domU type 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP xen-detect always thinks a domU is running as HVM guest as the cpuid instruction used to identify a Xen guest will always work. In order to identify a pv guest first try the pv special case of cpuid (prefixed with an ud2a instruction and "xen" in ASCII). This will fail on HVM and thus can be used to distinguish the guest types. Signed-off-by: Juergen Gross --- tools/misc/xen-detect.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/misc/xen-detect.c b/tools/misc/xen-detect.c index 787b5da..342856c 100644 --- a/tools/misc/xen-detect.c +++ b/tools/misc/xen-detect.c @@ -133,15 +133,10 @@ int main(int argc, char **argv) } } - /* Check for execution in HVM context. */ - detected = XEN_HVM; - if ( (version = check_for_xen(0)) != 0 ) - goto out; - /* * Set up a signal handler to test the paravirtualised CPUID instruction. * If executed outside Xen PV context, the extended opcode will fault, we - * will longjmp via the signal handler, and print "Not running on Xen". + * will longjmp via the signal handler, and test for HVM. */ detected = XEN_PV; if ( !setjmp(sigill_jmp) @@ -149,6 +144,11 @@ int main(int argc, char **argv) && ((version = check_for_xen(1)) != 0) ) goto out; + /* Check for execution in HVM context. */ + detected = XEN_HVM; + if ( !setjmp(sigill_jmp) && (version = check_for_xen(0)) != 0 ) + goto out; + detected = XEN_NONE; out: