We detect the absence of FP/SIMD after we boot the SMP CPUs, and by then we have kernel threads running already with TIF_FOREIGN_FPSTATE set which could be inherited by early userspace applications (e.g, modprobe triggered from initramfs). This could end up in the applications stuck 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). Fixes: 82e0191a1aa11abf ("arm64: Support systems without FP/ASIMD") Cc: Will Deacon <w...@kernel.org> Cc: Mark Rutland <mark.rutl...@arm.com> Cc: Catalin Marinas <catalin.mari...@arm.com> Signed-off-by: Suzuki K Poulose <suzuki.poul...@arm.com> --- arch/arm64/kernel/fpsimd.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 37d3912cfe06..dfcdd077aeca 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1128,12 +1128,19 @@ void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *st, void *sve_state, */ void fpsimd_restore_current_state(void) { - if (!system_supports_fpsimd()) - return; - get_cpu_fpsimd_context(); - - if (test_and_clear_thread_flag(TIF_FOREIGN_FPSTATE)) { + /* + * For the tasks that were created before we detected the absence of + * FP/SIMD, the TIF_FOREIGN_FPSTATE could be set via fpsimd_thread_switch() + * and/or could be inherited from the parent(init_task has this set). Even + * though userspace has not run yet, this could be inherited by the + * processes forked from one of those tasks (e.g, modprobe from initramfs). + * If the system doesn't support FP/SIMD, we must clear the flag for the + * tasks mentioned above, to indicate that the FPSTATE is clean (as we + * can't have one) to avoid looping for ever to clear the flag. + */ + if (test_and_clear_thread_flag(TIF_FOREIGN_FPSTATE) && + system_supports_fpsimd()) { task_fpsimd_load(); fpsimd_bind_task_to_cpu(); } @@ -1148,17 +1155,16 @@ void fpsimd_restore_current_state(void) */ void fpsimd_update_current_state(struct user_fpsimd_state const *state) { - if (!system_supports_fpsimd()) - return; - get_cpu_fpsimd_context(); current->thread.uw.fpsimd_state = *state; if (system_supports_sve() && test_thread_flag(TIF_SVE)) fpsimd_to_sve(current); - task_fpsimd_load(); - fpsimd_bind_task_to_cpu(); + if (system_supports_fpsimd()) { + task_fpsimd_load(); + fpsimd_bind_task_to_cpu(); + } clear_thread_flag(TIF_FOREIGN_FPSTATE); -- 2.21.0