Re: [PATCH] x86_64: test xmm/ymm register state after execve(2)

From: Alexey Dobriyan
Date: Wed Dec 06 2023 - 01:15:59 EST


On Tue, Dec 05, 2023 at 12:39:32PM -0800, Dave Hansen wrote:
> On 12/5/23 06:21, Alexey Dobriyan wrote:
> > Test that xmm/ymm registers are cleared immediately after execve(2).
> >
> > It is opportunistically named "check_xmm_ymm_zmm" because I don't have
> > AVX-512 machine but it will be trivial to extend without renaming stuff.
>
> Hi Alexey,
>
> This looks pretty useful. I know we've had bugs in this area in the
> past. Was there any recent motivation for this, though? Just curious.

I found check_initial_reg_state.c with cool assembly but only general
registers being checked.

> > --- /dev/null
> > +++ b/tools/testing/selftests/x86/check_xmm_ymm_zmm.c
> > @@ -0,0 +1,176 @@
> > +/*
> > + * Copyright (c) 2023 Alexey Dobriyan <adobriyan@xxxxxxxxx>
> > + *
> > + * Permission to use, copy, modify, and distribute this software for any
> > + * purpose with or without fee is hereby granted, provided that the above
> > + * copyright notice and this permission notice appear in all copies.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> > + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> > + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> > + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> > + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> > + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> > + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> > + */
> > +/* Test that xmm, ymm registers are cleared immediately after execve(2). */
>
> Can this be trimmed down to a nice SPDX header?

I'd rather not.

This is standalone test program, not part of kernel proper, so if it's
copied somewhere than copyrights are retained. Another project might not
even use SPDX scheme.

> > +#include <stdio.h>
> > +#include <string.h>
> > +
> > +#if defined __amd64__
> > +#elif defined __i386__
> > +#error "fix register count, SSE2 detection"
> > +#else
> > +#error
> > +#endif

> > +".Ltest_xmm:"
> > + "movdqu %xmm0, xmm + 16 * 0;"
> > + "movdqu %xmm1, xmm + 16 * 1;"
>
> Does this work on systems without XMMs? I know it's not common these
> days but it's possible, especially in VMs.

No. But I think all x86_64 systems have SSE2. So it is up to whoever will
port this test to i386.