Re: [PATCH v13 45/48] arm64: RMI: Provide accurate register list

Steven Price
2026-03-20T16:45:50Z

On 19/03/2026 18:53, Wei-Lin Chang wrote:
> On Wed, Mar 18, 2026 at 03:54:09PM +0000, Steven Price wrote:
>> From: Jean-Philippe Brucker <jean-philippe@linaro.org>
>>
>> Userspace can set a few registers with KVM_SET_ONE_REG (9 GP registers
>> at runtime, and 3 system registers during initialization). Update the
>> register list returned by KVM_GET_REG_LIST.
>>
>> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
>> Signed-off-by: Steven Price <steven.price@arm.com>
>> ---
>> Changes since v11:
>> * Reworked due to upstream changes.
>> Changes since v8:
>> * Minor type changes following review.
>> Changes since v7:
>> * Reworked on upstream changes.
>> ---
>> arch/arm64/kvm/guest.c | 6 ++++++
>> arch/arm64/kvm/hypercalls.c | 4 ++--
>> arch/arm64/kvm/sys_regs.c | 29 +++++++++++++++++++++++------
>> 3 files changed, 31 insertions(+), 8 deletions(-)
>>
>> diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
>> index 2c4db2d1a6ca..23fdb2ee8a61 100644
>> --- a/arch/arm64/kvm/guest.c
>> +++ b/arch/arm64/kvm/guest.c
>> @@ -620,6 +620,9 @@ static unsigned long num_sve_regs(const struct kvm_vcpu *vcpu)
>> if (!kvm_arm_vcpu_sve_finalized(vcpu))
>> return 1; /* KVM_REG_ARM64_SVE_VLS */
>>
>> + if (kvm_is_realm(vcpu->kvm))
>> + return 1; /* KVM_REG_ARM64_SVE_VLS */
>> +
>> return slices * (SVE_NUM_PREGS + SVE_NUM_ZREGS + 1 /* FFR */)
>> + 1; /* KVM_REG_ARM64_SVE_VLS */
>> }
>> @@ -647,6 +650,9 @@ static int copy_sve_reg_indices(const struct kvm_vcpu *vcpu,
>> if (!kvm_arm_vcpu_sve_finalized(vcpu))
>> return num_regs;
>>
>> + if (kvm_is_realm(vcpu->kvm))
>> + return num_regs;
>> +
>> for (i = 0; i < slices; i++) {
>> for (n = 0; n < SVE_NUM_ZREGS; n++) {
>> reg = KVM_REG_ARM64_SVE_ZREG(n, i);
>> diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c
>> index 58c5fe7d7572..70ac7971416c 100644
>> --- a/arch/arm64/kvm/hypercalls.c
>> +++ b/arch/arm64/kvm/hypercalls.c
>> @@ -414,14 +414,14 @@ void kvm_arm_teardown_hypercalls(struct kvm *kvm)
>>
>> int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu)
>> {
>> - return ARRAY_SIZE(kvm_arm_fw_reg_ids);
>> + return kvm_is_realm(vcpu->kvm) ? 0 : ARRAY_SIZE(kvm_arm_fw_reg_ids);
>> }
>>
>> int kvm_arm_copy_fw_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices)
>> {
>> int i;
>>
>> - for (i = 0; i < ARRAY_SIZE(kvm_arm_fw_reg_ids); i++) {
>> + for (i = 0; i < kvm_arm_get_fw_num_regs(vcpu); i++) {
>> if (put_user(kvm_arm_fw_reg_ids[i], uindices++))
>> return -EFAULT;
>> }
>> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
>> index ebb428b861f5..088d900b9c3a 100644
>> --- a/arch/arm64/kvm/sys_regs.c
>> +++ b/arch/arm64/kvm/sys_regs.c
>> @@ -5436,18 +5436,18 @@ int kvm_arm_sys_reg_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg
>> sys_reg_descs, ARRAY_SIZE(sys_reg_descs));
>> }
>>
>> -static unsigned int num_demux_regs(void)
>> +static inline unsigned int num_demux_regs(struct kvm_vcpu *vcpu)
>> {
>> - return CSSELR_MAX;
>> + return kvm_is_realm(vcpu->kvm) ? 0 : CSSELR_MAX;
>> }
>>
>> -static int write_demux_regids(u64 __user *uindices)
>> +static int write_demux_regids(struct kvm_vcpu *vcpu, u64 __user *uindices)
>> {
>> u64 val = KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_DEMUX;
>> unsigned int i;
>>
>> val |= KVM_REG_ARM_DEMUX_ID_CCSIDR;
>> - for (i = 0; i < CSSELR_MAX; i++) {
>> + for (i = 0; i < num_demux_regs(vcpu); i++) {
>> if (put_user(val | i, uindices))
>> return -EFAULT;
>> uindices++;
>> @@ -5491,11 +5491,28 @@ static bool copy_reg_to_user(const struct sys_reg_desc *reg, u64 __user **uind)
>> return true;
>> }
>>
>> +static inline bool kvm_realm_sys_reg_hidden_user(const struct kvm_vcpu *vcpu,
>> + u64 reg)
>> +{
>> + if (!kvm_is_realm(vcpu->kvm))
>> + return false;
>> +
>> + switch (reg) {
>> + case SYS_ID_AA64DFR0_EL1:
>> + case SYS_PMCR_EL0:
>> + return false;
>> + }
>> + return true;
>> +}
>> +
>> static int walk_one_sys_reg(const struct kvm_vcpu *vcpu,
>> const struct sys_reg_desc *rd,
>> u64 __user **uind,
>> unsigned int *total)
>> {
>> + if (kvm_realm_sys_reg_hidden_user(vcpu, reg_to_encoding(rd)))
>
> Hi,
>
> Same as my comment for patch 39, I would suggest moving the
> kvm_is_realm() check out of this function.

Sure, although at least this time the functions were right next to each
other ;)

Thanks,
Steve

> Thanks,
> Wei-Lin Chang
>
>> + return 0;
>> +
>> /*
>> * Ignore registers we trap but don't save,
>> * and for which no custom user accessor is provided.
>> @@ -5533,7 +5550,7 @@ static int walk_sys_regs(struct kvm_vcpu *vcpu, u64 __user *uind)
>>
>> unsigned long kvm_arm_num_sys_reg_descs(struct kvm_vcpu *vcpu)
>> {
>> - return num_demux_regs()
>> + return num_demux_regs(vcpu)
>> + walk_sys_regs(vcpu, (u64 __user *)NULL);
>> }
>>
>> @@ -5546,7 +5563,7 @@ int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices)
>> return err;
>> uindices += err;
>>
>> - return write_demux_regids(uindices);
>> + return write_demux_regids(vcpu, uindices);
>> }
>>
>> #define KVM_ARM_FEATURE_ID_RANGE_INDEX(r) \
>> --
>> 2.43.0
>>