From patchwork Wed May 22 18:42:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164872 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1239437ili; Wed, 22 May 2019 12:13:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwEffhWtb8UjLGXsCSVZsbRLA7P9l2JjOnFmsREoA7AcSa4OeQ7UKnghztvdKa1QAWjr7J X-Received: by 2002:a17:906:6545:: with SMTP id u5mr20094215ejn.102.1558552432288; Wed, 22 May 2019 12:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552432; cv=none; d=google.com; s=arc-20160816; b=njkGFC7aDo/ehZtvkAa/IMktYY+Gx/B7dWeVGINloQgYA8Ec9JON1uQyLv60vexkme vTLRxCPXTlj/x2kR0oM3SdKE2ZZijXxgOsbtsqaNAbC/gcrCos5CMJB3heiXeEZfG0zm mlpKKt9f/t7nehMcBKtIaFo3pVOyseUOgaUrj5VCaSia1EJdmyTQQnTTrX+yF3b0eRcS 3apziMQOv3gci5O4i2vRF+Yyjfqwe2JqvntAl/kVByYhKgQXRStX3wzi6hArSMoqEva0 hiwPorTsqf/pm12nEfvoj/zS38EfxvNSUtE4rDDjRL1knF8Rlr6G4TFQdZZ7adKTXcyt 33Ug== 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=2ZOvSlCVstHsIxkY3rXu99Q7piqIwzQbJ9bkZ8lPHXs=; b=U68oisDPPMO/xFoOyV4e88JWFVrCucx9jp5zEkLEmI9DhoxGW49ypTnz2qCfIul6wf uSx8Uw9FFVOy11goNR+gtWd2IGrYD4Bh+Y7XKmbO5gg3B5VaNB+zn4YJTArjZcRj77uZ zx1gxToxmO/iNitKYJ7M7lI0Ov1sV96VUq97HT4RIbxUpa+xtay76wq6zGCG48CzUuty XJ0L+C57mPb6Xnlbopft+H5Am8SDSCyRd0ODqf1bct19HmJAScbVFWquETjw5ckslXpM hbQFaPt+d87DkWjPPsX2SYTPsWmTFbp4rNOO6MQD1Tsjmb+zSYO66F4CztyXzXowDieQ Ed7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vNQKJAXQ; 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 o5si4421281ejh.34.2019.05.22.12.13.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:13:52 -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=vNQKJAXQ; 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]:49887 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWgR-0007br-3A for patch@linaro.org; Wed, 22 May 2019 15:13:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOp-00086d-7L for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCJ-000872-U9 for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:45 -0400 Received: from mail-yw1-xc44.google.com ([2607:f8b0:4864:20::c44]:41715) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCJ-00085w-PR for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:43 -0400 Received: by mail-yw1-xc44.google.com with SMTP id o65so1240637ywd.8 for ; Wed, 22 May 2019 11:42:42 -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=2ZOvSlCVstHsIxkY3rXu99Q7piqIwzQbJ9bkZ8lPHXs=; b=vNQKJAXQml5IIJRBkmHYQ+UeFXIUV8TEpCEEKufTkfAsYrCezZrlQQ7OyRa1ywZUzM DULL2P7etXtYfwO7wxNAeWIhNqoBx8xw5ADTYEMnOCGjetRckZ+wCLI5Br6CO+8cVSTH od6/2OafJLl6h3ALRkMVK8+LRH4z0KxRuGdCRat1DWIhWHv9VpJhUY7e9OAVtrqYNDXW CiSeYCggnbilXbk5l20ia7okflcyv2w+V4+8aQKAp/2unbX2XX4Yc8+T5IdMWUZPvri5 r8rQpEk2qSitgCvMmrma/w13tBWHJgTgiYKCAxJLO8g5jmDbjJPaSAqOVYRZIVAc6qkr Cu4Q== 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=2ZOvSlCVstHsIxkY3rXu99Q7piqIwzQbJ9bkZ8lPHXs=; b=T3o9tkhOKEkFN/mA96wTIbUQe4jQ9Q0RgNPvhrcu0NQmgAYuBxA/VgTh8Jaao5ULus jAiJJiekExUPfcwXounSTKWyBJQKqWIjvqE6sI3X3f/BZbbde3pebD5HDN3CkihrYF0c 0nWJArEbv8agDe98og4xU0GKdfDnjmQ+ROgmANnga1vjhpqrhqWGVuuKoUpbBEUcQ6Ko 9SP6ZY71tZETuB12N92rBjjUG2mFy9yCqtXrzq7dh22/fXell2RcV9eZx8CDBBqbi0MI YvK+ilqKJZwZapDO/fIyaQZlRtHNky3kmSMlFz8VW4PlvVNhYD83EoXMPrz50jutrLI4 j1tA== X-Gm-Message-State: APjAAAXG8JV5EhXqZTE//gyrNzQa7UOz7IQEpbvOKoVl1wkH6oTaeab6 dvUy2b0EuipygzueXVsZCrOAFO93fKQ= X-Received: by 2002:a81:9294:: with SMTP id j142mr15313237ywg.157.1558550561235; Wed, 22 May 2019 11:42:41 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:13 -0400 Message-Id: <20190522184226.17871-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c44 Subject: [Qemu-devel] [PULL 12/25] linux-user: 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: peter.maydell@linaro.org 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 during clone; which is a no-op unless the subsystem is in deterministic mode. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 30 +++++++++++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 22 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/linux-user/main.c b/linux-user/main.c index 3d2230320b..7e704845c0 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -34,6 +34,7 @@ #include "tcg.h" #include "qemu/timer.h" #include "qemu/envlist.h" +#include "qemu/guest-random.h" #include "elf.h" #include "trace/control.h" #include "target_elf.h" @@ -48,6 +49,7 @@ static int gdbstub_port; static envlist_t *envlist; static const char *cpu_model; static const char *cpu_type; +static const char *seed_optarg; unsigned long mmap_min_addr; unsigned long guest_base; int have_guest_base; @@ -290,15 +292,9 @@ static void handle_arg_pagesize(const char *arg) } } -static void handle_arg_randseed(const char *arg) +static void handle_arg_seed(const char *arg) { - unsigned long long seed; - - if (parse_uint_full(arg, &seed, 0) != 0 || seed > UINT_MAX) { - fprintf(stderr, "Invalid seed number: %s\n", arg); - exit(EXIT_FAILURE); - } - srand(seed); + seed_optarg = arg; } static void handle_arg_gdb(const char *arg) @@ -433,7 +429,7 @@ static const struct qemu_argument arg_table[] = { "", "run in singlestep mode"}, {"strace", "QEMU_STRACE", false, handle_arg_strace, "", "log system calls"}, - {"seed", "QEMU_RAND_SEED", true, handle_arg_randseed, + {"seed", "QEMU_RAND_SEED", true, handle_arg_seed, "", "Seed for pseudo-random number generator"}, {"trace", "QEMU_TRACE", true, handle_arg_trace, "", "[[enable=]][,events=][,file=]"}, @@ -689,8 +685,20 @@ int main(int argc, char **argv, char **envp) do_strace = 1; } - if (getenv("QEMU_RAND_SEED")) { - handle_arg_randseed(getenv("QEMU_RAND_SEED")); + if (seed_optarg == NULL) { + seed_optarg = getenv("QEMU_RAND_SEED"); + } + if (seed_optarg != NULL) { + unsigned long long seed; + + /* This will go away with the last user of rand(). */ + if (parse_uint_full(seed_optarg, &seed, 0) != 0) { + fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); + exit(EXIT_FAILURE); + } + srand(seed); + + qemu_guest_random_seed_main(seed_optarg, &error_fatal); } target_environ = envlist_to_environ(envlist, NULL); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index efa3ec2837..f3ea9cac21 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -107,6 +107,7 @@ #include "uname.h" #include "qemu.h" +#include "qemu/guest-random.h" #include "fd-trans.h" #ifndef CLONE_IO @@ -5482,6 +5483,7 @@ static void *clone_func(void *arg) put_user_u32(info->tid, info->child_tidptr); if (info->parent_tidptr) put_user_u32(info->tid, info->parent_tidptr); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* Enable signals. */ sigprocmask(SIG_SETMASK, &info->sigmask, NULL); /* Signal to the parent that we're ready. */ @@ -5568,6 +5570,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, initializing, so temporarily block all signals. */ sigfillset(&sigmask); sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask); + cpu->random_seed = qemu_guest_random_seed_thread_part1(); /* If this is our first additional thread, we need to ensure we * generate code for parallel execution and flush old translations.