From nobody Tue Apr 21 16:07:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5755AC433EF for ; Thu, 30 Jun 2022 12:00:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235167AbiF3MAF (ORCPT ); Thu, 30 Jun 2022 08:00:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230135AbiF3MAC (ORCPT ); Thu, 30 Jun 2022 08:00:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C04EA52393 for ; Thu, 30 Jun 2022 05:00:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 62DA5B8291F for ; Thu, 30 Jun 2022 12:00:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CAB7C34115; Thu, 30 Jun 2022 11:59:58 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="PZRUI3Ld" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1656590396; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l79OQpjYte3G9tZrhkDQofg0kfvRrmosbnXOJcuVKxA=; b=PZRUI3LdrnQ+6nTWC5oeRO9aHr0M0yHxjypirE2Ka/w8eU30pCHw/5iup1pQMULwUEBRT+ 2nmiNEGuwb1LEhZ2WT9hQgqSbacWsmitRyxYl3KFr79r0NRvY0RjUBU3/QddLGh9Nkkhpe ZRZW+a8e32C5M0i7URibLo+du+rH3E4= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 5b5f9f48 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Thu, 30 Jun 2022 11:59:56 +0000 (UTC) From: "Jason A. Donenfeld" 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" Subject: [PATCH v2] x86/setup: Allow passing RNG seeds via e820 setup table Date: Thu, 30 Jun 2022 13:59:52 +0200 Message-Id: <20220630115952.1917972-1-Jason@zx2c4.com> In-Reply-To: <20220630113300.1892799-1-Jason@zx2c4.com> References: <20220630113300.1892799-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- Changes v1->v2: - Fix small typo of data_len -> data->len. 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 =20 #define SETUP_INDIRECT (1<<31) =20 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index bd6c6fd373ae..ce8bb744e576 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -23,6 +23,7 @@ #include #include #include +#include =20 #include =20 @@ -343,7 +344,8 @@ static void __init parse_setup_data(void) data_len =3D data->len + sizeof(struct setup_data); data_type =3D data->type; pa_next =3D data->next; - early_memunmap(data, sizeof(*data)); + if (data_type !=3D SETUP_RNG_SEED) + early_memunmap(data, sizeof(*data)); =20 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; } --=20 2.35.1