Skip to content

Commit d04c77d

Browse files
committed
KVM: guest_memfd: delay folio_mark_uptodate() until after successful preparation
The up-to-date flag as is now is not too useful; it tells guest_memfd not to overwrite the contents of a folio, but it doesn't say that the page is ready to be mapped into the guest. For encrypted guests, mapping a private page requires that the "preparation" phase has succeeded, and at the same time the same page cannot be prepared twice. So, ensure that folio_mark_uptodate() is only called on a prepared page. If kvm_gmem_prepare_folio() or the post_populate callback fail, the folio will not be marked up-to-date; it's not a problem to call clear_highpage() again on such a page prior to the next preparation attempt. Reviewed-by: Michael Roth <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent d0d8722 commit d04c77d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

virt/kvm/guest_memfd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index, bool
7373

7474
for (i = 0; i < nr_pages; i++)
7575
clear_highpage(folio_page(folio, i));
76-
77-
folio_mark_uptodate(folio);
7876
}
7977

8078
if (prepare) {
@@ -84,6 +82,8 @@ static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index, bool
8482
folio_put(folio);
8583
return ERR_PTR(r);
8684
}
85+
86+
folio_mark_uptodate(folio);
8787
}
8888

8989
/*
@@ -646,6 +646,8 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long
646646

647647
p = src ? src + i * PAGE_SIZE : NULL;
648648
ret = post_populate(kvm, gfn, pfn, p, max_order, opaque);
649+
if (!ret)
650+
folio_mark_uptodate(folio);
649651

650652
folio_put(folio);
651653
if (ret)

0 commit comments

Comments
 (0)