[MDEV-28091] PERFORMANCE_SCHEMA unit tests fail due to memory misalignment Created: 2022-03-16  Updated: 2022-03-16  Resolved: 2022-03-16

Status: Closed
Project: MariaDB Server
Component/s: Performance Schema, Tests
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
Fix Version/s: 10.2.44, 10.3.35, 10.4.25, 10.5.16, 10.6.8, 10.7.4, 10.8.3

Type: Bug Priority: Major
Reporter: Marko Mäkelä Assignee: Marko Mäkelä
Resolution: Fixed Votes: 0
Labels: alignment
Environment:

Debian GNU/Linux AMD64, clang-13 or clang-14 -march=native -mtune=native



 Description   

On my system, 3 unit tests for performance_schema failed with SIGSEGV, on MariaDB Server 10.9. The reason turned out to be that the SIMD instruction MOVAPS was executed in create_thread() on a pointer that was only aligned to 128 bits (16 bytes), not the required 256 or 512 bits.

The reason turned out to be that the mocked up pfs_malloc() failed to return properly aligned memory (64 bytes or 512 bits in the case of AMD64):

diff --git a/storage/perfschema/unittest/stub_pfs_global.h b/storage/perfschema/unittest/stub_pfs_global.h
index 8a1f9216ba2..3d7d818cc51 100644
--- a/storage/perfschema/unittest/stub_pfs_global.h
+++ b/storage/perfschema/unittest/stub_pfs_global.h
@@ -24,6 +24,9 @@
 #include <my_sys.h>
 #include <pfs_global.h>
 #include <string.h>
+#ifdef HAVE_MEMALIGN
+# include <malloc.h>
+#endif
 
 bool pfs_initialized= false;
 
@@ -43,7 +46,15 @@ void *pfs_malloc(size_t size, myf)
   if (--stub_alloc_fails_after_count <= 0)
     return NULL;
 
+#ifndef PFS_ALIGNEMENT
   void *ptr= malloc(size);
+#elif defined HAVE_MEMALIGN
+  void *ptr= memalign(PFS_ALIGNEMENT, size);
+#elif defined HAVE_ALIGNED_MALLOC
+  void *ptr= _aligned_malloc(size, PFS_ALIGNEMENT);
+#else
+# error "Missing implementation"
+#endif
   if (ptr != NULL)
     memset(ptr, 0, size);
   return ptr;


Generated at Thu Feb 08 09:57:59 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.