From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C128EC433EF for ; Wed, 20 Oct 2021 18:29:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 495F3610A1 for ; Wed, 20 Oct 2021 18:29:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 495F3610A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BBD8294000E; Wed, 20 Oct 2021 14:29:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6D0D900003; Wed, 20 Oct 2021 14:29:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5BC694000E; Wed, 20 Oct 2021 14:29:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0191.hostedemail.com [216.40.44.191]) by kanga.kvack.org (Postfix) with ESMTP id 95CDC900003 for ; Wed, 20 Oct 2021 14:29:27 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3880E284A3 for ; Wed, 20 Oct 2021 18:29:27 +0000 (UTC) X-FDA: 78717653574.16.5CF8B4F Received: from mail-io1-f41.google.com (mail-io1-f41.google.com [209.85.166.41]) by imf03.hostedemail.com (Postfix) with ESMTP id 65CB83000099 for ; Wed, 20 Oct 2021 18:29:24 +0000 (UTC) Received: by mail-io1-f41.google.com with SMTP id b188so20936105iof.8 for ; Wed, 20 Oct 2021 11:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=q89oVyQBTUak6GonDhBQZ4EDfITIyfwn25FBB5afZ4A=; b=PivA0O37xPWODAtgcpFLG2r/iqzG5FxY0Z1hpYBfW6VZg5VIOVXpfMnxgJvbGRxTMI oD1HfkQFsFxt618Dy2o5t7Pmn99nl9ZFhg6kHos74iCwpoSWpazp9IlHtWEAu6qZMZHq 8tZGm/Jiz3KskWvoD3ZaJ3NODAa9KdLaa3wmG08Y6A6BslHnZza1nz0bs9hg1V1tASEN d4gVv9Q6EvK4gJrwPtDXDVaNJTEQyDiI6x7k3wxcB3yKnMhs1tauwPjWlai9SZ5UaoB9 qrPMPMNaVWpm8lxt45Shm0bVBGupNiefNymH/IoHyGOMwHgYK9HzdiXhFZEssPCtXp9Y 74/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=q89oVyQBTUak6GonDhBQZ4EDfITIyfwn25FBB5afZ4A=; b=kHlXef/TkUeMfNiUEEbPHAmQsYXdxgZ2vRn6SEmjbRQaDK51Bg3kqAHDy4sK0Ozqzd VyLnRLZR8o0QoX8HEsw70SjU/HdYGC63LUs2DRv/obDRpXcZl/oSDzPVWw96M1HIzMKu iDgCkQF5Dy9lMZsYxVAPm+PWIFRrlrA2WAGJt06fv/JyTxIhH/m8cVqHgBHvtSoE/Xtr u6o0uF0EagFe921nhEgSr0fVBrWlYRmzm4C+A5FezyFu06qNvJLDEJLkCV7OZkoLVzF8 O0sM7HJqwBtKhDQ3Mb9NlJ3cQ0bEm6D7lvOlN6nhr6tjI1nBN20zZ8TKg8a3y+L0+O8W K5SA== X-Gm-Message-State: AOAM532aHm3WPFz088hnYKDVr0iwMxUwOnWcPVRBHd+3Zt8rDc55a/dU Zf9411emmTb7SvKrL9Z8AAFyML63qkY7xiJeT3lKgieYMtg= X-Google-Smtp-Source: ABdhPJwkWpvxOxpujW3lsZJOksr9h84iP/TYpMsyjLLw3iXEacR6REvlDPfOHJXHv8y2tSgP93ld1vQs3EtYLRu3cFg= X-Received: by 2002:a6b:f614:: with SMTP id n20mr618747ioh.134.1634754565966; Wed, 20 Oct 2021 11:29:25 -0700 (PDT) MIME-Version: 1.0 References: <20210930212309.4001967-1-axelrasmussen@google.com> <20210930212309.4001967-3-axelrasmussen@google.com> In-Reply-To: <20210930212309.4001967-3-axelrasmussen@google.com> From: Axel Rasmussen Date: Wed, 20 Oct 2021 11:28:49 -0700 Message-ID: Subject: Re: [PATCH v2 2/3] userfaultfd/selftests: fix feature support detection To: Andrew Morton , Peter Xu , Shuah Khan Cc: Linux MM , Linuxkselftest , LKML Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 65CB83000099 X-Stat-Signature: fyq5s4pxsq9up79wc653h5opk6cpqejg Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=PivA0O37; spf=pass (imf03.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.166.41 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam04 X-HE-Tag: 1634754564-929091 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: Just a friendly bump for review. :) Peter, any objections to this version? I think it fairly closely matches your suggestions from v1. On Thu, Sep 30, 2021 at 2:23 PM Axel Rasmussen wrote: > > Before any tests are run, in set_test_type, we decide what feature(s) we > are going to be testing, based upon our command line arguments. However, > the supported features are not just a function of the memory type being > used, so this is broken. > > For instance, consider writeprotect support. It is "normally" supported > for anonymous memory, but furthermore it requires that the kernel has > CONFIG_HAVE_ARCH_USERFAULTFD_WP. So, it is *not* supported at all on > aarch64, for example. > > So, this commit fixes this by querying the kernel for the set of > features it supports in set_test_type, by opening a userfaultfd and > issuing a UFFDIO_API ioctl. Based upon the reported features, we toggle > what tests are enabled. > > Signed-off-by: Axel Rasmussen > --- > tools/testing/selftests/vm/userfaultfd.c | 54 ++++++++++++++---------- > 1 file changed, 31 insertions(+), 23 deletions(-) > > diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c > index 2a71a91559a7..00d1b7555865 100644 > --- a/tools/testing/selftests/vm/userfaultfd.c > +++ b/tools/testing/selftests/vm/userfaultfd.c > @@ -346,6 +346,16 @@ static struct uffd_test_ops hugetlb_uffd_test_ops = { > > static struct uffd_test_ops *uffd_test_ops; > > +static inline uint64_t uffd_minor_feature(void) > +{ > + if (test_type == TEST_HUGETLB && map_shared) > + return UFFD_FEATURE_MINOR_HUGETLBFS; > + else if (test_type == TEST_SHMEM) > + return UFFD_FEATURE_MINOR_SHMEM; > + else > + return 0; > +} > + > static void userfaultfd_open(uint64_t *features) > { > struct uffdio_api uffdio_api; > @@ -406,7 +416,7 @@ static void uffd_test_ctx_clear(void) > munmap_area((void **)&area_dst_alias); > } > > -static void uffd_test_ctx_init_ext(uint64_t *features) > +static void uffd_test_ctx_init(uint64_t features) > { > unsigned long nr, cpu; > > @@ -418,7 +428,7 @@ static void uffd_test_ctx_init_ext(uint64_t *features) > uffd_test_ops->release_pages(area_src); > uffd_test_ops->release_pages(area_dst); > > - userfaultfd_open(features); > + userfaultfd_open(&features); > > count_verify = malloc(nr_pages * sizeof(unsigned long long)); > if (!count_verify) > @@ -446,11 +456,6 @@ static void uffd_test_ctx_init_ext(uint64_t *features) > err("pipe"); > } > > -static inline void uffd_test_ctx_init(uint64_t features) > -{ > - uffd_test_ctx_init_ext(&features); > -} > - > static int my_bcmp(char *str1, char *str2, size_t n) > { > unsigned long i; > @@ -1191,7 +1196,6 @@ static int userfaultfd_minor_test(void) > void *expected_page; > char c; > struct uffd_stats stats = { 0 }; > - uint64_t req_features, features_out; > > if (!test_uffdio_minor) > return 0; > @@ -1199,21 +1203,7 @@ static int userfaultfd_minor_test(void) > printf("testing minor faults: "); > fflush(stdout); > > - if (test_type == TEST_HUGETLB) > - req_features = UFFD_FEATURE_MINOR_HUGETLBFS; > - else if (test_type == TEST_SHMEM) > - req_features = UFFD_FEATURE_MINOR_SHMEM; > - else > - return 1; > - > - features_out = req_features; > - uffd_test_ctx_init_ext(&features_out); > - /* If kernel reports required features aren't supported, skip test. */ > - if ((features_out & req_features) != req_features) { > - printf("skipping test due to lack of feature support\n"); > - fflush(stdout); > - return 0; > - } > + uffd_test_ctx_init(uffd_minor_feature()); > > uffdio_register.range.start = (unsigned long)area_dst_alias; > uffdio_register.range.len = nr_pages * page_size; > @@ -1574,6 +1564,8 @@ 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; > @@ -1607,6 +1599,22 @@ static void set_test_type(const char *type) > if ((unsigned long) area_count(NULL, 0) + sizeof(unsigned long long) * 2 > > page_size) > err("Impossible to run this test"); > + > + /* > + * Whether we can test certain features depends not just on test type, > + * but also on whether or not this particular kernel supports the > + * feature. > + */ > + > + userfaultfd_open(&features); > + > + test_uffdio_wp = test_uffdio_wp && > + (features & UFFD_FEATURE_PAGEFAULT_FLAG_WP); > + test_uffdio_minor = test_uffdio_minor && > + (features & uffd_minor_feature()); > + > + close(uffd); > + uffd = -1; > } > > static void sigalrm(int sig) > -- > 2.33.0.800.g4c38ced690-goog >