Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4916483pxy; Tue, 27 Apr 2021 15:57:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkp8mx05UkPANxHXRHY62gyWfKJKwU0T465ihgplh+bTLY5bGZupwmHFoWgNethw8MYc4P X-Received: by 2002:aa7:d950:: with SMTP id l16mr7077787eds.374.1619564242725; Tue, 27 Apr 2021 15:57:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619564242; cv=none; d=google.com; s=arc-20160816; b=Bmn74uo8kms+S6c1JiLOp3kszYPCfiTNBpW4tMqr9UkxcVmfPoOf/btI0AFg5xmboA 9TzxgAjfQqlf2mwMeTvdX1ecJZofLNhK9/eNQ9smaetWpm9/+GMoQ2K3vGmgLVavb2/z NhzSodMtKyd9+3ThiXK/twoeKcmIgkriC+06JS4d37VkcTj6Re5Prm9OSgwj2Jo3W/Tr bIcMnAYdyjwdyma3QW2dRkuBgQNo8lNEyJMiXxP4I3FXd6ov+ANQ05M42o/TtKqy/7bP kJuB3o7OSQHSsywzMkaC7FG6ZuxYIk8QuIzrPxv8CqR43DPgoMED4p6W3rJdbisRfcvj WYtg== 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=RRWLcA4U8+e/XOHvkZswRCx0YI32rbruxBRpXWbXmCs=; b=oUHLIfaDuhCJ4UHnnpd39ef8I7NG1np4qBkiZiXueaKGGn5N7HDDuTtPMfTntVWjKH FjJxnPJqsQH+E2D5ouGBPz6E2QtBGYLHy5mGfYd/5hYwIdOnkUH4jRHCjx8PFojc6w4k xOs/nL2PTh5rqSyJh28aWNC5JAr8gP66ODjdD6tFHdv6R3sj8i4kn66BSo5oq81g21Td LyU/jRGfnEj4N/3ODLv2buZznG+AAhBKafgGK8WYlDaYrWxN/8scFjWw/UT4TlFUgAmw fAgdZokl4bOsIYuq1MAYtIqMDsVEJItUQfMIkS7iBWAnuo/kCucwPJWr+Hth0OhLDPJS VxXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=okG18pV2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si3690030edr.347.2021.04.27.15.56.59; Tue, 27 Apr 2021 15:57:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=okG18pV2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239435AbhD0WyA (ORCPT + 99 others); Tue, 27 Apr 2021 18:54:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239458AbhD0Wxv (ORCPT ); Tue, 27 Apr 2021 18:53:51 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92588C06138A for ; Tue, 27 Apr 2021 15:53:07 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id a7-20020a5b00070000b02904ed415d9d84so17671187ybp.0 for ; Tue, 27 Apr 2021 15:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=RRWLcA4U8+e/XOHvkZswRCx0YI32rbruxBRpXWbXmCs=; b=okG18pV2cHje7Vas2xHrgpMSRzPJeLI9iRNJPNE0FPrPp6Klcqy7/1Swk9FhXFy3Qb tJpEyh/CfyzSMCfu+ZiCoWyeiRSKT3APXIJisybUxKCfMpzvt07y/CRA5np6G5JapEpB IUI6hMM0aN7/n1yjIYUXs9pj5LHPpMC/9gDy2s4fGjKSH94J6JXZvHYcGTjVJ0ktYWkq 1gR8Oy0hwQTr9EXyrrp0TO9YsOE8GFBDMrUmb73xr9K7a7VeRuC2Vo+NbSMC+Jz2Elej wemHAx8m2OCf16Mzand+AzUNOPgoC4hkLUjk9Kez5uNslnMgycE0zkqOGfIF4GhASWCT 0Yvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=RRWLcA4U8+e/XOHvkZswRCx0YI32rbruxBRpXWbXmCs=; b=fcAVfVGKCUICvvR7D65wCI0fcIHCdDKzTxnikkK//cofCeEHhcH+SeXPYfFAJ5TQK9 Nt2Cp6fpkQttebV7kjfqvxb9rm20Ejav5rwj4AugHDzdOaWP3DZseUklbYRQAH+6BYRX zH/GfJA9Z1ruoeoBs5ugoSuGZ7McPfJXvrkGP3MsDzejdTrCSkwRcpS8+ZsZE2d2l9sg SLXu+VZWhbrHmdZ/7q1cYp1zQHYGMgWfAEhxGvqDzsWCy5LQUU98mIUv9K/0lpgkZ18Q H//G3S5nuenf75PHYaI0utMlHp5y5a2Bl9HlHN0WvigWc/U/vGUY9dB1DA7D9zfnU+Yu /BOQ== X-Gm-Message-State: AOAM531WsBFEJwRMWiXNguN6Xy+mTpe/yJz0JI1/DpibpzgH1Vuk5Drd GO8aikQfXm37QD4/7MNdMIze4yl1G/6AcVqFZlJN X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:c423:570b:b823:c33e]) (user=axelrasmussen job=sendgmr) by 2002:a25:8682:: with SMTP id z2mr12874549ybk.325.1619563986815; Tue, 27 Apr 2021 15:53:06 -0700 (PDT) Date: Tue, 27 Apr 2021 15:52:44 -0700 In-Reply-To: <20210427225244.4326-1-axelrasmussen@google.com> Message-Id: <20210427225244.4326-11-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210427225244.4326-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH v5 10/10] userfaultfd/selftests: exercise minor fault handling shmem support From: Axel Rasmussen To: Alexander Viro , Andrea Arcangeli , Andrew Morton , Hugh Dickins , Jerome Glisse , Joe Perches , Lokesh Gidra , Mike Kravetz , Mike Rapoport , Peter Xu , Shaohua Li , Shuah Khan , Stephen Rothwell , Wang Qing Cc: linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Axel Rasmussen , Brian Geffon , "Dr . David Alan Gilbert" , Mina Almasry , Oliver Upton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enable test_uffdio_minor for test_type == TEST_SHMEM, and modify the test slightly to pass in / check for the right feature flags. Signed-off-by: Axel Rasmussen --- tools/testing/selftests/vm/userfaultfd.c | 29 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 3fbc69f513dc..a7ecc9993439 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -474,6 +474,7 @@ static void wp_range(int ufd, __u64 start, __u64 len, bool wp) static void continue_range(int ufd, __u64 start, __u64 len) { struct uffdio_continue req; + int ret; req.range.start = start; req.range.len = len; @@ -482,6 +483,17 @@ static void continue_range(int ufd, __u64 start, __u64 len) if (ioctl(ufd, UFFDIO_CONTINUE, &req)) err("UFFDIO_CONTINUE failed for address 0x%" PRIx64, (uint64_t)start); + + /* + * Error handling within the kernel for continue is subtly different + * from copy or zeropage, so it may be a source of bugs. Trigger an + * error (-EEXIST) on purpose, to verify doing so doesn't cause a BUG. + */ + req.mapped = 0; + ret = ioctl(ufd, UFFDIO_CONTINUE, &req); + if (ret >= 0 || req.mapped != -EEXIST) + err("failed to exercise UFFDIO_CONTINUE error handling, ret=%d, mapped=%" PRId64, + ret, (int64_t) req.mapped); } static void *locking_thread(void *arg) @@ -1182,7 +1194,7 @@ static int userfaultfd_minor_test(void) void *expected_page; char c; struct uffd_stats stats = { 0 }; - uint64_t features = UFFD_FEATURE_MINOR_HUGETLBFS; + uint64_t req_features, features_out; if (!test_uffdio_minor) return 0; @@ -1190,9 +1202,17 @@ static int userfaultfd_minor_test(void) printf("testing minor faults: "); fflush(stdout); - uffd_test_ctx_init_ext(&features); - /* If kernel reports the feature isn't supported, skip the test. */ - if (!(features & UFFD_FEATURE_MINOR_HUGETLBFS)) { + 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; @@ -1426,6 +1446,7 @@ static void set_test_type(const char *type) map_shared = true; test_type = TEST_SHMEM; uffd_test_ops = &shmem_uffd_test_ops; + test_uffdio_minor = true; } else { err("Unknown test type: %s", type); } -- 2.31.1.498.g6c1eba8ee3d-goog