Skip to contentSkip to conversation

Fixes for the umip test

PATCH In review Thomas Huth 2 participants 2 messages May 12, 2020 – Jun 23, 2020 KVM

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Fixes for the umip test

When compiling umip.c with -O2 instead of -O1, there are currently two problems. First, the compiler complains:

x86/umip.c: In function ‘do_ring3’:
x86/umip.c:162:37: error: array subscript 4096 is above array bounds of

    ‘unsigned char[4096]’ [-Werror=array-bounds]
       [user_stack_top]"m"(user_stack[sizeof user_stack]),
                           ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~

This can be fixed by initializing the stack to point to one of the last bytes of the array instead.

The second problem is that some tests are failing - and this is due to the fact that the GP_ASM macro uses inline asm without the "volatile" keyword - so that the compiler reorders this code in certain cases where it should not. Fix it by adding "volatile" here.

---
v3: Use "sizeof(long)" instead of "2"

 x86/umip.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
x86/umip.c +4 -2
index 7eee294..37f1ab8 100644
@@ -22,7 +22,8 @@ static void gp_handler(struct ex_regs *regs)
 
 
 #define GP_ASM(stmt, in, clobber)                  \
-     asm ("mov" W " $1f, %[expected_rip]\n\t"      \
+    asm volatile (                                 \
+          "mov" W " $1f, %[expected_rip]\n\t"      \
           "movl $2f-1f, %[skip_count]\n\t"         \
           "1: " stmt "\n\t"                        \
           "2: "                                    \
@@ -159,7 +160,8 @@ static int do_ring3(void (*fn)(const char *), const char *arg)
 		  : [ret] "=&a" (ret)
 		  : [user_ds] "i" (USER_DS),
 		    [user_cs] "i" (USER_CS),
-		    [user_stack_top]"m"(user_stack[sizeof user_stack]),
+		    [user_stack_top]"m"(user_stack[sizeof(user_stack) -
+						   sizeof(long)]),
 		    [fn]"r"(fn),
 		    [arg]"D"(arg),
 		    [kernel_ds]"i"(KERNEL_DS),
Signature · 1 line
2.18.1
maintainer
#1 lore raw
Quoted 41 lines · Thomas Huth

When compiling umip.c with -O2 instead of -O1, there are currently two problems. First, the compiler complains:

x86/umip.c: In function ‘do_ring3’:
x86/umip.c:162:37: error: array subscript 4096 is above array bounds of

    ‘unsigned char[4096]’ [-Werror=array-bounds]
       [user_stack_top]"m"(user_stack[sizeof user_stack]),
                           ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~

This can be fixed by initializing the stack to point to one of the last bytes of the array instead.

The second problem is that some tests are failing - and this is due to the fact that the GP_ASM macro uses inline asm without the "volatile" keyword - so that the compiler reorders this code in certain cases where it should not. Fix it by adding "volatile" here.

---
v3: Use "sizeof(long)" instead of "2"

 x86/umip.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
x86/umip.c +2 -1
index 7eee294..37f1ab8 100644
@@ -22,7 +22,8 @@ static void gp_handler(struct ex_regs *regs)
 
 
 #define GP_ASM(stmt, in, clobber)                  \
-     asm ("mov" W " $1f, %[expected_rip]\n\t"      \
+    asm volatile (                                 \
+          "mov" W " $1f, %[expected_rip]\n\t"      \
           "movl $2f-1f, %[skip_count]\n\t"         \
           "1: " stmt "\n\t"                        \
           "2: "                                    \

x86/umip.c static int do_ring3(void (*fn)(const char *), const char *arg) · line 167

Quoted 9 lines
x86/umip.c +2 -1
@@ -159,7 +160,8 @@ static int do_ring3(void (*fn)(const char *), const char *arg)
 		  : [ret] "=&a" (ret)
 		  : [user_ds] "i" (USER_DS),
 		    [user_cs] "i" (USER_CS),
-		    [user_stack_top]"m"(user_stack[sizeof user_stack]),
+		    [user_stack_top]"m"(user_stack[sizeof(user_stack) -
+						   sizeof(long)]),
 		    [fn]"r"(fn),
 		    [arg]"D"(arg),
 		    [kernel_ds]"i"(KERNEL_DS),

Pushed, thanks.

Paolo