mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 18:21:24 +02:00
KVM: SVM: Add support for allowing zero SEV ASIDs
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: 916391a2d1 ("KVM: SVM: Add support for SEV-ES capability in KVM")
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
Cc: stable@vger.kernel.org
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Link: https://lore.kernel.org/r/20240104190520.62510-1-Ashish.Kalra@amd.com
Link: https://lore.kernel.org/r/20240131235609.4161407-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
466eec4a22
commit
0aa6b90ef9
|
|
@ -144,10 +144,21 @@ static void sev_misc_cg_uncharge(struct kvm_sev_info *sev)
|
||||||
|
|
||||||
static int sev_asid_new(struct kvm_sev_info *sev)
|
static int sev_asid_new(struct kvm_sev_info *sev)
|
||||||
{
|
{
|
||||||
unsigned int asid, min_asid, max_asid;
|
/*
|
||||||
|
* SEV-enabled guests must use asid from min_sev_asid to max_sev_asid.
|
||||||
|
* SEV-ES-enabled guest can use from 1 to min_sev_asid - 1.
|
||||||
|
* Note: min ASID can end up larger than the max if basic SEV support is
|
||||||
|
* effectively disabled by disallowing use of ASIDs for SEV guests.
|
||||||
|
*/
|
||||||
|
unsigned int min_asid = sev->es_active ? 1 : min_sev_asid;
|
||||||
|
unsigned int max_asid = sev->es_active ? min_sev_asid - 1 : max_sev_asid;
|
||||||
|
unsigned int asid;
|
||||||
bool retry = true;
|
bool retry = true;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (min_asid > max_asid)
|
||||||
|
return -ENOTTY;
|
||||||
|
|
||||||
WARN_ON(sev->misc_cg);
|
WARN_ON(sev->misc_cg);
|
||||||
sev->misc_cg = get_current_misc_cg();
|
sev->misc_cg = get_current_misc_cg();
|
||||||
ret = sev_misc_cg_try_charge(sev);
|
ret = sev_misc_cg_try_charge(sev);
|
||||||
|
|
@ -159,12 +170,6 @@ static int sev_asid_new(struct kvm_sev_info *sev)
|
||||||
|
|
||||||
mutex_lock(&sev_bitmap_lock);
|
mutex_lock(&sev_bitmap_lock);
|
||||||
|
|
||||||
/*
|
|
||||||
* SEV-enabled guests must use asid from min_sev_asid to max_sev_asid.
|
|
||||||
* SEV-ES-enabled guest can use from 1 to min_sev_asid - 1.
|
|
||||||
*/
|
|
||||||
min_asid = sev->es_active ? 1 : min_sev_asid;
|
|
||||||
max_asid = sev->es_active ? min_sev_asid - 1 : max_sev_asid;
|
|
||||||
again:
|
again:
|
||||||
asid = find_next_zero_bit(sev_asid_bitmap, max_asid + 1, min_asid);
|
asid = find_next_zero_bit(sev_asid_bitmap, max_asid + 1, min_asid);
|
||||||
if (asid > max_asid) {
|
if (asid > max_asid) {
|
||||||
|
|
@ -2234,8 +2239,10 @@ void __init sev_hardware_setup(void)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
sev_asid_count = max_sev_asid - min_sev_asid + 1;
|
if (min_sev_asid <= max_sev_asid) {
|
||||||
WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count));
|
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_supported = true;
|
||||||
|
|
||||||
/* SEV-ES support requested? */
|
/* SEV-ES support requested? */
|
||||||
|
|
@ -2266,7 +2273,9 @@ void __init sev_hardware_setup(void)
|
||||||
out:
|
out:
|
||||||
if (boot_cpu_has(X86_FEATURE_SEV))
|
if (boot_cpu_has(X86_FEATURE_SEV))
|
||||||
pr_info("SEV %s (ASIDs %u - %u)\n",
|
pr_info("SEV %s (ASIDs %u - %u)\n",
|
||||||
sev_supported ? "enabled" : "disabled",
|
sev_supported ? min_sev_asid <= max_sev_asid ? "enabled" :
|
||||||
|
"unusable" :
|
||||||
|
"disabled",
|
||||||
min_sev_asid, max_sev_asid);
|
min_sev_asid, max_sev_asid);
|
||||||
if (boot_cpu_has(X86_FEATURE_SEV_ES))
|
if (boot_cpu_has(X86_FEATURE_SEV_ES))
|
||||||
pr_info("SEV-ES %s (ASIDs %u - %u)\n",
|
pr_info("SEV-ES %s (ASIDs %u - %u)\n",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user