• Dave Martin's avatar
    KVM: arm64/sve: Fix SVE trap restoration for non-current tasks · b3eb56b6
    Dave Martin authored
    Commit e6b673b7 ("KVM: arm64: Optimise FPSIMD handling to reduce
    guest/host thrashing") attempts to restore the configuration of
    userspace SVE trapping via a call to fpsimd_bind_task_to_cpu(), but
    the logic for determining when to do this is not correct.
    
    The patch makes the errnoenous assumption that the only task that
    may try to enter userspace with the currently loaded FPSIMD/SVE
    register content is current.  This may not be the case however:  if
    some other user task T is scheduled on the CPU during the execution
    of the KVM run loop, and the vcpu does not try to use the registers
    in the meantime, then T's state may be left there intact.  If T
    happens to be the next task to enter userspace on this CPU then the
    hooks for reloading the register state and configuring traps will
    be skipped.
    
    (Also, current never has SVE state at this point anyway and should
    always have the trap enabled, as a side-effect of the ioctl()
    syscall needed to reach the KVM run loop in the first place.)
    
    This patch instead restores the state of the EL0 trap from the
    state observed at the most recent vcpu_load(), ensuring that the
    trap is set correctly for the loaded context (if any).
    
    Fixes: e6b673b7 ("KVM: arm64: Optimise FPSIMD handling to reduce guest/host thrashing")
    Signed-off-by: default avatarDave Martin <Dave.Martin@arm.com>
    Signed-off-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
    b3eb56b6
kvm_host.h 16.7 KB