kselftest/arm64: Include larger SVE and SME VLs in signal tests
authorMark Brown <broonie@kernel.org>
Mon, 29 Aug 2022 16:07:03 +0000 (17:07 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Wed, 7 Sep 2022 13:25:47 +0000 (14:25 +0100)
Now that the core utilities for signal testing support handling data in
EXTRA_CONTEXT blocks we can test larger SVE and SME VLs which spill over
the limits in the base signal context. This is done by defining storage
for the context as a union with a ucontext_t and a buffer together with
some helpers for getting relevant sizes and offsets like we do for
fake_sigframe, this isn't the most lovely code ever but is fairly
straightforward to implement and much less invasive to the somewhat
unclear and indistinct layers of abstraction in the signal handling test
code.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20220829160703.874492-11-broonie@kernel.org
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
tools/testing/selftests/arm64/signal/testcases/ssve_regs.c
tools/testing/selftests/arm64/signal/testcases/sve_regs.c
tools/testing/selftests/arm64/signal/testcases/testcases.h
tools/testing/selftests/arm64/signal/testcases/za_regs.c

index 71f14632c524a8f409d8661e2a8ee89447767d13..d0a178945b1a82bb0097e18075ddce897d7b1c9a 100644 (file)
 #include "test_signals_utils.h"
 #include "testcases.h"
 
-struct fake_sigframe sf;
+static union {
+       ucontext_t uc;
+       char buf[1024 * 64];
+} context;
 static unsigned int vls[SVE_VQ_MAX];
 unsigned int nvls = 0;
 
@@ -55,8 +58,8 @@ static void setup_ssve_regs(void)
 static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc,
                         unsigned int vl)
 {
-       size_t resv_sz, offset;
-       struct _aarch64_ctx *head = GET_SF_RESV_HEAD(sf);
+       size_t offset;
+       struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context);
        struct sve_context *ssve;
        int ret;
 
@@ -73,11 +76,11 @@ static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc,
         * in it.
         */
        setup_ssve_regs();
-       if (!get_current_context(td, &sf.uc, sizeof(sf.uc)))
+       if (!get_current_context(td, &context.uc, sizeof(context)))
                return 1;
 
-       resv_sz = GET_SF_RESV_SIZE(sf);
-       head = get_header(head, SVE_MAGIC, resv_sz, &offset);
+       head = get_header(head, SVE_MAGIC, GET_BUF_RESV_SIZE(context),
+                         &offset);
        if (!head) {
                fprintf(stderr, "No SVE context\n");
                return 1;
@@ -101,16 +104,6 @@ static int sme_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
        int i;
 
        for (i = 0; i < nvls; i++) {
-               /*
-                * TODO: the signal test helpers can't currently cope
-                * with signal frames bigger than struct sigcontext,
-                * skip VLs that will trigger that.
-                */
-               if (vls[i] > 64) {
-                       printf("Skipping VL %u due to stack size\n", vls[i]);
-                       continue;
-               }
-
                if (do_one_sme_vl(td, si, uc, vls[i]))
                        return 1;
        }
index 4cdedb7067863d07b3ad8f54784bbbad8ec6c39f..8b16eabbb7697e3cb13e3b9d747345bb12b26bb6 100644 (file)
 #include "test_signals_utils.h"
 #include "testcases.h"
 
-struct fake_sigframe sf;
+static union {
+       ucontext_t uc;
+       char buf[1024 * 64];
+} context;
 static unsigned int vls[SVE_VQ_MAX];
 unsigned int nvls = 0;
 
@@ -55,8 +58,8 @@ static void setup_sve_regs(void)
 static int do_one_sve_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc,
                         unsigned int vl)
 {
-       size_t resv_sz, offset;
-       struct _aarch64_ctx *head = GET_SF_RESV_HEAD(sf);
+       size_t offset;
+       struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context);
        struct sve_context *sve;
 
        fprintf(stderr, "Testing VL %d\n", vl);
@@ -71,11 +74,11 @@ static int do_one_sve_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc,
         * in it.
         */
        setup_sve_regs();
-       if (!get_current_context(td, &sf.uc, sizeof(sf.uc)))
+       if (!get_current_context(td, &context.uc, sizeof(context)))
                return 1;
 
-       resv_sz = GET_SF_RESV_SIZE(sf);
-       head = get_header(head, SVE_MAGIC, resv_sz, &offset);
+       head = get_header(head, SVE_MAGIC, GET_BUF_RESV_SIZE(context),
+                         &offset);
        if (!head) {
                fprintf(stderr, "No SVE context\n");
                return 1;
@@ -99,14 +102,6 @@ static int sve_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
        int i;
 
        for (i = 0; i < nvls; i++) {
-               /*
-                * TODO: the signal test helpers can't currently cope
-                * with signal frames bigger than struct sigcontext,
-                * skip VLs that will trigger that.
-                */
-               if (vls[i] > 64)
-                       continue;
-
                if (do_one_sve_vl(td, si, uc, vls[i]))
                        return 1;
        }
index b39f538c7be1250b4c8ad8c21f61f99c90a4161f..040afded0b76eaf8a22e2fd665a74ae4be6dc030 100644 (file)
 #define GET_SF_RESV_SIZE(sf) \
        sizeof((sf).uc.uc_mcontext.__reserved)
 
+#define GET_BUF_RESV_HEAD(buf) \
+       (struct _aarch64_ctx *)(&(buf).uc.uc_mcontext.__reserved)
+
+#define GET_BUF_RESV_SIZE(buf) \
+       (sizeof(buf) - sizeof(buf.uc) + \
+        sizeof((buf).uc.uc_mcontext.__reserved))
+
 #define GET_UCP_RESV_SIZE(ucp) \
        sizeof((ucp)->uc_mcontext.__reserved)
 
index a92b8e9176837de16aafe6ba70c024511cfbbc58..ea45acb115d5b2338c31f62d37b39e5e6475a7ac 100644 (file)
 #include "test_signals_utils.h"
 #include "testcases.h"
 
-struct fake_sigframe sf;
+static union {
+       ucontext_t uc;
+       char buf[1024 * 128];
+} context;
 static unsigned int vls[SVE_VQ_MAX];
 unsigned int nvls = 0;
 
@@ -57,8 +60,8 @@ static char zeros[ZA_SIG_REGS_SIZE(SVE_VQ_MAX)];
 static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc,
                         unsigned int vl)
 {
-       size_t resv_sz, offset;
-       struct _aarch64_ctx *head = GET_SF_RESV_HEAD(sf);
+       size_t offset;
+       struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context);
        struct za_context *za;
 
        fprintf(stderr, "Testing VL %d\n", vl);
@@ -73,11 +76,10 @@ static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc,
         * in it.
         */
        setup_za_regs();
-       if (!get_current_context(td, &sf.uc, sizeof(sf.uc)))
+       if (!get_current_context(td, &context.uc, sizeof(context)))
                return 1;
 
-       resv_sz = GET_SF_RESV_SIZE(sf);
-       head = get_header(head, ZA_MAGIC, resv_sz, &offset);
+       head = get_header(head, ZA_MAGIC, GET_BUF_RESV_SIZE(context), &offset);
        if (!head) {
                fprintf(stderr, "No ZA context\n");
                return 1;
@@ -113,16 +115,6 @@ static int sme_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
        int i;
 
        for (i = 0; i < nvls; i++) {
-               /*
-                * TODO: the signal test helpers can't currently cope
-                * with signal frames bigger than struct sigcontext,
-                * skip VLs that will trigger that.
-                */
-               if (vls[i] > 32) {
-                       printf("Skipping VL %u due to stack size\n", vls[i]);
-                       continue;
-               }
-
                if (do_one_sme_vl(td, si, uc, vls[i]))
                        return 1;
        }