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: 1056820 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="y5JULUEm"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44LBM56yZpz9s9T for ; Fri, 15 Mar 2019 14:46:09 +1100 (AEDT) Received: from localhost ([127.0.0.1]:48849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dnL-0005eP-Ib for incoming@patchwork.ozlabs.org; Thu, 14 Mar 2019 23:46:07 -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-Google-Smtp-Source: APXvYqxgYkddHCLM0OsGxpTTuIjk9UGV0hexchJzvaFugw3IRVzxGfcMhiwEjT0bzfdk4DbuXfvjGQ== 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+incoming=patchwork.ozlabs.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 Reviewed-by: Philippe Mathieu-Daudé --- linux-user/main.c | 21 ++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 13 insertions(+), 11 deletions(-) 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.