Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp509374iog; Thu, 30 Jun 2022 05:14:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vp0Y/hMUQlPLQS0AWR+xURo6D6cGdAFo8aqo4ak9art8RnoFX5NG6MbK19rMHWgds/b3/5 X-Received: by 2002:a17:907:7b95:b0:6f4:ff03:981a with SMTP id ne21-20020a1709077b9500b006f4ff03981amr8553262ejc.653.1656591292860; Thu, 30 Jun 2022 05:14:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656591292; cv=none; d=google.com; s=arc-20160816; b=tqpj0NWJ6BMAbGGhU3fPPIWGVrb0E5vIUaKZ35wfRal7Hl8WqYNlSIgH8uTNZxHKv2 KrJvzNRXtKv+QpDgz9UDHLJXhQLjBRvo7Lu65N3qsXxRdRuhMIcPsTqmWs+SVBWoFJMI q+pEDVbl8c9F8IYAz1kmRA6uMIGMH/hh3J4vGHFS0XcDzVGqlcVFekV9lAAbigc4yUdB 453yEv6Qt58Fo62vGXqHgdN2WVDkbWAy+rR/hxfOnyufkN9MHB9S0HjeFJnyULThzo6h mOEuB1MfLRTPTzpgW8VPxGITwjWzN7cmZAqB/1js5JA9gIdTV8ZcCCgwT1nk3Abkz7YM IsKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=l79OQpjYte3G9tZrhkDQofg0kfvRrmosbnXOJcuVKxA=; b=hw2Vd34C8FLMayRHR9O3sob/DQdA/MRAULeuKdI7k29q9gvhLuDqjobcT1RUt/6VRC GGe/5sa3wR3rzi3Fkk/jTKDwpYg7ci771hcc2F3fhw7wLbV1t6KDNDTHBa3TrVZOEh5O sipaEj8JUiAfUCJgB4hJmms/4mhNh/qr+2YYRafbwSAIJyAOrTMibrz6mJExK86SUzyZ YQB0b1f3c7Rb5h8RImfxHJWiudpCKqbg3KUYBhq3Uo5KPJeGgTW4CuRDEOQtSr7XXxg5 j30jez2u5RtDpPuJyjXL4PgjszPbuIQBc/oWHtVMQZYvULWprzNpJXB3OjlblHAn9P7K tUEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=PZRUI3Ld; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a056402424500b00435764905fcsi24316469edb.159.2022.06.30.05.14.27; Thu, 30 Jun 2022 05:14:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=PZRUI3Ld; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235026AbiF3MAE (ORCPT + 99 others); Thu, 30 Jun 2022 08:00:04 -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: 8bit X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 #define SETUP_INDIRECT (1<<31) 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 #include @@ -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