lkml.org 
[lkml]   [2021]   [Jul]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH Part2 RFC v4 25/40] KVM: SVM: Reclaim the guest pages when SEV-SNP VM terminates
    Date
    The guest pages of the SEV-SNP VM maybe added as a private page in the
    RMP entry (assigned bit is set). The guest private pages must be
    transitioned to the hypervisor state before its freed.

    Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
    ---
    arch/x86/kvm/svm/sev.c | 39 +++++++++++++++++++++++++++++++++++++++
    1 file changed, 39 insertions(+)

    diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
    index 1f0635ac9ff9..4468995dd209 100644
    --- a/arch/x86/kvm/svm/sev.c
    +++ b/arch/x86/kvm/svm/sev.c
    @@ -1940,6 +1940,45 @@ find_enc_region(struct kvm *kvm, struct kvm_enc_region *range)
    static void __unregister_enc_region_locked(struct kvm *kvm,
    struct enc_region *region)
    {
    + struct rmpupdate val = {};
    + unsigned long i, pfn;
    + struct rmpentry *e;
    + int level, rc;
    +
    + /*
    + * The guest memory pages are assigned in the RMP table. Unassign it
    + * before releasing the memory.
    + */
    + if (sev_snp_guest(kvm)) {
    + for (i = 0; i < region->npages; i++) {
    + pfn = page_to_pfn(region->pages[i]);
    +
    + if (need_resched())
    + schedule();
    +
    + e = snp_lookup_page_in_rmptable(region->pages[i], &level);
    + if (unlikely(!e))
    + continue;
    +
    + /* If its not a guest assigned page then skip it. */
    + if (!rmpentry_assigned(e))
    + continue;
    +
    + /* Is the page part of a 2MB RMP entry? */
    + if (level == PG_LEVEL_2M) {
    + val.pagesize = RMP_PG_SIZE_2M;
    + pfn &= ~(KVM_PAGES_PER_HPAGE(PG_LEVEL_2M) - 1);
    + } else {
    + val.pagesize = RMP_PG_SIZE_4K;
    + }
    +
    + /* Transition the page to hypervisor owned. */
    + rc = rmpupdate(pfn_to_page(pfn), &val);
    + if (rc)
    + pr_err("Failed to release pfn 0x%lx ret=%d\n", pfn, rc);
    + }
    + }
    +
    sev_unpin_memory(kvm, region->pages, region->npages);
    list_del(&region->list);
    kfree(region);
    --
    2.17.1
    \
     
     \ /
      Last update: 2021-07-07 20:39    [W:3.911 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site