diff mbox

[kvm-unit-tests,v2] x86: prevent GCC from using sse* instructions

Message ID 20180307150931.15462-1-rkrcmar@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Radim Krčmář March 7, 2018, 3:09 p.m. UTC
GCC 8 emitted MOVDQU when compiling vmx.elf, but we do not enable
CR4.OSFXSR in that test, so the instruction throws #UD.
This patch forbids sse instructions, instead of enabling CR4.OSFXSR, as
I think it's better to keep the environment minimal.

Paolo suggested a way to keep sse around the function that uses it,
allowing us to disable all sse instructions.

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
v2: add -mno-sse [Paolo]
---
 x86/Makefile.x86_64 | 2 +-
 x86/emulator.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Paolo Bonzini March 7, 2018, 3:11 p.m. UTC | #1
On 07/03/2018 16:09, Radim Krčmář wrote:
> GCC 8 emitted MOVDQU when compiling vmx.elf, but we do not enable
> CR4.OSFXSR in that test, so the instruction throws #UD.
> This patch forbids sse instructions, instead of enabling CR4.OSFXSR, as
> I think it's better to keep the environment minimal.
> 
> Paolo suggested a way to keep sse around the function that uses it,
> allowing us to disable all sse instructions.
> 
> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
> ---
> v2: add -mno-sse [Paolo]
> ---
>  x86/Makefile.x86_64 | 2 +-
>  x86/emulator.c      | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/x86/Makefile.x86_64 b/x86/Makefile.x86_64
> index 623fc5b37726..af2f1dd8ce55 100644
> --- a/x86/Makefile.x86_64
> +++ b/x86/Makefile.x86_64
> @@ -1,7 +1,7 @@
>  cstart.o = $(TEST_DIR)/cstart64.o
>  bits = 64
>  ldarch = elf64-x86-64
> -COMMON_CFLAGS += -mno-red-zone
> +COMMON_CFLAGS += -mno-red-zone -mno-sse -mno-sse2
>  
>  cflatobjs += lib/x86/setjmp64.o
>  cflatobjs += lib/x86/intel-iommu.o
> diff --git a/x86/emulator.c b/x86/emulator.c
> index e6f27cccd031..c74237fb1b23 100644
> --- a/x86/emulator.c
> +++ b/x86/emulator.c
> @@ -652,7 +652,7 @@ static bool sseeq(sse_union *v1, sse_union *v2)
>      return ok;
>  }
>  
> -static void test_sse(sse_union *mem)
> +static __attribute__((target("sse"))) void test_sse(sse_union *mem)
>  {
>      sse_union v;
>  
> 

Even better, thanks!

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
diff mbox

Patch

diff --git a/x86/Makefile.x86_64 b/x86/Makefile.x86_64
index 623fc5b37726..af2f1dd8ce55 100644
--- a/x86/Makefile.x86_64
+++ b/x86/Makefile.x86_64
@@ -1,7 +1,7 @@ 
 cstart.o = $(TEST_DIR)/cstart64.o
 bits = 64
 ldarch = elf64-x86-64
-COMMON_CFLAGS += -mno-red-zone
+COMMON_CFLAGS += -mno-red-zone -mno-sse -mno-sse2
 
 cflatobjs += lib/x86/setjmp64.o
 cflatobjs += lib/x86/intel-iommu.o
diff --git a/x86/emulator.c b/x86/emulator.c
index e6f27cccd031..c74237fb1b23 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -652,7 +652,7 @@  static bool sseeq(sse_union *v1, sse_union *v2)
     return ok;
 }
 
-static void test_sse(sse_union *mem)
+static __attribute__((target("sse"))) void test_sse(sse_union *mem)
 {
     sse_union v;