sched_ext: create_dsq: Return -EEXIST on duplicate request
PATCH 1/1 sched_ext: create_dsq: Return -EEXIST on duplicate request
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.
--- kernel/sched/ext.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/ext.c +2 -2
@@ -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);
Signature · 1 line
2.47.2
Hi Jake,
Quoted 9 lines · Jake Hillion
create_dsqand therefore thescx_bpf_create_dsqkfunc currently silently ignore duplicate entries. As asched_extscheduler is creating each DSQ for a different purpose this is surprising behaviour.Replace
rhashtable_insert_fastwhich ignores duplicates withrhashtable_lookup_insert_fastthat reports duplicates (though doesn't return their value). The rest of the code is structured correctly and this now returns-EEXIST.
Quoted 5 lines
Tested by adding an extra
scx_bpf_create_dsqtoscx_simple. Previously this was ignored, now init fails with a -17 code. Also ranscx_lavdwhich continued to work well.Signed-off-by Jake Hillion <[email protected]>
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.
Thanks,
-Andrea
Quoted 23 lines
--- kernel/sched/ext.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/sched/ext.c +2
-2@@ -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);Signature · 1 line
2.47.2
Tejun Heo
AppliedQuoted 9 lines · Jake Hillion
create_dsqand therefore thescx_bpf_create_dsqkfunc currently silently ignore duplicate entries. As asched_extscheduler is creating each DSQ for a different purpose this is surprising behaviour.Replace
rhashtable_insert_fastwhich ignores duplicates withrhashtable_lookup_insert_fastthat reports duplicates (though doesn't return their value). The rest of the code is structured correctly and this now returns-EEXIST.
Quoted 5 lines
Tested by adding an extra
scx_bpf_create_dsqtoscx_simple. Previously this was ignored, now init fails with a -17 code. Also ranscx_lavdwhich continued to work well.Signed-off-by Jake Hillion <[email protected]>
Applied to sched_ext/for-6.15-fixes w/ stable cc'd.
Thanks.
Signature · 1 line
tejun