From nobody Sat May 18 03:01:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1666658683; cv=none; d=zohomail.com; s=zohoarc; b=j39cFrlt9p0BoBYzKhaxwzxiDJyY301omx1vTYUyxxV8jTUG6V9+PH+/W1lYaU5GJmJlkwkMtndAs4xs8pfWBpM2pqnIx1VX5sxklyAcsB/9pMTYWG/D6A/vNPZNMYMyH0cwqblM3M17OvxJVKTnA4CIMjdFDnfq/sI5KLjJ+4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666658683; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sj3/1iCHqDw7B+yCjXD5iTio/qli9LXP66NKKmy3/Go=; b=J3GXSVeFT8zuIspr8nw7iHXU0y7f/Sjpwo7Z7d/kt16UApHVA/utAbnybNNSUG672BDjyIPJKB3z4bR0s+0GQhYKCqGNtNqVXtwmjhjrhcFYWa8wPOtSe2kyKpIx3sv2Yd6zMT8VU31mwQcjCgYkTqjKI1s5/tLgB16B63KIA84= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666658683864389.897028466023; Mon, 24 Oct 2022 17:44:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on82q-0002Ii-Sv; Mon, 24 Oct 2022 20:43:52 -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 1on82o-00022X-J2 for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:43:50 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on82l-0005Bz-UX for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:43:50 -0400 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 dfw.source.kernel.org (Postfix) with ESMTPS id C677B6160B; Tue, 25 Oct 2022 00:43:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5619C433D6; Tue, 25 Oct 2022 00:43:38 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 368be95c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 25 Oct 2022 00:43:37 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="VPZQVTBb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666658618; 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=sj3/1iCHqDw7B+yCjXD5iTio/qli9LXP66NKKmy3/Go=; b=VPZQVTBbpbp3XQPDwQEylVUaSe0huMldh0dDMgynZXqkpBFHSNhwPIScyDy+cowxR3wRCg DWxAps9FSeLXbRB/GK1bS6Ot0LBklA14m4TVKnC08BbEBauRk06g3P0kgxSqsl0NN7Nzfl BBTUDwpiBggi+WpgabyBhxXEAmdUdkA= From: "Jason A. Donenfeld" To: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: "Jason A. Donenfeld" Subject: [PATCH v4 01/11] reset: allow registering handlers that aren't called by snapshot loading Date: Tue, 25 Oct 2022 02:43:17 +0200 Message-Id: <20221025004327.568476-2-Jason@zx2c4.com> In-Reply-To: <20221025004327.568476-1-Jason@zx2c4.com> References: <20221025004327.568476-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=139.178.84.217; envelope-from=SRS0=a4uw=22=zx2c4.com=Jason@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1666658686102100003 Content-Type: text/plain; charset="utf-8" Snapshot loading only expects to call deterministic handlers, not non-deterministic ones. So introduce a way of registering handlers that won't be called when reseting for snapshots. Signed-off-by: Jason A. Donenfeld --- hw/arm/aspeed.c | 4 ++-- hw/arm/mps2-tz.c | 4 ++-- hw/core/reset.c | 15 ++++++++++++++- hw/hppa/machine.c | 4 ++-- hw/i386/microvm.c | 4 ++-- hw/i386/pc.c | 6 +++--- hw/ppc/pegasos2.c | 4 ++-- hw/ppc/pnv.c | 4 ++-- hw/ppc/spapr.c | 4 ++-- hw/s390x/s390-virtio-ccw.c | 4 ++-- include/hw/boards.h | 2 +- include/sysemu/reset.h | 5 ++++- migration/savevm.c | 2 +- qapi/run-state.json | 5 ++++- softmmu/runstate.c | 11 ++++++++--- 15 files changed, 51 insertions(+), 27 deletions(-) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index bc3ecdb619..69cadb1c37 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -1349,12 +1349,12 @@ static void aspeed_machine_bletchley_class_init(Obj= ectClass *oc, void *data) aspeed_soc_num_cpus(amc->soc_name); } =20 -static void fby35_reset(MachineState *state) +static void fby35_reset(MachineState *state, ShutdownCause reason) { AspeedMachineState *bmc =3D ASPEED_MACHINE(state); AspeedGPIOState *gpio =3D &bmc->soc.gpio; =20 - qemu_devices_reset(); + qemu_devices_reset(reason); =20 /* Board ID: 7 (Class-1, 4 slots) */ object_property_set_bool(OBJECT(gpio), "gpioV4", true, &error_fatal); diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c index 394192b9b2..284c09c91d 100644 --- a/hw/arm/mps2-tz.c +++ b/hw/arm/mps2-tz.c @@ -1239,7 +1239,7 @@ static void mps2_set_remap(Object *obj, const char *v= alue, Error **errp) } } =20 -static void mps2_machine_reset(MachineState *machine) +static void mps2_machine_reset(MachineState *machine, ShutdownCause reason) { MPS2TZMachineState *mms =3D MPS2TZ_MACHINE(machine); =20 @@ -1249,7 +1249,7 @@ static void mps2_machine_reset(MachineState *machine) * reset see the correct mapping. */ remap_memory(mms, mms->remap); - qemu_devices_reset(); + qemu_devices_reset(reason); } =20 static void mps2tz_class_init(ObjectClass *oc, void *data) diff --git a/hw/core/reset.c b/hw/core/reset.c index 36be82c491..bcf323d6dd 100644 --- a/hw/core/reset.c +++ b/hw/core/reset.c @@ -33,6 +33,7 @@ typedef struct QEMUResetEntry { QTAILQ_ENTRY(QEMUResetEntry) entry; QEMUResetHandler *func; void *opaque; + bool skip_on_snapshot_load; } QEMUResetEntry; =20 static QTAILQ_HEAD(, QEMUResetEntry) reset_handlers =3D @@ -47,6 +48,16 @@ void qemu_register_reset(QEMUResetHandler *func, void *o= paque) QTAILQ_INSERT_TAIL(&reset_handlers, re, entry); } =20 +void qemu_register_reset_nosnapshotload(QEMUResetHandler *func, void *opaq= ue) +{ + QEMUResetEntry *re =3D g_new0(QEMUResetEntry, 1); + + re->func =3D func; + re->opaque =3D opaque; + re->skip_on_snapshot_load =3D true; + QTAILQ_INSERT_TAIL(&reset_handlers, re, entry); +} + void qemu_unregister_reset(QEMUResetHandler *func, void *opaque) { QEMUResetEntry *re; @@ -60,12 +71,14 @@ void qemu_unregister_reset(QEMUResetHandler *func, void= *opaque) } } =20 -void qemu_devices_reset(void) +void qemu_devices_reset(ShutdownCause reason) { QEMUResetEntry *re, *nre; =20 /* reset all devices */ QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) { + if (reason =3D=3D SHUTDOWN_CAUSE_SNAPSHOT_LOAD && re->skip_on_snap= shot_load) + continue; re->func(re->opaque); } } diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c index e53d5f0fa7..19ea7c2c66 100644 --- a/hw/hppa/machine.c +++ b/hw/hppa/machine.c @@ -411,12 +411,12 @@ static void machine_hppa_init(MachineState *machine) cpu[0]->env.gr[19] =3D FW_CFG_IO_BASE; } =20 -static void hppa_machine_reset(MachineState *ms) +static void hppa_machine_reset(MachineState *ms, ShutdownCause reason) { unsigned int smp_cpus =3D ms->smp.cpus; int i; =20 - qemu_devices_reset(); + qemu_devices_reset(reason); =20 /* Start all CPUs at the firmware entry point. * Monarch CPU will initialize firmware, secondary CPUs diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 52f9aa9d8c..ffd1884100 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -467,7 +467,7 @@ static void microvm_machine_state_init(MachineState *ma= chine) microvm_devices_init(mms); } =20 -static void microvm_machine_reset(MachineState *machine) +static void microvm_machine_reset(MachineState *machine, ShutdownCause rea= son) { MicrovmMachineState *mms =3D MICROVM_MACHINE(machine); CPUState *cs; @@ -480,7 +480,7 @@ static void microvm_machine_reset(MachineState *machine) mms->kernel_cmdline_fixed =3D true; } =20 - qemu_devices_reset(); + qemu_devices_reset(reason); =20 CPU_FOREACH(cs) { cpu =3D X86_CPU(cs); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 768982ae9a..3e86083db3 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1847,12 +1847,12 @@ static void pc_machine_initfn(Object *obj) cxl_machine_init(obj, &pcms->cxl_devices_state); } =20 -static void pc_machine_reset(MachineState *machine) +static void pc_machine_reset(MachineState *machine, ShutdownCause reason) { CPUState *cs; X86CPU *cpu; =20 - qemu_devices_reset(); + qemu_devices_reset(reason); =20 /* Reset APIC after devices have been reset to cancel * any changes that qemu_devices_reset() might have done. @@ -1867,7 +1867,7 @@ static void pc_machine_reset(MachineState *machine) static void pc_machine_wakeup(MachineState *machine) { cpu_synchronize_all_states(); - pc_machine_reset(machine); + pc_machine_reset(machine, SHUTDOWN_CAUSE_NONE); cpu_synchronize_all_post_reset(); } =20 diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c index ecf682b148..bb4d008ba9 100644 --- a/hw/ppc/pegasos2.c +++ b/hw/ppc/pegasos2.c @@ -248,14 +248,14 @@ static void pegasos2_pci_config_write(Pegasos2Machine= State *pm, int bus, pegasos2_mv_reg_write(pm, pcicfg + 4, len, val); } =20 -static void pegasos2_machine_reset(MachineState *machine) +static void pegasos2_machine_reset(MachineState *machine, ShutdownCause re= ason) { Pegasos2MachineState *pm =3D PEGASOS2_MACHINE(machine); void *fdt; uint64_t d[2]; int sz; =20 - qemu_devices_reset(); + qemu_devices_reset(reason); if (!pm->vof) { return; /* Firmware should set up machine so nothing to do */ } diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 40bb573d1a..3d01e26f84 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -643,13 +643,13 @@ static void pnv_powerdown_notify(Notifier *n, void *o= paque) } } =20 -static void pnv_reset(MachineState *machine) +static void pnv_reset(MachineState *machine, ShutdownCause reason) { PnvMachineState *pnv =3D PNV_MACHINE(machine); IPMIBmc *bmc; void *fdt; =20 - qemu_devices_reset(); + qemu_devices_reset(reason); =20 /* * The machine should provide by default an internal BMC simulator. diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index f79ac85ca1..66b414d2e9 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1623,7 +1623,7 @@ void spapr_check_mmu_mode(bool guest_radix) } } =20 -static void spapr_machine_reset(MachineState *machine) +static void spapr_machine_reset(MachineState *machine, ShutdownCause reaso= n) { SpaprMachineState *spapr =3D SPAPR_MACHINE(machine); PowerPCCPU *first_ppc_cpu; @@ -1649,7 +1649,7 @@ static void spapr_machine_reset(MachineState *machine) spapr_setup_hpt(spapr); } =20 - qemu_devices_reset(); + qemu_devices_reset(reason); =20 spapr_ovec_cleanup(spapr->ov5_cas); spapr->ov5_cas =3D spapr_ovec_new(); diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 03855c7231..8017acb1d5 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -405,7 +405,7 @@ static void s390_pv_prepare_reset(S390CcwMachineState *= ms) s390_pv_prep_reset(); } =20 -static void s390_machine_reset(MachineState *machine) +static void s390_machine_reset(MachineState *machine, ShutdownCause reason) { S390CcwMachineState *ms =3D S390_CCW_MACHINE(machine); enum s390_reset reset_type; @@ -427,7 +427,7 @@ static void s390_machine_reset(MachineState *machine) s390_machine_unprotect(ms); } =20 - qemu_devices_reset(); + qemu_devices_reset(reason); s390_crypto_reset(); =20 /* configure and start the ipl CPU only */ diff --git a/include/hw/boards.h b/include/hw/boards.h index 311ed17e18..90f1dd3aeb 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -231,7 +231,7 @@ struct MachineClass { const char *deprecation_reason; =20 void (*init)(MachineState *state); - void (*reset)(MachineState *state); + void (*reset)(MachineState *state, ShutdownCause reason); void (*wakeup)(MachineState *state); int (*kvm_type)(MachineState *machine, const char *arg); =20 diff --git a/include/sysemu/reset.h b/include/sysemu/reset.h index 0b0d6d7598..609e4d50c2 100644 --- a/include/sysemu/reset.h +++ b/include/sysemu/reset.h @@ -1,10 +1,13 @@ #ifndef QEMU_SYSEMU_RESET_H #define QEMU_SYSEMU_RESET_H =20 +#include "qapi/qapi-events-run-state.h" + typedef void QEMUResetHandler(void *opaque); =20 void qemu_register_reset(QEMUResetHandler *func, void *opaque); +void qemu_register_reset_nosnapshotload(QEMUResetHandler *func, void *opaq= ue); void qemu_unregister_reset(QEMUResetHandler *func, void *opaque); -void qemu_devices_reset(void); +void qemu_devices_reset(ShutdownCause reason); =20 #endif diff --git a/migration/savevm.c b/migration/savevm.c index 48e85c052c..a0cdb714f7 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -3058,7 +3058,7 @@ bool load_snapshot(const char *name, const char *vmst= ate, goto err_drain; } =20 - qemu_system_reset(SHUTDOWN_CAUSE_NONE); + qemu_system_reset(SHUTDOWN_CAUSE_SNAPSHOT_LOAD); mis->from_src_file =3D f; =20 if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { diff --git a/qapi/run-state.json b/qapi/run-state.json index 49989d30e6..e44c0de914 100644 --- a/qapi/run-state.json +++ b/qapi/run-state.json @@ -86,12 +86,15 @@ # ignores --no-reboot. This is useful for sanitizing # hypercalls on s390 that are used during kexec/kdump/bo= ot # +# @snapshot-load: A snapshot is being loaded by the record & replay +# subsystem; internal value (since 7.2) +# ## { 'enum': 'ShutdownCause', # Beware, shutdown_caused_by_guest() depends on enumeration order 'data': [ 'none', 'host-error', 'host-qmp-quit', 'host-qmp-system-reset', 'host-signal', 'host-ui', 'guest-shutdown', 'guest-reset', - 'guest-panic', 'subsystem-reset'] } + 'guest-panic', 'subsystem-reset', 'snapshot-load'] } =20 ## # @StatusInfo: diff --git a/softmmu/runstate.c b/softmmu/runstate.c index 1e68680b9d..3dd83d5e5d 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -441,11 +441,16 @@ void qemu_system_reset(ShutdownCause reason) cpu_synchronize_all_states(); =20 if (mc && mc->reset) { - mc->reset(current_machine); + mc->reset(current_machine, reason); } else { - qemu_devices_reset(); + qemu_devices_reset(reason); } - if (reason && reason !=3D SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { + switch (reason) { + case SHUTDOWN_CAUSE_NONE: + case SHUTDOWN_CAUSE_SUBSYSTEM_RESET: + case SHUTDOWN_CAUSE_SNAPSHOT_LOAD: + break; + default: qapi_event_send_reset(shutdown_caused_by_guest(reason), reason); } cpu_synchronize_all_post_reset(); --=20 2.38.1 From nobody Sat May 18 03:01:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1666659010; cv=none; d=zohomail.com; s=zohoarc; b=cQoJUKe6EG+QU4GZNgCypTlXj4AgjKzfOC5k28Vhz3bfY9Q5016zVS3OGlwU0RAtWXoE5pHleVaG8axq76vOM3FmoS+Pmwe7IB4v7C2pYOimKM1t/V9yEZ8DA4AskK2tlYXEt5r94A2ZDhVHviUl+ylbEc9YisLIcXPamFGspcg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666659010; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mbbFBZxOYFy4Zfuf8OqG4mrJyea5K03RVWzfP1v5dzM=; b=Vp0SfQMCL0lWL1HPjxgcB5Ur7l0hrIcVRqmjxux9n/qIADn5RgFhZ+4MjsC1lPWF/m0bi/fsWF/UPzNdndMAgz6UvqS/vGuLm0W12wEEcrtF/fLL1Jf7zWmPYytK8/SpT/lQO2sNaVmtXEO2jR+bTKABS4bpUZ9+KHOJZQ/bNvA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666659010137894.0864010263865; Mon, 24 Oct 2022 17:50:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on82s-0002lA-PE; Mon, 24 Oct 2022 20:43:54 -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 1on82r-0002Ur-Ey for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:43:53 -0400 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on82p-0005CO-Qh for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:43:53 -0400 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 dfw.source.kernel.org (Postfix) with ESMTPS id F061E616D7; Tue, 25 Oct 2022 00:43:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84911C433C1; Tue, 25 Oct 2022 00:43:42 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id cd7de717 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 25 Oct 2022 00:43:41 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="e3cEMzH7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666658621; 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=mbbFBZxOYFy4Zfuf8OqG4mrJyea5K03RVWzfP1v5dzM=; b=e3cEMzH7D9YrNitdh9pUoIi52oGo/wYsdnfALpUdVwb6lpzI/fnqbN9XJV2sIPz4QaZ1BO zEUX3Kc00pjWpilLTcKFAGL29YnXOo1yJo4f/xsF0JqjblZZHS/QTZtWA3rhN6rWSUl5me 6h4aYUGv2/dHTqAKRyAybZ8eqi1pxiw= From: "Jason A. Donenfeld" To: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: "Jason A. Donenfeld" , Alistair Francis , David Gibson Subject: [PATCH v4 02/11] device-tree: add re-randomization helper function Date: Tue, 25 Oct 2022 02:43:18 +0200 Message-Id: <20221025004327.568476-3-Jason@zx2c4.com> In-Reply-To: <20221025004327.568476-1-Jason@zx2c4.com> References: <20221025004327.568476-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2604:1380:4641:c500::1; envelope-from=SRS0=a4uw=22=zx2c4.com=Jason@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1666659012262100003 Content-Type: text/plain; charset="utf-8" When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Several architectures require this functionality, so export a function for injecting a new seed into the given FDT. Cc: Alistair Francis Cc: David Gibson Signed-off-by: Jason A. Donenfeld Reviewed-by: Alistair Francis --- include/sysemu/device_tree.h | 9 +++++++++ softmmu/device_tree.c | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h index e7c5441f56..ca5339beae 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -197,6 +197,15 @@ int qemu_fdt_setprop_sized_cells_from_array(void *fdt, qdt_tmp); \ }) =20 + +/** + * qemu_fdt_randomize_seeds: + * @fdt: device tree blob + * + * Re-randomize all "rng-seed" properties with new seeds. + */ +void qemu_fdt_randomize_seeds(void *fdt); + #define FDT_PCI_RANGE_RELOCATABLE 0x80000000 #define FDT_PCI_RANGE_PREFETCHABLE 0x40000000 #define FDT_PCI_RANGE_ALIASED 0x20000000 diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c index ce74f3d48d..30aa3aea9f 100644 --- a/softmmu/device_tree.c +++ b/softmmu/device_tree.c @@ -22,6 +22,7 @@ #include "qemu/option.h" #include "qemu/bswap.h" #include "qemu/cutils.h" +#include "qemu/guest-random.h" #include "sysemu/device_tree.h" #include "hw/loader.h" #include "hw/boards.h" @@ -680,3 +681,23 @@ void hmp_dumpdtb(Monitor *mon, const QDict *qdict) =20 info_report("dtb dumped to %s", filename); } + +void qemu_fdt_randomize_seeds(void *fdt) +{ + int noffset, poffset, len; + const char *name; + uint8_t *data; + + for (noffset =3D fdt_next_node(fdt, 0, NULL); + noffset >=3D 0; + noffset =3D fdt_next_node(fdt, noffset, NULL)) { + for (poffset =3D fdt_first_property_offset(fdt, noffset); + poffset >=3D 0; + poffset =3D fdt_next_property_offset(fdt, poffset)) { + data =3D (uint8_t *)fdt_getprop_by_offset(fdt, poffset, &name,= &len); + if (!data || strcmp(name, "rng-seed")) + continue; + qemu_guest_getrandom_nofail(data, len); + } + } +} --=20 2.38.1 From nobody Sat May 18 03:01:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1666659014; cv=none; d=zohomail.com; s=zohoarc; b=TgIFYBMUJDm/bCAKSFpqXZpBxrCHfbXXQTz71lf/Uvr8pT6xpBCm0gJnVn8JEUmPZ65EKk04do4m5AGwVqd00XX8eMt591G1MSvpBfxuZm08tvUiJpnvEzZZz3zgTt/NfdmdyU6i+yZgyVTfNy427GzDCVNIqlFNhVUufnNXMSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666659014; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UyBNdz6QOGFZ2HRazRqwrQ+cVRUmAFmpKB4TPiAWBbk=; b=NP/xQnheyC2FNd2W9Ptpe5/F4gUwDscf0XYQjF0dvnmsUNuyVLTTmlLhsrIL261bWZCc5MpxHZMSEUuAlYkiCfYjByFOrP29UuF/lR6SOSSInyFwBuS3/9xcwb9HZL6NjohdcfOeUsy9dNwuLEctI8/EJkomabstjvEG+ErmeMs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666659014691765.0979733688935; Mon, 24 Oct 2022 17:50:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on82v-0003E0-2j; Mon, 24 Oct 2022 20:43:57 -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 1on82p-00025y-T7 for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:43:51 -0400 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on82m-0005Cm-Kz for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:43:51 -0400 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 dfw.source.kernel.org (Postfix) with ESMTPS id BEBA7616D8; Tue, 25 Oct 2022 00:43:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD0C8C433D6; Tue, 25 Oct 2022 00:43:46 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 4d97ebf8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 25 Oct 2022 00:43:45 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="KUtT7ywq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666658625; 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=UyBNdz6QOGFZ2HRazRqwrQ+cVRUmAFmpKB4TPiAWBbk=; b=KUtT7ywq+THIMdU4adPqybN3PbnZbUaDc92M1ohSPz9dqQXXQc4P+hmqPo9HMt+9uubsME VlfRP0vGlN48NwpgZ9lbJ2p4lDbwTzMpgEXiUaGAW1y3Ugj9GvHsxlYvT7pyZN7NZHP0Oh I5mcFK9SpYXgbLtOeqvkP3VTAYZbHmE= From: "Jason A. Donenfeld" To: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: "Jason A. Donenfeld" Subject: [PATCH v4 03/11] x86: do not re-randomize RNG seed on snapshot load Date: Tue, 25 Oct 2022 02:43:19 +0200 Message-Id: <20221025004327.568476-4-Jason@zx2c4.com> In-Reply-To: <20221025004327.568476-1-Jason@zx2c4.com> References: <20221025004327.568476-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2604:1380:4641:c500::1; envelope-from=SRS0=a4uw=22=zx2c4.com=Jason@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1666659016045100001 Content-Type: text/plain; charset="utf-8" Snapshot loading is supposed to be deterministic, so we shouldn't re-randomize the various seeds used. Signed-off-by: Jason A. Donenfeld --- hw/i386/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 1148f70c03..bd50a064a3 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1111,7 +1111,7 @@ void x86_load_linux(X86MachineState *x86ms, setup_data->type =3D cpu_to_le32(SETUP_RNG_SEED); setup_data->len =3D cpu_to_le32(RNG_SEED_LENGTH); qemu_guest_getrandom_nofail(setup_data->data, RNG_SEED_LENGTH); - qemu_register_reset(reset_rng_seed, setup_data); + qemu_register_reset_nosnapshotload(reset_rng_seed, setup_data); fw_cfg_add_bytes_callback(fw_cfg, FW_CFG_KERNEL_DATA, reset_rng_se= ed, NULL, setup_data, kernel, kernel_size, true); } else { --=20 2.38.1 From nobody Sat May 18 03:01:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1666659044; cv=none; d=zohomail.com; s=zohoarc; b=mkUIiWYVB35k7yzwK1oZEDn6RM90OgKp41qg8Yjxk6J7tA0IC2MNSzX3iKiJCixZSv+FAQMckzte9fh3JDMacVs0EIcAuUWnUIl5ENKUoKq+wrjB/LVBXoQFT0B6wJMOzirw56coh8Rl8dDCopy7vrGY9R3PZQ21Y2qyCYCqTn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666659044; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RanAds+xBge68b64kZDRt7NuRJe5o63knTfwLsKT7L4=; b=XFNvBbSvlj6wyvlWCLiNBPsBmULrytVQ6uUUqNbmuV5wERd5C+lv9lz+nrh28V87rsblKadAOJ8GdDrW5REi6VNPez7eQFgn7Z60s6vEd98kixv3i1vlpXrlYGuN3NXk6/fG6kp1xuDkJ2+hT6aX9bwZpgs+ydIZghigeyUCq0A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666659044274753.014472744534; Mon, 24 Oct 2022 17:50:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on82t-0002v4-Fj; Mon, 24 Oct 2022 20:43:55 -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 1on82r-0002Sw-B2; Mon, 24 Oct 2022 20:43:53 -0400 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on82p-0005DN-Pf; Mon, 24 Oct 2022 20:43:53 -0400 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 dfw.source.kernel.org (Postfix) with ESMTPS id B166D616D3; Tue, 25 Oct 2022 00:43:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76187C433D6; Tue, 25 Oct 2022 00:43:49 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id a79714c3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 25 Oct 2022 00:43:48 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="NWa7MnIy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666658628; 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=RanAds+xBge68b64kZDRt7NuRJe5o63knTfwLsKT7L4=; b=NWa7MnIyGEd3vccWSpj5Gc7PwWbnO8Bjp8gT5cchwNJECLjvXZgU4XtgPlv7RpLQ1PB2Rs bASTF1zO0e3IwQ9pFWRtK77oWxpcP4zVA9y78hf5CKtH/ka2u6urJH2kftyZVvuIX/63Im 0UKN9mrSkQSuLiFXBz0YDx+OiKQwpx0= From: "Jason A. Donenfeld" To: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: "Jason A. Donenfeld" , qemu-arm@nongnu.org Subject: [PATCH v4 04/11] arm: re-randomize rng-seed on reboot Date: Tue, 25 Oct 2022 02:43:20 +0200 Message-Id: <20221025004327.568476-5-Jason@zx2c4.com> In-Reply-To: <20221025004327.568476-1-Jason@zx2c4.com> References: <20221025004327.568476-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2604:1380:4641:c500::1; envelope-from=SRS0=a4uw=22=zx2c4.com=Jason@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1666659046203100003 Content-Type: text/plain; charset="utf-8" When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Since the FDT is in the ROM region at this point, we add a hook right after the ROM has been added, so that we have a pointer to that copy of the FDT. Cc: Peter Maydell Cc: qemu-arm@nongnu.org Signed-off-by: Jason A. Donenfeld --- hw/arm/boot.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index b0b92af188..b106f31468 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -683,6 +683,8 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, * the DTB is copied again upon reset, even if addr points into RAM. */ rom_add_blob_fixed_as("dtb", fdt, size, addr, as); + qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds, + rom_ptr_for_as(as, addr, size)); =20 g_free(fdt); =20 --=20 2.38.1 From nobody Sat May 18 03:01:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1666658793; cv=none; d=zohomail.com; s=zohoarc; b=E2kFuJnbU2zgvQpnrDAQr7Ttdp6zS+eQyPoVOqYraptCoZ+e8ceKg8E5kkzjuC4EU4CSIP5WbpeubckoOHTqMIgsBZXtz0gjj98rYwdo0z4Hbnj7BV/hMBNy+MbguZgw/Xg3BnPJi1F5g247YRtVHveOIDdF4wWTKPI+8rnSXW0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666658793; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pWgHHf5sujP6iTUGGEkOEJD6tNbkAvI7pDJ41Ebu1BU=; b=BYhJ/JM18FQjVEzs+BREEETW2rbAZUJw16o34Na6jUvrY1KXTetyw6fTqjzMGzJobTgHGmIqy78AJ5qGW2LRTlHgH7bVuHUQEeWpmEkdWhoQeaFhpwLPoPoD9N2rxnrrilFzItDBSt48PO7vAZgxvP62bRSQVDiKcgv10bBbn2A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666658793042477.392615301306; Mon, 24 Oct 2022 17:46:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on832-0004H0-Fp; Mon, 24 Oct 2022 20:44:04 -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 1on830-00045R-GX; Mon, 24 Oct 2022 20:44:02 -0400 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on82y-0005Fd-UQ; Mon, 24 Oct 2022 20:44:02 -0400 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 05B33B80EDF; Tue, 25 Oct 2022 00:43:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 767FDC433C1; Tue, 25 Oct 2022 00:43:54 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 3e6d250c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 25 Oct 2022 00:43:52 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="G1KF+vIo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666658632; 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=pWgHHf5sujP6iTUGGEkOEJD6tNbkAvI7pDJ41Ebu1BU=; b=G1KF+vIoe+LYD4qwrJ+MF0ODWCndwMsGgmHjSo5GL4P1TZ5EiXEuna3rQHmUH3Z4Ze9vBi vyyAW7TpJAEELB4f9pY7q/g1PSjUxjxEzDHgHR4WIoDPzhzjLWF5pjPGHw+Lk8Yt5SqwTD kwqR6GAWa9c+hn6vwA5iSOvgMEJRNlQ= From: "Jason A. Donenfeld" To: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: "Jason A. Donenfeld" , Palmer Dabbelt , Alistair Francis , Bin Meng , qemu-riscv@nongnu.org Subject: [PATCH v4 05/11] riscv: re-randomize rng-seed on reboot Date: Tue, 25 Oct 2022 02:43:21 +0200 Message-Id: <20221025004327.568476-6-Jason@zx2c4.com> In-Reply-To: <20221025004327.568476-1-Jason@zx2c4.com> References: <20221025004327.568476-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2604:1380:4601:e00::1; envelope-from=SRS0=a4uw=22=zx2c4.com=Jason@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1666658794730100003 Content-Type: text/plain; charset="utf-8" When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Since the FDT is in the ROM region at this point, we add a hook right after the ROM has been added, so that we have a pointer to that copy of the FDT. Cc: Palmer Dabbelt Cc: Alistair Francis Cc: Bin Meng Cc: qemu-riscv@nongnu.org Signed-off-by: Jason A. Donenfeld Reviewed-by: Alistair Francis --- hw/riscv/boot.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c index e82bf27338..ebd351c840 100644 --- a/hw/riscv/boot.c +++ b/hw/riscv/boot.c @@ -30,6 +30,7 @@ #include "sysemu/device_tree.h" #include "sysemu/qtest.h" #include "sysemu/kvm.h" +#include "sysemu/reset.h" =20 #include =20 @@ -241,6 +242,8 @@ uint64_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_= size, void *fdt) =20 rom_add_blob_fixed_as("fdt", fdt, fdtsize, fdt_addr, &address_space_memory); + qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds, + rom_ptr_for_as(&address_space_memory, fdt_addr, fd= tsize)); =20 return fdt_addr; } --=20 2.38.1 From nobody Sat May 18 03:01:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1666659018; cv=none; d=zohomail.com; s=zohoarc; b=WF7ayvgv0JacBBsH4VgidBuJE233/kAsXR/psW7nrV+gWtBM9lwM3jTtTXBSLTvLDwCQ/QHb/F16ExGCFNrv42edstTppKqZFMYcy7XMpu/ytgcmLp96PWIwHMh5EyrKRbORBdz0+CperHB5VFJbPjTA16aLJQbXEYBYK1WmKuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666659018; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6kQwAsuAdm69PPzRbaPZt2minknZ85uFcatWBF75J38=; b=EzXSOVrIV2PYvGN/90bEMIRP+FXQMLLv5GjDxnsD33l6DDrcxiBvVet2drNll+LqxhDt36Gy1vbqvIkvQQWc/P5m70xoBb/PP8Pvn6WiatMHWpAbjW07f4fYaZ3U8WsHvOXjHNWSO2dpoiYE9nFLLjh85B3eYAAe6gTwuK+PeqY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666659018380980.5825101986619; Mon, 24 Oct 2022 17:50:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on83G-0004xK-IU; Mon, 24 Oct 2022 20:44:18 -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 1on83F-0004wr-3Z for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:17 -0400 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on831-0005Ft-AS for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:16 -0400 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 sin.source.kernel.org (Postfix) with ESMTPS id 1C44ECE1ABA; Tue, 25 Oct 2022 00:44:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E550FC433C1; Tue, 25 Oct 2022 00:43:57 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id d1b49b93 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 25 Oct 2022 00:43:56 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="hU/NnNm4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666658637; 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=6kQwAsuAdm69PPzRbaPZt2minknZ85uFcatWBF75J38=; b=hU/NnNm4fhR4qmjdMqy+/UfIkENOw+RYpCoazkb/fKVf6Aum8P0ugckWWTBPoAY79PTU0f ustOOVotrIaErmWxVyUztjydJ0xmDNbmV6Ckbh4rI+K51qCksdXcS8ZYLK3kdydytx4v2p Y1+WmReaaYVy7xXnT6/Q7BtI3QlXr2I= From: "Jason A. Donenfeld" To: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: "Jason A. Donenfeld" Subject: [PATCH v4 06/11] m68k/virt: do not re-randomize RNG seed on snapshot load Date: Tue, 25 Oct 2022 02:43:22 +0200 Message-Id: <20221025004327.568476-7-Jason@zx2c4.com> In-Reply-To: <20221025004327.568476-1-Jason@zx2c4.com> References: <20221025004327.568476-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2604:1380:40e1:4800::1; envelope-from=SRS0=a4uw=22=zx2c4.com=Jason@kernel.org; helo=sin.source.kernel.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1666659020095100003 Content-Type: text/plain; charset="utf-8" Snapshot loading is supposed to be deterministic, so we shouldn't re-randomize the various seeds used. Signed-off-by: Jason A. Donenfeld --- hw/m68k/virt.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c index 89c4108eb5..da5eafd275 100644 --- a/hw/m68k/virt.c +++ b/hw/m68k/virt.c @@ -89,7 +89,6 @@ typedef struct { M68kCPU *cpu; hwaddr initial_pc; hwaddr initial_stack; - struct bi_record *rng_seed; } ResetInfo; =20 static void main_cpu_reset(void *opaque) @@ -98,16 +97,18 @@ static void main_cpu_reset(void *opaque) M68kCPU *cpu =3D reset_info->cpu; CPUState *cs =3D CPU(cpu); =20 - if (reset_info->rng_seed) { - qemu_guest_getrandom_nofail((void *)reset_info->rng_seed->data + 2, - be16_to_cpu(*(uint16_t *)reset_info->rng_seed->data)); - } - cpu_reset(cs); cpu->env.aregs[7] =3D reset_info->initial_stack; cpu->env.pc =3D reset_info->initial_pc; } =20 +static void rerandomize_rng_seed(void *opaque) +{ + struct bi_record *rng_seed =3D opaque; + qemu_guest_getrandom_nofail((void *)rng_seed->data + 2, + be16_to_cpu(*(uint16_t *)rng_seed->data)); +} + static void virt_init(MachineState *machine) { M68kCPU *cpu =3D NULL; @@ -289,9 +290,10 @@ static void virt_init(MachineState *machine) BOOTINFO0(param_ptr, BI_LAST); rom_add_blob_fixed_as("bootinfo", param_blob, param_ptr - param_bl= ob, parameters_base, cs->as); - reset_info->rng_seed =3D rom_ptr_for_as(cs->as, parameters_base, - param_ptr - param_blob) + - (param_rng_seed - param_blob); + qemu_register_reset_nosnapshotload(rerandomize_rng_seed, + rom_ptr_for_as(cs->as, parameters_base, + param_ptr - param_blob) + + (param_rng_seed - param_blob)); g_free(param_blob); } } --=20 2.38.1 From nobody Sat May 18 03:01:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1666658781; cv=none; d=zohomail.com; s=zohoarc; b=c+vxoRmKQ/kssuYr1UC1U1m9LsYMFWNp5MloVedICDjuHeKlnwV6VqagHW07+1NCidW0vLgqsL7sT+xRjKbRWd4/subFJDrohvAgyJndJsFoPtvBQdJm9KPyx58/+ODAXCSE9RbJI7B3GcQPrCSbPExgJKddWDCtLKGa+14834Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666658781; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PSDSTJntQgeB6fD3TLJoIWuYFhQpzOA1P8jCGQcwdzw=; b=YoXcsxvaEMiL9Fqoqb+uj67NT6Dddrx4JBj0ec4fM89rWOtVMTLY1AKJz51n4IcaNnaeAmNjZ0gHaD0olduvsESHg1u5BFLivqKHihSomD1cddcnd4be76Dq01cGuDjQ23obSOXHztHCaamV30GgH3YNVPd8qSufHhyr22U5zmY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666658781630362.39845220040286; Mon, 24 Oct 2022 17:46:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on833-0004MH-Bm; Mon, 24 Oct 2022 20:44:05 -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 1on832-0004Ge-2j for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:04 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on830-0005Fy-Fc for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:03 -0400 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 dfw.source.kernel.org (Postfix) with ESMTPS id B40BE616E2; Tue, 25 Oct 2022 00:44:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 982E6C433C1; Tue, 25 Oct 2022 00:44:00 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id eca2ec70 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 25 Oct 2022 00:43:59 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="XCmkfcQJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666658640; 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=PSDSTJntQgeB6fD3TLJoIWuYFhQpzOA1P8jCGQcwdzw=; b=XCmkfcQJk7hP/dK6ywqnI4UVym6d3akxGx10ax7Lq7e7Am5XtPm+wEdz4TjRW+q/i70LAH zkQgED97Ymnlyid9fxRIufgWY+cKOk3XFSGdKks1zlhj9r2YbQO4L1rSasiIcepSsQvAwt wMIbC+KLPCkYv20EMfq4Hae1eJNNHdU= From: "Jason A. Donenfeld" To: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: "Jason A. Donenfeld" Subject: [PATCH v4 07/11] m68k/q800: do not re-randomize RNG seed on snapshot load Date: Tue, 25 Oct 2022 02:43:23 +0200 Message-Id: <20221025004327.568476-8-Jason@zx2c4.com> In-Reply-To: <20221025004327.568476-1-Jason@zx2c4.com> References: <20221025004327.568476-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=139.178.84.217; envelope-from=SRS0=a4uw=22=zx2c4.com=Jason@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1666658782497100001 Content-Type: text/plain; charset="utf-8" Snapshot loading is supposed to be deterministic, so we shouldn't re-randomize the various seeds used. Signed-off-by: Jason A. Donenfeld --- hw/m68k/q800.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c index e09e244ddc..9d52ca6613 100644 --- a/hw/m68k/q800.c +++ b/hw/m68k/q800.c @@ -321,27 +321,23 @@ static const TypeInfo glue_info =3D { }, }; =20 -typedef struct { - M68kCPU *cpu; - struct bi_record *rng_seed; -} ResetInfo; - static void main_cpu_reset(void *opaque) { - ResetInfo *reset_info =3D opaque; - M68kCPU *cpu =3D reset_info->cpu; + M68kCPU *cpu =3D opaque; CPUState *cs =3D CPU(cpu); =20 - if (reset_info->rng_seed) { - qemu_guest_getrandom_nofail((void *)reset_info->rng_seed->data + 2, - be16_to_cpu(*(uint16_t *)reset_info->rng_seed->data)); - } - cpu_reset(cs); cpu->env.aregs[7] =3D ldl_phys(cs->as, 0); cpu->env.pc =3D ldl_phys(cs->as, 4); } =20 +static void rerandomize_rng_seed(void *opaque) +{ + struct bi_record *rng_seed =3D opaque; + qemu_guest_getrandom_nofail((void *)rng_seed->data + 2, + be16_to_cpu(*(uint16_t *)rng_seed->data)); +} + static uint8_t fake_mac_rom[] =3D { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, =20 @@ -397,7 +393,6 @@ static void q800_init(MachineState *machine) NubusBus *nubus; DeviceState *glue; DriveInfo *dinfo; - ResetInfo *reset_info; uint8_t rng_seed[32]; =20 linux_boot =3D (kernel_filename !=3D NULL); @@ -408,12 +403,9 @@ static void q800_init(MachineState *machine) exit(1); } =20 - reset_info =3D g_new0(ResetInfo, 1); - /* init CPUs */ cpu =3D M68K_CPU(cpu_create(machine->cpu_type)); - reset_info->cpu =3D cpu; - qemu_register_reset(main_cpu_reset, reset_info); + qemu_register_reset(main_cpu_reset, cpu); =20 /* RAM */ memory_region_add_subregion(get_system_memory(), 0, machine->ram); @@ -687,9 +679,10 @@ static void q800_init(MachineState *machine) BOOTINFO0(param_ptr, BI_LAST); rom_add_blob_fixed_as("bootinfo", param_blob, param_ptr - param_bl= ob, parameters_base, cs->as); - reset_info->rng_seed =3D rom_ptr_for_as(cs->as, parameters_base, - param_ptr - param_blob) + - (param_rng_seed - param_blob); + qemu_register_reset_nosnapshotload(rerandomize_rng_seed, + rom_ptr_for_as(cs->as, parameters_base, + param_ptr - param_blob) + + (param_rng_seed - param_blob)); g_free(param_blob); } else { uint8_t *ptr; --=20 2.38.1 From nobody Sat May 18 03:01:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1666659036; cv=none; d=zohomail.com; s=zohoarc; b=REeMtTLXB8F0re0OoMTIJrBui7F+4KCD8eV+yJfuEyWnHSy81DJ7l07xhzHsEEhhjdHXrxzoj1TRmAHPXmx8uJpINY1u5gp42O4b4KTANBrGH3r643IV0moPy0MUaJ83Fwu6gwU2bXja1Hkgbr5JAn7ll4x628g5chfGgKKeDm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666659036; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=X7NNISyd6iRl3En/rg1K1JP5VsPepMwmanaqetfFnUU=; b=Nky4XM3XgtLB/anh6KsJrbSa0POrIXLc5t/fSS1rhYY2de/ou2W0WC6B9jtKY0cmqVmwYEPPZ5FLOp6/HS0/Ejm2Zm8ByiVI+cE41UpUUIkiPDquCFk8qtSQNydQsKF5vI83teN2TAAnkaHR1RFBUO/qFUBsJQEcPUrpn/FXYLM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666659036084958.7054807818153; Mon, 24 Oct 2022 17:50:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on83E-0004wM-5f; Mon, 24 Oct 2022 20:44:16 -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 1on83C-0004vx-JI for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:14 -0400 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on838-0005Gt-GJ for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:14 -0400 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 sin.source.kernel.org (Postfix) with ESMTPS id EE97ECE1AC2; Tue, 25 Oct 2022 00:44:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 717EBC433C1; Tue, 25 Oct 2022 00:44:05 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 035073f4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 25 Oct 2022 00:44:04 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="Zr0A1cbj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666658644; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X7NNISyd6iRl3En/rg1K1JP5VsPepMwmanaqetfFnUU=; b=Zr0A1cbj8MUw7S/cCvWPRFx4qs11FhM4ugChvWv7xEP+djH+SneJ3BH3NFuiYZ01Otu8V9 grQS5zHEDo4qHWRax6zE1gfR8qc/PHVFXNeI2+bP5RNAG61DVDZpGb+nL1q0+hxC2LkaO9 R0p6zSoL9XizCgcx7bvRDnRc1u44pVc= From: "Jason A. Donenfeld" To: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: "Jason A. Donenfeld" , Aleksandar Rikalo , Paul Burton , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v4 08/11] mips/boston: re-randomize rng-seed on reboot Date: Tue, 25 Oct 2022 02:43:24 +0200 Message-Id: <20221025004327.568476-9-Jason@zx2c4.com> In-Reply-To: <20221025004327.568476-1-Jason@zx2c4.com> References: <20221025004327.568476-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2604:1380:40e1:4800::1; envelope-from=SRS0=a4uw=22=zx2c4.com=Jason@kernel.org; helo=sin.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1666659038136100003 When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Since the FDT is in the ROM region at this point, we add a hook right after the ROM has been added, so that we have a pointer to that copy of the FDT. Cc: Aleksandar Rikalo Cc: Paul Burton Cc: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Jason A. Donenfeld --- hw/mips/boston.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/mips/boston.c b/hw/mips/boston.c index d2ab9da1a0..cab63f43bf 100644 --- a/hw/mips/boston.c +++ b/hw/mips/boston.c @@ -41,6 +41,7 @@ #include "sysemu/sysemu.h" #include "sysemu/qtest.h" #include "sysemu/runstate.h" +#include "sysemu/reset.h" =20 #include #include "qom/object.h" @@ -810,6 +811,8 @@ static void boston_mach_init(MachineState *machine) /* Calculate real fdt size after filter */ dt_size =3D fdt_totalsize(dtb_load_data); rom_add_blob_fixed("dtb", dtb_load_data, dt_size, dtb_paddr); + qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds, + rom_ptr(dtb_paddr, dt_size)); } else { /* Try to load file as FIT */ fit_err =3D load_fit(&boston_fit_loader, machine->kernel_filen= ame, s); --=20 2.38.1 From nobody Sat May 18 03:01:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1666658950; cv=none; d=zohomail.com; s=zohoarc; b=hRUqesMzGAkyJonzkmiUYogZTkfCsdWtd/DBbxyu0eWAaZ/vBU5SAPVilCMI50/cN3lkn5gTZZ/QNJaiRbLieHCzy74bewVydYA9gn+hEAh2CW0BvEMZlg/MRqQlJhfWD8JK1bOO692w/2G1biPtivrftL0qgKFgvbnTS4xOzSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666658950; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hd5sLN7e5NHAIrDa5FhRY1Hjf03Wbgh/dmRxMOuwntI=; b=BYTX/Y2TZpYBafrdAY2UB6Vom83YlXaHJXT6/hfiL4GHCLJ77Os3ldatxMLpY08j32spi83Jq66R5R1EubiSwQSXyJMKvVfrfNHlBRVTmlK6nhgGrxkEzUha7OBJhuSC+oWIzm7OBLtcoAk7pqT4RJW/hw3kWr24JgqkL+a9kKs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666658950721875.8457695698337; Mon, 24 Oct 2022 17:49:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on83F-0004wm-0R; Mon, 24 Oct 2022 20:44:17 -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 1on83C-0004w4-U6 for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:14 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on839-0005HB-Kr for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:14 -0400 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 dfw.source.kernel.org (Postfix) with ESMTPS id DC337616E4; Tue, 25 Oct 2022 00:44:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EA3AC433C1; Tue, 25 Oct 2022 00:44:09 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 5d290634 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 25 Oct 2022 00:44:08 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="Ot3qJxyU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666658648; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hd5sLN7e5NHAIrDa5FhRY1Hjf03Wbgh/dmRxMOuwntI=; b=Ot3qJxyUpfRWqTMi08pSBV8U91yuoP9ZVSoJ9cR8uiJpWf9uVxExcnytMiuMFTLOitOn6S KOVKEjcZINg48m69kMqpqDX7OpZJWxDM/qXVDE4vVxivADZj3BpyT/tnCOb94qgY8xiR2H fX0ItvBm1SvadL9v/WR9pvv0qSZ9lnA= From: "Jason A. Donenfeld" To: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: "Jason A. Donenfeld" , Aleksandar Rikalo , Paul Burton , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v4 09/11] mips/malta: pass RNG seed via env var and re-randomize on reboot Date: Tue, 25 Oct 2022 02:43:25 +0200 Message-Id: <20221025004327.568476-10-Jason@zx2c4.com> In-Reply-To: <20221025004327.568476-1-Jason@zx2c4.com> References: <20221025004327.568476-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=139.178.84.217; envelope-from=SRS0=a4uw=22=zx2c4.com=Jason@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1666658951647100001 As of the kernel commit linked below, Linux ingests an RNG seed passed as part of the environment block by the bootloader or firmware. This mechanism works across all different environment block types, generically, which pass some block via the second firmware argument. On malta, this has been tested to work when passed as an argument from U-Boot's linux_env_set. As is the case on most other architectures (such as boston), when booting with `-kernel`, QEMU, acting as the bootloader, should pass the RNG seed, so that the machine has good entropy for Linux to consume. So this commit implements that quite simply by using the guest random API, which is what is used on nearly all other archs too. It also reinitializes the seed on reboot, so that it is always fresh. Link: https://git.kernel.org/torvalds/c/056a68cea01 Cc: Aleksandar Rikalo Cc: Paul Burton Cc: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Jason A. Donenfeld --- hw/mips/malta.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/hw/mips/malta.c b/hw/mips/malta.c index 0e932988e0..d337de920c 100644 --- a/hw/mips/malta.c +++ b/hw/mips/malta.c @@ -26,6 +26,7 @@ #include "qemu/units.h" #include "qemu/bitops.h" #include "qemu/datadir.h" +#include "qemu/guest-random.h" #include "hw/clock.h" #include "hw/southbridge/piix.h" #include "hw/isa/superio.h" @@ -1017,6 +1018,17 @@ static void G_GNUC_PRINTF(3, 4) prom_set(uint32_t *p= rom_buf, int index, va_end(ap); } =20 +static void reinitialize_rng_seed(void *opaque) +{ + char *rng_seed_hex =3D opaque; + uint8_t rng_seed[32]; + + qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); + for (size_t i =3D 0; i < sizeof(rng_seed); ++i) { + sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]); + } +} + /* Kernel */ static uint64_t load_kernel(void) { @@ -1028,6 +1040,8 @@ static uint64_t load_kernel(void) long prom_size; int prom_index =3D 0; uint64_t (*xlate_to_kseg0) (void *opaque, uint64_t addr); + uint8_t rng_seed[32]; + char rng_seed_hex[sizeof(rng_seed) * 2 + 1]; =20 #if TARGET_BIG_ENDIAN big_endian =3D 1; @@ -1115,9 +1129,20 @@ static uint64_t load_kernel(void) =20 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 =3D 0; i < sizeof(rng_seed); ++i) { + sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]); + } + prom_set(prom_buf, prom_index++, "rngseed"); + prom_set(prom_buf, prom_index++, "%s", rng_seed_hex); + prom_set(prom_buf, prom_index++, NULL); =20 rom_add_blob_fixed("prom", prom_buf, prom_size, ENVP_PADDR); + qemu_register_reset_nosnapshotload(reinitialize_rng_seed, + memmem(rom_ptr(ENVP_PADDR, prom_size), prom_size, + rng_seed_hex, sizeof(rng_seed_hex))); =20 g_free(prom_buf); return kernel_entry; --=20 2.38.1 From nobody Sat May 18 03:01:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1666659072; cv=none; d=zohomail.com; s=zohoarc; b=gRbfp77CPzGOgd9FFWM0d+8dW+TObLB+6qWJ0vr11VfjvXgm1aMRgS1uRBuowT/LIXVHxrUbEr0r3PdKaof78n/LwuElfBaRLvj3KqK1s18g6VMdIfSTILv5Puv4dysfdiB0gEN47CF4Pi8e+ey3zOmLAnNdSphD4fzDBksUx0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666659072; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ATL8rtbSuz39xKOTaSAyB9TBkVZPhRXgfwvL3gzMBVU=; b=cDRaCv7z4YFiljV9jU4MrHgtc9j/Qpk8W0ttNSxfkt2QTxtsUMvmLA2e0gKq4JUltbZQTV63BqVYotdwnQGJ9Ac1Vh38LY2ANpEQAWCEw5aCi96pkkHvNUYMwHXgL58i9GYc1feDUvbu8efyv9GEcD7SMPwAyQixOsyrDsjkmnY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666659072894314.18588736343565; Mon, 24 Oct 2022 17:51:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on83H-0004xO-3U; Mon, 24 Oct 2022 20:44:19 -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 1on83F-0004wz-HP for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:17 -0400 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on83E-0005Hh-1g for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:17 -0400 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 89171B8170E; Tue, 25 Oct 2022 00:44:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90C4FC433D6; Tue, 25 Oct 2022 00:44:12 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 7bfb554f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 25 Oct 2022 00:44:11 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="WvMDl5so" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666658652; 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=ATL8rtbSuz39xKOTaSAyB9TBkVZPhRXgfwvL3gzMBVU=; b=WvMDl5soWa2tbJw/FpyB8EEPETQXNrirx+IcbqNCCKylFZ82oNd+78xyy4Op7XFBkyUs51 VK4BzL77rlrukeJdf2e4VWClKhbipxeGckq96/VrXB1ucm3J0SMj4cjCIsGO2riZsMoOpF xLqcZfBOOd9CfehyRWtL7X2Ubh2vXf0= From: "Jason A. Donenfeld" To: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: "Jason A. Donenfeld" , Stafford Horne Subject: [PATCH v4 10/11] openrisc: re-randomize rng-seed on reboot Date: Tue, 25 Oct 2022 02:43:26 +0200 Message-Id: <20221025004327.568476-11-Jason@zx2c4.com> In-Reply-To: <20221025004327.568476-1-Jason@zx2c4.com> References: <20221025004327.568476-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2604:1380:4601:e00::1; envelope-from=SRS0=a4uw=22=zx2c4.com=Jason@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1666659074430100003 Content-Type: text/plain; charset="utf-8" When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Since the FDT is in the ROM region at this point, we add a hook right after the ROM has been added, so that we have a pointer to that copy of the FDT. Cc: Stafford Horne Signed-off-by: Jason A. Donenfeld --- hw/openrisc/boot.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/openrisc/boot.c b/hw/openrisc/boot.c index 128ccbcba2..007e80cd5a 100644 --- a/hw/openrisc/boot.c +++ b/hw/openrisc/boot.c @@ -14,6 +14,7 @@ #include "hw/openrisc/boot.h" #include "sysemu/device_tree.h" #include "sysemu/qtest.h" +#include "sysemu/reset.h" =20 #include =20 @@ -111,6 +112,8 @@ uint32_t openrisc_load_fdt(void *fdt, hwaddr load_start, =20 rom_add_blob_fixed_as("fdt", fdt, fdtsize, fdt_addr, &address_space_memory); + qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds, + rom_ptr_for_as(&address_space_memory, fdt_addr, fd= tsize)); =20 return fdt_addr; } --=20 2.38.1 From nobody Sat May 18 03:01:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1666659040; cv=none; d=zohomail.com; s=zohoarc; b=C6Qj3m8cRIoU2fwhMW7afq2qya5po60Ii+xv5LGLS6o3SVIBw0V49pkCxJgQmJ5DnDiRrTXnj+BnUsUnouXK6nBUEEfvTAprPBKAyI8Ei6M3N1NtumVma2TwRkhQEmoQIr/E8C4KfK7GET+yTKpGyAa+UgCpum87gLfRWUIXS4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666659040; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F5e4XKRRUsbA42Uj4xQzXOtzJtgRZcaiKVrqwgHgg5g=; b=VFrbW5+PpNrGCmn+KstnwJN7DntrR3YX3sNMHL3CkVl8DrssYlDDSXyT77U+GetCmMg87CxqIWIJdVYtfEKfR6wVlD44kLFurslQVN5FOv7kXQ1qXKXPqYJNZ2OfgSyck36E9s92GKreqqnx+yrZsodwuHOPr235A0OX8o+7aro= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666659040034354.94849359351485; Mon, 24 Oct 2022 17:50:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on83M-0004yP-PI; Mon, 24 Oct 2022 20:44:24 -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 1on83L-0004xx-2R for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:23 -0400 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on83H-0005IX-Qu for qemu-devel@nongnu.org; Mon, 24 Oct 2022 20:44:22 -0400 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 dfw.source.kernel.org (Postfix) with ESMTPS id E2235616D5; Tue, 25 Oct 2022 00:44:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A8DFC433D6; Tue, 25 Oct 2022 00:44:17 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 3bc31a94 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 25 Oct 2022 00:44:15 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="Vh2qZ0e7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666658655; 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=F5e4XKRRUsbA42Uj4xQzXOtzJtgRZcaiKVrqwgHgg5g=; b=Vh2qZ0e72kVgiSk6ysZsrZCzv9wF7DKHupGJf5OOHcAxHsq1j0B4Gw6aPGRSVqIzEu0cnU yLs3k46Ap/bSCPEUlDC2tlj/EdkJgFUrbZjvStB4zhlOn/cSEOK6VZ3yErheyiI4yZbqpL VQPLJjjBE6OZbRegxWAc5U49fBjcyq4= From: "Jason A. Donenfeld" To: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: "Jason A. Donenfeld" , Yoshinori Sato Subject: [PATCH v4 11/11] rx: re-randomize rng-seed on reboot Date: Tue, 25 Oct 2022 02:43:27 +0200 Message-Id: <20221025004327.568476-12-Jason@zx2c4.com> In-Reply-To: <20221025004327.568476-1-Jason@zx2c4.com> References: <20221025004327.568476-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2604:1380:4641:c500::1; envelope-from=SRS0=a4uw=22=zx2c4.com=Jason@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1666659042256100003 Content-Type: text/plain; charset="utf-8" When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Since the FDT is in the ROM region at this point, we add a hook right after the ROM has been added, so that we have a pointer to that copy of the FDT. Cc: Yoshinori Sato Signed-off-by: Jason A. Donenfeld --- hw/rx/rx-gdbsim.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/rx/rx-gdbsim.c b/hw/rx/rx-gdbsim.c index 8ffe1b8035..47c17026c7 100644 --- a/hw/rx/rx-gdbsim.c +++ b/hw/rx/rx-gdbsim.c @@ -25,6 +25,7 @@ #include "hw/rx/rx62n.h" #include "sysemu/qtest.h" #include "sysemu/device_tree.h" +#include "sysemu/reset.h" #include "hw/boards.h" #include "qom/object.h" =20 @@ -148,6 +149,8 @@ static void rx_gdbsim_init(MachineState *machine) dtb_offset =3D ROUND_DOWN(machine->ram_size - dtb_size, 16); rom_add_blob_fixed("dtb", dtb, dtb_size, SDRAM_BASE + dtb_offset); + qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds, + rom_ptr(SDRAM_BASE + dtb_offset, dtb_size)= ); /* Set dtb address to R1 */ RX_CPU(first_cpu)->env.regs[1] =3D SDRAM_BASE + dtb_offset; } --=20 2.38.1