From nobody Mon Nov 10 01:15:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552621748239200.89688980906897; Thu, 14 Mar 2019 20:49:08 -0700 (PDT) Received: from localhost ([127.0.0.1]:48881 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dq2-0007z9-90 for importer@patchew.org; Thu, 14 Mar 2019 23:48:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcK-00059t-OD for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUd-0002uK-2I for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:48 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:35955) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUc-0002tF-Of for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:46 -0400 Received: by mail-pg1-x544.google.com with SMTP id r124so5420878pgr.3 for ; Thu, 14 Mar 2019 20:26:46 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5+Jw4ZT6nk5aJg5eDzucU6N22SG+dxTKxW+ellIVCNM=; b=tMmNvRpMJrGhYLsEIf4jmznWcXYIftlDl3x4Cdf9zJdFiNrZgBtC6V0NXgLiIFOD/n 6HT16AI4oNtuHY/uJQILouC1ME89evWsGJ4eTBy2BCX7OrGcItJ0vWWjEhz+BETZ1Wf5 jQYWiYCS1EJB8R5gFicUgF2H+bjj+Z1ZxzcfsRJ41WHjb1oIrAaJ7unrKqka2wVjo8VA OJznZEqPi6xD/1o0SVHqeyZDgDf/K2krX6ZsOSci9+MKC5ceD5j/SSII2rS6OeqEE1AD 8VdU2HzQYTKxDMxNDLZKLZ6QOSwB8C3VmNZ4zG5DhjjQr2ATI9g/b2rLvYFnn1mlJN6x IjWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5+Jw4ZT6nk5aJg5eDzucU6N22SG+dxTKxW+ellIVCNM=; b=alzZCiHISfHymwfH4FLchRWKofkIPWl2Cg+Dkh5sSHT/X8NBvDc+HlE4sjm9EVHYYL N9WH7X/RYJ2RW9hGoURnfadt2wMfOE55GgMZEwW1tD/a6w70Qw55ZI22X4XSF/qKlfar cF3OuIP7lFkMnG0ZgQpmq0nYwxL4QqoNkoiVlMDsj8yZxu9JoOuXNr6opq9MO0NqvVpb KOk1omsgzisxiRkUt6AOsrYoWz8yUvw5hw+wPkfhRjErSMwRMCATRSGFjLTDdV0CUm2Q bNkHbBbSlRMsPuur5UwJMCRPSdMphnxALZMaMRlBuei/YbtKKMZuscLjiuz7jxzm5Dm/ 3f0A== X-Gm-Message-State: APjAAAW003x/6sQC6zwmBOaqUe+n3fp8UkkyYjsp4kSXZj5gc03gF94w MyefPm5hPXVYpvUNO6d4lUHFiIBtHJI= X-Google-Smtp-Source: APXvYqzgwvsuvHNSixShHU3bXdyjCvL/ubX2UKw9ks0bASbQUi4WH4LtgViXdIQnhnd6uDSVRoBRIw== X-Received: by 2002:a62:d281:: with SMTP id c123mr1708816pfg.210.1552620405151; Thu, 14 Mar 2019 20:26:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:16 -0700 Message-Id: <20190315032629.21234-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH v3 10/23] cpus: Initialize pseudo-random seeds for all guest cpus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) When the -seed option is given, call qemu_guest_random_seed_main, putting the subsystem into deterministic mode. Pass derived seeds to each cpu created; which is a no-op unless the subsystem is in deterministic mode. Cc: Daniel P. Berrang=C3=A9 Signed-off-by: Richard Henderson Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qom/cpu.h | 1 + cpus.c | 9 +++++++++ vl.c | 4 ++++ qemu-options.hx | 10 ++++++++++ 4 files changed, 24 insertions(+) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 1d6099e5d4..343cc6d51e 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -372,6 +372,7 @@ struct CPUState { int singlestep_enabled; int64_t icount_budget; int64_t icount_extra; + uint64_t random_seed; sigjmp_buf jmp_env; =20 QemuMutex work_mutex; diff --git a/cpus.c b/cpus.c index e83f72b48b..6d88f6bfcd 100644 --- a/cpus.c +++ b/cpus.c @@ -49,6 +49,7 @@ #include "qemu/option.h" #include "qemu/bitmap.h" #include "qemu/seqlock.h" +#include "qemu/guest-random.h" #include "tcg.h" #include "hw/nmi.h" #include "sysemu/replay.h" @@ -1275,6 +1276,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created =3D true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 do { if (cpu_can_run(cpu)) { @@ -1318,6 +1320,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created =3D true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 do { qemu_mutex_unlock_iothread(); @@ -1477,6 +1480,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) cpu->created =3D true; cpu->can_do_io =3D 1; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 /* wait for initial kick-off after machine start */ while (first_cpu->stopped) { @@ -1591,6 +1595,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg) =20 hax_init_vcpu(cpu); qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 do { if (cpu_can_run(cpu)) { @@ -1630,6 +1635,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created =3D true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 do { if (cpu_can_run(cpu)) { @@ -1670,6 +1676,7 @@ static void *qemu_whpx_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created =3D true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 do { if (cpu_can_run(cpu)) { @@ -1723,6 +1730,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) cpu->can_do_io =3D 1; current_cpu =3D cpu; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 /* process any pending work */ cpu->exit_request =3D 1; @@ -2070,6 +2078,7 @@ void qemu_init_vcpu(CPUState *cpu) cpu->nr_cores =3D smp_cores; cpu->nr_threads =3D smp_threads; cpu->stopped =3D true; + cpu->random_seed =3D qemu_guest_random_seed_thread_part1(); =20 if (!cpu->as) { /* If the target cpu hasn't set up any address spaces itself, diff --git a/vl.c b/vl.c index c1d5484e12..d84f883c2c 100644 --- a/vl.c +++ b/vl.c @@ -128,6 +128,7 @@ int main(int argc, char **argv) #include "qapi/qapi-commands-ui.h" #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" +#include "qemu/guest-random.h" =20 #define MAX_VIRTIO_CONSOLES 1 =20 @@ -3330,6 +3331,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_DFILTER: qemu_set_dfilter_ranges(optarg, &error_fatal); break; + case QEMU_OPTION_seed: + qemu_guest_random_seed_main(optarg, &error_fatal); + break; case QEMU_OPTION_s: add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); break; diff --git a/qemu-options.hx b/qemu-options.hx index 08749a3391..b8da998668 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3601,6 +3601,16 @@ the 0x200 sized block starting at 0xffffffc000080000= and another 0x1000 sized block starting at 0xffffffc00005f000. ETEXI =20 +DEF("seed", HAS_ARG, QEMU_OPTION_seed, \ + "-seed number seed the pseudo-random number generator\n", + QEMU_ARCH_ALL) +STEXI +@item -seed @var{number} +@findex -seed +Force the guest to use a deterministic pseudo-random number generator, see= ded +with @var{number}. This does not affect crypto routines within the host. +ETEXI + DEF("L", HAS_ARG, QEMU_OPTION_L, \ "-L path set the directory for the BIOS, VGA BIOS and keymaps\= n", QEMU_ARCH_ALL) --=20 2.17.2