summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/arm64/signal/testcases/zt_regs.c
blob: 2e384d731618b5b32de15deda05a2b617527c397 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2021 ARM Limited
 *
 * Verify that using an instruction not supported in streaming mode
 * traps when in streaming mode.
 */

#include <signal.h>
#include <ucontext.h>
#include <sys/prctl.h>

#include "test_signals_utils.h"
#include "testcases.h"

static union {
	ucontext_t uc;
	char buf[1024 * 128];
} context;

static void enable_za(void)
{
	/* smstart za; real data is TODO */
	asm volatile(".inst 0xd503457f" : : : );
}

int zt_regs_run(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
{
	size_t offset;
	struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context);
	struct zt_context *zt;
	char *zeros;

	/*
	 * Get a signal context which should have a ZT frame and registers
	 * in it.
	 */
	enable_za();
	if (!get_current_context(td, &context.uc, sizeof(context)))
		return 1;

	head = get_header(head, ZT_MAGIC, GET_BUF_RESV_SIZE(context), &offset);
	if (!head) {
		fprintf(stderr, "No ZT context\n");
		return 1;
	}

	zt = (struct zt_context *)head;
	if (zt->nregs == 0) {
		fprintf(stderr, "Got context with no registers\n");
		return 1;
	}

	fprintf(stderr, "Got expected size %u for %d registers\n",
		head->size, zt->nregs);

	/* We didn't load any data into ZT so it should be all zeros */
	zeros = malloc(ZT_SIG_REGS_SIZE(zt->nregs));
	if (!zeros) {
		fprintf(stderr, "Out of memory, nregs=%u\n", zt->nregs);
		return 1;
	}
	memset(zeros, 0, ZT_SIG_REGS_SIZE(zt->nregs));

	if (memcmp(zeros, (char *)zt + ZT_SIG_REGS_OFFSET,
		   ZT_SIG_REGS_SIZE(zt->nregs)) != 0) {
		fprintf(stderr, "ZT data invalid\n");
		free(zeros);
		return 1;
	}

	free(zeros);

	td->pass = 1;

	return 0;
}

struct tdescr tde = {
	.name = "ZT register data",
	.descr = "Validate that ZT is present and has data when ZA is enabled",
	.feats_required = FEAT_SME2,
	.timeout = 3,
	.sanity_disabled = true,
	.run = zt_regs_run,
};