Re: [RFC][PATCH] sched,livepatch: Untangle cond_resched() and live-patching

From: Miroslav Benes
Date: Wed Mar 26 2025 - 11:03:31 EST


> void __klp_sched_try_switch(void)
> {
> - if (likely(!klp_patch_pending(current)))
> - return;
> -
> /*
> * This function is called from cond_resched() which is called in many
> * places throughout the kernel. Using the klp_mutex here might
> @@ -377,14 +365,14 @@ void __klp_sched_try_switch(void)
> * klp_try_switch_task(). Thanks to task_call_func() they won't be
> * able to switch this task while it's running.
> */
> - preempt_disable();
> + lockdep_assert_preemption_disabled();
>
> /*
> * Make sure current didn't get patched between the above check and
> * preempt_disable().
> */
> if (unlikely(!klp_patch_pending(current)))
> - goto out;
> + return;

It does not look correct. We just make sure that
klp_patch_pending(current) did not change here. It would be highly
unlikely. However, we should keep the likely way out (the first removed
condition above). So let's also s/unlikely/likely/ here.

And the comments in the function should be updated as well.

Miroslav