Skip to content

Commit 912dee5

Browse files
Andrew JonesMarc Zyngier
authored andcommitted
KVM: arm64: Check RAZ visibility in ID register accessors
The instruction encodings of ID registers are preallocated. Until an encoding is assigned a purpose the register is RAZ. KVM's general ID register accessor functions already support both paths, RAZ or not. If for each ID register we can determine if it's RAZ or not, then all ID registers can build on the general functions. The register visibility function allows us to check whether a register should be completely hidden or not, extending it to also report when the register should be RAZ or not allows us to use it for ID registers as well. Check for RAZ visibility in the ID register accessor functions, allowing the RAZ case to be handled in a generic way for all system registers. The new REG_RAZ flag will be used in a later patch. This patch has no intended functional change. Signed-off-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20201105091022.15373-4-drjones@redhat.com
1 parent 01fe5ac commit 912dee5

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

arch/arm64/kvm/sys_regs.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,12 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
11511151
return val;
11521152
}
11531153

1154+
static unsigned int id_visibility(const struct kvm_vcpu *vcpu,
1155+
const struct sys_reg_desc *r)
1156+
{
1157+
return 0;
1158+
}
1159+
11541160
/* cpufeature ID register access trap handlers */
11551161

11561162
static bool __access_id_reg(struct kvm_vcpu *vcpu,
@@ -1169,7 +1175,9 @@ static bool access_id_reg(struct kvm_vcpu *vcpu,
11691175
struct sys_reg_params *p,
11701176
const struct sys_reg_desc *r)
11711177
{
1172-
return __access_id_reg(vcpu, p, r, false);
1178+
bool raz = sysreg_visible_as_raz(vcpu, r);
1179+
1180+
return __access_id_reg(vcpu, p, r, raz);
11731181
}
11741182

11751183
static bool access_raz_id_reg(struct kvm_vcpu *vcpu,
@@ -1281,13 +1289,17 @@ static int __set_id_reg(const struct kvm_vcpu *vcpu,
12811289
static int get_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
12821290
const struct kvm_one_reg *reg, void __user *uaddr)
12831291
{
1284-
return __get_id_reg(vcpu, rd, uaddr, false);
1292+
bool raz = sysreg_visible_as_raz(vcpu, rd);
1293+
1294+
return __get_id_reg(vcpu, rd, uaddr, raz);
12851295
}
12861296

12871297
static int set_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
12881298
const struct kvm_one_reg *reg, void __user *uaddr)
12891299
{
1290-
return __set_id_reg(vcpu, rd, uaddr, false);
1300+
bool raz = sysreg_visible_as_raz(vcpu, rd);
1301+
1302+
return __set_id_reg(vcpu, rd, uaddr, raz);
12911303
}
12921304

12931305
static int get_raz_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
@@ -1372,6 +1384,7 @@ static bool access_ccsidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
13721384
.access = access_id_reg, \
13731385
.get_user = get_id_reg, \
13741386
.set_user = set_id_reg, \
1387+
.visibility = id_visibility, \
13751388
}
13761389

13771390
/*

arch/arm64/kvm/sys_regs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct sys_reg_desc {
6060
};
6161

6262
#define REG_HIDDEN (1 << 0) /* hidden from userspace and guest */
63+
#define REG_RAZ (1 << 1) /* RAZ from userspace and guest */
6364

6465
static __printf(2, 3)
6566
inline void print_sys_reg_msg(const struct sys_reg_params *p,
@@ -119,6 +120,15 @@ static inline bool sysreg_hidden(const struct kvm_vcpu *vcpu,
119120
return r->visibility(vcpu, r) & REG_HIDDEN;
120121
}
121122

123+
static inline bool sysreg_visible_as_raz(const struct kvm_vcpu *vcpu,
124+
const struct sys_reg_desc *r)
125+
{
126+
if (likely(!r->visibility))
127+
return false;
128+
129+
return r->visibility(vcpu, r) & REG_RAZ;
130+
}
131+
122132
static inline int cmp_sys_reg(const struct sys_reg_desc *i1,
123133
const struct sys_reg_desc *i2)
124134
{

0 commit comments

Comments
 (0)