Merge branch 'kvm-guest-sev-migration' into kvm-master
[platform/kernel/linux-starfive.git] / arch / x86 / mm / pat / set_memory.c
index 4f0cd50..b407211 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/libnvdimm.h>
 #include <linux/vmstat.h>
 #include <linux/kernel.h>
+#include <linux/cc_platform.h>
 
 #include <asm/e820/api.h>
 #include <asm/processor.h>
@@ -29,6 +30,8 @@
 #include <asm/proto.h>
 #include <asm/memtype.h>
 #include <asm/set_memory.h>
+#include <asm/hyperv-tlfs.h>
+#include <asm/mshyperv.h>
 
 #include "../mm_internal.h"
 
@@ -1980,15 +1983,15 @@ int set_memory_global(unsigned long addr, int numpages)
                                    __pgprot(_PAGE_GLOBAL), 0);
 }
 
-static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)
+/*
+ * __set_memory_enc_pgtable() is used for the hypervisors that get
+ * informed about "encryption" status via page tables.
+ */
+static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc)
 {
        struct cpa_data cpa;
        int ret;
 
-       /* Nothing to do if memory encryption is not active */
-       if (!mem_encrypt_active())
-               return 0;
-
        /* Should not be working on unaligned addresses */
        if (WARN_ONCE(addr & ~PAGE_MASK, "misaligned address: %#lx\n", addr))
                addr &= PAGE_MASK;
@@ -2029,6 +2032,17 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)
        return ret;
 }
 
+static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)
+{
+       if (hv_is_isolation_supported())
+               return hv_set_mem_host_visibility(addr, numpages, !enc);
+
+       if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
+               return __set_memory_enc_pgtable(addr, numpages, enc);
+
+       return 0;
+}
+
 int set_memory_encrypted(unsigned long addr, int numpages)
 {
        return __set_memory_enc_dec(addr, numpages, true);