diff mbox series

x86-64: Save APX registers in ld.so trampoline

Message ID 20240212004606.969653-1-hjl.tools@gmail.com
State New
Headers show
Series x86-64: Save APX registers in ld.so trampoline | expand

Commit Message

H.J. Lu Feb. 12, 2024, 12:46 a.m. UTC
Remove bound registers from STATE_SAVE_MASK and add APX registers to
STATE_SAVE_MASK so that APX registers are saved in ld.so trampoline.
This fixes BZ #31371.
---
 sysdeps/x86/sysdep.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Noah Goldstein Feb. 12, 2024, 6:16 p.m. UTC | #1
On Mon, Feb 12, 2024 at 12:46 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> Remove bound registers from STATE_SAVE_MASK and add APX registers to
> STATE_SAVE_MASK so that APX registers are saved in ld.so trampoline.
> This fixes BZ #31371.
> ---
>  sysdeps/x86/sysdep.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sysdeps/x86/sysdep.h b/sysdeps/x86/sysdep.h
> index 85d0a8c943..9877a3a46f 100644
> --- a/sysdeps/x86/sysdep.h
> +++ b/sysdeps/x86/sysdep.h
> @@ -26,9 +26,9 @@
>     aligned to 16 bytes for fxsave and 64 bytes for xsave.  */
>  #define STATE_SAVE_OFFSET (8 * 7 + 8)
>
> -/* Save SSE, AVX, AVX512, mask and bound registers.  */
> +/* Save SSE, AVX, AVX512, mask and APX registers.  */
>  #define STATE_SAVE_MASK \
> -  ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 6) | (1 << 7))
> +  ((1 << 1) | (1 << 2) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 19))

Not 100% necessary for this patch, but defines for which bit
is associated with which state would probably make this easier
to maintain.

I.e
#define STATE_BIT_FP        (1 << 0)
#define STATE_BIT_SSE       (1 << 1)
#define STATE_BIT_YMM       (1 << 2)
#define STATE_BIT_BNDREGS   (1 << 3)
#define STATE_BIT_BNDCSR    (1 << 4)
#define STATE_BIT_OPMASK    (1 << 5)
#define STATE_BIT_ZMM_Hi256 (1 << 6)
#define STATE_BIT_Hi16_ZMM  (1 << 7)
#define STATE_BIT_APX       (1 << 19)

#define STATE_SAVE_MASK (STATE_BIT_FP | STATE_BIT_SSE | ...)
>
>  /* Constants for bits in __x86_string_control:  */
>
> --
> 2.43.0
>
H.J. Lu Feb. 13, 2024, 4:18 a.m. UTC | #2
On Mon, Feb 12, 2024 at 10:16 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> On Mon, Feb 12, 2024 at 12:46 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > Remove bound registers from STATE_SAVE_MASK and add APX registers to
> > STATE_SAVE_MASK so that APX registers are saved in ld.so trampoline.
> > This fixes BZ #31371.
> > ---
> >  sysdeps/x86/sysdep.h | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/sysdeps/x86/sysdep.h b/sysdeps/x86/sysdep.h
> > index 85d0a8c943..9877a3a46f 100644
> > --- a/sysdeps/x86/sysdep.h
> > +++ b/sysdeps/x86/sysdep.h
> > @@ -26,9 +26,9 @@
> >     aligned to 16 bytes for fxsave and 64 bytes for xsave.  */
> >  #define STATE_SAVE_OFFSET (8 * 7 + 8)
> >
> > -/* Save SSE, AVX, AVX512, mask and bound registers.  */
> > +/* Save SSE, AVX, AVX512, mask and APX registers.  */
> >  #define STATE_SAVE_MASK \
> > -  ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 6) | (1 << 7))
> > +  ((1 << 1) | (1 << 2) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 19))
>
> Not 100% necessary for this patch, but defines for which bit
> is associated with which state would probably make this easier
> to maintain.
>
> I.e
> #define STATE_BIT_FP        (1 << 0)
> #define STATE_BIT_SSE       (1 << 1)
> #define STATE_BIT_YMM       (1 << 2)
> #define STATE_BIT_BNDREGS   (1 << 3)
> #define STATE_BIT_BNDCSR    (1 << 4)
> #define STATE_BIT_OPMASK    (1 << 5)
> #define STATE_BIT_ZMM_Hi256 (1 << 6)
> #define STATE_BIT_Hi16_ZMM  (1 << 7)
> #define STATE_BIT_APX       (1 << 19)

I copied the same macros from GDB:

https://sourceware.org/git?p=binutils-gdb.git;a=blob;f=gdbsupport/x86-xstate.h

The v2 patch is the part of this patch set:

https://patchwork.sourceware.org/project/glibc/list/?series=30854

> #define STATE_SAVE_MASK (STATE_BIT_FP | STATE_BIT_SSE | ...)
> >
> >  /* Constants for bits in __x86_string_control:  */
> >
> > --
> > 2.43.0
> >
diff mbox series

Patch

diff --git a/sysdeps/x86/sysdep.h b/sysdeps/x86/sysdep.h
index 85d0a8c943..9877a3a46f 100644
--- a/sysdeps/x86/sysdep.h
+++ b/sysdeps/x86/sysdep.h
@@ -26,9 +26,9 @@ 
    aligned to 16 bytes for fxsave and 64 bytes for xsave.  */
 #define STATE_SAVE_OFFSET (8 * 7 + 8)
 
-/* Save SSE, AVX, AVX512, mask and bound registers.  */
+/* Save SSE, AVX, AVX512, mask and APX registers.  */
 #define STATE_SAVE_MASK \
-  ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 6) | (1 << 7))
+  ((1 << 1) | (1 << 2) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 19))
 
 /* Constants for bits in __x86_string_control:  */