Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1018416pxb; Thu, 15 Apr 2021 11:49:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysc1iSIz6EWU6JCqdY3FdQ+SRjb4+bAuwmK/DIcQWy7o+DTGjzIt4kFZWYSL1wVQggk7a2 X-Received: by 2002:a17:90a:c281:: with SMTP id f1mr5286867pjt.58.1618512571815; Thu, 15 Apr 2021 11:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618512571; cv=none; d=google.com; s=arc-20160816; b=R77LVgfqxSfwb1pf60Rkq6jRistmnGfjH6GCF5WooaG3LAr6uBHHQlFLcmPta2eA3h h/ceHRg2Fz6Zumv3Fw+bzm6vTQYI6H/6brcB0lJeXkRWk/PuKbJ4zNEsOgpG3hiHyshb WorLCONhkYIV4Ebu8n5N6xQDD+E7urddZ0c6Q+EA/SD9tSaKq/khj2zhUFRcj83sNDD6 qhMXU2sf+IuBYE49jy/HiZMuBL4L8IlpEb8vVaB7FSCUmJdg6hbIq8M+E8sugSr9JbTa bJjBw/FLV2UJoqJQ4NG/feg3qYyGi56TIkU/7QRd2/26JWu/ZMQxUuv/cV3acPKhDq80 raGg== 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=NPeuLMJJBun5hHaf/B7onZQg8F0X8wxMw6hgTnGDv34=; b=enzS+Y4d2PbEcOaXBH+3C+TTdNVWDrMXBz3Is2TrxV0BWwBhavHEHykbZ6+lMHD6RL 9tJzagTKc3CxL2P3YAG6+ru4JQVi72FKRW1AA0Epnb/aSxNhCpXGA/PMdBE2I5EHIPQt wpdrcBeRKjlyhUSyqedPmo3nWOBONlmnbN2DTZYNaOFOIg4gA4Rt5IrJVx7zAb7AirSi frJYd8Md4kxWqeAbdXPHN2gihl5v2hurjz6CibAxE+zVEjXjJWTuPMUW9ljeZJN8vyDe 6d/mgzEhKTD2xqqnHa+1qz81maZ1YxAhygPd2ichV5S9A7UvwW2acT/H4kTIh3UzrmI+ j0eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vw7MzmYe; 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 y5si4858111pjp.126.2021.04.15.11.49.19; Thu, 15 Apr 2021 11:49:31 -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=vw7MzmYe; 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 S234853AbhDOSst (ORCPT + 99 others); Thu, 15 Apr 2021 14:48:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234826AbhDOSsX (ORCPT ); Thu, 15 Apr 2021 14:48:23 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63305C061760 for ; Thu, 15 Apr 2021 11:47:51 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id p75so3452520ybc.8 for ; Thu, 15 Apr 2021 11:47:51 -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=NPeuLMJJBun5hHaf/B7onZQg8F0X8wxMw6hgTnGDv34=; b=vw7MzmYeICCDTRNei7JjvxvzICXL2ZYuT4Nz6yv4/CUGud49o5WkaiMtGUEKjESiNe eqeLwt7B9gk5riuJjePaDEIXzryk7b0Mbr38Nkkl820E/HvvH22SX0pF+lA4xhjX6ow5 dUJYx0Oe3tM0v7Bmsk7r6IDlffnGRxKlJ3WgwXPU6L2juztGfnlihgY7sNzUe1s96oO9 qOaQs+JmiNApmOMt/72KEifjhtqmiTyp1mTvmMhfqYyC/qbuvzaYjU9gPDKDBcXGswrT y/LDRGxE6+iRNjY/2a/jM03q6ztRO1tvKZoMDEzSvPoYumCoj9FTQglvUy8NQBlEogtN jxEg== 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=NPeuLMJJBun5hHaf/B7onZQg8F0X8wxMw6hgTnGDv34=; b=i2Hpkmy3WGJjpT79L+y6XoV1B8FnaBteVLw3pMF8j/XYlCH/epeSArx6jaNbQds4cJ oFA6mgzu6iK0w11Nvh5Xi2hB/w8MOhI2Ib0njR3S8OG+h9dkPPzZPdn/ZdwRiasmhln9 7z1oVTy2JK6XeJWJ2L+mxXcgOmCjMQGqKsQp6+h4LpQA/X3YogQqef9AsFMgt82zjFC7 w8u5DNyM/6Okbb+kg+nhVb27e2eZzEhF2/KhJNkQR2g3DYFa3PPhH+JBGT9FOQnZ5+WS jAiQnA2YGVNW7Ajs0TDS9EdEDqr57UR6EKS1nIYbODKZG6j2NZkmxMfh+2UGtw1RVLbf BxrQ== X-Gm-Message-State: AOAM530LCF2NOhkwhqgjKCNBUwBH0vXb78z34cqCoU/N+Thp2P69QwEC +3cD6HSUS9Re013tTzmQmENkaZJVLZLdWgWtszsH X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:21b1:6e5c:b371:7e3]) (user=axelrasmussen job=sendgmr) by 2002:a25:3056:: with SMTP id w83mr6539422ybw.381.1618512470669; Thu, 15 Apr 2021 11:47:50 -0700 (PDT) Date: Thu, 15 Apr 2021 11:47:30 -0700 In-Reply-To: <20210415184732.3410521-1-axelrasmussen@google.com> Message-Id: <20210415184732.3410521-9-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210415184732.3410521-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog Subject: [PATCH v3 08/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.368.gbe11c130af-goog