Skip to content

Commit d45829b

Browse files
mzhang3579bonzini
authored andcommitted
KVM: SVM: Flush when freeing encrypted pages even on SME_COHERENT CPUs
Use clflush_cache_range() to flush the confidential memory when SME_COHERENT is supported in AMD CPU. Cache flush is still needed since SME_COHERENT only support cache invalidation at CPU side. All confidential cache lines are still incoherent with DMA devices. Cc: stable@vger.kerel.org Fixes: add5e2f ("KVM: SVM: Add support for the SEV-ES VMSA") Reviewed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Mingwei Zhang <mizhang@google.com> Message-Id: <20220421031407.2516575-3-mizhang@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 4bbef7e commit d45829b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,11 +2239,14 @@ static void sev_flush_encrypted_page(struct kvm_vcpu *vcpu, void *va)
22392239
unsigned long addr = (unsigned long)va;
22402240

22412241
/*
2242-
* If hardware enforced cache coherency for encrypted mappings of the
2243-
* same physical page is supported, nothing to do.
2242+
* If CPU enforced cache coherency for encrypted mappings of the
2243+
* same physical page is supported, use CLFLUSHOPT instead. NOTE: cache
2244+
* flush is still needed in order to work properly with DMA devices.
22442245
*/
2245-
if (boot_cpu_has(X86_FEATURE_SME_COHERENT))
2246+
if (boot_cpu_has(X86_FEATURE_SME_COHERENT)) {
2247+
clflush_cache_range(va, PAGE_SIZE);
22462248
return;
2249+
}
22472250

22482251
/*
22492252
* VM Page Flush takes a host virtual address and a guest ASID. Fall

0 commit comments

Comments
 (0)