From patchwork Wed Jul 14 22:25:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12377991 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EAECC12002 for ; Wed, 14 Jul 2021 22:25:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 12BA9613CA for ; Wed, 14 Jul 2021 22:25:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12BA9613CA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 669EF6B00DD; Wed, 14 Jul 2021 18:25:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61C9D6B00DE; Wed, 14 Jul 2021 18:25:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4941A6B00DF; Wed, 14 Jul 2021 18:25:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0148.hostedemail.com [216.40.44.148]) by kanga.kvack.org (Postfix) with ESMTP id 25BD76B00DD for ; Wed, 14 Jul 2021 18:25:44 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0A87518484CAE for ; Wed, 14 Jul 2021 22:25:43 +0000 (UTC) X-FDA: 78362626566.17.ED2C735 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf11.hostedemail.com (Postfix) with ESMTP id ABF2AF00020B for ; Wed, 14 Jul 2021 22:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626301542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Uq4QT2ZrcVHt/byJv1ujYeldpYEbg+Q7RaFfi3UPyeE=; b=PYGkOnSSRvOBpoR5w8sTJD1Nf89dAkin6AEZmgrBH5ORnv4pSjxSVUpKIbR6uzW6woWkbt X8rMGhEjCK9uUgvsEQgSv/xhPUwHkR1+8mmRH45IemlNKODTZAvyNUuNyhwKWbZSJfoCS0 UdCTlVKwhVAaBi+oDTHTDy0n0rJGbwA= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-29-KciQxx8gO82hKR2nODpScg-1; Wed, 14 Jul 2021 18:25:41 -0400 X-MC-Unique: KciQxx8gO82hKR2nODpScg-1 Received: by mail-qk1-f197.google.com with SMTP id bi3-20020a05620a3183b02903b55bbe1ef9so2297353qkb.13 for ; Wed, 14 Jul 2021 15:25:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Uq4QT2ZrcVHt/byJv1ujYeldpYEbg+Q7RaFfi3UPyeE=; b=mjlV4O1euuFTkcVSrfOEV79hWw4NHWPNaOZtIesSXsfZluB4j1vs1QuHh3TK4m/gLC vZrEz7Z4CR8G9aWKtpiCD6YFi2FLBRLjPwOGvgaCbpYSZxk66Gisxi32WdzYzNnAdT/8 9EbqGa86dmZHLhXSRLxJ1bgcEhVj2nMv5gpLP77rJT+QCa3acVvj/w4CBDE4vRFJnGx9 wmG3PeprhHwUA/aujGC9afBKGq6w+LvXV88RKOj+HxhC6v7Q6BCWxjIjPt3SXWnRCd+8 cIRmSc8QmVI6W+pywKRP+gTjqMPv807Zk++xjtaYjIwmx4/6R2DxBQnMFupv7OVeZ3Nx i5pw== X-Gm-Message-State: AOAM533fsqZScgnQxkJUHANi6dGIyIVNH7Wyd/LW3i1YpCn54qaSXJZS AOdozqgnM6Ysar0cb43rl5ekaGpeebTTqa+nePw+A1dCTpTEERK7n5Tf4B1m7B3LlqACU4sOti9 stE/AhLutgV6m/BDSoVk+ZPH0TXybuXlLB485cDm74Z2hf36rcEijDK3zyz+Y X-Received: by 2002:ae9:ea18:: with SMTP id f24mr221982qkg.177.1626301540481; Wed, 14 Jul 2021 15:25:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKWio2waCxeqg1e164RijCKEKXk6rILIQsIZLa2XpqKIZLo+ivNYlFqZ2GZR+4gVoFHCbOFQ== X-Received: by 2002:ae9:ea18:: with SMTP id f24mr221946qkg.177.1626301540222; Wed, 14 Jul 2021 15:25:40 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id j22sm1213396qtj.60.2021.07.14.15.25.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 15:25:39 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Mike Kravetz , Axel Rasmussen , Miaohe Lin , "Kirill A . Shutemov" , Hugh Dickins , Jason Gunthorpe , Alistair Popple , Matthew Wilcox , peterx@redhat.com, Jerome Glisse , Andrea Arcangeli , Mike Rapoport , Nadav Amit , David Hildenbrand Subject: [PATCH v4 26/26] userfaultfd/selftests: Enable uffd-wp for shmem/hugetlbfs Date: Wed, 14 Jul 2021 18:25:36 -0400 Message-Id: <20210714222536.49397-1-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210714222117.47648-1-peterx@redhat.com> References: <20210714222117.47648-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PYGkOnSS; spf=none (imf11.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: ABF2AF00020B X-Stat-Signature: rmo1kr6tikedsiuht7oz3x6ebuhk85ur X-HE-Tag: 1626301542-366164 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: After we added support for shmem and hugetlbfs, we can turn uffd-wp test on always now. Define HUGETLB_EXPECTED_IOCTLS to avoid using UFFD_API_RANGE_IOCTLS_BASIC, because UFFD_API_RANGE_IOCTLS_BASIC is normally a superset of capabilities, while the test may not satisfy them all. E.g., when hugetlb registered without minor mode, then we need to explicitly remove _UFFDIO_CONTINUE. Same thing to uffd-wp, as we'll need to explicitly remove _UFFDIO_WRITEPROTECT if not registered with uffd-wp. For the long term, we may consider dropping UFFD_API_* macros completely from uapi/linux/userfaultfd.h header files, because it may cause kernel header update to easily break userspace. Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index e363bdaff59d..015f2df8ece4 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -80,7 +80,7 @@ static int test_type; static volatile bool test_uffdio_copy_eexist = true; static volatile bool test_uffdio_zeropage_eexist = true; /* Whether to test uffd write-protection */ -static bool test_uffdio_wp = false; +static bool test_uffdio_wp = true; /* Whether to test uffd minor faults */ static bool test_uffdio_minor = false; @@ -320,6 +320,9 @@ struct uffd_test_ops { (1 << _UFFDIO_ZEROPAGE) | \ (1 << _UFFDIO_WRITEPROTECT)) +#define HUGETLB_EXPECTED_IOCTLS ((1 << _UFFDIO_WAKE) | \ + (1 << _UFFDIO_COPY)) + static struct uffd_test_ops anon_uffd_test_ops = { .expected_ioctls = ANON_EXPECTED_IOCTLS, .allocate_area = anon_allocate_area, @@ -335,7 +338,7 @@ static struct uffd_test_ops shmem_uffd_test_ops = { }; static struct uffd_test_ops hugetlb_uffd_test_ops = { - .expected_ioctls = UFFD_API_RANGE_IOCTLS_BASIC & ~(1 << _UFFDIO_CONTINUE), + .expected_ioctls = HUGETLB_EXPECTED_IOCTLS, .allocate_area = hugetlb_allocate_area, .release_pages = hugetlb_release_pages, .alias_mapping = hugetlb_alias_mapping, @@ -1580,8 +1583,6 @@ static void set_test_type(const char *type) if (!strcmp(type, "anon")) { test_type = TEST_ANON; uffd_test_ops = &anon_uffd_test_ops; - /* Only enable write-protect test for anonymous test */ - test_uffdio_wp = true; } else if (!strcmp(type, "hugetlb")) { test_type = TEST_HUGETLB; uffd_test_ops = &hugetlb_uffd_test_ops;