From patchwork Fri Mar 15 03:26:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160386 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16273329jad; Thu, 14 Mar 2019 20:49:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjxj9C/fRAladfFonIfZFgoXoicgnvd/OS/rbLPgaa1CYB0gMkfw+yKkzQhsBnqOtWP3nR X-Received: by 2002:adf:cd07:: with SMTP id w7mr770322wrm.110.1552621787566; Thu, 14 Mar 2019 20:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621787; cv=none; d=google.com; s=arc-20160816; b=MIADhGqFjcq2K3cttTcGRiuY/x2+SibZVqyhMEj+d47xu1uznnXDuXmrOxcd98f1mH 3mYXHmXW7eGsyXLRishxKMi9b8Z4g4zV8ZNSYoM3xWusvrAAgp15AxZcAcHMPvKoUBF8 SEAZVXn/yobLQBPHjzg6lpamod94u5Vx30cYzaYRiKa0aB6BWIB1Tg3exyKrJR0ItXlv dOpQYkjWHr6FA9aFqRHpJ/zlYL01Er/YXwgrntUr+LXyNNScEJvV9ISlN2ByCsKeptNh e8DxveCsa+8S0dHkG2V0NSjJIIoJdDVc6KsszDXhnQFFv8hkiVAeiXlKYf2MArsGNta+ 0ksA== 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=5+Jw4ZT6nk5aJg5eDzucU6N22SG+dxTKxW+ellIVCNM=; b=FIWArbAWeB9+zKpCsWZA2ebvz5XN2WT6Dx/nt5eeYc8FYdRUXwkKnqJDl7a+Z491xL CEiScmg631nd29ooqx++ZGOFXllSQ/Cua8JrPtttjA0rIHdhESn8MEM6byeJlSpkNnHK RCFUHNSDXp+tnFaLW50O5GPYZXIO1rSqS9ak2/vaIjGqw06xte/pAkzZzJFO0UaUxyjW P1xK5ZIVuVW4rgfIn1o2A2ftJUDRChWIjbWLirJ/vO3L09gkaoMuRGqFNc17vI9/21GX Pj3zlLKhKNlVpbWj01bwQqvbNOnMXKTWfBcYotSHb8cj1+NGPQfYX2t320q1xJRR0lHR qeTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tMmNvRpM; 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 r7si545908wmc.27.2019.03.14.20.49.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:49:47 -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=tMmNvRpM; 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]:48889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dqs-0000rQ-E4 for patch@linaro.org; Thu, 14 Mar 2019 23:49:46 -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) 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-Received: by 2002:a62:d281:: with SMTP id c123mr1708816pfg.210.1552620405151; Thu, 14 Mar 2019 20:26:45 -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) 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 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+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. Cc: 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.2 Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé 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; 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 = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1318,6 +1320,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(); @@ -1477,6 +1480,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) { @@ -1591,6 +1595,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)) { @@ -1630,6 +1635,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)) { @@ -1670,6 +1676,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)) { @@ -1723,6 +1730,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; @@ -2070,6 +2078,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 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" #define MAX_VIRTIO_CONSOLES 1 @@ -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 +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)