diff options
author | Pavel Dovgalyuk <pavel.dovgaluk@gmail.com> | 2019-12-19 15:50:48 +0300 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-01-07 12:08:39 +0100 |
commit | 878ec29b9c1915ea0da951064b8aac3050f2f5b9 (patch) | |
tree | 157253fa0974bd1e85f066c9c98b102e5de5cc67 /util | |
parent | fc6b2dbac1d57fc24420fb8ee25911eb6f1d1fb5 (diff) | |
download | qemu-878ec29b9c1915ea0da951064b8aac3050f2f5b9.zip qemu-878ec29b9c1915ea0da951064b8aac3050f2f5b9.tar.gz qemu-878ec29b9c1915ea0da951064b8aac3050f2f5b9.tar.bz2 |
replay: record and replay random number sources
Record/replay feature of icount allows deterministic running of execution
scenarios. Some CPUs and peripheral devices read random numbers from
external sources making deterministic execution impossible.
This patch adds recording and replaying of random read operations
into guest-random module, which is used by the virtual hardware.
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
Message-Id: <157675984852.14505.15709141760677102489.stgit@pasha-Precision-3630-Tower>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/guest-random.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/util/guest-random.c b/util/guest-random.c index 9453968..086115b 100644 --- a/util/guest-random.c +++ b/util/guest-random.c @@ -14,6 +14,7 @@ #include "qapi/error.h" #include "qemu/guest-random.h" #include "crypto/random.h" +#include "sysemu/replay.h" static __thread GRand *thread_rand; @@ -44,13 +45,21 @@ static int glib_random_bytes(void *buf, size_t len) int qemu_guest_getrandom(void *buf, size_t len, Error **errp) { + int ret; + if (replay_mode == REPLAY_MODE_PLAY) { + return replay_read_random(buf, len); + } if (unlikely(deterministic)) { /* Deterministic implementation using Glib's Mersenne Twister. */ - return glib_random_bytes(buf, len); + ret = glib_random_bytes(buf, len); } else { /* Non-deterministic implementation using crypto routines. */ - return qcrypto_random_bytes(buf, len, errp); + ret = qcrypto_random_bytes(buf, len, errp); + } + if (replay_mode == REPLAY_MODE_RECORD) { + replay_save_random(ret, buf, len); } + return ret; } void qemu_guest_getrandom_nofail(void *buf, size_t len) |