From: Suzuki K Poulose <suzuki.poulose@arm.com> To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, will@kernel.org, mark.rutland@arm.com, catalin.marinas@arm.com, dave.martin@arm.com, Suzuki K Poulose <suzuki.poulose@arm.com> Subject: [PATCH 2/3] arm64: nofpsmid: Clear TIF_FOREIGN_FPSTATE flag for early tasks Date: Thu, 10 Oct 2019 18:15:16 +0100 [thread overview] Message-ID: <20191010171517.28782-3-suzuki.poulose@arm.com> (raw) In-Reply-To: <20191010171517.28782-1-suzuki.poulose@arm.com> 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 <will@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Suzuki K Poulose <suzuki.poulose@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
WARNING: multiple messages have this Message-ID (diff)
From: Suzuki K Poulose <suzuki.poulose@arm.com> To: linux-arm-kernel@lists.infradead.org Cc: mark.rutland@arm.com, Suzuki K Poulose <suzuki.poulose@arm.com>, catalin.marinas@arm.com, linux-kernel@vger.kernel.org, will@kernel.org, dave.martin@arm.com Subject: [PATCH 2/3] arm64: nofpsmid: Clear TIF_FOREIGN_FPSTATE flag for early tasks Date: Thu, 10 Oct 2019 18:15:16 +0100 [thread overview] Message-ID: <20191010171517.28782-3-suzuki.poulose@arm.com> (raw) In-Reply-To: <20191010171517.28782-1-suzuki.poulose@arm.com> 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 <will@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Suzuki K Poulose <suzuki.poulose@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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-10-10 17:15 UTC|newest] Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-10-10 17:15 [PATCH 0/3] arm64: Fix support for systems without FP/SIMD Suzuki K Poulose 2019-10-10 17:15 ` Suzuki K Poulose 2019-10-10 17:15 ` [PATCH 1/3] arm64: cpufeature: Fix the type of no FP/SIMD capability Suzuki K Poulose 2019-10-10 17:15 ` Suzuki K Poulose 2019-10-11 11:36 ` Dave Martin 2019-10-11 11:36 ` Dave Martin 2019-10-11 12:13 ` Suzuki K Poulose 2019-10-11 12:13 ` Suzuki K Poulose 2019-10-11 14:21 ` Dave Martin 2019-10-11 14:21 ` Dave Martin 2019-10-11 17:28 ` Suzuki K Poulose 2019-10-11 17:28 ` Suzuki K Poulose 2019-10-14 14:52 ` Dave Martin 2019-10-14 14:52 ` Dave Martin 2019-10-14 15:45 ` Suzuki K Poulose 2019-10-14 15:45 ` Suzuki K Poulose 2019-10-14 15:50 ` Dave P Martin 2019-10-14 15:50 ` Dave P Martin 2019-10-14 16:57 ` Ard Biesheuvel 2019-10-14 16:57 ` Ard Biesheuvel 2019-10-15 9:44 ` Suzuki K Poulose 2019-10-15 9:44 ` Suzuki K Poulose 2019-10-15 9:52 ` Ard Biesheuvel 2019-10-15 9:52 ` Ard Biesheuvel 2019-10-15 10:24 ` Dave Martin 2019-10-15 10:24 ` Dave Martin 2019-10-15 10:30 ` Ard Biesheuvel 2019-10-15 10:30 ` Ard Biesheuvel 2019-10-15 13:03 ` Suzuki K Poulose 2019-10-15 13:03 ` Suzuki K Poulose 2019-10-15 13:11 ` Ard Biesheuvel 2019-10-15 13:11 ` Ard Biesheuvel 2019-10-15 14:05 ` Dave Martin 2019-10-15 14:05 ` Dave Martin 2019-10-10 17:15 ` Suzuki K Poulose [this message] 2019-10-10 17:15 ` [PATCH 2/3] arm64: nofpsmid: Clear TIF_FOREIGN_FPSTATE flag for early tasks Suzuki K Poulose 2019-10-11 11:26 ` Dave Martin 2019-10-11 11:26 ` Dave Martin 2019-10-17 12:42 ` Suzuki K Poulose 2019-10-17 12:42 ` Suzuki K Poulose 2019-10-17 16:09 ` Dave Martin 2019-10-17 16:09 ` Dave Martin 2019-10-10 17:15 ` [PATCH 3/3] arm64: cpufeature: Set the FP/SIMD compat HWCAP bits properly Suzuki K Poulose 2019-10-10 17:15 ` Suzuki K Poulose 2019-10-17 0:06 ` [PATCH 0/3] arm64: Fix support for systems without FP/SIMD Will Deacon 2019-10-17 0:06 ` Will Deacon
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20191010171517.28782-3-suzuki.poulose@arm.com \ --to=suzuki.poulose@arm.com \ --cc=catalin.marinas@arm.com \ --cc=dave.martin@arm.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=mark.rutland@arm.com \ --cc=will@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.