From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Laurent Vivier" <laurent@vivier.eu>
Subject: Re: [PATCH v6] hw/i386: pass RNG seed via setup_data entry
Date: Thu, 21 Jul 2022 07:00:12 -0400 [thread overview]
Message-ID: <20220721065744-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20220721104950.434544-1-Jason@zx2c4.com>
On Thu, Jul 21, 2022 at 12:49:50PM +0200, Jason A. Donenfeld wrote:
> Tiny machines optimized for fast boot time generally don't use EFI,
> which means a random seed has to be supplied some other way. For this
> purpose, Linux (≥5.20) supports passing a seed in the setup_data table
> with SETUP_RNG_SEED, specially intended for hypervisors, kexec, and
> specialized bootloaders. The linked commit shows the upstream kernel
> implementation.
>
> Link: https://git.kernel.org/tip/tip/c/68b8e9713c8
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Richard Henderson <richard.henderson@linaro.org>
> Cc: Eduardo Habkost <eduardo@habkost.net>
> Cc: Peter Maydell <peter.maydell@linaro.org>
> Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Cc: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Well why not.
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
who's merging this? Paolo me or you?
> ---
> hw/i386/x86.c | 21 +++++++++++++++++---
> include/standard-headers/asm-x86/bootparam.h | 1 +
> 2 files changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/hw/i386/x86.c b/hw/i386/x86.c
> index 6003b4b2df..56896cb4b2 100644
> --- a/hw/i386/x86.c
> +++ b/hw/i386/x86.c
> @@ -26,6 +26,7 @@
> #include "qemu/cutils.h"
> #include "qemu/units.h"
> #include "qemu/datadir.h"
> +#include "qemu/guest-random.h"
> #include "qapi/error.h"
> #include "qapi/qmp/qerror.h"
> #include "qapi/qapi-visit-common.h"
> @@ -774,7 +775,7 @@ void x86_load_linux(X86MachineState *x86ms,
> int dtb_size, setup_data_offset;
> uint32_t initrd_max;
> uint8_t header[8192], *setup, *kernel;
> - hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0;
> + hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0, first_setup_data = 0;
> FILE *f;
> char *vmode;
> MachineState *machine = MACHINE(x86ms);
> @@ -784,6 +785,7 @@ void x86_load_linux(X86MachineState *x86ms,
> const char *dtb_filename = machine->dtb;
> const char *kernel_cmdline = machine->kernel_cmdline;
> SevKernelLoaderContext sev_load_ctx = {};
> + enum { RNG_SEED_LENGTH = 32 };
>
> /* Align to 16 bytes as a paranoia measure */
> cmdline_size = (strlen(kernel_cmdline) + 16) & ~15;
> @@ -1063,16 +1065,29 @@ void x86_load_linux(X86MachineState *x86ms,
> kernel_size = setup_data_offset + sizeof(struct setup_data) + dtb_size;
> kernel = g_realloc(kernel, kernel_size);
>
> - stq_p(header + 0x250, prot_addr + setup_data_offset);
>
> setup_data = (struct setup_data *)(kernel + setup_data_offset);
> - setup_data->next = 0;
> + setup_data->next = cpu_to_le64(first_setup_data);
> + first_setup_data = prot_addr + setup_data_offset;
> setup_data->type = cpu_to_le32(SETUP_DTB);
> setup_data->len = cpu_to_le32(dtb_size);
>
> load_image_size(dtb_filename, setup_data->data, dtb_size);
> }
>
> + setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16);
> + kernel_size = setup_data_offset + sizeof(struct setup_data) + RNG_SEED_LENGTH;
> + kernel = g_realloc(kernel, kernel_size);
> + setup_data = (struct setup_data *)(kernel + setup_data_offset);
> + setup_data->next = cpu_to_le64(first_setup_data);
> + first_setup_data = prot_addr + setup_data_offset;
> + setup_data->type = cpu_to_le32(SETUP_RNG_SEED);
> + setup_data->len = cpu_to_le32(RNG_SEED_LENGTH);
> + qemu_guest_getrandom_nofail(setup_data->data, RNG_SEED_LENGTH);
> +
> + /* Offset 0x250 is a pointer to the first setup_data link. */
> + stq_p(header + 0x250, first_setup_data);
> +
> /*
> * If we're starting an encrypted VM, it will be OVMF based, which uses the
> * efi stub for booting and doesn't require any values to be placed in the
> diff --git a/include/standard-headers/asm-x86/bootparam.h b/include/standard-headers/asm-x86/bootparam.h
> index 072e2ed546..b2aaad10e5 100644
> --- a/include/standard-headers/asm-x86/bootparam.h
> +++ b/include/standard-headers/asm-x86/bootparam.h
> @@ -10,6 +10,7 @@
> #define SETUP_EFI 4
> #define SETUP_APPLE_PROPERTIES 5
> #define SETUP_JAILHOUSE 6
> +#define SETUP_RNG_SEED 9
>
> #define SETUP_INDIRECT (1<<31)
>
> --
> 2.35.1
next prev parent reply other threads:[~2022-07-21 11:05 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 14:54 [PATCH v3] hw/i386: pass RNG seed via setup_data entry Jason A. Donenfeld
2022-07-19 11:53 ` [PATCH resend " Jason A. Donenfeld
2022-07-20 13:03 ` Jason A. Donenfeld
2022-07-21 9:19 ` Paolo Bonzini
2022-07-21 9:47 ` Jason A. Donenfeld
2022-07-21 9:56 ` Jason A. Donenfeld
2022-07-21 10:09 ` [PATCH v4] " Jason A. Donenfeld
2022-07-21 10:35 ` Michael S. Tsirkin
2022-07-21 10:42 ` Jason A. Donenfeld
2022-07-21 10:47 ` [PATCH v5] " Jason A. Donenfeld
2022-07-21 10:49 ` [PATCH v6] " Jason A. Donenfeld
2022-07-21 11:00 ` Michael S. Tsirkin [this message]
2022-07-21 11:00 ` Jason A. Donenfeld
2022-07-21 11:47 ` Paolo Bonzini
2022-07-21 12:16 ` Jason A. Donenfeld
2022-07-21 12:27 ` Daniel P. Berrangé
2022-07-21 12:41 ` Paolo Bonzini
2022-07-21 12:52 ` Jason A. Donenfeld
2022-07-21 12:56 ` [PATCH v7] " Jason A. Donenfeld
2022-07-21 13:00 ` Paolo Bonzini
2022-07-21 13:00 ` Paolo Bonzini
2022-07-21 13:04 ` Jason A. Donenfeld
2022-07-22 6:10 ` Paolo Bonzini
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=20220721065744-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=Jason@zx2c4.com \
--cc=eduardo@habkost.net \
--cc=f4bug@amsat.org \
--cc=laurent@vivier.eu \
--cc=marcel.apfelbaum@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).