Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp963914pxb; Fri, 22 Jan 2021 03:55:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRKsWgSasyOnlGgcZjbOegu+DF7swCw75T2mPk6JOsffPM+LV5zuYLjTtDepxgH1LyVPU2 X-Received: by 2002:a05:6402:190a:: with SMTP id e10mr2974719edz.110.1611316547393; Fri, 22 Jan 2021 03:55:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611316547; cv=none; d=google.com; s=arc-20160816; b=z/Bc0SNTy7Z3yzw8cRp8zs74ufKZmdIMfKYgM264u4uc8Cjk/ChLq8PAZtLjaVq5FD SCb2+i3HlowGoSm6bD47vIn6Z6U9txIVL5bHRbTf/maoB7EaRRmAq7ogYmFMWDRzTNDA fe6Yk0HwD139zL1llAaJgWIAbN7UEXhK4RWegv0/22FI1LlgyKMXcYHe4xX40a/ufG51 L88phdo7vUZc/LaN0lIQTsNnTamgjp4U4ZFe4r2k14G5EIJYYypKb7YzfInYWYgw/B2g THoPG5eifN/CqKV+Mbwh4qhZUi+KB46CZqKVYDmZRxvW/5t9YBuMLbH97wxsOvpCQpMY zSzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=FtRMrcvMZpdFVkiWnk8JGKFkJ0Aor8jBlRYjs6oQ9vE=; b=g7lo0jL3halTbAC14Jc9O1npGMAVxUhZhLYrKb7yyIgDIeE9tc0b6VVXznP2hK05LM elMWaGHcNgqD0mdUfsiHihc5TXAH1Sh/Q2f5fnzHk3R5juy9rtHhxPY4D8shEmunXfx1 O8NqimLN1jAHdzIenZ5Xqg9GN9xpXXO73xo7GRXs6wR6IsiyUKiIeW4y6VxT1NeDI6BI kumSv1LpNmuw5SvpG6H/K9hsXTAWthg9rWO4pQuJ4vedDvUoQle/npb4etB/DZLfi26b WRka/VzBgzYRVuHeCni9gTNiWv33YebE7f0DUHwIC1/fmy/K6+JVmP7H1/LXdfoau7N+ 2VPg== 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 n19si2869763ejx.42.2021.01.22.03.55.23; Fri, 22 Jan 2021 03:55:47 -0800 (PST) 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 S1727494AbhAVLxp (ORCPT + 99 others); Fri, 22 Jan 2021 06:53:45 -0500 Received: from mga07.intel.com ([134.134.136.100]:24043 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727628AbhAVLCf (ORCPT ); Fri, 22 Jan 2021 06:02:35 -0500 IronPort-SDR: vcUkLZ7BCYdkyr13XKJSJxQT0rub6VWRI6/aXGBtZql7J8sSXps/wSW4oUheIbc/poD29dJdNU QIEaKd0EfdtQ== X-IronPort-AV: E=McAfee;i="6000,8403,9871"; a="243508171" X-IronPort-AV: E=Sophos;i="5.79,366,1602572400"; d="scan'208";a="243508171" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2021 03:01:48 -0800 IronPort-SDR: UgrdvjI1kXn/ptg69It8sW2WQvu82xMTvsjwAiZe10UtQiFCsIFW3eN9f9l4YVy00FJxXu5xJy 0IShcsGitiDg== X-IronPort-AV: E=Sophos;i="5.79,366,1602572400"; d="scan'208";a="403734332" Received: from shsi6026.sh.intel.com (HELO localhost) ([10.239.147.88]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2021 03:01:44 -0800 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 , Yu Wang , Reinette Chatre , Yin Fengwei , Shuo Liu , Borislav Petkov , Dave Hansen , Sean Christopherson , Dan Williams , Zhi Wang , Zhenyu Wang Subject: [PATCH v8 03/18] x86/acrn: Introduce acrn_cpuid_base() and hypervisor feature bits Date: Fri, 22 Jan 2021 19:01:07 +0800 Message-Id: <20210122110122.45800-4-shuo.a.liu@intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210122110122.45800-1-shuo.a.liu@intel.com> References: <20210122110122.45800-1-shuo.a.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Acked-by: Borislav Petkov 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 | 16 ++++++++++++++++ arch/x86/kernel/cpu/acrn.c | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/acrn.h b/arch/x86/include/asm/acrn.h index ff259b69cde7..127f20672c5d 100644 --- a/arch/x86/include/asm/acrn.h +++ b/arch/x86/include/asm/acrn.h @@ -2,7 +2,23 @@ #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); +static inline u32 acrn_cpuid_base(void) +{ + if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) + return hypervisor_cpuid_base("ACRNACRNACRN", 0); + + return 0; +} + #endif /* _ASM_X86_ACRN_H */ diff --git a/arch/x86/kernel/cpu/acrn.c b/arch/x86/kernel/cpu/acrn.c index e0c181781905..23f5f27b5a02 100644 --- a/arch/x86/kernel/cpu/acrn.c +++ b/arch/x86/kernel/cpu/acrn.c @@ -21,7 +21,7 @@ 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