Skip to content

Commit 6db7af0

Browse files
committed
KVM: arm64: Handle ID register reads using the VM-wide values
Everything is in place now to use the generic ID register infrastructure. Use the VM-wide values to service ID register reads. The ID registers are invariant after the VM has started, so there is no need for locking in that case. This is rather desirable for VM live migration, as the needless lock contention could prolong the VM blackout period. Link: https://lore.kernel.org/r/20230609190054.1542113-11-oliver.upton@linux.dev Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent c39f597 commit 6db7af0

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

arch/arm64/kvm/sys_regs.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ static u64 kvm_read_sanitised_id_reg(struct kvm_vcpu *vcpu,
13951395

13961396
static u64 read_id_reg(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
13971397
{
1398-
return __kvm_read_sanitised_id_reg(vcpu, r);
1398+
return IDREG(vcpu->kvm, reg_to_encoding(r));
13991399
}
14001400

14011401
/*
@@ -1634,7 +1634,19 @@ static int set_id_dfr0_el1(struct kvm_vcpu *vcpu,
16341634
static int get_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
16351635
u64 *val)
16361636
{
1637+
/*
1638+
* Avoid locking if the VM has already started, as the ID registers are
1639+
* guaranteed to be invariant at that point.
1640+
*/
1641+
if (kvm_vm_has_ran_once(vcpu->kvm)) {
1642+
*val = read_id_reg(vcpu, rd);
1643+
return 0;
1644+
}
1645+
1646+
mutex_lock(&vcpu->kvm->arch.config_lock);
16371647
*val = read_id_reg(vcpu, rd);
1648+
mutex_unlock(&vcpu->kvm->arch.config_lock);
1649+
16381650
return 0;
16391651
}
16401652

0 commit comments

Comments
 (0)