x86: introduce using_{svm,vmx}() helpers

As we now have AMD_SVM/INTEL_VMX config options for enabling/disabling these
features completely in the build, we need some build-time checks to ensure that
vmx/svm code can be used and things compile. Macros cpu_has_{svm,vmx} used to be
doing such checks at runtime, however they do not check if SVM/VMX support is
enabled in the build.

Also cpu_has_{svm,vmx} can potentially be called from non-{VMX,SVM} build
yet running on {VMX,SVM}-enabled CPU, so would correctly indicate that VMX/SVM
is indeed supported by CPU, but code to drive it can't be used.

New routines using_{vmx,svm}() indicate that both CPU _and_ build provide
corresponding technology support, while cpu_has_{vmx,svm} still remains for
informational runtime purpose, just as their naming suggests.

These new helpers are used right away in several sites, namely guard calls to
start_nested_{svm,vmx} and start_{svm,vmx} to fix a build when INTEL_VMX=n or
AMD_SVM=n.

Signed-off-by: Sergiy Kibrik <Sergiy_Kibrik@epam.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Sergiy Kibrik authored and Jan Beulich committed 2024-08-01 13:55:39 +02:00
1 parent e96831ece8
commit 3f7efa20e4
3 files changed
+14 -4

No files matched your search

+2 -2
View File
@@ -155,9 +155,9 @@ static int __init cf_check hvm_enable(void)
{
const struct hvm_function_table *fns = NULL;
if ( cpu_has_vmx )
if ( using_vmx() )
fns = start_vmx();
else if ( cpu_has_svm )
else if ( using_svm() )
fns = start_svm();
if ( fns == NULL )
+2 -2
View File
@@ -155,9 +155,9 @@ static int __init cf_check nestedhvm_setup(void)
* done, so that if (for example) HAP is disabled, nested virt is
* disabled as well.
*/
if ( cpu_has_vmx )
if ( using_vmx() )
start_nested_vmx(&hvm_funcs);
else if ( cpu_has_svm )
else if ( using_svm() )
start_nested_svm(&hvm_funcs);
return 0;
+10
View File
@@ -363,6 +363,16 @@ int hvm_copy_context_and_params(struct domain *dst, struct domain *src);
int hvm_get_param(struct domain *d, uint32_t index, uint64_t *value);
static inline bool using_vmx(void)
{
return IS_ENABLED(CONFIG_INTEL_VMX) && cpu_has_vmx;
}
static inline bool using_svm(void)
{
return IS_ENABLED(CONFIG_AMD_SVM) && cpu_has_svm;
}
#ifdef CONFIG_HVM
#define hvm_get_guest_tsc(v) hvm_get_guest_tsc_fixed(v, 0)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.