93dc2d
commit 1d401d1fccb85046402089268b94d86d822070e6
93dc2d
Author: Aurelien Jarno <aurelien@aurel32.net>
93dc2d
Date:   Mon Jan 17 19:41:40 2022 +0100
93dc2d
93dc2d
    x86: use default cache size if it cannot be determined [BZ #28784]
93dc2d
    
93dc2d
    In some cases (e.g QEMU, non-Intel/AMD CPU) the cache information can
93dc2d
    not be retrieved and the corresponding values are set to 0.
93dc2d
    
93dc2d
    Commit 2d651eb9265d ("x86: Move x86 processor cache info to
93dc2d
    cpu_features") changed the behaviour in such case by defining the
93dc2d
    __x86_shared_cache_size and __x86_data_cache_size variables to 0 instead
93dc2d
    of using the default values. This cause an issue with the i686 SSE2
93dc2d
    optimized bzero/routine which assumes that the cache size is at least
93dc2d
    128 bytes, and otherwise tries to zero/set the whole address space minus
93dc2d
    128 bytes.
93dc2d
    
93dc2d
    Fix that by restoring the original code to only update
93dc2d
    __x86_shared_cache_size and __x86_data_cache_size variables if the
93dc2d
    corresponding cache sizes are not zero.
93dc2d
    
93dc2d
    Fixes bug 28784
93dc2d
    Fixes commit 2d651eb9265d
93dc2d
    
93dc2d
    Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
93dc2d
    (cherry picked from commit c242fcce06e3102ca663b2f992611d0bda4f2668)
93dc2d
93dc2d
diff --git a/sysdeps/x86/cacheinfo.h b/sysdeps/x86/cacheinfo.h
93dc2d
index 41d2c81369840ada..63f36877e3f35d99 100644
93dc2d
--- a/sysdeps/x86/cacheinfo.h
93dc2d
+++ b/sysdeps/x86/cacheinfo.h
93dc2d
@@ -61,14 +61,20 @@ init_cacheinfo (void)
93dc2d
   long int data = cpu_features->data_cache_size;
93dc2d
   /* Round data cache size to multiple of 256 bytes.  */
93dc2d
   data = data & ~255L;
93dc2d
-  __x86_data_cache_size_half = data / 2;
93dc2d
-  __x86_data_cache_size = data;
93dc2d
+  if (data > 0)
93dc2d
+    {
93dc2d
+      __x86_data_cache_size_half = data / 2;
93dc2d
+      __x86_data_cache_size = data;
93dc2d
+    }
93dc2d
 
93dc2d
   long int shared = cpu_features->shared_cache_size;
93dc2d
   /* Round shared cache size to multiple of 256 bytes.  */
93dc2d
   shared = shared & ~255L;
93dc2d
-  __x86_shared_cache_size_half = shared / 2;
93dc2d
-  __x86_shared_cache_size = shared;
93dc2d
+  if (shared > 0)
93dc2d
+    {
93dc2d
+      __x86_shared_cache_size_half = shared / 2;
93dc2d
+      __x86_shared_cache_size = shared;
93dc2d
+    }
93dc2d
 
93dc2d
   __x86_shared_non_temporal_threshold
93dc2d
     = cpu_features->non_temporal_threshold;