From patchwork Fri May 10 17:30:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163919 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2678293ilr; Fri, 10 May 2019 10:42:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqznqo458k3mkI5bvN6zqd0yAqoxDDGCGjWEs/brRiJL+0F5aZgbAmO4ahi0v+6AJqbeu3hq X-Received: by 2002:a50:ed14:: with SMTP id j20mr12784643eds.84.1557510169170; Fri, 10 May 2019 10:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510169; cv=none; d=google.com; s=arc-20160816; b=zUnY/qZrwawdrtkjL4pPQT57iYgdKZfGzJwpTktuPJak36oKi+11ed7E6KtJnqxjGP ogPdlitLjds3vp2bwvvAUnyzgyBoZI6NAGjcsIAjC1WmOSgvTCGNOLuDaRgBoj9jp0zA Qr40hAgP2/NDe66n0MGqNIj0KR9e1upM05m7lHziAfk92DU1/NPVCMiPtALWN87zYjxi XfStM7Kd/13HOnowLFZu+/7Kx5XdA1tvSL56HTSnHBAR7uafHKi9ThvmTaBY7vdHbx6v 7jhXbwmaqBjWMFf4NEuUTGJ7tjtjH6helnmeOJrRHx+9VoaCfW6AHjnVJ6yuNn4OAZys vjdw== 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=oIDEuqyIXXAdXSBpywI+3D7Q/lmqC0qVHQeXrw+41sD2urhS3kzA5gzCTRhiJIf6GX d8MGC8BEpg8Kb3DQmGvW2unvGygfhAfmUlFtP6IUQty0xhDrz/zkxN319HVoycwThhAN CJhwLn7D97UuKmqj/rhWM8uCU31V6im1u158Kg+3KgkNrpuC0I81Qzsuu2KgaEVF/VDp O2/FWZrnKBqx8oVA2vLpn+RYuFjmeY8vxlz5Tdb5ekbjpHsOmV4fIRQbUJsq9oSXUeZX GNwvS8Xgz+RckLUe8JSNlZb6cohxq9C+R4ygNt2MDiyFAw6sC1cMiELTO064PwBx5Q7W VZTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XhA+pXlR; 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 k3si3456595ejv.154.2019.05.10.10.42.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:42:49 -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=XhA+pXlR; 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]:47637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Xj-0002c3-RJ for patch@linaro.org; Fri, 10 May 2019 13:42:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MR-0007Pg-CV for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MQ-00065I-5V for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:07 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:37843) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MP-000653-VI for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:06 -0400 Received: by mail-pf1-x444.google.com with SMTP id g3so3586230pfi.4 for ; Fri, 10 May 2019 10:31:05 -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=XhA+pXlR8e0RNUXPWtWVNimjmg3Im0ATqmR7L1NDpEcJFBVuCMDLyB+9tdR1cESaJc klGlyzU6AopnoZbNqxUG4f3T/lKayuqZB7r/ud0Wn99QDfyK4/xNtnsolmBYODXLsgy0 a8gths3Pz6XLS/kbvrlH49ry9+51SZy80svCFITgsgU0JWJCHXNSYgWKYhEjkdR+4Fuf y5pBBi4u9OLJ3l6lL+WNUMlEkSrDqrWYam7cbQLRMN6N0O43A/SeLyJ7FJ4SZWE72aF2 RGoZ0A+VMiypiEc5gz6wDOjsS26LpUXf+cNK6JDsRpLFyUPTyUdNk09UuBozIZoxg1dL InnA== 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=SNdjOtyEV1X5CwrV7U0nB0XLkYlDPyZDQor/fDofa0/laHpgZhPEGEwrddPO8e34vw N+db8Ljb8hDOv7kxZZHXUIlzIEVS50z0WxsRnX8QAY3/qe0bQULgWrRqyBiMTossZxRh cBuh8KR6ifBgtGL0UYzVE+6cv4Ab0Dm9BsOOjPxi75Dk9lB1bdeMnsoIQjOOxrxInBU0 F4jMTBIE6D1mBAmBuAnvI5R7ZvhIvaj7VLUapjuCfNtSouynIw9CLqSFmNfuwXTxy2QN V4RD4JOlj1OIYeq/v94DKA6nic82FcWyzOpxznj8drFZkzCQyV94/yv5V2icBlr/EN3D dXmg== X-Gm-Message-State: APjAAAXxJNT9RmJOb/h7fbMehwuWK/Ek5zUJgn0pHpCzR5jrV2gElOHq ESlKGiHC0kuKtbu38SAf03ouvCQROJI= X-Received: by 2002:a62:604:: with SMTP id 4mr16094082pfg.38.1557509464762; Fri, 10 May 2019 10:31:04 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:35 -0700 Message-Id: <20190510173049.28171-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-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::444 Subject: [Qemu-devel] [PATCH v6 11/25] 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)