• Reiji Watanabe's avatar
    KVM: arm64: mixed-width check should be skipped for uninitialized vCPUs · 26bf74bd
    Reiji Watanabe authored
    KVM allows userspace to configure either all EL1 32bit or 64bit vCPUs
    for a guest.  At vCPU reset, vcpu_allowed_register_width() checks
    if the vcpu's register width is consistent with all other vCPUs'.
    Since the checking is done even against vCPUs that are not initialized
    (KVM_ARM_VCPU_INIT has not been done) yet, the uninitialized vCPUs
    are erroneously treated as 64bit vCPU, which causes the function to
    incorrectly detect a mixed-width VM.
    
    Introduce KVM_ARCH_FLAG_EL1_32BIT and KVM_ARCH_FLAG_REG_WIDTH_CONFIGURED
    bits for kvm->arch.flags.  A value of the EL1_32BIT bit indicates that
    the guest needs to be configured with all 32bit or 64bit vCPUs, and
    a value of the REG_WIDTH_CONFIGURED bit indicates if a value of the
    EL1_32BIT bit is valid (already set up). Values in those bits are set at
    the first KVM_ARM_VCPU_INIT for the guest based on KVM_ARM_VCPU_EL1_32BIT
    configuration for the vCPU.
    
    Check vcpu's register width against those new bits at the vcpu's
    KVM_ARM_VCPU_INIT (instead of against other vCPUs' register width).
    
    Fixes: 66e94d5c ("KVM: arm64: Prevent mixed-width VM creation")
    Signed-off-by: default avatarReiji Watanabe <reijiw@google.com>
    Reviewed-by: default avatarOliver Upton <oupton@google.com>
    Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
    Link: https://lore.kernel.org/r/20220329031924.619453-2-reijiw@google.com
    26bf74bd
kvm_emulate.h 12 KB