• Mark Brown's avatar
    KVM: arm64: Clarify host SME state management · aaa2f14e
    Mark Brown authored
    Normally when running a guest we do not touch the floating point
    register state until first use of floating point by the guest, saving
    the current state and loading the guest state at that point. This has
    been found to offer a performance benefit in common cases. However
    currently if SME is active when switching to a guest then we exit
    streaming mode, disable ZA and invalidate the floating point register
    state prior to starting the guest.
    
    The exit from streaming mode is required for correct guest operation, if
    we leave streaming mode enabled then many non-SME operations can
    generate SME traps (eg, SVE operations will become streaming SVE
    operations). If EL1 leaves CPACR_EL1.SMEN disabled then the host is
    unable to intercept these traps. This will mean that a SME unaware guest
    will see SME exceptions which will confuse it. Disabling streaming mode
    also avoids creating spurious indications of usage of the SME hardware
    which could impact system performance, especially with shared SME
    implementations. Document the requirement to exit streaming mode
    clearly.
    
    There is no issue with guest operation caused by PSTATE.ZA so we can
    defer handling for that until first floating point usage, do so if the
    register state is not that of the current task and hence has already
    been saved. We could also do this for the case where the register state
    is that for the current task however this is very unlikely to happen and
    would require disproportionate effort so continue to save the state in
    that case.
    
    Saving this state on first use would require that we map and unmap
    storage for the host version of these registers for use by the
    hypervisor, taking care to deal with protected KVM and the fact that the
    host can free or reallocate the backing storage. Given that the strong
    recommendation is that applications should only keep PSTATE.ZA enabled
    when the state it enables is in active use it is difficult to see a case
    where a VMM would wish to do this, it would need to not only be using
    SME but also running the guest in the middle of SME usage. This can be
    revisited in the future if a use case does arises, in the interim such
    tasks will work but experience a performance overhead.
    
    This brings our handling of SME more into line with our handling of
    other floating point state and documents more clearly the constraints we
    have, especially around streaming mode.
    Signed-off-by: default avatarMark Brown <broonie@kernel.org>
    Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
    Link: https://lore.kernel.org/r/20221214-kvm-arm64-sme-context-switch-v2-3-57ba0082e9ff@kernel.org
    aaa2f14e
fpsimd.c 6.5 KB