Re: [patch V2 08/12] rseq: Implement time slice extension enforcement timer
From: Sebastian Andrzej Siewior
Date: Tue Oct 28 2025 - 06:22:10 EST
On 2025-10-28 14:52:09 [+0530], K Prateek Nayak wrote:
> On 10/28/2025 2:30 PM, Sebastian Andrzej Siewior wrote:
> >>> Without an interrupt on the target CPU, there is nothing stopping the
> >>> task from overstepping its fair share.
> >>
> >> When the task moves CPU, the rseq_exit_user_update() would clear all
> >> of the slice extension state before running the task again. The task
> >> will start off again with "rseq->slice_ctrl.request" and
> >> "rseq->slice_ctrl.granted" both at 0 signifying the task was
> >> rescheduled.
> >
> > I wasn't aware this is done once the task is in userland and then
> > relocated to another CPU.
>
> The exact path based on my understanding is:
>
> /* Task migrates to another CPU; Has to resume from kernel. */
> __schedule()
> context_switch()
> rseq_sched_switch_event()
> t->rseq.event.sched_switch = true;
> set_tsk_thread_flag(t, TIF_RSEQ);
>
> ...
> exit_to_user_mode_loop()
> rseq_exit_to_user_mode_restart()
> __rseq_exit_to_user_mode_restart()
> /* Sees t->rseq.event.sched_switch to be true. */
> rseq_exit_user_update()
> if (rseq_slice_extension_enabled())
> unsafe_put_user(0U, &rseq->slice_ctrl.all, efault); /* Unconditionally clears all of "rseq_ctrl" */
You are right. The migration thread preempts it on the old CPU and then
it gets scheduled in on the new CPU.
Sebastian