From patchwork Thu Mar 30 16:07: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: 13194491 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 40CC7C77B60 for ; Thu, 30 Mar 2023 16:07:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFAAA6B0085; Thu, 30 Mar 2023 12:07:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5D396B0087; Thu, 30 Mar 2023 12:07:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AEFE900002; Thu, 30 Mar 2023 12:07:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 88D156B0085 for ; Thu, 30 Mar 2023 12:07:22 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4B56D1A09E6 for ; Thu, 30 Mar 2023 16:07:22 +0000 (UTC) X-FDA: 80626044324.22.2F1CACC 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 28CF440010 for ; Thu, 30 Mar 2023 16:07:19 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Sj41GHY+; 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=1680192440; 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=E56MghZwBJmwObq6HpbLSvJ4ZkxH3HDhcAvyqpX+TEo=; b=EKalpmqIe+oLDdtD+EiZJzLY7IdYDwTgGJp+tchNlF9jiZIkNOHk4jvBLc3m1kPj8zu/o0 4sArhGtSRM+DDT9O3k+kgdKzX76nD9P2h4blk2bZYGUYoKwdFV8F2ED6fmYhdfF7cfrU19 7yDvcV0jkd2rvWf4sKMncJhHX0paBiA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Sj41GHY+; 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=1680192440; a=rsa-sha256; cv=none; b=l48I2ZU0i8y3fY+Nw0HWEmt8+vWWlO6EnCQ7xmeXsBjjFMKZcvs6U2ay5WyJRzP7eb6bOA JrDmjFjBw0appadlk16ifteSt83pBEaOcRS/tsP0rBvO7f2267BdfBZOEV5wLFGgKDBwSR qRdZY0gXrGBJhSBsH0WLlq4bEAylLNI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192439; 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=E56MghZwBJmwObq6HpbLSvJ4ZkxH3HDhcAvyqpX+TEo=; b=Sj41GHY+TP1Hr56nhapEHjBKwRNMZnR2beqvgS3NYHIxeG2kWGHM4f8bLEYyBI5LRC5XIe 2KimJI5Y3ghUs/tqIC9CfHjlHcg3p7hoP2KKBl9tniIxmsd2xORLWB7oGvjjLGMiNoGu18 hwgampGp9RfAfhPPUHW8QXQMu+yyJ70= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-156-HuTmpIlQMACOjLLpWZ16dg-1; Thu, 30 Mar 2023 12:07:18 -0400 X-MC-Unique: HuTmpIlQMACOjLLpWZ16dg-1 Received: by mail-qt1-f198.google.com with SMTP id f36-20020a05622a1a2400b003deb2fa544bso12792648qtb.0 for ; Thu, 30 Mar 2023 09:07:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192434; x=1682784434; 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=E56MghZwBJmwObq6HpbLSvJ4ZkxH3HDhcAvyqpX+TEo=; b=DMVMpnsZhlCzDmy2F2m5pdLqAzTSNaSkGu3Wf6OWaCduGyLZE24S2QazmV0vvH5wZy mknrnna3lzKQKhFRpZpMdLdft92jjeTzl5NyxaugV2GM4g709a4JsLR0eMmtKoVca0p+ jG+AzMHW0EZfZ20OLYnwQaOfBfpHGFBD0/gMWwR1DLbE4iJ9baIIThbwLVdSAcmVpPB9 ocCE6N3eod8ECFkW52RL0Ui5s+QhxVjByN7k8DzIvfAjZzSTsSEQLxFIyXV28M5HCMLk BxEorr7j0ljz8jo38HCMSRpu6hoQBIERg1k7sIltu8FrGfDqwDfvaTPJxyuPU2hdzf3v 6MEw== X-Gm-Message-State: AO0yUKV6yU94K/NG8yETqwxnpWjMlFc/rxJeQ2EiZutwU56g4nIzxnU+ zb9LRIRVU+GE0neeSDXRIqfATRtb/2X/A06aO16J3eMvc4l/2uWQNBV1iIX+IJbg8o6ay7KaBxG 5WTUjdufJlEfhzfzCGF7h5ES/oLkak1vtHbNszTAM9G98dmSb+g7S4LY4/yIYs6ustYZn X-Received: by 2002:a05:622a:1441:b0:3e3:c889:ecf9 with SMTP id v1-20020a05622a144100b003e3c889ecf9mr39965922qtx.1.1680192434282; Thu, 30 Mar 2023 09:07:14 -0700 (PDT) X-Google-Smtp-Source: AK7set9xAaaiu8B7fUg9IKNqpQZzRasQSp33mstFG5mjRfDlXBiQLIYFStz2qxFjSs126X/1sVdKHA== X-Received: by 2002:a05:622a:1441:b0:3e3:c889:ecf9 with SMTP id v1-20020a05622a144100b003e3c889ecf9mr39965871qtx.1.1680192433979; Thu, 30 Mar 2023 09:07:13 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id p126-20020a374284000000b007486fc7a74csm3517380qka.135.2023.03.30.09.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:12 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 09/29] selftests/mm: Reuse pagemap_get_entry() in vm_util.h Date: Thu, 30 Mar 2023 12:07:11 -0400 Message-Id: <20230330160711.3106988-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 28CF440010 X-Stat-Signature: wmd3irgfacdu16qkqrow4krht4d5yyzy X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680192439-806725 X-HE-Meta: U2FsdGVkX1/dB+CMMYMb1PmRodsX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JdG2dSooBye0W8VV9AXKql4XwG93dZw7mOxb9AvX/TnlRNcxnhqvz4u9MEq4jbT/8jwOkI1yFu21f4UvzyQVb0redQVYFW5RipC3M/97WJeSry6J4TlVxn0PleNFy3wnwN0w4gDp/t84Qz8EETOi5O/3JVTH7Jl5VgWhYfweyo087hyjRg6nDtXCj+UzVogQ1PUjks59tmaHP5mtQN9QYZniyiEM4ctWvuDrARfPI/vphx2xeyz2W+9DeJ/Dh2hZyASdVHfwlXTB9ZYN8Crq0Y/Bq4WACANI8N9akSSf+WXytGsJNj0gJcdTJfW4AcIbEQGalUMYB7qZL/BhDZhX9HyWFDW2QuoheQFKIHiURhcJaxtdGFJzdH/E95iBlMeraR+APSSMgiMBkl9cpyE= 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: Meanwhile drop pagemap_read_vaddr(). Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- tools/testing/selftests/mm/userfaultfd.c | 31 +++++++----------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c index 7e841f7e2884..795fbc4d84f8 100644 --- a/tools/testing/selftests/mm/userfaultfd.c +++ b/tools/testing/selftests/mm/userfaultfd.c @@ -1399,19 +1399,6 @@ static int pagemap_open(void) return fd; } -static uint64_t pagemap_read_vaddr(int fd, void *vaddr) -{ - uint64_t value; - int ret; - - ret = pread(fd, &value, sizeof(uint64_t), - ((uint64_t)vaddr >> 12) * sizeof(uint64_t)); - if (ret != sizeof(uint64_t)) - err("pread() on pagemap failed"); - - return value; -} - /* This macro let __LINE__ works in err() */ #define pagemap_check_wp(value, wp) do { \ if (!!(value & PM_UFFD_WP) != wp) \ @@ -1427,7 +1414,7 @@ static int pagemap_test_fork(bool present) if (!child) { /* Open the pagemap fd of the child itself */ fd = pagemap_open(); - value = pagemap_read_vaddr(fd, area_dst); + value = pagemap_get_entry(fd, area_dst); /* * After fork() uffd-wp bit should be gone as long as we're * without UFFD_FEATURE_EVENT_FORK @@ -1446,24 +1433,24 @@ static void userfaultfd_wp_unpopulated_test(int pagemap_fd) /* 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); + value = pagemap_get_entry(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); + value = pagemap_get_entry(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); + value = pagemap_get_entry(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); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, false); /* Drop it to make pte none again */ if (madvise(area_dst, page_size, MADV_DONTNEED)) @@ -1522,7 +1509,7 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) /* Touch the page */ *area_dst = 1; wp_range(uffd, (uint64_t)area_dst, test_pgsize, true); - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, true); /* Make sure uffd-wp bit dropped when fork */ if (pagemap_test_fork(true)) @@ -1536,7 +1523,7 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) err("madvise(MADV_PAGEOUT) failed"); /* Uffd-wp should persist even swapped out */ - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, true); /* Make sure uffd-wp bit dropped when fork */ if (pagemap_test_fork(false)) @@ -1544,12 +1531,12 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) /* Unprotect; this tests swap pte modifications */ wp_range(uffd, (uint64_t)area_dst, page_size, false); - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, false); /* Fault in the page from disk */ *area_dst = 2; - value = pagemap_read_vaddr(pagemap_fd, area_dst); + value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, false); close(pagemap_fd);