diff mbox series

[v1,2/8] x86: Add COND_VZEROUPPER that can replace vzeroupper if no `ret`

Message ID 20220603044229.2180216-2-goldstein.w.n@gmail.com
State New
Headers show
Series [v1,1/8] x86: Create header for VEC classes in x86 strings library | expand

Commit Message

Noah Goldstein June 3, 2022, 4:42 a.m. UTC
The RTM vzeroupper mitigation has no way of replacing inline
vzeroupper not before a return.

This code does not change any existing functionality.

There is no difference in the objdump of libc.so before and after this
patch.
---
 sysdeps/x86_64/multiarch/avx-rtm-vecs.h  |  1 +
 sysdeps/x86_64/multiarch/avx2-rtm-vecs.h |  1 +
 sysdeps/x86_64/sysdep.h                  | 16 ++++++++++++++++
 3 files changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/sysdeps/x86_64/multiarch/avx-rtm-vecs.h b/sysdeps/x86_64/multiarch/avx-rtm-vecs.h
index c00b83ea0e..e954b8e1b0 100644
--- a/sysdeps/x86_64/multiarch/avx-rtm-vecs.h
+++ b/sysdeps/x86_64/multiarch/avx-rtm-vecs.h
@@ -20,6 +20,7 @@ 
 #ifndef _AVX_RTM_VECS_H
 #define _AVX_RTM_VECS_H			1
 
+#define COND_VZEROUPPER			COND_VZEROUPPER_XTEST
 #define ZERO_UPPER_VEC_REGISTERS_RETURN	\
 	ZERO_UPPER_VEC_REGISTERS_RETURN_XTEST
 
diff --git a/sysdeps/x86_64/multiarch/avx2-rtm-vecs.h b/sysdeps/x86_64/multiarch/avx2-rtm-vecs.h
index a5d46e8c66..e20c3635a0 100644
--- a/sysdeps/x86_64/multiarch/avx2-rtm-vecs.h
+++ b/sysdeps/x86_64/multiarch/avx2-rtm-vecs.h
@@ -20,6 +20,7 @@ 
 #ifndef _AVX2_RTM_VECS_H
 #define _AVX2_RTM_VECS_H			1
 
+#define COND_VZEROUPPER			COND_VZEROUPPER_XTEST
 #define ZERO_UPPER_VEC_REGISTERS_RETURN	\
 	ZERO_UPPER_VEC_REGISTERS_RETURN_XTEST
 
diff --git a/sysdeps/x86_64/sysdep.h b/sysdeps/x86_64/sysdep.h
index f14d50786d..2cb31a558b 100644
--- a/sysdeps/x86_64/sysdep.h
+++ b/sysdeps/x86_64/sysdep.h
@@ -106,6 +106,22 @@  lose:									      \
 	vzeroupper;						\
 	ret
 
+/* Can be used to replace vzeroupper that is not directly before a
+   return.  */
+#define COND_VZEROUPPER_XTEST							\
+    xtest;							\
+    jz 1f;							\
+    vzeroall;							\
+    jmp 2f;							\
+1:							\
+    vzeroupper;							\
+2:
+
+/* In RTM define this as COND_VZEROUPPER_XTEST.  */
+#ifndef COND_VZEROUPPER
+# define COND_VZEROUPPER vzeroupper
+#endif
+
 /* Zero upper vector registers and return.  */
 #ifndef ZERO_UPPER_VEC_REGISTERS_RETURN
 # define ZERO_UPPER_VEC_REGISTERS_RETURN \