]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
LoongArch: Prevent cond_resched() occurring within kernel-fpu
authorTianyang Zhang <zhangtianyang@loongson.cn>
Wed, 14 May 2025 14:17:43 +0000 (22:17 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 May 2025 12:12:19 +0000 (14:12 +0200)
commitf4c0a7999fb599d653a5ae37625d449a47ced153
tree93d52fd5ebc9b3c424cec128402811162ae04b44
parent7722fba9f3bf0462a0fad7d47bf9903d989c741c
LoongArch: Prevent cond_resched() occurring within kernel-fpu

commit 2468b0e3d5659dfde77f081f266e1111a981efb8 upstream.

When CONFIG_PREEMPT_COUNT is not configured (i.e. CONFIG_PREEMPT_NONE/
CONFIG_PREEMPT_VOLUNTARY), preempt_disable() / preempt_enable() merely
acts as a barrier(). However, in these cases cond_resched() can still
trigger a context switch and modify the CSR.EUEN, resulting in do_fpu()
exception being activated within the kernel-fpu critical sections, as
demonstrated in the following path:

dcn32_calculate_wm_and_dlg()
    DC_FP_START()
dcn32_calculate_wm_and_dlg_fpu()
    dcn32_find_dummy_latency_index_for_fw_based_mclk_switch()
dcn32_internal_validate_bw()
    dcn32_enable_phantom_stream()
dc_create_stream_for_sink()
   kzalloc(GFP_KERNEL)
__kmem_cache_alloc_node()
    __cond_resched()
    DC_FP_END()

This patch is similar to commit d02198550423a0b (x86/fpu: Improve crypto
performance by making kernel-mode FPU reliably usable in softirqs).  It
uses local_bh_disable() instead of preempt_disable() for non-RT kernels
so it can avoid the cond_resched() issue, and also extend the kernel-fpu
application scenarios to the softirq context.

Cc: stable@vger.kernel.org
Signed-off-by: Tianyang Zhang <zhangtianyang@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/loongarch/kernel/kfpu.c