From patchwork Fri Mar 15 03:26:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160380 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16270629jad; Thu, 14 Mar 2019 20:45:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzl8JUzpaSRSrj8Jjfo113koyMOoY/+NPhDmZoHgsRzWOq0wsvhSJG6ld76jFcBe8Yuw6fN X-Received: by 2002:a7b:cbd3:: with SMTP id n19mr495716wmi.131.1552621539953; Thu, 14 Mar 2019 20:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621539; cv=none; d=google.com; s=arc-20160816; b=KfNdLTqAioSinYdgqS8v/Ls7773GtEXiN4fs6gu12XHZFN/72S8H3EY4zi789mg4rL uATg015YbaqpEXKeNZUQx9QqLzjht5SHaKdhMGabReYoJhySIwoGIy80Er57xJvlLDEG gBq7+F4zjnbuVTwnumoNuVfMiBrX09GcCKlv3mCxkJ3bUB3/RmnnIJHN1yDRAm7kiWkA ugn/8z4Hm3EON5P5RAZWNT8VYiRKbqYduqbg2UJ8CNdgfePnQhvvya3FJJRyQaFdreGA IeaIZ8u7oASBBBAtVde+Smf1E/ZKEP3Q4g5jpLSpbuTdOhUgpHq82jBv9S/9ryUb+RAJ gunw== 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:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=2t8AKJwpSYkRbWRtZ4Sd+TCbVTcy9tDgABdaXlbp67w=; b=gyesA7Nx00GA+hn5o3qb9t/tYeyegD3qMIN2EJfI2/Pg5/lk1+x0y2EgW2zeF+qZQ1 zQyOlqM9+tBIqu9jWJ26rZ7hjykXHTgRaic0WYrOY6rjxsSXA/mQjlYfGjqKmfhLuc6J MmkRapFtg17FjOvUbe9A7svk3WgmJOMGs9Zl12DQd8LiJVcXVkdiHPAi4EJnRvpt+jbC 4qxmYaV0OvmdQreI19oFWxxCZcmGydu9NLuDI2tPfokJwPgkPUSTOXw4W3uQiK0TACTO ckgqwxn8SoOhCnOsMeXeH9xVJIcFJ5yKplSmiBZlRn1I7cGE+CoxGvisiF1iYT3t1mq/ TUXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=y5JULUEm; 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 b3si591295wrm.378.2019.03.14.20.45.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:45:39 -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=y5JULUEm; 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]:48849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dms-0005eP-PQ for patch@linaro.org; Thu, 14 Mar 2019 23:45:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcK-00059H-No for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUe-0002vN-2j for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:48 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:45600) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUd-0002uT-PA for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:48 -0400 Received: by mail-pg1-x542.google.com with SMTP id 125so5384399pgc.12 for ; Thu, 14 Mar 2019 20:26:47 -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; bh=2t8AKJwpSYkRbWRtZ4Sd+TCbVTcy9tDgABdaXlbp67w=; b=y5JULUEma/BW6L1OiXa9oTiD9taJgV+CIWfek2eiwDZwfkSJNDKCXUkWjAoZ/Hewsp hHdf4ULtpho2aSUt1rbcTK1eIUueUsG5AgbXyCdr5xIcwwp9vXJTP1XXPzBzKy6tmWT9 T8oKziqGcOwocbze7ddMfemXoukxSAOBD3kFrKW88/nTp3il21RI44MfaVM3g2hrHxxs DdDZrpch94yCckjhmWMnobq4W0aa7d/Tgqxg445uKChmMw4ICSba18IS9qGND2zzojHw AbA9fQoieEkclpSBvpxPNxClbWUxW+nDEw1xVmo/+/Nv0kbl+aWLhjUCBo3gaD+ljdCG CJ+A== 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; bh=2t8AKJwpSYkRbWRtZ4Sd+TCbVTcy9tDgABdaXlbp67w=; b=twIbUqFwpZqFRvXXbgXoneiQJWpa4EKPTpC4VhXTJaWMA0szk31F2q3NmnJHBFxtiV wt1H/grDP660eHjgU/89SkOrSXGiEhl10nCjKbqRWKDapn91D1j21vb4s6HvZKQBHYsI 2kTZKkrxLxboIvpK5VzXRWLscaieu2P7RFoYt5BId7phF68eimjdXea6/EmlS8n62+5K EFJ12A+JRE9JIt0rI1MUn4KXqkHUbUTblP5lpCb4+PrcJJkSJj7cylXQw3tB8w06hln4 zmLdU8LSmWOe+1mS1uIcJS4Cz0se8HPNvTvVO4QfzUBjkoS+Zbi1FEJZHedVlN446T/M IiyA== X-Gm-Message-State: APjAAAW3mg1CX+KAcFYyGLNU8W3+2A8/8SYbHChWVpuYDh1Y0pjS07gs vY19mMzka9fKJT42C2rPvgDJj3xONs0= X-Received: by 2002:aa7:930b:: with SMTP id 11mr1726326pfj.49.1552620406346; Thu, 14 Mar 2019 20:26:46 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:17 -0700 Message-Id: <20190315032629.21234-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-1-richard.henderson@linaro.org> 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 v3 11/23] 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 Signed-off-by: Richard Henderson --- linux-user/main.c | 21 ++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 13 insertions(+), 11 deletions(-) -- 2.17.2 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/main.c b/linux-user/main.c index a0aba9cb1e..cf7095bdaf 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -33,6 +33,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" @@ -47,6 +48,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; @@ -289,15 +291,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) @@ -432,7 +428,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=]"}, @@ -687,8 +683,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 208fd1813d..8f7125cd67 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 @@ -5448,6 +5449,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. */ @@ -5534,6 +5536,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.