From patchwork Sun Sep 30 07:42:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10621177 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 0582814BD for ; Sun, 30 Sep 2018 07:43:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDD4B295D5 for ; Sun, 30 Sep 2018 07:43:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E179F295DE; Sun, 30 Sep 2018 07:43:16 +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 01E3A295DD for ; Sun, 30 Sep 2018 07:43:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCA6A8E0003; Sun, 30 Sep 2018 03:43:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D7A698E0001; Sun, 30 Sep 2018 03:43:13 -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 C6AAB8E0003; Sun, 30 Sep 2018 03:43:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 9E8688E0001 for ; Sun, 30 Sep 2018 03:43:13 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id l22-v6so10591072qtr.3 for ; Sun, 30 Sep 2018 00:43:13 -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=VGugSaH/p+7KRxdn9p/o8GvL8kFfpigjCC8IwUdpNAs=; b=abcmbTe4B9JOqtJNdKnqwBb6hFZM++mhaax0C4R+aiuxI87OI3ifIClqV60BsV6voa 7GMboRIgAXX0Abl+Fvhc1d/lqFH7drkMGZIN+aS/sXF3AKg/hPavRTUsT2tZrTCN3UH4 BwIZ1wkHHpvLH3sJsZM1mtZ1HeO6gBdu0iYbbVx/sAs8QEjCa9HFSY+kQVQQzsE1j+CJ ScW/NDsC5wIh5YOQXzvBqng3PPMl5tXgzJ5G38gsbiTdb/sFjMrAGUBca190CfKa59qI 00iBixl0/5arXrbEnACrobuwUhWN2mo8zN6gcqNfCl44vMefRHnmcjHJRTyWpGNL3Wmb BZCA== 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: ABuFfoin3zAoLAdF71pdvRqYsW8mwRKkP0Nm8GuSOu+QbUGCWT30AjgG kUUSfDjuPWPbfriv5u8ZX8/7IXHqbaZ8ChSctGpSFm/r7+mKzVDNfBAyyEJbuemSMmBwWSc1uRU AMaeJzp6m5AjbXCcX1wEgQxGV/IdhN83ovQcUUnuriPYGfu7HCPZdC5tjS1VSm87fVQ== X-Received: by 2002:aed:35cd:: with SMTP id d13-v6mr4669537qte.212.1538293393366; Sun, 30 Sep 2018 00:43:13 -0700 (PDT) X-Google-Smtp-Source: ACcGV61gjEI9kK19mH2T97FnZ873CNfTHacJbCDQ9tsRjjjVrvCI/6aDFvBSxeXnl3x4VnG/V3ad X-Received: by 2002:aed:35cd:: with SMTP id d13-v6mr4669524qte.212.1538293392828; Sun, 30 Sep 2018 00:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538293392; cv=none; d=google.com; s=arc-20160816; b=TiZQsKGzWGgHAyl9rLUCQZnWzHytgb0xuUTDgKmxGXy4Jeikm9gsvqKcjQ1qDXqMMr ZmuxzUiW/SGktzqemrijv6rBy/rtrqsCoqUS0sR+JEFuv5NqeV8o+E/U/9/+0YaocTQr TELRAJx0BSSpOwWtEeEZjwwPCk1QSC9sUIzW9wKhWNXxaCHJ6xs7kSAJMeXSfTzURrOi 8iV9XjWRU+07ZxDgrOsOUfu54wzPohhg74GdO4rSMX3bJOK+wMWP2coWecmOxkqwWE76 Eyw6gfL4/608Xfit6Z6aL9KqdaG+ZcbPvMt//cMlUM3moJGk+jcO/A5Vh0XO4Xclb/nX W7kw== 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=VGugSaH/p+7KRxdn9p/o8GvL8kFfpigjCC8IwUdpNAs=; b=y8DnLrZ0IP6hg36gWGOrtIPwKQO9N8CW6yvaBeMxhgCvP/eRwlchKe0ioh+cQgWdQe kD8yKmGl2w0DxKbQfu6ssSWejQ9ooumWxbMCpdUFEGRYZN9btCLvKXeCNyZZdFxqBm5E rsLInajSwEnYnzDGUT6mE9cMXE59h9G5ZqzPMxNZSctxti/MuifSis5aqJvcpT0s7A3y zFeRLKAUAGtoFRzJBppRcLF1gfnuBLKW55EiexCOBGEclwYKve+GE7UalGuEp+0sqwwT czr14Dqhh/LNl3GM281O0djvtGQsIYZxOSe/4GyHWY+V05qd6h3UV19ruAF6ZgtkLqp9 Z5oA== 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 d2-v6si2364505qvn.206.2018.09.30.00.43.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 00:43:12 -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-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 F2B734E90D; Sun, 30 Sep 2018 07:43:11 +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 AAF8A60164; Sun, 30 Sep 2018 07:43:07 +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 1/3] userfaultfd: selftest: cleanup help messages Date: Sun, 30 Sep 2018 15:42:57 +0800 Message-Id: <20180930074259.18229-2-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.38]); Sun, 30 Sep 2018 07:43:12 +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 Firstly, the help in the comment region is obsolete, now we support three parameters. Since at it, change it and move it into the help message of the program. Also, the help messages dumped here and there is obsolete too. Use a single usage() helper. Acked-by: Mike Rapoport Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 46 ++++++++++++++---------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 7b8171e3128a..5ff3a4f9173e 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -34,18 +34,6 @@ * per-CPU threads 1 by triggering userfaults inside * pthread_mutex_lock will also verify the atomicity of the memory * transfer (UFFDIO_COPY). - * - * The program takes two parameters: the amounts of physical memory in - * megabytes (MiB) of the area and the number of bounces to execute. - * - * # 100MiB 99999 bounces - * ./userfaultfd 100 99999 - * - * # 1GiB 99 bounces - * ./userfaultfd 1000 99 - * - * # 10MiB-~6GiB 999 bounces, continue forever unless an error triggers - * while ./userfaultfd $[RANDOM % 6000 + 10] 999; do true; done */ #define _GNU_SOURCE @@ -115,6 +103,30 @@ pthread_attr_t attr; ~(unsigned long)(sizeof(unsigned long long) \ - 1))) +const char *examples = + "# Run anonymous memory test on 100MiB region with 99999 bounces:\n" + "./userfaultfd anon 100 99999\n\n" + "# Run share memory test on 1GiB region with 99 bounces:\n" + "./userfaultfd shmem 1000 99\n\n" + "# Run hugetlb memory test on 256MiB region with 50 bounces (using /dev/hugepages/hugefile):\n" + "./userfaultfd hugetlb 256 50 /dev/hugepages/hugefile\n\n" + "# Run the same hugetlb test but using shmem:\n" + "./userfaultfd hugetlb_shared 256 50 /dev/hugepages/hugefile\n\n" + "# 10MiB-~6GiB 999 bounces anonymous test, " + "continue forever unless an error triggers\n" + "while ./userfaultfd anon $[RANDOM % 6000 + 10] 999; do true; done\n\n"; + +static void usage(void) +{ + fprintf(stderr, "\nUsage: ./userfaultfd " + "[hugetlbfs_file]\n\n"); + fprintf(stderr, "Supported : anon, hugetlb, " + "hugetlb_shared, shmem\n\n"); + fprintf(stderr, "Examples:\n\n"); + fprintf(stderr, examples); + exit(1); +} + static int anon_release_pages(char *rel_area) { int ret = 0; @@ -1272,8 +1284,7 @@ static void sigalrm(int sig) int main(int argc, char **argv) { if (argc < 4) - fprintf(stderr, "Usage: [hugetlbfs_file]\n"), - exit(1); + usage(); if (signal(SIGALRM, sigalrm) == SIG_ERR) fprintf(stderr, "failed to arm SIGALRM"), exit(1); @@ -1286,20 +1297,19 @@ int main(int argc, char **argv) nr_cpus; if (!nr_pages_per_cpu) { fprintf(stderr, "invalid MiB\n"); - fprintf(stderr, "Usage: \n"), exit(1); + usage(); } bounces = atoi(argv[3]); if (bounces <= 0) { fprintf(stderr, "invalid bounces\n"); - fprintf(stderr, "Usage: \n"), exit(1); + usage(); } nr_pages = nr_pages_per_cpu * nr_cpus; if (test_type == TEST_HUGETLB) { if (argc < 5) - fprintf(stderr, "Usage: hugetlb \n"), - exit(1); + usage(); huge_fd = open(argv[4], O_CREAT | O_RDWR, 0755); if (huge_fd < 0) { fprintf(stderr, "Open of %s failed", argv[3]); From patchwork Sun Sep 30 07:42:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10621179 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 397DB15A7 for ; Sun, 30 Sep 2018 07:43:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CAD3295D5 for ; Sun, 30 Sep 2018 07:43:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2082A295E3; Sun, 30 Sep 2018 07:43:21 +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 DB847295D5 for ; Sun, 30 Sep 2018 07:43:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABDDA8E0004; Sun, 30 Sep 2018 03:43:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A6C908E0001; Sun, 30 Sep 2018 03:43:18 -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 984378E0004; Sun, 30 Sep 2018 03:43:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 68A5B8E0001 for ; Sun, 30 Sep 2018 03:43:18 -0400 (EDT) Received: by mail-qt1-f199.google.com with SMTP id a26-v6so5395727qtb.22 for ; Sun, 30 Sep 2018 00:43:18 -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=9n1oKLJ3RGsLL5H5sw+MzDdr6BZPb2MRjost1v5zfrc=; b=VMzWc1WI91tGL6MNZUxwzLaF80iCnQ9L0jf1RUughm2UAb6rUvBq6CBgI2lpxGDOY5 Yhj6INXbtn/rNRIERyojFCIOXyLW/fvyTdyvcL11Q3ONa8BTgZkaVW0Vw2AweRuAHM3W YQnE/MBqtlXZsvCkEd0IzBEm5PRpeaydv07eSgDJt4QybxUF1CpidevkTCbh/bK0yZkP pu04x0DEk5LEYhJoI1c45scRBQkIDAeio3t4xNvP5/vTZ2vLhKUZl20Tzdj4KS3hztBZ p7pJNRTfo+BiV0UPezhR9oleQRvG/gmFfyas8l7c0d6GStfNwkxfuETsJ+Z+9tuMbjRz JZrw== 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: ABuFfoiraSYSHlQ1sGLtCnpcuy5cOKEPRkZqRPCsgDvZpP257VAtLv5p nP/QU8NOFQGQ2BGvuoQ2lT7Gz27AcAtARaTfIn+/GIY9GqbBDW4jK68PleN+o75UwNabu69xEgO AaZ4BPhN4XWKwH1NMbLyjnVFFON7UPYwMngwbserrNFPYz5D+cqxOJobydxmveUB2LQ== X-Received: by 2002:ac8:2a13:: with SMTP id k19-v6mr4423384qtk.245.1538293398200; Sun, 30 Sep 2018 00:43:18 -0700 (PDT) X-Google-Smtp-Source: ACcGV61PQz7rl9Xzxs1oCFuC76A5uyeT21wio26GajfFb4yIymmp3OHoV5s+vSovpH4Ckoatixgf X-Received: by 2002:ac8:2a13:: with SMTP id k19-v6mr4423373qtk.245.1538293397631; Sun, 30 Sep 2018 00:43:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538293397; cv=none; d=google.com; s=arc-20160816; b=JyPF5n3V0ZfY7Y9ndzL5VstAvuCr7cYsqQ8WKle5PUuMcTXMsMci72t8O4KXNCiV4P aCNJjNteW5bnzfB99yNokTvQtXF6WphInG3ymVaWEpgcLCNf+nrOY2Gwudh3NLHHJ/5I AYumm0rCIRRPbJNznlaDwOS4W0zyjgvzCFOHTXaG/yhwiN8XJOhsAQPhNigd8Ktu88Vz j+LaX9FNjcwjVwTvEuEYgZeGHSGseWrl9+OhN8lIXSM7mugzoivSzVYMJvtfUPQ8WTik HKU3Mu3imDblyWVEs3W6NeUjO0xkvTxsbwslV5+ZN6sszmHYOOXH/A9cG6FjQEdvG+ZA ez0A== 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=9n1oKLJ3RGsLL5H5sw+MzDdr6BZPb2MRjost1v5zfrc=; b=LxtBvvDYisqtEHYkQgn5e34MUDnpbC5DeUqwEv1yxyzQerzd8vmc6i1CDp729uZoSw V9sNpclytiSF3NVka/rKeX9vDZZmCGHimDdN75xcitxvMcEBTaVNVHuxGjVmaAXaVHrL rPJ8A1G85ZgcwykuBBp1mzqggUUBZNaE6Fa3kqCASKnQr7vjIoPF6ZLuXAMcP47Yo2M4 Q0g7jY/jDYGiKLmBN0df+ZRHztq6kX+6Xgrw48rZ2gg3Yn6pIL0NZ22+FfeJhk1LYvgf NeOKsTU6Xueuz7Gg9Ht260HRKJ/5+GU+X7LGcKQ2ovRfuhp8KfOLyQJbJjF0MZ0PGGfQ PlGg== 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 k66-v6si1837815qke.234.2018.09.30.00.43.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 00:43:17 -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-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 C26BA81F0B; Sun, 30 Sep 2018 07:43:16 +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 786306016F; Sun, 30 Sep 2018 07:43:12 +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 2/3] userfaultfd: selftest: generalize read and poll Date: Sun, 30 Sep 2018 15:42:58 +0800 Message-Id: <20180930074259.18229-3-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.27]); Sun, 30 Sep 2018 07:43:16 +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 We do very similar things in read and poll modes, but we're copying the codes around. Share the codes properly on reading the message and handling the page fault to make the code cleaner. Meanwhile this solves previous mismatch of behaviors between the two modes on that the old code: - did not check EAGAIN case in read() mode - ignored BOUNCE_VERIFY check in read() mode Signed-off-by: Peter Xu Acked-by: Mike Rapoport --- tools/testing/selftests/vm/userfaultfd.c | 77 +++++++++++++----------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 5ff3a4f9173e..7a8c6937cc67 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -451,6 +451,43 @@ static int copy_page(int ufd, unsigned long offset) return __copy_page(ufd, offset, false); } +static int uffd_read_msg(int ufd, struct uffd_msg *msg) +{ + int ret = read(uffd, msg, sizeof(*msg)); + + if (ret != sizeof(*msg)) { + if (ret < 0) { + if (errno == EAGAIN) + return 1; + else + perror("blocking read error"), exit(1); + } else { + fprintf(stderr, "short read\n"), exit(1); + } + } + + return 0; +} + +/* Return 1 if page fault handled by us; otherwise 0 */ +static int uffd_handle_page_fault(struct uffd_msg *msg) +{ + unsigned long offset; + + if (msg->event != UFFD_EVENT_PAGEFAULT) + fprintf(stderr, "unexpected msg event %u\n", + msg->event), exit(1); + + if (bounces & BOUNCE_VERIFY && + msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) + fprintf(stderr, "unexpected write fault\n"), exit(1); + + offset = (char *)(unsigned long)msg->arg.pagefault.address - area_dst; + offset &= ~(page_size-1); + + return copy_page(uffd, offset); +} + static void *uffd_poll_thread(void *arg) { unsigned long cpu = (unsigned long) arg; @@ -458,7 +495,6 @@ static void *uffd_poll_thread(void *arg) struct uffd_msg msg; struct uffdio_register uffd_reg; int ret; - unsigned long offset; char tmp_chr; unsigned long userfaults = 0; @@ -482,25 +518,15 @@ static void *uffd_poll_thread(void *arg) if (!(pollfd[0].revents & POLLIN)) fprintf(stderr, "pollfd[0].revents %d\n", pollfd[0].revents), exit(1); - ret = read(uffd, &msg, sizeof(msg)); - if (ret < 0) { - if (errno == EAGAIN) - continue; - perror("nonblocking read error"), exit(1); - } + if (uffd_read_msg(uffd, &msg)) + continue; switch (msg.event) { default: fprintf(stderr, "unexpected msg event %u\n", msg.event), exit(1); break; case UFFD_EVENT_PAGEFAULT: - if (msg.arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) - fprintf(stderr, "unexpected write fault\n"), exit(1); - offset = (char *)(unsigned long)msg.arg.pagefault.address - - area_dst; - offset &= ~(page_size-1); - if (copy_page(uffd, offset)) - userfaults++; + userfaults += uffd_handle_page_fault(&msg); break; case UFFD_EVENT_FORK: close(uffd); @@ -528,8 +554,6 @@ static void *uffd_read_thread(void *arg) { unsigned long *this_cpu_userfaults; struct uffd_msg msg; - unsigned long offset; - int ret; this_cpu_userfaults = (unsigned long *) arg; *this_cpu_userfaults = 0; @@ -538,24 +562,9 @@ static void *uffd_read_thread(void *arg) /* from here cancellation is ok */ for (;;) { - ret = read(uffd, &msg, sizeof(msg)); - if (ret != sizeof(msg)) { - if (ret < 0) - perror("blocking read error"), exit(1); - else - fprintf(stderr, "short read\n"), exit(1); - } - if (msg.event != UFFD_EVENT_PAGEFAULT) - fprintf(stderr, "unexpected msg event %u\n", - msg.event), exit(1); - if (bounces & BOUNCE_VERIFY && - msg.arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) - fprintf(stderr, "unexpected write fault\n"), exit(1); - offset = (char *)(unsigned long)msg.arg.pagefault.address - - area_dst; - offset &= ~(page_size-1); - if (copy_page(uffd, offset)) - (*this_cpu_userfaults)++; + if (uffd_read_msg(uffd, &msg)) + continue; + (*this_cpu_userfaults) += uffd_handle_page_fault(&msg); } return (void *)NULL; } From patchwork Sun Sep 30 07:42:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10621181 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 E587515A7 for ; Sun, 30 Sep 2018 07:43:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D94AF295D2 for ; Sun, 30 Sep 2018 07:43:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD993295DD; Sun, 30 Sep 2018 07:43:24 +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 6E586295D2 for ; Sun, 30 Sep 2018 07:43:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 567728E0005; Sun, 30 Sep 2018 03:43:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5147D8E0001; Sun, 30 Sep 2018 03:43:23 -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 404C58E0005; Sun, 30 Sep 2018 03:43:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by kanga.kvack.org (Postfix) with ESMTP id 153BC8E0001 for ; Sun, 30 Sep 2018 03:43:23 -0400 (EDT) Received: by mail-qt1-f198.google.com with SMTP id d1-v6so10426896qth.21 for ; Sun, 30 Sep 2018 00:43:23 -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=cbgn7B/FkjDMiVL7cNiqyvSHGP4pWU7H+r/K6/oK8y4=; b=fvp4bmYpnc+TbSGt/wNYR6Hgy5emcl9LEKf7O2K6lJETxaAOQuRM2azTvDNc17HESv Q+pgswMkfPt3YWF6X4CtHwuBLBjajao5EdpTRALWSdIFitNQi+Q/Gl2/oYJG/y1m2gz7 4xmNd9qzfQF2+5Nm0zutEJnBvtqXW4Q0fGwMXWRW/k6qKr6A/fu41WzCcJ+deaswyPe9 agqdPUKuHvY8g/CMWcNe4rgajkbmCWDfaKjPc0FEQEAjfZ1m2f9XMotBXbDk7BSrJ52f HV+UlAXB5IxGx3zGB41eRnLEIlR3SMz+mLHNQDtjG7G5FkH66H5rlmwCxxE5ToHAJg2z 8XRA== 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: ABuFfoiGuRvUUszKMV3k2IxMAdljV5IR823oS1IYgd1AGSNSu0DNbFiJ dju4FOyVzCHOpUyJ1HiQ52YfMHlpDmEQtAoJJZ7LQsLT/4Ku0ykk0WTAoZbv9lTsU07q3JiAFsX NGE9Wy28jDqwgkiGs9rLFfSnKx1rzi/Ii1hzuMhlWKjR9N513DZeoKmP4lScHsX/2Jg== X-Received: by 2002:ac8:1c1a:: with SMTP id a26-v6mr4575217qtk.16.1538293402872; Sun, 30 Sep 2018 00:43:22 -0700 (PDT) X-Google-Smtp-Source: ACcGV632CI0JwN49/wivt4rC1iBDQK+5e/Qpp+BRyOfEuRZKmqHDfgEE8d9LA51TZYgnkc/S7+eM X-Received: by 2002:ac8:1c1a:: with SMTP id a26-v6mr4575208qtk.16.1538293402404; Sun, 30 Sep 2018 00:43:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538293402; cv=none; d=google.com; s=arc-20160816; b=n4+YfAPgTq1mcd/myf4LfLZILEaATwP4dg1FJgsxNy6x2JqPr+pLHI0M29J4CrKpfO 2g6shrh3B0dp9ZxX1QNd4kkDW43NdI+gIm4nGMETWhLR2FQcQN2Tw58wv9gXciCmNx0i EcHh/Pew/oKNH2A3LrZ8nMP8PB5J2vuMmWCIHkrxZy1gl3W3+YBWdCcyLp42aK4GKSnv +jzbb5K59Q06P1yzKo3kaOMSYcSs8hAHXgyh1Wr3+CEtCkmgmUDjSGzTjjch2DbncGBd LRZqgE7hmof7mGTETxut0LGjRczlYzl9VLCisqBkqgTQOrUDehb/W7NVqXUqtt2anfYu 5lAQ== 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=cbgn7B/FkjDMiVL7cNiqyvSHGP4pWU7H+r/K6/oK8y4=; b=jcIDZ35Mvse5DGFCHXzAntbeyC+8Tfbh7CVYDhpiKSvz+bU4CpcJd3xWfnHZ+QtZ35 yHrOF/3mGH3jp12nmg57bxd+xa99NAIsSPFiovtwLCCH4uT5SXll8paUA/7AxMvgEIG4 q/a1Uu3f7mBgqlAP+h9Ab5ZJcvvjkXE7PANdGhy/M3pNgimxjHB8ZUApVs3Kn7TzjNTP PSthdzS/aR6yaauDtRKTH6Agmf0I0TMbrHg0Yk+oJa80go4kDkM4A7VADPjKhjdWh6/c AoHNA2QM9hfBKRZNphy0Ixt7ypRdVdZLZp7Z+jmJzK5nnY01CHRib5+DSTtaTiRHJxLe QKUg== 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 t41-v6si7089274qth.214.2018.09.30.00.43.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 00:43:22 -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-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) 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. 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; }