RISCV: config: tizen_visionfive2: Disable JH7110 crypto driver
[platform/kernel/linux-starfive.git] / drivers / hv / hv_common.c
index 6a2258f..ccad7bc 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/kmsg_dump.h>
 #include <linux/slab.h>
 #include <linux/dma-map-ops.h>
+#include <linux/set_memory.h>
 #include <asm/hyperv-tlfs.h>
 #include <asm/mshyperv.h>
 
@@ -359,6 +360,8 @@ int hv_common_cpu_init(unsigned int cpu)
        u64 msr_vp_index;
        gfp_t flags;
        int pgcount = hv_root_partition ? 2 : 1;
+       void *mem;
+       int ret;
 
        /* hv_cpu_init() can be called with IRQs disabled from hv_resume() */
        flags = irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL;
@@ -370,14 +373,41 @@ int hv_common_cpu_init(unsigned int cpu)
         * allocated if this CPU was previously online and then taken offline
         */
        if (!*inputarg) {
-               *inputarg = kmalloc(pgcount * HV_HYP_PAGE_SIZE, flags);
-               if (!(*inputarg))
+               mem = kmalloc(pgcount * HV_HYP_PAGE_SIZE, flags);
+               if (!mem)
                        return -ENOMEM;
 
                if (hv_root_partition) {
                        outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
-                       *outputarg = (char *)(*inputarg) + HV_HYP_PAGE_SIZE;
+                       *outputarg = (char *)mem + HV_HYP_PAGE_SIZE;
+               }
+
+               if (!ms_hyperv.paravisor_present &&
+                   (hv_isolation_type_snp() || hv_isolation_type_tdx())) {
+                       ret = set_memory_decrypted((unsigned long)mem, pgcount);
+                       if (ret) {
+                               /* It may be unsafe to free 'mem' */
+                               return ret;
+                       }
+
+                       memset(mem, 0x00, pgcount * HV_HYP_PAGE_SIZE);
                }
+
+               /*
+                * In a fully enlightened TDX/SNP VM with more than 64 VPs, if
+                * hyperv_pcpu_input_arg is not NULL, set_memory_decrypted() ->
+                * ... -> cpa_flush()-> ... -> __send_ipi_mask_ex() tries to
+                * use hyperv_pcpu_input_arg as the hypercall input page, which
+                * must be a decrypted page in such a VM, but the page is still
+                * encrypted before set_memory_decrypted() returns. Fix this by
+                * setting *inputarg after the above set_memory_decrypted(): if
+                * hyperv_pcpu_input_arg is NULL, __send_ipi_mask_ex() returns
+                * HV_STATUS_INVALID_PARAMETER immediately, and the function
+                * hv_send_ipi_mask() falls back to orig_apic.send_IPI_mask(),
+                * which may be slightly slower than the hypercall, but still
+                * works correctly in such a VM.
+                */
+               *inputarg = mem;
        }
 
        msr_vp_index = hv_get_register(HV_REGISTER_VP_INDEX);
@@ -502,6 +532,12 @@ bool __weak hv_isolation_type_snp(void)
 }
 EXPORT_SYMBOL_GPL(hv_isolation_type_snp);
 
+bool __weak hv_isolation_type_tdx(void)
+{
+       return false;
+}
+EXPORT_SYMBOL_GPL(hv_isolation_type_tdx);
+
 void __weak hv_setup_vmbus_handler(void (*handler)(void))
 {
 }
@@ -542,3 +578,9 @@ u64 __weak hv_ghcb_hypercall(u64 control, void *input, void *output, u32 input_s
        return HV_STATUS_INVALID_PARAMETER;
 }
 EXPORT_SYMBOL_GPL(hv_ghcb_hypercall);
+
+u64 __weak hv_tdx_hypercall(u64 control, u64 param1, u64 param2)
+{
+       return HV_STATUS_INVALID_PARAMETER;
+}
+EXPORT_SYMBOL_GPL(hv_tdx_hypercall);