Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2616468imm; Sun, 30 Sep 2018 00:45:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV63Gdv280ha7G+uEzMv90MN90GK3lRIYihE+9pzugkjaZg3Mz3+npKCf11G+pyq37/PjwKau X-Received: by 2002:a17:902:5e3:: with SMTP id f90-v6mr6181405plf.222.1538293559461; Sun, 30 Sep 2018 00:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538293559; cv=none; d=google.com; s=arc-20160816; b=DDskOcyDQ4+O507kqgdgpZjFoDOhyoyw2zbG3wbkDsdv5pOHad6+eZQn3FT0+ubX3W D+QiZeg8PJsO5jRQYI7H6WFMmDwxABPXCdzvu5BYrc/YvCp9T69RUaQqS+2fYJWIXWku kK1aqnwmYLJ/oo6zdNCuz6Iavru20xKZA6tpKbpeowkVqIJTyCF2zr49ugsh84oGr0er GUB++NL0IUzgOMR0yz61UEPcDmuNsmHbddJveZGtODWQCQ9JF0KJdjMLcXXngdCTsyg/ Qi860MdSqmkrIz0WLQDUEpKp/dWGUNz62s08R8W40B4xTa8rf/tVWpgFy9yTSmmMdNLA ssIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=cbgn7B/FkjDMiVL7cNiqyvSHGP4pWU7H+r/K6/oK8y4=; b=z8IwzSvh1DRUCShUNJ77JO0d0zFuXp9OGSGFjQgse1DR5k1o6g5+1ltfhHfEzfDxUZ i65rr2Wx2GQ5N++QoH2r4aK6M+g6olYDRJQxGbO7BU2Wwj7EawHptcrlV8KIbmd6G3rP 9mOzqtj47OaK7lV1Q77hecVX64O+DGkH2w+BeWvvL8kAAYLC415aawifNwrncBOWWHgg 4PhkJIM6A7j6ASvh4mNlM+SJ2HwfpeGmjO+P+N4ZV4RhVXvoO0YWauVhDc5K+wQ9C+pj r1J41tNua59dLwOmr0F3LG5YoYmT/Ogexjlw+s0UeFwooJmj5VoROruft2skX2lxi7Nu b1eA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g7-v6si2359151pgj.116.2018.09.30.00.45.44; Sun, 30 Sep 2018 00:45:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728193AbeI3OPQ (ORCPT + 99 others); Sun, 30 Sep 2018 10:15:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49152 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727651AbeI3OPP (ORCPT ); Sun, 30 Sep 2018 10:15:15 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D75FA70A; Sun, 30 Sep 2018 07:43:21 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 470DD60164; Sun, 30 Sep 2018 07:43:17 +0000 (UTC) From: Peter Xu To: linux-kernel@vger.kernel.org Cc: Shuah Khan , Mike Kravetz , Mike Rapoport , Jerome Glisse , peterx@redhat.com, linux-mm@kvack.org, Zi Yan , "Kirill A . Shutemov" , linux-kselftest@vger.kernel.org, Shaohua Li , Andrea Arcangeli , "Dr . David Alan Gilbert" , Andrew Morton Subject: [PATCH v2 3/3] userfaultfd: selftest: recycle lock threads first Date: Sun, 30 Sep 2018 15:42:59 +0800 Message-Id: <20180930074259.18229-4-peterx@redhat.com> In-Reply-To: <20180930074259.18229-1-peterx@redhat.com> References: <20180930074259.18229-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sun, 30 Sep 2018 07:43:21 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now we recycle the uffd servicing threads earlier than the lock threads. It might happen that when the lock thread is still blocked at a pthread mutex lock while the servicing thread has already quitted for the cpu so the lock thread will be blocked forever and hang the test program. To fix the possible race, recycle the lock threads first. This never happens with current missing-only tests, but when I start to run the write-protection tests (the feature is not yet posted upstream) it happens every time of the run possibly because in that new test we'll need to service two page faults for each lock operation. Acked-by: Mike Rapoport Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 7a8c6937cc67..5d1db824f73a 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -626,6 +626,12 @@ static int stress(unsigned long *userfaults) if (uffd_test_ops->release_pages(area_src)) return 1; + + finished = 1; + for (cpu = 0; cpu < nr_cpus; cpu++) + if (pthread_join(locking_threads[cpu], NULL)) + return 1; + for (cpu = 0; cpu < nr_cpus; cpu++) { char c; if (bounces & BOUNCE_POLL) { @@ -643,11 +649,6 @@ static int stress(unsigned long *userfaults) } } - finished = 1; - for (cpu = 0; cpu < nr_cpus; cpu++) - if (pthread_join(locking_threads[cpu], NULL)) - return 1; - return 0; } -- 2.17.1