{
__snp_leak_pages(pfn, pages, true);
}
+void snp_prepare(void);
#else
static inline bool snp_probe_rmptable_info(void) { return false; }
static inline int snp_rmptable_init(void) { return -ENOSYS; }
static inline void snp_leak_pages(u64 pfn, unsigned int npages) {}
static inline void kdump_sev_callback(void) { }
static inline void snp_fixup_e820_tables(void) {}
+static inline void snp_prepare(void) {}
#endif
#endif
#undef pr_fmt
#define pr_fmt(fmt) "SEV-SNP: " fmt
-static __init void mfd_enable(void *arg)
+static void mfd_enable(void *arg)
{
if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
return;
msr_set_bit(MSR_AMD64_SYSCFG, MSR_AMD64_SYSCFG_MFDM_BIT);
}
-static __init void snp_enable(void *arg)
+static void snp_enable(void *arg)
{
u64 val;
return true;
}
+void snp_prepare(void)
+{
+ u64 val;
+
+ /*
+ * Check if SEV-SNP is already enabled, this can happen in case of
+ * kexec boot.
+ */
+ rdmsrq(MSR_AMD64_SYSCFG, val);
+ if (val & MSR_AMD64_SYSCFG_SNP_EN)
+ return;
+
+ clear_rmp();
+
+ cpus_read_lock();
+
+ /*
+ * MtrrFixDramModEn is not shared between threads on a core,
+ * therefore it must be set on all CPUs prior to enabling SNP.
+ */
+ on_each_cpu(mfd_enable, NULL, 1);
+ on_each_cpu(snp_enable, NULL, 1);
+
+ cpus_read_unlock();
+}
+EXPORT_SYMBOL_FOR_MODULES(snp_prepare, "ccp");
+
/*
* Do the necessary preparations which are verified by the firmware as
* described in the SNP_INIT_EX firmware command description in the SNP
*/
int __init snp_rmptable_init(void)
{
- u64 val;
-
if (WARN_ON_ONCE(!cc_platform_has(CC_ATTR_HOST_SEV_SNP)))
return -ENOSYS;
if (!setup_rmptable())
return -ENOSYS;
- /*
- * Check if SEV-SNP is already enabled, this can happen in case of
- * kexec boot.
- */
- rdmsrq(MSR_AMD64_SYSCFG, val);
- if (val & MSR_AMD64_SYSCFG_SNP_EN)
- goto skip_enable;
-
- clear_rmp();
-
- /* MtrrFixDramModEn must be enabled on all the CPUs prior to enabling SNP. */
- on_each_cpu(mfd_enable, NULL, 1);
-
- on_each_cpu(snp_enable, NULL, 1);
+ snp_prepare();
-skip_enable:
/*
* Setting crash_kexec_post_notifiers to 'true' to ensure that SNP panic
* notifier is invoked to do SNP IOMMU shutdown before kdump.