076f82
commit 94b0dc9419bd038cb85b364a7556569386c31741
076f82
Author: Noah Goldstein <goldstein.w.n@gmail.com>
076f82
Date:   Wed Jun 15 10:41:29 2022 -0700
076f82
076f82
    x86: Add bounds `x86_non_temporal_threshold`
076f82
    
076f82
    The lower-bound (16448) and upper-bound (SIZE_MAX / 16) are assumed
076f82
    by memmove-vec-unaligned-erms.
076f82
    
076f82
    The lower-bound is needed because memmove-vec-unaligned-erms unrolls
076f82
    the loop aggressively in the L(large_memset_4x) case.
076f82
    
076f82
    The upper-bound is needed because memmove-vec-unaligned-erms
076f82
    right-shifts the value of `x86_non_temporal_threshold` by
076f82
    LOG_4X_MEMCPY_THRESH (4) which without a bound may overflow.
076f82
    
076f82
    The lack of lower-bound can be a correctness issue. The lack of
076f82
    upper-bound cannot.
076f82
    
076f82
    (cherry picked from commit b446822b6ae4e8149902a78cdd4a886634ad6321)
076f82
076f82
diff --git a/manual/tunables.texi b/manual/tunables.texi
076f82
index 28ff502990c2a10f..5ab3212f34e3dc37 100644
076f82
--- a/manual/tunables.texi
076f82
+++ b/manual/tunables.texi
076f82
@@ -47,7 +47,7 @@ glibc.malloc.mxfast: 0x0 (min: 0x0, max: 0xffffffffffffffff)
076f82
 glibc.elision.skip_lock_busy: 3 (min: -2147483648, max: 2147483647)
076f82
 glibc.malloc.top_pad: 0x0 (min: 0x0, max: 0xffffffffffffffff)
076f82
 glibc.cpu.x86_rep_stosb_threshold: 0x800 (min: 0x1, max: 0xffffffffffffffff)
076f82
-glibc.cpu.x86_non_temporal_threshold: 0xc0000 (min: 0x0, max: 0xffffffffffffffff)
076f82
+glibc.cpu.x86_non_temporal_threshold: 0xc0000 (min: 0x4040, max: 0x0fffffffffffffff)
076f82
 glibc.cpu.x86_shstk:
076f82
 glibc.cpu.hwcap_mask: 0x6 (min: 0x0, max: 0xffffffffffffffff)
076f82
 glibc.malloc.mmap_max: 0 (min: -2147483648, max: 2147483647)
076f82
diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h
076f82
index 560bf260e8fbd7bf..8f85f70858413ebe 100644
076f82
--- a/sysdeps/x86/dl-cacheinfo.h
076f82
+++ b/sysdeps/x86/dl-cacheinfo.h
076f82
@@ -931,8 +931,14 @@ dl_init_cacheinfo (struct cpu_features *cpu_features)
076f82
 
076f82
   TUNABLE_SET_WITH_BOUNDS (x86_data_cache_size, data, 0, SIZE_MAX);
076f82
   TUNABLE_SET_WITH_BOUNDS (x86_shared_cache_size, shared, 0, SIZE_MAX);
076f82
+  /* SIZE_MAX >> 4 because memmove-vec-unaligned-erms right-shifts the value of
076f82
+     'x86_non_temporal_threshold' by `LOG_4X_MEMCPY_THRESH` (4) and it is best
076f82
+     if that operation cannot overflow. Minimum of 0x4040 (16448) because the
076f82
+     L(large_memset_4x) loops need 64-byte to cache align and enough space for
076f82
+     at least 1 iteration of 4x PAGE_SIZE unrolled loop.  Both values are
076f82
+     reflected in the manual.  */
076f82
   TUNABLE_SET_WITH_BOUNDS (x86_non_temporal_threshold, non_temporal_threshold,
076f82
-			   0, SIZE_MAX);
076f82
+			   0x4040, SIZE_MAX >> 4);
076f82
   TUNABLE_SET_WITH_BOUNDS (x86_rep_movsb_threshold, rep_movsb_threshold,
076f82
 			   minimum_rep_movsb_threshold, SIZE_MAX);
076f82
   TUNABLE_SET_WITH_BOUNDS (x86_rep_stosb_threshold, rep_stosb_threshold, 1,