From patchwork Fri May 17 02:39:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164359 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1602186ili; Thu, 16 May 2019 19:44:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqytaj/5AXLrU9eBUUeep21BJkQB7o8z4/WnyJXwlzUBd62iBqrAUF1RQtvt2WT00rlvSyFp X-Received: by 2002:a17:906:e8c:: with SMTP id p12mr41216793ejf.18.1558061054870; Thu, 16 May 2019 19:44:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558061054; cv=none; d=google.com; s=arc-20160816; b=GR0z/i3Xfrs5/J0tPNXKdJIlmfdyvftPe8FprpUclkjGtruz/BHUglCeh5fRcTLhit 6lgjm2MGbKaVoNR/k4BkovHQ/AWQAbKnvHXcth8WZHfmxKVf08jvlytJOxmdG4UVX5vq YHBt4f1u14BQmiTHX3pbCW/ThQnMyuYULteVECQ8VJzj3mCOPzw1YY60ApFMi5KlntYR lYBsye1RD7AiZIjA++ggTY3r/4ne/nQbAXcgk7Hmg5pV0kNkISXcfAUq3qSfXbRoSzTu uNHKAVbcWfcyMH0R0lQigT2/5bnxflTPVOeyAP8no0eDu4UTDW6PM6goVrDIfMtnCLLX CzAA== 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=xy1OktLeK7/mJWPw/JMSGUFtW6+kUG05ru+wLl6Tmjo=; b=Ntr12G+IQDbtJw2JKlAf7PLb3JTn0SHUC9P28eRG/KBoVDhWDYNp6SHmkqEUEK3aa3 OpYrXYttUyP2U07O38B7KQ7ThBr5MX99Mk7JU8FUArSkmd/XQ9ulbLigzJuSpN23t01w 07GxWacXd6fDuU1IC8TjcW1r/aoURFGjkywzwu996OnV3u8mV7dYQN8zB2QriojbqrxI rFSp9adEmF0udT3UwD6zEgF1yA7THfrc2SnaudID6K4s8uAiDzjjS8UkxBmBOtSR+yu9 LFGaVGDaRKjOt5qvseVN1bA3ZOqgwTmIaXLELMZo3UQrFbft/GrR4BIJhEmAqGwm0h8n AoCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="fTAz/z6S"; 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 i6si4587185ejd.129.2019.05.16.19.44.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 16 May 2019 19:44:14 -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="fTAz/z6S"; 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]:40144 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRSqz-0000pe-O6 for patch@linaro.org; Thu, 16 May 2019 22:44:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39080) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRSmh-0005YC-7J for qemu-devel@nongnu.org; Thu, 16 May 2019 22:39:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRSmd-000287-7L for qemu-devel@nongnu.org; Thu, 16 May 2019 22:39:47 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:39668) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hRSmd-00027k-1I for qemu-devel@nongnu.org; Thu, 16 May 2019 22:39:43 -0400 Received: by mail-pg1-x542.google.com with SMTP id w22so2513691pgi.6 for ; Thu, 16 May 2019 19:39: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=xy1OktLeK7/mJWPw/JMSGUFtW6+kUG05ru+wLl6Tmjo=; b=fTAz/z6SLnzaFKL6OjNX5K5jhKFebfdhYcbMaxJpeXFSQxfyJ4f/CEglCNW9+auXtN 3sXqsbiWwHo49IVD8Xxxj3P2XEJbylVNnrJEcLjFwAcZEeI05GGXAuWWtJ7UVDaQ95n6 WNXMf3JGjqwkcCltsoT4jN0ThVOGZPMcLmBzjwzEBrvSAK5CmjJyvwEA032Thgy0LgQq 7Gp4AT4CWrXmiQnJVsND0yVCgaAdgtOvUPGG1SlLITHfQ43JXWOjwg5TdUDna4rvjxBi s7vqg4k/xAAwpFqHYKvR0NB4NzPAQSlzV8XZnQsg5nJGswyK5eJ0q9NpFkeNdopj01Yz AfXg== 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=xy1OktLeK7/mJWPw/JMSGUFtW6+kUG05ru+wLl6Tmjo=; b=mauYh/lBS5MU0Ebm4xRRMvMx2bktCxrDKU7Ngr0e58+wAQ4PQYIm5wQHwDVa7kSQJl bl9bUHuJCrRatkXq7hTXfLKzhYC8ZnfYFU9OOg8YENnY6u8XBZnI7Offou96Fo8A65Cb pVaUEHUUj8LSw3m5TFcWkS3ANB9Egqas69esygfrIiupOR6ZNqmWRyGWJesQqagpJpbY 8ZHIP/CHoEd9P5cRVT12iemu5TrCJkwyfY3nZNCg3/0YNkih24aCfg1GztBrdBo4Pbs1 4E4147mcKFFNkVaVJsxsnP5NuTKmHu62mQS5sJgE1mrZvf6uWAMk4Yqjv7gvZqZQ+41O k6og== X-Gm-Message-State: APjAAAUOM/Fabi6w3aXzEQW5OqLcNbh2KEmHvW5Y9cq09IbtYr84Dtk/ erWAVMeMUgOlBG4E/ax+4OJvad3KRK8= X-Received: by 2002:a63:e408:: with SMTP id a8mr54178798pgi.146.1558060781792; Thu, 16 May 2019 19:39:41 -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.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 19:39:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 16 May 2019 19:39:11 -0700 Message-Id: <20190517023924.1686-13-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::542 Subject: [Qemu-devel] [PATCH v8 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: 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 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 f5ff6f5dc8..96f20886ce 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.