kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>
Cc: Laurent Vivier <lvivier@redhat.com>,
	Drew Jones <drjones@redhat.com>, Bill Wendling <morbo@google.com>
Subject: [kvm-unit-tests PATCH 04/11] Fixes for the umip test
Date: Thu, 14 May 2020 21:26:19 +0200	[thread overview]
Message-ID: <20200514192626.9950-5-thuth@redhat.com> (raw)
In-Reply-To: <20200514192626.9950-1-thuth@redhat.com>

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.

Message-Id: <20200122160944.29750-1-thuth@redhat.com>
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 x86/umip.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/x86/umip.c b/x86/umip.c
index 7eee294..37f1ab8 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,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),
-- 
2.18.1


  parent reply	other threads:[~2020-05-14 19:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14 19:26 [kvm-unit-tests PATCH 00/11] Misc fixes and CI improvements Thomas Huth
2020-05-14 19:26 ` [kvm-unit-tests PATCH 01/11] x86/access: Fix phys-bits parameter Thomas Huth
2020-05-14 19:26 ` [kvm-unit-tests PATCH 02/11] Fix out-of-tree builds Thomas Huth
2020-05-14 19:26 ` [kvm-unit-tests PATCH 03/11] x86: avoid multiply defined symbol Thomas Huth
2020-05-14 19:26 ` Thomas Huth [this message]
2020-05-14 19:26 ` [kvm-unit-tests PATCH 05/11] Always compile the kvm-unit-tests with -fno-common Thomas Huth
2020-05-14 19:26 ` [kvm-unit-tests PATCH 06/11] Fix powerpc issue with the linker from Fedora 32 Thomas Huth
2020-05-14 19:26 ` [kvm-unit-tests PATCH 07/11] Update the gitlab-ci to " Thomas Huth
2020-05-14 19:26 ` [kvm-unit-tests PATCH 08/11] x86: use a non-negative number in shift Thomas Huth
2020-05-14 19:26 ` [kvm-unit-tests PATCH 09/11] x86: use inline asm to retrieve stack pointer Thomas Huth
2020-05-14 19:26 ` [kvm-unit-tests PATCH 10/11] vmx_tests: Silence warning from Clang Thomas Huth
2020-05-14 19:26 ` [kvm-unit-tests PATCH 11/11] Compile the kvm-unit-tests also with Clang Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200514192626.9950-5-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=morbo@google.com \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).