On Tue, Feb 11, 2025 at 03:39:07PM +0100, Sebastian Ott wrote:
+static int set_id_reg_non_ftr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
+ u64 val)
+{
+ u32 id = reg_to_encoding(rd);
+ int ret;
+
+ mutex_lock(&vcpu->kvm->arch.config_lock);
There's quite a few early outs, guard() might be a better fit than
explicitly dropping the lock.
+ /*
+ * Since guest access to MIDR_EL1 is not trapped
+ * set up VPIDR_EL2 to hold the MIDR_EL1 value.
+ */
+ if (id == SYS_MIDR_EL1)
+ write_sysreg(val, vpidr_el2);
This is problematic for a couple reasons:
- If the kernel isn't running at EL2, VPIDR_EL2 is undefined
- VPIDR_EL2 needs to be handled as part of the vCPU context, not
written to without a running vCPU. What would happen if two vCPUs
have different MIDR values?
Here's a new diff with some hacks thrown in to handle VPIDR_EL2
correctly. Very lightly tested :)