From patchwork Tue May 14 19:16:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164241 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3008312ili; Tue, 14 May 2019 12:26:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyn2gafTRbPh/X5VrW/Gk7Vsyv+LIQs1sTBpUyGvy9HC1XUK0G2CHi6nZrKnJWCiwyPZ5L X-Received: by 2002:aa7:d1d1:: with SMTP id g17mr38961021edp.19.1557861997553; Tue, 14 May 2019 12:26:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861997; cv=none; d=google.com; s=arc-20160816; b=Oul5VNwrr5Km30WVYVxmmQhkm39aqghgTbcSlTZUJVUShFrzroVMXX1UuJHf13WIh8 kGM8ebjYBkjZEGReMLmxF3eNSgM7uAwSYT1VHAlEDFwHdPM+hGy8raAJdK2vC5+19jPk 7EI/vjj3AykbApwMOzPr62Pfvxvgp5JUzooChlbpWN5GJkbGbKbOdk+Z7sZkisySo0jc MwvOE8RqdMEatTMga2gcUclfMxMsQMPjG1dxemk9aCqHML6CKgyZkTButAlOJz0eokMU QD6WWpNl6bBdVrQ3kis9CtJNHtBL0gHwtnQwwDUWbbzHfWjm1/pWZwI3EHVGhtcJgAa0 /y2g== 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=s8yc16r4G7/iWgSicXmbxDAKsDLLma4QKEmy8Zz6iucVrxH7qNExNthvhMULk1GMsp NiCM+BEgOtIRwCM2rBxalrkT0Tx4ezTri8hSpdrOuPre4sr2VlmMVkeBgiSXOi2MvUzG Ii6nuDyM2KxoWNTN0aQylzlW3YAYDmDITxoe+xb5asks359Xr2zBsGm+M0pL+suF5ZNX v/OtAtUhYZ/Rp49UvnpMViaPm1tceghwXE93XLl5a+zIeKoYtpD+TL0zwgHPlS1l7TVM JJkyrRkNWOdn/jZ8+3wMKGd7VGTUpPuF5/+CgfZjo72x2Ca5zo5gGd+hHOBjkWdMCkN1 nIJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jEtx2Jdf; 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 f47si13041722edd.144.2019.05.14.12.26.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:26:37 -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=jEtx2Jdf; 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]:53046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd4O-00028e-B8 for patch@linaro.org; Tue, 14 May 2019 15:26:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvH-0002Uj-FS for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvG-0006r4-BV for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:11 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:42779) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvG-0006qd-53 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:10 -0400 Received: by mail-pg1-x544.google.com with SMTP id 145so38402pgg.9 for ; Tue, 14 May 2019 12:17:10 -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=jEtx2JdfSEnx9wg7IUoABEvgcTiDkClNISLTjxkFd1xs3ygY/erYGhuPNuKzbok7wY 9zg1++DiysYh58F6krddQ06B7PN/nODTb0wihz5dV5XmVMzW5yePW70gCx7sySeES1AJ e0PEmUzBuai1f62E6AtPzQSVx5TFy4C5iRATdKryKLJkuI2W7Vwq55Pd0O79qxxAl1CA wDWbrMGI3IjAfhJ6Nm6f3YGU5vLsOimPN7kvGn881rk7x+fGwcR42lqtK7LH2eTBE4Cj MTMSjMOtOZQpRClbC4MHR5zcESZpfKuA55f1avXEFCKf4y4mfs83rdpTg8AAkgUokhSw KX0A== 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=n59hbWQNVm/VOsLTyvZFr6u1bNQyuI6YB3/OKag09BvtuNiVsQpyv2X5VfUcN2aBji mzG5NoIZ2CBafDjsyzmLc8I1OhS//RrGze2OKfWYHEwfIzUnxsSdvfI13epGxA97QIkX XXF6LLUEuU6/pgCD6/lEXRufQfu7YkibZe4J8duGBkBNPAiLp168ZyXyjTv3n3g3dqCA jtwZpl9HBrOQilb2xP+bEZvVeUQrIklmp7CyuODDXgXjXAZ3dvO/QFAhCa071CFRuQyZ +W982rMi6VLzrQHoCQTGJqIhoFswDDIxLiVCzvdHqejIMgZPJNDsq9lO3EIHmcVnYbrz gw/g== X-Gm-Message-State: APjAAAWcGQJ7xDTzzt4aIA9l6V/11FFP9bqwnBUStpKfbeF+F0y2KCVd aL2nC+jYY+I0N9lVw2Kxy2B7I8ARioQ= X-Received: by 2002:a63:5cb:: with SMTP id 194mr40132251pgf.294.1557861428923; Tue, 14 May 2019 12:17:08 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id o6sm18682982pfa.88.2019.05.14.12.17.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:39 -0700 Message-Id: <20190514191653.31488-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 10/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: , 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)