hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/arch/arm64/kvm/sys_regs.h
....@@ -1,3 +1,4 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Copyright (C) 2012,2013 - ARM Ltd
34 * Author: Marc Zyngier <marc.zyngier@arm.com>
....@@ -5,18 +6,6 @@
56 * Derived from arch/arm/kvm/coproc.h
67 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
78 * Authors: Christoffer Dall <c.dall@virtualopensystems.com>
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License, version 2, as
11
- * published by the Free Software Foundation.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
209 */
2110
2211 #ifndef __ARM64_KVM_SYS_REGS_LOCAL_H__
....@@ -30,11 +19,18 @@
3019 u8 Op2;
3120 u64 regval;
3221 bool is_write;
33
- bool is_aarch32;
34
- bool is_32bit; /* Only valid if is_aarch32 is true */
3522 };
3623
3724 struct sys_reg_desc {
25
+ /* Sysreg string for debug */
26
+ const char *name;
27
+
28
+ enum {
29
+ AA32_ZEROHIGH,
30
+ AA32_LO,
31
+ AA32_HI,
32
+ } aarch32_map;
33
+
3834 /* MRS/MSR instruction which accesses it. */
3935 u8 Op0;
4036 u8 Op1;
....@@ -61,13 +57,33 @@
6157 const struct kvm_one_reg *reg, void __user *uaddr);
6258 int (*set_user)(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
6359 const struct kvm_one_reg *reg, void __user *uaddr);
60
+
61
+ /* Return mask of REG_* runtime visibility overrides */
62
+ unsigned int (*visibility)(const struct kvm_vcpu *vcpu,
63
+ const struct sys_reg_desc *rd);
6464 };
65
+
66
+#define REG_HIDDEN (1 << 0) /* hidden from userspace and guest */
67
+#define REG_RAZ (1 << 1) /* RAZ from userspace and guest */
68
+
69
+static __printf(2, 3)
70
+inline void print_sys_reg_msg(const struct sys_reg_params *p,
71
+ char *fmt, ...)
72
+{
73
+ va_list va;
74
+
75
+ va_start(va, fmt);
76
+ /* Look, we even formatted it for you to paste into the table! */
77
+ kvm_pr_unimpl("%pV { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n",
78
+ &(struct va_format){ fmt, &va },
79
+ p->Op0, p->Op1, p->CRn, p->CRm, p->Op2, p->is_write ? "write" : "read");
80
+ va_end(va);
81
+}
6582
6683 static inline void print_sys_reg_instr(const struct sys_reg_params *p)
6784 {
68
- /* Look, we even formatted it for you to paste into the table! */
69
- kvm_pr_unimpl(" { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n",
70
- p->Op0, p->Op1, p->CRn, p->CRm, p->Op2, p->is_write ? "write" : "read");
85
+ /* GCC warns on an empty format string */
86
+ print_sys_reg_msg(p, "%s", "");
7187 }
7288
7389 static inline bool ignore_write(struct kvm_vcpu *vcpu,
....@@ -99,6 +115,24 @@
99115 __vcpu_sys_reg(vcpu, r->reg) = r->val;
100116 }
101117
118
+static inline bool sysreg_hidden(const struct kvm_vcpu *vcpu,
119
+ const struct sys_reg_desc *r)
120
+{
121
+ if (likely(!r->visibility))
122
+ return false;
123
+
124
+ return r->visibility(vcpu, r) & REG_HIDDEN;
125
+}
126
+
127
+static inline bool sysreg_visible_as_raz(const struct kvm_vcpu *vcpu,
128
+ const struct sys_reg_desc *r)
129
+{
130
+ if (likely(!r->visibility))
131
+ return false;
132
+
133
+ return r->visibility(vcpu, r) & REG_RAZ;
134
+}
135
+
102136 static inline int cmp_sys_reg(const struct sys_reg_desc *i1,
103137 const struct sys_reg_desc *i2)
104138 {
....@@ -123,6 +157,7 @@
123157 const struct sys_reg_desc table[],
124158 unsigned int num);
125159
160
+#define AA32(_x) .aarch32_map = AA32_##_x
126161 #define Op0(_x) .Op0 = _x
127162 #define Op1(_x) .Op1 = _x
128163 #define CRn(_x) .CRn = _x
....@@ -130,6 +165,7 @@
130165 #define Op2(_x) .Op2 = _x
131166
132167 #define SYS_DESC(reg) \
168
+ .name = #reg, \
133169 Op0(sys_reg_Op0(reg)), Op1(sys_reg_Op1(reg)), \
134170 CRn(sys_reg_CRn(reg)), CRm(sys_reg_CRm(reg)), \
135171 Op2(sys_reg_Op2(reg))