From patchwork Fri Jan 28 20:08:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12729024 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 6AF05C4167D for ; Fri, 28 Jan 2022 20:08:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E02D6B00D6; Fri, 28 Jan 2022 15:08:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 48DC16B00FE; Fri, 28 Jan 2022 15:08:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3559B6B0100; Fri, 28 Jan 2022 15:08:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id 272B16B00D6 for ; Fri, 28 Jan 2022 15:08:56 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DE3AF80BFA22 for ; Fri, 28 Jan 2022 20:08:55 +0000 (UTC) X-FDA: 79080784230.23.2F400C2 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2059.outbound.protection.outlook.com [40.107.93.59]) by imf12.hostedemail.com (Postfix) with ESMTP id 73DB240013 for ; Fri, 28 Jan 2022 20:08:55 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ROV0JxFZ/1D64xMkRQfRxLLjRZ0UZtZz6Janb1mnxxBfFPJjrTojmJxKhSQ7eYrpYgvOiQ1pOiyQx8COdUe4qqcqOsWJB/FnVMjOxnMgK3QhS6HsS+V7u38osgKsnnElqaLRfTw3UxpsldEzix3fgvYkwAEXfMQsnpvBtjMmFhNFUVfx5LQIq3wivzi642fWx9Ro/8cTlkIzq5nCqUFpcKuDi8/5Nqyr/vba+lRr8daS2n1GwnuP4LYc3o5HF6y++KCfPFdXlUq6ygpwSdpy23f6LWnKyS+5+8mX6tqhOsCkLVqSemucRCXOin5nQ0lvPelUzVmZzux4Mw0qZGa3iw== 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=F0rN4N4gPflqxuYM3l8bPuLLJMLi9xz0M3xCz+bR1Mw=; b=MgDkbaWfPJcNN48HRAY28nWniRQGxDbrETa3oVeGUqL/4+g/WSvl0DMAoT6emN/cwI/rzhHUvtGgy1MX4bi86UEnw2506YNDtQUmHH4HRmPoRTYo/WbNFfYLy+b/+uS3SToaG6YUikddid+bC8SAx1n3NuGvcl5SNSC1iMZG30atzPqBckD1hJ/pqc0r6myLiUZ6dbL6u+u4r9uoAvybTTRYsbuUc4OB9n7aqJBnwzu5Dwpmrnu1Nlz/GMuUn9+EyOxY/n0HVqQxul+wV2iO30sn+yhvnDmZ9zquNnfw9SCw4vnMa52TPwzwwQ4cJ6tq1YiOe3sVqB/VqOLATSq8tQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F0rN4N4gPflqxuYM3l8bPuLLJMLi9xz0M3xCz+bR1Mw=; b=mTUNB02JGvzgtJ2sIWWPeNEXnOr7LnPC9qaAMxfGPUQQzmdZN88Rh+1C4jx6tvMTR6X4G9Gdm6eTXVmOmiteqaE6H0RVtH8xIvCCZLHr84V9rIlEpiZkacPERzjHNtcp6mXZekNtRZAkG8CbKVQMnk3FC/i8OGn0BAA/KcRz6v0= Received: from MWHPR19CA0059.namprd19.prod.outlook.com (2603:10b6:300:94::21) by BYAPR12MB3078.namprd12.prod.outlook.com (2603:10b6:a03:a8::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Fri, 28 Jan 2022 20:08:53 +0000 Received: from CO1NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:300:94:cafe::6d) by MWHPR19CA0059.outlook.office365.com (2603:10b6:300:94::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.18 via Frontend Transport; Fri, 28 Jan 2022 20:08:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT022.mail.protection.outlook.com (10.13.175.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Fri, 28 Jan 2022 20:08:53 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Fri, 28 Jan 2022 14:08:51 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v5 02/10] mm: add device coherent vma selection for memory migration Date: Fri, 28 Jan 2022 14:08:17 -0600 Message-ID: <20220128200825.8623-3-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220128200825.8623-1-alex.sierra@amd.com> References: <20220128200825.8623-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2e16e69d-3d5d-4dc5-d100-08d9e29a01c1 X-MS-TrafficTypeDiagnostic: BYAPR12MB3078:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:635; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +Rq/Cz0F1EZ+wZLMGMcZzIM6b3Cs399ng2cXCFf27rAvaXfoc9OUUqmnlwRMe2GbEGW32A2xfDNTxKMWQiI4e8BAG5iax/hPsCsP81zAE3nG7R8YPsUL74Qn0mHl8Bym27l9b6NiFSVQDUU9udWbo2Tfe/u+Km/kJxvsNBEZAUjHSCaYIopa3BvXSWcFu7UTH/LoO7saVips2oP0V58DizbcN7fezdPY9K99SV7VuuLK4s/IKe/G6UZAvqcXwA0paeEsrD5DZoJx5v0rCEWlCupibBHmKySduaAGN8vhe07Ne/sShtAO46KZ/L0La0HL4zd4FdidUbvTM3vLPsCAmePjaBX/uVTsrrpVBYup8Ug9HdlZUWqFQ1Hvzq5hnjua5u1cOMKiKxxQQ8Pqoyd74AXq08/OI4M/e68OVu/t2umAR54cBMPqUmuAL4F6pXsmdNToGZEk0QVz1QaezcRzzDsZgRLl8j777tBXqFOzxkgyy9uPp4o8lC7X4yA2dxCvZ39MpF/JqL8vnKoepSZ7unbugKbRSkmCLTYeWQLEL1K2TgTPdWwWDPdnobzALxc6cFmyTF540txsUoadMwTE7qNtaKS1eeikR1M7U91omyOrnK2Oo2/I+gBTMJIU8QsL7tXvgufGb7Q1wQaivBph2G26E7Qp2rOUhVbJHay8vuUz+/nzV/iNQN1MuSQ7BiWPveB+++UGsEJYWP4tAJVdFA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(36860700001)(4326008)(8936002)(70586007)(36756003)(70206006)(86362001)(8676002)(81166007)(2616005)(83380400001)(26005)(7696005)(356005)(508600001)(336012)(426003)(47076005)(82310400004)(316002)(6666004)(40460700003)(44832011)(5660300002)(54906003)(110136005)(2906002)(186003)(1076003)(16526019)(7416002)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2022 20:08:53.0237 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e16e69d-3d5d-4dc5-d100-08d9e29a01c1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3078 X-Stat-Signature: jd5g8wmsnrz7w1eu4h5ycsuy9chmnaug X-Rspam-User: nil Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=mTUNB02J; spf=pass (imf12.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.59 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 73DB240013 X-HE-Tag: 1643400535-553952 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: This case is used to migrate pages from device memory, back to system memory. Device coherent type memory is cache coherent from device and CPU point of view. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling --- v2: condition added when migrations from device coherent pages. --- include/linux/migrate.h | 1 + mm/migrate.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index db96e10eb8da..66a34eae8cb6 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -130,6 +130,7 @@ static inline unsigned long migrate_pfn(unsigned long pfn) enum migrate_vma_direction { MIGRATE_VMA_SELECT_SYSTEM = 1 << 0, MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1, + MIGRATE_VMA_SELECT_DEVICE_COHERENT = 1 << 2, }; struct migrate_vma { diff --git a/mm/migrate.c b/mm/migrate.c index cd137aedcfe5..d3cc3589e1e8 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2264,7 +2264,8 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, if (is_writable_device_private_entry(entry)) mpfn |= MIGRATE_PFN_WRITE; } else { - if (!(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) + if (!(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM) && + !(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_COHERENT)) goto next; pfn = pte_pfn(pte); if (is_zero_pfn(pfn)) { @@ -2273,6 +2274,13 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, goto next; } page = vm_normal_page(migrate->vma, addr, pte); + if (page && !is_zone_device_page(page) && + !(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) + goto next; + if (page && is_device_coherent_page(page) && + (!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_COHERENT) || + page->pgmap->owner != migrate->pgmap_owner)) + goto next; mpfn = migrate_pfn(pfn) | MIGRATE_PFN_MIGRATE; mpfn |= pte_write(pte) ? MIGRATE_PFN_WRITE : 0; }