Commit d418238d authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/rth/tags/pull-rng-20190522' into staging



Introduce qemu_guest_getrandom.
Use qemu_guest_getrandom in aspeed, nrf51, bcm2835, exynos4210 rng devices.
Use qemu_guest_getrandom in target/ppc darn instruction.
Support ARMv8.5-RNG extension.
Support x86 RDRAND extension.

Acked-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
Acked-by: default avatarLaurent Vivier <laurent@vivier.eu>

# gpg: Signature made Wed 22 May 2019 19:36:43 BST
# gpg:                using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F
# gpg:                issuer "richard.henderson@linaro.org"
# gpg: Good signature from "Richard Henderson <richard.henderson@linaro.org>" [full]
# Primary key fingerprint: 7A48 1E78 868B 4DB6 A85A  05C0 64DF 38E8 AF7E 215F

* remotes/rth/tags/pull-rng-20190522: (25 commits)
  target/i386: Implement CPUID_EXT_RDRAND
  target/ppc: Use qemu_guest_getrandom for DARN
  target/ppc: Use gen_io_start/end around DARN
  target/arm: Implement ARMv8.5-RNG
  target/arm: Put all PAC keys into a structure
  hw/misc/exynos4210_rng: Use qemu_guest_getrandom
  hw/misc/bcm2835_rng: Use qemu_guest_getrandom_nofail
  hw/misc/nrf51_rng: Use qemu_guest_getrandom_nofail
  aspeed/scu: Use qemu_guest_getrandom_nofail
  linux-user: Remove srand call
  linux-user/aarch64: Use qemu_guest_getrandom for PAUTH keys
  linux-user: Use qemu_guest_getrandom_nofail for AT_RANDOM
  linux-user: Call qcrypto_init if not using -seed
  linux-user: Initialize pseudo-random seeds for all guest cpus
  cpus: Initialize pseudo-random seeds for all guest cpus
  util: Add qemu_guest_getrandom and associated routines
  ui/vnc: Use gcrypto_random_bytes for start_auth_vnc
  ui/vnc: Split out authentication_failed
  crypto: Change the qcrypto_random_bytes buffer type to void*
  crypto: Use getrandom for qcrypto_random_bytes
  ...

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents c4600d5d 369fd5ca
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -413,7 +413,7 @@ dummy := $(call unnest-vars,, \
                block-obj-y \
                block-obj-m \
                crypto-obj-y \
                crypto-aes-obj-y \
                crypto-user-obj-y \
                qom-obj-y \
                io-obj-y \
                common-obj-y \
@@ -487,7 +487,7 @@ subdir-slirp: .git-submodule-status
	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp BUILD_DIR="$(BUILD_DIR)/slirp" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(LDFLAGS)")

$(SUBDIR_RULES): libqemuutil.a $(common-obj-y) \
	$(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY))
	$(qom-obj-y) $(crypto-user-obj-$(CONFIG_USER_ONLY))

ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS))
# Only keep -O and -g cflags
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ block-obj-m = block/
# crypto-obj-y is code used by both qemu system emulation and qemu-img

crypto-obj-y = crypto/
crypto-aes-obj-y = crypto/
crypto-user-obj-y = crypto/

#######################################################################
# qom-obj-y is code used by both qemu system emulation and qemu-img
+2 −2
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ dummy := $(call unnest-vars,.., \
               block-obj-m \
               chardev-obj-y \
               crypto-obj-y \
               crypto-aes-obj-y \
               crypto-user-obj-y \
               qom-obj-y \
               io-obj-y \
               common-obj-y \
@@ -189,7 +189,7 @@ all-obj-y += $(common-obj-y)
all-obj-y += $(qom-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y)
all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y)
all-obj-$(CONFIG_USER_ONLY) += $(crypto-user-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y)

+58 −29
Original line number Diff line number Diff line
@@ -2784,17 +2784,23 @@ fi
# GNUTLS probe

if test "$gnutls" != "no"; then
    pass="no"
    if $pkg_config --exists "gnutls >= 3.1.18"; then
        gnutls_cflags=$($pkg_config --cflags gnutls)
        gnutls_libs=$($pkg_config --libs gnutls)
        libs_softmmu="$gnutls_libs $libs_softmmu"
        libs_tools="$gnutls_libs $libs_tools"
        # Packaging for the static libraries is not always correct.
        # At least ubuntu 18.04 ships only shared libraries.
        write_c_skeleton
        if compile_prog "" "$gnutls_libs" ; then
            LIBS="$gnutls_libs $LIBS"
            QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags"
        gnutls="yes"
    elif test "$gnutls" = "yes"; then
            pass="yes"
        fi
    fi
    if test "$pass" = "no" && test "$gnutls" = "yes"; then
	feature_not_found "gnutls" "Install gnutls devel >= 3.1.18"
    else
        gnutls="no"
        gnutls="$pass"
    fi
fi

@@ -2849,43 +2855,52 @@ has_libgcrypt() {


if test "$nettle" != "no"; then
    pass="no"
    if $pkg_config --exists "nettle >= 2.7.1"; then
        nettle_cflags=$($pkg_config --cflags nettle)
        nettle_libs=$($pkg_config --libs nettle)
        nettle_version=$($pkg_config --modversion nettle)
        libs_softmmu="$nettle_libs $libs_softmmu"
        libs_tools="$nettle_libs $libs_tools"
        # Link test to make sure the given libraries work (e.g for static).
        write_c_skeleton
        if compile_prog "" "$nettle_libs" ; then
            LIBS="$nettle_libs $LIBS"
            QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags"
        nettle="yes"

            if test -z "$gcrypt"; then
               gcrypt="no"
            fi
    else
        if test "$nettle" = "yes"; then
            pass="yes"
        fi
    fi
    if test "$pass" = "no" && test "$nettle" = "yes"; then
        feature_not_found "nettle" "Install nettle devel >= 2.7.1"
    else
            nettle="no"
        fi
        nettle="$pass"
    fi
fi

if test "$gcrypt" != "no"; then
    pass="no"
    if has_libgcrypt; then
        gcrypt_cflags=$(libgcrypt-config --cflags)
        gcrypt_libs=$(libgcrypt-config --libs)
        # Debian has remove -lgpg-error from libgcrypt-config
        # Debian has removed -lgpg-error from libgcrypt-config
        # as it "spreads unnecessary dependencies" which in
        # turn breaks static builds...
        if test "$static" = "yes"
        then
            gcrypt_libs="$gcrypt_libs -lgpg-error"
        fi
        libs_softmmu="$gcrypt_libs $libs_softmmu"
        libs_tools="$gcrypt_libs $libs_tools"

        # Link test to make sure the given libraries work (e.g for static).
        write_c_skeleton
        if compile_prog "" "$gcrypt_libs" ; then
            LIBS="$gcrypt_libs $LIBS"
            QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags"
            pass="yes"
        fi
    fi
    if test "$pass" = "yes"; then
        gcrypt="yes"

        cat > $TMPC << EOF
#include <gcrypt.h>
int main(void) {
@@ -2898,14 +2913,12 @@ EOF
        if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
            gcrypt_hmac=yes
        fi
    else
        if test "$gcrypt" = "yes"; then
    elif test "$gcrypt" = "yes"; then
        feature_not_found "gcrypt" "Install gcrypt devel >= 1.5.0"
    else
        gcrypt="no"
    fi
fi
fi


if test "$gcrypt" = "yes" && test "$nettle" = "yes"
@@ -5802,6 +5815,20 @@ if compile_prog "" "" ; then
    have_utmpx=yes
fi

##########################################
# check for getrandom()

have_getrandom=no
cat > $TMPC << EOF
#include <sys/random.h>
int main(void) {
    return getrandom(0, 0, GRND_NONBLOCK);
}
EOF
if compile_prog "" "" ; then
    have_getrandom=yes
fi

##########################################
# checks for sanitizers

@@ -7191,7 +7218,9 @@ fi
if test "$have_utmpx" = "yes" ; then
  echo "HAVE_UTMPX=y" >> $config_host_mak
fi

if test "$have_getrandom" = "yes" ; then
  echo "CONFIG_GETRANDOM=y" >> $config_host_mak
fi
if test "$ivshmem" = "yes" ; then
  echo "CONFIG_IVSHMEM=y" >> $config_host_mak
fi
+9 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@
#include "qemu/option.h"
#include "qemu/bitmap.h"
#include "qemu/seqlock.h"
#include "qemu/guest-random.h"
#include "tcg.h"
#include "hw/nmi.h"
#include "sysemu/replay.h"
@@ -1276,6 +1277,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
    /* signal CPU creation */
    cpu->created = true;
    qemu_cond_signal(&qemu_cpu_cond);
    qemu_guest_random_seed_thread_part2(cpu->random_seed);

    do {
        if (cpu_can_run(cpu)) {
@@ -1319,6 +1321,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg)
    /* signal CPU creation */
    cpu->created = true;
    qemu_cond_signal(&qemu_cpu_cond);
    qemu_guest_random_seed_thread_part2(cpu->random_seed);

    do {
        qemu_mutex_unlock_iothread();
@@ -1478,6 +1481,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)
    cpu->created = true;
    cpu->can_do_io = 1;
    qemu_cond_signal(&qemu_cpu_cond);
    qemu_guest_random_seed_thread_part2(cpu->random_seed);

    /* wait for initial kick-off after machine start */
    while (first_cpu->stopped) {
@@ -1592,6 +1596,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg)

    hax_init_vcpu(cpu);
    qemu_cond_signal(&qemu_cpu_cond);
    qemu_guest_random_seed_thread_part2(cpu->random_seed);

    do {
        if (cpu_can_run(cpu)) {
@@ -1631,6 +1636,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg)
    /* signal CPU creation */
    cpu->created = true;
    qemu_cond_signal(&qemu_cpu_cond);
    qemu_guest_random_seed_thread_part2(cpu->random_seed);

    do {
        if (cpu_can_run(cpu)) {
@@ -1671,6 +1677,7 @@ static void *qemu_whpx_cpu_thread_fn(void *arg)
    /* signal CPU creation */
    cpu->created = true;
    qemu_cond_signal(&qemu_cpu_cond);
    qemu_guest_random_seed_thread_part2(cpu->random_seed);

    do {
        if (cpu_can_run(cpu)) {
@@ -1724,6 +1731,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
    cpu->can_do_io = 1;
    current_cpu = cpu;
    qemu_cond_signal(&qemu_cpu_cond);
    qemu_guest_random_seed_thread_part2(cpu->random_seed);

    /* process any pending work */
    cpu->exit_request = 1;
@@ -2071,6 +2079,7 @@ void qemu_init_vcpu(CPUState *cpu)
    cpu->nr_cores = smp_cores;
    cpu->nr_threads = smp_threads;
    cpu->stopped = true;
    cpu->random_seed = qemu_guest_random_seed_thread_part1();

    if (!cpu->as) {
        /* If the target cpu hasn't set up any address spaces itself,
Loading