0002-kvm-unit-tests-test-for-rdseed-rdrand.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. From 8d9a62a5fa89001266352a929c5d40b28c0dda85 Mon Sep 17 00:00:00 2001
  2. From: Matt Weber <matthew.weber@rockwellcollins.com>
  3. Date: Fri, 12 Jan 2018 19:07:27 -0600
  4. Subject: [PATCH v2] kvm-unit-tests: test for rdseed/rdrand
  5. The build fails when the host binutils isn't at least 2.23
  6. (2.22.x introduced RDSEED).
  7. Fixes:
  8. http://autobuild.buildroot.net/results/c39/c3987a3cbd2960b0ff50f872636bdfd8d1a9c820/
  9. Upstream:
  10. https://marc.info/?l=kvm&m=151580743523259&w=2
  11. Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
  12. ---
  13. Makefile | 2 +-
  14. configure | 18 ++++++++++++++++++
  15. x86/vmx_tests.c | 6 ++++++
  16. 3 files changed, 25 insertions(+), 1 deletion(-)
  17. diff --git a/Makefile b/Makefile
  18. index d9ad42b..799e9b5 100644
  19. --- a/Makefile
  20. +++ b/Makefile
  21. @@ -50,7 +50,7 @@ include $(SRCDIR)/$(TEST_DIR)/Makefile
  22. cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
  23. > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
  24. -COMMON_CFLAGS += -g $(autodepend-flags)
  25. +COMMON_CFLAGS += -g $(autodepend-flags) $(EXTRA_CFLAGS)
  26. COMMON_CFLAGS += -Wall -Wwrite-strings -Wclobbered -Wempty-body -Wuninitialized
  27. COMMON_CFLAGS += -Wignored-qualifiers -Wunused-but-set-parameter
  28. frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer
  29. diff --git a/configure b/configure
  30. index dd9d361..21c0219 100755
  31. --- a/configure
  32. +++ b/configure
  33. @@ -171,6 +171,23 @@ mkdir -p lib
  34. ln -sf "$asm" lib/asm
  35. +cat > rd_test.c <<EOF
  36. +#include <stdint.h>
  37. +int main() {
  38. + uint16_t seed=0;
  39. + unsigned char ok;
  40. + asm volatile ("rdseed %0; setc %1"
  41. + : "=r" (seed), "=qm" (ok));
  42. + return ok;
  43. +}
  44. +EOF
  45. +if $cross_prefix$cc -o /dev/null rd_test.c &> /dev/null; then
  46. + echo "Checking for rdseed/rdrand... Yes."
  47. +else
  48. + echo "Checking for rdseed/rdrand... No."
  49. + extra_cflags="-DNO_RDSEEDRAND"
  50. +fi
  51. +
  52. # create the config
  53. cat <<EOF > config.mak
  54. SRCDIR=$srcdir
  55. @@ -181,6 +198,7 @@ ARCH_NAME=$arch_name
  56. PROCESSOR=$processor
  57. CC=$cross_prefix$cc
  58. CXX=$cross_prefix$cxx
  59. +EXTRA_CFLAGS=$extra_cflags
  60. LD=$cross_prefix$ld
  61. OBJCOPY=$cross_prefix$objcopy
  62. OBJDUMP=$cross_prefix$objdump
  63. diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
  64. index 4a3e94b..2cbe3eb 100644
  65. --- a/x86/vmx_tests.c
  66. +++ b/x86/vmx_tests.c
  67. @@ -770,8 +770,10 @@ asm(
  68. "insn_sldt: sldt %ax;ret\n\t"
  69. "insn_lldt: xor %eax, %eax; lldt %ax;ret\n\t"
  70. "insn_str: str %ax;ret\n\t"
  71. +#ifndef NO_RDSEEDRAND
  72. "insn_rdrand: rdrand %rax;ret\n\t"
  73. "insn_rdseed: rdseed %rax;ret\n\t"
  74. +#endif
  75. );
  76. extern void insn_hlt();
  77. extern void insn_invlpg();
  78. @@ -796,8 +798,10 @@ extern void insn_lldt();
  79. extern void insn_str();
  80. extern void insn_cpuid();
  81. extern void insn_invd();
  82. +#ifndef NO_RDSEEDRAND
  83. extern void insn_rdrand();
  84. extern void insn_rdseed();
  85. +#endif
  86. u32 cur_insn;
  87. u64 cr3;
  88. @@ -853,8 +857,10 @@ static struct insn_table insn_table[] = {
  89. {"DESC_TABLE (LLDT)", CPU_DESC_TABLE, insn_lldt, INSN_CPU1, 47, 0, 0, 0},
  90. {"DESC_TABLE (STR)", CPU_DESC_TABLE, insn_str, INSN_CPU1, 47, 0, 0, 0},
  91. /* LTR causes a #GP if done with a busy selector, so it is not tested. */
  92. +#ifndef NO_RDSEEDRAND
  93. {"RDRAND", CPU_RDRAND, insn_rdrand, INSN_CPU1, VMX_RDRAND, 0, 0, 0},
  94. {"RDSEED", CPU_RDSEED, insn_rdseed, INSN_CPU1, VMX_RDSEED, 0, 0, 0},
  95. +#endif
  96. // Instructions always trap
  97. {"CPUID", 0, insn_cpuid, INSN_ALWAYS_TRAP, 10, 0, 0, 0},
  98. {"INVD", 0, insn_invd, INSN_ALWAYS_TRAP, 13, 0, 0, 0},
  99. --
  100. 1.9.1