From patchwork Mon May 6 17:33:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163427 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp258469ilm; Mon, 6 May 2019 10:40:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNj7Gxgf4to1FoijK/OEO3rLXqmlmGzM1TkOg8nGJDPs9hyAhmfoW8DR8LRytW2G3goJGE X-Received: by 2002:a5d:53cd:: with SMTP id a13mr18705436wrw.201.1557164437098; Mon, 06 May 2019 10:40:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164437; cv=none; d=google.com; s=arc-20160816; b=mdF47Pmp6/YpvhFxWZpxu71goxqYbvUCBYyQ/3u0tRnwQZdPLVwhrkz+So4Jw5E3eh d8Lx4I3i/N5hJOWEbnu30CQzK2bVtgTMbqyHfl0zqI3sxS/DJXWex/JCWUPWTndoSvvb fnQZicVkSbbCQQwESkpWwTs14kUHP0GpgLCoZ3m6RPItFLcHJ5gvnaF8foJhICVwpped eLSlZ97zZ4rWUo/8loADA6yTJ1a6ijV4d3CL7+qaNZFKIwDfBVPyRglL5g0ZjlYhdMPe M86y0B5xl/DC1fDgqTacOiFiz6BDQAoJ5vtN36en9tlrkV+WUnvxqr070l2jmcoCdwYE sSIA== 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=Fj9NAT+dC/44CVxKQ9vRk+R9FLW3wBp4fXibMqKhPs0=; b=oYf1qyUGDGybnPAvDQ0VCi4ja4gNlL7Q9l5We4jffZfjfoUS/68ud4g6R7vGKVglWB 7acGo/cPKIVkCCxDGFGLJmtflI0EPOnasXIomndA1IO2M9XGMbSBIlj5qgIei0kDBlMS kkfK5HWw3Y8S0foYxyTDBcZ7O8TYNvd0SqwoTeM+jxGXuN2cNbknjFv/Ock7gNK093Fq oWHUVQhsMXMaxH75P+nZz0NyRAx3QwIYVkErS1/awCn0dDZVrpa/P0vlVzPpTFN8rMau GrY/iU8p96JsONauijS7tmGSvHL6nJfTaqpyi1P+XeeL5ZXL9WIvtTK4IK7Xy+YTKeB5 I9ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NS4nASxH; 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 a21si7030912wmb.116.2019.05.06.10.40.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:40: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=NS4nASxH; 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]:59997 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhbP-0006rj-TX for patch@linaro.org; Mon, 06 May 2019 13:40:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVG-00018h-PG for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVF-0001Ou-70 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:14 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:40440) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVF-0001N1-07 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:13 -0400 Received: by mail-pl1-x642.google.com with SMTP id b3so6707168plr.7 for ; Mon, 06 May 2019 10:34:11 -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=Fj9NAT+dC/44CVxKQ9vRk+R9FLW3wBp4fXibMqKhPs0=; b=NS4nASxHHKXLy0BIyjl1W6Y0jZRvqItBP8DTW46Iu6scDsjW7PAngMCDENbFU3Pe8O inOUA56K/FjJPK2G7scK7/3cibtebx4f8qqd1HcMKifsbavxb88zgn6WIYna/qGOVlVb 9zPiUg0XYrSgtHOUyXTX1gNx1066/e//ZkquhlBzDlfIeot4G8LnZxin9T1mCIWG5GC2 x3LlzYf9gV67QqaZGFADNFu4KnP4wXAwoqhwim/AScSTO1ViKKbzAMdepSVqokzVEC95 iniHUQbcoPeARExpqyaWn5oF2LgtJA1hvjgcx57hxiqN5w+x0iE52WlhoUOEq6BY/AKi 3AMA== 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=Fj9NAT+dC/44CVxKQ9vRk+R9FLW3wBp4fXibMqKhPs0=; b=C4iKdFnnvclX6ARMZxUXVPGMHv5arO2PuZoXt1LZqfitanINcWMVPDbHv2oyLC5t4/ siNfIaupJTF/NrfYonRqar1ARmD7Y+UotfekzjxdBHw5PVAkIdVXsqZ3p3DXNSmBWmv2 R1CpWmrep2X6QVKfmX2vc9ZYoStVHsICIBq/0hOGd5XCzJUcmJ72rPZ9y0vjwuA+fP4f 5GN0V7zZhbEyFh+20kLrESMLpLjp70lhBdk78+Uu9C9qt+UqnFruBuvE58rlKYyYkths kKxfaK8DF2zMtExi+/z0zC4Rlu8DJqV/jI35dKH04s5as73kMI2szfMQ8yPaLLe4YACe TIJw== X-Gm-Message-State: APjAAAVOC3qaXZBofbVO3P4xdZCYynAab5biR0TqcMRetIGPHBXJavHN ppVQd044bNT5qYMmWIkCR5FnsMRkURk= X-Received: by 2002:a17:902:4624:: with SMTP id o33mr33953868pld.191.1557164050651; Mon, 06 May 2019 10:34:10 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:41 -0700 Message-Id: <20190506173353.32206-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::642 Subject: [Qemu-devel] [PATCH v4 12/24] 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: Laurent Vivier 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. Cc: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 21 ++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 13 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/linux-user/main.c b/linux-user/main.c index 3d2230320b..7dfb202e5d 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,11 @@ 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) { + 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 96cd4bf86d..ce377b2fc1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -110,6 +110,7 @@ #include "uname.h" #include "qemu.h" +#include "qemu/guest-random.h" #include "fd-trans.h" #ifndef CLONE_IO @@ -5441,6 +5442,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. */ @@ -5527,6 +5529,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.