Skip to content

Commit 32071fa

Browse files
committed
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.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 1b5ef14 commit 32071fa

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static void __svm_write_tsc_multiplier(u64 multiplier)
573573

574574
static __always_inline struct sev_es_save_area *sev_es_host_save_area(struct svm_cpu_data *sd)
575575
{
576-
return page_address(sd->save_area) + 0x400;
576+
return &sd->save_area->host_sev_es_save;
577577
}
578578

579579
static inline void kvm_cpu_svm_disable(void)
@@ -696,31 +696,32 @@ static void svm_cpu_uninit(int cpu)
696696
return;
697697

698698
kfree(sd->sev_vmcbs);
699-
__free_page(sd->save_area);
699+
__free_page(__sme_pa_to_page(sd->save_area_pa));
700700
sd->save_area_pa = 0;
701701
sd->save_area = NULL;
702702
}
703703

704704
static int svm_cpu_init(int cpu)
705705
{
706706
struct svm_cpu_data *sd = per_cpu_ptr(&svm_data, cpu);
707+
struct page *save_area_page;
707708
int ret = -ENOMEM;
708709

709710
memset(sd, 0, sizeof(struct svm_cpu_data));
710-
sd->save_area = snp_safe_alloc_page_node(cpu_to_node(cpu), GFP_KERNEL);
711-
if (!sd->save_area)
711+
save_area_page = snp_safe_alloc_page_node(cpu_to_node(cpu), GFP_KERNEL);
712+
if (!save_area_page)
712713
return ret;
713714

714715
ret = sev_cpu_init(sd);
715716
if (ret)
716717
goto free_save_area;
717718

718-
sd->save_area_pa = __sme_page_pa(sd->save_area);
719+
sd->save_area = page_address(save_area_page);
720+
sd->save_area_pa = __sme_page_pa(save_area_page);
719721
return 0;
720722

721723
free_save_area:
722-
__free_page(sd->save_area);
723-
sd->save_area = NULL;
724+
__free_page(save_area_page);
724725
return ret;
725726

726727
}

arch/x86/kvm/svm/svm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ struct svm_cpu_data {
335335
u32 next_asid;
336336
u32 min_asid;
337337

338-
struct page *save_area;
338+
struct vmcb *save_area;
339339
unsigned long save_area_pa;
340340

341341
struct vmcb *current_vmcb;

0 commit comments

Comments
 (0)