summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/powerpc/dexcr/dexcr.h
blob: 51e9ba3b09979d61ba84f2fcdd059fd7b896af3c (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * POWER Dynamic Execution Control Facility (DEXCR)
 *
 * This header file contains helper functions and macros
 * required for all the DEXCR related test cases.
 */
#ifndef _SELFTESTS_POWERPC_DEXCR_DEXCR_H
#define _SELFTESTS_POWERPC_DEXCR_DEXCR_H

#include <stdbool.h>
#include <sys/prctl.h>
#include <sys/types.h>

#include "reg.h"

#define DEXCR_PR_BIT(aspect)	__MASK(63 - (32 + (aspect)))
#define DEXCR_PR_SBHE		DEXCR_PR_BIT(0)
#define DEXCR_PR_IBRTPD		DEXCR_PR_BIT(3)
#define DEXCR_PR_SRAPD		DEXCR_PR_BIT(4)
#define DEXCR_PR_NPHIE		DEXCR_PR_BIT(5)

#define PPC_RAW_HASH_ARGS(b, i, a) \
	((((i) >> 3) & 0x1F) << 21 | (a) << 16 | (b) << 11 | (((i) >> 8) & 0x1))
#define PPC_RAW_HASHST(b, i, a) \
	str(.long (0x7C0005A4 | PPC_RAW_HASH_ARGS(b, i, a));)
#define PPC_RAW_HASHCHK(b, i, a) \
	str(.long (0x7C0005E4 | PPC_RAW_HASH_ARGS(b, i, a));)

struct dexcr_aspect {
	const char *name;	/* Short display name */
	const char *opt;	/* Option name for chdexcr */
	const char *desc;	/* Expanded aspect meaning */
	unsigned int index;	/* Aspect bit index in DEXCR */
	unsigned long prctl;	/* 'which' value for get/set prctl */
};

static const struct dexcr_aspect aspects[] = {
	{
		.name = "SBHE",
		.opt = "sbhe",
		.desc = "Speculative branch hint enable",
		.index = 0,
		.prctl = PR_PPC_DEXCR_SBHE,
	},
	{
		.name = "IBRTPD",
		.opt = "ibrtpd",
		.desc = "Indirect branch recurrent target prediction disable",
		.index = 3,
		.prctl = PR_PPC_DEXCR_IBRTPD,
	},
	{
		.name = "SRAPD",
		.opt = "srapd",
		.desc = "Subroutine return address prediction disable",
		.index = 4,
		.prctl = PR_PPC_DEXCR_SRAPD,
	},
	{
		.name = "NPHIE",
		.opt = "nphie",
		.desc = "Non-privileged hash instruction enable",
		.index = 5,
		.prctl = PR_PPC_DEXCR_NPHIE,
	},
	{
		.name = "PHIE",
		.opt = "phie",
		.desc = "Privileged hash instruction enable",
		.index = 6,
		.prctl = -1,
	},
};

bool dexcr_exists(void);

bool pr_dexcr_aspect_supported(unsigned long which);

bool pr_dexcr_aspect_editable(unsigned long which);

int pr_get_dexcr(unsigned long pr_aspect);

int pr_set_dexcr(unsigned long pr_aspect, unsigned long ctrl);

unsigned int pr_which_to_aspect(unsigned long which);

bool hashchk_triggers(void);

enum dexcr_source {
	DEXCR,		/* Userspace DEXCR value */
	HDEXCR,		/* Hypervisor enforced DEXCR value */
	EFFECTIVE,	/* Bitwise OR of UDEXCR and ENFORCED DEXCR bits */
};

unsigned int get_dexcr(enum dexcr_source source);

void await_child_success(pid_t pid);

void hashst(unsigned long lr, void *sp);

void hashchk(unsigned long lr, void *sp);

void do_bad_hashchk(void);

#endif  /* _SELFTESTS_POWERPC_DEXCR_DEXCR_H */