Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4158690imw; Tue, 19 Jul 2022 00:29:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1upwSYiHJX+fghjnEtTMkPxFYDcK5nBYOmfSZC3GLm++q2TFtzSrzgh1D+5vMj5HKyO1Adc X-Received: by 2002:a17:902:bb95:b0:169:4d7:fee with SMTP id m21-20020a170902bb9500b0016904d70feemr32094902pls.80.1658215743846; Tue, 19 Jul 2022 00:29:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658215743; cv=none; d=google.com; s=arc-20160816; b=W66J6esa4t3/cxFhkrCko1ItgxWiCO14V+0pNwwpSKWxQogLpKGUS6BIxne4jPOyiO IVl5dDaeMaAUtO98TBpV4F6f4qezebLpdadIJ6bhSVKZNpj0oCI87sodRcaXmQBLQHN/ kiuO3bEZ1Ba8gIZpO1IFN8a+4Au9Uibd/ZkE0f3clI6rXc1zCjgi9x+6j8c24SqYryXI X/en0KylZv6QzbWfzWQW8+7t9XuboK6VnTQdZIcUqp4ConauK9MA8RJoKcHcVmAa3e/c XxXdO7kQ+Xl1CIRKnA1cyiqEwspTSKmD0l0XUSsmw3tAvg1rhhacljIJEOR1A/Q6iwub zz6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=1TLI4cpTkvvZ1FKyQqbMuV6JR4Z1X/NR24gingPwxq8=; b=o9dAzMvGqIKAWqMBfiM++GbqkwDPGkGO+RXR+GRpEQlVO4Y1aL3Ae2dE0+otmbKuMl UUh8zDdcQ2YmavtRMl1Hz0qCVlopBdbxOK0vceWTnRfbGXRO9z7rC/KHIyhXp89qgqQP tjIrjayS1wK2EKODiZ7ZPmKl9Ab7ZLS4u1fhqFLrZjgYNGFeWwme5qi6++bDtJhPWUdL WuqyIasFfIYBaBY30WTmYlmdm9n3mpUfxs2KGmfxlK/5CCAQLGR3Taph2z0SGp31+NKs reC6azDurfP+sTwsWFTaM8F5+qjfKSe9KdLVVru5+6WkklAlHNIg4LX/+Oqubvakfp8b Q75A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Z3KNNmdb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 192-20020a6302c9000000b0041a3b1deca2si3958836pgc.218.2022.07.19.00.28.49; Tue, 19 Jul 2022 00:29:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Z3KNNmdb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236134AbiGSHYX (ORCPT + 99 others); Tue, 19 Jul 2022 03:24:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235378AbiGSHYV (ORCPT ); Tue, 19 Jul 2022 03:24:21 -0400 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0239F25C6D; Tue, 19 Jul 2022 00:24:19 -0700 (PDT) Date: Tue, 19 Jul 2022 09:24:12 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1658215458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1TLI4cpTkvvZ1FKyQqbMuV6JR4Z1X/NR24gingPwxq8=; b=Z3KNNmdbS78+gMFM5ylDfit3NDN6v4XIVpnL5nZlOmOTYa/IY9SqrdhNDxr3pyXbhG+855 FpALKOao9PZEoNeQim3P5jIwieLcIja0BukbXIWYenXoHXGxfaAcEozHrJaN0Fgo4N7Iu0 Ry1E/7q6t1vcq0o9eG4UZBZE97EHuUM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Andrew Jones To: Gavin Shan Cc: kvmarm@lists.cs.columbia.edu, shan.gavin@gmail.com, maz@kernel.org, linux-kernel@vger.kernel.org, oliver.upton@linux.dev, linux-kselftest@vger.kernel.org, pbonzini@redhat.com, shuah@kernel.org Subject: Re: [PATCH v4] KVM: selftests: Fix target thread to be migrated in rseq_test Message-ID: <20220719072412.mmuptm3kf6wwi5pt@kamzik> References: <20220719020830.3479482-1-gshan@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220719020830.3479482-1-gshan@redhat.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 19, 2022 at 10:08:30AM +0800, Gavin Shan wrote: > 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: 61e52f1630f5 ("KVM: selftests: Add a test for KVM_RUN+rseq to detect task migration bugs") > Suggested-by: Sean Christopherson > Signed-off-by: Gavin Shan > Reviewed-by: Oliver Upton > --- > v4: Pick the code change as Sean suggested. > --- > tools/testing/selftests/kvm/rseq_test.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/tools/testing/selftests/kvm/rseq_test.c b/tools/testing/selftests/kvm/rseq_test.c > index 4158da0da2bb..2237d1aac801 100644 > --- a/tools/testing/selftests/kvm/rseq_test.c > +++ b/tools/testing/selftests/kvm/rseq_test.c > @@ -82,8 +82,9 @@ static int next_cpu(int cpu) > return cpu; > } > > -static void *migration_worker(void *ign) > +static void *migration_worker(void *__rseq_tid) > { > + pid_t rseq_tid = (pid_t)(unsigned long)__rseq_tid; > cpu_set_t allowed_mask; > int r, i, cpu; > > @@ -106,7 +107,7 @@ static void *migration_worker(void *ign) > * stable, i.e. while changing affinity is in-progress. > */ > smp_wmb(); > - r = sched_setaffinity(0, sizeof(allowed_mask), &allowed_mask); > + r = sched_setaffinity(rseq_tid, sizeof(allowed_mask), &allowed_mask); > TEST_ASSERT(!r, "sched_setaffinity failed, errno = %d (%s)", > errno, strerror(errno)); > smp_wmb(); > @@ -231,7 +232,8 @@ int main(int argc, char *argv[]) > vm = vm_create_default(VCPU_ID, 0, guest_code); > ucall_init(vm, NULL); > > - pthread_create(&migration_thread, NULL, migration_worker, 0); > + pthread_create(&migration_thread, NULL, migration_worker, > + (void *)(unsigned long)gettid()); > > for (i = 0; !done; i++) { > vcpu_run(vm, VCPU_ID); > -- > 2.23.0 Thanks for figuring this out Gavin and Sean! Reviewed-by: Andrew Jones