]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
KVM: SVM: Don't flush cache if hardware enforces cache coherency across encryption...
authorKrish Sadhukhan <krish.sadhukhan@oracle.com>
Thu, 17 Sep 2020 21:20:38 +0000 (21:20 +0000)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 13:17:51 +0000 (15:17 +0200)
BugLink: https://bugs.launchpad.net/bugs/1969672
commit e1ebb2b49048c4767cfa0d8466f9c701e549fa5e upstream.

In some hardware implementations, coherency between the encrypted and
unencrypted mappings of the same physical page in a VM is enforced. In
such a system, it is not required for software to flush the VM's page
from all CPU caches in the system prior to changing the value of the
C-bit for the page.

So check that bit before flushing the cache.

Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Link: https://lkml.kernel.org/r/20200917212038.5090-4-krish.sadhukhan@oracle.com
[ The linux-5.4.y stable branch does not have the Linux 5.7 refactoring commit
  eaf78265a4ab ("KVM: SVM: Move SEV code to separate file") so the
  change was manually applied to sev_clflush_pages() in arch/x86/kvm/svm.c. ]
Signed-off-by: Liam Merwick <liam.merwick@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
arch/x86/kvm/svm.c

index 7f1167196d6e2a4f4fa834480b6770c3e328c34e..c1cccbb6bb56f2e66e799335bb41c12a3dad7ffa 100644 (file)
@@ -1904,7 +1904,8 @@ static void sev_clflush_pages(struct page *pages[], unsigned long npages)
        uint8_t *page_virtual;
        unsigned long i;
 
-       if (npages == 0 || pages == NULL)
+       if (this_cpu_has(X86_FEATURE_SME_COHERENT) || npages == 0 ||
+           pages == NULL)
                return;
 
        for (i = 0; i < npages; i++) {