[RFC PATCH v3 04/10] sched/core: Dont allow to use CPU marked as paravirt

Shrikanth Hegde posted 10 patches 5 months ago
[RFC PATCH v3 04/10] sched/core: Dont allow to use CPU marked as paravirt
Posted by Shrikanth Hegde 5 months ago
Don't allow a paravirt CPU to be used while looking for a CPU to use.

Push task mechanism uses stopper thread which going to call
select_fallback_rq and use this mechanism to avoid picking a paravirt CPU.

Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
 kernel/sched/core.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b8a84e4691c8..279b0dd72b5e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2462,8 +2462,13 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu)
 		return cpu_online(cpu);
 
 	/* Non kernel threads are not allowed during either online or offline. */
-	if (!(p->flags & PF_KTHREAD))
-		return cpu_active(cpu);
+	if (!(p->flags & PF_KTHREAD)) {
+		/* A user thread shouldn't be allowed on a paravirt cpu */
+		if (is_cpu_paravirt(cpu))
+			return false;
+		else
+			return cpu_active(cpu);
+	}
 
 	/* KTHREAD_IS_PER_CPU is always allowed. */
 	if (kthread_is_per_cpu(p))
@@ -2473,6 +2478,10 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu)
 	if (cpu_dying(cpu))
 		return false;
 
+	/* Non percpu kthreads should stay away from paravirt cpu*/
+	if (is_cpu_paravirt(cpu))
+		return false;
+
 	/* But are allowed during online. */
 	return cpu_online(cpu);
 }
-- 
2.47.3
Re: [RFC PATCH v3 04/10] sched/core: Dont allow to use CPU marked as paravirt
Posted by K Prateek Nayak 5 months ago
Hello Shrikanth,

On 9/10/2025 11:12 PM, Shrikanth Hegde wrote:
> @@ -2462,8 +2462,13 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu)
>  		return cpu_online(cpu);
>  
>  	/* Non kernel threads are not allowed during either online or offline. */
> -	if (!(p->flags & PF_KTHREAD))
> -		return cpu_active(cpu);
> +	if (!(p->flags & PF_KTHREAD)) {
> +		/* A user thread shouldn't be allowed on a paravirt cpu */
> +		if (is_cpu_paravirt(cpu))
> +			return false;
> +		else

nit. redundant "else". I think this can be simplified as:

    return !is_cpu_paravirt(cpu) && cpu_active(cpu);

> +			return cpu_active(cpu);
> +	}

-- 
Thanks and Regards,
Prateek
Re: [RFC PATCH v3 04/10] sched/core: Dont allow to use CPU marked as paravirt
Posted by Shrikanth Hegde 5 months ago

On 9/11/25 10:46 AM, K Prateek Nayak wrote:
> Hello Shrikanth,
> 

Hi Prateek, Thanks for looking into this.

> On 9/10/2025 11:12 PM, Shrikanth Hegde wrote:
>> @@ -2462,8 +2462,13 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu)
>>   		return cpu_online(cpu);
>>   
>>   	/* Non kernel threads are not allowed during either online or offline. */
>> -	if (!(p->flags & PF_KTHREAD))
>> -		return cpu_active(cpu);
>> +	if (!(p->flags & PF_KTHREAD)) {
>> +		/* A user thread shouldn't be allowed on a paravirt cpu */
>> +		if (is_cpu_paravirt(cpu))
>> +			return false;
>> +		else
> 
> nit. redundant "else". I think this can be simplified as:
>

alright.
>      return !is_cpu_paravirt(cpu) && cpu_active(cpu);
> 
>> +			return cpu_active(cpu);
>> +	}
>