lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <173ABBF7-4EF9-410A-B36F-C15C0D01CED8@gmail.com>
Date: Tue, 30 Sep 2025 01:40:44 +0800
From: Jemmy Wong <jemmywong512@...il.com>
To: K Prateek Nayak <kprateek.nayak@....com>
Cc: Jemmy Wong <jemmywong512@...il.com>,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH] sched: Add _TIF_NEED_RESCHED_LAZY to __resched_curr check

Hi Prateek,

Thank you for the very detailed example, which helped me clearly understand the 
difference between TIF_NEED_RESCHED and TIF_NEED_RESCHED_LAZY.

The source code logic seems correct and effectively prevents repeated flag settings:
> if (cti->flags & ((1 << tif) | _TIF_NEED_RESCHED))
>     return;

The inclusion of _TIF_NEED_RESCHED in the check indicates:
1. TIF_NEED_RESCHED has higher priority/urgent than TIF_NEED_RESCHED_LAZY.
2. TIF_NEED_RESCHED_LAZY is not needed if TIF_NEED_RESCHED is set.

> On Sep 29, 2025, at 12:37 PM, K Prateek Nayak <kprateek.nayak@....com> wrote:
> __resched_curr() is used to set both TIF_NEED_RESCHED_LAZY and
> TIF_NEED_RESCHED.
> 
> By putting this check here, any effort to set NEED_RESCHED and force an
> early preemption will bail out if NEED_RESCHED_LAZY is already set which
> will delay the preemption.
> 
> An example:
> 
>    /* New fair task wakes up. */
>    check_preempt_wakeup_fair()
>        resched_curr_lazy()
>            __resched_curr(TIF_NEED_RESCHED_LAZY)
> 
>    /* New RT task wakes up. */
>    wakeup_preempt()
>        resched_curr()
>            __resched_curr(TIF_NEED_RESCHED)
>                /* Sees NEED_RESCHED_LAZY is already set. */
>                /* Does not do a set_preempt_need_resched() */
> 
>    ... /* Added latency */
>    sched_tick()
>        if (tif_test_bit(TIF_NEED_RESCHED_LAZY))
>            resched_curr()
>                __resched_curr(TIF_NEED_RESCHED)
>                    /* Again bails out early! */
> 
>    ... /* More latency! */
> 
> 
> So, the tick doesn't even upgrade the LAZY flag to a full NEED_RESCHED
> and the only time you actually schedule is either at exit to user mode
> or if a kthread decides to yield.
> 
> Going back to your commit message, something like:
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 7f1e5cb94c53..3275abce9ca2 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -1164,6 +1164,9 @@ static __always_inline int get_lazy_tif_bit(void)
> 
> void resched_curr_lazy(struct rq *rq)
> {
> + if (task_thread_info(rq->curr)->flags & TIF_NEED_RESCHED_MASK)
> + return;
> +
> __resched_curr(rq, get_lazy_tif_bit());
> }
> 
> probably fits the bill better.
> 
>> 
>> cpu = cpu_of(rq);
>> --
>> 2.50.1 (Apple Git-155)
>> 
> 
> -- 
> Thanks and Regards,
> Prateek
> 

Best Regards,
Jemmy


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ