linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: SVM: Mark SEV launch secret pages as dirty.
@ 2020-08-07  1:23 Cfir Cohen
  2020-08-07 17:55 ` David Rientjes
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Cfir Cohen @ 2020-08-07  1:23 UTC (permalink / raw)
  To: kvm @ vger . kernel . org, Lendacky Thomas, Singh Brijesh
  Cc: Grimm Jon, David Rientjes, Paolo Bonzini, Sean Christopherson,
	Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin,
	x86, linux-kernel, Cfir Cohen

The LAUNCH_SECRET command performs encryption of the
launch secret memory contents. Mark pinned pages as
dirty, before unpinning them.
This matches the logic in sev_launch_update().

Signed-off-by: Cfir Cohen <cfir@google.com>
---
 arch/x86/kvm/svm/sev.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 5573a97f1520..37c47d26b9f7 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -850,7 +850,7 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp)
 	struct kvm_sev_launch_secret params;
 	struct page **pages;
 	void *blob, *hdr;
-	unsigned long n;
+	unsigned long n, i;
 	int ret, offset;
 
 	if (!sev_guest(kvm))
@@ -863,6 +863,14 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp)
 	if (!pages)
 		return -ENOMEM;
 
+	/*
+	 * The LAUNCH_SECRET command will perform in-place encryption of the
+	 * memory content (i.e it will write the same memory region with C=1).
+	 * It's possible that the cache may contain the data with C=0, i.e.,
+	 * unencrypted so invalidate it first.
+	 */
+	sev_clflush_pages(pages, n);
+
 	/*
 	 * The secret must be copied into contiguous memory region, lets verify
 	 * that userspace memory pages are contiguous before we issue command.
@@ -908,6 +916,11 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp)
 e_free:
 	kfree(data);
 e_unpin_memory:
+	/* content of memory is updated, mark pages dirty */
+	for (i = 0; i < n; i++) {
+		set_page_dirty_lock(pages[i]);
+		mark_page_accessed(pages[i]);
+	}
 	sev_unpin_memory(kvm, pages, n);
 	return ret;
 }
-- 
2.28.0.163.g6104cc2f0b6-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-09-25  4:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07  1:23 [PATCH] KVM: SVM: Mark SEV launch secret pages as dirty Cfir Cohen
2020-08-07 17:55 ` David Rientjes
2020-08-08  0:02 ` Krish Sadhukhan
2020-08-08  0:37 ` [PATCH v2] " Cfir Cohen
2020-08-10 11:05   ` Brijesh Singh
     [not found] ` <20200919045505.GC21189@sjchrist-ice>
2020-09-23 16:59   ` [PATCH] " Paolo Bonzini
     [not found]     ` <20200923170444.GA20076@linux.intel.com>
2020-09-23 17:16       ` Paolo Bonzini
2020-09-23 17:26         ` Sean Christopherson
2020-09-23 17:27           ` Paolo Bonzini
2020-09-25  2:00 ` Cfir Cohen
2020-09-25  4:54   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).