| 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2021 ARM Limited |
| 4 | * |
| 5 | * Verify that the ZA register context in signal frames is set up as |
| 6 | * expected. |
| 7 | */ |
| 8 | |
| 9 | #include <kselftest.h> |
| 10 | #include <signal.h> |
| 11 | #include <ucontext.h> |
| 12 | #include <sys/prctl.h> |
| 13 | |
| 14 | #include "test_signals_utils.h" |
| 15 | #include "sve_helpers.h" |
| 16 | #include "testcases.h" |
| 17 | |
| 18 | static union { |
| 19 | ucontext_t uc; |
| 20 | char buf[1024 * 128]; |
| 21 | } context; |
| 22 | |
| 23 | static bool sme_get_vls(struct tdescr *td) |
| 24 | { |
| 25 | int res = sve_fill_vls(VLS_USE_SME, 1); |
| 26 | |
| 27 | if (!res) |
| 28 | return true; |
| 29 | |
| 30 | if (res == KSFT_SKIP) |
| 31 | td->result = KSFT_SKIP; |
| 32 | |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | static void setup_za_regs(void) |
| 37 | { |
| 38 | /* smstart za; real data is TODO */ |
| 39 | asm volatile(".inst 0xd503457f" : : : ); |
| 40 | } |
| 41 | |
| 42 | static char zeros[ZA_SIG_REGS_SIZE(SVE_VQ_MAX)]; |
| 43 | |
| 44 | static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, |
| 45 | unsigned int vl) |
| 46 | { |
| 47 | size_t offset; |
| 48 | struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context); |
| 49 | struct za_context *za; |
| 50 | |
| 51 | fprintf(stderr, "Testing VL %d\n" , vl); |
| 52 | |
| 53 | if (prctl(PR_SME_SET_VL, vl) != vl) { |
| 54 | fprintf(stderr, "Failed to set VL\n" ); |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | /* |
| 59 | * Get a signal context which should have a SVE frame and registers |
| 60 | * in it. |
| 61 | */ |
| 62 | setup_za_regs(); |
| 63 | if (!get_current_context(td, &context.uc, sizeof(context))) |
| 64 | return 1; |
| 65 | |
| 66 | head = get_header(head, magic: ZA_MAGIC, GET_BUF_RESV_SIZE(context), offset: &offset); |
| 67 | if (!head) { |
| 68 | fprintf(stderr, "No ZA context\n" ); |
| 69 | return 1; |
| 70 | } |
| 71 | |
| 72 | za = (struct za_context *)head; |
| 73 | if (za->vl != vl) { |
| 74 | fprintf(stderr, "Got VL %d, expected %d\n" , za->vl, vl); |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | if (head->size != ZA_SIG_CONTEXT_SIZE(sve_vq_from_vl(vl))) { |
| 79 | fprintf(stderr, "ZA context size %u, expected %lu\n" , |
| 80 | head->size, ZA_SIG_CONTEXT_SIZE(sve_vq_from_vl(vl))); |
| 81 | return 1; |
| 82 | } |
| 83 | |
| 84 | fprintf(stderr, "Got expected size %u and VL %d\n" , |
| 85 | head->size, za->vl); |
| 86 | |
| 87 | /* We didn't load any data into ZA so it should be all zeros */ |
| 88 | if (memcmp(zeros, (char *)za + ZA_SIG_REGS_OFFSET, |
| 89 | ZA_SIG_REGS_SIZE(sve_vq_from_vl(za->vl))) != 0) { |
| 90 | fprintf(stderr, "ZA data invalid\n" ); |
| 91 | return 1; |
| 92 | } |
| 93 | |
| 94 | if (get_svcr() != 0) { |
| 95 | fprintf(stderr, "Unexpected SVCR %lx\n" , get_svcr()); |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static int sme_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc) |
| 103 | { |
| 104 | int i; |
| 105 | |
| 106 | for (i = 0; i < nvls; i++) { |
| 107 | if (do_one_sme_vl(td, si, uc, vls[i])) |
| 108 | return 1; |
| 109 | } |
| 110 | |
| 111 | td->pass = 1; |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | struct tdescr tde = { |
| 117 | .name = "ZA register" , |
| 118 | .descr = "Check that we get the right ZA registers reported" , |
| 119 | .feats_required = FEAT_SME, |
| 120 | .timeout = 3, |
| 121 | .init = sme_get_vls, |
| 122 | .run = sme_regs, |
| 123 | }; |
| 124 | |