From nobody Thu Sep 19 01:05:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=quarantine dis=quarantine) header.from=epam.com ARC-Seal: i=1; a=rsa-sha256; t=1720504499; cv=none; d=zohomail.com; s=zohoarc; b=n6d8F8zLHOSNeZB+b9030utkUnxgzWY2PzQpvLIlHpGfOmY7DNrKFmvrdsRf63Cbl+njaaWH7vQOVrr0vzy1YFQMIFvGdnhpNn1F8rdJAv+hTbpQRZ0CslA5b5zk4R5rUhOm9AUH0NXlgjVDlO+1TvFTxExTzcYr1O13luXgn1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720504499; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7qKXR4Nhn9A4ZiMJVQYEFV0FMNeh1kuLLfLNK1yCNhg=; b=ih7XubzM3fLZIUg10eP2kgD+Rg0weMQNm6P5dMMYQ3z0BkgNvAEL8/gggXFKCTfWQxhM152IbY+lqKFN1MxIZGIxg/QJC+JGSfE2wZbC8epG4h83q+LJ0mS7A+2bLD8+I3FGGbcPalEgKE5dcD3wn208nBljThH138Qy1qDIFHk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1720504499767539.2878159662432; Mon, 8 Jul 2024 22:54:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.755751.1164209 (Exim 4.92) (envelope-from ) id 1sR3oJ-0001T4-KF; Tue, 09 Jul 2024 05:54:43 +0000 Received: by outflank-mailman (output) from mailman id 755751.1164209; Tue, 09 Jul 2024 05:54:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3oJ-0001Sx-FA; Tue, 09 Jul 2024 05:54:43 +0000 Received: by outflank-mailman (input) for mailman id 755751; Tue, 09 Jul 2024 05:54:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3oI-0001So-JW for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 05:54:42 +0000 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id babed62a-3db7-11ef-8776-851b0ebba9a2; Tue, 09 Jul 2024 07:54:40 +0200 (CEST) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id E72AB26FC2; Tue, 9 Jul 2024 01:54:38 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id CE49926FC1; Tue, 9 Jul 2024 01:54:38 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 440D226FC0; Tue, 9 Jul 2024 01:54:37 -0400 (EDT) (envelope-from sakib@darkstar.site) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: babed62a-3db7-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=DDNDkiZVLdutMBS7Fc+YynLKX qz7hyMKSP5XW4Bwk6o=; b=vK63Z7oPVwGdF/tt9S48HYUwtZIToqrBQ/gTC6LCp cD3E6pWlaJPcU0y15uIVj/wwocIBvd9hyY7U16TW21sv1c67x7OLJSQHS4U1x/Gz itOHJ+P+EMuY6kBLPRgQDkf8raTlzAuYzxTay//o1gelp4QBwR9bvHMJRfByRv2a 3g= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jan Beulich , Stefano Stabellini , Xenia Ragiadakou Subject: [XEN PATCH v4 05/14] x86: introduce using_{svm,vmx}() helpers Date: Tue, 9 Jul 2024 08:54:34 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: B98AD47E-3DB7-11EF-8880-965B910A682E-90055647!pb-smtp2.pobox.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @pobox.com) X-ZM-MESSAGEID: 1720504501173100001 Content-Type: text/plain; charset="utf-8" As we now have SVM/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 do= ing 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 VMX=3Dn or S= VM=3Dn. Signed-off-by: Sergiy Kibrik CC: Jan Beulich Reviewed-by: Jan Beulich --- changes in v4: - make using_{vmx,svm} static inline functions instead of macros - squash patch with 2 other patches where using_{vmx,svm} are being used - changed patch description changes in v3: - introduce separate macros instead of modifying behaviour of cpu_has_{vmx= ,svm} --- xen/arch/x86/hvm/hvm.c | 4 ++-- xen/arch/x86/hvm/nestedhvm.c | 4 ++-- xen/arch/x86/include/asm/hvm/hvm.h | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 7f4b627b1f..057c61b4c3 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -155,9 +155,9 @@ static int __init cf_check hvm_enable(void) { const struct hvm_function_table *fns =3D NULL; =20 - if ( cpu_has_vmx ) + if ( using_vmx() ) fns =3D start_vmx(); - else if ( cpu_has_svm ) + else if ( using_svm() ) fns =3D start_svm(); =20 if ( fns =3D=3D NULL ) diff --git a/xen/arch/x86/hvm/nestedhvm.c b/xen/arch/x86/hvm/nestedhvm.c index 451c4da6d4..5009167372 100644 --- a/xen/arch/x86/hvm/nestedhvm.c +++ b/xen/arch/x86/hvm/nestedhvm.c @@ -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); =20 return 0; diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/= hvm/hvm.h index 34824af6df..2927a2ad6c 100644 --- a/xen/arch/x86/include/asm/hvm/hvm.h +++ b/xen/arch/x86/include/asm/hvm/hvm.h @@ -363,6 +363,16 @@ int hvm_copy_context_and_params(struct domain *dst, st= ruct domain *src); =20 int hvm_get_param(struct domain *d, uint32_t index, uint64_t *value); =20 +static inline bool using_vmx(void) +{ + return IS_ENABLED(CONFIG_VMX) && cpu_has_vmx; +} + +static inline bool using_svm(void) +{ + return IS_ENABLED(CONFIG_SVM) && cpu_has_svm; +} + #ifdef CONFIG_HVM =20 #define hvm_get_guest_tsc(v) hvm_get_guest_tsc_fixed(v, 0) --=20 2.25.1