• Dave Martin's avatar
    KVM: arm64/sve: Make register ioctl access errors more consistent · 52110aa9
    Dave Martin authored
    Currently, the way error codes are generated when processing the
    SVE register access ioctls in a bit haphazard.
    
    This patch refactors the code so that the behaviour is more
    consistent: now, -EINVAL should be returned only for unrecognised
    register IDs or when some other runtime error occurs.  -ENOENT is
    returned for register IDs that are recognised, but whose
    corresponding register (or slice) does not exist for the vcpu.
    
    To this end, in {get,set}_sve_reg() we now delegate the
    vcpu_has_sve() check down into {get,set}_sve_vls() and
    sve_reg_to_region().  The KVM_REG_ARM64_SVE_VLS special case is
    picked off first, then sve_reg_to_region() plays the role of
    exhaustively validating or rejecting the register ID and (where
    accepted) computing the applicable register region as before.
    
    sve_reg_to_region() is rearranged so that -ENOENT or -EPERM is not
    returned prematurely, before checking whether reg->id is in a
    recognised range.
    
    -EPERM is now only returned when an attempt is made to access an
    actually existing register slice on an unfinalized vcpu.
    
    Fixes: e1c9c983 ("KVM: arm64/sve: Add SVE support to register access ioctl interface")
    Fixes: 9033bba4 ("KVM: arm64/sve: Add pseudo-register for the guest's vector lengths")
    Suggested-by: default avatarAndrew Jones <drjones@redhat.com>
    Signed-off-by: default avatarDave Martin <Dave.Martin@arm.com>
    Reviewed-by: default avatarAndrew Jones <drjones@redhat.com>
    Signed-off-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
    52110aa9
guest.c 21.6 KB