Bug #81197 crash with STATUS_ILLEGAL_INSTRUCTION if CPU/OS cant do AVX instructions
Submitted: 26 Apr 2016 2:18 Modified: 16 Feb 2017 17:41
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S1 (Critical)
Version:5.7.12 OS:Windows
Assigned to: CPU Architecture:Any

[26 Apr 2016 2:18] Shane Bester
Description:
Not all CPU's support these fast-path functions but mysqld.exe is compiled with them anyway.  Sample stack trace from affected system.

mysqld!log+0x2d3 [f:\dd\vctools\crt\fpw32\tran\amd64\log.asm @ 429]
mysqld!cost_group_min_max+0x32b [.\sql\opt_range.cc @ 13124]
mysqld!get_best_group_min_max+0xe40 [.\sql\opt_range.cc @ 12441]
mysqld!test_quick_select+0xafe [.\sql\opt_range.cc @ 3026]
mysqld!get_quick_record_count+0xae [.\sql\sql_optimizer.cc @ 5900]
mysqld!JOIN::estimate_rowcount+0x29d [.\sql\sql_optimizer.cc @ 5646]
mysqld!JOIN::make_join_plan+0x159 [.\sql\sql_optimizer.cc @ 5003]
mysqld!JOIN::optimize+0x5eb [.\sql\sql_optimizer.cc @ 368]
mysqld!st_select_lex::optimize+0x49 [.\sql\sql_select.cc @ 1009]
mysqld!handle_query+0x1bd [.\sql\sql_select.cc @ 164]
mysqld!execute_sqlcom_select+0x217 [.\sql\sql_parse.cc @ 5109]
mysqld!mysql_execute_command+0x716 [.\sql\sql_parse.cc @ 2758]
mysqld!mysql_parse+0x25a [.\sql\sql_parse.cc @ 5525]

The "log" function is crashing.

const double tree_height= table_records == 0 ?
         1.0 :
         ceil(log(double(table_records)) /
         log(double(keys_per_block))); 

__log_F_inv_tail+0x7a0 (00000001`40f47ff0)]
...
 nop     dword ptr [rax+rax]
 xor     rax,rax
 vpsrlq  xmm3,xmm0,34h   <----------- STATUS_ILLEGAL_INSTRUCTION
 vmovd   rax,xmm0
 vpsubq  xmm3,xmm3,xmmword ptr [mysqld!__log_F_inv_tail+0x7d0 
 vcvtdq2pd xmm6,xmm3
 vpand   xmm5,xmm0,xmmword ptr [mysqld!__log_F_inv_tail+0x780
 vcomisd xmm5,mmword ptr [mysqld!__log_F_inv_tail+0x780 
 je      mysqld!log+0x500 
 vpxor   xmm5,xmm5,xmm5
 vcomisd xmm0,xmm5

How to repeat:
run select distinct(intcol) from table on an affected system.

Suggested fix:
Avoid use these instructions if CPU cannot support them. Check CPUID at runtime and use different version.

Or 

update the documentation to specify minimum requirements for CPU features.
[26 Apr 2016 2:21] MySQL Verification Team
affected system in this case was:
Windows 7 Ultimate 64
CPU:Intel(R) Xeon(R) CPU E5-1620 v3 3.50GHz
[26 Apr 2016 3:28] MySQL Verification Team
Some references.
https://bugzilla.mozilla.org/show_bug.cgi?id=1160148
https://software.intel.com/en-us/blogs/2011/04/14/is-avx-enabled/

Looks like Win7 service pack 1 may be required:

https://en.wikipedia.org/wiki/Advanced_Vector_Extensions

if cpu supports AVX instructions, you can run:
   bcdedit /set xsavedisable 0
and reboot.
[26 Apr 2016 14:07] MySQL Verification Team
Windows 7 Service Pack 1 solved the problem.
I think this needs to be mentioned on the "supported platforms" page.
[27 Apr 2016 7:11] MySQL Verification Team
Microsoft Windows 2008 Server R2 also requires SP1 to use AVX instructions.
[27 Apr 2016 7:12] MySQL Verification Team
so this is a request to add the SP1 requirements to:
https://www.mysql.com/support/supportedplatforms/database.html
[23 Jun 2016 7:20] MySQL Verification Team
Bug #81799 marked as duplicate of this
[11 Nov 2016 20:39] James Day
If your operating system is Windows 2008 R2 or Windows 7 and you do not have SP1 installed MySQL 5.7 will regularly restart and in the MySQL server error log file you will see this:

mysqld got exception 0xc000001d

This error message is because you are also using a CPU that does not support the VPSRLQ instruction and indicates that the CPU instruction that was attempted is not supported.

You can confirm this diagnosis by using the client program mysql and running this statement:

SELECT log10(100);

If your system is affected your MySQL server will immediately restart.

To fix this error, you MUST install SP1. This adds the required operating system support for the CPU capability detection and disables that support when the CPU does not have the required instructions.

Alternatively you can install an older version of MySQL, like 5.6.

Windows Server 2008 R2 end of support from Microsoft was 22 February 2013, two years after SP1 was released for it, as described in the Microsoft product lifecycle description at https://support.microsoft.com/en-us/lifecycle/search?alpha=Windows%202008%20R2 .

Windows 7 status is similar, also out of Microsoft support well before MySQL 5.7 was released, details at https://support.microsoft.com/en-us/lifecycle/search?alpha=Windows%207 .

Earlier versions of Windows will also be affected.

Because the operating system including the service pack was out of Microsoft support before MySQL version 5.7 was released we will not be changing the 5.7 server itself to detect this issue, instead you should install the Windows service pack or use an earlier version of MySQL.

James Day, MySQL Senior Principal Support Engineer, Oracle
[11 Nov 2016 21:19] James Day
Both Windows 7 and Windows Server 2008 R2 are affected because the server one is the server version of Windows 7.

The CPU instruction involved is VPSRLQ and this is part of the foundation part of the AVX-512 feature set, to be implemented in all CPUs that support AVX-512. 

Without checking in great depth it appears that the instruction is first supported in Xeon's Skylake EX/EP "Purley" generation with release expected in 2017 and in the 2016 Phi x200 Knights Landing processor that was announced in 2013 and first released in June 2016, as well as the related co-processor. The Cannonlake feature set is also expected to include the AVX-512 features.

At the time of writing it appears unclear when non-Xeon desktop CPUs will have support for AVX-512.

Just because a family of CPUs supports a feature does not mean that all CPUs in that family support it. CPUs are typically released in many sub-versions, so if you want this feature, ensure that the specific CPU model number you are buying has it.

Just having a CPU with the feature is not enough because the operating system also has to preserve the register used by the feature and that support needs the service pack in Windows Server 2008 R2 and 7.

CPUs which do have the feature should optimize queries a bit faster than ones without it. That's why MySQL included support for the feature that was expected to become available early in 5.7's lifecycle.
[11 Nov 2016 21:28] James Day
It is not certain that SELECT log10(100); will always confirm diagnosis, it's just one way that can help to increase confidence in the diagnosis. Since the service pack is mandatory for MySQL 5.7 you must install it anyway.
[27 Jan 2017 12:38] MySQL Verification Team
see https://bugs.mysql.com/bug.php?id=84690 (MySQL crashes on startup with existing ssl-certificates on Nano Server)
[29 Jan 2017 17:05] Sebastian Tkaczuk
Try this WORKAROUND using Hyper-V 2012 R2:
For virtual machine activate processor compatibility-mode for porting to another machine.
[16 Feb 2017 17:41] Paul DuBois
Posted by developer:
 
Updated https://dev.mysql.com/doc/refman/5.7/en/windows-installation.html with the SP1 requirement.