From patchwork Fri May 10 01:24:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163797 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1724618ilr; Thu, 9 May 2019 18:31:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNRCKjx62bjtyCUQfKuHAM4dcRLWGRFZvZnwzdEumKVDBcoNBIJy6d7Meg/jGGTqO7hv03 X-Received: by 2002:adf:f788:: with SMTP id q8mr5461672wrp.181.1557451895648; Thu, 09 May 2019 18:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451895; cv=none; d=google.com; s=arc-20160816; b=n0UkQWv4Z4t40mhUFih2k+MoFTz1FO8MfgDk2qirrUvZYKR+0zF4PUO6214/Tqco1r Sqm2cZoaLEzhWEFyI4w9Uwr3ncmtyrq5azw8PQElnMkrcHR07rF1XaIBTq7a86k+BSaT JxgOf3YkaoI3NO/FJOKFX/H2ckN3RzBeYE6dOSUcUz0NTiPtjegtEyfIvH9Tgg2QLDQm rlXYSI4ugm6LIl7qWPfsJ+az65/OWtzApN8xm1zUuCE4A8Yh0z6OWVhbOgWMbs7jqL4B 0TJoV9TGEOLa4j6GplJmuAdcrAnPD9HzHFrNOJepSATPxtxEYFporpZU+wi3evR4/RDZ 6J3Q== 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=I3gtAlIWwDdw8etvrF0cUhXO78/4AJyRaaREgjfC74k=; b=WUecqDQR8snKO/VRoREE/INZxTizCoVdH1MnjHiCjRghENye5Mdr76oyJEvYs03iEz /YZdWN7lNcGDg9Nj05rLu4eg0bC6GBEa47WfAAxfLfYXDJPxSvd2RH5zkTk6PV/0sQY9 aFC7WTJrPlyMB/8JvYn0YdbquVvFViDR5+2AnqikBGhGTe2HXzMXhG5K8Y3r+lgt0EJv 6B2zmK4LgB99UMk2f7hK+Fktje1/xYovEuVKRPWv0d9Bbx7GQLdyA6MvYq/O/na81K2K V5p2tj94Kcgb8WTfM/BTsAg29kmiwtayZ6et12co3TS40giVWgcqZzrWxQkerFw9JEr/ b/vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=lWSrTqIG; 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 x4si3154854wrd.107.2019.05.09.18.31.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:31:35 -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=lWSrTqIG; 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]:35088 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuNq-0003Wy-FT for patch@linaro.org; Thu, 09 May 2019 21:31:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHm-0006Jt-81 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHk-00016y-JH for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:18 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:36158) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHk-00015O-B6 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:16 -0400 Received: by mail-pl1-x642.google.com with SMTP id d21so2000876plr.3 for ; Thu, 09 May 2019 18:25:16 -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=I3gtAlIWwDdw8etvrF0cUhXO78/4AJyRaaREgjfC74k=; b=lWSrTqIGyEpoxCi5qCJh3C98tzIqCjZHmhq/gwqJWOcc4vawGnvQI+fLvSNkizm8PN 1CnRNl37I5h2vyYkwxLPa4/Lo37E5AZyGQnQWKynsP6n57pO5F6+TVC9l1PM0WMHNlpK Xsccb/mWv1Xw9PvfI64hLDP7oeiVomDRyOryMbjeIKFcIAhT2uXYF+x6tNSxq7Qmlzem SwlGUgHW0Jx4XgbVtqKmhK9XNF8hxgsVzZZqRBg5Ovpj7p3eCh0LHkUQtGXROUcGafw0 4iggZlf4uRgWJAnP1P3mkZ9PT0UFQPC9IJdX9tMbEdU3rKEv1o7qVzEzeM9/UECI4AXR B18A== 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=I3gtAlIWwDdw8etvrF0cUhXO78/4AJyRaaREgjfC74k=; b=aRVRHi763scAL3ZfglgsyeCYhbhzjrc3hyscA2b/Gi4XncCcGlfw0ncNR5866S939p 2xwgu4+DgP7+g2jUykDCdJZJb9V2rR0VJXTDgW3NhDhxVWwNsjRu48c7xec80Z7CcE4F kzq4n85hDCf2MFThDV4ntZ13wEEqeFn89fEPY0ILCSPOS1MEZh+y2FWelJGUcWHF1KvJ qd5uNq/0VZZEBExsJtPp01Pf9cQxcud5c0h+3GHBjM4a4ZDqsZ3a0Sg7i7RmUBL22EQr 2EzkCDV4fU1THs9u30zuzfAK/80AJeHHlH492XoXAkNMccBMwXqHTNQIeepnUkIq7coK yuVQ== X-Gm-Message-State: APjAAAVwhy1xxv//xwvzjs6Rl4K7wOra5d80kThHXfvjzr1+sHzsLL/4 cnUytTLKHM7dN2A3b9Fe/t7Mvt50obg= X-Received: by 2002:a17:902:868b:: with SMTP id g11mr9342202plo.273.1557451514950; Thu, 09 May 2019 18:25:14 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:46 -0700 Message-Id: <20190510012458.22706-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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 --- v5: Retain srand() until last user goes away. --- linux-user/main.c | 30 +++++++++++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 22 insertions(+), 11 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier 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 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.