Skip to content

Commit a655276

Browse files
sean-jcbonzini
authored andcommitted
KVM: SEV: Fall back to vmalloc for SEV-ES scratch area if necessary
Use kvzalloc() to allocate KVM's buffer for SEV-ES's GHCB scratch area so that KVM falls back to __vmalloc() if physically contiguous memory isn't available. The buffer is purely a KVM software construct, i.e. there's no need for it to be physically contiguous. Cc: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20211109222350.2266045-3-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 75236f5 commit a655276

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,7 +2260,7 @@ void sev_free_vcpu(struct kvm_vcpu *vcpu)
22602260
__free_page(virt_to_page(svm->sev_es.vmsa));
22612261

22622262
if (svm->sev_es.ghcb_sa_free)
2263-
kfree(svm->sev_es.ghcb_sa);
2263+
kvfree(svm->sev_es.ghcb_sa);
22642264
}
22652265

22662266
static void dump_ghcb(struct vcpu_svm *svm)
@@ -2493,7 +2493,7 @@ void sev_es_unmap_ghcb(struct vcpu_svm *svm)
24932493
svm->sev_es.ghcb_sa_sync = false;
24942494
}
24952495

2496-
kfree(svm->sev_es.ghcb_sa);
2496+
kvfree(svm->sev_es.ghcb_sa);
24972497
svm->sev_es.ghcb_sa = NULL;
24982498
svm->sev_es.ghcb_sa_free = false;
24992499
}
@@ -2581,15 +2581,15 @@ static int setup_vmgexit_scratch(struct vcpu_svm *svm, bool sync, u64 len)
25812581
len, GHCB_SCRATCH_AREA_LIMIT);
25822582
return -EINVAL;
25832583
}
2584-
scratch_va = kzalloc(len, GFP_KERNEL_ACCOUNT);
2584+
scratch_va = kvzalloc(len, GFP_KERNEL_ACCOUNT);
25852585
if (!scratch_va)
25862586
return -ENOMEM;
25872587

25882588
if (kvm_read_guest(svm->vcpu.kvm, scratch_gpa_beg, scratch_va, len)) {
25892589
/* Unable to copy scratch area from guest */
25902590
pr_err("vmgexit: kvm_read_guest for scratch area failed\n");
25912591

2592-
kfree(scratch_va);
2592+
kvfree(scratch_va);
25932593
return -EFAULT;
25942594
}
25952595

0 commit comments

Comments
 (0)