From patchwork Wed Apr 12 16:42:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209345 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 13D71C77B6E for ; Wed, 12 Apr 2023 16:42:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2DC3900005; Wed, 12 Apr 2023 12:42:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DE1B900003; Wed, 12 Apr 2023 12:42:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87EA3900005; Wed, 12 Apr 2023 12:42:40 -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 789C7900003 for ; Wed, 12 Apr 2023 12:42:40 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 32ACE1C4843 for ; Wed, 12 Apr 2023 16:42:40 +0000 (UTC) X-FDA: 80673307680.20.024F34B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id D803320029 for ; Wed, 12 Apr 2023 16:42:37 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BGIYY+ha; spf=pass (imf03.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=1681317757; 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=WqDS6jtSapL9ifdeK9em1EDp4bv+6WCKRXbZ+q/xf6g=; b=Ym+wO7Ac4e/f62W0zbepnBypkQVG3WlZFv+0wso9PYVjxodmuIxXkZ9knziYkY/np2LTn6 yfh7OBSDPGioJ3KZuOuAlmUEuYQMvZPGvbdCzxDS/JWlWWAM5UVRXeFEAvdtTgUKsAd15V alberqDyaP6IU968M+B7pw+vhZNZ0SM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BGIYY+ha; spf=pass (imf03.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=1681317757; a=rsa-sha256; cv=none; b=CuO2lLF/9fBoL9/MmLS9FPl+B5DMFKyhiXHbOpB58xkoCpPD3U5SEam++0Bv2Xqg3kJ58j NxbM5C2IADoph/6nrOzA08pWs7O+ak0xkCI6GC0ZcQ/PkXrZBwZYnlbHclijxhcfTYN1R2 AjU6RabLSSuY+IEzxFHrv/hmCHU6Sh4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317757; 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=WqDS6jtSapL9ifdeK9em1EDp4bv+6WCKRXbZ+q/xf6g=; b=BGIYY+haPKQQBmcVZwQQSV0OOhzkr1h5L3iNSCZdqmETRyH9DzjGaICsXzrwawl1w6geju Rw1qjGk5pMSfbTfo9TE0t3to8bFj6j3dYThVBQY2kEl7yAnDjUGxHl4ulieOQuJL7wlJxK FCR6/UbPqX0va4JOeAviOlj2p7E+/eg= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-80-5O1tfVcZM1GN6F5FFHZAKA-1; Wed, 12 Apr 2023 12:42:35 -0400 X-MC-Unique: 5O1tfVcZM1GN6F5FFHZAKA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74a65b255beso53900585a.0 for ; Wed, 12 Apr 2023 09:42:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317755; x=1683909755; 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=WqDS6jtSapL9ifdeK9em1EDp4bv+6WCKRXbZ+q/xf6g=; b=bTLfD22BPV5O13/yMJ2CMau7/ZCOibppD+Hgkn+ff4kJKT+bzXJUt+MEzONpC/72GI DuEf8tj6wi64dqkb0M7ONhugUXwdtK+J97tyUp3CnxNGcuytIv4l68e9w5oty4qk1RFO aZCBvT/8japFzycSf21iBMQ/09l0falcOWK7vU6aO71qLz+acEWSVRdo6krDsBhXLCGc ieQqCe3/UaEBt0LfNAsJaK2TroLQ7C81stx0InjdTR+/FnPwsz/GDE4fJcnEZ+55VLB1 hX0nHG6m28G1lrzhT28M9fSEDu6hgBiXCjZ8Q+iqfxcN8balx8RUP1pf0BM6cuqyf8iw Mdvg== X-Gm-Message-State: AAQBX9duHU33jRXv1wdrlbshXnU9eizRq0z9O7Ud5oF6L1Bbs8LBorq4 vJqMVbOy1kE/2wlvlLKV3/MM6/QuqjAyUbcsIR44CTQBiTyU2K8lVWjyWaOow7wbq9jzL4QB8OS WogH1KUkOaJQ= X-Received: by 2002:a05:6214:4002:b0:5ac:463b:a992 with SMTP id kd2-20020a056214400200b005ac463ba992mr4597598qvb.0.1681317754971; Wed, 12 Apr 2023 09:42:34 -0700 (PDT) X-Google-Smtp-Source: AKy350ZccWUkGHYWZ2bzm1zWaJsqlvJFElNocxXwtSRv3N+papWfiGQIPvLDwhR7/K1RnRC+7EOELw== X-Received: by 2002:a05:6214:4002:b0:5ac:463b:a992 with SMTP id kd2-20020a056214400200b005ac463ba992mr4597570qvb.0.1681317754674; Wed, 12 Apr 2023 09:42:34 -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 g14-20020a05620a218e00b0074a25a59667sm4749109qka.115.2023.04.12.09.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:33 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 09/31] selftests/mm: Reuse pagemap_get_entry() in vm_util.h Date: Wed, 12 Apr 2023 12:42:31 -0400 Message-Id: <20230412164231.328157-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: 5geg5194j7pmxjrt968ajir6eskjkzou X-Rspam-User: X-Rspamd-Queue-Id: D803320029 X-Rspamd-Server: rspam06 X-HE-Tag: 1681317757-435925 X-HE-Meta: U2FsdGVkX1+iys3PMjp1azmp8SWPnIVwQ7z2DfRksGTGxYppsDUjD98GNboBEt4d6aVzYlhODNRJllMulHNIOQn2ZWPccGFzag8pm2pVKMw+7N5V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rgXGxi0Uz+yTX1hvmQVgRB10nz/Pk/QXQO6VK1Z67VNRsBk4NVnp5joN+IPBcex+HNVHc25Ptofa/aohOq860soEl4VWW8jW3clWUa/N+W78C3dNtTN490RmejQYRgx9uruDSlAhC6oIWUrfNmfwHJv77oXcDPhoy9FimPqHrfUPMyFmEDU/O+lhZ3Lfe0NdQypHe3eLKEajEWlHTL/CjYgEipuObUH9RilaJ2OJKlZ++Vh+lnjPG1ecIgV+vfH23Zc+zEmJLwXtq8tiOKem/ZWj/ZAIvOQ4GlKyyWdN/VHWBE6cQXaP0wJvq9gYGvDKk1aMD4Gvz2xhvrKWoer7xFLmrU6+BN7rfjJrO9RFiqsuNTnRwgdIGL+rc5XXg9ZczswZxN6dPdvcV1eco8qNEVS+DtbDCX1UXsXdPUmf/uo+ADOAzPHA== 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(). Reviewed-by: Axel Rasmussen Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- 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);