From patchwork Wed Sep 14 09:12:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12975880 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 962FAECAAD3 for ; Wed, 14 Sep 2022 09:12:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBFB98D0001; Wed, 14 Sep 2022 05:12:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D6F536B0073; Wed, 14 Sep 2022 05:12:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C11178D0001; Wed, 14 Sep 2022 05:12:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B29F06B0071 for ; Wed, 14 Sep 2022 05:12:31 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 842FFAB698 for ; Wed, 14 Sep 2022 09:12:31 +0000 (UTC) X-FDA: 79910125302.02.5C29AC3 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2080.outbound.protection.outlook.com [40.107.92.80]) by imf13.hostedemail.com (Postfix) with ESMTP id C72DC2009F for ; Wed, 14 Sep 2022 09:12:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ks6kwu3jLh1rKRLd0O4YWhhaNsb1CKhpUnZyUXTiA6y0ip6ZFP+1pUxkLP5rIl7u0yJNFzVHBdR94jgqEEFbOAaQgFvbpsfEZ+aAb7nyWnTymqjNFKO5k5uCcykJccpi6j3s/moK9EYIZKiguw5Bze2TD5mdJCEXLaRPx9i/77AV75nl2Y93J41t9M+oFkRozDCijFu7fIPTPAwM0l2tDflfzMPHkxpDn9qn7AhYou+bdg+QsLX/1yB0fMI9ps746EkJXNoeAmRulbbjL2IYt9sdjWZ3g7oe1wNsYnndRClS4ISHH3LrCSDz6N1Bo65bW82GM69WX5R5nwHXyLmseg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hcBz27dx0k6tZLhoNzFfz1l1Z+o3ywvQ68rCVs+p9UM=; b=EoSjocsXKRlEQ7KTzhjzRNs3YbhE84v6sBPk+TCAxuE58zQcoGL8kOUhdETxuHTDbVnO05iwQaQH9rtAQI28D/UDUlgWa6KQLJ8OOcd+JaDQQvyTAAH6MLeUQzQk3SZkg/+D9y7RQ5ywTsnHq8/OZ2KCbjfnQ8TUpzuGAsr5x6zc2EhgjqHA0PTFLbGRgTQuPAmjaLL5//Uin5bZicD8JU/TqX4edop53RVif41aoxWqNtA6JKhtQBqjsNhpdbOZ54jCIIycOVCZfnjXz3Sss767rqLlHWovkMoxceTYP6h7qLPbStVFImxB+oNoygW80nKNgnvQwuq4T3Cd9vfwZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hcBz27dx0k6tZLhoNzFfz1l1Z+o3ywvQ68rCVs+p9UM=; b=jQlm5UOI2YgCiWTUiucS04yEMKDuddu+cz0Tq/oauFYGbqZxhSduYaimHbAOEZMvTf6XOUaAE/5kz1Qvk9f8zUHftQiznUR+AzhsUCA45djXztdlei4LbYhcl+LkGdgRQshT01J8Bq7JPZLJ8Id6T7RVUKvvvRcqth/G71oTQSjlCCYB4lT6thO4L7USP7rqfz9Vd01NRIg/0tgOrf6yv6ylzJdGmDuxZnX8VoRy6hBTQA55nqx9XQnD/HRGjlWaqR2a2md0cYk2RricL4UGkxIZWcjylnmTYIgJ/d5qzdB922NhaR1Q178i/3eMjE8+n/pT7SlBuexTllmKiDneWg== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by DM6PR12MB4894.namprd12.prod.outlook.com (2603:10b6:5:209::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.14; Wed, 14 Sep 2022 09:12:28 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::243c:a9ba:2442:8974]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::243c:a9ba:2442:8974%6]) with mapi id 15.20.5612.022; Wed, 14 Sep 2022 09:12:28 +0000 From: Alistair Popple To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: John Hubbard , Peter Xu , Nadav Amit , huang ying , LKML , "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org, Alistair Popple , =?utf-8?q?Mika_Penttil=C3=A4?= Subject: [PATCH v2] hmm-tests: Fix migrate_dirty_page test Date: Wed, 14 Sep 2022 19:12:05 +1000 Message-Id: <20220914091205.557676-1-apopple@nvidia.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: SY5PR01CA0075.ausprd01.prod.outlook.com (2603:10c6:10:1f4::11) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|DM6PR12MB4894:EE_ X-MS-Office365-Filtering-Correlation-Id: 8e82983c-b49a-4333-c9b6-08da96313f32 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A6J0mOkAZnyILdNuznvGKatngcgWPB9PWVgGO76gPFDQtC8jGRqKdPZD4q3AqHFyrHZgoAHdyLTgHBwB/jPHlBrRCwo+MYGckIDDyFsU5ch8Q4hc8exfgRBu1v/7r26etmlvDazZbDHNf6AJtxVr+VXAqgUjBfvjIaO72zUm03cKs9/9tNrpqK1h6I0WeFhtuwCIBxX8bIz7YinRxURCQ9ISg8ULBROoA3roRvjBNPhRI3cTE6wDB2IkmXJsWdTH9zTuJJSXqxseZSooZ6xp+IVfNabVFmy4b9Kx7vxQD1PhTnujgmqrfQqR9F38hZHzHfSP/F22Jxu/XD03xIzUCJ5MzdNEFAe5yE1+aKF6Zt7FDpsfObhRfIi73zbi75DMRcK/02JCKKjg0orIgEwWS4WntqGqqaoLnikLqTFv82oL71Ouw24pGww9Bdss0B0qqzAI6TD4dTgBeZj+9YbpHNFIi9lBPzA2lg4eF5QA8EeBbRnF3keuGLmAVlf0D7GjZ7Cf0XI8LXZ8radjRJTSFDRSAieDg+Dor1PETOLCFRryloKfi1Go9gz6Dszix1F15a5SxENod95zFo+o3JK1nbgRU+YAIwr39TF4UWgf7lzclOZeez2ANvwSeB4Ezl3ks8743yS5IuCLeifAcfqTvba6IXV66Hkgx2hzhF15Z3YFqGiHhK944hMKvclTjDcDJ2vQFEzyR6bQf0RyEIoqBryG5kooecyI/cIqwQM/CCfo8lt5dLTfQ3yVLrfHInRa X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB3176.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(39860400002)(136003)(376002)(396003)(346002)(451199015)(5660300002)(4326008)(8936002)(1076003)(2616005)(6666004)(2906002)(8676002)(36756003)(66946007)(316002)(38100700002)(41300700001)(6512007)(86362001)(54906003)(66556008)(6506007)(66476007)(6486002)(7416002)(186003)(83380400001)(478600001)(26005)(14143004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?NS4yqF05rccNa2800IVjnvF4cSI7?= =?utf-8?q?tJXI6J/Xj73T5AYzuFR1YLpmV0BBgYOB9hjkyAHpT0hyu4nBQrtXKz6xqiYuXvsM6?= =?utf-8?q?ewDkV3CGqI85MtV+2URiD/xjdoV/B+S5SCviPiduiUsDjjRvo13wHW32J/fozwlj9?= =?utf-8?q?pd+I2MRCZ7Whg3nnh5tSoohOf0oWefV4XBtw0vvJU1Z3bGRfCOgjrXlk/Qk/hTUdm?= =?utf-8?q?idAtgSlCC/S4IB7Jbn5xOv+EKqMSlLp22Oey8xWUuEv7YNtELZvzYjY8wghJXOi8B?= =?utf-8?q?II68aNQiUcCjTQoehYMwqMIGO0fJcVRWZhDaJscRS1cXc9QlbSnV74dWcYTwPXoY/?= =?utf-8?q?6sw78NZC4AGc9schlohBxzmtHZiCn1TOhybD01bpv953s0aE5yKfa5NxwrhgCC4nl?= =?utf-8?q?DF60AK8JZOQG38tC7u0i9HZuX1MwAc38y6jbcm4zaD0EqbTzcWzWjH1HU3M37Waag?= =?utf-8?q?iDnOX2AM2rFbnKHt9AKFBWKfFD81E5WjG6AEHThR8OXDzw3num99o3GUFgHY1a9xA?= =?utf-8?q?uW3YHinUlP1R1r9isAMgjK10tTEkZtB7km52Tzawy2Gfvm+Hos7A2YbqthAf91hut?= =?utf-8?q?HDlemcvR4Q6KVGVR/YZI7Dsij6n2UqVR6yMYaW3ggmgLSbg2275Jj1/5aAT+Z6WZI?= =?utf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utf-8?q?Mp+rd31eYki5?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e82983c-b49a-4333-c9b6-08da96313f32 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2022 09:12:28.5140 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lokocAU/u/Fcw++SXbSifRWfXD2CN2BPSUH5hha1YAhFW4ObrMZki2veBuOd2r0NsvSxiKQ72Ejmdoiwuq0nHg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4894 ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=jQlm5UOI; spf=pass (imf13.hostedemail.com: domain of apopple@nvidia.com designates 40.107.92.80 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1663146751; a=rsa-sha256; cv=pass; b=MJz6YDISicie2k3HqrNcajtRB/aZd+ILIc5QEhBtL+7y7blPxlaoxuB3CgePhdnC8JFHDl 1+C5wxz4E1TdBddFnwWgLvAd0BbSULjQhaQiCvWVkjufa1BlCV4wHafX8j4eiRxG9+QQQ3 /aJrqE+AmKfVU1V8kYoF4W5Jbd3XmB0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663146751; 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: references:dkim-signature; bh=hcBz27dx0k6tZLhoNzFfz1l1Z+o3ywvQ68rCVs+p9UM=; b=rQ0Gm1YhWxjWkrjJ5iY9vM+AFDOok/hYCNd9HK++liA0nq9dHrJDJ87jN2P8HQCSGtGrHN AP+JNuWnk+tcWieSDUXigc1EhhRkLNAn2GLzq/zPgfIsy9qwW/XSFzdjFORq+N5XSRfXpS dwaAzw50vXuaa7SLvBb9swSF8E+5liU= X-Stat-Signature: q9zitw1dqo1qfrm1cjxermy47wfkkn5f X-Rspamd-Queue-Id: C72DC2009F X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=jQlm5UOI; spf=pass (imf13.hostedemail.com: domain of apopple@nvidia.com designates 40.107.92.80 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com X-Rspamd-Server: rspam12 X-HE-Tag: 1663146750-197614 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: As noted by John Hubbard the original test relied on side effects of the implementation of migrate_vma_setup() to detect if pages had been swapped to disk or not. This is subject to change in future so explicitly check for swap entries via pagemap instead. Fix a spelling mistake while we're at it. Signed-off-by: Alistair Popple Fixes: 5cc88e844e87 ("selftests/hmm-tests: add test for dirty bits") Reviewed-by: Mika Penttilä --- Changes for v2: - Added Mika's Reviewed-by (Thanks!) - Moved pagemap checks into vm_util.c as suggested by David H. --- tools/testing/selftests/vm/Makefile | 1 + tools/testing/selftests/vm/hmm-tests.c | 28 ++++++++++++++++++++++---- tools/testing/selftests/vm/vm_util.c | 22 ++++++++++++++++++++ tools/testing/selftests/vm/vm_util.h | 2 ++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile index d9fa6a9ea584..17e36129efd2 100644 --- a/tools/testing/selftests/vm/Makefile +++ b/tools/testing/selftests/vm/Makefile @@ -100,6 +100,7 @@ include ../lib.mk $(OUTPUT)/madv_populate: vm_util.c $(OUTPUT)/soft-dirty: vm_util.c $(OUTPUT)/split_huge_page_test: vm_util.c +$(OUTPUT)/hmm-tests: vm_util.c ifeq ($(MACHINE),x86_64) BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 70fdb49b59ed..509fe8c5158e 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -37,6 +37,7 @@ */ #include "../../../../lib/test_hmm_uapi.h" #include "../../../../mm/gup_test.h" +#include "vm_util.h" struct hmm_buffer { void *ptr; @@ -1261,9 +1262,24 @@ static int destroy_cgroup(void) return 0; } +/* Returns true if at least one page in the range is on swap */ +static bool pages_swapped(void *ptr, size_t size) +{ + int fd = open("/proc/self/pagemap", O_RDONLY); + bool ret; + + if (fd < 0) + return false; + + ret = pagemap_range_some_swapped(fd, ptr, size); + close(fd); + + return ret; +} + /* * Try and migrate a dirty page that has previously been swapped to disk. This - * checks that we don't loose dirty bits. + * checks that we don't lose dirty bits. */ TEST_F(hmm, migrate_dirty_page) { @@ -1300,6 +1316,10 @@ TEST_F(hmm, migrate_dirty_page) ASSERT_FALSE(write_cgroup_param(cgroup, "memory.reclaim", 1UL<<30)); + /* Make sure at least some pages got paged to disk. */ + if (!pages_swapped(buffer->ptr, size)) + SKIP(return, "Pages weren't swapped when they should have been"); + /* Fault pages back in from swap as clean pages */ for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) tmp += ptr[i]; @@ -1309,10 +1329,10 @@ TEST_F(hmm, migrate_dirty_page) ptr[i] = i; /* - * Attempt to migrate memory to device, which should fail because - * hopefully some pages are backed by swap storage. + * Attempt to migrate memory to device. This might fail if some pages + * are/were backed by swap but that's ok. */ - ASSERT_TRUE(hmm_migrate_sys_to_dev(self->fd, buffer, npages)); + hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_FALSE(write_cgroup_param(cgroup, "memory.reclaim", 1UL<<30)); diff --git a/tools/testing/selftests/vm/vm_util.c b/tools/testing/selftests/vm/vm_util.c index b58ab11a7a30..2768d4f3de4c 100644 --- a/tools/testing/selftests/vm/vm_util.c +++ b/tools/testing/selftests/vm/vm_util.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include #include "../kselftest.h" @@ -20,6 +21,14 @@ uint64_t pagemap_get_entry(int fd, char *start) return entry; } +bool pagemap_is_swapped(int fd, char *start) +{ + uint64_t entry = pagemap_get_entry(fd, start); + + // Check if swap entry bit (62nd bit) is set + return entry & 0x4000000000000000ull; +} + bool pagemap_is_softdirty(int fd, char *start) { uint64_t entry = pagemap_get_entry(fd, start); @@ -28,6 +37,19 @@ bool pagemap_is_softdirty(int fd, char *start) return entry & 0x0080000000000000ull; } +/* Returns true if at least one page in the range is in swap */ +bool pagemap_range_some_swapped(int fd, char *start, size_t len) +{ + unsigned long i; + unsigned long npages = len / getpagesize(); + + for (i = 0; i < npages; i++) + if (pagemap_is_swapped(fd, start + i * getpagesize())) + return true; + + return false; +} + void clear_softdirty(void) { int ret; diff --git a/tools/testing/selftests/vm/vm_util.h b/tools/testing/selftests/vm/vm_util.h index 2e512bd57ae1..307e11f72341 100644 --- a/tools/testing/selftests/vm/vm_util.h +++ b/tools/testing/selftests/vm/vm_util.h @@ -4,6 +4,8 @@ uint64_t pagemap_get_entry(int fd, char *start); bool pagemap_is_softdirty(int fd, char *start); +bool pagemap_is_swapped(int fd, char *start); +bool pagemap_range_some_swapped(int fd, char *start, size_t len); void clear_softdirty(void); uint64_t read_pmd_pagesize(void); uint64_t check_huge(void *addr);