Bug 21661 - [Anolis23.3 RC][loongarch]在内核非抢占配置下,因条件调度触发上下文切换导致FPU状态异常的问题​​
Summary: [Anolis23.3 RC][loongarch]在内核非抢占配置下,因条件调度触发上下文切换导致FPU状态异常的问题​​
Status: RESOLVED FIXED
Alias: None
Product: ANCK 6.6 Dev
Classification: ANCK
Component: ARCH(unspecified) (show other bugs) ARCH(unspecified)
Version: 6.6.88-4
Hardware: loongarch Linux
: P3-Medium S3-normal
Target Milestone: ---
Assignee: gaojuxin09
QA Contact: shuming
URL:
Whiteboard: Cherry-pick to RC2
Keywords:
Depends on:
Blocks:
 
Reported: 2025-06-05 10:21 UTC by gaojuxin09
Modified: 2025-06-06 10:20 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gaojuxin09 loongson_group 2025-06-05 10:21:59 UTC
Description of problem:


Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:
Comment 1 小龙 admin 2025-06-05 14:36:41 UTC
The PR Link: https://gitee.com/anolis/cloud-kernel/pulls/5394
Comment 2 gaojuxin09 loongson_group 2025-06-06 09:58:18 UTC
commit 1f2c50487822dd41e78c968a8f94b770ea34894e
Author: Tianyang Zhang <zhangtianyang@loongson.cn>
Date:   Wed May 7 09:44:58 2025 +0800

    LoongArch: Prevent cond_resched() occurring within kernel-fpu
    
    ANBZ: #21661
    
    commit 2468b0e3d5659dfde77f081f266e1111a981efb8 upstarem.
    
    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 d021985 (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>
    Reviewed-by: Juxin Gao <gaojuxin@loongson.cn>
    Link: https://gitee.com/anolis/cloud-kernel/pulls/5394