Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1682707imm; Sat, 29 Sep 2018 01:44:54 -0700 (PDT) X-Google-Smtp-Source: ACcGV63ITRG1KWLLFafeoPaLrTixls0BQCMGH4B9dJlY+V5dZ82i06gYAgmgUCh8ybFkSckHYtwR X-Received: by 2002:a17:902:bb90:: with SMTP id m16-v6mr2261057pls.254.1538210694644; Sat, 29 Sep 2018 01:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538210694; cv=none; d=google.com; s=arc-20160816; b=ei6KSg0NEMSXGu4nLa4CvA86K/Qyl0Q78gW4h6AgGWKc575ZFZPnDXP4Z/nNM8w8jc 5U0LaGTzDi8xXCDMpG3r1A5jbcEZ2BmpX0ou+4IwpqhwHw3sdGA/q4P3Z0+OGxY05Jlw G3oocLcSxcca0Ws+JAMO4+U8mxMngteiCjerznl4WpNz3cNht61dhHBwZIynK5FD7LmR YIs+FlqiZQ/VqR0ccOyespftP+AjHjpXQjyeDTuUfszyR9YkIe6m/MCanToJ5E4FTHeN 0UfDLEDHe6dJnXfqoePWPaAcKojfi7mI5UwAUcLVzX6OOdHK6fE/9AkClAUZlDKxzLg3 4lrw== 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=05flFEVEhG7qTUpNjE7Sf2JlGt3wwT/uLXi6I+/HmrI=; b=Y9ZuL4I44TkAa7p5OnRpTU2GaoANpP5ViDDMwCJOikKXO8bYutkJSLTjPsIdTSil2E JSRA7dPXn/i27isLP9qIB38V8PFwFatwiA6pG1rNlY2DIHYPQHujFaQ1jz5VyneTnGWS NHwvK8oaJmdOGb8T38L7VyzU0QFNJxcFnphBEzR2M0xtaVNA4V1T8fHO7ieLUgl764Gn laJcSpzHoipr2cC4AKffVA2YlAtpgpQvtLbmkmvCY9xje0Km1QNkxGDoI2YiZnsK2JsH m21aXhdt0VY8aXIppLMT22M2o0N6m4ivLfBLuU3Bx/5A0vY2patt/wnpTEFL3iT8DBfY v6ow== 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 77-v6si7705051pfu.154.2018.09.29.01.44.39; Sat, 29 Sep 2018 01:44:54 -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 S1727882AbeI2PLK (ORCPT + 99 others); Sat, 29 Sep 2018 11:11:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37066 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727637AbeI2PLJ (ORCPT ); Sat, 29 Sep 2018 11:11:09 -0400 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) 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. 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 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; } -- 2.17.1