0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <signal.h>
0010 #include <ucontext.h>
0011 #include <sys/prctl.h>
0012
0013 #include "test_signals_utils.h"
0014 #include "testcases.h"
0015
0016 struct fake_sigframe sf;
0017 static unsigned int vls[SVE_VQ_MAX];
0018 unsigned int nvls = 0;
0019
0020 static bool sme_get_vls(struct tdescr *td)
0021 {
0022 int vq, vl;
0023
0024
0025
0026
0027 for (vq = SVE_VQ_MAX; vq > 0; --vq) {
0028 vl = prctl(PR_SVE_SET_VL, vq * 16);
0029 if (vl == -1)
0030 return false;
0031
0032 vl &= PR_SME_VL_LEN_MASK;
0033
0034
0035 vq = sve_vq_from_vl(vl);
0036
0037 vls[nvls++] = vl;
0038 }
0039
0040
0041 if (nvls < 1) {
0042 fprintf(stderr, "Only %d VL supported\n", nvls);
0043 return false;
0044 }
0045
0046 return true;
0047 }
0048
0049 static void setup_za_regs(void)
0050 {
0051
0052 asm volatile(".inst 0xd503457f" : : : );
0053 }
0054
0055 static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc,
0056 unsigned int vl)
0057 {
0058 size_t resv_sz, offset;
0059 struct _aarch64_ctx *head = GET_SF_RESV_HEAD(sf);
0060 struct za_context *za;
0061
0062 fprintf(stderr, "Testing VL %d\n", vl);
0063
0064 if (prctl(PR_SME_SET_VL, vl) != vl) {
0065 fprintf(stderr, "Failed to set VL\n");
0066 return 1;
0067 }
0068
0069
0070
0071
0072
0073 setup_za_regs();
0074 if (!get_current_context(td, &sf.uc))
0075 return 1;
0076
0077 resv_sz = GET_SF_RESV_SIZE(sf);
0078 head = get_header(head, ZA_MAGIC, resv_sz, &offset);
0079 if (!head) {
0080 fprintf(stderr, "No ZA context\n");
0081 return 1;
0082 }
0083
0084 za = (struct za_context *)head;
0085 if (za->vl != vl) {
0086 fprintf(stderr, "Got VL %d, expected %d\n", za->vl, vl);
0087 return 1;
0088 }
0089
0090
0091 fprintf(stderr, "Got expected size %u and VL %d\n",
0092 head->size, za->vl);
0093
0094 return 0;
0095 }
0096
0097 static int sme_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
0098 {
0099 int i;
0100
0101 for (i = 0; i < nvls; i++) {
0102
0103
0104
0105
0106
0107 if (vls[i] > 32) {
0108 printf("Skipping VL %u due to stack size\n", vls[i]);
0109 continue;
0110 }
0111
0112 if (do_one_sme_vl(td, si, uc, vls[i]))
0113 return 1;
0114 }
0115
0116 td->pass = 1;
0117
0118 return 0;
0119 }
0120
0121 struct tdescr tde = {
0122 .name = "ZA register",
0123 .descr = "Check that we get the right ZA registers reported",
0124 .feats_required = FEAT_SME,
0125 .timeout = 3,
0126 .init = sme_get_vls,
0127 .run = sme_regs,
0128 };