Path: blob/master/tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c
26295 views
// SPDX-License-Identifier: GPL-2.01/*2* Copyright (C) 2023 Arm Limited3*4* Verify that the POR_EL0 register context in signal frames is set up as5* expected.6*/78#include <signal.h>9#include <ucontext.h>10#include <sys/auxv.h>11#include <sys/prctl.h>12#include <unistd.h>13#include <asm/sigcontext.h>1415#include "test_signals_utils.h"16#include "testcases.h"1718static union {19ucontext_t uc;20char buf[1024 * 128];21} context;2223#define SYS_POR_EL0 "S3_3_C10_C2_4"2425static uint64_t get_por_el0(void)26{27uint64_t val;2829asm volatile(30"mrs %0, " SYS_POR_EL0 "\n"31: "=r"(val)32:33: );3435return val;36}3738int poe_present(struct tdescr *td, siginfo_t *si, ucontext_t *uc)39{40struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context);41struct poe_context *poe_ctx;42size_t offset;43bool in_sigframe;44bool have_poe;45__u64 orig_poe;4647have_poe = getauxval(AT_HWCAP2) & HWCAP2_POE;48if (have_poe)49orig_poe = get_por_el0();5051if (!get_current_context(td, &context.uc, sizeof(context)))52return 1;5354poe_ctx = (struct poe_context *)55get_header(head, POE_MAGIC, td->live_sz, &offset);5657in_sigframe = poe_ctx != NULL;5859fprintf(stderr, "POR_EL0 sigframe %s on system %s POE\n",60in_sigframe ? "present" : "absent",61have_poe ? "with" : "without");6263td->pass = (in_sigframe == have_poe);6465/*66* Check that the value we read back was the one present at67* the time that the signal was triggered.68*/69if (have_poe && poe_ctx) {70if (poe_ctx->por_el0 != orig_poe) {71fprintf(stderr, "POR_EL0 in frame is %llx, was %llx\n",72poe_ctx->por_el0, orig_poe);73td->pass = false;74}75}7677return 0;78}7980struct tdescr tde = {81.name = "POR_EL0",82.descr = "Validate that POR_EL0 is present as expected",83.timeout = 3,84.run = poe_present,85};868788