From 08cb938197e82eddce146662a47ff990827ff60a Mon Sep 17 00:00:00 2001 From: Haifeng Xu Date: Sat, 21 Sep 2024 12:38:54 +0800 Subject: [PATCH] ht_affinity.c: fix ht_affinity test failure Running ht_affinity test fails: smt_smp_affinity 0 TINFO : Set affinity through system call smt_smp_affinity 0 TINFO : Set test process affinity. mask: 1 smt_smp_affinity 0 TINFO : ...Error ... smt_smp_affinity 0 TINFO : Set test process affinity. mask: c0000000 smt_smp_affinity 0 TINFO : ...Error smt_smp_affinity 3 TFAIL : ht_affinity.c:240: System call setaffinity() is error. 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. After using sizeof on the mask instead of sizeof(unsigned long), ht_affinity test succeeds: smt_smp_affinity 0 TINFO : Set affinity through system call smt_smp_affinity 0 TINFO : Set test process affinity. mask: 1 smt_smp_affinity 0 TINFO : ...OK ... smt_smp_affinity 0 TINFO : Set test process affinity. mask: c0000000 smt_smp_affinity 0 TINFO : ...OK smt_smp_affinity 3 TPASS : System call setaffinity() is OK. Signed-off-by: Haifeng Xu Suggested-by: Cyril Hrubis Reviewed-by: Cyril Hrubis --- .../kernel/sched/hyperthreading/ht_affinity/ht_affinity.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/sched/hyperthreading/ht_affinity/ht_affinity.c b/testcases/kernel/sched/hyperthreading/ht_affinity/ht_affinity.c index f6e9f2745a5..3c2fe1bf1db 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++) {