From patchwork Fri Sep 2 00:35:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12963467 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 BE709ECAAD3 for ; Fri, 2 Sep 2022 00:36:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 539F78D0007; Thu, 1 Sep 2022 20:36:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C1ED8D0001; Thu, 1 Sep 2022 20:36:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3141B8D0007; Thu, 1 Sep 2022 20:36:28 -0400 (EDT) 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 1B6CD8D0001 for ; Thu, 1 Sep 2022 20:36:28 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E18771403AB for ; Fri, 2 Sep 2022 00:36:27 +0000 (UTC) X-FDA: 79865279214.22.BABE01D Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2059.outbound.protection.outlook.com [40.107.92.59]) by imf23.hostedemail.com (Postfix) with ESMTP id 591E014005F for ; Fri, 2 Sep 2022 00:36:27 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BwGIx7uOkT4bj9sFaQJRp8+TJF50AHCi5/3kMKOiUFiRY+H2jpRwQyOdM361qYCHZAyoeHaorIEA8h/8gtGNVpMh1ed88IHzx4OYkEppJfZm7MbMVYGag7qy9p+HztCDdnTyCQy7eX3iQDu1AkXH4l/TzhjlStCpPmYh31EJ6vU2JS0YNSWF1FSoLzBwpQ/kHP4pVG2OGQ09WMeMd3gp6LuN0c/sQ3pM1VTM+3KOjBBvEmgyHAcjMtRsavKlzAsRJGCioJm/FRG2OUSO7eNVrBFI9Q7kU3HNZwCYYU2E9kJJX3BacWL0xfVUVAofWr+T57lML7SkQWLuoE6DbGwnfA== 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=eiZcJOw/Rdqbcxw/aFtmjNXtEWbSyoeadqVjC97LY1g=; b=QtnrpoEQj7E6rRzZnGoJ8l2rLmLa2kzGcWLqIwPJn9fvx9cvMzjZ/KF0L8/dyR5ce/RRlSjb+KqpblVhkgQtO/wQjqbNdFhwNRzvVvneYyhIA4mELxO+FWO9h95/X+XgBpvggBEt8eeMIXagmtvXl1jDtJlapf7hS03WJmoydDViYJN6BwmvetjC4CkMQM4qFMfzBTB5a/RSjVBaN4iiWMfL6d9X9BkCh/JtapJmPWvxk7F8VfzCM1Av5nseg+SWXsJ68BpPXZZ78LbbAMJtPVwjK+//Qb0V+YwDbGVFS3avVtK9t8PFl727EXncfN6cqAwILeZujM3He6lGbNKKxQ== 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=eiZcJOw/Rdqbcxw/aFtmjNXtEWbSyoeadqVjC97LY1g=; b=sgHnj4CYpJYMwiN15g41RE6v2YRVDjN1KRDQmqulsUFYkn1gHH1wwei9EjevxeJxQRNKg8lGVuexn7OZuBnZKoIqbjg9Vhk/N5NSK85IUZ5friPMgzIxf5PSK4l1QCfscOhsvP3+T3EILKNET/TnQ7L/ltLZf4EDGuSq3knatm040o2mo5hHKA9MVS1UZRh7XG3BTZqFXuCXSTsymsgHDh3UKtOwn5iHK8mAT5DP9XLkJEQL7YGCCjFWW8WKG1tY0RoRRyjW2nnVbDQjBoWsSCI/2lLEVIGNeR9YDF7yy6xoOFqodgWVb46MBo8N1Z2Nfb1iJnU1YMqsOLpfif9SpQ== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by DM4PR12MB5086.namprd12.prod.outlook.com (2603:10b6:5:389::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 2 Sep 2022 00:36:25 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::7432:2749:aa27:722c]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::7432:2749:aa27:722c%7]) with mapi id 15.20.5566.021; Fri, 2 Sep 2022 00:36:25 +0000 From: Alistair Popple To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: Peter Xu , Nadav Amit , Alistair Popple , huang ying , LKML , "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , John Hubbard , David Hildenbrand , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org, "Huang, Ying" , stable@vger.kernel.org Subject: [PATCH v4 1/4] mm/migrate_device.c: Flush TLB while holding PTL Date: Fri, 2 Sep 2022 10:35:51 +1000 Message-Id: <9f801e9d8d830408f2ca27821f606e09aa856899.1662078528.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: BYAPR07CA0085.namprd07.prod.outlook.com (2603:10b6:a03:12b::26) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ac77a4c3-da93-448c-d75e-08da8c7b2aa6 X-MS-TrafficTypeDiagnostic: DM4PR12MB5086:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5By7JDjBV4FpvC0E2wNtdupNsf7r0E3W3wZqcO0NzjDSM98U210fvCJOK0aOZK/IRLsojvLDPE3s+Dd+fneNQbigsasxpJKUW+wlafT4P3yvbPOM+zTdBvw15cezTRvt9d0It4ijrCR8DR68oGjlcRsSlss1Tjy9Y0exWk7H/ECrJxrRqzHBUSjzRRgNkOiMJ20M5qf8O1AIABgfTrJxAZlPqvbeSGXU/96wyyh450esWAqo+pVzm3kQEB6skkRU5yM40oB0SOZPDaMXwhF2oHpLvou5SeZ1xbJ7liugzniVIMcRzZmLn4YKOZRL7EPedY6YLAfojneRJ+zVvlnco3BrL/hJ9TiZpkjrno+Wwdl9fU6KAKuAC13TkE+yrFoXQ/OUW18MTpVrvTOQb8C0gjVUjJ9ifYnRmCchvdfGupmwsY2l0JGnuUonGntMZhY/CVWpV/mYoG4UEkX21Q6EoD713Jiftchh1ftkq6/BiPhVm1+wNWd9CIQzSF51ERzZ5I7KIh9SaNrH04SU9keQibiCiXujNdxd7DntU2hdzNf3PAKj8vpFo+IYgukwne4VYZHNhZlWg0sbkxKy8OeV11vWr3wmCSyMGeXeEz6/nozJ36JrC0/+Or6Ou6z9aFcZx0RXWISV6ETYTbojWRJsGcBxXAJaaVho5PNPYmrq2PJk6jSyfFcFinkuWH9VMd8vdEemkhSrB7b39iC6ckLWHA== 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:(13230016)(4636009)(366004)(376002)(346002)(39860400002)(396003)(136003)(83380400001)(38100700002)(66556008)(66946007)(66476007)(8676002)(4326008)(54906003)(316002)(2906002)(7416002)(8936002)(5660300002)(6506007)(6512007)(26005)(186003)(2616005)(478600001)(41300700001)(6666004)(6486002)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3G2x+tFQF0Bd6VTDJFUQT1LTnTEEbkHbuy6CcZEs1eJts9JPjNQqzJuWE9tJNqandOfZGDks/GjTuplL3s2hW4EG2UUizk3a4WlEAdSD6XAu29kMuq0LpA6UIkm+IEJkhGzCS/rDv1gSPzO3Wj/N9lHVLLs+MRKnkl7vgGgNIRtpcM7giSrGBS8ZpnwAsWMitAZGM8YugyLq6LkgDKzVxbMxV/HwMeOPDjOS4ayw61Ia1g/ihfTgU4aTcWRcnvzKp2eRkxqTbnJ9/EVFm64DTfpG8bOYofqhX5z3YgjiNnz2XnBwjFzFqtaEMcAz6WqPoTXaqV9pAvIzas7hQVbve3EYbcTdiRRsZ/LqNurgiBSmL4Iz50KvTEvGw+ex7yvOi756drYiGCY2rM06pbxZERL9gN8CrqU1WhzPBYODex4jQt3CkODbeM+GcLJxSUtIMJo/pimK3806kM53dXfGZMekTknIHi73YurtmvhsmR9gWli11ne+RkiGFDqIIlVto13vjmYOHW7SawNmJUVhXvsdvEFIrnIbpulaKmIhqphB4HTY/tTdLYVz4NuxCdEvArMh6E+JXl2k9+ysh+FxA+SkKfXmWj3eOs4oH9eXjL+53sA63OuGrvzPjnn2Cx60fit7DhjvM2j/lQPdm4a4TW+tV04BleB8PwkTvK6b4F2eY5eDn1mcaJcvi5re+aS++vraCtjnmXcIDVLcyC9LcjSabN7tjr4tiMIaMITdmoayoYJKFM4sOJY9/eayuVku+ZRZivfGGLMK3TQl7ZILxemCWNOpVv2Y1KR5Y19JKgKftAONIq8Yz5mm84aIAxg06UxmMK5042EoacEpAiDkj0/9roTGK9oPQTgLevGRrnfRgyNMrpuai8tGdM/740JsiuIapNi5ydxSJnUNB8dnAiWnZZQeqhc5bNSILdfFX3sYY/BCl9Adaw+m9mymhXhCwGcxA3ECuUbqcEO5vPhs9JWqe8U97YNa9fc9gog1Q1lz7Ldy2Ty3WDUOrHzxHNL+A/oE3dXuHvQE3/oI+pl9ShiMcvypr7E7A5puPAAhPSUN5cyCdStLtbgC/zroSH6e0wh/Kot5ZsXyw2xYCfCh00TklNLo6IFokxZZrEdtnWTaReFL0dgaN9SiMhxVb7TmAGi/3zv7T3Xeyjf6AZezHEvrJsRPAAwShbY3YFv4CzPfiWgB83K7LxUCuB4wZyrE0qKbnV+AxTjOzJntmccKSKPDVcAE6MKIJ2ysXC3uAQuM2cuRc67RnMxfdzOZi2CLzdDRDcqJnC7zFfg6YxrzPa5rg7KUnK+/D0FaezbNr6lZDd/iTo+ZZLGs/AOEAxEltIUrqL9Aw/qLilCnHtuOLE6vjsdtF1H1/sPx8ZABXJvfI/sJX1Ca0O8zY09+EIfh/3EHvR7uIoKtfuMkiGSlVC4DvBhDtx/Yda2joV8UgQJjKdE8PqzvOb4YrZ3X7jGKMCyRr8vje3VpebsakdHNSGEDzPpIvxmg/ATy89bpV7kgM1UNdL8y8EAkcaawDg2bN5not0GyQHBbqFkHUZ4MsF+d6hHr3kO6erSoqZOvnsFbyx2vHnIvrK1eWmplbZ1W X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac77a4c3-da93-448c-d75e-08da8c7b2aa6 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 00:36:25.2820 (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: 01V0ss6H0tvrrxartWe58iu8sKaOouzy1+HsWOLX3ATOVpRHxzv1QacREU11LQuJrg/2fFsEOSRavEoexZJtCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5086 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1662078987; a=rsa-sha256; cv=pass; b=aBLDBNsNNkrkZgKk07nQr+M+1QuEro+SWzgpuna+NfJK4Sdi/dSo1JOSqTO82AwbAi7Lch M7FmL/11dl9UJpXBmVQtA/T65DDdFsXS29guW+id3yaoZ+Vz+qvAMs5twj6c1xuGHyNZ2t 1CoLQt2iQa9b8gZ+UMwwFU2UhNasiRk= ARC-Authentication-Results: i=2; imf23.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=sgHnj4CY; spf=pass (imf23.hostedemail.com: domain of apopple@nvidia.com designates 40.107.92.59 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-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662078987; 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=eiZcJOw/Rdqbcxw/aFtmjNXtEWbSyoeadqVjC97LY1g=; b=rzMwtH/bO9TjLalb/uRZyK6NksYDpGs7Zn999TXWT+u1h6ZuFBnFrDvoh9h6He01433GsI +kOyJfPM4140fSDgrMWekGlORX476+HtB/gfNWJNVpPzgFi8cdhznRmuTSn64bwiPz329I cs64ZXKuLC9qAnWfjiSrQVsZzWDaBFs= Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=sgHnj4CY; spf=pass (imf23.hostedemail.com: domain of apopple@nvidia.com designates 40.107.92.59 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-Stat-Signature: kkukf9aw3aq9sooqc93embk8kzquy3jy X-Rspamd-Queue-Id: 591E014005F X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1662078987-246113 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: When clearing a PTE the TLB should be flushed whilst still holding the PTL to avoid a potential race with madvise/munmap/etc. For example consider the following sequence: CPU0 CPU1 ---- ---- migrate_vma_collect_pmd() pte_unmap_unlock() madvise(MADV_DONTNEED) -> zap_pte_range() pte_offset_map_lock() [ PTE not present, TLB not flushed ] pte_unmap_unlock() [ page is still accessible via stale TLB ] flush_tlb_range() In this case the page may still be accessed via the stale TLB entry after madvise returns. Fix this by flushing the TLB while holding the PTL. Signed-off-by: Alistair Popple Reported-by: Nadav Amit Reviewed-by: "Huang, Ying" Fixes: 8c3328f1f36a ("mm/migrate: migrate_vma() unmap page from vma while collecting pages") Cc: stable@vger.kernel.org Acked-by: David Hildenbrand Acked-by: Peter Xu --- Changes for v4: - Added Review-by Changes for v3: - New for v3 --- mm/migrate_device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) base-commit: ffcf9c5700e49c0aee42dcba9a12ba21338e8136 diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 27fb37d..6a5ef9f 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -254,13 +254,14 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, migrate->dst[migrate->npages] = 0; migrate->src[migrate->npages++] = mpfn; } - arch_leave_lazy_mmu_mode(); - pte_unmap_unlock(ptep - 1, ptl); /* Only flush the TLB if we actually modified any entries */ if (unmapped) flush_tlb_range(walk->vma, start, end); + arch_leave_lazy_mmu_mode(); + pte_unmap_unlock(ptep - 1, ptl); + return 0; } From patchwork Fri Sep 2 00:35:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12963468 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 89736ECAAD3 for ; Fri, 2 Sep 2022 00:36:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 253508D000B; Thu, 1 Sep 2022 20:36:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DC1C8D0001; Thu, 1 Sep 2022 20:36:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 007258D000B; Thu, 1 Sep 2022 20:36:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E0E9F8D0001 for ; Thu, 1 Sep 2022 20:36:30 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BE3411A05DE for ; Fri, 2 Sep 2022 00:36:30 +0000 (UTC) X-FDA: 79865279340.03.DF37A92 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2072.outbound.protection.outlook.com [40.107.223.72]) by imf06.hostedemail.com (Postfix) with ESMTP id 4DCD6180042 for ; Fri, 2 Sep 2022 00:36:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HPjy/YOSM4krJjxO3w1/EglK30Cq/Ngf51FwvzNnWoiyE2T3DGXnMgmOsqVaq3W2w+YpEIXBev0bjvDW052PqBklXzTzyusKNNL9oHzUSOJzHApktO4sd2j7PLYeXt4F2pv+5F6NuYKpLF2oq4oMAeT94mN9RyZIYhOpiK4XIvgsRHWjYlrL2B3nkJsZVM1pM/oPgF0lLz0heHnSNNFC4KqYiXbQrHYtRB5ECQtDLhjRe1lJR81Wt+1GZnp5DoicB/yCvzHkpvbxBs23WCZef0Q15qriX09s2ZcKJ5g0L+dErziU1n0F7Sc5/TC2Oj4EteIepT5KHk7tIEALyG2KJQ== 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=mBq7JTG8UcLfh2/v7e/GA0COLHpr5d4BKHxKbsKdJWY=; b=NEladrlR2qzjwcHS/WlO3VQXyAeVFLGM8BGZYq/MHKN6bG+xvwAlMnQ0tvPp8da1lQKib0d4BAWXd6j4AtlqWb5YN1C58RfVP73lVAgF8xCkXiAY4fw8+nhgHqNd+oCB9FhoBBdI6CHH6nI9KUhdKT8PH0QKfgRBpcwm8HperzqmSQF4tvRhNvsGr0SaOJHZYcyK99SgLlUFitBs05X4BmcEE1FK6ZJrz1cpkIh6Lc65CL/7N5pSYee2jHIirB5NGd0ofBuFuvjShYQaehcW9euKTkGCdRvJp3MfwVSGUOEgwRppfjznvpufUEDDI870B5rp5BpUGJuavAzHnemVbw== 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=mBq7JTG8UcLfh2/v7e/GA0COLHpr5d4BKHxKbsKdJWY=; b=mDDhRsyAv5BeFKpCGuvg1hSydXNrVviq1v9hovieaAney46FD/ZHPOHc5XHtxags7FgnH1Ouaqhdbipw0ZwQpKgoUOVJBVe1UbFKJ+0sBFMKKImULJpKMmRlnB1Lb46BfuGBpggWM+vD/fn7nLa8ttmh8cHpaEtigHXEcpspyoNuRwgmZzJGPLn4dnkXJ6p3wBWpEkLRGcHnEX0GIunH1nbqNgQS+wKZXVeJXM4tmOhaft9ApEHElQOKNtH0Z6cgENkDLSWr/9wpwqL5f9e1TODS3cI5FZfIEN9MiKAywpmxQg0fIUgHe6CA1du9qz52BK21J47FEmVQBcmvXr0yMw== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by DM4PR12MB5086.namprd12.prod.outlook.com (2603:10b6:5:389::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 2 Sep 2022 00:36:28 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::7432:2749:aa27:722c]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::7432:2749:aa27:722c%7]) with mapi id 15.20.5566.021; Fri, 2 Sep 2022 00:36:28 +0000 From: Alistair Popple To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: Peter Xu , Nadav Amit , Alistair Popple , huang ying , LKML , "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , John Hubbard , David Hildenbrand , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org, stable@vger.kernel.org Subject: [PATCH v4 2/4] mm/migrate_device.c: Add missing flush_cache_page() Date: Fri, 2 Sep 2022 10:35:52 +1000 Message-Id: <5676f30436ab71d1a587ac73f835ed8bd2113ff5.1662078528.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <9f801e9d8d830408f2ca27821f606e09aa856899.1662078528.git-series.apopple@nvidia.com> References: <9f801e9d8d830408f2ca27821f606e09aa856899.1662078528.git-series.apopple@nvidia.com> X-ClientProxiedBy: SJ0PR03CA0138.namprd03.prod.outlook.com (2603:10b6:a03:33c::23) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 490f612b-ec56-46fc-cd5d-08da8c7b2c6b X-MS-TrafficTypeDiagnostic: DM4PR12MB5086:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: svMKKubL4qq1pI5f17ewmn6YTLoyd/xR4UXUuo3MIs8fpU00cQi8E0RaUtX2sMpEd3vTXmi6vXVaCtKlCCfuL2Oh1amT4CAvhoFE0X/yxnsuqjB+cqefS3Tb9dFhnWYYEfwdCmhvrYY67295nSv1DyaMUKX7Iq398/KZhrCIlYt4fU5dHLozLzvAgOhEwk8/UqYOs7cK+sV5EhC13hjula0AYlGe4slBIWganW4dFZtz3rG4bpOLaMic/RXuKfDgvstteOU/tm1XXqLGqXaJ2VRU6BHPRQ+symCSG9Ti7Z81B88sCGxW1sbBYLxZ69mE9WRN7GGIPAs5nMSGqtpFZgiSDzvOMM1e1wbd8mJXAcss1YNM7FiOEa8MpweJbuaoBgnWUDH3OwfJy7iSoJPdUvybi701LkLkFUkEcnsBaZ0fLSdl8efOPahQPIp+KWpjW9wxjZqSeUZSxXNL4kCsmekX95sJvzBwh4yr4LIuqelkqnXpZblggorOlgmxNODbebpMqgyKdgODW2G7r3AXEjoPQ8pkmkkLmdw97pSZ6ExMfY/ksCktiYF/HtDUMmyC8dF7UjNbQYzKtVW0Y6p4OP/LWF2aoS+LHRxwRsQLtznEXb4Ks2pLfdCbJg7jR/gfKjsA3ekQivG7WP4Mug8+qdWkTRHdUMOQXk5TG8ZuqoaBDdE2ZvEDugAulgj5A12bHutxORaGYhk1EZ0MpzKfVg== 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:(13230016)(4636009)(366004)(376002)(346002)(39860400002)(396003)(136003)(83380400001)(38100700002)(66556008)(66946007)(66476007)(8676002)(4326008)(54906003)(316002)(2906002)(7416002)(4744005)(8936002)(5660300002)(6506007)(6512007)(26005)(186003)(2616005)(478600001)(41300700001)(6666004)(6486002)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 236XCLhMfKzBKE+M4Vk88cHmtZs7H9OBEE6zxBZwSRUm9hX5ZwXnoUvoDMf4sQHeig5A0d3D1zRbs5oow52t56gLkkMG9Tn0P8vAU+SdY5vOrZSYuvDftCjQYWAzIzkF48a7k9n4wGemZsMeCT080tVQ9rO60nu75+BPuFtPzBTx3L1WwgbhDCAmwiGSnvjZFjctlrxqsf92kFooAJ5if3638gDP8C4yQyjueB4S9MWEaO7olmWTaRshCQ1Sh5MjOdO/0qCoR+wObVsIE7Fs4pB+rCeqLMRIQMjTgOHF2HQWh9Ep+ztBcLvkytS7ABwVjSOY7PUtQhjf2Rme0xuLXfSGWiEUpJyFqx5OanqiCs8BDIOnx2oHt5OR4CzAZv1Fz6gGp8ApCW77WA5j5Zv+lSjsYuOgkQYAf0slSbajbxYLefG9ZeSg2YZ3QKg3B8r0p8A8qpctdufr1ewqPpoZ74GYLnrWlIX3ZOhmuBm7YS3Q8T887Cdcca3AixrL5/FyllVQ+545vx4vgldbDW3EAzOOa2aJgd/0JiTZKO8A7OTtdPpFB2VbsyBm2/ZYrgCSTAz87J1s/vI/TwfBJy3TxZJBgLcIxQBZRGYNXG0IJ3yTG4iqNQPKVKJtWDs4KE9O7h+IsUK9Lto+sO5tuhvWrp9HA6B2aw/WduPJGLtRtNBoR2iFPcgpUiT9qwqcum/cNmSJ05MOVCUjLwvxL7ivI/nJF/ezyGs17uPJtUN6IsF+obT5wOtLxVzyNxIGyU9pCy3caNKr0AzFgMDVn3k06GivZm5i4d/tAmgnqzEMuuMVFwWVc+kbuPqQOYKPZvxXMdL5gXF5zTKP2VkBhwS/xYm3qGBWzu/jLYvQ2kCg6HydexVTqGlhXrUE5kKmJRE9npQq0N/wKoEKpimKFSCfm0uXM14bJAydi0qYHjAfmb1w5RdhKZ6Y3voyscbbzbq73fylpiinMuDkVo8CJMcsnBXYTbzhTCSzKjZpcUbQydDztbsgLzJ1ktlLQTckk2HUoXsK7KxFCG3vFaoMX9Ixbisq9zBEla0sZLjsxB/o5yRta6QeN8ZTXMB6xB/SWgkwTTFQ4vqsnjareu8bqRG0d1RNYVd1g1qT9TCY+rZdulLrV6IkBMkPuejXGNZr5WM3Dp56iIQIrJRhEmEcUfVBl6vz6MIlbi6CXIi417WVo0I8MBTKlDT/uVzYIrkLWZ/gLrE9M5270HDwnJW4J5P9eZPnfV5jZOUbepaQkzHfJdW7kQWuuJPucYxjgxo+N9ehI8sez6YojKuazHImnPHVj67zm0Hpmdk0KdN4nrwILKeUr7UfNZ6f2p4szDQKNUIvxZrHqdJ9GcZHI9fNx2+aqNqOxyIRGqdV9FJKn4N4TSeDDYGsUsKRRhq+Psg5zsyj3kpv+w/hjH98ZrpweQPgbggkm0pimhzAuoE7VsSyP9Ne3RWfz5tYUD6mOOxPsYPoNfSxn6hRuWGJJqn848URBjPagHzFN4mBbOyQGR74djd88Q6weqNxQvvj+ylNPxFjCMffjdqtErMOe9s5wgWrdDh5cQMVmmbpBhWGJ9Yue7w5gM8mONuoT+LRZqmru+/Z X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 490f612b-ec56-46fc-cd5d-08da8c7b2c6b X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 00:36:28.1881 (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: XPqO3ZNFmxVy8krYKt2oNJSeakaO/db5aSVpR7Qq6pW6b0mjEIjzZiDcUgcLZrdvkoaeveSLVsAIW3H72CXMwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5086 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662078990; 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=mBq7JTG8UcLfh2/v7e/GA0COLHpr5d4BKHxKbsKdJWY=; b=FaJ0kVfMV/LDdroZE4UTAdcg6vNyHI1X1LkILq0twF3O9fuXjsGRy5O5TlBnZMBsvnOzev tsTASS94nGPyF+uh6SwOL7mWPSxt/Rh8+SHS/4Ao6yJcz5ZPGUnGrJARdTUF4PUDA+GJ0D zZd2HJeFEhQ3vVec83ECvdwF7ipCbMo= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=mDDhRsyA; spf=pass (imf06.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.72 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1662078990; a=rsa-sha256; cv=pass; b=AIYdBvkc6HIUYr1APgUY0Y4FQZRrJ4pL5Cidmpf3BCA2d0Y9Th5VXRlenYnQh6MnLcGhU9 TWq/88AsN1Y0+Qz67F4tuSTj/ZE3lyxFvZdd2orBiBNT0DqXM8dZW86VDPpbjuZEnwpxFi jRVd293w7ayFCBFUkO1BZbS3lO5mdNY= Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=mDDhRsyA; spf=pass (imf06.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.72 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspamd-Server: rspam11 X-Stat-Signature: 477ko7mpzr5fr4mhcyn5jn6ah4ayxq1b X-Rspamd-Queue-Id: 4DCD6180042 X-Rspam-User: X-HE-Tag: 1662078990-907977 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: Currently we only call flush_cache_page() for the anon_exclusive case, however in both cases we clear the pte so should flush the cache. Signed-off-by: Alistair Popple Fixes: 8c3328f1f36a ("mm/migrate: migrate_vma() unmap page from vma while collecting pages") Cc: stable@vger.kernel.org Reviewed-by: David Hildenbrand Acked-by: Peter Xu --- New for v4 --- mm/migrate_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 6a5ef9f..4cc849c 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -193,9 +193,9 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, bool anon_exclusive; pte_t swp_pte; + flush_cache_page(vma, addr, pte_pfn(*ptep)); anon_exclusive = PageAnon(page) && PageAnonExclusive(page); if (anon_exclusive) { - flush_cache_page(vma, addr, pte_pfn(*ptep)); ptep_clear_flush(vma, addr, ptep); if (page_try_share_anon_rmap(page)) { From patchwork Fri Sep 2 00:35:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12963469 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 8AF83ECAAD3 for ; Fri, 2 Sep 2022 00:36:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A1358D000C; Thu, 1 Sep 2022 20:36:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22A6F8D0001; Thu, 1 Sep 2022 20:36:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 007208D000C; Thu, 1 Sep 2022 20:36:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DCD9E8D0001 for ; Thu, 1 Sep 2022 20:36:33 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BC83CAABA1 for ; Fri, 2 Sep 2022 00:36:33 +0000 (UTC) X-FDA: 79865279466.24.F759800 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2071.outbound.protection.outlook.com [40.107.92.71]) by imf09.hostedemail.com (Postfix) with ESMTP id 6D53214005A for ; Fri, 2 Sep 2022 00:36:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dyRNPuo8BsJxh3UwMs9ULm0BsFDlOM2TYFOWHMSsw5NwNPY0IMRhCLZp7OV98Cgcf3Sb90do8k+FtEKWE+t7/jMwpIE5Afk5oP4N8RcVSRw/2uNdSIvooYpjZYdk4nPzIcdpKQ1o0XFKEmlm0ObHFDMyUyGc5MRHMbYAMvk/22fr0zfs+iVdfA2KY6zvAgLT3f659Wk5djMJY53LHuw/JGDZOYq9mrvDeUN/IjSJrMevudGvS5MJa5w5MHtQ8oQr4pfEX1Y2hCLou5/lNOyYbWMXEWA8hzFD1SGci2nNbB/u5WomX4ovt9qblkx59usvgeR6nLmBesdv0tdLuph+ww== 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=JwIh+pOb9F/V8uLUX51TWSv/dWZCwxq39gA4eUPAYA8=; b=Nf/boYf/2hlUhJv1TvkLWTUBZD0fLK2zv49JdnBIEKFqEAylr4j6iBVl+14TICvjmBDO+oGOEUMpP9W8L38AJGFK/+T6Ts3f8ZFrbVHbvi33CmvEf+J60pYqpgpVBHQvS3q0zDsw+pAc+qA5iRXst7iPDPGrZRntRv5LHnqMP8gXrdEV/ZqJKu+agOU5nA3M9OuWnv/oa1R8ORZhTkguXllQ/uOkew7DiwG1wicBdBCYHx4SOc04nKR2ZATkj5r6KA3s+1C7mIti8AWvR9A2JJ0i9RPX5a8MdZv+7LqxfeMedxEh4IVAlHW4kCdMpSHbUy9MdZpL3M0PW00kLGlbKA== 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=JwIh+pOb9F/V8uLUX51TWSv/dWZCwxq39gA4eUPAYA8=; b=TrY5Mr8GXMp9HYqiKUyb4oycuSNS1NtfoLL0oGPOnTlg13FpnuzZjzu1b/nHLdGx73JU7KK2TR1GIlnLHgdX2y7y6LB9NE+AVbYZ7lGwb26dNHz3VfrD1OxSyS/tqqeTWTrNnap1buF8/iF49dcredTxi9j5h1j6cS84px6Wy3GbZq9f0zo/rDosthnVYk9pwfXLZ3dmiEcQKg0mVBiTxrlKZvcwMBjS2PttblH3ZxEGIrwrh0nMoIlTVBPbIHP12+oNOuPyx6v1b3HyW/mwVqZl8a9y8sSPTsOXHko5+2gkxVuU3Lpl3IzS+srrrUX0SY5Ps0ZEoj6Mm2JqhO0ytg== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by DM4PR12MB5086.namprd12.prod.outlook.com (2603:10b6:5:389::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 2 Sep 2022 00:36:31 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::7432:2749:aa27:722c]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::7432:2749:aa27:722c%7]) with mapi id 15.20.5566.021; Fri, 2 Sep 2022 00:36:31 +0000 From: Alistair Popple To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: Peter Xu , Nadav Amit , Alistair Popple , huang ying , LKML , "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , John Hubbard , David Hildenbrand , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org, "Huang, Ying" , stable@vger.kernel.org Subject: [PATCH v4 3/4] mm/migrate_device.c: Copy pte dirty bit to page Date: Fri, 2 Sep 2022 10:35:53 +1000 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: <9f801e9d8d830408f2ca27821f606e09aa856899.1662078528.git-series.apopple@nvidia.com> References: <9f801e9d8d830408f2ca27821f606e09aa856899.1662078528.git-series.apopple@nvidia.com> X-ClientProxiedBy: BYAPR02CA0012.namprd02.prod.outlook.com (2603:10b6:a02:ee::25) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bcd364d0-3f4a-4cde-5cf9-08da8c7b2e6c X-MS-TrafficTypeDiagnostic: DM4PR12MB5086:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cfe6lMeUMqzm4nHn05cTv+vP4h9ov4y7IhKdGY3FSHyQmhLJU/tEHpGzwfloEykUMGTK0nP35QggRydqTfVxnGNZNt/2goZY68L1ZEi96i1tuFSmQQfyFdtmFYxUeA0z3fe+ZMIutH0HACEICG2J4Kvh0mykKvEFXqaAE1aLX5Hya/bJPi2BJ5UV132vnr14wCoNiws/dF4Ltqq9tcMx8fj5YR9O7lCCQ5KEfcx4ngbWyVq5e5xvbVOTNy0AQRJ0T1Ur6uRJEKHjsLBC0NL6DVq1qjd46OjOBkb74DI+LwCC71n1UVMQr9xz3KuZie4w4VXfMPOuGiV67rrQO2X8JWioQctUvPAPFUKqCMM/kqEDH+dgatN/lOmv5IfnLkpXoprLjcArEHlhHZzXdPH8gzSS5iAqP9zpZbMvLDNk9PBLAMJ4kB3KMMD6sQECsvHlXTASd5u6BiJ6KGWH6HtVl8EuWsgd2x7KWtxA0c6G2sRcZn8iJxRPL1gA2xcdGjBJVvxDvmk03NmFFMs28exDBxOytElfanyeqeSEERKrXyqEyBhwZJCLut+jVVhAdBbqtmcKO6xCzX1uDXcIAEC/uqskSNdCaUnLWgoDO1nOP3H5GP0lh9XWPDeDfxsNxDipEYSLuwpSRswnIE6y5ZHPgAV6Rb41ACKJFp9FYDmbaZD7RtZDiOj0XiY1iFFmJRXBQo0o0dw1iUgvXcKmSLHrmxEGotMDE9WJgjWXXGi/P9hLexKnSOG26cow6j6rXEOrMZPo7LemuhaQ7S32/hqiJQ== 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:(13230016)(4636009)(366004)(376002)(346002)(39860400002)(396003)(136003)(83380400001)(38100700002)(66556008)(66946007)(66476007)(8676002)(4326008)(54906003)(316002)(2906002)(7416002)(8936002)(5660300002)(6506007)(6512007)(26005)(186003)(2616005)(478600001)(41300700001)(6666004)(6486002)(86362001)(36756003)(14143004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MFnSiP0zUD6MrqST28fik/XxHwucyB1dUytDDNcKBt8SU5ZN+TenQEG64ONn0EVb1jg4G0UNgWRnXjQ9sJd1wy87R3U/4cmwUqLOt1wnz036T00HgB/kzq8rs9QYEVry5VGgZoCyv85Yqp4kbVnDhyvUWVmQbdArWmkeG2+hiaZrrMeQGWRrE1TWzlwhNO/YYP7k0i48mBYH6EbTZ66gSBdb2h42FV2xpBzS2utvtX2VZLOJMQBXBhGRZzncwu2sTRLEol8OPQQiPon1GEABpu3WLdFEdNa3LkoQEFAvjuX+upnbW/rj6L/sUhQfBXoPq8BEEwPGCoiUxyKqSv2/EPa459lId6hu+Vt8odH2TVx/iMLjghkT2IHDjE9eIgOAK7aNb2E9U2LB94CJthdLQztVSwRAT5/2wXTOBh7KQfmAU9AOY0PDXtN7hBmXRQXMexiW0d4g3CdmkGUBJkXGHwVdIySC+HGCHcNvqwndzfB9eL0hJ/v0e3MMU7sTW3Qg0Bpu3pGaB92P9NVZTNpSVVKN+KGM+g7UGERXRmfRbyv8aSQ9POiWjVmEdPIBaKjElOSCOEtozS6/qJKUJtXnLrHiMjKHb9ALNTqRbdk2eSf+vi0kxb5LuKGfGJgMZim0xiS6w1TDHqXeQErf+BG32hIs/azobiTwbXzxbaCHeMzIiMgbt0UdXT9hnzKJ/jeJwLX9iYXlDzCxv8UpWkkJcKHTxsYOOtMVYwAwRmNQtbACHai0l6x4ix//M51lQKxgJCA48JwMBw82MhS/nXV/rqYI+RcVEotXFD7XA1ISRNbrL748V6XuVJrGYO+P3Nu7zD4Y7OT8osibTaP/Dh9M0uIMKIGWw2sf4VK4cXxeo8py67JJe2TRvDrVQ+o9/RAM6XZBhEsXyLQfpC0h1XSFg+8YPeEFHttM7Q4muCwz5ECQDkk2O9gZTxnJLy3eBYPfOsk7XEeRmc+RCl/iq0vQpjmu/oG2k1NOI1os6z5Cz9GD2usvc72pOt2ZvFY+xL9HZTeyOXuj3Mx/wxxLZ1hI9iRuK//Hu6fIrzkfFZhwqLIDqbTWhHFhRGLjPto1F5kFPVv55c3ys4JkAdDt7yFX8lJsqYUn0t5Ko2akxCJ4aI/ITpkPIljqYybnj/tE+Ts5Fm6js2QWj5cDiVQuIk2oBlYSbfjZFVcDCuzd1VHD719UZp5hKzVLU+7jYUrWoEM1s76GsuzQtydsTESLBn2vVnkaTSnn0S7u90aP0nfvpOWiglyEZ3fL+ipdd+Ol0+lXEC6HTaUjR29SmfdkaNfnaqg0LQ2GeBNjpSM32HqeVNWaBTO7kyrphv9M7HD2lWwVHkrMP3tVYat4gkQbFGwsTuKJP9+7hV2Q/EFdaRje8IwmxRyy/4bU8OB7Ru6wqZtSwHoep21xr5NCdh8Jaro1zyaXAqD1XDdIlAoK3GOlciStn3sLHB1t6RQ//+wcwfBFdQ421UwtrtDGLCa92NyfRT65JY/PJ5LaH7OJunTFKZcWQOJYtiiTqR2r5afM/YpPZazeoGK8BzErSvfsIaIjrRI6mOYRNhYDbJplpz7M6Ur7SdXBOT6/4DWji7vyCi11 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bcd364d0-3f4a-4cde-5cf9-08da8c7b2e6c X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 00:36:31.6253 (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: dBV+rry+eVaQm7aVmbUrtq0rMRhX+Hsg2Bao59cCMzDoHEP50twrnE6DyZ/T35dJ9eOKoKLjnbwTvsbOmkN2Jw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5086 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662078993; 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=JwIh+pOb9F/V8uLUX51TWSv/dWZCwxq39gA4eUPAYA8=; b=VX3aLBlDs/k/CvHupB+XjvC+MiI2znrg1fMtzybVZ5PEQhhPAFdUQ/B1kXwlzkj0YE/E/H 0LTzd/3Dr8nMA9H47emSK3JRvKFXjhWHip0ZsqDnHntyjibhtTsxIgiBF0JhbcGWe//H+k 4vWzbVVIMfL+fcWLJAAbiAqriIC/NcY= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=TrY5Mr8G; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf09.hostedemail.com: domain of apopple@nvidia.com designates 40.107.92.71 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1662078993; a=rsa-sha256; cv=pass; b=W1PWZH2rkd7SmRIWwQpAjRRDvNOxzmdjUP7/mCMtEMMDc6uj5gzzxliAr2XkFbOX8oo0nu 8AuU027q9UEhRADTjMpQV6GujMME5PpcPAyHn90ZHnl2B+kd5wHavCKiizyltr25mbr/mT Uwwal+z9PhpJDsYkwup47I2KCZ3cXlc= Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=TrY5Mr8G; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf09.hostedemail.com: domain of apopple@nvidia.com designates 40.107.92.71 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspamd-Queue-Id: 6D53214005A X-Stat-Signature: tqcupjhxex1axk9x3crzkzugdte7p6ig X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1662078993-538549 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: migrate_vma_setup() has a fast path in migrate_vma_collect_pmd() that installs migration entries directly if it can lock the migrating page. When removing a dirty pte the dirty bit is supposed to be carried over to the underlying page to prevent it being lost. Currently migrate_vma_*() can only be used for private anonymous mappings. That means loss of the dirty bit usually doesn't result in data loss because these pages are typically not file-backed. However pages may be backed by swap storage which can result in data loss if an attempt is made to migrate a dirty page that doesn't yet have the PageDirty flag set. In this case migration will fail due to unexpected references but the dirty pte bit will be lost. If the page is subsequently reclaimed data won't be written back to swap storage as it is considered uptodate, resulting in data loss if the page is subsequently accessed. Prevent this by copying the dirty bit to the page when removing the pte to match what try_to_migrate_one() does. Signed-off-by: Alistair Popple Acked-by: Peter Xu Reviewed-by: "Huang, Ying" Reported-by: "Huang, Ying" Fixes: 8c3328f1f36a ("mm/migrate: migrate_vma() unmap page from vma while collecting pages") Cc: stable@vger.kernel.org Acked-by: David Hildenbrand --- Changes for v4: - Added Reviewed-by Changes for v3: - Defer TLB flushing - Split a TLB flushing fix into a separate change. Changes for v2: - Fixed up Reported-by tag. - Added Peter's Acked-by. - Atomically read and clear the pte to prevent the dirty bit getting set after reading it. - Added fixes tag --- mm/migrate_device.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 4cc849c..dbf6c7a 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -196,7 +197,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, flush_cache_page(vma, addr, pte_pfn(*ptep)); anon_exclusive = PageAnon(page) && PageAnonExclusive(page); if (anon_exclusive) { - ptep_clear_flush(vma, addr, ptep); + pte = ptep_clear_flush(vma, addr, ptep); if (page_try_share_anon_rmap(page)) { set_pte_at(mm, addr, ptep, pte); @@ -206,11 +207,15 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, goto next; } } else { - ptep_get_and_clear(mm, addr, ptep); + pte = ptep_get_and_clear(mm, addr, ptep); } migrate->cpages++; + /* Set the dirty flag on the folio now the pte is gone. */ + if (pte_dirty(pte)) + folio_mark_dirty(page_folio(page)); + /* Setup special migration page table entry */ if (mpfn & MIGRATE_PFN_WRITE) entry = make_writable_migration_entry( From patchwork Fri Sep 2 00:35:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12963470 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 88688ECAAD3 for ; Fri, 2 Sep 2022 00:36:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27A218D000D; Thu, 1 Sep 2022 20:36:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2035C8D0001; Thu, 1 Sep 2022 20:36:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 007698D000D; Thu, 1 Sep 2022 20:36:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DD0868D0001 for ; Thu, 1 Sep 2022 20:36:37 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BBDB58064A for ; Fri, 2 Sep 2022 00:36:37 +0000 (UTC) X-FDA: 79865279634.11.40EF4EE Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2074.outbound.protection.outlook.com [40.107.223.74]) by imf09.hostedemail.com (Postfix) with ESMTP id 6954B140063 for ; Fri, 2 Sep 2022 00:36:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kMsyD7ngCN3BrhFkJ8tl374RBgeRfLe6jz90lKRzU3FDpToiPRj7Hi/+DGpCd27D0zZniLzy4kqI/S9DwzuCC/hUYbMQ2uw2gsx5Xo8Ystn9jn+d60FhSVyfyOGqsW5o1JTV3gSDPII+jJMN7wgK3D3dxAbUEFbTuBgoYjCry5EGhWscXKyPLhvQAzX+eLrMZXMKGCDgAa+AvO9fZm++0o2M+VyPpgTSEMxJtHHMZImkkWac0Yoh6itpD4flAHIvyZi+EbQcKAxgZcv7IkCpxoxD9tFlmi+k1Zg7PKmQEiV2f3EIBEPnaSe1x7bPLEN/J9abbJqKXlL+q3bfjBrPUA== 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=snVPulbAKBAi9Wd3KFPYZ5rYVHb8mY3ptG8l5yLntdE=; b=V3aN3DwnIXe4uCgL1JSY01lX5L47V+76Uqtv+qv5MGWum30lddKjByjmEhMArVlDyTLrEnjV8KTj7ZP7fokP0WeWPVUXNfuLpxxTaLVKrUemuLAVRWYYNlpy+QDM6DXn/MBxTiUolOp5EwVVKICeSwtnAm3p1IXr4k+tFZX1tbz/Zvkxv2cFL+Q+uaCJjVMGAULWod867Y++C4kBPShXuyVPXZ/lObnaONS1JijX1M2UOdm8x4tw145DDZFJ2qs+Oim1KUbIRTwnV5GXTlCL/u2kgp9OTIJrpXDfxaWza75meJ6PamZzNQReJlmFRIULYPnpr7LU8MQHsple6ljlQA== 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=snVPulbAKBAi9Wd3KFPYZ5rYVHb8mY3ptG8l5yLntdE=; b=qc00d6dqsqh2LWhNxJ2wfkXPT/E4iU2KHg4k17NoLOmphShVV5ttd6pBnz42XD2hXxx9L1NIvDC0a+RH7hR8DlRFQltyU1tZsW83nKT4rh6SwkWWHhvjl5qsqFEUEoOUp9GvqznZvN5jHKLtTyyhCxi1PprGcNcFo64hZH+z/UoNTZeXYYM6Obo+6UYFExiJB8+Ppype+WpXSRqdluJzISMDZW3j+mfnYRCXlwkr2lsTFJwSkyFhY1u/GrzIyCEvgeI2YCE953M5UjGrM1DDODgz8JDdrfVXFBM8Z/WOOCF8RyNRv4YZQOWbc09pXSDG4qApSPGFeY0y/IMZ5wA2Gg== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by DM4PR12MB5086.namprd12.prod.outlook.com (2603:10b6:5:389::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 2 Sep 2022 00:36:34 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::7432:2749:aa27:722c]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::7432:2749:aa27:722c%7]) with mapi id 15.20.5566.021; Fri, 2 Sep 2022 00:36:34 +0000 From: Alistair Popple To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: Peter Xu , Nadav Amit , Alistair Popple , huang ying , LKML , "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , John Hubbard , David Hildenbrand , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v4 4/4] selftests/hmm-tests: Add test for dirty bits Date: Fri, 2 Sep 2022 10:35:54 +1000 Message-Id: <68cf1d70f3fb8ce4e3c1a4899c19df4f6c382a13.1662078528.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <9f801e9d8d830408f2ca27821f606e09aa856899.1662078528.git-series.apopple@nvidia.com> References: <9f801e9d8d830408f2ca27821f606e09aa856899.1662078528.git-series.apopple@nvidia.com> X-ClientProxiedBy: BYAPR02CA0035.namprd02.prod.outlook.com (2603:10b6:a02:ee::48) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bebedc6f-f861-4f5b-f099-08da8c7b302e X-MS-TrafficTypeDiagnostic: DM4PR12MB5086:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ExQ4mvJ50R4yZIKt9jjMPLnK/J4AOA0LaVyJLdW3R3kjLulbtzUCQwT+ghiFcxZTFBuKJWtnXrZ5u6LvhNtTXfy6S8vR4zM90uZxAzmDYHkH0h4w6/z87zSZVNBU1assEwr1fqvgZ+3iAZevC+v8ig2q08sDQpMA8UXXG+zyKuRoRF2WN5ZHuvphVreRJ+foDt7hhDHkTb/rpBr4BLDAZjBEiVP0FqsVsUKF3E0t9jpCVN3c5z/dIPIjrHMAMGoVk86yMaTajzN3NrSY5lYZ+g/HGAhXWdYOOiCLG8F5jm4zJXLVykgN2Wbk3uG/Tz1/GozwZnKhS7HbaDmVim1xPauBlfnUaji2bGlMl36QMRgLxw6gnuJf6x6TwNjCK1CThGg0ZtxWzxn4ThG9kH3YQ1GWz5RFMTj10sbv6U+mSqTIFmwNAyw0fQiT29mh/eSPwF7MjJwpMJfUHCR6c6u+QH8HNNVk+L72vd66CK+iDrBn0Y6yP7I5/Qx+UwfkwWQyzzcK0mJPP41+ipD0W8ehRV1YZYwLB6Z5ED+knOdLwIEt+w9TC0YCacuIaB2N0L5VI7rLR4eHDg1SyJrzbDNnJqVhZR/MoEHlbh2NB/5EJ2sVLZnrTeiW6YLtwy7BupiCUA/BZ7AucGJqXGB2MxZKjKTJUxVlhoYbOtsHJbBoI033aaxwa9s8R3HqxffbFWh+LeLTzKoqC2akYxScPLNPsmELQl2tszvyZ8Pk60Mw22ueFJnxiE1oO8i9lC8ZyKR006Ba4GqDwvbEW8/qRShlkQ== 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:(13230016)(4636009)(366004)(376002)(346002)(39860400002)(396003)(136003)(83380400001)(38100700002)(66556008)(66946007)(66476007)(8676002)(4326008)(54906003)(316002)(2906002)(7416002)(8936002)(5660300002)(6506007)(6512007)(26005)(186003)(2616005)(478600001)(41300700001)(6666004)(6486002)(86362001)(36756003)(14143004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VmGNANBEa1Fw+xmhL5w6HEE+x+BnF7luHiubRg4xZ0DbPj3T9onpqv6cN1A7BKbr/psl0jqZDvwdYblXFGVGcyHoyQW7ITwBq9RwZ0wLxlf78fV7PK7Cd3xIwr3M+ws8Yit5lJ94qkP+gdBqNkKJJW2M3eurlWkvUBdEsC9PVg86Bjv0AQbd/54uNZpY68+NSfTnHGrMjar8IErMzJoinb/Ja6VIeL9NFrMXeQvEiIdNkHhWQHX656ih1oWbFCgZLhvitFw5ps7Rsw5S9m/O+uils/nuSN9Oi7qvtWWnK1c2L9zxznwfgHkqUhq4AZLhzobFdj9tc47Mab6Sotqz+kVsZ7LI80bfelCOkp1WeBOfE45yrMQGPL01bYAzxw4PVF5XoYgjZ015gAHrl69QHQkLSHGp7ATlcEDqhlvxrzXoivpRWrMf0NGRYbZIgco8oooeKmTJPGjk4fm+Nu/NVW1QF0mPFtdd1vaCV+m0CTzCV1Pwr07S42iux8Q+wMRveXdJwKUQuesM0u12NHgDyRMAq3UyTTkL4Vm1ZeEGV6yex/19FdCIQCBCokibqmWFUmM6j76KpxqeXe0ODVEI9s44OOiE8ZRBUMXFFv8YDUXAeg+Xy3mVzdI+WKvRW1u7Gr6LBg8FOcPttQ/IvfkVZkjqRyCVmByrFg1prcwreIXh45VKn9bi7AIcoht9BM5Irakjr9YYeMqgz77y0DAIiBv/tqBUDozEzUTfm6ZP34h7JuCZz3imrC1mSGbFBNyw/5N6O7OT3/ERuCfbX+tIf10gCu+mVZnsw5UkwlMP+g/zZh0OQ7xS7/avAeECkMaoMANZ7/LygbVnmhsI6SfeVu5fk/ki2vixsTJiwzED5dOHzBWq9GCQoLp+UpyPWQeye83jcv1xkmoVGUTAD1B1tO1WRPcXEL5zWgrBgkewLhRu5J4eejR1jdp1L6UkWhr90O9/DR3H0gLBMgqTN4wl7ThlhDCy1uEJJTxzNucwMRtjpdL1YpEVLVRHB3NwppjibQHk3LBiL4wIz3rhP3s72oiG0fP6skxOa9oIGmTVcnFch/UUn5UCpRmvYQJkpmv7NVHwASfPIJjErXxo21QmwpBcqhpXaRgjzc2FKDfII7ilsT0tW7smEM3h/55+H/dzd6oNsZLLkkPX/17dqkTVThH+7HLIvkqfU6ir7nkg7n9M3hOxU381m9M2qegjjzEL99hBsp4J8k6FyYcEHlAyisaHbJIjYaOwvgClx7rBXfrIRfwbyruQnbSXE/fK2doVts8UrUdRv5i529SuP8FKb1KD1PoWh8GzFwVerxzJRzI3tLYYls7ULigJpN2mjAOv0Q4TP9O3kpOeH7yvKO+Jzwf5S4t4t0TIDhiwkFYhDfrkBF9TrUWlOUwMDyL8aGhXFMDJxuUmPbUTSXtyGzhMiJsXvq3fubqsoPvimKuKUVFZut/6TbsnUY2TcLweB1Vn4FkLXBwwaeFfQcWSvwgsR/gwf2yLOEvbPQZVw4Hv+F7pBHCRBj5nxQ4a/2+lOWY3QzBqA5BISVFSZJnYbHcJtk4jtQ3/9wAnlPZSB9zsNhkoy6PwixgQv4k+8ydomnKf X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bebedc6f-f861-4f5b-f099-08da8c7b302e X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 00:36:34.4688 (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: sd30vTZIZeGkZpOBB5j0BGtlRcEvo31xweQ/x/lyWbhPEyAUNC2EoP2mX9lM8aLk/3E+9aD446N/WqV/uwc8Yw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5086 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662078996; 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=snVPulbAKBAi9Wd3KFPYZ5rYVHb8mY3ptG8l5yLntdE=; b=PNj9lmtjHxqeXXNkhNbyljn6g0HmQ1g4BmHMUXtvW7j5KeDrecfGhi045lr4hisXUFgdqG uK0beIwWTXRlkCaf6kt/9JOhX1l1PMA91fbgzOwvZTF9NF8vtoVzuB43YGJOBR83hfPALV DXQpNrSbCUyswJVsdEK0X6HmIll+VK4= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=qc00d6dq; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf09.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.74 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1662078996; a=rsa-sha256; cv=pass; b=7JBg0uf8zJNvb5EULEbCGr6lvF3jSyPp4fuGHaD4GAHvFNKYnpb9pA4BYZx/EGyiWRpFQ7 DlI66ZUM6VfCrJGY9ct53fy/lWU416uCcXVDEI3L47sOMCV5f79m1pSozBc9AJqdO9lAXA /XybK2U3zVdteqzlow2nPMw2EEGeb58= X-Stat-Signature: xorpsgz965eu61b9wt6zwq9qcn6wykf7 X-Rspamd-Queue-Id: 6954B140063 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=qc00d6dq; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf09.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.74 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com X-Rspamd-Server: rspam12 X-Rspam-User: X-HE-Tag: 1662078996-473019 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: We were not correctly copying PTE dirty bits to pages during migrate_vma_setup() calls. This could potentially lead to data loss, so add a test for this. Signed-off-by: Alistair Popple --- tools/testing/selftests/vm/hmm-tests.c | 124 ++++++++++++++++++++++++++- 1 file changed, 124 insertions(+) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 529f53b..70fdb49 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -1200,6 +1200,130 @@ TEST_F(hmm, migrate_multiple) } } +static char cgroup[] = "/sys/fs/cgroup/hmm-test-XXXXXX"; +static int write_cgroup_param(char *cgroup_path, char *param, long value) +{ + int ret; + FILE *f; + char *filename; + + if (asprintf(&filename, "%s/%s", cgroup_path, param) < 0) + return -1; + + f = fopen(filename, "w"); + if (!f) { + ret = -1; + goto out; + } + + ret = fprintf(f, "%ld\n", value); + if (ret < 0) + goto out1; + + ret = 0; + +out1: + fclose(f); +out: + free(filename); + + return ret; +} + +static int setup_cgroup(void) +{ + pid_t pid = getpid(); + int ret; + + if (!mkdtemp(cgroup)) + return -1; + + ret = write_cgroup_param(cgroup, "cgroup.procs", pid); + if (ret) + return ret; + + return 0; +} + +static int destroy_cgroup(void) +{ + pid_t pid = getpid(); + int ret; + + ret = write_cgroup_param("/sys/fs/cgroup/cgroup.procs", + "cgroup.proc", pid); + if (ret) + return ret; + + if (rmdir(cgroup)) + return -1; + + return 0; +} + +/* + * Try and migrate a dirty page that has previously been swapped to disk. This + * checks that we don't loose dirty bits. + */ +TEST_F(hmm, migrate_dirty_page) +{ + struct hmm_buffer *buffer; + unsigned long npages; + unsigned long size; + unsigned long i; + int *ptr; + int tmp = 0; + + npages = ALIGN(HMM_BUFFER_SIZE, self->page_size) >> self->page_shift; + ASSERT_NE(npages, 0); + size = npages << self->page_shift; + + buffer = malloc(sizeof(*buffer)); + ASSERT_NE(buffer, NULL); + + buffer->fd = -1; + buffer->size = size; + buffer->mirror = malloc(size); + ASSERT_NE(buffer->mirror, NULL); + + ASSERT_EQ(setup_cgroup(), 0); + + buffer->ptr = mmap(NULL, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + buffer->fd, 0); + ASSERT_NE(buffer->ptr, MAP_FAILED); + + /* Initialize buffer in system memory. */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ptr[i] = 0; + + ASSERT_FALSE(write_cgroup_param(cgroup, "memory.reclaim", 1UL<<30)); + + /* Fault pages back in from swap as clean pages */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + tmp += ptr[i]; + + /* Dirty the pte */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ptr[i] = i; + + /* + * Attempt to migrate memory to device, which should fail because + * hopefully some pages are backed by swap storage. + */ + ASSERT_TRUE(hmm_migrate_sys_to_dev(self->fd, buffer, npages)); + + ASSERT_FALSE(write_cgroup_param(cgroup, "memory.reclaim", 1UL<<30)); + + /* Check we still see the updated data after restoring from swap. */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); + + hmm_buffer_free(buffer); + destroy_cgroup(); +} + /* * Read anonymous memory multiple times. */