[PATCH 3/4] KVM: arm64: show writable masks for feature registers
Sebastian Ott
sebott at redhat.com
Mon Mar 18 11:20:06 PDT 2024
On Mon, 18 Mar 2024, Marc Zyngier wrote:
> On Mon, 18 Mar 2024 11:16:35 +0000,
> Sebastian Ott <sebott at redhat.com> wrote:
>>
>> Instead of using ~0UL provide the actual writable mask for
>> non-id feature registers in the output of the
>> KVM_ARM_GET_REG_WRITABLE_MASKS ioctl.
>
> CTR_EL0 definitely seems to be in the feature ID range. And so does
> CLIDR_EL1.
Sry, bad wording. I mean feature id regs for which is_id_reg() is false.
>>
>> This changes the mask for the CTR_EL0 register.
>
> Only that?
Yes.
>> Signed-off-by: Sebastian Ott <sebott at redhat.com>
>> ---
>> arch/arm64/kvm/sys_regs.c | 21 ++++++---------------
>> 1 file changed, 6 insertions(+), 15 deletions(-)
>>
>> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
>> index b2019faa9d73..0f8fe7790c35 100644
>> --- a/arch/arm64/kvm/sys_regs.c
>> +++ b/arch/arm64/kvm/sys_regs.c
>> @@ -2489,12 +2489,12 @@ static const struct sys_reg_desc sys_reg_descs[] = {
>>
>> { SYS_DESC(SYS_CCSIDR_EL1), access_ccsidr },
>> { SYS_DESC(SYS_CLIDR_EL1), access_clidr, reset_clidr, CLIDR_EL1,
>> - .set_user = set_clidr },
>> + .set_user = set_clidr, .val = ~0UL },
>
> How is CLIDR_EL1 (and all the crap that depend on it) recomputed when
> CTR_EL0 is changed?
Do we have means to handle dependencies here? There is no natural order
in which userspace is writing to these regs. Nor a good time or a trigger
when the kernel should do a sanity/dependency check..
>
>> { SYS_DESC(SYS_CCSIDR2_EL1), undef_access },
>> { SYS_DESC(SYS_SMIDR_EL1), undef_access },
>> { SYS_DESC(SYS_CSSELR_EL1), access_csselr, reset_unknown, CSSELR_EL1 },
>> { SYS_DESC(SYS_CTR_EL0), access_ctr, .reset = reset_ctr,
>> - .get_user = get_ctr, .set_user = set_ctr},
>> + .get_user = get_ctr, .set_user = set_ctr, .val = CTR_EL0_DIC_MASK},
>
> This is all extremely fragile. We need a better solution for this. And
> we need far more than just DIC here.
>
>> { SYS_DESC(SYS_SVCR), undef_access },
>>
>> { PMU_SYS_REG(PMCR_EL0), .access = access_pmcr, .reset = reset_pmcr,
>> @@ -3934,20 +3934,11 @@ int kvm_vm_ioctl_get_reg_writable_masks(struct kvm *kvm, struct reg_mask_range *
>> if (!is_feature_id_reg(encoding) || !reg->set_user)
>> continue;
>>
>> - /*
>> - * For ID registers, we return the writable mask. Other feature
>> - * registers return a full 64bit mask. That's not necessary
>> - * compliant with a given revision of the architecture, but the
>> - * RES0/RES1 definitions allow us to do that.
>> - */
>> - if (is_id_reg(encoding)) {
>> - if (!reg->val ||
>> - (is_aa32_id_reg(encoding) && !kvm_supports_32bit_el0()))
>> - continue;
>> - val = reg->val;
>> - } else {
>> - val = ~0UL;
>> + if (!reg->val ||
>> + (is_aa32_id_reg(encoding) && !kvm_supports_32bit_el0())) {
>> + continue;
>> }
>> + val = reg->val;
>
> Are CLIDR_EL1 and CTR_EL0 the only two ID registers that had a
> set_user callback without an encoded mask?
These 2 are the only regs affected by this patch - meaning
!is_id_reg() && reg->set_user && !reg->val
More information about the linux-arm-kernel
mailing list