All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests v2 PATCH] Fixes for the umip test
@ 2020-02-10 14:35 Thomas Huth
  2020-02-10 14:56 ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Huth @ 2020-02-10 14:35 UTC (permalink / raw)
  To: kvm, Paolo Bonzini; +Cc: Vitaly Kuznetsov

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.

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 v2: Add parentheses and fix doubled whitespace as requested by Vitaly

 x86/umip.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/x86/umip.c b/x86/umip.c
index 7eee294..339bea4 100644
--- a/x86/umip.c
+++ b/x86/umip.c
@@ -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,7 @@ 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) - 2]),
 		    [fn]"r"(fn),
 		    [arg]"D"(arg),
 		    [kernel_ds]"i"(KERNEL_DS),
-- 
2.18.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [kvm-unit-tests v2 PATCH] Fixes for the umip test
  2020-02-10 14:35 [kvm-unit-tests v2 PATCH] Fixes for the umip test Thomas Huth
@ 2020-02-10 14:56 ` Paolo Bonzini
  2020-02-10 14:59   ` Thomas Huth
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2020-02-10 14:56 UTC (permalink / raw)
  To: Thomas Huth, kvm; +Cc: Vitaly Kuznetsov

On 10/02/20 15:35, Thomas Huth wrote:
>  #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,7 @@ 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) - 2]),

This should be "- sizeof(long)" in order to keep the stack aligned.

I can fix this when I apply.

Paolo

>  		    [fn]"r"(fn),
>  		    [arg]"D"(arg),
>  		    [kernel_ds]"i"(KERNEL_DS),
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [kvm-unit-tests v2 PATCH] Fixes for the umip test
  2020-02-10 14:56 ` Paolo Bonzini
@ 2020-02-10 14:59   ` Thomas Huth
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Huth @ 2020-02-10 14:59 UTC (permalink / raw)
  To: Paolo Bonzini, kvm; +Cc: Vitaly Kuznetsov

On 10/02/2020 15.56, Paolo Bonzini wrote:
> On 10/02/20 15:35, Thomas Huth wrote:
>>  #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,7 @@ 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) - 2]),
> 
> This should be "- sizeof(long)" in order to keep the stack aligned.
> 
> I can fix this when I apply.

Thanks!

 Thomas


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-10 14:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-10 14:35 [kvm-unit-tests v2 PATCH] Fixes for the umip test Thomas Huth
2020-02-10 14:56 ` Paolo Bonzini
2020-02-10 14:59   ` Thomas Huth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.