linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
	linux-kernel@vger.kernel.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: [PATCH] x86/setup: Allow passing RNG seeds via e820 setup table
Date: Thu, 30 Jun 2022 13:33:00 +0200	[thread overview]
Message-ID: <20220630113300.1892799-1-Jason@zx2c4.com> (raw)

Currently the only way x86 can get an early boot RNG seed is via EFI,
which is generally always used now for physical machines, but is very
rarely used in VMs, especially VMs that are optimized for starting
"instantaneously", such as Firecracker's MicroVM. Here, we really want
the ability for the firmware to pass a random seed, similar to what OF
platforms do with the "rng-seed" property. It also would be nice for
bootloaders to be able to append seeds to the kernel before launching.

This patch accomplishes that by adding SETUP_RNG_SEED, similar to the
other 7 SETUP_* entries that are parsed from the e820 setup table. I've
verified that this works well with QEMU.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 arch/x86/include/uapi/asm/bootparam.h | 1 +
 arch/x86/kernel/setup.c               | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
index bea5cdcdf532..a60676b8d1d4 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -11,6 +11,7 @@
 #define SETUP_APPLE_PROPERTIES		5
 #define SETUP_JAILHOUSE			6
 #define SETUP_CC_BLOB			7
+#define SETUP_RNG_SEED			8
 
 #define SETUP_INDIRECT			(1<<31)
 
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index bd6c6fd373ae..4135fa17a90e 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -23,6 +23,7 @@
 #include <linux/usb/xhci-dbgp.h>
 #include <linux/static_call.h>
 #include <linux/swiotlb.h>
+#include <linux/random.h>
 
 #include <uapi/linux/mount.h>
 
@@ -343,7 +344,8 @@ static void __init parse_setup_data(void)
 		data_len = data->len + sizeof(struct setup_data);
 		data_type = data->type;
 		pa_next = data->next;
-		early_memunmap(data, sizeof(*data));
+		if (data_type != SETUP_RNG_SEED)
+			early_memunmap(data, sizeof(*data));
 
 		switch (data_type) {
 		case SETUP_E820_EXT:
@@ -355,6 +357,10 @@ static void __init parse_setup_data(void)
 		case SETUP_EFI:
 			parse_efi_setup(pa_data, data_len);
 			break;
+		case SETUP_RNG_SEED:
+			add_bootloader_randomness(data + 1, data_len);
+			early_memunmap(data, sizeof(*data));
+			break;
 		default:
 			break;
 		}
-- 
2.35.1


             reply	other threads:[~2022-06-30 11:33 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-30 11:33 Jason A. Donenfeld [this message]
2022-06-30 11:59 ` [PATCH v2] x86/setup: Allow passing RNG seeds via e820 setup table Jason A. Donenfeld
2022-06-30 12:09   ` [PATCH v3] " Jason A. Donenfeld
2022-06-30 13:31     ` [PATCH v4] " Jason A. Donenfeld
2022-07-01 17:58       ` [PATCH v5] " Jason A. Donenfeld
2022-07-01 18:25         ` H. Peter Anvin
2022-07-01 18:42           ` Jason A. Donenfeld
2022-07-01 18:52             ` H. Peter Anvin
2022-07-01 18:53               ` Jason A. Donenfeld
2022-07-03  0:44                 ` [PATCH v6] x86/setup: Use rng seeds from setup_data Jason A. Donenfeld
2022-07-07  0:08                   ` [PATCH v7] " Jason A. Donenfeld
2022-07-08 11:39                     ` [PATCH tip v8] " Jason A. Donenfeld
2022-07-09  1:51                       ` H. Peter Anvin
2022-07-09  9:43                         ` Jason A. Donenfeld
2022-07-09  9:48                           ` [PATCH tip v9] " Jason A. Donenfeld
2022-07-09 22:42                             ` H. Peter Anvin
2022-07-09 23:23                               ` Jason A. Donenfeld
2022-07-09  9:49                         ` [PATCH tip v8] " Borislav Petkov
2022-07-09  9:53                           ` Jason A. Donenfeld
2022-07-09 10:21                           ` Borislav Petkov
2022-07-09 21:45                           ` H. Peter Anvin
2022-07-09 21:57                             ` Borislav Petkov
2022-07-09 22:41                               ` H. Peter Anvin
2022-07-10  9:45                                 ` Borislav Petkov
2022-07-10 11:11                                   ` Jason A. Donenfeld
2022-07-10 12:27                                     ` Borislav Petkov
2022-07-10 17:13                                       ` Jason A. Donenfeld
2022-07-10 17:29                                         ` [PATCH tip v10] " Jason A. Donenfeld
2022-07-11  9:39 ` [tip: x86/kdump] " tip-bot2 for Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220630113300.1892799-1-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).