On Thu, 10 Feb 2022 05:31:49 +0000, Reiji Watanabe <reijiw@xxxxxxxxxx> wrote: > > Hi Marc, > > On Wed, Feb 9, 2022 at 4:04 AM Marc Zyngier <maz@xxxxxxxxxx> wrote: > > > > Hi Reiji, > > > > On Wed, 09 Feb 2022 05:32:36 +0000, > > Reiji Watanabe <reijiw@xxxxxxxxxx> wrote: > > > > > > Hi Marc, > > > > > > On Tue, Feb 8, 2022 at 6:41 AM Marc Zyngier <maz@xxxxxxxxxx> wrote: > > > > > > > > In [1], I suggested another approach that didn't require extra state, > > > > and moved the existing checks under the kvm lock. What was wrong with > > > > that approach? > > > > > > With that approach, even for a vcpu that has a broken set of features, > > > which leads kvm_reset_vcpu() to fail for the vcpu, the vcpu->arch.features > > > are checked by other vCPUs' vcpu_allowed_register_width() until the > > > vcpu->arch.target is set to -1. > > > Due to this, I would think some or possibly all vCPUs' kvm_reset_vcpu() > > > may or may not fail (e.g. if userspace tries to configure vCPU#0 with > > > 32bit EL1, and vCPU#1 and #2 with 64 bit EL1, KVM_ARM_VCPU_INIT > > > for either vCPU#0, or both vCPU#1 and #2 should fail. But, with that > > > approach, it doesn't always work that way. Instead, KVM_ARM_VCPU_INIT > > > for all vCPUs could fail or KVM_ARM_VCPU_INIT for vCPU#0 and #1 could > > > fail while the one for CPU#2 works). > > > Also, even after the first KVM_RUN for vCPUs are already done, > > > (the first) KVM_ARM_VCPU_INIT for another vCPU could cause the > > > kvm_reset_vcpu() for those vCPUs to fail. > > > > > > I would think those behaviors are odd, and I wanted to avoid them. > > > > OK, fair enough. But then you need to remove most of the uses of > > KVM_ARM_VCPU_EL1_32BIT so that it is only used as a userspace > > interface and > > Yes, I will. > > > maybe not carried as part of the vcpu feature flag anymore. > > At the first call of kvm_reset_vcpu() for the guest, the new kvm > flag is not set yet. So, KVM_ARM_VCPU_EL1_32BIT will be needed > by the function (unless we pass the flag as an argument for the > function or by any other way). Which is why I said 'maybe'. It's not a big deal if the flags stays, but I don't want it evaluated further down the line. It is also pretty similar to HCR_EL2.RW, which we already test with vcpu_el1_is_32bit(). Overall, we need to reduce that state to be as simple as possible. > > > Also, we really should turn all these various bits in the kvm struct > > into a set of flags. I have a patch posted there[1] for this, feel > > free to pick it up. > > Thank you for the suggestion. But, kvm->arch.el1_reg_width is not > a binary because it needs to indicate an uninitialized state. So, it > won't fit perfectly with kvm->arch.flags, which is introduced by [1] > as it is. Of course it's feasible by using 2 bits of the flags though... 2 bits is what I had in mind (one bit to indicate that it has already been initialised, another to carry the actual width). Thanks, M. -- Without deviation from the norm, progress is not possible.