Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp556065pxk; Thu, 3 Sep 2020 06:58:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhR7+egfIArqIuWwzy4uUX7dAO/1KQbIjPc1XxCLp2cLnwO8gi5v0+aysR5Ji78xtZj3I+ X-Received: by 2002:a17:906:af92:: with SMTP id mj18mr2235003ejb.242.1599141521816; Thu, 03 Sep 2020 06:58:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599141521; cv=none; d=google.com; s=arc-20160816; b=hJUsJA7OVRE6PSoh5BA/sL0ewhRZzKdw7xeN1o0Sko3Uyzt6olN3CwULAY5tjx/nBb UXisBxwx5DSTlQF4EN1PFk+rBprf8QuNkT+h+GQukDhjzJ9bs+vf1uUmLq497YKF3Uc7 HjJ6YTqP2h+muM2JE3hnnJKNihLbw4rWq7qS1zS5ljZhobVkFTNw5RvhwW8XgzLnN8uw zMPB9VA12JLK8EHqN7zQUe/JxoyNLi+G6XxpfhTKmSJTcnFWYBv5NUhM4lUyhwillW0w KHmSP2IX4KIBrFx0fZHZ916VI7gj8ppUEY2R1KOfhwvZM8vFHAjButGgdMtj+mqWESyP 3gkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=Bq6NUgSve6Qn5CFyGlLz/KrmBLQTgCGMG5Z76z3IaWU=; b=e3FzwBnKH8knu3IuHVnRYq2KqRc+iv7svi2Eka+vni53ozDqU0KNUiZubTOD7dlpAX OFrrDE3w6+XGMjrMh/jTjKeDY0lTmcdzru7af23kiyhg7wUpjGWSwwegJF6x1wZGcKhR ofP5aEBkrOSNBKg/WBHi2P66qPRknQu0SnLSAOgKUxF6dHrqVsIhvN5LNYfR/1lrLuNt vCxQU4d3SfzJvkAZRSyTw9k3suZKtvmug/EZy7IpHqZlqkB/DeJHY4nJLUVccMvdTsTW cUBdKGg6B5k3AXgGcBp1fymKs2CUxlLfT20N7qvBegbiDd5/y9hzT33LbYc9+CXceBXX Fozg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w20si1842823ejb.217.2020.09.03.06.58.18; Thu, 03 Sep 2020 06:58:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728731AbgICN5C (ORCPT + 99 others); Thu, 3 Sep 2020 09:57:02 -0400 Received: from mga03.intel.com ([134.134.136.65]:32640 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728917AbgICMpD (ORCPT ); Thu, 3 Sep 2020 08:45:03 -0400 IronPort-SDR: TYESReYTxbxJ7DRFlMfOqSj3owcceFUJPNGAXzY9EE++0H9vd2zsxNuPMECgJ9Q/NJdTaDA/Ds xS99T6NF74ew== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="157568358" X-IronPort-AV: E=Sophos;i="5.76,386,1592895600"; d="scan'208";a="157568358" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 05:42:31 -0700 IronPort-SDR: fG3ZVucVSrURUgMCzDOadMcNvdlWN6e07wd94vzp4rLI+qL+grQQ2U/xtylJKclJGhOSA7Lpum dOSKCXSEN2WA== X-IronPort-AV: E=Sophos;i="5.76,386,1592895600"; d="scan'208";a="326207068" Received: from shsi6026.sh.intel.com (HELO localhost) ([10.239.147.135]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 05:42:28 -0700 From: shuo.a.liu@intel.com To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Greg Kroah-Hartman , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Sean Christopherson , Yu Wang , Reinette Chatre , Yin Fengwei , Shuo Liu , Dave Hansen , Dan Williams , Zhi Wang , Zhenyu Wang Subject: [PATCH v2 03/17] x86/acrn: Introduce an API to check if a VM is privileged Date: Thu, 3 Sep 2020 20:41:47 +0800 Message-Id: <20200903124201.17275-4-shuo.a.liu@intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200903124201.17275-1-shuo.a.liu@intel.com> References: <20200903124201.17275-1-shuo.a.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yin Fengwei ACRN Hypervisor reports hypervisor features via CPUID leaf 0x40000001 which is similar to KVM. A VM can check if it's the privileged VM using the feature bits. The Service VM is the only privileged VM by design. Signed-off-by: Yin Fengwei Signed-off-by: Shuo Liu Reviewed-by: Reinette Chatre Cc: Dave Hansen Cc: Sean Christopherson Cc: Dan Williams Cc: Fengwei Yin Cc: Zhi Wang Cc: Zhenyu Wang Cc: Yu Wang Cc: Reinette Chatre Cc: Greg Kroah-Hartman --- arch/x86/include/asm/acrn.h | 9 +++++++++ arch/x86/kernel/cpu/acrn.c | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/acrn.h b/arch/x86/include/asm/acrn.h index ff259b69cde7..a2d4aea3a80d 100644 --- a/arch/x86/include/asm/acrn.h +++ b/arch/x86/include/asm/acrn.h @@ -2,7 +2,16 @@ #ifndef _ASM_X86_ACRN_H #define _ASM_X86_ACRN_H +/* + * This CPUID returns feature bitmaps in EAX. + * Guest VM uses this to detect the appropriate feature bit. + */ +#define ACRN_CPUID_FEATURES 0x40000001 +/* Bit 0 indicates whether guest VM is privileged */ +#define ACRN_FEATURE_PRIVILEGED_VM BIT(0) + void acrn_setup_intr_handler(void (*handler)(void)); void acrn_remove_intr_handler(void); +bool acrn_is_privileged_vm(void); #endif /* _ASM_X86_ACRN_H */ diff --git a/arch/x86/kernel/cpu/acrn.c b/arch/x86/kernel/cpu/acrn.c index bd1d7e759a0f..6f0a00cbbf7e 100644 --- a/arch/x86/kernel/cpu/acrn.c +++ b/arch/x86/kernel/cpu/acrn.c @@ -21,9 +21,26 @@ #include #include +static u32 acrn_cpuid_base(void) +{ + static u32 acrn_cpuid_base; + + if (!acrn_cpuid_base && boot_cpu_has(X86_FEATURE_HYPERVISOR)) + acrn_cpuid_base = hypervisor_cpuid_base("ACRNACRNACRN", 0); + + return acrn_cpuid_base; +} + +bool acrn_is_privileged_vm(void) +{ + return cpuid_eax(acrn_cpuid_base() | ACRN_CPUID_FEATURES) & + ACRN_FEATURE_PRIVILEGED_VM; +} +EXPORT_SYMBOL_GPL(acrn_is_privileged_vm); + static u32 __init acrn_detect(void) { - return hypervisor_cpuid_base("ACRNACRNACRN", 0); + return acrn_cpuid_base(); } static void __init acrn_init_platform(void) -- 2.28.0