1*0f4ef8a3SGanesh Goudar // SPDX-License-Identifier: GPL-2.0-or-later
2*0f4ef8a3SGanesh Goudar
3*0f4ef8a3SGanesh Goudar #include <errno.h>
4*0f4ef8a3SGanesh Goudar #include <fcntl.h>
5*0f4ef8a3SGanesh Goudar #include <signal.h>
6*0f4ef8a3SGanesh Goudar #include <stdio.h>
7*0f4ef8a3SGanesh Goudar #include <string.h>
8*0f4ef8a3SGanesh Goudar #include <sys/ioctl.h>
9*0f4ef8a3SGanesh Goudar #include <sys/mman.h>
10*0f4ef8a3SGanesh Goudar #include <sys/stat.h>
11*0f4ef8a3SGanesh Goudar #include <sys/types.h>
12*0f4ef8a3SGanesh Goudar #include <unistd.h>
13*0f4ef8a3SGanesh Goudar
14*0f4ef8a3SGanesh Goudar #include "vas-api.h"
15*0f4ef8a3SGanesh Goudar #include "utils.h"
16*0f4ef8a3SGanesh Goudar
17*0f4ef8a3SGanesh Goudar static bool faulted;
18*0f4ef8a3SGanesh Goudar
sigbus_handler(int n,siginfo_t * info,void * ctxt_v)19*0f4ef8a3SGanesh Goudar static void sigbus_handler(int n, siginfo_t *info, void *ctxt_v)
20*0f4ef8a3SGanesh Goudar {
21*0f4ef8a3SGanesh Goudar ucontext_t *ctxt = (ucontext_t *)ctxt_v;
22*0f4ef8a3SGanesh Goudar struct pt_regs *regs = ctxt->uc_mcontext.regs;
23*0f4ef8a3SGanesh Goudar
24*0f4ef8a3SGanesh Goudar faulted = true;
25*0f4ef8a3SGanesh Goudar regs->nip += 4;
26*0f4ef8a3SGanesh Goudar }
27*0f4ef8a3SGanesh Goudar
test_ra_error(void)28*0f4ef8a3SGanesh Goudar static int test_ra_error(void)
29*0f4ef8a3SGanesh Goudar {
30*0f4ef8a3SGanesh Goudar struct vas_tx_win_open_attr attr;
31*0f4ef8a3SGanesh Goudar int fd, *paste_addr;
32*0f4ef8a3SGanesh Goudar char *devname = "/dev/crypto/nx-gzip";
33*0f4ef8a3SGanesh Goudar struct sigaction act = {
34*0f4ef8a3SGanesh Goudar .sa_sigaction = sigbus_handler,
35*0f4ef8a3SGanesh Goudar .sa_flags = SA_SIGINFO,
36*0f4ef8a3SGanesh Goudar };
37*0f4ef8a3SGanesh Goudar
38*0f4ef8a3SGanesh Goudar memset(&attr, 0, sizeof(attr));
39*0f4ef8a3SGanesh Goudar attr.version = 1;
40*0f4ef8a3SGanesh Goudar attr.vas_id = 0;
41*0f4ef8a3SGanesh Goudar
42*0f4ef8a3SGanesh Goudar SKIP_IF(access(devname, F_OK));
43*0f4ef8a3SGanesh Goudar
44*0f4ef8a3SGanesh Goudar fd = open(devname, O_RDWR);
45*0f4ef8a3SGanesh Goudar FAIL_IF(fd < 0);
46*0f4ef8a3SGanesh Goudar FAIL_IF(ioctl(fd, VAS_TX_WIN_OPEN, &attr) < 0);
47*0f4ef8a3SGanesh Goudar FAIL_IF(sigaction(SIGBUS, &act, NULL) != 0);
48*0f4ef8a3SGanesh Goudar
49*0f4ef8a3SGanesh Goudar paste_addr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0ULL);
50*0f4ef8a3SGanesh Goudar
51*0f4ef8a3SGanesh Goudar /* The following assignment triggers exception */
52*0f4ef8a3SGanesh Goudar mb();
53*0f4ef8a3SGanesh Goudar *paste_addr = 1;
54*0f4ef8a3SGanesh Goudar mb();
55*0f4ef8a3SGanesh Goudar
56*0f4ef8a3SGanesh Goudar FAIL_IF(!faulted);
57*0f4ef8a3SGanesh Goudar
58*0f4ef8a3SGanesh Goudar return 0;
59*0f4ef8a3SGanesh Goudar }
60*0f4ef8a3SGanesh Goudar
main(void)61*0f4ef8a3SGanesh Goudar int main(void)
62*0f4ef8a3SGanesh Goudar {
63*0f4ef8a3SGanesh Goudar return test_harness(test_ra_error, "inject-ra-err");
64*0f4ef8a3SGanesh Goudar }
65*0f4ef8a3SGanesh Goudar
66