From patchwork Fri Aug 12 05:22:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12941906 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 ECFCFC00140 for ; Fri, 12 Aug 2022 05:23:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60D0E8E0001; Fri, 12 Aug 2022 01:23:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5964C6B0075; Fri, 12 Aug 2022 01:23:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E9908E0001; Fri, 12 Aug 2022 01:23:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 29C0C6B0073 for ; Fri, 12 Aug 2022 01:23:26 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F0D7CAB71A for ; Fri, 12 Aug 2022 05:23:25 +0000 (UTC) X-FDA: 79789797612.25.BDE7FB4 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2085.outbound.protection.outlook.com [40.107.94.85]) by imf09.hostedemail.com (Postfix) with ESMTP id 4F41B14019C for ; Fri, 12 Aug 2022 05:23:25 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dvy5oBudKnOBiROLKC1x/8Reg59+CaNY4IpKZQAZSGDVRYtN2hkwTFqmJQ4py9+IGK16D+gIhrgi0qsKaCJa4Q/ropfu7+PuDozxpHCT7zXIUwJBlwuQY5cYQi9DW49AR5Yp+crPwsLTJn6HzF3elYDInaE+XOCKgrKA1i4O1kEk0oHsxfSdUQYb0upbqgtc7VaKuBUtJzPoVUBYkVB0MJXFtMf9qLK7cupOfCtEx9hZWLZeHmhvTKW/3xishSxKjpC6IIvlAlXOiBmMOsHSfZ/ZG8dUFImsmyD+AYPNp9FiaaqRABy5n8JL/ObLq3jYupEIYD/h7yti5NPEF7hrLQ== 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=51rvVXCforVG/VV+jnIVuOgd23Hpr3PwEdWaoS4K4Ag=; b=PTPt+wTpDUSpwP2bldMCKH4yyt1/aWuT+4hzf0sDIvVFgwvDUnxYad95ckafB7tr0dAduHbPNbKiZ8mGf5apSt3e+vprYTnOxBYjZ4LWU4Gvk3G6S2zuO72cN3dkGDBvIWLHjDYVJtk1MZV99+nm+ZtFmQqujeSPO9OdwStCHgHaMhDT3YNNSpOvp14y/GctGHNUPSDKozfOHrQ7D/1P754xUdvjd3MHZbZvMfXEkCITzhFQjsaH0GjjUe8tc8sib1rZuktw7+z4jw0B+g9ojHpZvG0J3tdVYtQ7Nj4IHJkwm0oIFYZMrQNIV7tyxUgtBUNJsdE03P23lw/dZ5H0Sg== 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=51rvVXCforVG/VV+jnIVuOgd23Hpr3PwEdWaoS4K4Ag=; b=WyOup/eT8jSp0HsvOo8t4CDibuFbMl7zXDqHLiwS7USFBzqrTeprs67kcgSdly0UNs38C+j0C/XJQj4oN3+NgP4s/vLKe2vSZqWveRoFJGCzntnK0nFbD/8zTV9DvzuofDwT/OzJC9mKmtUO5k5r0J3RtAs23dhWvhBiRO85K1MEK5555WxLKxT/UMtXlhywOF7xFShKOirHz1MPk15lgQpAmc+6s6G3wjB06X1AoDqicL2gymZiIVwQdseo01QEjJDkifnSdMxoOaeYRuwlPplmYLHplnFFBEcIazop5SjWaXqUU+mg2q3Wvgpv9Y/5f23N0D1YooypguhBTjUjMQ== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by DM6PR12MB3978.namprd12.prod.outlook.com (2603:10b6:5:1c5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.10; Fri, 12 Aug 2022 05:23:22 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::eca6:a4a7:e2b2:27e7]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::eca6:a4a7:e2b2:27e7%5]) with mapi id 15.20.5504.025; Fri, 12 Aug 2022 05:23:22 +0000 From: Alistair Popple To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , John Hubbard , David Hildenbrand , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , linuxram@us.ibm.com, paulus@ozlabs.org, Alistair Popple , Peter Xu Subject: [PATCH 1/2] mm/migrate_device.c: Copy pte dirty bit to page Date: Fri, 12 Aug 2022 15:22:30 +1000 Message-Id: X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: SJ0PR05CA0125.namprd05.prod.outlook.com (2603:10b6:a03:33d::10) 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: 1c049e8a-ea4d-4c64-9c17-08da7c22c646 X-MS-TrafficTypeDiagnostic: DM6PR12MB3978:EE_ X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SEqxDmnTGkCMcmXruL2YwA3gFXLqkbLkJlU3S2HPk+1mKgakGYz0hUdlcCfj19RmX4X32nFRsylqHDFZIzo+dfbuWaYYqQcsptsrKlhVlv5C/qrZkDXa/YWIGXY/91DHeNE6ewiDYxq3V+cgA1HRyLhxsUp5Wv17UL6lCyVxNM9bCV6hLSb7ig+DPzs2VxmZdFsbOx3h9OSR6otIvRd+XqiTNI3dFpuzHCDtC/660UGlucj/CZA/ycC/sPyityWsGTKH8EPdcbQx6X3tdsl1lNNcMhl2YVgykqaSHzbpnrnXyMe2W9faavnIKncBoWiI8gnttj6wz0Pkr3w8fizFS+QtL/TevYmrgEKT+KLHjrzLV+82qBe2HA+G9vLrj+zfcr6Q32TPIw7/X2XM8eGT9+2IktoR3tVflme6URMpEsLsFZ3plfT9Ad/whE4YMhhf05Ct+vNAdEWZO92Qy20R3JeZjid7wJY+uSPND4eNB6/GDH+meh7MHVW21CMjvFjl5fitdB5wroEjVtFshLqHpP+qmC0VLevEaDy3iqcvWxkCJXkXUnOa1aJt0KPx3INNfm6KmhzX4ykOZ8Qd9Rc7y2ydlU3OVM5TwnJDtei621MD1P2e19kS77X/HHoESeUO3VuLLGQC7UMNgQCTtaPnQLVo4NypW3wwCkfnrwE5mrh+JxwZCmKeCCE4vwgaUlQxBGfgMEuI8Yd+DRexlJwSDbRXBWjZvzva5CPSUau/MDmqG8STBjNltUHENXa0h9T65/h6pJFE37fX8XMiz6AfvwldPz2wau5B82+0ImukwhI= 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)(396003)(39860400002)(376002)(136003)(366004)(346002)(5660300002)(6666004)(6506007)(41300700001)(26005)(6512007)(8936002)(86362001)(66946007)(316002)(54906003)(478600001)(66476007)(6486002)(66556008)(4326008)(8676002)(2906002)(36756003)(186003)(83380400001)(7416002)(2616005)(38100700002)(14143004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: p6v+vMlQXzvaJbQolEmbNflt4yfX7aFofHGyhM++QGIFQeaIFv7CSciF+P3u3/7O7ziuxvxVfCuYTqXL19KrrRsa13UV+lVsIylGzc/Ierly5iB/gM/wEDwzQmdYnuspGpLYI1hrg2+x8u+QzS8ndOiETC29HpHHpcUAR48neThnCGgHXIfuYYoJDCxBMtCmKO5i6BcaJrYSYkTGqbhbLGDybC7TJZmPwnBFreGPa7NF358f6rnYos3Hx4NEBuWKz09bKhjT+zMHig0VRJJUGjOoI8Cddf8tbcen3BRIu/Wmz+syZn970WEVDbPEKlq2GI0YnvJTe2Gu+uVvD3IVBcyQwPu4tGPryAg2HpLHMMc7fnZRkkdapz3jPUE/aPZpcYeucu3Bs9s9xCwWxGvs4L11IXwMIPiDhR+WHKIwSwvOLXJSOOlUEcqvIJN5HjVRA6zfmPsU0oDWPhTc3leMOHCkA6vV8/eHr9el79EPHORm8acRpttSZsyA+Zl/OrWjURpll/GnTNpRrUSPYUa7GWkHZthBn3QaJcsPi3PHUNnFwWQxaIMjDHTA9Rz3sn9ckIqyNioZmHTEAIfrHq9b2fYOIXhNc0o9X+gfObi7PiUNDma6nG7BNVbmzD5Xe58d+9UMKtqg/2dcBFekIcdSi5PVmB15yZtRH3OCCv3yBQ4Pgy1chcoNJrDScv7SI1W1x82/WJJwCNeEU0Y8EC2xOUQC3Z8uvebUCCvMC8ZjraiwIM/xZX+V05ty22MpgSjU0AOOyJH3FN4QCb/D2sqQ7MoTpfBn9pF5sJgPqT8O9YuYPh1CxtgB06lw+J6Kpq7Fp8GPWfx3COvH61zFCUOjhjq1iYzaUK1FniZY60THAqjV3rPvQFKB7pcC4MY8kN5PSLpsqSX7lcuuOqq/poOHhqjzwMctiOKEQCevC1kPJpxbaf72buE3IS4A2btkVtdYQ65NhPjalvEPWo21IsP7ukWJMjmz3aLEp2zD4u3xkLyjiOQacOTMwJJ7eu7GzuywhUWsdQ8aJH2SswS78h2Vc99KKJM7Cit83xBKD9yJHO4gbOV3j1L73imgevEymKZn1EAUQaxiQ0UtalDN64ujhxKgxjalofZtEgr1qUk7vR78t6QB3dDyn6INJorN+aVF4v92WM56N2L8suD4fGv8DusI8w4z65xOzDlysB/90HMBh29LQZ8Rp3UlP5aa8ZWUAM5FSCf9Sw6EcWzvtkj+b46GrYxPzhF18C7hjbBb9DdfMYy8WslNPCA1iofcr9tsrMnhAAvA6vUrVfpj8hAm7/H2lAnOug+pPQQs8A6QRyOKiP/R8Zk23aSqnk8YI6wajWOG1npuUxE7XLJrHkkU5HdlrFavaGNyvnlwwCvOYfmo7Vsu3fe7fjke0ZI6S4rPce3XlWK7FGCHFrvaQzbQbQ2hlebsAEyUCV4ZVQ+niPqzG0tGEPYBurTKHQeLAcZ2C8xHj0oa21SnTMctYZBBuu4VxbZyKPw/3M0I3yruqfrajQF0G6VATcuue2eJbHQ1T8hHGIqvN+EkkwBxhx1t1/haCl8yxfNpNb1EAMJUCFKoQsqbg04kLe15rYsCDxT6 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c049e8a-ea4d-4c64-9c17-08da7c22c646 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2022 05:23:22.4532 (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: FojY0PWVXMMSgYG5XSWloU6ebwTYWyYRbS+oPpTh6qg5GvFfFM8e4lzn7255JF2EDXpXjkupyi7dVACL1tcpIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3978 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660281805; 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=51rvVXCforVG/VV+jnIVuOgd23Hpr3PwEdWaoS4K4Ag=; b=J2ycAN17PynfcAPm7TF0phJwbv3Y3Y1q+ujYBLHEwm12Qn4b6l8Ymrpb0MErwYNaQ+T4kV W+/dHlwTTjcRNgiTxFLkd2op6N91uhGOUIxu5LKK3W71Yn7/OpGvosMzK+4EYdLn9SSWJR eg5d8sgQtpHqFDUfSuLwLvASx/HdiKU= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="WyOup/eT"; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf09.hostedemail.com: domain of apopple@nvidia.com designates 40.107.94.85 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=1660281805; a=rsa-sha256; cv=pass; b=T3fTRInqZrvQIghDprGo9bUA+FC4FYnqXAckwn6xyUjKztQy0Rfr8yZtONJazBse/GtO2k 4pPc/rYtleSvcFh9WAeoiSAgY0FfSIZ2a20C23xDer9mcr9qkiWcvJJpS4qwhy6cKw9EKE FgyfPWl7h/sygNPZaEHhKPgUgMxIin0= X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4F41B14019C X-Rspam-User: X-Stat-Signature: ypte3mg76bscfr4gzqrb1pj3puoek575 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="WyOup/eT"; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf09.hostedemail.com: domain of apopple@nvidia.com designates 40.107.94.85 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-HE-Tag: 1660281805-213374 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 Reported-by: Peter Xu Reported-by: Huang Ying Acked-by: Peter Xu --- mm/migrate_device.c | 5 +++++ 1 file changed, 5 insertions(+) base-commit: ffcf9c5700e49c0aee42dcba9a12ba21338e8136 diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 27fb37d..d38f8a6 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -211,6 +212,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, 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(