Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4479301imw; Tue, 19 Jul 2022 07:22:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sKyTPI7T5Zo+Xok9fe7jcFvAgQBbpfrO0PDQ2jZjsmq7DbySK8JF06UdsLAepxfk/zvTzD X-Received: by 2002:a05:6402:847:b0:437:62bd:bbc0 with SMTP id b7-20020a056402084700b0043762bdbbc0mr43800382edz.285.1658240565077; Tue, 19 Jul 2022 07:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658240565; cv=none; d=google.com; s=arc-20160816; b=HERB06YbNHSpWj/Uq7VxH/zWJi4ZUZYzF/YCIBTW9aV6n0Y1Uj7hSKOyD75DbVqmOT 49gOJXtSZ3teYgECrRv1Q3EfVyZc5Fdh1gbJIWrY+tVGiBhXWQk+hiZ8y8HGmurWrg4W yKW68nBaArVTccUX0M1p2vGlGHcIt2S6EK1/rn9xocbMD+XtIbFscLYjITpR4AjEbH4H nwVi0zo3TC3zBB9g9tSZ0uomMgRxD7Rv1sHRj1GwluupgPQ/zxINtBt/7YcaEgmtmePV YWfTO2vzqS+q5Qrs9sq0SLDzAW+JiF7pLwYLzqpyGMJ3VVby1V2HdVPT+JrTvYyirH/T 6PfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=/m2NS+tTnqV4bKM9ewNHJoxDhTc6Y1oQ8gKFxD1trHs=; b=hGQGc6XBERTN7/7MNQElU2bWtWRxQ4gK99DV/riZrfxqFDB5tcvIJukfkKmQZKTMsD rbyiwcls5o411N/IVy4sDzm61BoPElWX+GB3Lia/yfoY6DlWecIDYUbjqKf7P7IL7rQT Vt7Xq28HvT/peMLUrr7AJB2TwjPSjqMHGwrlTKqkKnRh1/z8kKq0mV98JfytHUQiqesQ mEn9o199AcayadiZUIcM6RUKfP0INi/hUfCpUs6iSR5pxi90nmzPxd+mYfw9rWt+wY69 OXZHhR5CrC2ehJ3rxDD524RgvDLJOu4hZy1zHMg5YzmD9GI008qIsvSqfFYdSfu07pmk KVAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HNq5hpxj; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g2-20020a056402424200b0043a7a473db2si23798139edb.484.2022.07.19.07.22.19; Tue, 19 Jul 2022 07:22:45 -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=@redhat.com header.s=mimecast20190719 header.b=HNq5hpxj; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237857AbiGSNwl (ORCPT + 99 others); Tue, 19 Jul 2022 09:52:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237819AbiGSNw1 (ORCPT ); Tue, 19 Jul 2022 09:52:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AE2A29CE2B for ; Tue, 19 Jul 2022 06:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658235880; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/m2NS+tTnqV4bKM9ewNHJoxDhTc6Y1oQ8gKFxD1trHs=; b=HNq5hpxj0IYa9fVhhKY1jWOdxEZSOyNOdX75O+f20xeujPxIJGZjUKF+1cR66cTw5GIaTP w0Q6BpzPLbjas+AZQNIIVJw7kPjNSVMNLBaUxUcBvVapGjanFf6NX1LAESteZOldOYcfrj bQx/IYNB38Dl3Jo9vlAOY7omlluZotw= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-54-fUpZfaEOOLCDe0o0xpFb0w-1; Tue, 19 Jul 2022 09:04:37 -0400 X-MC-Unique: fUpZfaEOOLCDe0o0xpFb0w-1 Received: by mail-ed1-f70.google.com with SMTP id h20-20020a05640250d400b0043b6a4a2f11so3408049edb.23 for ; Tue, 19 Jul 2022 06:04:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=/m2NS+tTnqV4bKM9ewNHJoxDhTc6Y1oQ8gKFxD1trHs=; b=qVsPd8MSBR/sClwgQFq7Dq/mTu/E+nsuPBz418jSvkLpt77woMeBieErD1+KeMRNOg OqW4hjUHIoiwEfdR+uWQ2nadta4LJd11c4LSbKw78fl0infA58q21JuD7mAHmBmh2gID CRFOPj9Hr+UpZmoj0UglNUB58OtXgxXmZMSePXUMFMypkcDjnVx8Kw9JjSAtC7nmKCvx ijqdrYo7UlzHtPqkE84qBURfUEcVvlkS686FUFGVN1xePNox+Wi8b81t58r+DNoAjdrX ow3jS6PfYpnai9S9xVbSpMiyo9jBSPWlPQFVSp9hsCpobrCNcuZiYJOquO/Jy82GR0IX kbkA== X-Gm-Message-State: AJIora9q9//L9XvSzovrLkfQQx/f8K4qXur8DMJr+usgZaiJJJHG7yAe O+FhQTH4cyeoDFg28v/ultAz26PXGa6gZY20NhcvtOvU7SmukFcK72Z+yE8qMQvwkgRHAesvh/9 7VkpPaj7r5twD+nja7ZZ/g+mG X-Received: by 2002:a05:6402:350a:b0:43a:a486:102e with SMTP id b10-20020a056402350a00b0043aa486102emr43636760edd.372.1658235875759; Tue, 19 Jul 2022 06:04:35 -0700 (PDT) X-Received: by 2002:a05:6402:350a:b0:43a:a486:102e with SMTP id b10-20020a056402350a00b0043aa486102emr43636731edd.372.1658235875538; Tue, 19 Jul 2022 06:04:35 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:9af8:e5f5:7516:fa89? ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.googlemail.com with ESMTPSA id lv8-20020a170906bc8800b0072b91a3d7e9sm6670356ejb.28.2022.07.19.06.04.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Jul 2022 06:04:34 -0700 (PDT) Message-ID: <2b9070bd-61b2-0057-003e-f6c46f6c34a8@redhat.com> Date: Tue, 19 Jul 2022 15:04:33 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v4] KVM: selftests: Fix target thread to be migrated in rseq_test Content-Language: en-US To: Gavin Shan , kvmarm@lists.cs.columbia.edu Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, oliver.upton@linux.dev, seanjc@google.com, shuah@kernel.org, maz@kernel.org, shan.gavin@gmail.com References: <20220719020830.3479482-1-gshan@redhat.com> From: Paolo Bonzini In-Reply-To: <20220719020830.3479482-1-gshan@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 7/19/22 04:08, 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); Queued, thanks. Paolo