From: Martin Radev <martin.b.ra...@gmail.com>

Make sure the machine supports RDRAND, otherwise there is no trusted
source of of randomness in the system.

Signed-off-by: Martin Radev <martin.b.ra...@gmail.com>
Signed-off-by: Joerg Roedel <jroe...@suse.de>
---
 arch/x86/boot/compressed/sev-es.c |  3 +++
 arch/x86/kernel/sev-es-shared.c   | 15 +++++++++++++++
 arch/x86/kernel/sev-es.c          |  3 +++
 3 files changed, 21 insertions(+)

diff --git a/arch/x86/boot/compressed/sev-es.c 
b/arch/x86/boot/compressed/sev-es.c
index b522c18c0588..eb1a8b5cc753 100644
--- a/arch/x86/boot/compressed/sev-es.c
+++ b/arch/x86/boot/compressed/sev-es.c
@@ -145,6 +145,9 @@ void sev_es_shutdown_ghcb(void)
        if (!boot_ghcb)
                return;
 
+       if (!sev_es_check_cpu_features())
+               error("SEV-ES CPU Features missing.");
+
        /*
         * GHCB Page must be flushed from the cache and mapped encrypted again.
         * Otherwise the running kernel will see strange cache effects when
diff --git a/arch/x86/kernel/sev-es-shared.c b/arch/x86/kernel/sev-es-shared.c
index 608f76d0d088..56de70cb80d8 100644
--- a/arch/x86/kernel/sev-es-shared.c
+++ b/arch/x86/kernel/sev-es-shared.c
@@ -9,6 +9,21 @@
  * and is included directly into both code-bases.
  */
 
+#ifndef __BOOT_COMPRESSED
+#define error(v)       pr_err(v)
+#define has_cpuflag(f) boot_cpu_has(f)
+#endif
+
+static bool __init sev_es_check_cpu_features(void)
+{
+       if (!has_cpuflag(X86_FEATURE_RDRAND)) {
+               error("RDRAND instruction not supported - no trusted source of 
randomness available\n");
+               return false;
+       }
+
+       return true;
+}
+
 static void sev_es_terminate(unsigned int reason)
 {
        u64 val = GHCB_SEV_TERMINATE;
diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c
index 61308f9c8138..481ea00c58b6 100644
--- a/arch/x86/kernel/sev-es.c
+++ b/arch/x86/kernel/sev-es.c
@@ -682,6 +682,9 @@ void __init sev_es_init_vc_handling(void)
        if (!sev_es_active())
                return;
 
+       if (!sev_es_check_cpu_features())
+               panic("SEV-ES CPU Features missing");
+
        /* Initialize per-cpu GHCB pages */
        for_each_possible_cpu(cpu) {
                sev_es_alloc_runtime_data(cpu);
-- 
2.27.0

Reply via email to