Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp152134pxy; Tue, 20 Apr 2021 15:12:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzymeiL6GJdMpWsYDv2cEeX6wAKs54l8c5gSByvNLayaYJtNZvrFG8FSprUWGcvB8gdPCvo X-Received: by 2002:a17:906:4a89:: with SMTP id x9mr29431935eju.121.1618956748044; Tue, 20 Apr 2021 15:12:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618956748; cv=none; d=google.com; s=arc-20160816; b=awpgYIf0Mv1QhRijM9udVhqz8jTFVnkKkE5NYj3ySI/Q56vz7b3ce/IjHYIVnmNbp5 /81X5RKZvpYZJVrNrO5sJkIiwLsKqf1ZTaj6CzE9Vqv8ebRVgbMDdAkD/8U2weCbol2E /T0GAyl5hNrfUZErv67DY3rItqxOBR7Fu33wPCkwvloYHef0zhc2zhVOpseTrUkzppx6 IyZDV9sA486M5XLDUna7iEv9LBKg0wzRbmvtaW31W2CRszz48oO4XYwzhNFQS4GUdreE nrn0ORINKj5TWB477LFkn2EcIOoSVYXGHCIB7N7HSqFPobQatj8KjP1f4J3EqF8fD5h9 OS+A== 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=h1FmkySHA8+hxffLSQsNmkLSLLaeZiFVVmaE02qo8RLWht15Mo6BmxseMpoBq7ayS5 gBJAOP6wZ/kB7Y9rxhjLIMUWdFirWcpc91U9gMKBjBoPjI3/qkXK3tsoljVreXS9cFOk 6WSXRIY5h8roCILFDxsonzYyZXetLUTvwH7gW84h/MaYpMfKaDfkvu4ub1MUlV8KQeGZ 2K640OwQdIyX82xntEovlZGakbhPG2iq6D0sLvNNR77dHecSsMUvQjS06BVkPHuDZHxl kPbdNs84AJBmYHjQ13EQkDJzAOyhyGGqLBBnD/1wbIeFNNKMxIAKxdVaj033Yu2iWEUc Luhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZreUEMGX; 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 u24si67311ejo.371.2021.04.20.15.12.05; Tue, 20 Apr 2021 15:12:28 -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=ZreUEMGX; 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 S234294AbhDTWJO (ORCPT + 99 others); Tue, 20 Apr 2021 18:09:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234288AbhDTWI7 (ORCPT ); Tue, 20 Apr 2021 18:08:59 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C36EC06138A for ; Tue, 20 Apr 2021 15:08:24 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id p15-20020a05620a056fb02902e30b3f1950so8222276qkp.23 for ; Tue, 20 Apr 2021 15:08:24 -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=ZreUEMGX5w46ttG+DVBFu8u1yQcYHgC00EnXT+xD6FaeUxYRrZP/60cA7/0Noho0dU i0SVSFKQZsfa+6G9feTiogYQyxP1TNNWCtDd3TDjF1lH5UYppSg6lLHqvf1y2xMzLiqw dFrUFCqFTn/HL60soYFWayK9JwpCCIi3TZoX6vBPCn8k8GHmtK7uTavC2gGYfc/H6woj uzNvo8KGW5r6v6n8duFxibIs33FwMdL7rGkKyjethciITgma7juCPWhsOErHcZ7XilTz /uf20aIdqN0FlsbiuXvqy/29Vzbwb4Q31UjqyR1RHaAhC39f6UktbqNrEwKhihjEWMg6 /YAA== 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=pLW5deFzqvv5EPU2tfU46v9+czSzrkGfIvU3bz59waRPAyK2BIpQKodSgW6VogaSYD 0CcTM4187w6qMGgyufMw9JTpPkBv+FcH6KtWmH64oqgIGMHUOnzzHLXNntefqM1bSrAA ahUCE7awQUaApuVBpsJD9LQAPaF4EyLI6SmKQJ1vwPOVKbzEhZQEVog0jinzK99q0RsN MXqjL7G2FVmjf7FIyEMKS693pp3VYF+B07Z3FjHHTY66PLaMFLbH6tdttPg3aJmJ/wW2 Knf5RKMtn3tJ1A+d6+NeahvXQdog7AKg5uHG9l8WkXQiCgJZE81NxrZf/7IepyR9KhJ5 CcQw== X-Gm-Message-State: AOAM530C0nwuY1PhGop7iL9J0A3huGddfkwvWGYy0mmY7AMKEBJEHyBz CxmfvmHe0uJ9altHEagfFzXvcZm4lVl7svkNTKq1 X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:c40e:ee2c:2ab8:257a]) (user=axelrasmussen job=sendgmr) by 2002:ad4:4944:: with SMTP id o4mr29064674qvy.18.1618956503394; Tue, 20 Apr 2021 15:08:23 -0700 (PDT) Date: Tue, 20 Apr 2021 15:08:02 -0700 In-Reply-To: <20210420220804.486803-1-axelrasmussen@google.com> Message-Id: <20210420220804.486803-9-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210420220804.486803-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog Subject: [PATCH v4 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