From patchwork Sat Sep 29 08:43:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10620687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A11A1750 for ; Sat, 29 Sep 2018 08:43:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AC012AF98 for ; Sat, 29 Sep 2018 08:43:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CCD12AFA1; Sat, 29 Sep 2018 08:43:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 090BD2AF98 for ; Sat, 29 Sep 2018 08:43:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC2878E0005; Sat, 29 Sep 2018 04:43:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E4AF88E0001; Sat, 29 Sep 2018 04:43:35 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3B448E0005; Sat, 29 Sep 2018 04:43:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id A508F8E0001 for ; Sat, 29 Sep 2018 04:43:35 -0400 (EDT) Received: by mail-qk1-f200.google.com with SMTP id z18-v6so8335927qki.22 for ; Sat, 29 Sep 2018 01:43:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=05flFEVEhG7qTUpNjE7Sf2JlGt3wwT/uLXi6I+/HmrI=; b=DmFL8PgdATY8VNIFI3Y0v7Lr75qxu/OR8C1RbCRsRVEbPG9Ojkkgl99UsjcEaDcUpN EdAXonGt75wyzxtd+z3dpa0OzDLtJU+6hVqKhrB6LasWUblLG4OJad/gciWAvlNvCgYY R1KlW/5P4cVQDI+WPDRIQpwoE0Y8lWBK3A12KkLFw+UQtANSo0iqb/+GPfMEYFTxSwg6 94izizAoAbLIM+QuMEmzy1vs6xHQ5iTFYXHdywgfMa1OofBz5qulNEyJt3Y7mUAvkSSQ LI0pkE5y78pO4e7SDMxzUL8DXUKoWamwTjARBYfFQGzZHQZDMe4uHd2MZV0+gxdPDPMz N5OA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: ABuFfohVTIQlbj1uc98zvpyTmHaluv2Nihe5Ai98k9YUHEtYuyJcpu4q +xZy1jWJRqHCtGpQFzXXEvkxkGP+Ms+qWz8hDFzvfYam1UMvhNvIWVQyN2N9r3GwnWTkJUIe+dv pJ42z8T9k+4qh41knTKyTF4RYqth9VXlIAxrdjZ4JPikS8iddlYk4K6eooeQPa3vqUA== X-Received: by 2002:ad4:404a:: with SMTP id r10-v6mr1696910qvp.246.1538210615424; Sat, 29 Sep 2018 01:43:35 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Maz4btNV+lArI5NiNT/tNkU6s4msbSfmVDcftgXeM0qlJeFdhd3IZ4qopOhfh4IObXT6p X-Received: by 2002:ad4:404a:: with SMTP id r10-v6mr1696898qvp.246.1538210614931; Sat, 29 Sep 2018 01:43:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538210614; cv=none; d=google.com; s=arc-20160816; b=asra/2FerKG747vJvmWH6nfMjHvzrpQr5/cNMVDUCptHpOhGHvK2fhmNfIBtj00F3s /aZc8psAdCqzlvRlXM82qofgX9qh9HQhZMTN4rnRX+7HY4ynZpaMwYd5ceG5doI8Ok4Y t2aRF4pjooHFaYYLibzVd/zTzmiomr+k2qekA1+/H05L6mObX+jvVT/kHja71AKTBhPt luwPsoe4IrIi5r8xYDWJ7KwZsAlqgQGfssTp45ztk9eBtME8uOdwa3hM10qT9Ngnqyr8 Tl9miRIVjPIOj0pdVDSgunmtYGbvQWsAB8wLoJ/xaSF4edyIviUvOcxIsHQg6ZNnoP1/ Gxew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=05flFEVEhG7qTUpNjE7Sf2JlGt3wwT/uLXi6I+/HmrI=; b=S4rE1ZLLI8zv9xV5HsRQGa5n51TNrUGrh+exobSARBLJF9s45JON5vh8R6PJPH3QvK ntdyWEQpszD5H9xHGzTbu5GxyKjYLsLDngpVdMKFpPPhXyVn/nxnZC7YfnH9bIxriqLh 1RBgfmqjCSHGQ+hEZ6IMEn9Y1DB5YGF41AgWTXELEMoH6wM1SGyqY9uFMTSKOMrsOLOd a4g28UTRGYLx7F1vk+gfwneQWm8MFco+qBdUT/tRxTgVr5f/UUhieefoh47iNq3AmSPJ caIRK/R38udpI6Xx3CK8gWjl5H3FCSQbi4PcemioAZXR+rITc1PfG09MLK0AMRbUYZU7 kC0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id m21-v6si1431024qtb.280.2018.09.29.01.43.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 01:43:34 -0700 (PDT) Received-SPF: pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 203D688306; Sat, 29 Sep 2018 08:43:34 +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 C5694106A790; Sat, 29 Sep 2018 08:43:29 +0000 (UTC) From: Peter Xu To: linux-kernel@vger.kernel.org Cc: Shuah Khan , Jerome Glisse , Mike Rapoport , Mike Kravetz , 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 3/3] userfaultfd: selftest: recycle lock threads first Date: Sat, 29 Sep 2018 16:43:11 +0800 Message-Id: <20180929084311.15600-4-peterx@redhat.com> In-Reply-To: <20180929084311.15600-1-peterx@redhat.com> References: <20180929084311.15600-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 29 Sep 2018 08:43:34 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Peter Xu Acked-by: Mike Rapoport --- 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 f79706f13ce7..a388675b15af 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -623,6 +623,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) { @@ -640,11 +646,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; }