Skip to content

Commit ce7ea0c

Browse files
tlendackybonzini
authored andcommitted
KVM: SVM: Move GHCB unmapping to fix RCU warning
When an SEV-ES guest is running, the GHCB is unmapped as part of the vCPU run support. However, kvm_vcpu_unmap() triggers an RCU dereference warning with CONFIG_PROVE_LOCKING=y because the SRCU lock is released before invoking the vCPU run support. Move the GHCB unmapping into the prepare_guest_switch callback, which is invoked while still holding the SRCU lock, eliminating the RCU dereference warning. Fixes: 291bd20 ("KVM: SVM: Add initial support for a VMGEXIT VMEXIT") Reported-by: Borislav Petkov <[email protected]> Signed-off-by: Tom Lendacky <[email protected]> Message-Id: <b2f9b79d15166f2c3e4375c0d9bc3268b7696455.1620332081.git.thomas.lendacky@amd.com> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 368340a commit ce7ea0c

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,7 @@ static int sev_es_validate_vmgexit(struct vcpu_svm *svm)
21972197
return -EINVAL;
21982198
}
21992199

2200-
static void pre_sev_es_run(struct vcpu_svm *svm)
2200+
void sev_es_unmap_ghcb(struct vcpu_svm *svm)
22012201
{
22022202
if (!svm->ghcb)
22032203
return;
@@ -2233,9 +2233,6 @@ void pre_sev_run(struct vcpu_svm *svm, int cpu)
22332233
struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
22342234
int asid = sev_get_asid(svm->vcpu.kvm);
22352235

2236-
/* Perform any SEV-ES pre-run actions */
2237-
pre_sev_es_run(svm);
2238-
22392236
/* Assign the asid allocated with this SEV guest */
22402237
svm->asid = asid;
22412238

arch/x86/kvm/svm/svm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,9 @@ static void svm_prepare_guest_switch(struct kvm_vcpu *vcpu)
14371437
struct vcpu_svm *svm = to_svm(vcpu);
14381438
struct svm_cpu_data *sd = per_cpu(svm_data, vcpu->cpu);
14391439

1440+
if (sev_es_guest(vcpu->kvm))
1441+
sev_es_unmap_ghcb(svm);
1442+
14401443
if (svm->guest_state_loaded)
14411444
return;
14421445

arch/x86/kvm/svm/svm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ void sev_es_init_vmcb(struct vcpu_svm *svm);
581581
void sev_es_create_vcpu(struct vcpu_svm *svm);
582582
void sev_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector);
583583
void sev_es_prepare_guest_switch(struct vcpu_svm *svm, unsigned int cpu);
584+
void sev_es_unmap_ghcb(struct vcpu_svm *svm);
584585

585586
/* vmenter.S */
586587

0 commit comments

Comments
 (0)