]> Git Repo - J-linux.git/commitdiff
KVM: SVM: Track the per-CPU host save area as a VMCB pointer
authorSean Christopherson <[email protected]>
Fri, 2 Aug 2024 20:45:11 +0000 (13:45 -0700)
committerSean Christopherson <[email protected]>
Fri, 30 Aug 2024 02:06:12 +0000 (19:06 -0700)
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/[email protected]
Signed-off-by: Sean Christopherson <[email protected]>
arch/x86/kvm/svm/svm.c
arch/x86/kvm/svm/svm.h

index dd1cfee3e38fc7ac733cce37a5d92ba25f7e1741..cac9e36960cad1d40c3baf28e996e8ac93d4500f 100644 (file)
@@ -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)
 {
-       return page_address(sd->save_area) + 0x400;
+       return &sd->save_area->host_sev_es_save;
 }
 
 static inline void kvm_cpu_svm_disable(void)
@@ -696,7 +696,7 @@ static void svm_cpu_uninit(int cpu)
                return;
 
        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 = NULL;
 }
@@ -704,23 +704,24 @@ static void svm_cpu_uninit(int cpu)
 static int svm_cpu_init(int cpu)
 {
        struct svm_cpu_data *sd = per_cpu_ptr(&svm_data, cpu);
+       struct page *save_area_page;
        int ret = -ENOMEM;
 
        memset(sd, 0, sizeof(struct svm_cpu_data));
-       sd->save_area = snp_safe_alloc_page_node(cpu_to_node(cpu), GFP_KERNEL);
-       if (!sd->save_area)
+       save_area_page = snp_safe_alloc_page_node(cpu_to_node(cpu), GFP_KERNEL);
+       if (!save_area_page)
                return ret;
 
        ret = sev_cpu_init(sd);
        if (ret)
                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;
 
 free_save_area:
-       __free_page(sd->save_area);
-       sd->save_area = NULL;
+       __free_page(save_area_page);
        return ret;
 
 }
index 2b095acdb97f1f807569de59895a0f24823af0a6..43fa6a16eb1917821945ca8fdebf1caff1ddcb54 100644 (file)
@@ -335,7 +335,7 @@ struct svm_cpu_data {
        u32 next_asid;
        u32 min_asid;
 
-       struct page *save_area;
+       struct vmcb *save_area;
        unsigned long save_area_pa;
 
        struct vmcb *current_vmcb;
This page took 0.065434 seconds and 4 git commands to generate.