From patchwork Thu Mar 9 22:37:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13168422 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 734A0C61DA4 for ; Thu, 9 Mar 2023 22:37:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1582F280002; Thu, 9 Mar 2023 17:37:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 106636B007B; Thu, 9 Mar 2023 17:37:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9C33280002; Thu, 9 Mar 2023 17:37:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DAD786B0078 for ; Thu, 9 Mar 2023 17:37:23 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B07B81C69A5 for ; Thu, 9 Mar 2023 22:37:23 +0000 (UTC) X-FDA: 80550822366.11.EB4D9F8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id A7EE8C000D for ; Thu, 9 Mar 2023 22:37:21 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BRUDcZKV; spf=pass (imf10.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=1678401441; a=rsa-sha256; cv=none; b=yx6BMDftXM7F7yCqUo8ao++3aEXj/Kl/W4WFSSIzbVdUoBvhrSz688DO6wRqR60etigsu9 XMSG3K+F9t7FIiaCslzoh+T3pa280PVtdbpFywhYcNTHLOhf0T0p8d1S/txy6lMQQQJ0nA 245EjOPZ0gnE6Yu34oVZBS0VY/aYi3E= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BRUDcZKV; spf=pass (imf10.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=1678401441; 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=16T/OeYDhKBCd7ofnWvGEa3d8pN7BfzUFvDlTE9Ml0K3rdJQpOWamKASBRw2xXMOnJnR4/ ns+sUEXmRKFdqBsHGFdMNCTaiaXPT/8TUEGtHuWoqwij0s8g5KRO0PE6Lzta5fQPOxA88d UHp9HrHAEW8tqlGbmUgh08HHeiCcqQo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678401441; 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=BRUDcZKVwdvXXFJL0sJS0RfFmdSd0Vgdjputs3nGxjEJ0Id2lJPFiXxvryQQY6HbxxweEJ qC9HM8IwdasPnetzBCJAF+p1jdaMunjN1glYRhhhV/Zn2FmeriI7WPOBxY4Tprhgix5xzz agb05AcMEUhw2BSrdoUajGIhzit6buk= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-90-pbnZdw2tNQm0QMbJzutyFw-1; Thu, 09 Mar 2023 17:37:20 -0500 X-MC-Unique: pbnZdw2tNQm0QMbJzutyFw-1 Received: by mail-qk1-f199.google.com with SMTP id x5-20020a05620a01e500b007428997e800so2059856qkn.10 for ; Thu, 09 Mar 2023 14:37:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678401438; 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=gzrUXlAwTdthBTuUWIzYB4qJJ0PEjBbh4N9FJOVlLX2ZAIXv8B3csOl+46U99l9Hnf Qnh4lpXuPZCrIUiJmuEWCqz4upmA1SvBJYy95SspFSraB9qR4SqfolAn3I8+x6cLtIT4 GuukJLqycp3/eBf2GIM9LCqu4uj1aMltVGUT0MdPI5MBRqn21PiCguz8d51yXFFbyNFf 9VRVInyNMNbubY57HIKAP9ayTHXaZ0uaTGuuOUfdLXmWuinDHio1KC28qrXbPWyz+bpo hTa8lKhFsqVKvK3RfZhZZ5EM6+84afRWn8uK9PpT493RwRccJ+PX2ixceMDLK6BmIwq2 wdDg== X-Gm-Message-State: AO0yUKUwKGGbvh6AtkGvs6m/0Nf6iDl7dYIlFCTz4HyNflyh2bf6rZFK UQXHolM/vQXF95KlAkLwVgolPc7SEj1iiGrYC/VOAyEwctOnLLXDuknY9yZSCScaTy7jivs+O1n G+Pgt1EV/SCo+FF7Rtib/slbShZkpOrwII/7Ad+ILdzJmqUwDoD1ocTWNY76NEvj4dTeA X-Received: by 2002:a05:622a:1a09:b0:3bf:c458:5bac with SMTP id f9-20020a05622a1a0900b003bfc4585bacmr1271821qtb.0.1678401438568; Thu, 09 Mar 2023 14:37:18 -0800 (PST) X-Google-Smtp-Source: AK7set/zs42/Izdu6QlfJ7NnX3Mn0ZoSSqNN1L96LiNcygyJm4jXsLB3B/nRmD9vB/SX58+KtB6MDA== X-Received: by 2002:a05:622a:1a09:b0:3bf:c458:5bac with SMTP id f9-20020a05622a1a0900b003bfc4585bacmr1271786qtb.0.1678401438212; Thu, 09 Mar 2023 14:37:18 -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 c26-20020ac84e1a000000b003b8484fdfccsm172215qtw.42.2023.03.09.14.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 14:37:16 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nadav Amit , Axel Rasmussen , Paul Gofman , Muhammad Usama Anjum , David Hildenbrand , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Andrew Morton Subject: [PATCH v4 2/2] selftests/mm: Smoke test UFFD_FEATURE_WP_UNPOPULATED Date: Thu, 9 Mar 2023 17:37:11 -0500 Message-Id: <20230309223711.823547-3-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230309223711.823547-1-peterx@redhat.com> References: <20230309223711.823547-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Queue-Id: A7EE8C000D X-Rspamd-Server: rspam01 X-Stat-Signature: m8b3mm3xrii697ko4uudbas1n7jsq13t X-HE-Tag: 1678401441-563234 X-HE-Meta: U2FsdGVkX18PhsYbUANCir2mqOFeqjNC3OuhwVTk+E6OWQdZvYPuSKb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pjjZhryMMbe4k6YN3LaSjfLyW4yorm5Z/IqmFABPbH9g5Cwi21i+/VFSeCLl8cJaE8O4wZ9KQlXT9B3lSfzeotsQPhzqWXndG9zImUiindkjy4hSaEaTnapEDf5LFlaoVOEAAQ9Hg27WSz8IWp4h4yn9a/F/6dPHRFtYYLwV1PClDCn2RnriH53+KBio/X0rezz50uCkYFKk+hwDinPwo6THKTEVpHQuyePIkh0CM0MT0WeT3AFFEm5wkd0d/sD8j+Lp1zbYrZmZNLRzNj30E3CU8aIjhkO4UwJux2VQT9flOr3gJOjb74Qv53Ga6N0jxM2ShiJdW33narA//4WFGfQALe1q3XrxaFg5Q8Y3vfuu6cXamlBJlZ5iRHGwK8qgJeCm+O98u52bcNBA= 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");