From: Ashish Kalra <Ashish.Kalra@amd.com>
To: <pbonzini@redhat.com>
Cc: <seanjc@google.com>, <tglx@linutronix.de>, <mingo@redhat.com>,
<bp@alien8.de>, <dave.hansen@linux.intel.com>, <x86@kernel.org>,
<hpa@zytor.com>, <thomas.lendacky@amd.com>, <kvm@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <joro@8bytes.org>
Subject: [PATCH] x86/sev: Add support for allowing zero SEV ASIDs.
Date: Tue, 2 Jan 2024 23:21:36 +0000 [thread overview]
Message-ID: <20240102232136.38778-1-Ashish.Kalra@amd.com> (raw)
From: Ashish Kalra <ashish.kalra@amd.com>
Some BIOSes allow the end user to set the minimum SEV ASID value
(CPUID 0x8000001F_EDX) to be greater than the maximum number of
encrypted guests, or maximum SEV ASID value (CPUID 0x8000001F_ECX)
in order to dedicate all the SEV ASIDs to SEV-ES or SEV-SNP.
The SEV support, as coded, does not handle the case where the minimum
SEV ASID value can be greater than the maximum SEV ASID value.
As a result, the following confusing message is issued:
[ 30.715724] kvm_amd: SEV enabled (ASIDs 1007 - 1006)
Fix the support to properly handle this case.
Fixes: 916391a2d1dc ("KVM: SVM: Add support for SEV-ES capability in KVM")
Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
Cc: stable@vger.kernel.org
---
arch/x86/kvm/svm/sev.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 4900c078045a..ad41008ca0d9 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -59,10 +59,14 @@ module_param_named(sev_es, sev_es_enabled, bool, 0444);
/* enable/disable SEV-ES DebugSwap support */
static bool sev_es_debug_swap_enabled = true;
module_param_named(debug_swap, sev_es_debug_swap_enabled, bool, 0444);
+
+/* When true, at least one type of SEV guest is enabled to run */
+static bool sev_guests_enabled;
#else
#define sev_enabled false
#define sev_es_enabled false
#define sev_es_debug_swap_enabled false
+#define sev_guests_enabled false
#endif /* CONFIG_KVM_AMD_SEV */
static u8 sev_enc_bit;
@@ -1854,7 +1858,7 @@ int sev_mem_enc_ioctl(struct kvm *kvm, void __user *argp)
struct kvm_sev_cmd sev_cmd;
int r;
- if (!sev_enabled)
+ if (!sev_guests_enabled)
return -ENOTTY;
if (!argp)
@@ -2172,8 +2176,10 @@ void sev_vm_destroy(struct kvm *kvm)
void __init sev_set_cpu_caps(void)
{
- if (!sev_enabled)
+ if (!sev_guests_enabled) {
kvm_cpu_cap_clear(X86_FEATURE_SEV);
+ return;
+ }
if (!sev_es_enabled)
kvm_cpu_cap_clear(X86_FEATURE_SEV_ES);
}
@@ -2229,9 +2235,11 @@ void __init sev_hardware_setup(void)
goto out;
}
- sev_asid_count = max_sev_asid - min_sev_asid + 1;
- WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count));
- sev_supported = true;
+ if (min_sev_asid <= max_sev_asid) {
+ sev_asid_count = max_sev_asid - min_sev_asid + 1;
+ WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count));
+ sev_supported = true;
+ }
/* SEV-ES support requested? */
if (!sev_es_enabled)
@@ -2262,7 +2270,8 @@ void __init sev_hardware_setup(void)
if (boot_cpu_has(X86_FEATURE_SEV))
pr_info("SEV %s (ASIDs %u - %u)\n",
sev_supported ? "enabled" : "disabled",
- min_sev_asid, max_sev_asid);
+ sev_supported ? min_sev_asid : 0,
+ sev_supported ? max_sev_asid : 0);
if (boot_cpu_has(X86_FEATURE_SEV_ES))
pr_info("SEV-ES %s (ASIDs %u - %u)\n",
sev_es_supported ? "enabled" : "disabled",
@@ -2270,6 +2279,7 @@ void __init sev_hardware_setup(void)
sev_enabled = sev_supported;
sev_es_enabled = sev_es_supported;
+ sev_guests_enabled = sev_enabled || sev_es_enabled;
if (!sev_es_enabled || !cpu_feature_enabled(X86_FEATURE_DEBUG_SWAP) ||
!cpu_feature_enabled(X86_FEATURE_NO_NESTED_DATA_BP))
sev_es_debug_swap_enabled = false;
@@ -2278,7 +2288,7 @@ void __init sev_hardware_setup(void)
void sev_hardware_unsetup(void)
{
- if (!sev_enabled)
+ if (!sev_guests_enabled)
return;
/* No need to take sev_bitmap_lock, all VMs have been destroyed. */
@@ -2293,7 +2303,7 @@ void sev_hardware_unsetup(void)
int sev_cpu_init(struct svm_cpu_data *sd)
{
- if (!sev_enabled)
+ if (!sev_guests_enabled)
return 0;
sd->sev_vmcbs = kcalloc(nr_asids, sizeof(void *), GFP_KERNEL);
--
2.34.1
next reply other threads:[~2024-01-02 23:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-02 23:21 Ashish Kalra [this message]
2024-01-03 0:30 ` [PATCH] x86/sev: Add support for allowing zero SEV ASIDs Sean Christopherson
2024-01-03 20:41 ` Kalra, Ashish
2024-01-03 21:10 ` Sean Christopherson
2024-01-03 21:22 ` Kalra, Ashish
2024-01-03 21:54 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240102232136.38778-1-Ashish.Kalra@amd.com \
--to=ashish.kalra@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox