Path: blob/master/tools/testing/selftests/arm64/signal/testcases/sve_regs.c
26295 views
// SPDX-License-Identifier: GPL-2.01/*2* Copyright (C) 2021 ARM Limited3*4* Verify that the SVE register context in signal frames is set up as5* expected.6*/78#include <kselftest.h>9#include <signal.h>10#include <ucontext.h>11#include <sys/prctl.h>1213#include "test_signals_utils.h"14#include "sve_helpers.h"15#include "testcases.h"1617static union {18ucontext_t uc;19char buf[1024 * 64];20} context;2122static bool sve_get_vls(struct tdescr *td)23{24int res = sve_fill_vls(VLS_USE_SVE, 1);2526if (!res)27return true;2829if (res == KSFT_SKIP)30td->result = KSFT_SKIP;3132return false;33}3435static void setup_sve_regs(void)36{37/* RDVL x16, #1 so we should have SVE regs; real data is TODO */38asm volatile(".inst 0x04bf5030" : : : "x16" );39}4041static int do_one_sve_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc,42unsigned int vl)43{44size_t offset;45struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context);46struct sve_context *sve;4748fprintf(stderr, "Testing VL %d\n", vl);4950if (prctl(PR_SVE_SET_VL, vl) == -1) {51fprintf(stderr, "Failed to set VL\n");52return 1;53}5455/*56* Get a signal context which should have a SVE frame and registers57* in it.58*/59setup_sve_regs();60if (!get_current_context(td, &context.uc, sizeof(context)))61return 1;6263head = get_header(head, SVE_MAGIC, GET_BUF_RESV_SIZE(context),64&offset);65if (!head) {66fprintf(stderr, "No SVE context\n");67return 1;68}6970sve = (struct sve_context *)head;71if (sve->vl != vl) {72fprintf(stderr, "Got VL %d, expected %d\n", sve->vl, vl);73return 1;74}7576/* The actual size validation is done in get_current_context() */77fprintf(stderr, "Got expected size %u and VL %d\n",78head->size, sve->vl);7980return 0;81}8283static int sve_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc)84{85int i;8687for (i = 0; i < nvls; i++) {88if (do_one_sve_vl(td, si, uc, vls[i]))89return 1;90}9192td->pass = 1;9394return 0;95}9697struct tdescr tde = {98.name = "SVE registers",99.descr = "Check that we get the right SVE registers reported",100.feats_required = FEAT_SVE,101.timeout = 3,102.init = sve_get_vls,103.run = sve_regs,104};105106107