From patchwork Tue Apr 27 16:13:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12226913 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,SPF_PASS,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 46199C433B4 for ; Tue, 27 Apr 2021 16:14:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E322B613E7 for ; Tue, 27 Apr 2021 16:14:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E322B613E7 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 5716B6B00A4; Tue, 27 Apr 2021 12:14:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 418CD6B00A7; Tue, 27 Apr 2021 12:14:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F157B6B00A5; Tue, 27 Apr 2021 12:14:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id ACF536B00A1 for ; Tue, 27 Apr 2021 12:14:06 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6F10A8249980 for ; Tue, 27 Apr 2021 16:14:06 +0000 (UTC) X-FDA: 78078643692.15.92272D1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf24.hostedemail.com (Postfix) with ESMTP id AB128A000190 for ; Tue, 27 Apr 2021 16:13:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619540045; 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=cr+5e1VLs/HzikgCvktprPaWi0mBnwkwdmGII74N+nI=; b=U24Eg0xlD0Hf6cy2OqtNADy/iGFtRIMloDVOu8A4uDtrp2a468P6LnprMwSEcvKLLKkZMV Ejoo874SFgieVYNXOkCdF+y7BST/qAmFY20ZyyvGtaHRQ+hsjvruCJ+xYGkncHK5rPd4tK Xg8WH8vwa5LP2xTi3IWsU1pmVUoys6g= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213-7QmcO4tKP86X81rCIjlXOQ-1; Tue, 27 Apr 2021 12:14:03 -0400 X-MC-Unique: 7QmcO4tKP86X81rCIjlXOQ-1 Received: by mail-qv1-f70.google.com with SMTP id w20-20020a0562140b34b029019c9674180fso26183792qvj.0 for ; Tue, 27 Apr 2021 09:14:02 -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=cr+5e1VLs/HzikgCvktprPaWi0mBnwkwdmGII74N+nI=; b=N+9d0pwYix1M44VotK5OvMHWcrcxp+mSjTX0Dklmm2qN4t/eh+pRezmrpiGnye1CNt USETNS+lEB1Vq3KkLJP2o4fwECSDH/ICuRuDtSoLTbbwP2TX4DybqpZ86szX9eohPhNA tDpkoCRAvjn5lDd5yNRL+V0Dj7n6ri7MUMINX98IpEgQcdAMGf1Y5hZ5TwfzDZWC6QwZ CzH9bPrVKK9Z8GsfpjmP2D/uDYSXhduhaltM7zzWjvwRoSYJ5mE/o6dr9f5r9/3btoRo Joo9vCT6MuA6ThGk0j2eQENtV5iXovgR21LbOTIjhrg5Ku08EGxpt1oCeGkgreFdzNSf HCUQ== X-Gm-Message-State: AOAM531DNMNui5IKdQLri+WXUjdjNjNy7w5A1z13ZZAot4Lt7qLGuG34 iQxb47VdYP66B2rdiKvwru8wP11+mgdJ95Y3gUODLw3uSaofsdw+Hihf5MBsRPUv8UlfY+qjN0k q5N8zWQdQtCJsIf+2pZhKJu+tvCr55PvfxEYmlpmcavhyfmjWG3hzXomEUC1r X-Received: by 2002:a05:620a:74b:: with SMTP id i11mr14332434qki.445.1619540041980; Tue, 27 Apr 2021 09:14:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5lVjxxW5hAwO00BZZT8kxy+y40eQhnQFXe208ItbjEc0IxNxi5grm6oA/Uy+P+8egT9t04g== X-Received: by 2002:a05:620a:74b:: with SMTP id i11mr14332387qki.445.1619540041643; Tue, 27 Apr 2021 09:14:01 -0700 (PDT) Received: from xz-x1.redhat.com (bras-base-toroon474qw-grc-77-184-145-104-227.dsl.bell.ca. [184.145.104.227]) by smtp.gmail.com with ESMTPSA id v66sm3103621qkd.113.2021.04.27.09.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Apr 2021 09:14:01 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nadav Amit , Miaohe Lin , Mike Rapoport , Andrea Arcangeli , Hugh Dickins , peterx@redhat.com, Jerome Glisse , Mike Kravetz , Jason Gunthorpe , Matthew Wilcox , Andrew Morton , Axel Rasmussen , "Kirill A . Shutemov" Subject: [PATCH v2 24/24] userfaultfd/selftests: Enable uffd-wp for shmem/hugetlbfs Date: Tue, 27 Apr 2021 12:13:17 -0400 Message-Id: <20210427161317.50682-25-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210427161317.50682-1-peterx@redhat.com> References: <20210427161317.50682-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: AB128A000190 X-Stat-Signature: ejwsio8h139zpe8m1rsunq3autx6tdfs Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619540035-127345 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 6339aeaeeff8b..cfa6c0e960e6a 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; @@ -299,6 +299,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, @@ -314,7 +317,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, @@ -1374,8 +1377,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;