Commit 32071fa3 authored by Sean Christopherson's avatar Sean Christopherson

KVM: SVM: Track the per-CPU host save area as a VMCB pointer

The host save area is a VMCB, track it as such to help readers follow
along, but mostly to cleanup/simplify the retrieval of the SEV-ES host
save area.

Note, the compile-time assertion that

  offsetof(struct vmcb, save) == EXPECTED_VMCB_CONTROL_AREA_SIZE

ensures that the SEV-ES save area is indeed at offset 0x400 (whoever added
the expected/architectural VMCB offsets apparently likes decimal).

No functional change intended.

Link: https://lore.kernel.org/r/20240802204511.352017-4-seanjc@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 1b5ef14d
...@@ -573,7 +573,7 @@ static void __svm_write_tsc_multiplier(u64 multiplier) ...@@ -573,7 +573,7 @@ static void __svm_write_tsc_multiplier(u64 multiplier)
static __always_inline struct sev_es_save_area *sev_es_host_save_area(struct svm_cpu_data *sd) static __always_inline struct sev_es_save_area *sev_es_host_save_area(struct svm_cpu_data *sd)
{ {
return page_address(sd->save_area) + 0x400; return &sd->save_area->host_sev_es_save;
} }
static inline void kvm_cpu_svm_disable(void) static inline void kvm_cpu_svm_disable(void)
...@@ -696,7 +696,7 @@ static void svm_cpu_uninit(int cpu) ...@@ -696,7 +696,7 @@ static void svm_cpu_uninit(int cpu)
return; return;
kfree(sd->sev_vmcbs); kfree(sd->sev_vmcbs);
__free_page(sd->save_area); __free_page(__sme_pa_to_page(sd->save_area_pa));
sd->save_area_pa = 0; sd->save_area_pa = 0;
sd->save_area = NULL; sd->save_area = NULL;
} }
...@@ -704,23 +704,24 @@ static void svm_cpu_uninit(int cpu) ...@@ -704,23 +704,24 @@ static void svm_cpu_uninit(int cpu)
static int svm_cpu_init(int cpu) static int svm_cpu_init(int cpu)
{ {
struct svm_cpu_data *sd = per_cpu_ptr(&svm_data, cpu); struct svm_cpu_data *sd = per_cpu_ptr(&svm_data, cpu);
struct page *save_area_page;
int ret = -ENOMEM; int ret = -ENOMEM;
memset(sd, 0, sizeof(struct svm_cpu_data)); memset(sd, 0, sizeof(struct svm_cpu_data));
sd->save_area = snp_safe_alloc_page_node(cpu_to_node(cpu), GFP_KERNEL); save_area_page = snp_safe_alloc_page_node(cpu_to_node(cpu), GFP_KERNEL);
if (!sd->save_area) if (!save_area_page)
return ret; return ret;
ret = sev_cpu_init(sd); ret = sev_cpu_init(sd);
if (ret) if (ret)
goto free_save_area; goto free_save_area;
sd->save_area_pa = __sme_page_pa(sd->save_area); sd->save_area = page_address(save_area_page);
sd->save_area_pa = __sme_page_pa(save_area_page);
return 0; return 0;
free_save_area: free_save_area:
__free_page(sd->save_area); __free_page(save_area_page);
sd->save_area = NULL;
return ret; return ret;
} }
......
...@@ -335,7 +335,7 @@ struct svm_cpu_data { ...@@ -335,7 +335,7 @@ struct svm_cpu_data {
u32 next_asid; u32 next_asid;
u32 min_asid; u32 min_asid;
struct page *save_area; struct vmcb *save_area;
unsigned long save_area_pa; unsigned long save_area_pa;
struct vmcb *current_vmcb; struct vmcb *current_vmcb;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment