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: 77289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1249842vqo; Thu, 30 Mar 2023 09:21:43 -0700 (PDT) X-Google-Smtp-Source: AKy350abm/z6dG1CcC7YE1jEWQsSaSM1I2lQEK7U6rxaFfZ06Odz0pFqV1sTCmmKVgR6jUMWtxOi X-Received: by 2002:a17:90a:190f:b0:237:50b6:9838 with SMTP id 15-20020a17090a190f00b0023750b69838mr28314518pjg.45.1680193303081; Thu, 30 Mar 2023 09:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193303; cv=none; d=google.com; s=arc-20160816; b=iQloERRP1J106BE+2cEV25pVPRVbEQ3HI05pPnHHiHGGyZ4PbYsZ8GTZlh1EoD4xUH P3oE9o2AITRSByY9sZBcmQENIIfozkBuM7CfxSjxZ7wKByhP8QrHlaxZqS5xR7xFEWcC Z5MkMu7IaMW9hjs2w2nRp1HqgT9s4RuAWtaqdxctrwSgi9m37qCQSY48CLMStlev7id9 g89SMJOEKdPCovpDt6HH0wZFjdCMeZXk6GoexbqVJwvTXNhwHkyDLAMkD4z2af3Gkz08 CUainGmLsavQ69xCuCJiCDQc3XvjtkNZ5ZH7k64dk1TVPjlmrmlhR6gy/K5ovARC3wQv DCJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=E56MghZwBJmwObq6HpbLSvJ4ZkxH3HDhcAvyqpX+TEo=; b=TO+Z6oSBvCHq0o+ShU39+B1bfDcG/LrBjfvLHXUbDI8W8U0ui2WQVKugw0b7o0fam/ xL0ehnRpmRZFNzME9C1baWcXWaPiC8ocoq9UEcYqdFlVShzncPOGv+TR2bAxXrcbLukH +xxjhTpmfSYg8DL9Fw24rq1i3eqTjw/1GDNPFebDHCTGcy5/juoSe5eFHSqHg98agbdE 4yquwcahWXMhMIp7+6s5wvpXBbTgR5tB44Ak23gURUu0/WHpBAWkgc4vFE95xvgmcpDU 93ZpnKvo2+SXEV28t5mG/V64hQCf0eNCWTwc8iN6+DQ1GIR8SEna0Dzisb/kAYI0c2Pp rxzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AF91dBak; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r21-20020a170902e3d500b001a1f6d61e0fsi14747930ple.134.2023.03.30.09.21.29; Thu, 30 Mar 2023 09:21:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AF91dBak; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231272AbjC3QII (ORCPT + 99 others); Thu, 30 Mar 2023 12:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231625AbjC3QH4 (ORCPT ); Thu, 30 Mar 2023 12:07:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02510A27B for ; Thu, 30 Mar 2023 09:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192436; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E56MghZwBJmwObq6HpbLSvJ4ZkxH3HDhcAvyqpX+TEo=; b=AF91dBakt6zza2SclKAYqOdBUynTFRYfJxLY53C8Xq/LnXEpnJTDBquEfSREl0K2WoeYJN xIi2krrkU+KlWIbE9RWdr2MiujoXt42RX6JrBRZo6oJavojhsOKB8XAY8ikV5+2WGgrv63 lNZBLuGFon6vIWriVoezjxEMqKyB1PY= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-290-1dMOqwSCMwKLlmZnQcXyPg-1; Thu, 30 Mar 2023 12:07:14 -0400 X-MC-Unique: 1dMOqwSCMwKLlmZnQcXyPg-1 Received: by mail-qv1-f72.google.com with SMTP id px9-20020a056214050900b005d510cdfc41so8511729qvb.7 for ; Thu, 30 Mar 2023 09:07:14 -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=Y7kkQZV5Q5v0MzhjgxQ+hZ+/NcwFXo6RRqsHCkfMIcbVyAkdZoGCdSurKvRPeNFDOK K/toUIAzUFlCqNHwAWBYwfCITiD1OBmeq0aU3cvuVQrWO2o+M/GQIbgYTknZ1426EyI/ BHsw9751J+KaHDhrrqfzYpAHbAqwmKOMJezknfZWAGKCq395w8eRpCMx93JF7DykRcTS OIAklilFWGYFNohCxPqMx3CKze8GDt0YJqyST9/ifRu64LyivT18vG3IxYEar7Eg6q0T qwYZ/8HazpsL/X7kQGdxuxO9nA1CNbzcydUt9JsyXYynW4GMY3PfWlUnyUBcJTpMXfVO jekQ== X-Gm-Message-State: AO0yUKUAKpYEuhKuYfp4N4iyNa3mIUtlFDuYz2XrO+Ihl2YBxFxWvCTQ TQXvSP8LM/k3qZfV6MfuQPi7uUStDsWPrcW9twcvRngNUKmvn2QSszy2hUGf7zALODDp+b8mNq7 P4RQw+pBukVAB9Bdi21rT69TE X-Received: by 2002:a05:622a:1441:b0:3e3:c889:ecf9 with SMTP id v1-20020a05622a144100b003e3c889ecf9mr39965906qtx.1.1680192434233; Thu, 30 Mar 2023 09:07:14 -0700 (PDT) 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-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761810373349016639?= X-GMAIL-MSGID: =?utf-8?q?1761810373349016639?= 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);