KVM: arm64: nv: Allow a sysreg to be hidden from userspace only
authorMarc Zyngier <maz@kernel.org>
Thu, 9 Feb 2023 17:58:17 +0000 (17:58 +0000)
committerOliver Upton <oliver.upton@linux.dev>
Sat, 11 Feb 2023 10:13:29 +0000 (10:13 +0000)
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>
arch/arm64/kvm/sys_regs.c
arch/arm64/kvm/sys_regs.h

index de209059fd34da9743471f0b87b0a06357b37587..55a14c86a4554b9aa762ac7ecbbc62c52084ba78 100644 (file)
@@ -2980,7 +2980,7 @@ int kvm_sys_reg_get_user(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg,
        int ret;
 
        r = id_to_sys_reg_desc(vcpu, reg->id, table, num);
-       if (!r)
+       if (!r || sysreg_hidden_user(vcpu, r))
                return -ENOENT;
 
        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;
 
        r = id_to_sys_reg_desc(vcpu, reg->id, table, num);
-       if (!r)
+       if (!r || sysreg_hidden_user(vcpu, r))
                return -ENOENT;
 
        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))
                return 0;
 
-       if (sysreg_hidden(vcpu, rd))
+       if (sysreg_hidden_user(vcpu, rd))
                return 0;
 
        if (!copy_reg_to_user(rd, uind))
index e4ebb3a379fdb95e1d4fcc45e8e7d3221f0cf64d..6b11f2cc71467281620dc9b5d6bae2151b340cda 100644 (file)
@@ -85,8 +85,9 @@ struct sys_reg_desc {
 };
 
 #define REG_HIDDEN             (1 << 0) /* hidden from userspace and guest */
-#define REG_RAZ                        (1 << 1) /* RAZ from userspace and guest */
-#define REG_USER_WI            (1 << 2) /* WI from userspace only */
+#define REG_HIDDEN_USER                (1 << 1) /* hidden 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)
 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;
 }
 
+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,
                                         const struct sys_reg_desc *r)
 {