From patchwork Fri May 10 01:24:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163801 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1729112ilr; Thu, 9 May 2019 18:37:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjgHohpCGYE0BakEL4DOz+FPEPsdN5PEYtxJ51hrsCw6p8C+7ZYf773QnjDintnzfUBgGC X-Received: by 2002:adf:dc8a:: with SMTP id r10mr5466221wrj.15.1557452234179; Thu, 09 May 2019 18:37:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452234; cv=none; d=google.com; s=arc-20160816; b=xD9BR9o6lX/OLsvhI3jMt6nanP5iheFid/BTPZzFS+lQj/gVGInt8tNjaZWhOi0VQd 0cda1c17G9GqE31/rirM1s4scB1fYEGco9U8Qa+ip5JV/uk3vxhabSaiWSYheli9wyfC aghZpuAVq9PbN5138E4ui7ZpeUhc8TIa8hbMKAnXffvn1tF00eBEr4XbJmn3bpOFPVM9 xOiJpxQj0fNuMpOKNjL2dUjTS5SUw0adFaFqKhBfUjw/bTt+qP9QINHPqhDF/Ucg1Avd HblcrVsLRyt+5/rsTlJ7UOuOF1Hni7+SRCMwX48pxiYIo6OjT3LtU2dJVQ1ZfWaiHLCc HX3Q== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=bkE8afCSKjfPsR7fgbmdbQ4E9wg03Ngr6ljSuu1sRofGBkxKswUU4UBVt7CmDN0r3u HSTrDOCUhGdImQXZ8wO7Xba36OH/fAj1DfsqrfHc92fbldgxIvT71Kl2xd0cIGT2Ikk+ Dv4kv5OS2P3ZH5/yIv8ZeTqPvZBdbU5fN8tvx3b3z5aocrnFrGZzDOESvhNncjQjZmNc Hlv/Ivz9oYxxiaX4mMx42AK4U1F1cgBKBHujPpWTmo39atUimDAI9t/G1e+oQsh2I7CO Db6iKaDA83PcHZpOgRr7j1JSMYsBVyhBIlSdcAjR/1we3Lu9M7XbHEAc6KjWaGC2xBhI CiPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=j8P2tzpn; 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=fail (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 k12si3144846wrv.21.2019.05.09.18.37.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:37:14 -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=fail header.i=@linaro.org header.s=google header.b=j8P2tzpn; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:35160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuTJ-0000oo-37 for patch@linaro.org; Thu, 09 May 2019 21:37:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHl-0006Jl-SM for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-000156-K3 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:17 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:40273) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHj-00013f-9s for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pg1-x544.google.com with SMTP id d31so2125001pgl.7 for ; Thu, 09 May 2019 18:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=j8P2tzpnte+SI9rVHVDw0BwJyYRgOSyAnzi3bejGi6puCKW8FtfkBUDN4sga2EKyI1 517pnckY6YQrLv6XnEBN7W/FLlYNwqxnyflyS03CvsB+/s9bLvF325v50n2mWb7WY6nq js9l8p0jBfH1snbf0fRYW470bUJwUVhYZCiIlUag67QHlH93ZHE12WtFKAJqvYqBNr2X 7h3TynJB1XhzmvnfqRGysbSOdBwvvYwOSs8kTxw4dLecTY6Rz6noiVSPxJdK9ygW7Avx kPVSuWWXaNvNXzK16YfZFtVZVxPYaBwHsuti6fla2EWIJo6y0a6oXk+ZFOsTTR6DxOro NFJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=eCHvkmc2nQKiKmkoJbXgLZ7avH/HOyjMYATFyC5F1ag13noahDf1G1CpeHwnBFqKUZ HF4pAVLy/cB3NgmYRVT0eeRh8FzfjTSC0zg0cRyPyP2S+hREsnwDcw1xopOxxlKhlGkk oJ3guigN5LF4lR7KkUgGaQXgXEiNmXxKSQLaaRds9jZyuaUcXAJA18T6iA0LFp+H3wQV TpsTW8w2/VXkenGJqhOVUl8XMGrhoI9i+AMQM9kKbwxovzUONlKjEbCsqU6mV+0Jg3l/ km2/5o2RSyS6oGKTaitEg94aItxZKfbn01HSTHIXTUGvuukyQLBbv/netocy2LSZhcBO 2BFQ== X-Gm-Message-State: APjAAAUmbPrhegO8D/ssaKrHuipFAIGadyQy3bkV5M4JRaeZ3N10VCAK CQZzp6uroH2fKIOYjAb+C28+n3MKi+M= X-Received: by 2002:a62:594b:: with SMTP id n72mr9866146pfb.186.1557451513774; Thu, 09 May 2019 18:25:13 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:45 -0700 Message-Id: <20190510012458.22706-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-1-richard.henderson@linaro.org> MIME-Version: 1.0 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 v5 11/24] 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- include/qom/cpu.h | 1 + cpus.c | 9 +++++++++ vl.c | 4 ++++ qemu-options.hx | 10 ++++++++++ 4 files changed, 24 insertions(+) -- 2.17.1 diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 08abcbd3fe..9793ec39bc 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -369,6 +369,7 @@ struct CPUState { int singlestep_enabled; int64_t icount_budget; int64_t icount_extra; + uint64_t random_seed; sigjmp_buf jmp_env; QemuMutex work_mutex; diff --git a/cpus.c b/cpus.c index e58e7ab0f6..ffc57119ca 100644 --- a/cpus.c +++ b/cpus.c @@ -50,6 +50,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" @@ -1276,6 +1277,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1319,6 +1321,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { qemu_mutex_unlock_iothread(); @@ -1478,6 +1481,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) cpu->created = true; cpu->can_do_io = 1; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* wait for initial kick-off after machine start */ while (first_cpu->stopped) { @@ -1592,6 +1596,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg) hax_init_vcpu(cpu); qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1631,6 +1636,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1671,6 +1677,7 @@ static void *qemu_whpx_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1724,6 +1731,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) cpu->can_do_io = 1; current_cpu = cpu; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* process any pending work */ cpu->exit_request = 1; @@ -2071,6 +2079,7 @@ void qemu_init_vcpu(CPUState *cpu) cpu->nr_cores = smp_cores; cpu->nr_threads = smp_threads; cpu->stopped = true; + cpu->random_seed = qemu_guest_random_seed_thread_part1(); if (!cpu->as) { /* If the target cpu hasn't set up any address spaces itself, diff --git a/vl.c b/vl.c index b6709514c1..e1d75a047f 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" #define MAX_VIRTIO_CONSOLES 1 @@ -3347,6 +3348,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 51802cbb26..0191ef8b1e 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 +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, seeded +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)