Skip to content

Commit 17b0128

Browse files
committed
wireguard: selftests: use maximum cpu features and allow rng seeding
By forcing the maximum CPU that QEMU has available, we expose additional capabilities, such as the RNDR instruction, which increases test coverage. This then allows the CI to skip the fake seeding step in some cases. Also enable STRICT_KERNEL_RWX to catch issues related to early jump labels when the RNG is initialized at boot. Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent e052a47 commit 17b0128

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

tools/testing/selftests/wireguard/qemu/Makefile

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ QEMU_VPORT_RESULT := virtio-serial-device
6464
ifeq ($(HOST_ARCH),$(ARCH))
6565
QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
6666
else
67-
QEMU_MACHINE := -cpu cortex-a53 -machine virt
68-
CFLAGS += -march=armv8-a -mtune=cortex-a53
67+
QEMU_MACHINE := -cpu max -machine virt
68+
CFLAGS += -march=armv8-a
6969
endif
7070
else ifeq ($(ARCH),aarch64_be)
7171
CHOST := aarch64_be-linux-musl
@@ -76,8 +76,8 @@ QEMU_VPORT_RESULT := virtio-serial-device
7676
ifeq ($(HOST_ARCH),$(ARCH))
7777
QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
7878
else
79-
QEMU_MACHINE := -cpu cortex-a53 -machine virt
80-
CFLAGS += -march=armv8-a -mtune=cortex-a53
79+
QEMU_MACHINE := -cpu max -machine virt
80+
CFLAGS += -march=armv8-a
8181
endif
8282
else ifeq ($(ARCH),arm)
8383
CHOST := arm-linux-musleabi
@@ -88,8 +88,8 @@ QEMU_VPORT_RESULT := virtio-serial-device
8888
ifeq ($(HOST_ARCH),$(ARCH))
8989
QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
9090
else
91-
QEMU_MACHINE := -cpu cortex-a15 -machine virt
92-
CFLAGS += -march=armv7-a -mtune=cortex-a15 -mabi=aapcs-linux
91+
QEMU_MACHINE := -cpu max -machine virt
92+
CFLAGS += -march=armv7-a -mabi=aapcs-linux
9393
endif
9494
else ifeq ($(ARCH),armeb)
9595
CHOST := armeb-linux-musleabi
@@ -100,8 +100,8 @@ QEMU_VPORT_RESULT := virtio-serial-device
100100
ifeq ($(HOST_ARCH),$(ARCH))
101101
QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
102102
else
103-
QEMU_MACHINE := -cpu cortex-a15 -machine virt
104-
CFLAGS += -march=armv7-a -mabi=aapcs-linux # We don't pass -mtune=cortex-a15 due to a compiler bug on big endian.
103+
QEMU_MACHINE := -cpu max -machine virt
104+
CFLAGS += -march=armv7-a -mabi=aapcs-linux
105105
LDFLAGS += -Wl,--be8
106106
endif
107107
else ifeq ($(ARCH),x86_64)
@@ -112,8 +112,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage
112112
ifeq ($(HOST_ARCH),$(ARCH))
113113
QEMU_MACHINE := -cpu host -machine q35,accel=kvm
114114
else
115-
QEMU_MACHINE := -cpu Skylake-Server -machine q35
116-
CFLAGS += -march=skylake-avx512
115+
QEMU_MACHINE := -cpu max -machine q35
117116
endif
118117
else ifeq ($(ARCH),i686)
119118
CHOST := i686-linux-musl
@@ -123,8 +122,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage
123122
ifeq ($(subst x86_64,i686,$(HOST_ARCH)),$(ARCH))
124123
QEMU_MACHINE := -cpu host -machine q35,accel=kvm
125124
else
126-
QEMU_MACHINE := -cpu coreduo -machine q35
127-
CFLAGS += -march=prescott
125+
QEMU_MACHINE := -cpu max -machine q35
128126
endif
129127
else ifeq ($(ARCH),mips64)
130128
CHOST := mips64-linux-musl
@@ -182,7 +180,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
182180
ifeq ($(HOST_ARCH),$(ARCH))
183181
QEMU_MACHINE := -cpu host,accel=kvm -machine pseries
184182
else
185-
QEMU_MACHINE := -machine pseries
183+
QEMU_MACHINE := -machine pseries -device spapr-rng,rng=rng -object rng-random,id=rng
186184
endif
187185
else ifeq ($(ARCH),powerpc64le)
188186
CHOST := powerpc64le-linux-musl
@@ -192,7 +190,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
192190
ifeq ($(HOST_ARCH),$(ARCH))
193191
QEMU_MACHINE := -cpu host,accel=kvm -machine pseries
194192
else
195-
QEMU_MACHINE := -machine pseries
193+
QEMU_MACHINE := -machine pseries -device spapr-rng,rng=rng -object rng-random,id=rng
196194
endif
197195
else ifeq ($(ARCH),powerpc)
198196
CHOST := powerpc-linux-musl
@@ -247,7 +245,7 @@ QEMU_VPORT_RESULT := virtio-serial-ccw
247245
ifeq ($(HOST_ARCH),$(ARCH))
248246
QEMU_MACHINE := -cpu host,accel=kvm -machine s390-ccw-virtio -append $(KERNEL_CMDLINE)
249247
else
250-
QEMU_MACHINE := -machine s390-ccw-virtio -append $(KERNEL_CMDLINE)
248+
QEMU_MACHINE := -cpu max -machine s390-ccw-virtio -append $(KERNEL_CMDLINE)
251249
endif
252250
else
253251
$(error I only build: x86_64, i686, arm, armeb, aarch64, aarch64_be, mips, mipsel, mips64, mips64el, powerpc64, powerpc64le, powerpc, m68k, riscv64, riscv32, s390x)

tools/testing/selftests/wireguard/qemu/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sys/utsname.h>
2222
#include <sys/sendfile.h>
2323
#include <sys/sysmacros.h>
24+
#include <sys/random.h>
2425
#include <linux/random.h>
2526
#include <linux/version.h>
2627

@@ -58,6 +59,8 @@ static void seed_rng(void)
5859
{
5960
int bits = 256, fd;
6061

62+
if (!getrandom(NULL, 0, GRND_NONBLOCK))
63+
return;
6164
pretty_message("[+] Fake seeding RNG...");
6265
fd = open("/dev/random", O_WRONLY);
6366
if (fd < 0)

tools/testing/selftests/wireguard/qemu/kernel.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ CONFIG_TTY=y
3131
CONFIG_BINFMT_ELF=y
3232
CONFIG_BINFMT_SCRIPT=y
3333
CONFIG_VDSO=y
34+
CONFIG_STRICT_KERNEL_RWX=y
3435
CONFIG_VIRTUALIZATION=y
3536
CONFIG_HYPERVISOR_GUEST=y
3637
CONFIG_PARAVIRT=y
@@ -65,6 +66,8 @@ CONFIG_PROC_FS=y
6566
CONFIG_PROC_SYSCTL=y
6667
CONFIG_SYSFS=y
6768
CONFIG_TMPFS=y
69+
CONFIG_RANDOM_TRUST_CPU=y
70+
CONFIG_RANDOM_TRUST_BOOTLOADER=y
6871
CONFIG_CONSOLE_LOGLEVEL_DEFAULT=15
6972
CONFIG_LOG_BUF_SHIFT=18
7073
CONFIG_PRINTK_TIME=y

0 commit comments

Comments
 (0)