1
0
Fork 0
alistair23-linux/arch/arm64/kvm
Suzuki K Poulose 7df80a021f arm64: nofpsmid: Handle TIF_FOREIGN_FPSTATE flag cleanly
commit 52f73c383b upstream.

We detect the absence of FP/SIMD after an incapable CPU is brought up,
and by then we have kernel threads running already with TIF_FOREIGN_FPSTATE set
which could be set for early userspace applications (e.g, modprobe triggered
from initramfs) and init. This could cause the applications to loop forever in
do_nofity_resume() as we never clear the TIF flag, once we now know that
we don't support FP.

Fix this by making sure that we clear the TIF_FOREIGN_FPSTATE flag
for tasks which may have them set, as we would have done in the normal
case, but avoiding touching the hardware state (since we don't support any).

Also to make sure we handle the cases seemlessly we categorise the
helper functions to two :
 1) Helpers for common core code, which calls into take appropriate
    actions without knowing the current FPSIMD state of the CPU/task.

    e.g fpsimd_restore_current_state(), fpsimd_flush_task_state(),
        fpsimd_save_and_flush_cpu_state().

    We bail out early for these functions, taking any appropriate actions
    (e.g, clearing the TIF flag) where necessary to hide the handling
    from core code.

 2) Helpers used when the presence of FP/SIMD is apparent.
    i.e, save/restore the FP/SIMD register state, modify the CPU/task
    FP/SIMD state.
    e.g,

    fpsimd_save(), task_fpsimd_load() - save/restore task FP/SIMD registers

    fpsimd_bind_task_to_cpu()  \
                                - Update the "state" metadata for CPU/task.
    fpsimd_bind_state_to_cpu() /

    fpsimd_update_current_state() - Update the fp/simd state for the current
                                    task from memory.

    These must not be called in the absence of FP/SIMD. Put in a WARNING
    to make sure they are not invoked in the absence of FP/SIMD.

KVM also uses the TIF_FOREIGN_FPSTATE flag to manage the FP/SIMD state
on the CPU. However, without FP/SIMD support we trap all accesses and
inject undefined instruction. Thus we should never "load" guest state.
Add a sanity check to make sure this is valid.

Fixes: 82e0191a1a ("arm64: Support systems without FP/ASIMD")
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-02-14 16:34:18 -05:00
..
hyp arm64: nofpsmid: Handle TIF_FOREIGN_FPSTATE flag cleanly 2020-02-14 16:34:18 -05:00
Kconfig Make anon_inodes unconditional 2019-04-19 14:03:11 +02:00
Makefile arm64: KVM: Add accessors to track guest/host only counters 2019-04-24 15:35:30 +01:00
debug.c KVM: arm64: Write arch.mdcr_el2 changes since last vcpu_load on VHE 2020-02-01 09:34:52 +00:00
fpsimd.c arm64/fpsimd: Introduce fpsimd_save_and_flush_cpu_state() and use it 2019-06-04 13:17:30 +01:00
guest.c KVM: arm64/sve: Fix vq_present() macro to yield a bool 2019-07-05 12:07:51 +02:00
handle_exit.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
hyp-init.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
hyp.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
inject_fault.c KVM: arm64: Correct PSTATE on exception entry 2020-02-11 04:35:16 -08:00
irq.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 422 2019-06-05 17:37:15 +02:00
pmu.c KVM: arm64: Move pmu hyp code under hyp's Makefile to avoid instrumentation 2019-05-24 14:53:20 +01:00
regmap.c arm64: KVM: regmap: Fix unexpected switch fall-through 2019-07-26 15:33:41 +01:00
reset.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
sys_regs.c KVM: arm64: Ensure 'params' is initialised when looking up sys register 2019-12-31 16:46:24 +01:00
sys_regs.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
sys_regs_generic_v8.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
trace.h arm64: KVM: Add trapped system register access tracepoint 2018-12-19 17:47:08 +00:00
va_layout.c arm64: mm: Introduce vabits_actual 2019-08-09 11:17:21 +01:00
vgic-sys-reg-v3.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00