From patchwork Mon Mar 6 21:39:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13162420 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FD3AC61DA4 for ; Mon, 6 Mar 2023 21:39:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3AE26B0073; Mon, 6 Mar 2023 16:39:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EC3476B0074; Mon, 6 Mar 2023 16:39:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D15DA280001; Mon, 6 Mar 2023 16:39:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C35286B0073 for ; Mon, 6 Mar 2023 16:39:39 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 880751A0172 for ; Mon, 6 Mar 2023 21:39:39 +0000 (UTC) X-FDA: 80539790478.26.310A123 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 70A7140009 for ; Mon, 6 Mar 2023 21:39:37 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UZL7aJty; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678138777; h=from:from:sender: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:dkim-signature; bh=dh3vnUO1CryjqGh5pf4N+hTFZfi7U8elDbn6yAru0xw=; b=ZsxmEhoEt5z0lqNl1CULZreeLMuwf+CqguMNslhkCVKPNAXu501GiwQtTt2Y32resBD5vb ihgcPO6D3SdAmkAim5H0qtqT0+Imo0zG46EEenSijH/RyA3TMgu1cqGRWS5pp1Kaz5tEn7 d6aoND8PoVKQGMSk0U3ePNDVjcRaGrE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UZL7aJty; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678138777; a=rsa-sha256; cv=none; b=v4lHGEUmBy4ao2rh28Uj/3cZgdJy0k7+0h3XwFe0XOcyoETZo9WCFp1ukp2//rf/ZNVZ5i OOj2OtMgw+BAKDpfb0XSxJhe84HYWLx8RHILtk3dG6JCm1t/X+aIhahXrmM9vuPRUp7oXH SkpTJ2IHd8V8KRM61JdBXwUa2xBoS0A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678138776; 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=dh3vnUO1CryjqGh5pf4N+hTFZfi7U8elDbn6yAru0xw=; b=UZL7aJty1myW0x0pk9VJsPUaX60uc8UcUZgynjfl1RF0ybQE10wwvKnmU/b/RzSKpZyOjw Rnemglf4GIimH637oI7+JE8u6jPRpSs+5OwFORtUn04GRpx9miNG7WCyuOE09RDwotvNdR KkSf8nOyJLlAx8a5uzvjzsfjMpvU8Ek= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-470-j6DpVYMQOp25RhO-nWs2iw-1; Mon, 06 Mar 2023 16:39:35 -0500 X-MC-Unique: j6DpVYMQOp25RhO-nWs2iw-1 Received: by mail-qt1-f199.google.com with SMTP id x4-20020ac85384000000b003bfbb485e2dso5983791qtp.22 for ; Mon, 06 Mar 2023 13:39:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678138773; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dh3vnUO1CryjqGh5pf4N+hTFZfi7U8elDbn6yAru0xw=; b=lBwuIG3UmG0NRPo57yyOOvMHoP3iMwPphIEzKaGPmqQN4vjdMGVBtJyOyamcvsqJaG gnbMacrP4cfA7lX+M5jp3VUqkodSXWrtmros4Hjqc99HROkkN5c3yuwtqSqFj8EqyLcP mH9t9WQNuEXFbncj9dHNrJAulNMZZ06OQHBL9lhhn07P9dcnnVWQZpRvY+AXfXu3fWko nKI4UsZ3Bk38AgAbVv/eLAUk31sCnqhMyDgmOptSLIhu1A5KRLafKYmJ6wvDP2n9baCJ bcJshsHIml8jWk/zV3nq5jm9WXecf3+YTYuoV43MbgPbAP31T52f6ITBHLebqPgsw/B0 eVFQ== X-Gm-Message-State: AO0yUKU01i+6htUYxi4RhZ5dkv2RE2k6PQmodKKwBSpfOT9LelDpAbEh 0NMBQyDNoQJrcQBhJXzrHPzPgzLrSzgqyoztBb8R9c1cjsGUMhD0M65Db7eFJ7H63K6RPGGBXa+ 13i0cThruXSUuCFtbJ4J1cYKBxQvc0h19qlVPrpxn7BFjiubLv7oUK18mY9WvNG3nbpsM X-Received: by 2002:ac8:5e0a:0:b0:3b8:36f8:830e with SMTP id h10-20020ac85e0a000000b003b836f8830emr17691683qtx.6.1678138773427; Mon, 06 Mar 2023 13:39:33 -0800 (PST) X-Google-Smtp-Source: AK7set9ol7LMQNBhaMyIBRZulf0Y2fuCeROIjvtU2gPZUJ2lDeqPLHVXUOpB/4I1eDjWa/ErESxpNw== X-Received: by 2002:ac8:5e0a:0:b0:3b8:36f8:830e with SMTP id h10-20020ac85e0a000000b003b836f8830emr17691649qtx.6.1678138773087; Mon, 06 Mar 2023 13:39:33 -0800 (PST) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-56-70-30-145-63.dsl.bell.ca. [70.30.145.63]) by smtp.gmail.com with ESMTPSA id e20-20020a05622a111400b003bfa66b7484sm8522884qty.35.2023.03.06.13.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 13:39:30 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muhammad Usama Anjum , peterx@redhat.com, Andrea Arcangeli , Axel Rasmussen , Mike Rapoport , Nadav Amit , Paul Gofman , Andrew Morton , David Hildenbrand Subject: [PATCH v3 2/2] selftests/mm: Smoke test WP_UNPOPULATED Date: Mon, 6 Mar 2023 16:39:25 -0500 Message-Id: <20230306213925.617814-3-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230306213925.617814-1-peterx@redhat.com> References: <20230306213925.617814-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: k47j6mswgfd6dwwrn1hsprpnzp7o8zdp X-Rspam-User: X-Rspamd-Queue-Id: 70A7140009 X-Rspamd-Server: rspam06 X-HE-Tag: 1678138777-975365 X-HE-Meta: U2FsdGVkX19vIeELnMHJN4pbbG987+nrKOELq32jXz4yq6ZVSjEtF/BFVW6L9SODsmmcAEjImns6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/RWW4hT62yqP1j4u4+i/paXFBcXvUxE99Pl6NLa8FAmcMznVfsim/ajL4Fhnm5XrlByYm+rNL2i23H15/rStCaIrNFefA8GM5brtXkQWXJHBz7uRYnX1jNnHrX7DA/WH3gVYvaPk39ofqF3J3FhXRKNzq3Xi7Gi2bY8YAj3C3YGsvwbrZB/qKit5x0D8GDKOzYtEcFPVvIBdSII8Pz02xLV+psMlcHGOT3f7eeDn5owVVkZBq//LzAMcr2SbNierlmCZsGTwAQkQV8J5w8CQW3PxIxexxQPMyOJwSmvTOAdycr1jUZNv9I4cmFOBufJnEzrtQyMlqqqSplHGNYWIXH/6MyibdldHSptcU= 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: Enable it by default on the stress test, and add some smoke tests for the pte markers on anonymous. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/userfaultfd.c | 45 ++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c index 7f22844ed704..e030d63c031a 100644 --- a/tools/testing/selftests/mm/userfaultfd.c +++ b/tools/testing/selftests/mm/userfaultfd.c @@ -1444,6 +1444,43 @@ static int pagemap_test_fork(bool present) return result; } +static void userfaultfd_wp_unpopulated_test(int pagemap_fd) +{ + uint64_t value; + + /* Test applying pte marker to anon unpopulated */ + wp_range(uffd, (uint64_t)area_dst, page_size, true); + value = pagemap_read_vaddr(pagemap_fd, area_dst); + pagemap_check_wp(value, true); + + /* Test unprotect on anon pte marker */ + wp_range(uffd, (uint64_t)area_dst, page_size, false); + value = pagemap_read_vaddr(pagemap_fd, area_dst); + pagemap_check_wp(value, false); + + /* Test zap on anon marker */ + wp_range(uffd, (uint64_t)area_dst, page_size, true); + if (madvise(area_dst, page_size, MADV_DONTNEED)) + err("madvise(MADV_DONTNEED) failed"); + value = pagemap_read_vaddr(pagemap_fd, area_dst); + pagemap_check_wp(value, false); + + /* Test fault in after marker removed */ + *area_dst = 1; + value = pagemap_read_vaddr(pagemap_fd, area_dst); + pagemap_check_wp(value, false); + /* Drop it to make pte none again */ + if (madvise(area_dst, page_size, MADV_DONTNEED)) + err("madvise(MADV_DONTNEED) failed"); + + /* Test read-zero-page upon pte marker */ + wp_range(uffd, (uint64_t)area_dst, page_size, true); + *(volatile char *)area_dst; + /* Drop it to make pte none again */ + if (madvise(area_dst, page_size, MADV_DONTNEED)) + err("madvise(MADV_DONTNEED) failed"); +} + static void userfaultfd_pagemap_test(unsigned int test_pgsize) { struct uffdio_register uffdio_register; @@ -1462,7 +1499,7 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) /* Flush so it doesn't flush twice in parent/child later */ fflush(stdout); - uffd_test_ctx_init(0); + uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED); if (test_pgsize > page_size) { /* This is a thp test */ @@ -1482,6 +1519,10 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) pagemap_fd = pagemap_open(); + /* Smoke test WP_UNPOPULATED first when it's still empty */ + if (test_pgsize == page_size) + userfaultfd_wp_unpopulated_test(pagemap_fd); + /* Touch the page */ *area_dst = 1; wp_range(uffd, (uint64_t)area_dst, test_pgsize, true); @@ -1526,7 +1567,7 @@ static int userfaultfd_stress(void) struct uffdio_register uffdio_register; struct uffd_stats uffd_stats[nr_cpus]; - uffd_test_ctx_init(0); + uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED); if (posix_memalign(&area, page_size, page_size)) err("out of memory");