Skip to content

Commit e923b05

Browse files
Gavin Shanbonzini
authored andcommitted
KVM: selftests: Fix target thread to be migrated in rseq_test
In rseq_test, there are two threads, which are vCPU thread and migration worker separately. Unfortunately, the test has the wrong PID passed to sched_setaffinity() in the migration worker. It forces migration on the migration worker because zeroed PID represents the calling thread, which is the migration worker itself. It means the vCPU thread is never enforced to migration and it can migrate at any time, which eventually leads to failure as the following logs show. host# uname -r 5.19.0-rc6-gavin+ host# # cat /proc/cpuinfo | grep processor | tail -n 1 processor : 223 host# pwd /home/gavin/sandbox/linux.main/tools/testing/selftests/kvm host# for i in `seq 1 100`; do \ echo "--------> $i"; ./rseq_test; done --------> 1 --------> 2 --------> 3 --------> 4 --------> 5 --------> 6 ==== Test Assertion Failure ==== rseq_test.c:265: rseq_cpu == cpu pid=3925 tid=3925 errno=4 - Interrupted system call 1 0x0000000000401963: main at rseq_test.c:265 (discriminator 2) 2 0x0000ffffb044affb: ?? ??:0 3 0x0000ffffb044b0c7: ?? ??:0 4 0x0000000000401a6f: _start at ??:? rseq CPU = 4, sched CPU = 27 Fix the issue by passing correct parameter, TID of the vCPU thread, to sched_setaffinity() in the migration worker. Fixes: 61e52f1 ("KVM: selftests: Add a test for KVM_RUN+rseq to detect task migration bugs") Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Gavin Shan <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Message-Id: <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 450a563 commit e923b05

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tools/testing/selftests/kvm/rseq_test.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ static int next_cpu(int cpu)
8282
return cpu;
8383
}
8484

85-
static void *migration_worker(void *ign)
85+
static void *migration_worker(void *__rseq_tid)
8686
{
87+
pid_t rseq_tid = (pid_t)(unsigned long)__rseq_tid;
8788
cpu_set_t allowed_mask;
8889
int r, i, cpu;
8990

@@ -106,7 +107,7 @@ static void *migration_worker(void *ign)
106107
* stable, i.e. while changing affinity is in-progress.
107108
*/
108109
smp_wmb();
109-
r = sched_setaffinity(0, sizeof(allowed_mask), &allowed_mask);
110+
r = sched_setaffinity(rseq_tid, sizeof(allowed_mask), &allowed_mask);
110111
TEST_ASSERT(!r, "sched_setaffinity failed, errno = %d (%s)",
111112
errno, strerror(errno));
112113
smp_wmb();
@@ -231,7 +232,8 @@ int main(int argc, char *argv[])
231232
vm = vm_create_default(VCPU_ID, 0, guest_code);
232233
ucall_init(vm, NULL);
233234

234-
pthread_create(&migration_thread, NULL, migration_worker, 0);
235+
pthread_create(&migration_thread, NULL, migration_worker,
236+
(void *)(unsigned long)gettid());
235237

236238
for (i = 0; !done; i++) {
237239
vcpu_run(vm, VCPU_ID);

0 commit comments

Comments
 (0)