[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220630120955.1937664-1-Jason@zx2c4.com>
Date: Thu, 30 Jun 2022 14:09:55 +0200
From: "Jason A. Donenfeld" <Jason@...c4.com>
To: tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
dave.hansen@...ux.intel.com, x86@...nel.org, hpa@...or.com,
linux-kernel@...r.kernel.org
Cc: "Jason A. Donenfeld" <Jason@...c4.com>
Subject: [PATCH v3] x86/setup: Allow passing RNG seeds via e820 setup table
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@...c4.com>
---
Changes v2->v3:
- Actually memmap the right area with the random bytes in it. This
worked before because of page sizes, but the code wasn't right. Now
it's right.
arch/x86/include/uapi/asm/bootparam.h | 1 +
arch/x86/kernel/setup.c | 8 ++++++++
2 files changed, 9 insertions(+)
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..33e9d23296b6 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>
@@ -355,6 +356,13 @@ static void __init parse_setup_data(void)
case SETUP_EFI:
parse_efi_setup(pa_data, data_len);
break;
+ case SETUP_RNG_SEED:
+ pa_data += sizeof(*data);
+ data_len -= sizeof(*data);
+ data = early_memremap(pa_data, data_len);
+ add_bootloader_randomness(data, data_len);
+ early_memunmap(data, data_len);
+ break;
default:
break;
}
--
2.35.1
Powered by blists - more mailing lists