NetBSD Problem Report #47248

From www@NetBSD.org  Mon Nov 26 10:09:25 2012
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id 20E0563DFC7
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 26 Nov 2012 10:09:25 +0000 (UTC)
Message-Id: <20121126100923.6BFC463DFC7@www.NetBSD.org>
Date: Mon, 26 Nov 2012 10:09:23 +0000 (UTC)
From: jaapb@NetBSD.org
Reply-To: jaapb@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: Using -march=native on Intel I5 causes illegal instructions
X-Send-Pr-Version: www-1.0

>Number:         47248
>Category:       kern
>Synopsis:       Using -march=native on Intel I5 causes illegal instructions
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 26 10:10:00 +0000 2012
>Closed-Date:    Fri Oct 25 04:40:53 +0000 2019
>Last-Modified:  Fri Oct 25 04:40:53 +0000 2019
>Originator:     Jaap Boender
>Release:        6.0_STABLE
>Organization:
>Environment:
NetBSD purcell.mdx.ac.uk 6.0_STABLE NetBSD 6.0_STABLE (PURCELL) #6: Tue Nov 20 14:03:01 GMT 2012  root@purcell.mdx.ac.uk:/usr/obj/sys/arch/amd64/compile/PURCELL amd64
>Description:
[See also the discussion on port-amd64, starting here: http://mail-index.netbsd.org/port-amd64/2012/11/13/msg001794.html ]

On my laptop, which has an Intel i5-3320 CPU (see below for cpuctl output), using devel/cpuflags results in the kernel, toolchain and distribution being compiled with
-march=native -msse3 -mfpmath=sse. This works fine for kernel and toolchain, but after installing the new distribution, every executable I try to run coredumps with "Illegal instruction".

This seems to be a problem with AVX instructions being generated, but the AVX bit in the kernel not being set.

An example of a generated executable and its core dump can be found on ftp.NetBSD.org in /pub/NetBSD/misc/jaapb/amd64_ill/gawk{,core} .

-- cpuctl identify output --
cpu0: Intel Pentium Pro, II or III (686-class), 2591.84 MHz, id 0x306a9
cpu0: features  0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR>
cpu0: features  0xbfebfbff<PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR>
cpu0: features  0xbfebfbff<SSE,SSE2,SS,HTT,TM,SBF>
cpu0: features2 0x77bae3ff<SSE3,PCLMULQDQ,DTES64,MONITOR,DS-CPL,VMX,SMX,EST>
cpu0: features2 0x77bae3ff<TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE41,SSE42,X2APIC>
cpu0: features2 0x77bae3ff<POPCNT,B24,AES,XSAVE,AVX,F16C,B30>
cpu0: features3 0x28100800<SYSCALL/SYSRET,XD,EM64T>
cpu0: features4 0x1<LAHF>
cpu0: "Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz"
cpu0: ITLB 64 4KB entries 4-way
cpu0: DTLB 64 4KB entries 4-way
cpu0: Initial APIC ID 0
cpu0: Cluster/Package ID 0
cpu0: Core ID 0
cpu0: SMT ID 0
cpu0: family 06 model 0a extfamily 00 extmodel 03 stepping 09
cpu0: UCode version: ?

>How-To-Repeat:
Compile something with the -march=native flag on an Intel i5-3320 CPU. I detected the problem with build.sh distribution, but just compiling lang/gawk also triggers the problem.
>Fix:
A workaround is not using -march=native but -march=core2. This works fine.

>Release-Note:

>Audit-Trail:
From: David Laight <david@l8s.co.uk>
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: kern/47248: Using -march=native on Intel I5 causes illegal instructions
Date: Sun, 30 Dec 2012 16:42:40 +0000

 On Mon, Nov 26, 2012 at 10:10:00AM +0000, jaapb@NetBSD.org wrote:
 > >Synopsis:       Using -march=native on Intel I5 causes illegal instructions

 The gcc code that converts -march=native into a list of -mxxx options
 (-mcx16 -msahf -maes -mpclmul -mpopcnt -mavx on my i7) is only checking
 that the cpu supports the extra instructions, not that the OS also has
 support.

 The Intel docs vol 1 secton 13.5 tell you to check the OXSAVE bit
 as well as the AVX one (otherwise it is likely to be an old OS).
 The doc also says to check that the XCR0 bits indicate that AVX
 can actually be used - but I suspect the kernel may want to 'lazy-set'
 that bit.

 Checking OXSAVE is easy, fixed in rev 1.2 of gcc's driver_i386.c

 	David

 -- 
 David Laight: david@l8s.co.uk

From: diro@nixsyspaus.org
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/47248
Date: Mon, 14 Jan 2013 10:53:06 -0500

 Will this be pulled up into 6.0.2?

State-Changed-From-To: open->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Fri, 25 Oct 2019 04:40:53 +0000
State-Changed-Why:
The original issue is fixed, and netbsd can execute AVX instructions.
The GCC fix is in all currently supported netbsd versions.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.