From patchwork Fri May 17 02:39:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164368 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1605894ili; Thu, 16 May 2019 19:49:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqztCSJt8xn67ESCBLNu3zsZpSzsefEMHBH8M0vXLmGqk48EaP3/fJw44wh8Acc6huMmvuTN X-Received: by 2002:a50:a5fb:: with SMTP id b56mr54259446edc.262.1558061365900; Thu, 16 May 2019 19:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558061365; cv=none; d=google.com; s=arc-20160816; b=KctG/ozHJzwRnR9CKBMSDPacmlXayOCevLFQFUD9023U1E83ppRyICfp0CUq6vy/kS 03N7GoJaLo/JokxnU6KayhxQsAPnpvkl8CJxnt82MWdavEjzz3YK+i8Igk6Rgc3LVje4 +pbb4hPfhvzuKTc5Crvq8TwjgVDCwUxFtjlEmG5FizTiYBgKTHNnJSxWofg5cQej+aef DlclvJ5c0Bxp810TJfD1ZMFSdZ/1wTT2EqYhv1xHEA9ebUZF7iOAcpbYGh5jZkFUtlyi e9tU2rYSsAy6vjG8gKhXkTjyZPmn1LAi1O1jqY9wWAqbnpbVqrIgygt//dNuWN4/pv/c 52KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=eqLqRIJfbw1VXh/etrqocjccO592s1RZr81gJ0ITim/ifP87g6rVwkglKK4OOGRjVy d8lTKya0qlfm1ZkISlHMVFQiKgQxmEfNp3QkjpETHo6vrf42fvV6fB55iiUjg8hTECaZ IiiMz8T59sZWE8yhEfN281bYZd12KLfUXobA01kloso28VSOaOu18PfgOnTq1DUFd1vc A0o7Oh30jCtjcI1HC4bJW9Xhs0jRI90fruiH6W4T8NvyihQUvDpBh/Z91DRKKK9t1Cnc evG9xosMKKMvkJBMseoqDdYDy7o4Ilvv0AHYqrklKDy2uqKUACGjorqab/MplduoO7kV B2gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qjApryCP; 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 s24si2312661eju.328.2019.05.16.19.49.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 16 May 2019 19:49:25 -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=qjApryCP; 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]:40221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRSw0-0004r2-Ou for patch@linaro.org; Thu, 16 May 2019 22:49:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRSmd-0005WX-NL for qemu-devel@nongnu.org; Thu, 16 May 2019 22:39:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRSmc-00027o-GR for qemu-devel@nongnu.org; Thu, 16 May 2019 22:39:43 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:44890) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hRSmb-00027N-UL for qemu-devel@nongnu.org; Thu, 16 May 2019 22:39:42 -0400 Received: by mail-pg1-x543.google.com with SMTP id z16so2503294pgv.11 for ; Thu, 16 May 2019 19:39:41 -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=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=qjApryCP2LiyI2c1MBtLiZFcwSc658Nu0QXBtzXRPzb5BPMlnligMPuSq//UMthzQC Tw+jRxJ978ezjWi2H8wD/WIstBzSv5xmuvf6GI+saiOtGv0tcX69Zf1MJFMUALEcxFEv ch03G4K6/zN5xcqNTDb5ZFt4HQ4+PzYq3ZwkgnSEhczF2M71LPaCFJBz8Q8vQ53J2lyr fs+NoSRPU6jlgImfEs6diB2Y0pNKFSosh8xSlYZsXZmfKvJf1Op97Dw/JUBb2JArZf+O 1G1dgjpRBCb+9OhTlPBf3Hi+n7rvQ3mCnJwdB0adyHgTVeFmI3nBYYsDUWU7CdHQA7Rx 4KPg== 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=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=HvjFAl0pjSqEu0gMvrEiu00LIVmV5JI6UH31agBwrpdddV0HAJRi7n5aXETduhHbzL 21dxl20jUMkn+/5zIIW8EClAu0XxIjbPAblLtFfohrYj4WhMX0dZHlt5I1jSqNyUh1/H cUtXOpiaRIs03Sm8kRT9iEoq3W+SkqBeJodwQq2te3E3YBrn5pwbwv/EKY8hALMk5vV2 BaappD2LK/eGX15aQgy5KJgj3kHkdcvPcILQ4jagdnbPCLdJ03xYf+MASq5wUhboHp3O 8czcEyBSfKJi5q9EeIxGf/lmwSDHQlQ35fZnrpIgmxvPAih3Y7Q7umghsi6U1FRQzv1J 8sWw== X-Gm-Message-State: APjAAAVN0aa0AXqtIlPNb+NPlVYABpt4i+ImF4aXp/8L6XMVc1Rq0bqA AKNY6inIDGH6i40zNobog/cKwzuTKaI= X-Received: by 2002:a63:ed03:: with SMTP id d3mr53763499pgi.7.1558060780502; Thu, 16 May 2019 19:39:40 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id w6sm6984152pge.30.2019.05.16.19.39.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 19:39:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 16 May 2019 19:39:10 -0700 Message-Id: <20190517023924.1686-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190517023924.1686-1-richard.henderson@linaro.org> References: <20190517023924.1686-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::543 Subject: [Qemu-devel] [PATCH v8 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: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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)