From patchwork Thu Apr 11 10:15:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 787940 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp148931wrm; Thu, 11 Apr 2024 03:17:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWn1b9J7KHXa4lBk7nP4QumHHUHJlS38JclrDYQlPy+Fv5HajGxUZ1KSLkvaH9e8GsMu/eiNlEwCX2j3zcgE8gJ X-Google-Smtp-Source: AGHT+IGFp8HUq1m3iqS+G3Qsr9WkoXhFjP7pT9Ici6C9SHU28ZavlxSYiXe+hzsMm3axpmiKQE1b X-Received: by 2002:a25:8d0b:0:b0:dcd:aee6:fa9 with SMTP id n11-20020a258d0b000000b00dcdaee60fa9mr5338542ybl.53.1712830665128; Thu, 11 Apr 2024 03:17:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712830665; cv=none; d=google.com; s=arc-20160816; b=TFuujpnScJEeDRjUcuc4dQYzvAxfA/4ZN+ficUmNkey1xAmoZUNmz8p9hdEDDWM0QG hLLsFs57GsjKubbeI5eM/EInC9ux+S2QznwiaFXWopFEPgPUdRBrEjb/LLqe8+nl6+KT AcPMhhXtjxUHXRfClhWKIEKKOdr/N7wRbBeA8oLLPWIFFbx53T+fHwYYrISm4PwtGB2B Mkin4iTYJib8oLIEwPeUKBpdpJFUnp5DqJOPS7Nl1ClVtn6qcaDa2nzzddgR28LD68bk /dPZila3bWLBJ6u/i/Yd2vwg5Eixk4evEnSBqXrw+MU+GVrB8UAOI/Fmo2m6Uhq82EDb kAuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4MCcGHhKA7wPhoBY3l6p9Olu+doueLftUh6GAPbrfFo=; fh=pz1yopd/wrdYlGtYXbhy+U1KH6qXkA5iyTnaoXfRYpE=; b=QGy1/F8hq/JmjFQRsfPXD7kqdnQtOn/8RyD/7rh5Rl8sqDLtXKu6YhirWiOOqLALuy 2QkSWnI68rPUo5fJ3U/jZUskGqJhONa1Yt3cBtImzrmMDCqAK4bs+RsYoodrnIYJt5en 6jYbfgyz9Ptp+B+xADD1zeZm014obrU6sxobinYY5czHbgGqWk48pDDMyt4Lv0MtI6sg 8q4Az9jt5caiCqCAdH8KS+BNOhdTpYbUht1S+FJHGR0kGwmSAJcK4bFKdewwvLfSC6KU F9WYcTHrZxAMytL2J5Ioo2hsItKUSx3LetNf8IaN7QqgfoMPPol4mE3ZhxzyGyA4NCxh wuHQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OSb52WSY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x12-20020a0cfe0c000000b00699477fc5b3si1124377qvr.211.2024.04.11.03.17.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Apr 2024 03:17:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OSb52WSY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rurUK-0005JV-1d; Thu, 11 Apr 2024 06:17:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rurTp-00058u-5a for qemu-devel@nongnu.org; Thu, 11 Apr 2024 06:16:31 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rurTg-0007UT-1O for qemu-devel@nongnu.org; Thu, 11 Apr 2024 06:16:28 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-34665dd7744so1303453f8f.1 for ; Thu, 11 Apr 2024 03:16:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712830577; x=1713435377; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4MCcGHhKA7wPhoBY3l6p9Olu+doueLftUh6GAPbrfFo=; b=OSb52WSY0B2mZTlTPa51sMidfmq+eaI6IArXxnW6ZQBxwoqvhQP5jryhgCXSXQc8PL p/lBeOKhVGgbQRll8N0Fb3EiunFeqMiXsOnxGrIkeyDGji2xjyc6oAQ/CGJJ5eRCADNA u2XxT1q4+lFAx68Hfp5tQ4MqgwvRjh1OIVGiRXVAXc5xzs6xyw1IJBaBiQ8h3zlvjlSw L6hJr3dwWdIHfs4/GTloxSeJS/LWOkTIjadIxUtAhQvHpjfGSSiT1rMAVe7Eu1lxs4uS 07wGXhtecaogZBZkVFridO2JiUWf0KYI+EXexT/CcUytBuqttjzDuVntNEXCY6nAiFQ5 7a6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712830577; x=1713435377; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4MCcGHhKA7wPhoBY3l6p9Olu+doueLftUh6GAPbrfFo=; b=CW8L/GFP99C/gWgff8wOX5SNkYfoMIaJroOJVHNkeCosRxDGJ6jsxKVJlrS+ndlXkV 7zer7J5FmxTl/rb+9fbkWweeoQOWSuMcikgCOdEx6qCWssrhW0yBCrjCKEoSMzjy8po4 aIQQMndp9Kd4ThIevojyE2ii8b2JsayR/pbb3tR1VsZFPTXjZmI6dHOLsXd+uEb+cJbs SSNGa/HKVqB6peVlXI/3yT1zQbHOQPEicCng61434fFcXbvM5ZRMZe16cWM1AVr4HHNs p7hHG86vAXjFe3BpIYNkXYXZ8JYgE/gaLN5WG6sJpPmLhLPnpujwAC7HsnGTzvmExDkh UACQ== X-Gm-Message-State: AOJu0YwwIPQsOi2874+4V3TjT/a38LP3PYs3FjcSLYHRX+KsUo/dIPzl TnIUZ9DSTS/0zT02pknOHj+2GiuJqcu+indGDX1JxemwbSOFM1usFi4YuWNBHKu7M8BgQnpJoMl zrEE= X-Received: by 2002:adf:e702:0:b0:346:305c:d34a with SMTP id c2-20020adfe702000000b00346305cd34amr3676036wrm.20.1712830577088; Thu, 11 Apr 2024 03:16:17 -0700 (PDT) Received: from localhost.localdomain (137.red-88-29-174.dynamicip.rima-tde.net. [88.29.174.137]) by smtp.gmail.com with ESMTPSA id dl5-20020a0560000b8500b00345fb949c28sm1404822wrb.100.2024.04.11.03.16.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 11 Apr 2024 03:16:16 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-ppc@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Aurelien Jarno , Jiaxun Yang Subject: [PATCH v2 04/13] hw/mips/malta: Add re-usable rng_seed_hex_new() method Date: Thu, 11 Apr 2024 12:15:40 +0200 Message-ID: <20240411101550.99392-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240411101550.99392-1-philmd@linaro.org> References: <20240411101550.99392-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=philmd@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Extract common code from reinitialize_rng_seed() and load_kernel() to rng_seed_hex_new(). Signed-off-by: Philippe Mathieu-Daudé --- hw/mips/malta.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/mips/malta.c b/hw/mips/malta.c index af74008c82..9fc6a7d313 100644 --- a/hw/mips/malta.c +++ b/hw/mips/malta.c @@ -850,15 +850,24 @@ static void G_GNUC_PRINTF(3, 4) prom_set(uint32_t *prom_buf, int index, va_end(ap); } -static void reinitialize_rng_seed(void *opaque) +static char *rng_seed_hex_new(void) { - char *rng_seed_hex = opaque; uint8_t rng_seed[32]; + char rng_seed_hex[sizeof(rng_seed) * 2 + 1]; qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); for (size_t i = 0; i < sizeof(rng_seed); ++i) { sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]); } + + return g_strdup(rng_seed_hex); +} + +static void reinitialize_rng_seed(void *opaque) +{ + g_autofree char *rng_seed_hex = rng_seed_hex_new(); + + strcpy(opaque, rng_seed_hex); } /* Kernel */ @@ -870,8 +879,7 @@ static uint64_t load_kernel(void) uint32_t *prom_buf; long prom_size; int prom_index = 0; - uint8_t rng_seed[32]; - char rng_seed_hex[sizeof(rng_seed) * 2 + 1]; + g_autofree char *rng_seed_hex = rng_seed_hex_new(); size_t rng_seed_prom_offset; kernel_size = load_elf(loaderparams.kernel_filename, NULL, @@ -946,10 +954,6 @@ static uint64_t load_kernel(void) prom_set(prom_buf, prom_index++, "modetty0"); prom_set(prom_buf, prom_index++, "38400n8r"); - qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); - for (size_t i = 0; i < sizeof(rng_seed); ++i) { - sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]); - } prom_set(prom_buf, prom_index++, "rngseed"); rng_seed_prom_offset = prom_index * ENVP_ENTRY_SIZE + sizeof(uint32_t) * ENVP_NB_ENTRIES;