virt inclusion category: feature bugzilla: https://gitcode.com/openeuler/kernel/issues/10066 ---------------------------------------- The enum sys_reg member TLBIDIDR_EL1 exists only to back the sys_reg_desc table entry. The guest-visible value is a VM-wide constant synthesized from the hardware TLBIDIDR (the NIS/NOS fields carry the virtual domain counts NVIS/NVOS), so cache it in struct tlbidomain at VM init and let access_tlbididr() read it directly. Removing the enum member leaves NR_SYS_REGS, and therefore the layout of struct kvm_vcpu_arch, unchanged, eliminating the need for KABI_EXTEND_ENUM. As a side effect TLBIDIDR_EL1 is no longer listed by KVM_GET_REG_LIST nor directly readable via KVM_GET_ONE_REG; userspace observes the synthesized value through the guest trap path, which is the intended interface. Signed-off-by: Jinqian Yang <yangjinqian1@huawei.com> --- arch/arm64/include/asm/kvm_host.h | 5 ++--- arch/arm64/kvm/arm.c | 7 +++++++ arch/arm64/kvm/sys_regs.c | 20 ++------------------ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index d96c41719732..29a47406714c 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -244,6 +244,8 @@ struct tlbidomain { u8 nvis; /* TLBIDIDR.NIS */ u8 nis; + /* Guest-visible TLBIDIDR value (NIS/NOS carry virtual domain counts) */ + u64 tlbididr_val; /* Used to prevent concurrent modifications to the domain mapping. */ spinlock_t tlbid_lock; /* Per-pCPU list of vCPUs whose last_pcpu equals this pCPU */ @@ -512,9 +514,6 @@ enum vcpu_sysreg { CNTHV_CTL_EL2, CNTHV_CVAL_EL2, - /* TLBI Domains Identification Register (EL1) */ - KABI_EXTEND_ENUM(TLBIDIDR_EL1) - NR_SYS_REGS /* Nothing after this line! */ }; diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 16202f89ae6d..b40c4548c7f1 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -336,6 +336,13 @@ static int kvm_arm_init_tlbidomain(struct kvm *kvm) vdomain->nvis = FIELD_GET(TLBIDIDR_EL1_NVIS_MASK, tlbididr); vdomain->num_domains = -1; vdomain->kvm_tlbid_enabled = true; + /* + * Guest-visible TLBIDIDR: the NIS/NOS fields carry the virtual + * domain counts (NVIS/NVOS), since the guest uses vDomains. + */ + vdomain->tlbididr_val = FIELD_PREP(TLBIDIDR_EL1_NIS_MASK, vdomain->nvis) | + FIELD_PREP(TLBIDIDR_EL1_NOS_MASK, + FIELD_GET(TLBIDIDR_EL1_NVOS_MASK, tlbididr)); max_vdomains = 1 << vdomain->nvis; kvm_info("TLBIDIDR: 0x%llx, NIS: %d, NVIS: %d\n", tlbididr, vdomain->nis, vdomain->nvis); diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 82b5b33b1760..1ef578caa7c0 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -283,7 +283,7 @@ static bool access_tlbididr(struct kvm_vcpu *vcpu, if (p->is_write) return ignore_write(vcpu, p); - p->regval = vcpu_read_sys_reg(vcpu, r->reg); + p->regval = vcpu->kvm->arch.vdomain.tlbididr_val; return true; } @@ -726,22 +726,6 @@ static u64 reset_amair_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) return amair; } -static u64 reset_tlbididr_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) -{ - if (!system_supports_tlbid()) - return 0; - - u64 tlbididr = read_sysreg_s(SYS_TLBIDIDR_EL1); - u64 nvis = FIELD_GET(TLBIDIDR_EL1_NVIS_MASK, tlbididr); - u64 nvos = FIELD_GET(TLBIDIDR_EL1_NVOS_MASK, tlbididr); - - tlbididr = FIELD_PREP(TLBIDIDR_EL1_NIS_MASK, nvis); - tlbididr |= FIELD_PREP(TLBIDIDR_EL1_NOS_MASK, nvos); - - vcpu_write_sys_reg(vcpu, tlbididr, TLBIDIDR_EL1); - return tlbididr; -} - static u64 reset_actlr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) { u64 actlr = read_sysreg(actlr_el1); @@ -2664,7 +2648,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SYS_DESC(SYS_LORN_EL1), trap_loregion }, { SYS_DESC(SYS_LORC_EL1), trap_loregion }, { SYS_DESC(SYS_MPAMIDR_EL1), workaround_bad_mpam_abi }, - { SYS_DESC(SYS_TLBIDIDR_EL1), access_tlbididr, reset_tlbididr_el1, TLBIDIDR_EL1 }, + { SYS_DESC(SYS_TLBIDIDR_EL1), access_tlbididr }, { SYS_DESC(SYS_LORID_EL1), trap_loregion }, { SYS_DESC(SYS_MPAM1_EL1), workaround_bad_mpam_abi }, -- 2.33.0