Skip to content

Commit

Permalink
KVM: SVM: Move SEV VMCB tracking allocation to sev.c
Browse files Browse the repository at this point in the history
Move the allocation of the SEV VMCB array to sev.c to help pave the way
toward encapsulating SEV enabling wholly within sev.c.

No functional change intended.

Reviewed by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210422021125.3417167-13-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Sean Christopherson authored and Paolo Bonzini committed Apr 26, 2021
1 parent 8cb756b commit b95c221
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
12 changes: 12 additions & 0 deletions arch/x86/kvm/svm/sev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,18 @@ void sev_hardware_teardown(void)
sev_flush_asids();
}

int sev_cpu_init(struct svm_cpu_data *sd)
{
if (!svm_sev_enabled())
return 0;

sd->sev_vmcbs = kcalloc(max_sev_asid + 1, sizeof(void *), GFP_KERNEL);
if (!sd->sev_vmcbs)
return -ENOMEM;

return 0;
}

/*
* Pages used by hardware to hold guest encrypted state must be flushed before
* returning them to the system.
Expand Down
15 changes: 7 additions & 8 deletions arch/x86/kvm/svm/svm.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,22 +553,21 @@ static void svm_cpu_uninit(int cpu)
static int svm_cpu_init(int cpu)
{
struct svm_cpu_data *sd;
int ret = -ENOMEM;

sd = kzalloc(sizeof(struct svm_cpu_data), GFP_KERNEL);
if (!sd)
return -ENOMEM;
return ret;
sd->cpu = cpu;
sd->save_area = alloc_page(GFP_KERNEL);
if (!sd->save_area)
goto free_cpu_data;

clear_page(page_address(sd->save_area));

if (svm_sev_enabled()) {
sd->sev_vmcbs = kcalloc(max_sev_asid + 1, sizeof(void *),
GFP_KERNEL);
if (!sd->sev_vmcbs)
goto free_save_area;
}
ret = sev_cpu_init(sd);
if (ret)
goto free_save_area;

per_cpu(svm_data, cpu) = sd;

Expand All @@ -578,7 +577,7 @@ static int svm_cpu_init(int cpu)
__free_page(sd->save_area);
free_cpu_data:
kfree(sd);
return -ENOMEM;
return ret;

}

Expand Down
1 change: 1 addition & 0 deletions arch/x86/kvm/svm/svm.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ void pre_sev_run(struct vcpu_svm *svm, int cpu);
void __init sev_set_cpu_caps(void);
void __init sev_hardware_setup(void);
void sev_hardware_teardown(void);
int sev_cpu_init(struct svm_cpu_data *sd);
void sev_free_vcpu(struct kvm_vcpu *vcpu);
int sev_handle_vmgexit(struct kvm_vcpu *vcpu);
int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in);
Expand Down

0 comments on commit b95c221

Please sign in to comment.