From patchwork Fri Jul 15 15:05:12 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: 12919365 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 37DCFCCA480 for ; Fri, 15 Jul 2022 15:05:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B68DF9401ED; Fri, 15 Jul 2022 11:05:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEF699401F3; Fri, 15 Jul 2022 11:05:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7654F9401ED; Fri, 15 Jul 2022 11:05:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5B6A99401F1 for ; Fri, 15 Jul 2022 11:05:50 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3FBD320A6E for ; Fri, 15 Jul 2022 15:05:50 +0000 (UTC) X-FDA: 79689658860.18.C52D474 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2079.outbound.protection.outlook.com [40.107.101.79]) by imf18.hostedemail.com (Postfix) with ESMTP id 933C81C00BF for ; Fri, 15 Jul 2022 15:05:46 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IOC6GziTPn+qimKUDipKx9IzoQDfSMXK6oxiveM/o5MeF0UbZ9mJcpaGfkkdrXYixibhomFcpChUdSv2+9PB0CzP85fIH+aZuAxlk5Lnqv3qYsakPoE12je83bbdFUYA0GkReGhIRUspGErJAdn/rg5YyfYGv4hQ6nr46Z3N7Te/4AP+Cn2CNw7YsVpU0Ne7mfqTKD7xuVVVw3Y3VSxZenO9k7okpbwZWI+QHEYWDq2wNm74T/j0Nsnz6JQACR16a0eB5yRbhuFHIYhrtHVKnS1p1EetZjDLY8r9HvbsLVRFr+Ev/njdr7SPWuhG6BTU53oGoyXm1gEhc91U50rplw== 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=FufDotkIE3bdjczHZAIIAyLhAtHM05ZPrkv0yNJ6rj0=; b=QRlydB4cQU/ykWs4I4wRcnUKNVDmp3KN5225nJ0V3UYUd5OVzPikG4bdmMqDZyWURJf4rzhbXd/c2nxI9Ei9lGi/MPqAIoNvD6QmRxB+VQ/m+5GxhC/LysdVtW4KMLxGMf0w0z4y44XL6a/38sDFJPkym4n/kod914Zini9tgeBsYNzKipM0dQUMgdxOOKhu/lDOJ6Vd4PZzzHpC61lpbrgwW7LN5MzmCqJlwSIKA3d2dvBbxu34AY3SSQ8wSysgczuiVtDJQnQDAFnLCaqEwhuYyiZZ1VGBGWxpIUyr1gVw2Fxyyniz40pfvWqVeo0tIYKucqlZe3BJOAk5dAE9hA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=FufDotkIE3bdjczHZAIIAyLhAtHM05ZPrkv0yNJ6rj0=; b=pvfJ4UZfVZ+Lrbb85UYtODyfEdylvP5Ka9rraduUOqH7734m7c2+DNxXSU2CxNShrgdUGDkIo8+pFfZTSFg1VR3ZA248k/6Gh8KS7y3dIHrsR7ai8+brvBsRPHcudnhDrJs2jbeNR1/jnusu8XGART2lO1dLWeCiUz3NGGQ5KEY= Received: from DS7P222CA0004.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::14) by LV2PR12MB5750.namprd12.prod.outlook.com (2603:10b6:408:17e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.18; Fri, 15 Jul 2022 15:05:43 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::e4) by DS7P222CA0004.outlook.office365.com (2603:10b6:8:2e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:42 +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; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT045.mail.protection.outlook.com (10.13.173.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:41 +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.28; Fri, 15 Jul 2022 10:05:39 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 05/14] mm: add device coherent vma selection for memory migration Date: Fri, 15 Jul 2022 10:05:12 -0500 Message-ID: <20220715150521.18165-6-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1a2f3484-bb6c-4f4f-4f6a-08da66737c5e X-MS-TrafficTypeDiagnostic: LV2PR12MB5750:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2jQfFetPKdPb69TlQ9GJdiRSwpgh6CG9O9j4i+0A2InL4kpJOY5zOcgpP/nVAiH31gJWqDScpM3jNSXJ4arijUOJqSobM9+vbtXx88PQsjQn5VKynqYnGzAXIw4cYbr/dx28RXhEi55um2YGQTzJC03C3wI8+pfYE99ky5vwNOSWyTWDF6PvHr6zCqi7i9I4/Ps3Q/Pjo6exKQT7rxRkBMp7/L/hPCYnep7dnx9aP4w/KRtQuPLRNCx+Rc6HBnEHKpoJy4N7QrLhk4aHAqBpAaPWKYQ7/0jovuxWfTd3Y+9ZLrxfaaz2hcpTnTYkyf57fKYc23aZzO9tEkxbZL8BncphcMU79fioiuH/zFOMd/qL5hgItEd2skQTH+ie0QB6bpVudTrxFrF4LkmF/MwWNaqLGgKzFq051L4W86zkl/s3eRWkR9GZhYCpT0tK8zbwgGoiXM1+MoYfFty175rPK/4TYsZPb0UTBAG4jq0/25vVIDXQnTNyK2dN77ZMHDyHJtnivyevZZSrKsjiwClUNrMXhvjTcoMc1PWoqBoX5g5lmphHIEM4GaqqSbmf4eY2Jt4yYerPzbJ6nlMhgS4KKvzpU7AcbJm3APGQXEgxyGDnTj70Mj+Vdj9+w3Z/apwtA7qpZjc9JGuXDYuKlWbmWLuQEROHyoG8ZfO8jHKbEWWM2zzJBanITIcG6fGhqg629N29a66btg8823wNi/pX4hmdvKTH7yd6+alWoUpZ9SOhQI2S2Gb4vp4ia515mzZ1xLFjvSFS0qkqxV3seRlMln8zpp624WCozzvOvD/v05k3+fSX+bID4Wp3sbomF+zOYR3C68E+PXsuBI/HK07/YeW6j0ZIGDTXIUzr1mC1hos= 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:(13230016)(4636009)(136003)(39860400002)(396003)(376002)(346002)(40470700004)(36840700001)(46966006)(82310400005)(316002)(36756003)(82740400003)(40480700001)(8676002)(4326008)(356005)(81166007)(54906003)(6916009)(70206006)(36860700001)(70586007)(26005)(7696005)(336012)(426003)(8936002)(6666004)(2906002)(2616005)(1076003)(86362001)(44832011)(40460700003)(83380400001)(478600001)(47076005)(41300700001)(7416002)(5660300002)(186003)(16526019)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:41.9236 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a2f3484-bb6c-4f4f-4f6a-08da66737c5e 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: DM6NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5750 ARC-Authentication-Results: i=2; imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=pvfJ4UZf; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf18.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.79 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657897549; 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=FufDotkIE3bdjczHZAIIAyLhAtHM05ZPrkv0yNJ6rj0=; b=LmKzBQOBwizusZp6/z/DlT9c3pgeQAyGhEHW+VH6xco1s8YNt0fnUuCj/EXFVci2HIIb5s NRqOI6OxXhGT2JjbNXFXkhOseARbwYljZ/0C46CrTG6huwjYQAu7osTJ8OZqhhicJTMFJp pJSNlRlzxegw+me5YKR7/F6alGswsl8= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897549; a=rsa-sha256; cv=pass; b=V+eiiWuNHnGGZf5Er12e/qiGVBLmi9vqs1qLN9LWIWVmVBKiXz5CnTxZ7LdoxAqSwS1zhK g3uCqCQXqzPeh8Mrfb6EFx1qbm0f8oOHbRrsJgACK/wiAM9THCionBI4o4RZfr95y8LYIK izNUy7Y7QlS27JAF7lwY47qln4GyyeM= X-Rspam-User: X-Rspamd-Queue-Id: 933C81C00BF X-Rspamd-Server: rspam02 X-Stat-Signature: bgc8f6sntrdyqh1zgw4smyw97qbxcy59 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=pvfJ4UZf; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf18.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.79 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1657897546-724348 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 Reviewed-by: Alistair Poppple Signed-off-by: Christoph Hellwig Reviewed-by: David Hildenbrand --- include/linux/migrate.h | 1 + mm/migrate_device.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 069a89e847f3..b84908debe5c 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -148,6 +148,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_device.c b/mm/migrate_device.c index a4847ad65da3..18bc6483f63a 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -148,15 +148,21 @@ 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)) - goto next; pfn = pte_pfn(pte); - if (is_zero_pfn(pfn)) { + if (is_zero_pfn(pfn) && + (migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) { mpfn = MIGRATE_PFN_MIGRATE; migrate->cpages++; 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; + else 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; }