@@ -85,6 +85,10 @@ static DECLARE_RWSEM(sev_deactivate_lock);
8585static DEFINE_MUTEX (sev_bitmap_lock );
8686unsigned int max_sev_asid ;
8787static unsigned int min_sev_asid ;
88+ static unsigned int max_sev_es_asid ;
89+ static unsigned int min_sev_es_asid ;
90+ static unsigned int max_snp_asid ;
91+ static unsigned int min_snp_asid ;
8892static unsigned long sev_me_mask ;
8993static unsigned int nr_asids ;
9094static unsigned long * sev_asid_bitmap ;
@@ -173,20 +177,31 @@ static void sev_misc_cg_uncharge(struct kvm_sev_info *sev)
173177 misc_cg_uncharge (type , sev -> misc_cg , 1 );
174178}
175179
176- static int sev_asid_new (struct kvm_sev_info * sev )
180+ static int sev_asid_new (struct kvm_sev_info * sev , unsigned long vm_type )
177181{
178182 /*
179183 * SEV-enabled guests must use asid from min_sev_asid to max_sev_asid.
180184 * SEV-ES-enabled guest can use from 1 to min_sev_asid - 1.
181- * Note: min ASID can end up larger than the max if basic SEV support is
182- * effectively disabled by disallowing use of ASIDs for SEV guests.
183185 */
184- unsigned int min_asid = sev -> es_active ? 1 : min_sev_asid ;
185- unsigned int max_asid = sev -> es_active ? min_sev_asid - 1 : max_sev_asid ;
186- unsigned int asid ;
186+ unsigned int min_asid , max_asid , asid ;
187187 bool retry = true;
188188 int ret ;
189189
190+ if (vm_type == KVM_X86_SNP_VM ) {
191+ min_asid = min_snp_asid ;
192+ max_asid = max_snp_asid ;
193+ } else if (sev -> es_active ) {
194+ min_asid = min_sev_es_asid ;
195+ max_asid = max_sev_es_asid ;
196+ } else {
197+ min_asid = min_sev_asid ;
198+ max_asid = max_sev_asid ;
199+ }
200+
201+ /*
202+ * The min ASID can end up larger than the max if basic SEV support is
203+ * effectively disabled by disallowing use of ASIDs for SEV guests.
204+ */
190205 if (min_asid > max_asid )
191206 return - ENOTTY ;
192207
@@ -440,7 +455,7 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
440455 if (vm_type == KVM_X86_SNP_VM )
441456 sev -> vmsa_features |= SVM_SEV_FEAT_SNP_ACTIVE ;
442457
443- ret = sev_asid_new (sev );
458+ ret = sev_asid_new (sev , vm_type );
444459 if (ret )
445460 goto e_no_asid ;
446461
@@ -3042,6 +3057,9 @@ void __init sev_hardware_setup(void)
30423057 if (min_sev_asid == 1 )
30433058 goto out ;
30443059
3060+ min_sev_es_asid = min_snp_asid = 1 ;
3061+ max_sev_es_asid = max_snp_asid = min_sev_asid - 1 ;
3062+
30453063 sev_es_asid_count = min_sev_asid - 1 ;
30463064 WARN_ON_ONCE (misc_cg_set_capacity (MISC_CG_RES_SEV_ES , sev_es_asid_count ));
30473065 sev_es_supported = true;
@@ -3065,11 +3083,11 @@ void __init sev_hardware_setup(void)
30653083 if (boot_cpu_has (X86_FEATURE_SEV_ES ))
30663084 pr_info ("SEV-ES %s (ASIDs %u - %u)\n" ,
30673085 str_enabled_disabled (sev_es_supported ),
3068- min_sev_asid > 1 ? 1 : 0 , min_sev_asid - 1 );
3086+ min_sev_es_asid , max_sev_es_asid );
30693087 if (boot_cpu_has (X86_FEATURE_SEV_SNP ))
30703088 pr_info ("SEV-SNP %s (ASIDs %u - %u)\n" ,
30713089 str_enabled_disabled (sev_snp_supported ),
3072- min_sev_asid > 1 ? 1 : 0 , min_sev_asid - 1 );
3090+ min_snp_asid , max_snp_asid );
30733091
30743092 sev_enabled = sev_supported ;
30753093 sev_es_enabled = sev_es_supported ;
0 commit comments