Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5177523ioo; Tue, 31 May 2022 23:04:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtfHtP/bUVbCjPiz3c0uh4RUi7s9R8htajYVLCKLOd3G030HOGQ9mGKsxtAEa4rL4I69jo X-Received: by 2002:a17:90b:1a8a:b0:1e0:3630:19f0 with SMTP id ng10-20020a17090b1a8a00b001e0363019f0mr32277123pjb.89.1654063495552; Tue, 31 May 2022 23:04:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654063495; cv=pass; d=google.com; s=arc-20160816; b=jYk5VUMllbrGB8wjcBxxkCDdBQc9J+M/pv+YtcWNlQb3MnJ3HeZEN9Q1NtP4k8j2pE UCv8d53+W0K71EDPgTzIDegBNb4LD0CnzYgmuKweni44H9nsKUYaxZNcsOMWodfuvnkI hbNWLb2rvMVes18Gxgjl7RzgKqGxLZmoYTWbKXW1Pana0IwoDD1+v69fb80tK6r4EWOc T5MdDBDDLAFT28pIOzoMFgJtb4lx88/xRWmTXrpEnAlQFnltOgHj2hlwV48CFYzQjiX0 9/FERbW0OqjMnLM/UtWXtDpptqsusYbPDs3EuXebqDGvhsMlzY+0dC9aSAgzWdJudJwr tIew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Tsm1npeQJz5adlkprwdiF30iBrFOX7mFKo901b9QP1o=; b=mwH1qgdUhSF/GWfUNqp+scBZLZGtWkCKfHANoKH4IVLKMG33gja0N3aIOXHYqYJKS9 0Gut1ylFa4D/CQ/B+BOeQG0Sy16kmBgd6XiFivv4LjwyWpbWZ8vhy1VfVOQPxsEJsrSu a6AKZk5QAXpDFOzSZ5QJ+Db4y6VLNPiMSbJY8jV2tCT/e3F5h4nlA38IAjIyRoMi3h/o SxcQf1lY5TjcUNVn0CCxnQNpgkAoKI6bCTdN7WBWjtezG7bLdAHYs9refbxzlqBix9A/ D9j3MKQWzjWMtapbquyHPbV/Hb2Wqy8dipTM0Gztpz3j48fjFSTgMLqrnEJtPDmN/SvP ORpQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=i6Qtpeqw; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a056a00238f00b00506bc45aaecsi1072675pfc.371.2022.05.31.23.04.31; Tue, 31 May 2022 23:04:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=i6Qtpeqw; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347624AbiEaUBU (ORCPT + 99 others); Tue, 31 May 2022 16:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347625AbiEaUBE (ORCPT ); Tue, 31 May 2022 16:01:04 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2048.outbound.protection.outlook.com [40.107.237.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8114F60BAE; Tue, 31 May 2022 13:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ANg0ssv87wEb2XlAkSXvQ2aM2moJqsHnzpBZUZEibwiJnW7XN8c9nIxHcSwA6fb4GXpJSnSNOD3FaLeph5QFsfI0VoMbRh7aw734EMqDAJ6gVHSIsZ7Ii5nQBKtKo48o5KnR1K6me6uUAqDNIMF9CIf1xyqvqAU1DiFdrgPLfIJ0g1bBY4BGnMowIqwTqhQ2kbOnAXU7GkrkZo/ZQmPXP3Rt6+244yPrvxwA/sYL9sw5KTGzLG4e5B4nHLJY7L6+u17JH5nFOJuJi3Imz3yQWd+z/s+dIC9rYhVWwvdKR9QScjYB/RArzzBrb091trmNAjix5fjFqVNBwN/lYGYVNQ== 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=Tsm1npeQJz5adlkprwdiF30iBrFOX7mFKo901b9QP1o=; b=NzV1MfjFkfeNjlfSQJWq9Lj++LiagKnpb249faNZDkSQqjms/g0iWuSD89IAWmycxW+UXEAbvQd7sQZ+XIE3dxueMB6aG6sRyvekqYyQhEwtQpJXEeqfEMu+/rBJQeslZC9SGs8bvQmCW86tXLpD20wPdjtQkWOl9MHJUcLjP/tAJVZHifpMX2THkOQlUQ4odPkt7j5fGxSxo3SG0YLW3Zg8hU65GWHKX8HvcZzouLQaq4NwfyvTMSNr45vUMGAweFEUuWyr4yQHH4p3PQKdgb+HE6auDP9RrFh5r/xpWNO5yq/z71bO52LfqsiHhSkqB0JzipCf8R9NBkHtNTWG0w== 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=Tsm1npeQJz5adlkprwdiF30iBrFOX7mFKo901b9QP1o=; b=i6QtpeqwY7WedUfcYi41+sR5m8T4W1bUzEiLKPTUPrmEtIj3UBQEgi0JlC1+IPwPo3Zhp9t+3zZw61QfdMzz4idTN+1g2b9g9zrBQ4Rbl0lT0KsXF+Qko4+ObmbjKojSq5/IfooYz3rk1mBJKp47EIuaTZlSYXHngtzmt6U3Q88= Received: from BN9PR03CA0410.namprd03.prod.outlook.com (2603:10b6:408:111::25) by DM6PR12MB3769.namprd12.prod.outlook.com (2603:10b6:5:14a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Tue, 31 May 2022 20:00:57 +0000 Received: from BN8NAM11FT027.eop-nam11.prod.protection.outlook.com (2603:10b6:408:111:cafe::78) by BN9PR03CA0410.outlook.office365.com (2603:10b6:408:111::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Tue, 31 May 2022 20:00:57 +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 BN8NAM11FT027.mail.protection.outlook.com (10.13.177.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5293.13 via Frontend Transport; Tue, 31 May 2022 20:00:57 +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; Tue, 31 May 2022 15:00:55 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v5 03/13] mm: add device coherent vma selection for memory migration Date: Tue, 31 May 2022 15:00:31 -0500 Message-ID: <20220531200041.24904-4-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220531200041.24904-1-alex.sierra@amd.com> References: <20220531200041.24904-1-alex.sierra@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: 0bba815c-d1b5-489e-bd25-08da434046de X-MS-TrafficTypeDiagnostic: DM6PR12MB3769:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MWqTiNeofnuKHB6n/0vxzk/17wAYkpSXhmJVdm5AteM7m6npVmQLKZdvBBNTtApdDJ6sadq+RcdSVbjFLje2RhYF3GFgKNUkP+KqZV6bqHYIdnen6O9rZAzut4gl34tlU92TanLFqALuTPsvLCsDS9FWNkoH10h3CSYOKBdSdnOn9HRGcyaA+U+nWs6/MdHLzL2yVeqnHULFuCey+lQCwa+OvxT/v7ZU2v6eKddoNofWLwHskN9hsyvEYtUdnJepMg4//oRALx8HAUMQd9zl00/KJW61ePCH8bFvZxWMs293DIEdBvIPLxUZJXo8jbLUVKGRkc3v++KnhGCOMomP1BPFn01D6zkDYHjZqInmnxRmcE34gjLPsFeYOsbJzHPApqWNJazZ5fWqOl626YKGjiCmX688z9GZxW3CiFSLRUSnzjbHls1LOGqConcHl1QYvVyS4FdeBR93dzzo8O5/3VL6+O+x0se4y4DXNaYAWE8CfO2zcv90P6zT7up0FnHyV+Bly8UTZBdrVqtxlJ/7480AvBEjoHVWgVRN478Thk1irOcas6/2wdp0ahiBN4caUwdNBT97SMIwPtGQOO4UctCEYnctWnkVSgm+kywMnoxZDDLy2Vvg+yE53K00rA+SV0bfRTh7D6D2KarUiX2fssr5usjCKD69RUN78V8hzc5/lq2X8zXlL83p+BxNZp49et4X74p9K61sGuz8VOJeQA== 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)(40470700004)(36840700001)(46966006)(54906003)(81166007)(316002)(2906002)(26005)(7696005)(6916009)(36756003)(356005)(47076005)(83380400001)(336012)(426003)(8936002)(4326008)(16526019)(2616005)(7416002)(70206006)(5660300002)(70586007)(82310400005)(8676002)(44832011)(86362001)(40460700003)(508600001)(186003)(1076003)(36860700001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2022 20:00:57.1692 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0bba815c-d1b5-489e-bd25-08da434046de 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: BN8NAM11FT027.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3769 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 --- 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; } -- 2.32.0