[LTP] [PATCH] ht_affinity.c: fix ht_affinity test failure

Cyril Hrubis chrubis@suse.cz
Fri Sep 20 10:58:06 CEST 2024


Hi!
> The type of cpumask pointer used in set_affinity() is unsigned long, but
> ht_affinity used a unsigned int pointer. When kernel copy cpumask from
> user-space pointer, the high 32bit of cpumask is a random value. So the
> process can't be bind to the cpu specified by users.

Good catch, however it would be better if we used sizeof on the mask
instead of sizeof(unsigned long) in the sched_setaffinity() as well:

diff --git a/testcases/kernel/sched/hyperthreading/ht_affinity/ht_affinity.c b/testcases/kernel/sched/hyperthreading/ht_affinity/ht_affinity.c
index f6e9f2745..3c2fe1bf1 100644
--- a/testcases/kernel/sched/hyperthreading/ht_affinity/ht_affinity.c
+++ b/testcases/kernel/sched/hyperthreading/ht_affinity/ht_affinity.c
@@ -67,7 +67,7 @@ int HT_SetAffinity(void)
                tst_resm(TINFO, "Set test process affinity.");
                printf("mask: %x\n", mask);

-               sched_setaffinity(pid, sizeof(unsigned long), &mask);
+               sched_setaffinity(pid, sizeof(mask), &mask);

                for (j = 0; j < 10; j++) {
                        for (k = 0; k < 10; k++) {
@@ -95,7 +95,7 @@ int HT_SetAffinity(void)
                tst_resm(TINFO, "Set test process affinity.");
                printf("mask: %x\n", mask);

-               sched_setaffinity(pid, sizeof(unsigned long), &mask);
+               sched_setaffinity(pid, sizeof(mask), &mask);

                for (j = 0; j < 10; j++) {
                        for (k = 0; k < 10; k++) {



Most of the code does that already which makes it impossible to pass
different size than the actual size.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list