[CRIU] [PATCH] zdtm/x86: Don't override %ebx in fpu00

Dmitry Safonov dima at arista.com
Wed Oct 31 03:16:14 MSK 2018


%ebx, %ecx, %eax aren't specified as clobbers in chk_proc_fpu(),
while asm cpuid overwrites them.

In the turn, %ebx is used as a code position by gcc now:
    1661:       e8 9a 00 00 00          call   1700 <__x86.get_pc_thunk.bx>
    1666:       81 c3 46 68 00 00       add    $0x6846,%ebx

Which results in dereferencing some ugly garbage (result of cpuid).

Let's use zdtm/lib cpuid() function instead.

Signed-off-by: Dmitry Safonov <dima at arista.com>
---
 test/zdtm/static/fpu00.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/test/zdtm/static/fpu00.c b/test/zdtm/static/fpu00.c
index 3e168a2f..04aa738f 100644
--- a/test/zdtm/static/fpu00.c
+++ b/test/zdtm/static/fpu00.c
@@ -7,6 +7,9 @@ const char *test_doc	= "Start a calculation, leaving FPU in a certain state,\n"
 const char *test_author	= "Pavel Emelianov <xemul at parallels.com>";
 
 #if defined(__i386__) || defined(__x86_64__)
+
+#include "cpuid.h"
+
 void start(float a, float b, float c, float d)
 {
 	__asm__ volatile (
@@ -31,16 +34,15 @@ float finish(void)
 	return res;
 }
 
+#define CPUID_FEAT_EDX_FPU (1 << 0)
+
 int chk_proc_fpu(void)
 {
-	unsigned long fi;
+	uint32_t eax, ebx, ecx, edx;
 
-	__asm__ volatile (
-			"mov $1, %%eax\n"
-			"cpuid\n"
-			: "=d" (fi) : : "eax"
-		);
-	return fi & (1 << 0);
+	cpuid(1, &eax, &ebx, &ecx, &edx);
+
+	return edx & CPUID_FEAT_EDX_FPU;
 }
 #endif
 
-- 
2.19.1



More information about the CRIU mailing list