[PATCH v6 3/3] aarch64: tests for SME
Yury Khrustalev
yury.khrustalev@arm.com
Wed Oct 8 10:28:35 GMT 2025
Hi,
Thanks for the suggestions for improving the tests!
On Tue, Oct 07, 2025 at 01:28:36PM -0300, Adhemerval Zanella Netto wrote:
>
> On 06/10/25 08:53, Yury Khrustalev wrote:
> > This commit adds tests for the following use cases relevant to handing of
> > the SME state:
> >
> > - fork() and vfork()
> > - clone() and clone3()
> > - signal handler
> >
> > ...
> >
> > + /* Enabled ZA state so that effect of disabling be observable. */
> > + enable_sme_za_state (ptr);
> > + check_sme_za_state ("before clone", /* Clear. */ false);
> > +
> > + pid_t pid = __clone3 (&args, sizeof (args), fun, syscall_name);
>
> Unfortunately this does not work on all scenarios. With gcc 15.2.1 with
> glibc configured with --enable-stack-protector=all I see:
>
> $ make test t=misc/tst-sme-clone3
> [...]
> syscall error 22 (Invalid argument)
> make[2]: Leaving directory '/home/azanella/Projects/glibc/glibc-git/misc'
> FAIL: misc/tst-sme-clone3
Good catch.
> ...
> I think it would be better to pull the implementation from glibc itself,
> which is the one that we should actually test:
Right. I went this way originally, but after undefined symbol errors I
thought there would be more, so opted out for using the libgcc
implementation.
> -$(objpfx)tst-sme-clone3: $(objpfx)clone3.o
> +$(objpfx)tst-sme-clone3: $(objpfx)clone3.o \
> + $(objpfx)__arm_za_disable.o
Right
> +/* Required by __arm_za_disable.S and provided by statup code as hidden
> + symbol. */
> +uint64_t _dl_hwcap2;
A neat trick, thanks.
> ...
> > +
> > + /* Check that ZA state of SME was disabled in parent. */
> > + check_sme_za_state ("after clone in parent", /* Clear. */ true);
> > +
> > + printf ("%s child pid: %d\n", syscall_name, pid);
> > + if (pid == -1)
> > + {
> > + if (errno == ENOSYS)
> > + {
> > + puts ("clone3 syscall is not supported");
> > + exit (EXIT_UNSUPPORTED);
> > + }
> > + perror ("clone3");
> > + TEST_VERIFY_EXIT (0);
> > + }
>
> I think we can assume that HWCAP_SME (Linux 5.19) implies in clone3 (Linux 5.3)
> support.
I'm dropping this part: as you correctly pointed out below, we'd exit on
any syscall error anyway.
> > + if (waitid (P_PID, pid, NULL, WEXITED))
>
> Maybe xwaitpid?
Agreed.
> > +/* Workaround to simplify linking with clone3.o. */
> > +void __syscall_error(int code)
> > +{
> > + int err = -code;
> > + fprintf (stderr, "syscall error %d (%s)\n", err, strerror (err));
> > + exit (err);
>
> This makes all the clone3 error handling superflous.
Correct.
> > ...
> >
> > +static void
> > +handler (int signo, siginfo_t *si, void *ctx)
> > +{
> > + TEST_VERIFY (signo == SIGUSR1);
> > + printf ("in the handler: %d and %p\n", signo, si);
>
> The printf here is not async-signal-safe, but I think it should not matter
> for this test.
We can use xwrite() here if we don't print signo and si (which is rather
unnecessary at this point).
> > ...
> >
> > + enable_sme_za_state (blk);
> > + check_sme_za_state ("before signal", false /* State is not clear. */);
> > + xraise (SIGUSR1);
>
> Afaik SIGUSR1 is not a synchronous signal, meaning that the next
> check_sme_za_state state is not guarantee to execute *after* the signal handler
> is being acted uppon.
>
> The best strategy would do something like:
>
> ...
>
> +static int pipefd[2];
> +
Another neat trick, thanks.
> > ...
> >
> > + pid_t pid = vfork ();
> > +
> > + if (pid == 0)
> > + {
> > + /* Check that ZA state of SME was disabled in child. */
> > + check_sme_za_state ("after vfork in child", /* Clear. */ true);
> > + exit (0);
>
> Use _exit. It is undefined calling any other function other than
> execve/_exit after vfork; but I think it should not matter on this
> test.
Good point.
> ...
Thanks, I'll be sending v7 shortly.
Kind regards,
Yury
More information about the Libc-alpha
mailing list