Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5879563ioo; Wed, 1 Jun 2022 14:50:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXh81m4/Hjnu3EzS9SvqLDrr+XuPeg5UeU3/gKoh9u81cTRdGnjTPuHb+Acrq+m25cgSI1 X-Received: by 2002:a63:e15:0:b0:3fb:a607:40c0 with SMTP id d21-20020a630e15000000b003fba60740c0mr1282713pgl.300.1654120201121; Wed, 01 Jun 2022 14:50:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654120201; cv=none; d=google.com; s=arc-20160816; b=qsOHaAcsxoEMDfxF/LhNrvzNE8dHeseeHesPQRXYcM6fk/rdDN8y2yqs4gYUXuMnq4 xoPPQOFe03RHldwpEaLAT5KTW0CQnfVIzE69dohFrIz5Yygbg7bPSu02h9R3cvPHdKVd LuIQQSBALEsRoITgL9/Dd1o1gp18p8f9gtjgbbsh81cg8oj/hMG+cVJtQckOCHFSdjJ4 NaCSSlw3sxsnJO8jQNVEp4vgM/jnRZiWAnlcELAgPG4NqsGjvTygoF+WKyHEBRNtTb0/ 7w4rjEUr1eKWK8N/fAIJ9gFaf6W0d4mkWAcMXmV6Sd32XndzN1aiYboYPj2gMe6ATY+r kIRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=dcDBeY/HLlNXef9d9FAHPxWe/EV2aZU1witDOt2KoeY=; b=uDH98nbdwOb+Bnye9Cwgo0ymdyhwp4CJsaSAUv552HKg4auS/bPaXfijsbWEElwCvH 9MsCbz+sDtV0+agWlsESMmi2I+uCBwnDQKZSML0orEQTbwq6NFRRSLP6HijofQd/TeYY f+jZ0gETksS7x6OBA2DxYMeJJps55GPIaMqEpnzh1tfL0N5/2wVkCDLLZeEYvfQUNUur kRvKP6chIZUUaIK47mvTPE5QDQy8WNpf2YBow3cr10YySrj3r/Eg0R8FT2/lNjl3BdR5 HUL4EjuLzTjMGGFGNVvAYq+Xw9bFk2vmVSy6t43/iivVQUom4K5p+gzJDIzCmZp03pJo PdFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KaDwHX79; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id co18-20020a17090afe9200b001e312672c02si3537610pjb.30.2022.06.01.14.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 14:50:01 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KaDwHX79; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 520B856C04; Wed, 1 Jun 2022 14:10:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231297AbiFAVK3 (ORCPT + 99 others); Wed, 1 Jun 2022 17:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231319AbiFAVKK (ORCPT ); Wed, 1 Jun 2022 17:10:10 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0C2739BB1 for ; Wed, 1 Jun 2022 14:10:06 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2f4e17a5809so25911117b3.2 for ; Wed, 01 Jun 2022 14:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=dcDBeY/HLlNXef9d9FAHPxWe/EV2aZU1witDOt2KoeY=; b=KaDwHX79CJbASDMmgXRlKLc/huskW7utSclJ0kfppbnZS1T/syXXX0OOqqco2+9elP 5EBfVeZWFsTr/FQRRajBdxKDD8WMBg7o9fiYLOlSBVHnkUMU6qLlmQ8wbxRiy97vjj1n d1MHsEJH+Fi8Yb2ErPHvZ95O8Pno4nEVoSdAmNwSrCbw8KI+39rmeI321hQC0x1VXEWa VizEGAex47VEQ4UJzuGfcJgV8KzlCSFFPFdauODxm1cORxr0QYeWj8tzyU2u86tekVow Y2TOE/hImTDvfKNFRWfSNAw6WFb0njnagrXm1EE2xQotfnLtM0lz0f8/yYojMTbYOQce HPJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=dcDBeY/HLlNXef9d9FAHPxWe/EV2aZU1witDOt2KoeY=; b=IQQDTowk0q7ptgv9lPTQ4eIvlOwmyY1UNCUpVuU3xzYyctjCPEm2IdylOOtHSmrhD+ lPAcS9zABFUopCqdpFc5m7763JfI/6WqZX4cbC/pGXNTT93BvEoDmWZqh7iW0PUaHkdr psBVSPC3m+995tF0H4ps+RbYdghVJTX2CIATmsHgivanD4dQPA+F9xRY6/jo+EVd3lBJ NQrZvy32Y/3MygIv05oqz2uWmiT8KyfIiou8PpjD9zRhpOBXgG7cS4APmxlqTytYHRzT 1d1cN4AV9PuWlopoudJ85KImj6fFtqCCIlFkJV15Uy3L3h3I65ji/e5PTx2uFDgbPo7e mnyg== X-Gm-Message-State: AOAM5333PRa6IxXCartrek25wPs7hR9hfFgnnFmPEomJTLVNoS1Rm4Dv Ss3BHol6cmgQuIlBMiL1cwZvlFG8gb0SvIrBIYDv X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:aaec:e358:9f0e:2b26]) (user=axelrasmussen job=sendgmr) by 2002:a25:744:0:b0:64f:79e5:6528 with SMTP id 65-20020a250744000000b0064f79e56528mr1969376ybh.104.1654117805867; Wed, 01 Jun 2022 14:10:05 -0700 (PDT) Date: Wed, 1 Jun 2022 14:09:50 -0700 In-Reply-To: <20220601210951.3916598-1-axelrasmussen@google.com> Message-Id: <20220601210951.3916598-6-axelrasmussen@google.com> Mime-Version: 1.0 References: <20220601210951.3916598-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH v3 5/6] userfaultfd: selftests: make /dev/userfaultfd testing configurable From: Axel Rasmussen To: Alexander Viro , Andrew Morton , Charan Teja Reddy , Dave Hansen , "Dmitry V . Levin" , Gleb Fotengauer-Malinovskiy , Hugh Dickins , Jan Kara , Jonathan Corbet , Mel Gorman , Mike Kravetz , Mike Rapoport , Nadav Amit , Peter Xu , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , zhangyi Cc: Axel Rasmussen , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Instead of always testing both userfaultfd(2) and /dev/userfaultfd, let the user choose which to test. As with other test features, change the behavior based on a new command line flag. Introduce the idea of "test mods", which are generic (not specific to a test type) modifications to the behavior of the test. This is sort of borrowed from this RFC patch series [1], but simplified a bit. The benefit is, in "typical" configurations this test is somewhat slow (say, 30sec or something). Testing both clearly doubles it, so it may not always be desirable, as users are likely to use one or the other, but never both, in the "real world". [1]: https://patchwork.kernel.org/project/linux-mm/patch/20201129004548.1619714-14-namit@vmware.com/ Signed-off-by: Axel Rasmussen --- tools/testing/selftests/vm/userfaultfd.c | 41 +++++++++++++++++------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 1badb5d31bf9..aeee6f1ad8ef 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -128,6 +128,8 @@ struct uffd_stats { const char *examples = "# Run anonymous memory test on 100MiB region with 99999 bounces:\n" "./userfaultfd anon 100 99999\n\n" + "# Run the same anonymous memory test, but using /dev/userfaultfd:\n" + "./userfaultfd anon:dev 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:\n" @@ -144,6 +146,13 @@ static void usage(void) "[hugetlbfs_file]\n\n"); fprintf(stderr, "Supported : anon, hugetlb, " "hugetlb_shared, shmem\n\n"); + fprintf(stderr, "'Test mods' can be joined to the test type string with a ':'. " + "Supported mods:\n"); + fprintf(stderr, "\tdev - Use /dev/userfaultfd instead of userfaultfd(2)\n"); + fprintf(stderr, "\nExample test mod usage:\n"); + fprintf(stderr, "# Run anonymous memory test with /dev/userfaultfd:\n"); + fprintf(stderr, "./userfaultfd anon:dev 100 99999\n\n"); + fprintf(stderr, "Examples:\n\n"); fprintf(stderr, "%s", examples); exit(1); @@ -1607,8 +1616,6 @@ unsigned long default_huge_page_size(void) static void set_test_type(const char *type) { - uint64_t features = UFFD_API_FEATURES; - if (!strcmp(type, "anon")) { test_type = TEST_ANON; uffd_test_ops = &anon_uffd_test_ops; @@ -1626,10 +1633,28 @@ static void set_test_type(const char *type) test_type = TEST_SHMEM; uffd_test_ops = &shmem_uffd_test_ops; test_uffdio_minor = true; - } else { - err("Unknown test type: %s", type); + } +} + +static void parse_test_type_arg(const char *raw_type) +{ + char *buf = strdup(raw_type); + uint64_t features = UFFD_API_FEATURES; + + while (buf) { + const char *token = strsep(&buf, ":"); + + if (!test_type) + set_test_type(token); + else if (!strcmp(token, "dev")) + test_dev_userfaultfd = true; + else + err("unrecognized test mod '%s'", token); } + if (!test_type) + err("failed to parse test type argument: '%s'", raw_type); + if (test_type == TEST_HUGETLB) page_size = default_huge_page_size(); else @@ -1676,7 +1701,7 @@ int main(int argc, char **argv) err("failed to arm SIGALRM"); alarm(ALARM_INTERVAL_SECS); - set_test_type(argv[1]); + parse_test_type_arg(argv[1]); nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); nr_pages_per_cpu = atol(argv[2]) * 1024*1024 / page_size / @@ -1714,12 +1739,6 @@ int main(int argc, char **argv) } printf("nr_pages: %lu, nr_pages_per_cpu: %lu\n", nr_pages, nr_pages_per_cpu); - - test_dev_userfaultfd = false; - if (userfaultfd_stress()) - return 1; - - test_dev_userfaultfd = true; return userfaultfd_stress(); } -- 2.36.1.255.ge46751e96f-goog