KVM: arm64: nv: Allow a sysreg to be hidden from userspace only
So far, we never needed to distinguish between registers hidden from userspace and being hidden from a guest (they are always either visible to both, or hidden from both). With NV, we have the ugly case of the EL02 and EL12 registers, which are only a view on the EL0 and EL1 registers. It makes absolutely no sense to expose them to userspace, since it already has the canonical view. Add a new visibility flag (REG_HIDDEN_USER) and a new helper that checks for it and REG_HIDDEN when checking whether to expose a sysreg to userspace. Subsequent patches will make use of it. Reviewed-by: Alexandru Elisei <alexandru.elisei@arm.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230209175820.1939006-16-maz@kernel.org Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
This commit is contained in:
parent
d9552fe133
commit
e6b367db0f
|
@ -2980,7 +2980,7 @@ int kvm_sys_reg_get_user(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
r = id_to_sys_reg_desc(vcpu, reg->id, table, num);
|
r = id_to_sys_reg_desc(vcpu, reg->id, table, num);
|
||||||
if (!r)
|
if (!r || sysreg_hidden_user(vcpu, r))
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
if (r->get_user) {
|
if (r->get_user) {
|
||||||
|
@ -3024,7 +3024,7 @@ int kvm_sys_reg_set_user(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg,
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
r = id_to_sys_reg_desc(vcpu, reg->id, table, num);
|
r = id_to_sys_reg_desc(vcpu, reg->id, table, num);
|
||||||
if (!r)
|
if (!r || sysreg_hidden_user(vcpu, r))
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
if (sysreg_user_write_ignore(vcpu, r))
|
if (sysreg_user_write_ignore(vcpu, r))
|
||||||
|
@ -3118,7 +3118,7 @@ static int walk_one_sys_reg(const struct kvm_vcpu *vcpu,
|
||||||
if (!(rd->reg || rd->get_user))
|
if (!(rd->reg || rd->get_user))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (sysreg_hidden(vcpu, rd))
|
if (sysreg_hidden_user(vcpu, rd))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!copy_reg_to_user(rd, uind))
|
if (!copy_reg_to_user(rd, uind))
|
||||||
|
|
|
@ -85,8 +85,9 @@ struct sys_reg_desc {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define REG_HIDDEN (1 << 0) /* hidden from userspace and guest */
|
#define REG_HIDDEN (1 << 0) /* hidden from userspace and guest */
|
||||||
#define REG_RAZ (1 << 1) /* RAZ from userspace and guest */
|
#define REG_HIDDEN_USER (1 << 1) /* hidden from userspace only */
|
||||||
#define REG_USER_WI (1 << 2) /* WI from userspace only */
|
#define REG_RAZ (1 << 2) /* RAZ from userspace and guest */
|
||||||
|
#define REG_USER_WI (1 << 3) /* WI from userspace only */
|
||||||
|
|
||||||
static __printf(2, 3)
|
static __printf(2, 3)
|
||||||
inline void print_sys_reg_msg(const struct sys_reg_params *p,
|
inline void print_sys_reg_msg(const struct sys_reg_params *p,
|
||||||
|
@ -152,6 +153,15 @@ static inline bool sysreg_hidden(const struct kvm_vcpu *vcpu,
|
||||||
return sysreg_visibility(vcpu, r) & REG_HIDDEN;
|
return sysreg_visibility(vcpu, r) & REG_HIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool sysreg_hidden_user(const struct kvm_vcpu *vcpu,
|
||||||
|
const struct sys_reg_desc *r)
|
||||||
|
{
|
||||||
|
if (likely(!r->visibility))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return r->visibility(vcpu, r) & (REG_HIDDEN | REG_HIDDEN_USER);
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool sysreg_visible_as_raz(const struct kvm_vcpu *vcpu,
|
static inline bool sysreg_visible_as_raz(const struct kvm_vcpu *vcpu,
|
||||||
const struct sys_reg_desc *r)
|
const struct sys_reg_desc *r)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue