[debian-mysql] Bug#1006702: Run-time detection of ISA extensions

Marko Mäkelä marko.makela at mariadb.com
Fri Mar 11 06:35:17 GMT 2022


Like Daniel Black wrote, the code in question should be unreachable
unless support for those ISA extensions is detected at runtime.

When it comes to IA-32 or i386,
https://wiki.debian.org/SupportedArchitectures says: 'requires "686"
class CPU.' In fact, the Pentium LOCK CMPXCHG8B instruction (of the
f00f bug infame) would be needed for implementing 64-bit atomic
operations on a 32-bit processor. Many 32-bit atomic operations use
the 80486 LOCK XADD.

The AMD64 ISA implies SSE2, which I suppose is within the '"686" class
CPU' territory.

There actually was a real bug
https://jira.mariadb.org/browse/MDEV-24745 due to a sloppy
implementation of the run-time CPU detection. A colleague ignored my
advice and implemented the run-time check (which uses the 80486 CPUID
instruction) in a compilation unit that was compiled with -msse4.2.
The same compilation unit included some CRC-32C instructions (which
are part of SSE 4.2) and a generic implementation of CRC-32C. Due to
the -msse4.2, the compiler would emit some SSE 4.1 instructions for
the generic fallback code, and that code failed with SIGILL on older
CPUs.

Currently, the compilation unit that implements the run-time CPU
detection is being compiled without any 'dangerous' flags.

A big reason why MariaDB enables instruction set extensions for entire
compilation units is that older versions of GCC did not support target
attributes for functions. We want older in-support GNU/Linux
distributions to be able to compile the source code with the stock
compiler, which can be as old as GCC 4.8.5 for example in the case of
CentOS 7.

When it comes to SIMD implementations of CRC computation on POWER, I
trust Daniel's judgement. On ARMv8 we did have some trouble, most
recently with the carry-less multiplication (pmull) that is not
available on the Raspberry Pi 4:
https://jira.mariadb.org/browse/MDEV-23030

In MariaDB Server 10.6.6, I added some run-time detection of
transactional memory for IA-32 and AMD64. The support for Intel TSX-NI
will be detected by CPUID, and some functions are declared with the
target "rtm". On s390x and POWER, Hardware Transactional Memory can be
enabled at compilation time: POWER ISA v2.07 or later is implemented
in POWER8 or later.

Best regards,

Marko
-- 
Marko Mäkelä, Lead Developer InnoDB
MariaDB Corporation



More information about the pkg-mysql-maint mailing list