All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched_ext: create_dsq: Return -EEXIST on duplicate request
@ 2025-03-25 22:41 Jake Hillion
  2025-03-26  6:08 ` Andrea Righi
  2025-03-26 20:33 ` Tejun Heo
  0 siblings, 2 replies; 3+ messages in thread
From: Jake Hillion @ 2025-03-25 22:41 UTC (permalink / raw)
  To: tj; +Cc: arighi, changwoo, sched-ext, linux-kernel, Jake Hillion

create_dsq and therefore the scx_bpf_create_dsq kfunc currently silently
ignore duplicate entries. As a sched_ext scheduler is creating each DSQ
for a different purpose this is surprising behaviour.

Replace rhashtable_insert_fast which ignores duplicates with
rhashtable_lookup_insert_fast that reports duplicates (though doesn't
return their value). The rest of the code is structured correctly and
this now returns -EEXIST.

Tested by adding an extra scx_bpf_create_dsq to scx_simple. Previously
this was ignored, now init fails with a -17 code. Also ran scx_lavd
which continued to work well.

Signed-off-by: Jake Hillion <jake@hillion.co.uk>
---
 kernel/sched/ext.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 21575d39c376..b47be2729ece 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -4171,8 +4171,8 @@ static struct scx_dispatch_q *create_dsq(u64 dsq_id, int node)
 
 	init_dsq(dsq, dsq_id);
 
-	ret = rhashtable_insert_fast(&dsq_hash, &dsq->hash_node,
-				     dsq_hash_params);
+	ret = rhashtable_lookup_insert_fast(&dsq_hash, &dsq->hash_node,
+					    dsq_hash_params);
 	if (ret) {
 		kfree(dsq);
 		return ERR_PTR(ret);
-- 
2.47.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched_ext: create_dsq: Return -EEXIST on duplicate request
  2025-03-25 22:41 [PATCH] sched_ext: create_dsq: Return -EEXIST on duplicate request Jake Hillion
@ 2025-03-26  6:08 ` Andrea Righi
  2025-03-26 20:33 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Andrea Righi @ 2025-03-26  6:08 UTC (permalink / raw)
  To: Jake Hillion; +Cc: tj, changwoo, sched-ext, linux-kernel

Hi Jake,

On Tue, Mar 25, 2025 at 10:41:52PM +0000, Jake Hillion wrote:
> create_dsq and therefore the scx_bpf_create_dsq kfunc currently silently
> ignore duplicate entries. As a sched_ext scheduler is creating each DSQ
> for a different purpose this is surprising behaviour.
> 
> Replace rhashtable_insert_fast which ignores duplicates with
> rhashtable_lookup_insert_fast that reports duplicates (though doesn't
> return their value). The rest of the code is structured correctly and
> this now returns -EEXIST.
> 
> Tested by adding an extra scx_bpf_create_dsq to scx_simple. Previously
> this was ignored, now init fails with a -17 code. Also ran scx_lavd
> which continued to work well.
> 
> Signed-off-by: Jake Hillion <jake@hillion.co.uk>

Nice catch! It'd be nice to test the correct behavior in
tools/testing/selftests/sched_ext/create_dsq.bpf.c, maybe you can send a
separate patch for this. In the meantime, this one looks good to me.

Acked-by: Andrea Righi <arighi@nvidia.com>

Thanks,
-Andrea

> ---
>  kernel/sched/ext.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 21575d39c376..b47be2729ece 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -4171,8 +4171,8 @@ static struct scx_dispatch_q *create_dsq(u64 dsq_id, int node)
>  
>  	init_dsq(dsq, dsq_id);
>  
> -	ret = rhashtable_insert_fast(&dsq_hash, &dsq->hash_node,
> -				     dsq_hash_params);
> +	ret = rhashtable_lookup_insert_fast(&dsq_hash, &dsq->hash_node,
> +					    dsq_hash_params);
>  	if (ret) {
>  		kfree(dsq);
>  		return ERR_PTR(ret);
> -- 
> 2.47.2
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched_ext: create_dsq: Return -EEXIST on duplicate request
  2025-03-25 22:41 [PATCH] sched_ext: create_dsq: Return -EEXIST on duplicate request Jake Hillion
  2025-03-26  6:08 ` Andrea Righi
@ 2025-03-26 20:33 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2025-03-26 20:33 UTC (permalink / raw)
  To: Jake Hillion; +Cc: arighi, changwoo, sched-ext, linux-kernel

On Tue, Mar 25, 2025 at 10:41:52PM +0000, Jake Hillion wrote:
> create_dsq and therefore the scx_bpf_create_dsq kfunc currently silently
> ignore duplicate entries. As a sched_ext scheduler is creating each DSQ
> for a different purpose this is surprising behaviour.
> 
> Replace rhashtable_insert_fast which ignores duplicates with
> rhashtable_lookup_insert_fast that reports duplicates (though doesn't
> return their value). The rest of the code is structured correctly and
> this now returns -EEXIST.
> 
> Tested by adding an extra scx_bpf_create_dsq to scx_simple. Previously
> this was ignored, now init fails with a -17 code. Also ran scx_lavd
> which continued to work well.
> 
> Signed-off-by: Jake Hillion <jake@hillion.co.uk>

Applied to sched_ext/for-6.15-fixes w/ stable cc'd.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-26 20:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-25 22:41 [PATCH] sched_ext: create_dsq: Return -EEXIST on duplicate request Jake Hillion
2025-03-26  6:08 ` Andrea Righi
2025-03-26 20:33 ` Tejun Heo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.