From patchwork Tue Jun 28 00:14:41 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: 12897303 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 1025CC43334 for ; Tue, 28 Jun 2022 00:15:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91ABB8E0003; Mon, 27 Jun 2022 20:15:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 82E628E0001; Mon, 27 Jun 2022 20:15:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56DF68E0003; Mon, 27 Jun 2022 20:15:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 49C2E8E0001 for ; Mon, 27 Jun 2022 20:15:25 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1C671344AB for ; Tue, 28 Jun 2022 00:15:25 +0000 (UTC) X-FDA: 79625725410.05.D597303 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2083.outbound.protection.outlook.com [40.107.95.83]) by imf08.hostedemail.com (Postfix) with ESMTP id 300F416002D for ; Tue, 28 Jun 2022 00:15:24 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oE6fZ8I0jMr6WZrifI9JShD67W/ewuqHSC8Oyp9NQfKizgfoq8X88Iil+k7Gq/z0meROiiEvo0bzRYMZy2GU6bfirjahzSlbZclMuw2pO6/AU1HoUEo3QW5Uagjfmky/stsSfvk1M3tZcxogQh23xW9HhtlOGJxboQeps6mh2M3QAtXR+jNf6loJSAn/H0UzqJkS73DegQNDvLwCOkobuQM3Oo+m+0RLoW6U+46Eurp58Qy0I+GrmAg37ifh8ddcz+tGcA+Hf/mPJiKZzHFxTmCXipzcB44ij4tmq4Oe564OJH4aUb7qKd5Sht89ecpQ400AWBTc6iHQaClXs7hzTw== 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=NN0fSNUfIviFYWrAMIMXsV6Hsd+z0eNwwBrjR/TyjQM=; b=LwWe0Plt8oHjzwUyliTcVhYSni4phhqLrw1AcH3wjUSnmizbeqrHcWpo4buuV3lYWn2k9r0EZ12Umkc63ypfiz4x5LQ45XgD8+kXa5gsiItpti3c/xnBzqdGfoWfpTc/ZKHxsypimVPjWxBFqoHMpYgkE/7HDoJBxGNuxOyLM7Hhujt7PKhjVAhDdtjmy/ozT9FUTG4xO6PHnxdJij5fjl0rA2QJ2N0w/XB4Xzjf6GM/XsVn9ggDZbpzTfntcOeOxusT6SuVEeEphZUOnoFbhp75O43vU2Y9pDhAwtsZYtTLnmlsztiLYg4cZtHK2oeL/7h+Frv2eaP55dM1THjl4w== 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=NN0fSNUfIviFYWrAMIMXsV6Hsd+z0eNwwBrjR/TyjQM=; b=LGRGIb/Dqrq45ICJ3ltbqgNYYCsxnCJjqmM09w2B0HmmvnsySU0E/m51EfeoWeWt0Vayf17g1979lVoEF1ev3wJ/Fo26e1iYtA3E1+WLEpjcFD8SjJF8ygM1nKimLjKPu5G7j0XObt/LRbw085ADRXXNiBPQDBK2rjhuQZXSK2M= Received: from MWHPR15CA0071.namprd15.prod.outlook.com (2603:10b6:301:4c::33) by DM5PR1201MB0156.namprd12.prod.outlook.com (2603:10b6:4:59::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.18; Tue, 28 Jun 2022 00:15:21 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::fe) by MWHPR15CA0071.outlook.office365.com (2603:10b6:301:4c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.21 via Frontend Transport; Tue, 28 Jun 2022 00:15:21 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:21 +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; Mon, 27 Jun 2022 19:15:19 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 01/14] mm: add zone device coherent type memory support Date: Mon, 27 Jun 2022 19:14:41 -0500 Message-ID: <20220628001454.3503-2-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: 409e7f1a-17dc-4c6d-5fbd-08da589b4a45 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0156:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u1DjzDxF3dMAGFSp97zu9ayedEP7+drZsuobDdeFUHq9JRD8QHSbv9s7E1illC2Vc8XzEM3Ai9ZBr6Ypb6aNLi6FE2t2ScOp5gB7S6U3ljTb15yfviPxu1Y9wnIP6N39JUEFFSl0ttAvTbQihPSoGaYq4PiVjF3yVf/Y7WZKoKvCm/LEEuZSg+Q1N+SU0RlYSHDZQmimy+iVHaj8V+lMFOnEk/qgXbqmFYsf6TRgDsbLYFshnsk6sR9TMzmCdOJmqX6GeFnXxqr6d4T52JNydUEpWrYdEIiIa440kPm6Jt2JNJoLPQyQPj+VMJIP5HSwxW7uhNZmwVc2FseIiL/yZeGx0EyyCzOCXSV1fOTp23cBACGxH8dHSPTUue55xwUpLdRqw3flO02iRXNzSfhkLkVa290A42Fxu/ys5HF4a5OcFqhJR4FXZl/ObgxEDdz71JLJ5yP5MqmAe7pTRsBZXLknuGT87Qlysb33vJwZrGX8na3O4p2t7Vp5+bOoE/1dk/EJrfsxhSBh1mocxlQ54PqKs1zer73DgAUNmNEQysn78BLx0DJW8GeH+OUYRgYwzwtH/zO4b9a1s4aQ1SAOrO/ZKTWpVUz+OAoxzsQoqHIW3+0FPTKI7pEjQob6rYeqmCSnnssu8e9o6QUAw9oG4S3p5/wr44lncKlQuWuUUiPTNsjrbvd0b/qXOqevZN0D57Bv6T+2XLxaa0g1AEHC8D49DooTx4mDQuLVlH6eCMbjaXsd1QAixznrwPt1i7dFg+MctN+MN68Ij39LeMBrgUg/ZejpWmRC9anRaC+QLturfvpCBcS0iraSI9mq2RemXDVsmDDHpZZDATJ+nmEsQQ== 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)(39860400002)(136003)(396003)(346002)(376002)(46966006)(40470700004)(36840700001)(4326008)(70586007)(8676002)(36860700001)(70206006)(83380400001)(81166007)(8936002)(44832011)(426003)(7696005)(47076005)(40460700003)(356005)(478600001)(40480700001)(26005)(82740400003)(16526019)(336012)(186003)(7416002)(5660300002)(36756003)(82310400005)(1076003)(2906002)(6916009)(316002)(6666004)(54906003)(2616005)(41300700001)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:21.3707 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 409e7f1a-17dc-4c6d-5fbd-08da589b4a45 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0156 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375324; a=rsa-sha256; cv=pass; b=tDzm/lWnJDlneucEWdcW01a+7ChSNiBqJROvy+FLeFVHWZuw/BSGJl8Iks1E0CvogzaGuH 7+7vUqE8LheJsz21I+phDJzM3oUN7hkp6SY7EmG5D7UwU9Yu7/NLGt8xtIbv1u3SPvtpnh NXraS3wE6bdyHjIOTKqTjBKL/RWhKfo= ARC-Authentication-Results: i=2; imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="LGRGIb/D"; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf08.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.95.83 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=1656375324; 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=NN0fSNUfIviFYWrAMIMXsV6Hsd+z0eNwwBrjR/TyjQM=; b=denM9+Kj7jzRahbaTKFt6lg0BjjOBTG5YbIum75NsCqrxC0sWsjQ/OUC/3/prXojnFWG2Y 3AbszVwu/thYWXEXEZLeG1S7Gi+ykCkMXN11F9xmtTnW1hZXRZkgwA9JR+1QaHnXMo/meZ plqeKgvuLUx7VOnvT4CpTPfmT0cq1ls= X-Rspam-User: X-Stat-Signature: t8u5pz1hkbr3cr1ji7x5hxn9yb1qe3pf X-Rspamd-Queue-Id: 300F416002D Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="LGRGIb/D"; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf08.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.95.83 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam03 X-HE-Tag: 1656375324-155949 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: Device memory that is cache coherent from device and CPU point of view. This is used on platforms that have an advanced system bus (like CAPI or CXL). Any page of a process can be migrated to such memory. However, no one should be allowed to pin such memory so that it can always be evicted. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Popple [hch: rebased ontop of the refcount changes, removed is_dev_private_or_coherent_page] Signed-off-by: Christoph Hellwig --- include/linux/memremap.h | 19 +++++++++++++++++++ mm/memcontrol.c | 7 ++++--- mm/memory-failure.c | 8 ++++++-- mm/memremap.c | 10 ++++++++++ mm/migrate_device.c | 16 +++++++--------- mm/rmap.c | 5 +++-- 6 files changed, 49 insertions(+), 16 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 8af304f6b504..9f752ebed613 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -41,6 +41,13 @@ struct vmem_altmap { * A more complete discussion of unaddressable memory may be found in * include/linux/hmm.h and Documentation/vm/hmm.rst. * + * MEMORY_DEVICE_COHERENT: + * Device memory that is cache coherent from device and CPU point of view. This + * is used on platforms that have an advanced system bus (like CAPI or CXL). A + * driver can hotplug the device memory using ZONE_DEVICE and with that memory + * type. Any page of a process can be migrated to such memory. However no one + * should be allowed to pin such memory so that it can always be evicted. + * * MEMORY_DEVICE_FS_DAX: * Host memory that has similar access semantics as System RAM i.e. DMA * coherent and supports page pinning. In support of coordinating page @@ -61,6 +68,7 @@ struct vmem_altmap { enum memory_type { /* 0 is reserved to catch uninitialized type fields */ MEMORY_DEVICE_PRIVATE = 1, + MEMORY_DEVICE_COHERENT, MEMORY_DEVICE_FS_DAX, MEMORY_DEVICE_GENERIC, MEMORY_DEVICE_PCI_P2PDMA, @@ -143,6 +151,17 @@ static inline bool folio_is_device_private(const struct folio *folio) return is_device_private_page(&folio->page); } +static inline bool is_device_coherent_page(const struct page *page) +{ + return is_zone_device_page(page) && + page->pgmap->type == MEMORY_DEVICE_COHERENT; +} + +static inline bool folio_is_device_coherent(const struct folio *folio) +{ + return is_device_coherent_page(&folio->page); +} + static inline bool is_pci_p2pdma_page(const struct page *page) { return IS_ENABLED(CONFIG_PCI_P2PDMA) && diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 618c366a2f07..5d37a85c67da 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5665,8 +5665,8 @@ static int mem_cgroup_move_account(struct page *page, * 2(MC_TARGET_SWAP): if the swap entry corresponding to this pte is a * target for charge migration. if @target is not NULL, the entry is stored * in target->ent. - * 3(MC_TARGET_DEVICE): like MC_TARGET_PAGE but page is MEMORY_DEVICE_PRIVATE - * (so ZONE_DEVICE page and thus not on the lru). + * 3(MC_TARGET_DEVICE): like MC_TARGET_PAGE but page is device memory and + * thus not on the lru. * For now we such page is charge like a regular page would be as for all * intent and purposes it is just special memory taking the place of a * regular page. @@ -5704,7 +5704,8 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma, */ if (page_memcg(page) == mc.from) { ret = MC_TARGET_PAGE; - if (is_device_private_page(page)) + if (is_device_private_page(page) || + is_device_coherent_page(page)) ret = MC_TARGET_DEVICE; if (target) target->page = page; diff --git a/mm/memory-failure.c b/mm/memory-failure.c index da39ec8afca8..79f175eeb190 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1685,12 +1685,16 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, goto unlock; } - if (pgmap->type == MEMORY_DEVICE_PRIVATE) { + switch (pgmap->type) { + case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_COHERENT: /* - * TODO: Handle HMM pages which may need coordination + * TODO: Handle device pages which may need coordination * with device-side memory. */ goto unlock; + default: + break; } /* diff --git a/mm/memremap.c b/mm/memremap.c index b870a659eee6..0f8f08f8a991 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -315,6 +315,16 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid) return ERR_PTR(-EINVAL); } break; + case MEMORY_DEVICE_COHERENT: + if (!pgmap->ops->page_free) { + WARN(1, "Missing page_free method\n"); + return ERR_PTR(-EINVAL); + } + if (!pgmap->owner) { + WARN(1, "Missing owner\n"); + return ERR_PTR(-EINVAL); + } + break; case MEMORY_DEVICE_FS_DAX: if (IS_ENABLED(CONFIG_FS_DAX_LIMITED)) { WARN(1, "File system DAX not supported\n"); diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 5052093d0262..a4847ad65da3 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -518,7 +518,7 @@ EXPORT_SYMBOL(migrate_vma_setup); * handle_pte_fault() * do_anonymous_page() * to map in an anonymous zero page but the struct page will be a ZONE_DEVICE - * private page. + * private or coherent page. */ static void migrate_vma_insert_page(struct migrate_vma *migrate, unsigned long addr, @@ -594,11 +594,8 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, page_to_pfn(page)); entry = swp_entry_to_pte(swp_entry); } else { - /* - * For now we only support migrating to un-addressable device - * memory. - */ - if (is_zone_device_page(page)) { + if (is_zone_device_page(page) && + !is_device_coherent_page(page)) { pr_warn_once("Unsupported ZONE_DEVICE page type.\n"); goto abort; } @@ -701,10 +698,11 @@ void migrate_vma_pages(struct migrate_vma *migrate) mapping = page_mapping(page); - if (is_device_private_page(newpage)) { + if (is_device_private_page(newpage) || + is_device_coherent_page(newpage)) { /* - * For now only support private anonymous when migrating - * to un-addressable device memory. + * For now only support anonymous memory migrating to + * device private or coherent memory. */ if (mapping) { migrate->src[i] &= ~MIGRATE_PFN_MIGRATE; diff --git a/mm/rmap.c b/mm/rmap.c index 5bcb334cd6f2..04fac1af870b 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1957,7 +1957,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, /* Update high watermark before we lower rss */ update_hiwater_rss(mm); - if (folio_is_zone_device(folio)) { + if (folio_is_device_private(folio)) { unsigned long pfn = folio_pfn(folio); swp_entry_t entry; pte_t swp_pte; @@ -2131,7 +2131,8 @@ void try_to_migrate(struct folio *folio, enum ttu_flags flags) TTU_SYNC))) return; - if (folio_is_zone_device(folio) && !folio_is_device_private(folio)) + if (folio_is_zone_device(folio) && + (!folio_is_device_private(folio) && !folio_is_device_coherent(folio))) return; /* From patchwork Tue Jun 28 00:14:42 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: 12897304 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 0F3A5CCA47B for ; Tue, 28 Jun 2022 00:15:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAE0B8E0001; Mon, 27 Jun 2022 20:15:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D88348E0005; Mon, 27 Jun 2022 20:15:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD6D08E0001; Mon, 27 Jun 2022 20:15:25 -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 A28DA8E0005 for ; Mon, 27 Jun 2022 20:15:25 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 738602117D for ; Tue, 28 Jun 2022 00:15:25 +0000 (UTC) X-FDA: 79625725410.30.4E02265 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2076.outbound.protection.outlook.com [40.107.92.76]) by imf29.hostedemail.com (Postfix) with ESMTP id D537B12001E for ; Tue, 28 Jun 2022 00:15:24 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qpi6tTJNDwOv4KHTiRYMKcXYoUVewT+sguQ0tUyqvWJnohUtTSofBwzqdZWVTqb6XPY754XTAPjyvm8toOWFcdldasgYlh8OfiADlO9aZtcO5PBWNMujpxiVFf+z9kSGBtKavLOcx31gz6klkR+UIbi5IHeNj53u+d2vzF6eq+e3Cuuzh2XM4fkH3iZm+aNrOEkYgvyk+/fqjSoj4LJZcpOwQzcei9yisXaPzNndqCBAsHg101VlqMkGazBekEitEQmjPoVLn9xP7WJy2TU9imCYJ/got1eFkSGEkOIESn37ZF/IpzhHcrJURqidReFfu+ps1jbMZalEZHzTx6Xw+Q== 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=xYDXGg3K1in8s7W57rXMiHvUn8+n+gxnVSApI1oD/Fc=; b=hQbUUgpqlH+kY1iHS4joUag1WEMKj0BU8sdLbWESjB+OrpAmCxtDuQFgu1r5vvtj5GKd6v4DNLqtpf9gly24r6rD1fiMM1GU1hvcU6O+50ACsPcRNHrjJAMT44Eb/vr54ZRuKoQd4qkQA/HOm9CemCXgyBzif7m9pKRQfSNG+I+aA/MiSzdQc1m8ryTTxeCmNslOzkDSoRfwScLlWfHirkDzCwjs0Tc12OsfQ2HjNnXxwbnaVO+2pkMJC3mt+yZyn1yCzPBfaVH7F0edQK9VGTyiFhHcPJXKiP8kExcVp/f2eS43nqHMo46Xwzh/YWgw6eBkXP/OflhZ6gfS+bSWWg== 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=xYDXGg3K1in8s7W57rXMiHvUn8+n+gxnVSApI1oD/Fc=; b=intcZ95BydNfStKFxe4cYnnEvk8IqznBg+IJKJVUao0bWHeV+c1Aj55aDHt8XKHQU4OeIqpsG9ii7hRBe8xX0CG+XDKrjuB48CaOEoAMNcczbPjGaKa2L6M8oH3TFkdBEG8CShwDSh7e9MtYZ9CBS5dXeHr5jfvw0c3a+cpDbQI= Received: from MWHPR15CA0054.namprd15.prod.outlook.com (2603:10b6:301:4c::16) by SJ1PR12MB6337.namprd12.prod.outlook.com (2603:10b6:a03:456::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15; Tue, 28 Jun 2022 00:15:22 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::b7) by MWHPR15CA0054.outlook.office365.com (2603:10b6:301:4c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.21 via Frontend Transport; Tue, 28 Jun 2022 00:15:22 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:22 +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; Mon, 27 Jun 2022 19:15:20 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 02/14] mm: handling Non-LRU pages returned by vm_normal_pages Date: Mon, 27 Jun 2022 19:14:42 -0500 Message-ID: <20220628001454.3503-3-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: afa43afa-82c1-46a4-7eb9-08da589b4ac8 X-MS-TrafficTypeDiagnostic: SJ1PR12MB6337:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XHSLxf7diBsKIawg1nJzWyT8/FptRt2DtCVYvjvQR0uvyCnBFVu9A/FQl2kS7QAs1UEAkWDAXnOrQzc7nvAcVj+iuCbbqHoCU2B7rJ5bQQzNshx13LZGoLI4gKIT+S2Lgz+6n/hPbLeFKtYCqOLE9B6yv0BoXEn7Fq9K1eciKBLpylMF2kG+MSi6b6iAtr+3ek/pA8VqNAmJh2N2jz1FONnRwjPba1m9tdVyR2NeIPrSLm0QHziva0yCjneLSrZNgcsuPPzrWZmtaZynX++4cVqzNsq8H6k51CCNZT9DQSJgDSloOtXVAQ4P/IiGOhh3LAK0Xm5aZV3yjd3JgxmFZJjoKtHVFBWTAwD2fv5kvDI/Zrr+g7htQlBffG3Y2rnSRAl/DvaxZCUK2DQL0CE1gWVnmhYFe55dds20RGGIbHT/y3lr2DLmjYAlYbLWh5fDBCWdJd7F8EmaM226W89MFMrBZHqbofsm7xAFVFhvLoUjWdkvveHa+cXw8MOB7OoPFUHg5FWM7/bnQgmm1I3tlh2Ir/LmTaShmPfomkEk5c4ZYhlLXmxv9ilepjtKZaOmTo6Dyb5i7K97iMCULscq6QiQL4DkCcZQ65Ftiks+aOSCRV+2UNc+ybJswJDeaPmte1i7CNfWlwnRkhHQTFr9sxOYfMNlHr+zemR1hJD4CD3+Xs3l2qxPOls2k9Phcm84/rLfksIQMeTPr1ohd/w+lOahQNYc6Rv5hQOHvOF4SCk/F9wTbPAFgq+ZeQuMkMyniaCBeJDJdozRr6ORd/+yI6ykz3GFtqee/uSUzyL1FKNj5arFTXUVqJ0WkIn952F8QLi7sEecxDJJRk28sUK8Qw== 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)(396003)(39860400002)(136003)(346002)(376002)(40470700004)(46966006)(36840700001)(7416002)(36756003)(316002)(70206006)(186003)(44832011)(478600001)(4326008)(356005)(2906002)(6916009)(81166007)(16526019)(8936002)(54906003)(5660300002)(1076003)(70586007)(82310400005)(8676002)(40460700003)(41300700001)(6666004)(7696005)(86362001)(40480700001)(36860700001)(2616005)(82740400003)(336012)(426003)(47076005)(26005)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:22.2300 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: afa43afa-82c1-46a4-7eb9-08da589b4ac8 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6337 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375325; a=rsa-sha256; cv=pass; b=Y49A7k86K4u8YQhsRkdKjPVgSwZxbTvvusBGwftkH5X7pT8jnl3qhj3RJ3KLIfWuefvLiE dD4zpOdv9Mswh7qHV40u3eHxnt7mCYT2m+PyRkawasPyDK3hi00juHeHi35fWCQGPX+uQf R9V9dwDedHSda2+HR8C71i8UZ5V7eV4= ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=intcZ95B; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf29.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.92.76 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656375325; 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=xYDXGg3K1in8s7W57rXMiHvUn8+n+gxnVSApI1oD/Fc=; b=nR6Dqtpihup78VrNo6zKN/IZNoQh0oWL/aeUynsGEtmJWyzfFHqbV6Drl3GuQRmYMgjae3 Wfu8t/3mZEYIgTAX1DrJYwnKb3vKzvNxfpJl6umY7Um0nx54KEO2/GDH4M74LwJqJmp119 lE/3z6mwWInK5CHTzzeDtX9tOom3j34= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D537B12001E Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=intcZ95B; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf29.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.92.76 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: X-Stat-Signature: jwxu8jn6wqmo6j6pmfwfmehzz1ngaeoq X-HE-Tag: 1656375324-281915 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: With DEVICE_COHERENT, we'll soon have vm_normal_pages() return device-managed anonymous pages that are not LRU pages. Although they behave like normal pages for purposes of mapping in CPU page, and for COW. They do not support LRU lists, NUMA migration or THP. We also introduced a FOLL_LRU flag that adds the same behaviour to follow_page and related APIs, to allow callers to specify that they expect to put pages on an LRU list. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Popple --- fs/proc/task_mmu.c | 2 +- include/linux/mm.h | 3 ++- mm/gup.c | 6 +++++- mm/huge_memory.c | 2 +- mm/khugepaged.c | 9 ++++++--- mm/ksm.c | 6 +++--- mm/madvise.c | 4 ++-- mm/memory.c | 9 ++++++++- mm/mempolicy.c | 2 +- mm/migrate.c | 4 ++-- mm/mlock.c | 2 +- mm/mprotect.c | 2 +- 12 files changed, 33 insertions(+), 18 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 2d04e3470d4c..2dd8c8a66924 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1792,7 +1792,7 @@ static struct page *can_gather_numa_stats(pte_t pte, struct vm_area_struct *vma, return NULL; page = vm_normal_page(vma, addr, pte); - if (!page) + if (!page || is_zone_device_page(page)) return NULL; if (PageReserved(page)) diff --git a/include/linux/mm.h b/include/linux/mm.h index cf3d0d673f6b..f6f5d48c1934 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -601,7 +601,7 @@ struct vm_operations_struct { #endif /* * Called by vm_normal_page() for special PTEs to find the - * page for @addr. This is useful if the default behavior + * page for @addr. This is useful if the default behavior * (using pte_page()) would not find the correct page. */ struct page *(*find_special_page)(struct vm_area_struct *vma, @@ -2934,6 +2934,7 @@ struct page *follow_page(struct vm_area_struct *vma, unsigned long address, #define FOLL_NUMA 0x200 /* force NUMA hinting page fault */ #define FOLL_MIGRATION 0x400 /* wait for page to replace migration entry */ #define FOLL_TRIED 0x800 /* a retry, previous pass started an IO */ +#define FOLL_LRU 0x1000 /* return only LRU (anon or page cache) */ #define FOLL_REMOTE 0x2000 /* we are working on non-current tsk/mm */ #define FOLL_COW 0x4000 /* internal GUP flag */ #define FOLL_ANON 0x8000 /* don't do file mappings */ diff --git a/mm/gup.c b/mm/gup.c index 551264407624..48b45bcc8501 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -532,7 +532,11 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, } page = vm_normal_page(vma, address, pte); - if (!page && pte_devmap(pte) && (flags & (FOLL_GET | FOLL_PIN))) { + if ((flags & FOLL_LRU) && ((page && is_zone_device_page(page)) || + (!page && pte_devmap(pte)))) { + page = ERR_PTR(-EEXIST); + goto out; + } else if (!page && pte_devmap(pte) && (flags & (FOLL_GET | FOLL_PIN))) { /* * Only return device mapping pages in the FOLL_GET or FOLL_PIN * case since they are only valid while holding the pgmap diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 834f288b3769..d242184ab169 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2906,7 +2906,7 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, } /* FOLL_DUMP to ignore special (like zero) pages */ - page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP); + page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP | FOLL_LRU); if (IS_ERR(page)) continue; diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 16be62d493cd..671ac7800e53 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -618,7 +618,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, goto out; } page = vm_normal_page(vma, address, pteval); - if (unlikely(!page)) { + if (unlikely(!page) || unlikely(is_zone_device_page(page))) { result = SCAN_PAGE_NULL; goto out; } @@ -1267,7 +1267,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, writable = true; page = vm_normal_page(vma, _address, pteval); - if (unlikely(!page)) { + if (unlikely(!page) || unlikely(is_zone_device_page(page))) { result = SCAN_PAGE_NULL; goto out_unmap; } @@ -1479,7 +1479,8 @@ void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr) goto abort; page = vm_normal_page(vma, addr, *pte); - + if (WARN_ON_ONCE(page && is_zone_device_page(page))) + page = NULL; /* * Note that uprobe, debugger, or MAP_PRIVATE may change the * page table, but the new page will not be a subpage of hpage. @@ -1497,6 +1498,8 @@ void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr) if (pte_none(*pte)) continue; page = vm_normal_page(vma, addr, *pte); + if (WARN_ON_ONCE(page && is_zone_device_page(page))) + goto abort; page_remove_rmap(page, vma, false); } diff --git a/mm/ksm.c b/mm/ksm.c index 54f78c9eecae..400790128102 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -474,7 +474,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr) do { cond_resched(); page = follow_page(vma, addr, - FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE); + FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE | FOLL_LRU); if (IS_ERR_OR_NULL(page)) break; if (PageKsm(page)) @@ -559,7 +559,7 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item) if (!vma) goto out; - page = follow_page(vma, addr, FOLL_GET); + page = follow_page(vma, addr, FOLL_GET | FOLL_LRU); if (IS_ERR_OR_NULL(page)) goto out; if (PageAnon(page)) { @@ -2307,7 +2307,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page) while (ksm_scan.address < vma->vm_end) { if (ksm_test_exit(mm)) break; - *page = follow_page(vma, ksm_scan.address, FOLL_GET); + *page = follow_page(vma, ksm_scan.address, FOLL_GET | FOLL_LRU); if (IS_ERR_OR_NULL(*page)) { ksm_scan.address += PAGE_SIZE; cond_resched(); diff --git a/mm/madvise.c b/mm/madvise.c index 0316bbc6441b..e252635fe935 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -421,7 +421,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, continue; page = vm_normal_page(vma, addr, ptent); - if (!page) + if (!page || is_zone_device_page(page)) continue; /* @@ -639,7 +639,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, } page = vm_normal_page(vma, addr, ptent); - if (!page) + if (!page || is_zone_device_page(page)) continue; /* diff --git a/mm/memory.c b/mm/memory.c index 7a089145cad4..e18555af9024 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -624,6 +624,13 @@ struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, if (is_zero_pfn(pfn)) return NULL; if (pte_devmap(pte)) +/* + * NOTE: New uers of ZONE_DEVICE will not set pte_devmap() and will have + * refcounts incremented on their struct pages when they are inserted into + * PTEs, thus they are safe to return here. Legacy ZONE_DEVICE pages that set + * pte_devmap() do not have refcounts. Example of legacy ZONE_DEVICE is + * MEMORY_DEVICE_FS_DAX type in pmem or virtio_fs drivers. + */ return NULL; print_bad_pte(vma, addr, pte, NULL); @@ -4693,7 +4700,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) pte = pte_modify(old_pte, vma->vm_page_prot); page = vm_normal_page(vma, vmf->address, pte); - if (!page) + if (!page || is_zone_device_page(page)) goto out_map; /* TODO: handle PTE-mapped THP */ diff --git a/mm/mempolicy.c b/mm/mempolicy.c index d39b01fd52fe..abc26890fc95 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -523,7 +523,7 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr, if (!pte_present(*pte)) continue; page = vm_normal_page(vma, addr, *pte); - if (!page) + if (!page || is_zone_device_page(page)) continue; /* * vm_normal_page() filters out zero pages, but there might diff --git a/mm/migrate.c b/mm/migrate.c index 6c1ea61f39d8..0b7f74a6c88e 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1613,7 +1613,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, goto out; /* FOLL_DUMP to ignore special (like zero) pages */ - page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP); + page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP | FOLL_LRU); err = PTR_ERR(page); if (IS_ERR(page)) @@ -1804,7 +1804,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, goto set_status; /* FOLL_DUMP to ignore special (like zero) pages */ - page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP); + page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP | FOLL_LRU); err = PTR_ERR(page); if (IS_ERR(page)) diff --git a/mm/mlock.c b/mm/mlock.c index 716caf851043..b14e929084cc 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -333,7 +333,7 @@ static int mlock_pte_range(pmd_t *pmd, unsigned long addr, if (!pte_present(*pte)) continue; page = vm_normal_page(vma, addr, *pte); - if (!page) + if (!page || is_zone_device_page(page)) continue; if (PageTransCompound(page)) continue; diff --git a/mm/mprotect.c b/mm/mprotect.c index ba5592655ee3..e034aae2a98b 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -95,7 +95,7 @@ static unsigned long change_pte_range(struct mmu_gather *tlb, continue; page = vm_normal_page(vma, addr, oldpte); - if (!page || PageKsm(page)) + if (!page || is_zone_device_page(page) || PageKsm(page)) continue; /* Also skip shared copy-on-write pages */ From patchwork Tue Jun 28 00:14:43 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: 12897308 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 D52E0C433EF for ; Tue, 28 Jun 2022 00:15:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF2108E0005; Mon, 27 Jun 2022 20:15:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3C398E000A; Mon, 27 Jun 2022 20:15:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 804F68E0005; Mon, 27 Jun 2022 20:15:29 -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 4A9138E0005 for ; Mon, 27 Jun 2022 20:15:29 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 22F793410D for ; Tue, 28 Jun 2022 00:15:29 +0000 (UTC) X-FDA: 79625725578.14.031D8DB Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2056.outbound.protection.outlook.com [40.107.94.56]) by imf16.hostedemail.com (Postfix) with ESMTP id 70CE0180048 for ; Tue, 28 Jun 2022 00:15:28 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LJmWxqYnkbugdzvbUmgtA4Jul8GpXyMG+6JKZholdijS1FxV++KHFybIV1kXUbyZcT3fP8m5giMgUOdPadNdcfnK1pYl8aTXZ4HJ8U6xnSzEBWO/fO/oMSF09Udldzg/WeZ3Aoyco48oq3jG9DpqsX7r5J4eH00M2bBiDBOhAW2QRLaFsP08z9jtiw33/wkLbS5NvAVgpaCCV7KIGktsSeKudvSPCtezYkwoC27aTfSZidPKiVPitomCR6HGJYswy0NaxjPATHKwgHuC+I7RUwbLkh6XiS5qT5Ckx8A0gmgA5nlLArLb/CkboOm+uxI/s7Mhd0GJv9RIVODFrhsosA== 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=UicCErbq5JQ9LDUgL3w5jd5oyfd14KPY9LWn5iUhKABOf8A2Ew/mClZJFPQZAlN9SrDEEz9mrOnFxwCO8FeyD5bHHd26skNvZZMgJanNgr/te+R5UUdtcl8mXNBEahuUJ5u+koLJvdLdCJvgI1qSCEoHSaalZlFu9E1URCelAxVBDFehCGuWiksJhRkqtuITcObMSr1Z1HaMM5h5+2GAHx8kWyZtZjaHrc6/CB9GZXrke6+t9YKcRmjjowOX66935rAVlyTkHO3uJXZDt1hU9cl4tSKE1GC+myYB/7OoKRqHlziIpKLBJOOAMYHZ5KpKFT2R+4u6PuBq1iRQRZOkZg== 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=qrjM2r7rjaWcAd6iDxh8RVACGrlw+jZcT7ziuQ0wJxMtIXi0zlvmrPnq26RWlNfu/6B8CJtpuwe+9tH7Jz9OVKtBXIHahrFFMwggGkR4vUj0IUb9qJaQigj1QL80RnbXmAr1ZCj+Wz1fUBci5Nm2SNXwjwJ38mLvzzU+LktHiyo= Received: from MWHPR15CA0062.namprd15.prod.outlook.com (2603:10b6:301:4c::24) by PH7PR12MB5951.namprd12.prod.outlook.com (2603:10b6:510:1da::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16; Tue, 28 Jun 2022 00:15:23 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::f4) by MWHPR15CA0062.outlook.office365.com (2603:10b6:301:4c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.21 via Frontend Transport; Tue, 28 Jun 2022 00:15:23 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:22 +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; Mon, 27 Jun 2022 19:15:20 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 03/14] mm: add device coherent vma selection for memory migration Date: Mon, 27 Jun 2022 19:14:43 -0500 Message-ID: <20220628001454.3503-4-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: b5ffa500-ca13-4826-641c-08da589b4b31 X-MS-TrafficTypeDiagnostic: PH7PR12MB5951:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IZ4PBMWihroTxDyEouPSwgLVWP3u/e90ABhz7W0+/TK2ZIo7SThhhD4xjMbAE/BFmsKjOL6WKqzVJtHVZpVj8oM+eaLfV/sME1yugiCbKW25/PyYzT/Z4Mqe3UE1KeNX254NYmsnZjAmDjJw0kD+14N9ORg7dFK70+Fy40OdKx2yJx7TEX1i5uaTFoVTLj5e72fwO8sE/qluRG24FBeMxcBn2Crakf1z0fZesp2/wBvE788Q4qQxbt7F4rWNlAkuXABsOm3cQ2MV59j9JV5sXyL1OfEKiF2ux8rX4iXiGbR/gKblxx5f14K5oasQh0NAb1BSK3sDOwitMWzRc6g3dDxOVYUvx6FXMnLORjNSGsfEM7srTgQz3GJSb1fp3R2mvC6Lca3iR4MCsxA4IWSLiruGmU5BtlcFmHulNq4+zFOg0yJIyXEffvll8j/Nw4F8tnbQigDKV7XdWm8/Nnm7KmAjhhElqDKmfSHtMHk28h94icbbKk72Grh2n4QyXHiQkDJowzqIde4tTx5K9sggfL/vK3/ZqxwY9vxWDBsZtf7qK10q+qKpN/fVzSGz/j5rcKDaw7yYfDBLre6P+jTdaLkU8XM5ASyRjEoxl5AgBoMHUGKHVytKzY3rkB3dtrRp9ZsJ2FnDLu7orwpbPtXulYuIiOlnWiVUYpBX0rAArUgrIVDYC5yR6yTgkojxgkL2R8Cx2N/jQdypaxYMWLi/YQc5xV5vwnn5FXANstHg6qKrLQt/pQ+x0DD+dzaPRp2JJZ68zvP3YVMnoiXg+FSBJ2VCWpQ32lq/fk9YMthZYnTVeFt4pbqKecDtdXf5wJ6ig6W59wHpcm5mXLJka8jWWA== 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)(346002)(396003)(39860400002)(376002)(136003)(40470700004)(36840700001)(46966006)(16526019)(336012)(47076005)(4326008)(70586007)(426003)(2906002)(1076003)(8676002)(316002)(186003)(82310400005)(40460700003)(7416002)(86362001)(41300700001)(70206006)(7696005)(2616005)(26005)(5660300002)(478600001)(8936002)(44832011)(6666004)(54906003)(40480700001)(83380400001)(6916009)(82740400003)(36860700001)(81166007)(36756003)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:22.9174 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b5ffa500-ca13-4826-641c-08da589b4b31 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5951 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375328; a=rsa-sha256; cv=pass; b=o5anChdfOF3s38+BaA+MR5xM27vO6007uoKwhbJZ9JU/2407o8cch4+PQYCvjJXhPQ4eKN Jfbo46gPskBhkTFuBiaJtM4V0K6snm24JudTa8zdWS0GdU+57xzAeXVlULW+S9unhpUoj3 7akzHLJoltOArP9RhPd1kteH3yWPCuw= ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=qrjM2r7r; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf16.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.56 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656375328; 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=Tsm1npeQJz5adlkprwdiF30iBrFOX7mFKo901b9QP1o=; b=3RpINTOj2hABUbfmnCgVEwFqTVH1dzPCkT1/r8clgpA2nQjxLEh5GbLmpaS9tV41oaQhPL YrQku8WvBd01q2CfWIBmLwDuB7gtmorimSO8UHeEKudaPmgN67kdTTkLOr/x2pIlLEs1BT hLJZ9zRQ/vkmOeRqErv6aWB673iiJfQ= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 70CE0180048 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=qrjM2r7r; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf16.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.56 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: X-Stat-Signature: fdegjy6ki3nhzyftdo1fmwkzsbzpakp7 X-HE-Tag: 1656375328-689949 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 --- 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; } From patchwork Tue Jun 28 00:14:44 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: 12897305 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 68296CCA482 for ; Tue, 28 Jun 2022 00:15:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 411838E0006; Mon, 27 Jun 2022 20:15:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3994A8E0005; Mon, 27 Jun 2022 20:15:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23A2B8E0006; Mon, 27 Jun 2022 20:15:27 -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 0A3268E0005 for ; Mon, 27 Jun 2022 20:15:27 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DD5252116C for ; Tue, 28 Jun 2022 00:15:26 +0000 (UTC) X-FDA: 79625725452.13.0E38835 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by imf15.hostedemail.com (Postfix) with ESMTP id 56313A0020 for ; Tue, 28 Jun 2022 00:15:26 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ECxnCUevJ5EHEWP/tNTRU1uFb1AhVKXtt692WBDQbVE/Cl43Y7uF95Hm6ALLQBjIuUl7g7yhXpPNYyr8qfWi6NRBFKYXkYh3QM8WXjtlbTgBl9tJfXuqeUoPFO8qJHCFAod5j0XdQ6+h4D9zGnHvUoMTcZBeZSkxRLSQ29yIjCkXOzSo27LLE3f8RtsStXdQhgsvdHzBLZiYuwebX79fkoti9K0Bkr0JrKBn4GgrxJtO49Q106vrhMHjJCQS8ZMfKS4jibR+73P83M95KRueBgaUPNfoIq0x0IjyqA4yyg/S63bEonQyby2jL7UAQFO87E/bVPSsb2HTVo/WdmJvSw== 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=4EJHkZDbAdLVpEXXE+RGiJTJBXEdpU2pe/Diqmm86p8=; b=PMld9Tu03EJ1t8Pz0Ymup3kkjlfdNlz0XEiZ44LlNrBOQDRo9gjyfMNXHxSR3UxDp/DECNgmMOkhmmoIRBrmbdU35r1ut7IcXQFboh9qhsMw/k9XnyW7H3tr26skqYNkBLYYF6ocj4FrdcGVas1K3iBivEllR2zykT3LkOmbx7BK2i6o9AWxXmtYgks7SRzXej9mWdi7Z/jbyUBOQJvJkwqgXLyu3MaJZkR76JdgoCF8apgA+JSApmteahTS626JtaKDU9DZcztDQG8G0UMfjaKpPjy/m83myt1EHfKWqwWXJnGVIWFYwbXQ/ygkUqIPOu8SJGymchW3nbBQkN/s0Q== 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=4EJHkZDbAdLVpEXXE+RGiJTJBXEdpU2pe/Diqmm86p8=; b=rju4uXN/eQHXojgxg22tXznI0G4wTfLGf0MnUU0isc8F1t1tlqujJaJRcNig8jWd+doD7++4thC03Mo7EGq+e578MAiPtPc4QRV8Jp1EzKDLLHY9P5iqH+3N0vsIBJo1nc8zvwBWr1uKP+vobxIypBvdvUONF/YNu7lO8k10WdE= Received: from MWHPR15CA0051.namprd15.prod.outlook.com (2603:10b6:301:4c::13) by DS7PR12MB5933.namprd12.prod.outlook.com (2603:10b6:8:7c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.18; Tue, 28 Jun 2022 00:15:24 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::5e) by MWHPR15CA0051.outlook.office365.com (2603:10b6:301:4c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.21 via Frontend Transport; Tue, 28 Jun 2022 00:15:24 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:23 +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; Mon, 27 Jun 2022 19:15:21 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 04/14] mm: remove the vma check in migrate_vma_setup() Date: Mon, 27 Jun 2022 19:14:44 -0500 Message-ID: <20220628001454.3503-5-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: 2795fad9-0fac-462b-a9db-08da589b4bbb X-MS-TrafficTypeDiagnostic: DS7PR12MB5933:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: staTyeIixwAZnINmxZQ6SP0NwdsFniCsictnGBX5mQHoYsqMkhS4ixSdog9iXdHA5/xGZU8yTio2+ZBUzgcxoHECAiLsMWX9ZP8/BlNFN0LdGEWR64qMoQPSpF7YdIrFe9pMoHZ/OwEHCiT2kAWb8GKw7B+fHDtEd8FY9rQXddam71Fe4QBDn6LCYx1rHEbJ71fObD06umaATtG/b0uU0MOcx6wEOUlrhfax9ksZ5yundIVmk4AZ56SGutrPCszOLNUAU/fOUBcEALbtR3XPrjIZrbD9kfzuTY+NqM1zPKcnPuE4emvpOk/qZawEEoOtuVckKONoLG7Bu84gCspgEWP4VRVdG1704ooHLrpwT6j/NXGwpUNt1ADeI4EPsEMXxDO5nORNxOl2rxlg20Ufxe6hFbH30SSpbLYS4bkt/Zj9UL8UZvoZ4H/xCnCAPuNe6IV2sVx3Ecc2JoSiCW9ycxy+h38JYHWNeetvZVg4ivfIPUTx+3K0ti+QR1pqsOFooadQNijVEiMaeXymcu9Zuc6iCWKacycv2A40NDgv4DvHg0qscgczERnisd9cZ7f/Pe0BftQUKe1CRbs8uCmwA88vGDQKcQE+44fAbKTJ7BBBQ8B8UQgIZGrwG9JVI6AwQD52rstsRTo1oCAUVidAuYFbakwNspC3h+Huf1urEcCt+NQjX8p85UYpYR72d4/r3iYJyh1IYalhC8uH3TmOi6wYqDHbQFz4gBQzAZN/DLTJIzWAcGjiWrdOlVCbRSDFHVI8rRXyteX6ZObQ/HjS13GPBvR010cWj34W8b0i2GoANsCrPrSi4+jdDOlenWIU47sFKIIi1afU24WLyRqTUQ== 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)(39860400002)(376002)(136003)(346002)(396003)(46966006)(40470700004)(36840700001)(356005)(81166007)(1076003)(16526019)(6916009)(82310400005)(186003)(316002)(2616005)(40480700001)(5660300002)(426003)(36756003)(7416002)(47076005)(54906003)(336012)(83380400001)(86362001)(70206006)(40460700003)(2906002)(36860700001)(8676002)(26005)(44832011)(7696005)(41300700001)(4326008)(82740400003)(70586007)(8936002)(6666004)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:23.8236 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2795fad9-0fac-462b-a9db-08da589b4bbb 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5933 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375326; a=rsa-sha256; cv=pass; b=7y+CMtSqQbB023khPMpFrKowK1SGmE52+hMhB6NsREx0O1elaausJxLCbe3mzRYwU+tW7E VybjmgjX3qcMP3t8atOeYOn6iH2TESzD+ayeKh811eIA4VW8uLfkD5k4KZZag6HEaHtHh8 011JZmY8RXEGMEIth8RYixMqX5Naub8= ARC-Authentication-Results: i=2; imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="rju4uXN/"; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf15.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.40 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=1656375326; 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=4EJHkZDbAdLVpEXXE+RGiJTJBXEdpU2pe/Diqmm86p8=; b=YSGjPJDKfDLaSppagcB4+43BbElIaIsh1PMpon8Z4Vk5NK8OC0l2V2NqSHbZY0rDq4cKCd cj7fGbmVyOvPoz/ua7x4xH0i5pru6Wj1cwcumpuAPUFZ/AfhA2mq3Z3M5EfPlnDjvxwAc6 ZbMW6eit48wYqNk1dmrEoXOrkbvnvug= X-Stat-Signature: kqaf8c655erxf1jd46iotzoirrjcsuyf X-Rspamd-Queue-Id: 56313A0020 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="rju4uXN/"; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf15.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.40 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1656375326-326854 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: From: Alistair Popple migrate_vma_setup() checks that a valid vma is passed so that the page tables can be walked to find the pfns associated with a given address range. However in some cases the pfns are already known, such as when migrating device coherent pages during pin_user_pages() meaning a valid vma isn't required. Signed-off-by: Alistair Popple Acked-by: Felix Kuehling Signed-off-by: Christoph Hellwig --- mm/migrate_device.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 18bc6483f63a..cf9668376c5a 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -486,24 +486,24 @@ int migrate_vma_setup(struct migrate_vma *args) args->start &= PAGE_MASK; args->end &= PAGE_MASK; - if (!args->vma || is_vm_hugetlb_page(args->vma) || - (args->vma->vm_flags & VM_SPECIAL) || vma_is_dax(args->vma)) - return -EINVAL; - if (nr_pages <= 0) - return -EINVAL; - if (args->start < args->vma->vm_start || - args->start >= args->vma->vm_end) - return -EINVAL; - if (args->end <= args->vma->vm_start || args->end > args->vma->vm_end) - return -EINVAL; if (!args->src || !args->dst) return -EINVAL; - - memset(args->src, 0, sizeof(*args->src) * nr_pages); - args->cpages = 0; - args->npages = 0; - - migrate_vma_collect(args); + if (args->vma) { + if (is_vm_hugetlb_page(args->vma) || + (args->vma->vm_flags & VM_SPECIAL) || vma_is_dax(args->vma)) + return -EINVAL; + if (args->start < args->vma->vm_start || + args->start >= args->vma->vm_end) + return -EINVAL; + if (args->end <= args->vma->vm_start || + args->end > args->vma->vm_end) + return -EINVAL; + memset(args->src, 0, sizeof(*args->src) * nr_pages); + args->cpages = 0; + args->npages = 0; + + migrate_vma_collect(args); + } if (args->cpages) migrate_vma_unmap(args); @@ -685,7 +685,7 @@ void migrate_vma_pages(struct migrate_vma *migrate) continue; } - if (!page) { + if (!page && migrate->vma) { if (!(migrate->src[i] & MIGRATE_PFN_MIGRATE)) continue; if (!notified) { From patchwork Tue Jun 28 00:14:45 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: 12897306 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 E7D1DCCA483 for ; Tue, 28 Jun 2022 00:15:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DE6E8E0007; Mon, 27 Jun 2022 20:15:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 942728E0005; Mon, 27 Jun 2022 20:15:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76D6F8E0007; Mon, 27 Jun 2022 20:15: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 5D6F68E0005 for ; Mon, 27 Jun 2022 20:15:28 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 37EB120F29 for ; Tue, 28 Jun 2022 00:15:28 +0000 (UTC) X-FDA: 79625725536.04.2955771 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2086.outbound.protection.outlook.com [40.107.93.86]) by imf29.hostedemail.com (Postfix) with ESMTP id 6DB34120027 for ; Tue, 28 Jun 2022 00:15:27 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oEnkM0xOgeY/hbvaeJIVgqd4Ue9w/yL6irrrs3gAUNM9fMMsZGGkl0i7ovX6eNt0riYbs7BcS8/Zj+fhn5p3wCFWSbF9eg45MPIKB4yknakPsEXppUqEg71kLwgx4aXD73ZkQmHIyQkN4xxOaHC+B0D2pcF5rwcxgAP+tg/VOc+4SVL4W/lDMlt5KrMsUQtvPCC7xiU1QVJSk7gOXX8HKTPkdcOp6oQvO0nf0YV1BCdJ2IsunfKdks1r2c07iQGIF0Bp216+ExkNK+eC70ZeLISswWR2XkH2IsIzCs1CNFSz/PDN7DJjFSOO3v03IHjj3KFxSID7jeC189GPLUfdvA== 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=F48ZVvqhlm2XwBwJbDJOT+M2fGXCuMlUauIgbpjkrV8=; b=kLCdtOSEFkSNh/SA3MQfXva/bLip/ZFr/K8lDJCXjVeWsfbu/ZFGYLhhLPf+KB82uFeXVyne+rEjUxLKO23cpdsucdDBAl4b0CfY4rW8y0NaLJwmw2T1uIfI0+RPm417QnG2dA9KgEDOtFi+pQO2zYLWAwfi0r2QwGLTTPa2VtdntBiwu60HF3/Ik+bMro04+F2t8anaj1LBdNOOpeSWNuwcgoL0X2Nsdj0D8Hxkca0cmjIa2jeg8y6vD6HfUEJYMpiAG34G22mgyOxbXkxSE983dhfjfIeuSP1ZTO1hS4QxZZtYnBrN42rmrslnzZY2N+aEnvVGvX8wnyMCMx9Qag== 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=F48ZVvqhlm2XwBwJbDJOT+M2fGXCuMlUauIgbpjkrV8=; b=G6mnHIZ5AFBbwSrwZY/yNaQ0ZX1tqvrOgNRadgIinq+ke/C2HhNDdO+JmJrXx5SFFd8eWckGGUdwh+y/+FlC6uN1yRnAd5uN2+iD0KK+lHqI2/ql2z1HiflN9U3kt4jilJQhs8E/digutG1lDyT8J0yyN+/Kug/p/tnNvNt7ROc= Received: from MWHPR15CA0069.namprd15.prod.outlook.com (2603:10b6:301:4c::31) by CY4PR12MB1910.namprd12.prod.outlook.com (2603:10b6:903:128::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.18; Tue, 28 Jun 2022 00:15:25 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::f7) by MWHPR15CA0069.outlook.office365.com (2603:10b6:301:4c::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.21 via Frontend Transport; Tue, 28 Jun 2022 00:15:24 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:24 +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; Mon, 27 Jun 2022 19:15:22 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 05/14] mm/gup: migrate device coherent pages when pinning instead of failing Date: Mon, 27 Jun 2022 19:14:45 -0500 Message-ID: <20220628001454.3503-6-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: 7db7243b-81fb-4562-8d62-08da589b4c43 X-MS-TrafficTypeDiagnostic: CY4PR12MB1910:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2KXiGQqA7dgePJzUTlFQwOal3TnAs0em1NwORCcXFM8jqwoKDx40ZsdbYshYFax1ZhhQ0qY59E19+6QXc1w82RYJuHbpxqw8Hu7lJCmgG7AzXDZLZOJUnPqOUK3rQ7pmJ/OJKstbe1kySh8R/3jz5s+vF0MBI1v3CzQfBc5v4T51yac3SEIVkN4HR858vuK3to7cWYPRnS9wjVZza4AJBDPO8TRswRmzt/PNhq19+C0p3Q63/eDZqPhD767vzK1UDL5lGOZhixnVe1YqV7IZ+HdcpTXXGk+d3ysYlZtXNEr/BHbmuxjFv2EcMQUnhuGOKXZLAFB8vyuhlo41kxVIFNCwbD5ahRL5QRb6MypWpxvsHjpbJWoO4I49ng4M0ibLnilXc+un8KzaF5pUnmZ+pRhQTJEqYrH6FLYReckhboaxivTYV/VeilxpdJUz1Fe/QRoo1Po+MAcQTOr2nqbkG+Tq+0nS/VMvTonhl8KR2tVV28+ap5Rjy2uGLzk1LGY+z8Qu6XRNX83CysvJ6dA1zLuWkM0ELgYUieAHYliUkQEA68kD6LoX9JVE2+p5IDyv3ViRh/z9jAUQu1XVT4Oi1pl1U/4cL06Z/crA2iC6FDUQrMAKz+/EcfBMeArWDir/AJmhKls6oswrYtiop3fUgLyhLtnUsahAXh98nj2CYk9RbcLnkgu4sJ+cVkH8Yx8jv5cV4pXUkGIkCVNqT0md4uUKiXAEVy9IsNLjo6G3a6y8NgJsQ8fpgWxCADCm33IFqC3zoPqQNE2fQ1lkFm8NxXGCILYsQ7IVKBb9ejqzhBlOuz1rVZYYggRUMRz/ua1PrxCZObYY54nVuR/uZfGswA== 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)(346002)(376002)(396003)(39860400002)(36840700001)(40470700004)(46966006)(6916009)(70206006)(82740400003)(86362001)(8676002)(40480700001)(5660300002)(4326008)(7416002)(356005)(70586007)(8936002)(54906003)(81166007)(36756003)(36860700001)(26005)(478600001)(82310400005)(336012)(6666004)(41300700001)(83380400001)(2906002)(7696005)(1076003)(2616005)(16526019)(186003)(44832011)(40460700003)(47076005)(316002)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:24.7142 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7db7243b-81fb-4562-8d62-08da589b4c43 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1910 ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=G6mnHIZ5; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf29.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.86 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656375327; 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=F48ZVvqhlm2XwBwJbDJOT+M2fGXCuMlUauIgbpjkrV8=; b=VCsJxegTQcV80i8nn6PDB4G0IEgkYaLaHQa6Fh+g/msxklGZoIjk8vXfXWztlqOcU4xmpL AQd98vbT+y7ybfSPGsJehpY+hVTfU6cCEGzvyIYt5sn4PA4JirjLEfnVRxoRS2XQLbkeXI atA36eZI5+0BUNiF5De6rW1eYO3EMjs= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375327; a=rsa-sha256; cv=pass; b=JK5n/z9acyrGa69rlMMsvSvSojpmI4QG2q0TbhoBn5b8w7Ttq9L+QWZxWLWhtrjbbqvbyx zBX9J/v8GL+mlSJjDBydgwSyv9eJKK+8xdfjtc/wD/pfyZgk0DV5kyEvhuRCaxS2qizmoX 2+sn5tMDgI5d6/LaRYYaDNm3bNTi76o= X-Stat-Signature: bygbypxfdx8etwztpp4w6cbn17u698ac X-Rspamd-Queue-Id: 6DB34120027 X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=G6mnHIZ5; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf29.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.86 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspamd-Server: rspam12 X-HE-Tag: 1656375327-740260 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: From: Alistair Popple Currently any attempts to pin a device coherent page will fail. This is because device coherent pages need to be managed by a device driver, and pinning them would prevent a driver from migrating them off the device. However this is no reason to fail pinning of these pages. These are coherent and accessible from the CPU so can be migrated just like pinning ZONE_MOVABLE pages. So instead of failing all attempts to pin them first try migrating them out of ZONE_DEVICE. Signed-off-by: Alistair Popple Acked-by: Felix Kuehling [hch: rebased to the split device memory checks, moved migrate_device_page to migrate_device.c] Signed-off-by: Christoph Hellwig --- mm/gup.c | 50 +++++++++++++++++++++++++++++++++++++----- mm/internal.h | 1 + mm/migrate_device.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 6 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 48b45bcc8501..c29a7b5fbbfd 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -133,7 +133,8 @@ struct folio *try_grab_folio(struct page *page, int refs, unsigned int flags) * path. */ if (unlikely((flags & FOLL_LONGTERM) && - !is_pinnable_page(page))) + (!is_pinnable_page(page) || + is_device_coherent_page(page)))) return NULL; /* @@ -1895,9 +1896,43 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, continue; prev_folio = folio; - if (folio_is_pinnable(folio)) + /* + * Device private pages will get faulted in during gup so it + * shouldn't be possible to see one here. + */ + if (WARN_ON_ONCE(folio_is_device_private(folio))) { + ret = -EFAULT; + goto unpin_pages; + } + + /* + * Device coherent pages are managed by a driver and should not + * be pinned indefinitely as it prevents the driver moving the + * page. So when trying to pin with FOLL_LONGTERM instead try + * to migrate the page out of device memory. + */ + if (folio_is_device_coherent(folio)) { + WARN_ON_ONCE(PageCompound(&folio->page)); + + /* + * Migration will fail if the page is pinned, so convert + * the pin on the source page to a normal reference. + */ + if (gup_flags & FOLL_PIN) { + get_page(&folio->page); + unpin_user_page(&folio->page); + } + + pages[i] = migrate_device_page(&folio->page, gup_flags); + if (!pages[i]) { + ret = -EBUSY; + goto unpin_pages; + } continue; + } + if (folio_is_pinnable(folio)) + continue; /* * Try to move out any movable page before pinning the range. */ @@ -1933,10 +1968,13 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, return nr_pages; unpin_pages: - if (gup_flags & FOLL_PIN) { - unpin_user_pages(pages, nr_pages); - } else { - for (i = 0; i < nr_pages; i++) + for (i = 0; i < nr_pages; i++) { + if (!pages[i]) + continue; + + if (gup_flags & FOLL_PIN) + unpin_user_page(pages[i]); + else put_page(pages[i]); } diff --git a/mm/internal.h b/mm/internal.h index c0f8fbe0445b..eeab4ee7a4a3 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -853,6 +853,7 @@ int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, unsigned long addr, int page_nid, int *flags); void free_zone_device_page(struct page *page); +struct page *migrate_device_page(struct page *page, unsigned int gup_flags); /* * mm/gup.c diff --git a/mm/migrate_device.c b/mm/migrate_device.c index cf9668376c5a..5decd26dd551 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -794,3 +794,56 @@ void migrate_vma_finalize(struct migrate_vma *migrate) } } EXPORT_SYMBOL(migrate_vma_finalize); + +/* + * Migrate a device coherent page back to normal memory. The caller should have + * a reference on page which will be copied to the new page if migration is + * successful or dropped on failure. + */ +struct page *migrate_device_page(struct page *page, unsigned int gup_flags) +{ + unsigned long src_pfn, dst_pfn = 0; + struct migrate_vma args; + struct page *dpage; + + lock_page(page); + src_pfn = migrate_pfn(page_to_pfn(page)) | MIGRATE_PFN_MIGRATE; + args.src = &src_pfn; + args.dst = &dst_pfn; + args.cpages = 1; + args.npages = 1; + args.vma = NULL; + migrate_vma_setup(&args); + if (!(src_pfn & MIGRATE_PFN_MIGRATE)) + return NULL; + + dpage = alloc_pages(GFP_USER | __GFP_NOWARN, 0); + + /* + * get/pin the new page now so we don't have to retry gup after + * migrating. We already have a reference so this should never fail. + */ + if (dpage && WARN_ON_ONCE(!try_grab_page(dpage, gup_flags))) { + __free_pages(dpage, 0); + dpage = NULL; + } + + if (dpage) { + lock_page(dpage); + dst_pfn = migrate_pfn(page_to_pfn(dpage)); + } + + migrate_vma_pages(&args); + if (src_pfn & MIGRATE_PFN_MIGRATE) + copy_highpage(dpage, page); + migrate_vma_finalize(&args); + if (dpage && !(src_pfn & MIGRATE_PFN_MIGRATE)) { + if (gup_flags & FOLL_PIN) + unpin_user_page(dpage); + else + put_page(dpage); + dpage = NULL; + } + + return dpage; +} From patchwork Tue Jun 28 00:14:46 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: 12897307 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 80CF4C43334 for ; Tue, 28 Jun 2022 00:15:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9903F8E0009; Mon, 27 Jun 2022 20:15:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F0548E0008; Mon, 27 Jun 2022 20:15:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CF838E0009; Mon, 27 Jun 2022 20:15:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 531548E0008 for ; Mon, 27 Jun 2022 20:15:29 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 28783603E0 for ; Tue, 28 Jun 2022 00:15:29 +0000 (UTC) X-FDA: 79625725578.12.958A615 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2052.outbound.protection.outlook.com [40.107.95.52]) by imf31.hostedemail.com (Postfix) with ESMTP id A84D720018 for ; Tue, 28 Jun 2022 00:15:28 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BD2EQOcjfcS8lK/SsKTwyY2tYKtELO+gdLHjyqPKx3e/jtF50bV+qyTbmRqqNI1PZuFTC+C1mnDnzcJSa6jp5GJQryBJgkgLm7ZDdyKosmKlPkGErinv5TWDnThLWz4+cetBg/QbdxJYURhoQckfq54F+LB/ywwxAVgsJq7Wu5fl9R2unnLUPEwpDg7JvX5u5tjj71g8iP0XMbAKzStCiMrBGb3jHwysjg+V2GIYcaf6R2gV+xIH4BHD37EoA06KkF83sqPD9BEo5taPIWPqDEFhEgfYu55CopOEMZba9+AWnpK82pTdp3ermq6PgMO+KO4H8vuD3KkvfcGghrX9zw== 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=lOc606mfE+GTytdQbIdWily1XFcltRIawMZTJWDA8VM=; b=WM3sNLWrpXgvH3IRMnTsskjSUBF5J7V3QGqzlRM9tPV5xWDA4jf9uMaDirE0BMLiIq5AK1XCnD/rllUJgkwTQVd6Igcgu0TDG1j+yojssDWNdo4P70PaNxX/UQfBXCjdzkm1pRN47IgorE2emwYNicqX9m5+NFa3EoiZj4gfbz2qn+qyjd7NrYRuMiUfA9r50jjFi7iYj0HjqfNKzbPYtw8IKb7YqWqD+OH5ksIM/p5SwjQrw8JQukoNBZN6vxohkhH2yviXotOHKs1chM5Kv1rjn5MXddaqthpNHRxjhXy2e6X/nSaiRLWBtSCFvo3zL7DWh5rNVcGeyVd805md6w== 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=lOc606mfE+GTytdQbIdWily1XFcltRIawMZTJWDA8VM=; b=uLGB7Sgr+3/FiBtGe1XlinL2uqhInwwb/LgZ5OwrYCOKzG1+BGB29aGMLP0M480j3wiYeIRflV36rykle7DBNtRk1CBzJX3X0cmMX69/B8BcuobrYOzF9nz4zG7s0N3x0+CWTrD9tdw58AkUOP+hnCfWCs5rHzrMhL7up9tPP0o= Received: from MW4PR03CA0175.namprd03.prod.outlook.com (2603:10b6:303:8d::30) by BN6PR12MB1939.namprd12.prod.outlook.com (2603:10b6:404:107::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15; Tue, 28 Jun 2022 00:15:26 +0000 Received: from CO1NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8d:cafe::e7) by MW4PR03CA0175.outlook.office365.com (2603:10b6:303:8d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17 via Frontend Transport; Tue, 28 Jun 2022 00:15:26 +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 CO1NAM11FT057.mail.protection.outlook.com (10.13.174.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:25 +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; Mon, 27 Jun 2022 19:15:23 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 06/14] mm: add device coherent checker to is_pinnable_page Date: Mon, 27 Jun 2022 19:14:46 -0500 Message-ID: <20220628001454.3503-7-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: 28e050aa-050a-4656-c2ad-08da589b4cec X-MS-TrafficTypeDiagnostic: BN6PR12MB1939:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fHZjme3QrUcv8uzFpdg09GbLsXhCf8XpwTTGz+lSfL5mBDMfbiJziO9+gJ9kQu91U8WXFlNDphnL48xvIYQ7Q9TJWpGYvNv8woAOwyDWuxKLiJ7XhnwYfAuB/NkCP+Hm5zy/oIaBy+9kHeWg+EmmZw76Tix81sjnAERo2Lc4OtfnA1VWAYzk8eFhTi+P9ns0RgJtPneZs0ojJRKwiLQSC9VtC5NfKpYYUVlB5ApfC49/eGAwZaFpFUGW+SUj4PM3yNU+iC5njnLh1QDIdXVBvL1Cn5CnHaktFvqQMILHIsGhXekqiL8HaV1TXh93hRYW6BMmcvjpDQHxUDGT5eThKz9PXg16Vxf35h8gXU8fwDN9udzjcMCyel6TMrxaX69qh3r4NTG7yH3pLRHLmvU0xzCCxsqvqIS14ma2VLZDJxk/0qp4ecAvYnZZ157KhQ0Skp1jslft0+zNNpz9XVArSLGjapQeZRWc5533rNm9fwzoY0vl03IxS3nP8+SA3Y4X057/5MjVB0rqMDXHg5FuS7boD/6VBb07Pi6Gd8BXc36/UNuqjOPn5QRlzTk+hNSerjs+G/kGvCMUH5i1EJrwmUfTZxiPRTK0+9YRVONy1qFmGLosVBfiSDM9BrilI6cT1uTOSAwlpn56xD1BF5gEy0LDXkmYxZX6LUhINYHM6B1L6cXHyI6mfAFYp1wFMJBJvdcfo4/Ua2Ip2CHBZgkxIguCLxzvD4nMPfEZf/qqP3sMkUEb0J7wNVkmDq9JYbrQZkRnB/IrQ0yNl7BpumNQ4pXyCl+R8qDHqnr24shvkt0YbziiKaF3z14Uw1mTGeWwXiDXtcal7A9TDz0Qy0hlKw== 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)(346002)(376002)(396003)(39860400002)(136003)(40470700004)(46966006)(36840700001)(426003)(336012)(6916009)(2906002)(47076005)(36756003)(54906003)(316002)(36860700001)(2616005)(16526019)(4326008)(40480700001)(40460700003)(478600001)(83380400001)(1076003)(6666004)(70586007)(8936002)(186003)(70206006)(8676002)(41300700001)(86362001)(5660300002)(7416002)(81166007)(26005)(82740400003)(82310400005)(7696005)(44832011)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:25.8387 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 28e050aa-050a-4656-c2ad-08da589b4cec 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: CO1NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1939 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375328; a=rsa-sha256; cv=pass; b=HPn6splIdWBTQUphYriuQzKdL8H9102TzVw5X+y8HNs5FYgm66ZfvARbJSPqqWUJ+mslsH yulG6NgqRa64d2jAidQUSim8FysmqNS03JQRvyQ0NKaK/IpfGfkQfXerlN57wWJ/2b5UIX 7LxM+tdqTm2PnHB4L+jcGppQox4qh3c= ARC-Authentication-Results: i=2; imf31.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=uLGB7Sgr; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf31.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.95.52 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656375328; 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=lOc606mfE+GTytdQbIdWily1XFcltRIawMZTJWDA8VM=; b=minXpgI7goAmpa/kUrHf/Z+7Jx9OO034BULSK4JgGucNbsCxeHSxQro6mGyaXEAJJblvMO 9JcJ7V6BMHg6NksLbedmfPRYHsv2afprdv6IsZaHs5Jnpf5Bb+Wa+TDL/ygLC/cKBbjwOz 27Xe95IanTQCfrwUkYeVF73G4WbWy1o= X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=uLGB7Sgr; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf31.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.95.52 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam02 X-Stat-Signature: zxoxfb9psx55eutr4gtuw1ihmk9pmcch X-Rspamd-Queue-Id: A84D720018 X-HE-Tag: 1656375328-924793 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: is_device_coherent checker was added to is_pinnable_page and renamed to is_longterm_pinnable_page. The reason is that device coherent pages are not supported for longterm pinning. Signed-off-by: Alex Sierra --- include/linux/memremap.h | 25 +++++++++++++++++++++++++ include/linux/mm.h | 24 ------------------------ mm/gup.c | 5 ++--- mm/gup_test.c | 4 ++-- mm/hugetlb.c | 2 +- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 9f752ebed613..6fc0ced64b2d 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -169,6 +169,31 @@ static inline bool is_pci_p2pdma_page(const struct page *page) page->pgmap->type == MEMORY_DEVICE_PCI_P2PDMA; } +/* MIGRATE_CMA and ZONE_MOVABLE do not allow pin pages */ +#ifdef CONFIG_MIGRATION +static inline bool is_longterm_pinnable_page(struct page *page) +{ +#ifdef CONFIG_CMA + int mt = get_pageblock_migratetype(page); + + if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE) + return false; +#endif + return !(is_device_coherent_page(page) || + is_zone_movable_page(page) || + is_zero_pfn(page_to_pfn(page))); +} +#else +static inline bool is_longterm_pinnable_page(struct page *page) +{ + return true; +} +#endif +static inline bool folio_is_longterm_pinnable(struct folio *folio) +{ + return is_longterm_pinnable_page(&folio->page); +} + #ifdef CONFIG_ZONE_DEVICE void *memremap_pages(struct dev_pagemap *pgmap, int nid); void memunmap_pages(struct dev_pagemap *pgmap); diff --git a/include/linux/mm.h b/include/linux/mm.h index f6f5d48c1934..b91a4a1f260b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1590,30 +1590,6 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma, return page_maybe_dma_pinned(page); } -/* MIGRATE_CMA and ZONE_MOVABLE do not allow pin pages */ -#ifdef CONFIG_MIGRATION -static inline bool is_pinnable_page(struct page *page) -{ -#ifdef CONFIG_CMA - int mt = get_pageblock_migratetype(page); - - if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE) - return false; -#endif - return !is_zone_movable_page(page) || is_zero_pfn(page_to_pfn(page)); -} -#else -static inline bool is_pinnable_page(struct page *page) -{ - return true; -} -#endif - -static inline bool folio_is_pinnable(struct folio *folio) -{ - return is_pinnable_page(&folio->page); -} - static inline void set_page_zone(struct page *page, enum zone_type zone) { page->flags &= ~(ZONES_MASK << ZONES_PGSHIFT); diff --git a/mm/gup.c b/mm/gup.c index c29a7b5fbbfd..ada73b775a82 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -133,8 +133,7 @@ struct folio *try_grab_folio(struct page *page, int refs, unsigned int flags) * path. */ if (unlikely((flags & FOLL_LONGTERM) && - (!is_pinnable_page(page) || - is_device_coherent_page(page)))) + !is_longterm_pinnable_page(page))) return NULL; /* @@ -1931,7 +1930,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, continue; } - if (folio_is_pinnable(folio)) + if (folio_is_longterm_pinnable(folio)) continue; /* * Try to move out any movable page before pinning the range. diff --git a/mm/gup_test.c b/mm/gup_test.c index d974dec19e1c..9d705ba6737e 100644 --- a/mm/gup_test.c +++ b/mm/gup_test.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -53,7 +53,7 @@ static void verify_dma_pinned(unsigned int cmd, struct page **pages, dump_page(page, "gup_test failure"); break; } else if (cmd == PIN_LONGTERM_BENCHMARK && - WARN(!is_pinnable_page(page), + WARN(!is_longterm_pinnable_page(page), "pages[%lu] is NOT pinnable but pinned\n", i)) { dump_page(page, "gup_test failure"); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a57e1be41401..368fd33787b0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1135,7 +1135,7 @@ static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid) lockdep_assert_held(&hugetlb_lock); list_for_each_entry(page, &h->hugepage_freelists[nid], lru) { - if (pin && !is_pinnable_page(page)) + if (pin && !is_longterm_pinnable_page(page)) continue; if (PageHWPoison(page)) From patchwork Tue Jun 28 00:14:47 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: 12897309 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 498ACC43334 for ; Tue, 28 Jun 2022 00:15:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 151A98E000A; Mon, 27 Jun 2022 20:15:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 101F58E0008; Mon, 27 Jun 2022 20:15:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0CE68E000A; Mon, 27 Jun 2022 20:15:29 -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 D6FF18E0008 for ; Mon, 27 Jun 2022 20:15:29 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B223C603E0 for ; Tue, 28 Jun 2022 00:15:29 +0000 (UTC) X-FDA: 79625725578.15.094EC32 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2071.outbound.protection.outlook.com [40.107.212.71]) by imf30.hostedemail.com (Postfix) with ESMTP id 0391D80002 for ; Tue, 28 Jun 2022 00:15:28 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lgqoyZ0/TS5qPnTCyYsHkk+wS0pZ+KHaRgsclJaKg20iuoosmQo5lwn3ypz0QZ/ODfLZbQmSmaUk1P1N/nbFi4HZuTq0RauzQX/+GtzIZd6UG6bq5a+PypJRj6lgDvJ1ETj/RJS5Wmm5rNZevxsy19gjr552RNosklTbH7P/PCzRNWEwLCF0T7Zo97Tb4zw590Ps6dgD/a+u6UjC55NV4tgFwhj1z5sx9sBO73MYpF+Ivsyrgx93cmHZrjtbPbJ2NNlab4OEWnkvtv5T9COHP+QXVs/lVeBGPsAk6zqnLROu+DHe1e4T1qbK0IN9PEV3NWE3v+YYPaOUjYxf4+byVg== 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=HCXWiNEvF3TUrQgA6hemuT7kHRIWD5ROdsIgulORq7M=; b=B2nqdXXnWT0gytKPJGjUqU3zoJQtNH5i6Rjusdcb7mHgNtxUzb0vAWK1mWU36Dm1A46PCm1WkhheJ54ULdF6LQJrQhupdpyIMv9jDn7RaA/zlZykkkB/SotnP9RevqYlRWrFs1mMNe5916Em52D6/u/pDS16zYGTLLIQylxPbZ53Kklm5F+GXeSqU8o8fnXlDBYUCMkUS4RDCxEZ/6OQN+e/Fvst2LV1AMS57E+fdLivYwi3rQjz3EbanI8VfECTOdni7ldJF4VvbqICtBLDGeBD2thqD7+J5e9cUc7X5f9VuiusSKPuJ2u1Dvh9COhzOKfAsSRysT4a8cg82632Kw== 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=HCXWiNEvF3TUrQgA6hemuT7kHRIWD5ROdsIgulORq7M=; b=MSzsgXs40NN+ZNAUAV7zmYxagt2kUeh07tGCePXh7NvL3K5jdm0IrTQAuDN+0BzfrRTglpSt1b/5kxyoYGfebTKyddClPBKyupyWJSdk91wL/x8TRoCTBqYQ76GcZP8uGhHzhXU5C9gu7zI4xOMbqmDApZeFpFLkd8viI4Weqfg= Received: from MWHPR15CA0061.namprd15.prod.outlook.com (2603:10b6:301:4c::23) by MWHPR12MB1328.namprd12.prod.outlook.com (2603:10b6:300:c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16; Tue, 28 Jun 2022 00:15:25 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::26) by MWHPR15CA0061.outlook.office365.com (2603:10b6:301:4c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.21 via Frontend Transport; Tue, 28 Jun 2022 00:15:25 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:25 +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; Mon, 27 Jun 2022 19:15:24 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 07/14] drm/amdkfd: add SPM support for SVM Date: Mon, 27 Jun 2022 19:14:47 -0500 Message-ID: <20220628001454.3503-8-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: 2c0017bb-faab-481a-5e63-08da589b4cb8 X-MS-TrafficTypeDiagnostic: MWHPR12MB1328:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6ijCzlUrFvFuNOxLh/fuHPaJPzYB+BcSKsT5H3KPm4zU83+atFWTvfWwQDYz3VTLK623ennhLfElWhkbGpyC4VpCkXEXW8P4GHme+j4TS5QI3fA2J5U0sMpIL8eQNaWA0f6H+GFn1if593JIQyT8W6ILxOv3Apbruhcm1gTtmJqpnWoH2TkVrGnPKqaerP6KJvjAzIRSE5XiQabxjp2XbtwAjwuNt1iWn7Epn3bIbKJpcA3ljDCz8nrqq3jui9CWb0wo0mT1pEf3I6gEd1k17YYSzyA2cQHS1u2K65SjsPdB/Cnr+dppdOWvHmcaHObZdP9031swaF5NJdtttBzGJRCuG9XeR+qTX/w1p6nsVo5ItFdY3LSqipXiPAHbCKp7s0k2Q++7+/LIS3YnkOmoFZgfLrmmolDf00Lzr+oVSLVK4QgnSSMHnbma0V4AS4eARB5pR8wHETwYqcJJ9i7bdiHI7Bjuxer1rJbE3hjHofeOplyimXvRg5uHj5AElLYAyJmfThdX9YpGUa82HYvzTx05jkgLP8Seye76Kalk36oBT52Bli4IwAJnahQt/UtjQQnMZ43Me0aU8/bICYcCjb980ArMWtQRvWYnxy0/BGyG4Asy+PAZNVobegaAN32H98Prswz20PCH9c+FE3LUL81EH531XSevM476xR5oFkqbzS1/0srvhcREBKVdgqwGG2LPngZmN9fr6J+1jz/zIIRB/wULpQivUDDqnK6EjfkquukY4se+4LDmT9hy75fL1bPMgbArt+6jOYfE8QH98NU/fSlUOfp7avkJF6iE0yjdQIt0IhESFKTAGoUmh8PB/bQcx7AR9aLfvvbSxu1UoQ== 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)(346002)(39860400002)(396003)(136003)(376002)(40470700004)(46966006)(36840700001)(82740400003)(7696005)(356005)(8936002)(81166007)(36756003)(5660300002)(70586007)(70206006)(83380400001)(86362001)(82310400005)(44832011)(4326008)(36860700001)(7416002)(8676002)(26005)(426003)(40460700003)(2616005)(1076003)(40480700001)(478600001)(41300700001)(54906003)(6666004)(186003)(16526019)(316002)(6916009)(336012)(2906002)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:25.4798 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2c0017bb-faab-481a-5e63-08da589b4cb8 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1328 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656375329; 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=HCXWiNEvF3TUrQgA6hemuT7kHRIWD5ROdsIgulORq7M=; b=laes6Hw2gJAw9HgVQ7pBYukbIwb0yOmUDl9WOIl1o1Qfah+qyhjo2Cx6ZVFxOgRtJ3GVMK tSOHb6nUMJNCN3cKVOULsQr70PnN2nhnFKJSNld4jp+G6DMpYno+pkUSpgoE9pLMtZ66ly FJprbqhYJS8Z0sJm+5Kc18xdXysredM= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=MSzsgXs4; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf30.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.212.71 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375329; a=rsa-sha256; cv=pass; b=wqLhhFWNiFAoNQ6tU+hZvf4tzhpaWIwukVMIYkRH7EqnJaSzl/YVrjkp3dWiZlCFpuIO+y xG97eIiUB01YTSOwx1iu3HDhHLxy5RqN9nv3Fd9cgLL2Q849EXD6YGyWIYm/P6GPJeYnJ3 pC2Xy9kbjj3AqULYKX+uFj3t9PVLuo8= X-Rspamd-Queue-Id: 0391D80002 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=MSzsgXs4; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf30.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.212.71 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: hd9qodmote8fxkdam89d8ok67fmfenkr X-HE-Tag: 1656375328-984947 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 CPU is connected throug XGMI, it has coherent access to VRAM resource. In this case that resource is taken from a table in the device gmc aperture base. This resource is used along with the device type, which could be DEVICE_PRIVATE or DEVICE_COHERENT to create the device page map region. Also, MIGRATE_VMA_SELECT_DEVICE_COHERENT flag is selected for coherent type case during migration to device. Signed-off-by: Alex Sierra Reviewed-by: Felix Kuehling Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 34 +++++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index e44376c2ecdc..f73e3e340413 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -671,13 +671,15 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.vma = vma; migrate.start = start; migrate.end = end; - migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; migrate.pgmap_owner = SVM_ADEV_PGMAP_OWNER(adev); + if (adev->gmc.xgmi.connected_to_cpu) + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_COHERENT; + else + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; buf = kvcalloc(npages, 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t), GFP_KERNEL); - if (!buf) goto out; @@ -947,7 +949,7 @@ int svm_migrate_init(struct amdgpu_device *adev) { struct kfd_dev *kfddev = adev->kfd.dev; struct dev_pagemap *pgmap; - struct resource *res; + struct resource *res = NULL; unsigned long size; void *r; @@ -962,28 +964,34 @@ int svm_migrate_init(struct amdgpu_device *adev) * should remove reserved size */ size = ALIGN(adev->gmc.real_vram_size, 2ULL << 20); - res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); - if (IS_ERR(res)) - return -ENOMEM; + if (adev->gmc.xgmi.connected_to_cpu) { + pgmap->range.start = adev->gmc.aper_base; + pgmap->range.end = adev->gmc.aper_base + adev->gmc.aper_size - 1; + pgmap->type = MEMORY_DEVICE_COHERENT; + } else { + res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); + if (IS_ERR(res)) + return -ENOMEM; + pgmap->range.start = res->start; + pgmap->range.end = res->end; + pgmap->type = MEMORY_DEVICE_PRIVATE; + } - pgmap->type = MEMORY_DEVICE_PRIVATE; pgmap->nr_range = 1; - pgmap->range.start = res->start; - pgmap->range.end = res->end; pgmap->ops = &svm_migrate_pgmap_ops; pgmap->owner = SVM_ADEV_PGMAP_OWNER(adev); - pgmap->flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; - + pgmap->flags = 0; /* Device manager releases device-specific resources, memory region and * pgmap when driver disconnects from device. */ r = devm_memremap_pages(adev->dev, pgmap); if (IS_ERR(r)) { pr_err("failed to register HMM device memory\n"); - /* Disable SVM support capability */ pgmap->type = 0; - devm_release_mem_region(adev->dev, res->start, resource_size(res)); + if (pgmap->type == MEMORY_DEVICE_PRIVATE) + devm_release_mem_region(adev->dev, res->start, + res->end - res->start + 1); return PTR_ERR(r); } From patchwork Tue Jun 28 00:14:48 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: 12897310 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 A4024CCA485 for ; Tue, 28 Jun 2022 00:15:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D4208E000B; Mon, 27 Jun 2022 20:15:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45D208E0008; Mon, 27 Jun 2022 20:15:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FB8D8E000C; Mon, 27 Jun 2022 20:15:30 -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 164438E000B for ; Mon, 27 Jun 2022 20:15:30 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E84D92116C for ; Tue, 28 Jun 2022 00:15:29 +0000 (UTC) X-FDA: 79625725578.23.F068625 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2085.outbound.protection.outlook.com [40.107.93.85]) by imf12.hostedemail.com (Postfix) with ESMTP id 6C8C040025 for ; Tue, 28 Jun 2022 00:15:29 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZZuZAA9e00hY3vr2BHvuGRvYWyng+RwfYsvmXBn4LUaedl/WjAoM0MiOfz9/yo/NQEjtgzjzfNlg0nu7w3ZpUesKlnyWabJkfGe0qo59P1yH83eFYF7mhYKMCMM7n9nnNb9/fyxm0suVzY30txeoXxZ0BSR5tPasgBTVHBlNRbhyPY6MovlGRa4mg2gb4Ja3dNdSsCwPIAHv0DU3Zno6eCx04fs4x+/znFLG5Yi/Sz4v+NgD26tY8M2ohfJFYmpumUXEkMwgvjbZlsMa2hxuSvEJFcK2AmLIjWaoaKIoKYyX+faskf6+Z/GFLaBqTf5V5E3rAkpwAQtrVjJ0djcPBg== 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=F8lzcu9Uc51zZ3prS+uZltVgKEco8VgkJ2E7O9HgaPo=; b=QfRbGa4Dg3aVWoJzzWdyraX5gkQQBWn68FFHfYA7WiK280AOuXk8kUYMmEdFrO6knP4tmYNu/eGmaycnFzE07p3JLhoiHBbjHmhjJ5NNav8PKa+RemjMW/7cHKZe5VgHW/9JzChAde6Vxh4wYMN1OwP8bjIYGHEQu/jSSbNTb2kO5Z4yHNWJPuU55qmcnWG85QmrMHkJ+3zhgqCRR6xG4b81LYofSqg0kYqwv3JJw2rgHmF1V7h9UhlEHrauzdxwKnzuvGEjnelaDabckYUNz8oEJmTXW890Thb4SDfZ3KqHw3TLUyhzxr3PCscYF16Rs2h5JzRw2X3minTu/e/mHw== 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=F8lzcu9Uc51zZ3prS+uZltVgKEco8VgkJ2E7O9HgaPo=; b=5IvYC7qGYtY4daUwOx1XchG2GGAfnp1akninHrV0PtZWYZUWcnchgYL4XSHAAGVbVpnzaCdk6EnOAacJni5Js3o3b4SWpVjPyJXk4amD2ijZhtYjFYnKIEbZZoDNqhQfuPQlVOV3YS4IYPxAlxs3vLq7Qr6TNIE2JMuV9TlmCW8= Received: from MWHPR15CA0061.namprd15.prod.outlook.com (2603:10b6:301:4c::23) by BN8PR12MB3089.namprd12.prod.outlook.com (2603:10b6:408:40::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16; Tue, 28 Jun 2022 00:15:27 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::d3) by MWHPR15CA0061.outlook.office365.com (2603:10b6:301:4c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.21 via Frontend Transport; Tue, 28 Jun 2022 00:15:26 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:26 +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; Mon, 27 Jun 2022 19:15:24 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 08/14] lib: test_hmm add ioctl to get zone device type Date: Mon, 27 Jun 2022 19:14:48 -0500 Message-ID: <20220628001454.3503-9-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: 89c87115-dc05-412c-7b3d-08da589b4d5a X-MS-TrafficTypeDiagnostic: BN8PR12MB3089:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +jcbLb/aMcJGlKuxBJeys9TkXwK8EQ3ss0l111Ydt5x7LSgdDz1sgKrqd8idimZaeJ9WdVtFoHs/mUZrFK+6hAjbVPK8U5Tx0ALT67+f+xSgJJFRawX7YuSwFQ5Bp/wXkYnvzEox1v3QUuP0X7J2hveJgKRl1uqBhml3KGQ7b8DptjlhvTY8wFbfx032lgjVySUaRzYIAEAX7snrsYtrtnkppzGmiSE33kvksP9gtFU2UdV0Ce/P9u4Rqo36JmBEuEKpAv+FlorZ5vlVLBTIx17DrXEqGtklVzeVEq6EhPBdlbnTVTsbOJaetuUKmHgSWv5uxRvpwRqUogrJaMZ9CcvO9MAszz9ThXzpvmIGSEZ+lL92wpPSr6QzfAHdx4ELwKcOmI4qvXd+OUTj4bEDBiqpyZ9dJfjC5SqrIPu+4qQK3k1tnliwVMFOhJhzJ5ZetB+/Tt60nb45Qccls68hy2eMByRtzYGmcdzeAf8tNWM2G/bP5LcTlNJKkpifjjCYsTwNXK18NawIQ17wM4SfLybGlRRoq5w/qFtg1ZExx8necK5YRhpZFhSaciVjXwA5ix84c6QykpYF+gC0J2Ry3/6j0h4Pe8/+fUenaMb2ZJXnf10xvk1w7AqvM/dFvKrZLq5akoNcCPNWgYs65X1eO07GK5xFU+0lyzFEDVuuHdsftbByxdj2lPBJSbHuIF9H2hvtm4jIafgmqMLg7P+bQc6+FkUPZHEvfxn2zIMaLGOqllbodjJVjEsjwdWnRUG6VHzn+q++iM62Ss+yibXJ1Cn8I0MeRaJ3qjgU8pqXdRvvurmRQTguc301KEGwIqA4PmpIl6aVF7qRt/1Kyv6wfw== 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)(376002)(346002)(39860400002)(396003)(46966006)(36840700001)(40470700004)(47076005)(5660300002)(26005)(2616005)(16526019)(7416002)(54906003)(70206006)(336012)(1076003)(82310400005)(186003)(426003)(36860700001)(6916009)(8676002)(2906002)(41300700001)(83380400001)(40480700001)(8936002)(44832011)(86362001)(316002)(6666004)(36756003)(70586007)(356005)(82740400003)(40460700003)(478600001)(4326008)(7696005)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:26.5422 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89c87115-dc05-412c-7b3d-08da589b4d5a 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3089 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656375329; 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=F8lzcu9Uc51zZ3prS+uZltVgKEco8VgkJ2E7O9HgaPo=; b=LI0injjbrdSgjxhNNcNBSmRZGt1FILVZH2MkGAkZZT34cdOKusi5n/nOlCwD2UErBAyVHs jDn/tyvZVe71UE2HeCPF1hyrNmOu8g9Z4lCgS2CB7v6k3n7oXYnb3j0Cfm3swOetTSGxwy kuiClOwlBqmpaBpWGStqXn5iaqQ1GYw= ARC-Authentication-Results: i=2; imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=5IvYC7qG; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf12.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.85 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375329; a=rsa-sha256; cv=pass; b=d1ViHaADih9gXeChs2gFsgn++VyZOP5HcKhpySIBqf/l3oLJWOPsxo7HSaSSFB/VqmcGw3 AhNRqguu66wDNvnJfo3T4BWtcrxJzExFHqFCPPgJALmUF1PXIFsKAzjn4Jn+XKae9pLsxK 3UmCq0Nw1ucdX/HZEoFhKwQVR1Em2es= X-Rspamd-Queue-Id: 6C8C040025 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=5IvYC7qG; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf12.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.85 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: zryr8qgh8geerr98kw3rz3hjmarg8tpb X-HE-Tag: 1656375329-779669 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: new ioctl cmd added to query zone device type. This will be used once the test_hmm adds zone device coherent type. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Poppple Signed-off-by: Christoph Hellwig --- lib/test_hmm.c | 11 +++++++++-- lib/test_hmm_uapi.h | 14 ++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index cfe632047839..915ef6b5b0d4 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -87,6 +87,7 @@ struct dmirror_chunk { struct dmirror_device { struct cdev cdevice; struct hmm_devmem *devmem; + unsigned int zone_device_type; unsigned int devmem_capacity; unsigned int devmem_count; @@ -1260,14 +1261,20 @@ static void dmirror_device_remove(struct dmirror_device *mdevice) static int __init hmm_dmirror_init(void) { int ret; - int id; + int id = 0; + int ndevices = 0; ret = alloc_chrdev_region(&dmirror_dev, 0, DMIRROR_NDEVICES, "HMM_DMIRROR"); if (ret) goto err_unreg; - for (id = 0; id < DMIRROR_NDEVICES; id++) { + memset(dmirror_devices, 0, DMIRROR_NDEVICES * sizeof(dmirror_devices[0])); + dmirror_devices[ndevices++].zone_device_type = + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; + dmirror_devices[ndevices++].zone_device_type = + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; + for (id = 0; id < ndevices; id++) { ret = dmirror_device_init(dmirror_devices + id, id); if (ret) goto err_chrdev; diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index f14dea5dcd06..0511af7464ee 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -31,10 +31,11 @@ struct hmm_dmirror_cmd { /* Expose the address space of the calling process through hmm device file */ #define HMM_DMIRROR_READ _IOWR('H', 0x00, struct hmm_dmirror_cmd) #define HMM_DMIRROR_WRITE _IOWR('H', 0x01, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_MIGRATE _IOWR('H', 0x02, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_SNAPSHOT _IOWR('H', 0x03, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_EXCLUSIVE _IOWR('H', 0x04, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_CHECK_EXCLUSIVE _IOWR('H', 0x05, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_MIGRATE_TO_DEV _IOWR('H', 0x02, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_MIGRATE_TO_SYS _IOWR('H', 0x03, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_SNAPSHOT _IOWR('H', 0x04, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_EXCLUSIVE _IOWR('H', 0x05, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_CHECK_EXCLUSIVE _IOWR('H', 0x06, struct hmm_dmirror_cmd) /* * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT. @@ -62,4 +63,9 @@ enum { HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE = 0x30, }; +enum { + /* 0 is reserved to catch uninitialized type fields */ + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1, +}; + #endif /* _LIB_TEST_HMM_UAPI_H */ From patchwork Tue Jun 28 00:14:49 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: 12897311 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 48376C433EF for ; Tue, 28 Jun 2022 00:15:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C6C18E000C; Mon, 27 Jun 2022 20:15:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 300D78E0008; Mon, 27 Jun 2022 20:15:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14FE88E000C; Mon, 27 Jun 2022 20:15:31 -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 016418E0008 for ; Mon, 27 Jun 2022 20:15:30 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id D84A7806E0 for ; Tue, 28 Jun 2022 00:15:30 +0000 (UTC) X-FDA: 79625725620.26.20683BA Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2062.outbound.protection.outlook.com [40.107.101.62]) by imf29.hostedemail.com (Postfix) with ESMTP id 5EE84120032 for ; Tue, 28 Jun 2022 00:15:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CQBoNlNOEbv562ppiTOUc5ziJc9wKlw7zOfWD2aYhQB2kd0SOw8lSEfa/OQU/Q1rYwriCt0B9srw7vk3EJg1geYHx0oGxS+iIHs15IPLH1rE6ParXJUcyjF+GfDX9f0g09ChqwQXzOitvbSHcXnsNSMJr8TWvLf3wq8WtTov/9qhiQuweEhDfS5H09kQEYRB5M4DpbO1L97vBq1xUSpiuiSUqjgaoWbJwbX93IYsIfAKKx7dT7+s7QR7aFql1TTzdiXeEIpbiaiyVcAUS5zLf4jemU9+5JpqV6CR3kZWhkEDUmu30mydB1yLaR61EtIT7QCZ89306kctCxOI+4n7eg== 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=0Gq5krbSDZgVmQmlPCe18YVS7UIhP8NZXgBaLYb/5yI=; b=DA6BCuaRtkF8NYh5oPiHmGcUWTiF0tRsxobKYVxm5Jizf/HiOdXro89G2Ke9JV5l2Bf967NDFVksdQw9SYnzct3hw9P5fA7hItdGU+ODNhEd9ys1akFcki0hRc1gbKuNgjRqDSDRj3/iBHnRxrrSXWtB13nITYDrU2oaQ0/hhiM65vGpQtkLKH37e258BDyjU+szrl+cGzqUk86q17pRSBKnrFdcLWzWo5fwevtcUWfG58/OTXLex7ICU8g99GF5zjPMir6iKndsV7K1tkVC9O/faO6mUc7yxvmTkIy4XW7i7kzGwFeNQrw6qOZ+lJD8dNlweBwF2dPx6hU0ncDsgw== 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=0Gq5krbSDZgVmQmlPCe18YVS7UIhP8NZXgBaLYb/5yI=; b=2NTeppBeiOqRZNUx3VdUT5FXcIXb459R0UKQyX0gXTqWSVpYvfCKr2VufNkGoSUO9y3wf0SnKsQld4kUYN2tn/gm1DYLwszwoXYFlaqRtweYGZ6NyGit94Ve+AKOl3cEA8KhJFWXVwYZqqdZrBJVeXkoba6pgmIysBfZ8n+Fm6A= Received: from MW4PR03CA0175.namprd03.prod.outlook.com (2603:10b6:303:8d::30) by CH2PR12MB3669.namprd12.prod.outlook.com (2603:10b6:610:27::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16; Tue, 28 Jun 2022 00:15:27 +0000 Received: from CO1NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8d:cafe::16) by MW4PR03CA0175.outlook.office365.com (2603:10b6:303:8d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17 via Frontend Transport; Tue, 28 Jun 2022 00:15:27 +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 CO1NAM11FT057.mail.protection.outlook.com (10.13.174.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:27 +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; Mon, 27 Jun 2022 19:15:25 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 09/14] lib: test_hmm add module param for zone device type Date: Mon, 27 Jun 2022 19:14:49 -0500 Message-ID: <20220628001454.3503-10-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: 785ac2d5-9c84-4c95-0466-08da589b4db5 X-MS-TrafficTypeDiagnostic: CH2PR12MB3669:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DMPK10uccKv4VA3wDYXBsCn+dE2zZs9JaXLG8zUsl+gDxlFsnkDP2Mip09vF+N+lMEa56wgplLUO7BaikDcfTeoVVIPSFO0g2cQtEFkuBpVWafOBHmTvXD2r+D2X8xFQ0ft/9CSB1GlXZ8dvzB5/FJG6o8J2foxuglCoEGWuriroRVzA62K9ijVPwVPW0z5GNEXIJcFctvUzDBky2j8E/Kr8Ft2Dq8YX6IOW//Bmw/PYCzyIFAHjeRVdh5EjCLYyr84VHyfg4i9BLESDbvf4eToO67tmGVDS77/8Mw4QY+eBsvLF/6CBBv46S+IVuMlTv/xnZhDHzMOj6fxb0oFU6nQIyy3Mgm3SbrvGOEIQiNVixJp62r1/v+FrMs248sK1wQkvIDVWU7RpUWSyLzIBOG9MC8X9MCnxKcOVu9/ZH3YCGg7tYVd2Xra16YvhxupJiY4BnjHMnVLqGJ6gPqO2Q6KnLV895WDhBMxf/P9gdh15tbNQVl+An+WkDLc6WqPrhpzgpJvZdhTJ5mwM8ZlHZXbrEdzvUTDWhNzT3ie0TlGC/W4RxEX/BaroWhMHg7JIfKMdaS/auf41sWWV9UnymhNjXrRHBNQHUkLdztk04m+BXLmtUkn0sK4x61pIknYvUGejQTt9ldJz1mg0RuNLaTUmGRgl6ATwOzoMimZBAMx2i9ERjBa2GgRZpvKmAkOP9O0jDJ/M9+XzMWrRGojPRRVSQyvM1xbPUzUHyhoJALRsjIv/2C62tduCNrEzFbm4q4qAB+9Y9e6/J5cvetVUIhIH19ypOS5ZjocZ91m40+xfvqHatYXGyqBpZgCCl4JLbexGQVAOUzhm6RCa5mxlZw== 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)(39860400002)(376002)(396003)(136003)(346002)(36840700001)(40470700004)(46966006)(4326008)(8676002)(82740400003)(316002)(356005)(70586007)(1076003)(70206006)(6666004)(36756003)(54906003)(82310400005)(186003)(36860700001)(40460700003)(16526019)(2616005)(40480700001)(83380400001)(47076005)(7696005)(426003)(2906002)(44832011)(41300700001)(7416002)(336012)(86362001)(8936002)(26005)(6916009)(478600001)(81166007)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:27.1355 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 785ac2d5-9c84-4c95-0466-08da589b4db5 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: CO1NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3669 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375330; a=rsa-sha256; cv=pass; b=c8ocZ2Y5MjgRbheCEQ/AGwHvAKBL0TkOlePA67R+HkGHWz3SycbVABZk6b+ugSVXPbfKD+ 480zHUrsn/tBoANs2eXB0FxEbqhaLXSWTwIeb6YQXB2nAFZ8CXZ+OKt389eBZuz3MQEntg fK2GIW+TFVdVihxlhi1b6Fjad09fa70= ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=2NTeppBe; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf29.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.62 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656375330; 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=0Gq5krbSDZgVmQmlPCe18YVS7UIhP8NZXgBaLYb/5yI=; b=Kr4J+OXSFUuNJvD1uzvYrKWzVnyxhIZuIbU29WSyc7f+QAp0+8xNa+zoWomssRUu0BgFwJ gD3ebf8z2+Y3YIhjFPWuzzSKeoSbdPZon7YeOhKgbAOxXFgXSdPdpP+Y28KQq8heKag3YC Lt6KAxj7OTDDp8JrOeWhVZ1kGkfyI7U= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5EE84120032 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=2NTeppBe; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf29.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.62 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: X-Stat-Signature: km3cqnjjfjcx5wdrh5k395fek8tusty5 X-HE-Tag: 1656375330-170013 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: In order to configure device coherent in test_hmm, two module parameters should be passed, which correspond to the SP start address of each device (2) spm_addr_dev0 & spm_addr_dev1. If no parameters are passed, private device type is configured. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Poppple Signed-off-by: Christoph Hellwig --- lib/test_hmm.c | 73 ++++++++++++++++++++++++++++++++------------- lib/test_hmm_uapi.h | 1 + 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 915ef6b5b0d4..afb30af9f3ff 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -37,6 +37,16 @@ #define DEVMEM_CHUNK_SIZE (256 * 1024 * 1024U) #define DEVMEM_CHUNKS_RESERVE 16 +static unsigned long spm_addr_dev0; +module_param(spm_addr_dev0, long, 0644); +MODULE_PARM_DESC(spm_addr_dev0, + "Specify start address for SPM (special purpose memory) used for device 0. By setting this Coherent device type will be used. Make sure spm_addr_dev1 is set too. Minimum SPM size should be DEVMEM_CHUNK_SIZE."); + +static unsigned long spm_addr_dev1; +module_param(spm_addr_dev1, long, 0644); +MODULE_PARM_DESC(spm_addr_dev1, + "Specify start address for SPM (special purpose memory) used for device 1. By setting this Coherent device type will be used. Make sure spm_addr_dev0 is set too. Minimum SPM size should be DEVMEM_CHUNK_SIZE."); + static const struct dev_pagemap_ops dmirror_devmem_ops; static const struct mmu_interval_notifier_ops dmirror_min_ops; static dev_t dmirror_dev; @@ -455,28 +465,44 @@ static int dmirror_write(struct dmirror *dmirror, struct hmm_dmirror_cmd *cmd) return ret; } -static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, +static int dmirror_allocate_chunk(struct dmirror_device *mdevice, struct page **ppage) { struct dmirror_chunk *devmem; - struct resource *res; + struct resource *res = NULL; unsigned long pfn; unsigned long pfn_first; unsigned long pfn_last; void *ptr; + int ret = -ENOMEM; devmem = kzalloc(sizeof(*devmem), GFP_KERNEL); if (!devmem) - return false; + return ret; - res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, - "hmm_dmirror"); - if (IS_ERR(res)) + switch (mdevice->zone_device_type) { + case HMM_DMIRROR_MEMORY_DEVICE_PRIVATE: + res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, + "hmm_dmirror"); + if (IS_ERR_OR_NULL(res)) + goto err_devmem; + devmem->pagemap.range.start = res->start; + devmem->pagemap.range.end = res->end; + devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; + break; + case HMM_DMIRROR_MEMORY_DEVICE_COHERENT: + devmem->pagemap.range.start = (MINOR(mdevice->cdevice.dev) - 2) ? + spm_addr_dev0 : + spm_addr_dev1; + devmem->pagemap.range.end = devmem->pagemap.range.start + + DEVMEM_CHUNK_SIZE - 1; + devmem->pagemap.type = MEMORY_DEVICE_COHERENT; + break; + default: + ret = -EINVAL; goto err_devmem; + } - devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; - devmem->pagemap.range.start = res->start; - devmem->pagemap.range.end = res->end; devmem->pagemap.nr_range = 1; devmem->pagemap.ops = &dmirror_devmem_ops; devmem->pagemap.owner = mdevice; @@ -497,10 +523,14 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, mdevice->devmem_capacity = new_capacity; mdevice->devmem_chunks = new_chunks; } - ptr = memremap_pages(&devmem->pagemap, numa_node_id()); - if (IS_ERR(ptr)) + if (IS_ERR_OR_NULL(ptr)) { + if (ptr) + ret = PTR_ERR(ptr); + else + ret = -EFAULT; goto err_release; + } devmem->mdevice = mdevice; pfn_first = devmem->pagemap.range.start >> PAGE_SHIFT; @@ -529,15 +559,17 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, } spin_unlock(&mdevice->lock); - return true; + return 0; err_release: mutex_unlock(&mdevice->devmem_lock); - release_mem_region(devmem->pagemap.range.start, range_len(&devmem->pagemap.range)); + if (res && devmem->pagemap.type == MEMORY_DEVICE_PRIVATE) + release_mem_region(devmem->pagemap.range.start, + range_len(&devmem->pagemap.range)); err_devmem: kfree(devmem); - return false; + return ret; } static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) @@ -562,7 +594,7 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) spin_unlock(&mdevice->lock); } else { spin_unlock(&mdevice->lock); - if (!dmirror_allocate_chunk(mdevice, &dpage)) + if (dmirror_allocate_chunk(mdevice, &dpage)) goto error; } @@ -1232,10 +1264,8 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id) if (ret) return ret; - /* Build a list of free ZONE_DEVICE private struct pages */ - dmirror_allocate_chunk(mdevice, NULL); - - return 0; + /* Build a list of free ZONE_DEVICE struct pages */ + return dmirror_allocate_chunk(mdevice, NULL); } static void dmirror_device_remove(struct dmirror_device *mdevice) @@ -1248,8 +1278,9 @@ static void dmirror_device_remove(struct dmirror_device *mdevice) mdevice->devmem_chunks[i]; memunmap_pages(&devmem->pagemap); - release_mem_region(devmem->pagemap.range.start, - range_len(&devmem->pagemap.range)); + if (devmem->pagemap.type == MEMORY_DEVICE_PRIVATE) + release_mem_region(devmem->pagemap.range.start, + range_len(&devmem->pagemap.range)); kfree(devmem); } kfree(mdevice->devmem_chunks); diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index 0511af7464ee..f700da7807c1 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -66,6 +66,7 @@ enum { enum { /* 0 is reserved to catch uninitialized type fields */ HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1, + HMM_DMIRROR_MEMORY_DEVICE_COHERENT, }; #endif /* _LIB_TEST_HMM_UAPI_H */ From patchwork Tue Jun 28 00:14:50 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: 12897312 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 D6AB2CCA47B for ; Tue, 28 Jun 2022 00:15:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C03F58E000D; Mon, 27 Jun 2022 20:15:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB1128E0008; Mon, 27 Jun 2022 20:15:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98E558E000D; Mon, 27 Jun 2022 20:15:32 -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 824DB8E0008 for ; Mon, 27 Jun 2022 20:15:32 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 54D1F340AF for ; Tue, 28 Jun 2022 00:15:32 +0000 (UTC) X-FDA: 79625725704.28.049AFF2 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2065.outbound.protection.outlook.com [40.107.237.65]) by imf08.hostedemail.com (Postfix) with ESMTP id C8C9A16002F for ; Tue, 28 Jun 2022 00:15:31 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aQ7AUd+pomg3AiK+kaqmUtYwnIa6GPASja38ru6Ljx88y7w8zJ1xZ90B1Ye6CaNJhSQaQFFktJ3d4ogAudxFku2qbFF3z5FnQJ09LA+KXp73qWrmfKImSW43LASk4V5Ec1+y5/j7Dab9IbOCIt5HAbpO11cGv3eMLVyZKqk2WCoqiiahKfFKLz7IYSFl+WAgcoXIb5/2CqxmrRUAoxKjah0fCb2bWNUzrdK5TWuNO1RCep8EQOk+jLTIMVSfCF+DqSqog6NsN8zyuNGpigVsDjVBkbhlbWMDXWHmpqyGamLQGrE4sc0pqCVjR8W5ewcuEvWFaJpBs/7GJzXZZhXwqw== 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=qXHkTMDP9sqYKzMO3NOS8Ic3UgCNCptiqPNyD5wLuTo=; b=aGZKQHURNgNd8EIZd9vYFIWY0CGuswkUfWP4/7zu6JlceV8hYN6u/Ub1z2iYwIWaX08QjbhhFYlFP93u/dPdIxrREDLNVqeb1CTWdVd5YwZnBBhhhJ+JomlycYPTuk8r2wHQ2wfACcVC2DGKpckLwSw56Pa9ksTepi9MZNCV+Oz99TPGlKO3YtKW1fBVHlKbzvmN2pMOu+RJj7agJVuIBvmvFg8xq7p0Y5DHRq5hYHW52hmPghPiCbtY+WoBVbuIQSlIqip7time0ZaUYuR9vS9repWdOfTj8sUqUlG2y6293TUCr1djf+yT8921gvJ2uC3O9Et75gGghBMorAAe2Q== 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=qXHkTMDP9sqYKzMO3NOS8Ic3UgCNCptiqPNyD5wLuTo=; b=oza9lRiRi03V8idNYWrho+8ZCxM7LYk5l1JR2pc2Pv8YCM1hM5VIL5W0fIUaFdaqZF8JThma47rD5nW8GghZrYUe6JuCNh3S7kAMRoB9GHre5vj5OQXQlFmkcStnQnYXs2wN7bHu2kN2fSuV3PUFLe5PSUT5rP3kVJXRA/w1ATA= Received: from MWHPR15CA0061.namprd15.prod.outlook.com (2603:10b6:301:4c::23) by DM5PR12MB1738.namprd12.prod.outlook.com (2603:10b6:3:112::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17; Tue, 28 Jun 2022 00:15:27 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::26) by MWHPR15CA0061.outlook.office365.com (2603:10b6:301:4c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.21 via Frontend Transport; Tue, 28 Jun 2022 00:15:27 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:27 +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; Mon, 27 Jun 2022 19:15:26 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 10/14] lib: add support for device coherent type in test_hmm Date: Mon, 27 Jun 2022 19:14:50 -0500 Message-ID: <20220628001454.3503-11-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: f8bf622d-aaf2-4a51-e7f0-08da589b4deb X-MS-TrafficTypeDiagnostic: DM5PR12MB1738:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M+3eRX3PAmHEUMmSy9ZIpmCfI4vYK96gvm5KzggTRaMhODmc4yNonpez5CgprkvDLqG6ke9pbRShvU/5LwE0cjsiDfAsoSCa+AcHhaUVYZnnZGvIYBxk17IueQ5llhPCvzlqLwqJw+qxUiF9IB4T4Ji5nWm2PXRfN+XU0IZ5xwfaxu/fp89e4c2o5RLzrrhq3Rp/4W3pzlRGUN4WPKowZ4oDpfl90Wv0PcTFxpOxPimXVjfB8+Yk5PfwwlyzojK8BqwlFAm9IgN+A9R7g8tOhYWF0LhYT3G7AdPIrmz6iPb7oltCejxEyWtwqvSlZsuxXkn0eSl/sTkd7fdAVbaJ4Y4BH7bHKfMBYLfMfWsrctzYDx0iT5tqAFK6Iky+mUIQt29obiuGZibPK2C3S0GKWMIWkLttWnnfvFvb6Jls7/UxnGtv79V2aVOTBOx2PBjNw20u5oOREXHEJiTKcWj7vzQzxRvJGizah+c3ZXMeZ2RuGc8UH0jpWT4rUTEH1CTpRp1cbPb5VGMlgFSh6yW8JfhHIkneFxFKwFfA4V0gMrpXeRnsxr4Er+5+RTIpB6vP322jDl8DHnpC0kvXdLc6JGEttn7rsLQhwFy1UIESPsI2Q2DGvkI1lNpCDS6AflMsVh+H0a4CXC/gnc0usW1ZRqYgXh0QXr9EuchN92l/DUvQZy33r6tQmkaOFW47kWUN8sboFWU41NzjUlZ8/T3r9WcIfVYnym5nA2phm765h5VNa8oMjLTqs9NglaRXyjVi5xn+IDSskXbxGOt6a10Fqj2Pb3P1eI9aWAT6IxLzt6zg4L5PhNVbRS0k10yO3asG7CA08iXDSs+ra2WHLR5ZiQ== 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)(346002)(136003)(376002)(39860400002)(396003)(40470700004)(36840700001)(46966006)(2616005)(4326008)(70586007)(6916009)(8676002)(70206006)(86362001)(316002)(8936002)(40480700001)(44832011)(7696005)(26005)(81166007)(41300700001)(54906003)(6666004)(40460700003)(82740400003)(82310400005)(16526019)(30864003)(83380400001)(186003)(2906002)(47076005)(1076003)(336012)(426003)(36860700001)(478600001)(5660300002)(7416002)(36756003)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:27.4952 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f8bf622d-aaf2-4a51-e7f0-08da589b4deb 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1738 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375332; a=rsa-sha256; cv=pass; b=QTcmOGyZOoviG6Q8GQjtW7Nyzlr+nPTKc1QUP3x/K3xvSYZhxk5clzlWI50vEUzEBNEAvy QlhQ5b0+H0g9TXyeabOTujv133IwJWiLgCDKR7WnNEwkL1vWxzj3PFLXm+lFQTaT5DGvEK 8gZeRh51yIBw6AK8Huy/KWLK1KgFNRc= ARC-Authentication-Results: i=2; imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=oza9lRiR; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf08.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.65 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=1656375332; 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=qXHkTMDP9sqYKzMO3NOS8Ic3UgCNCptiqPNyD5wLuTo=; b=PCWIxh/1hSQgdRCTCxxK4toorC0RNHHXEq52H2/9ceu36QYMkGiUNsDZfERky6dWRhv6tJ hO2GG0zJvhgAWu3xr9/Md+Twi3/fRyMaZ/nmgCLnZl6/8LXctpLVyI7YiupTwOBrElMAdQ hTUGp+OggAMRf1Kuusoqc+kpUdgdfak= X-Rspam-User: X-Stat-Signature: qi6b9ko5y6968ch6ndfte1fnymrewntt X-Rspamd-Queue-Id: C8C9A16002F Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=oza9lRiR; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf08.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.65 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam03 X-HE-Tag: 1656375331-334361 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: Device Coherent type uses device memory that is coherently accesible by the CPU. This could be shown as SP (special purpose) memory range at the BIOS-e820 memory enumeration. If no SP memory is supported in system, this could be faked by setting CONFIG_EFI_FAKE_MEMMAP. Currently, test_hmm only supports two different SP ranges of at least 256MB size. This could be specified in the kernel parameter variable efi_fake_mem. Ex. Two SP ranges of 1GB starting at 0x100000000 & 0x140000000 physical address. Ex. efi_fake_mem=1G@0x100000000:0x40000,1G@0x140000000:0x40000 Private and coherent device mirror instances can be created in the same probed. This is done by passing the module parameters spm_addr_dev0 & spm_addr_dev1. In this case, it will create four instances of device_mirror. The first two correspond to private device type, the last two to coherent type. Then, they can be easily accessed from user space through /dev/hmm_mirror. Usually num_device 0 and 1 are for private, and 2 and 3 for coherent types. If no module parameters are passed, two instances of private type device_mirror will be created only. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Poppple --- lib/test_hmm.c | 253 +++++++++++++++++++++++++++++++++----------- lib/test_hmm_uapi.h | 4 + 2 files changed, 196 insertions(+), 61 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index afb30af9f3ff..7930853e7fc5 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -32,11 +32,22 @@ #include "test_hmm_uapi.h" -#define DMIRROR_NDEVICES 2 +#define DMIRROR_NDEVICES 4 #define DMIRROR_RANGE_FAULT_TIMEOUT 1000 #define DEVMEM_CHUNK_SIZE (256 * 1024 * 1024U) #define DEVMEM_CHUNKS_RESERVE 16 +/* + * For device_private pages, dpage is just a dummy struct page + * representing a piece of device memory. dmirror_devmem_alloc_page + * allocates a real system memory page as backing storage to fake a + * real device. zone_device_data points to that backing page. But + * for device_coherent memory, the struct page represents real + * physical CPU-accessible memory that we can use directly. + */ +#define BACKING_PAGE(page) (is_device_private_page((page)) ? \ + (page)->zone_device_data : (page)) + static unsigned long spm_addr_dev0; module_param(spm_addr_dev0, long, 0644); MODULE_PARM_DESC(spm_addr_dev0, @@ -125,6 +136,21 @@ static int dmirror_bounce_init(struct dmirror_bounce *bounce, return 0; } +static bool dmirror_is_private_zone(struct dmirror_device *mdevice) +{ + return (mdevice->zone_device_type == + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE) ? true : false; +} + +static enum migrate_vma_direction +dmirror_select_device(struct dmirror *dmirror) +{ + return (dmirror->mdevice->zone_device_type == + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE) ? + MIGRATE_VMA_SELECT_DEVICE_PRIVATE : + MIGRATE_VMA_SELECT_DEVICE_COHERENT; +} + static void dmirror_bounce_fini(struct dmirror_bounce *bounce) { vfree(bounce->ptr); @@ -575,16 +601,19 @@ static int dmirror_allocate_chunk(struct dmirror_device *mdevice, static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) { struct page *dpage = NULL; - struct page *rpage; + struct page *rpage = NULL; /* - * This is a fake device so we alloc real system memory to store - * our device memory. + * For ZONE_DEVICE private type, this is a fake device so we allocate + * real system memory to store our device memory. + * For ZONE_DEVICE coherent type we use the actual dpage to store the + * data and ignore rpage. */ - rpage = alloc_page(GFP_HIGHUSER); - if (!rpage) - return NULL; - + if (dmirror_is_private_zone(mdevice)) { + rpage = alloc_page(GFP_HIGHUSER); + if (!rpage) + return NULL; + } spin_lock(&mdevice->lock); if (mdevice->free_pages) { @@ -603,7 +632,8 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) return dpage; error: - __free_page(rpage); + if (rpage) + __free_page(rpage); return NULL; } @@ -629,12 +659,16 @@ static void dmirror_migrate_alloc_and_copy(struct migrate_vma *args, * unallocated pte_none() or read-only zero page. */ spage = migrate_pfn_to_page(*src); + if (WARN(spage && is_zone_device_page(spage), + "page already in device spage pfn: 0x%lx\n", + page_to_pfn(spage))) + continue; dpage = dmirror_devmem_alloc_page(mdevice); if (!dpage) continue; - rpage = dpage->zone_device_data; + rpage = BACKING_PAGE(dpage); if (spage) copy_highpage(rpage, spage); else @@ -648,6 +682,8 @@ static void dmirror_migrate_alloc_and_copy(struct migrate_vma *args, */ rpage->zone_device_data = dmirror; + pr_debug("migrating from sys to dev pfn src: 0x%lx pfn dst: 0x%lx\n", + page_to_pfn(spage), page_to_pfn(dpage)); *dst = migrate_pfn(page_to_pfn(dpage)); if ((*src & MIGRATE_PFN_WRITE) || (!spage && args->vma->vm_flags & VM_WRITE)) @@ -725,11 +761,7 @@ static int dmirror_migrate_finalize_and_map(struct migrate_vma *args, if (!dpage) continue; - /* - * Store the page that holds the data so the page table - * doesn't have to deal with ZONE_DEVICE private pages. - */ - entry = dpage->zone_device_data; + entry = BACKING_PAGE(dpage); if (*dst & MIGRATE_PFN_WRITE) entry = xa_tag_pointer(entry, DPT_XA_TAG_WRITE); entry = xa_store(&dmirror->pt, pfn, entry, GFP_ATOMIC); @@ -809,15 +841,126 @@ static int dmirror_exclusive(struct dmirror *dmirror, return ret; } -static int dmirror_migrate(struct dmirror *dmirror, - struct hmm_dmirror_cmd *cmd) +static vm_fault_t dmirror_devmem_fault_alloc_and_copy(struct migrate_vma *args, + struct dmirror *dmirror) +{ + const unsigned long *src = args->src; + unsigned long *dst = args->dst; + unsigned long start = args->start; + unsigned long end = args->end; + unsigned long addr; + + for (addr = start; addr < end; addr += PAGE_SIZE, + src++, dst++) { + struct page *dpage, *spage; + + spage = migrate_pfn_to_page(*src); + if (!spage || !(*src & MIGRATE_PFN_MIGRATE)) + continue; + + if (WARN_ON(!is_device_private_page(spage) && + !is_device_coherent_page(spage))) + continue; + spage = BACKING_PAGE(spage); + dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr); + if (!dpage) + continue; + pr_debug("migrating from dev to sys pfn src: 0x%lx pfn dst: 0x%lx\n", + page_to_pfn(spage), page_to_pfn(dpage)); + + lock_page(dpage); + xa_erase(&dmirror->pt, addr >> PAGE_SHIFT); + copy_highpage(dpage, spage); + *dst = migrate_pfn(page_to_pfn(dpage)); + if (*src & MIGRATE_PFN_WRITE) + *dst |= MIGRATE_PFN_WRITE; + } + return 0; +} + +static unsigned long +dmirror_successful_migrated_pages(struct migrate_vma *migrate) +{ + unsigned long cpages = 0; + unsigned long i; + + for (i = 0; i < migrate->npages; i++) { + if (migrate->src[i] & MIGRATE_PFN_VALID && + migrate->src[i] & MIGRATE_PFN_MIGRATE) + cpages++; + } + return cpages; +} + +static int dmirror_migrate_to_system(struct dmirror *dmirror, + struct hmm_dmirror_cmd *cmd) { unsigned long start, end, addr; unsigned long size = cmd->npages << PAGE_SHIFT; struct mm_struct *mm = dmirror->notifier.mm; struct vm_area_struct *vma; - unsigned long src_pfns[64]; - unsigned long dst_pfns[64]; + unsigned long src_pfns[64] = { 0 }; + unsigned long dst_pfns[64] = { 0 }; + struct migrate_vma args; + unsigned long next; + int ret; + + start = cmd->addr; + end = start + size; + if (end < start) + return -EINVAL; + + /* Since the mm is for the mirrored process, get a reference first. */ + if (!mmget_not_zero(mm)) + return -EINVAL; + + cmd->cpages = 0; + mmap_read_lock(mm); + for (addr = start; addr < end; addr = next) { + vma = vma_lookup(mm, addr); + if (!vma || !(vma->vm_flags & VM_READ)) { + ret = -EINVAL; + goto out; + } + next = min(end, addr + (ARRAY_SIZE(src_pfns) << PAGE_SHIFT)); + if (next > vma->vm_end) + next = vma->vm_end; + + args.vma = vma; + args.src = src_pfns; + args.dst = dst_pfns; + args.start = addr; + args.end = next; + args.pgmap_owner = dmirror->mdevice; + args.flags = dmirror_select_device(dmirror); + + ret = migrate_vma_setup(&args); + if (ret) + goto out; + + pr_debug("Migrating from device mem to sys mem\n"); + dmirror_devmem_fault_alloc_and_copy(&args, dmirror); + + migrate_vma_pages(&args); + cmd->cpages += dmirror_successful_migrated_pages(&args); + migrate_vma_finalize(&args); + } +out: + mmap_read_unlock(mm); + mmput(mm); + + return ret; +} + +static int dmirror_migrate_to_device(struct dmirror *dmirror, + struct hmm_dmirror_cmd *cmd) +{ + unsigned long start, end, addr; + unsigned long size = cmd->npages << PAGE_SHIFT; + struct mm_struct *mm = dmirror->notifier.mm; + struct vm_area_struct *vma; + unsigned long src_pfns[64] = { 0 }; + unsigned long dst_pfns[64] = { 0 }; struct dmirror_bounce bounce; struct migrate_vma args; unsigned long next; @@ -854,6 +997,7 @@ static int dmirror_migrate(struct dmirror *dmirror, if (ret) goto out; + pr_debug("Migrating from sys mem to device mem\n"); dmirror_migrate_alloc_and_copy(&args, dmirror); migrate_vma_pages(&args); dmirror_migrate_finalize_and_map(&args, dmirror); @@ -862,7 +1006,10 @@ static int dmirror_migrate(struct dmirror *dmirror, mmap_read_unlock(mm); mmput(mm); - /* Return the migrated data for verification. */ + /* + * Return the migrated data for verification. + * Only for pages in device zone + */ ret = dmirror_bounce_init(&bounce, start, size); if (ret) return ret; @@ -905,6 +1052,12 @@ static void dmirror_mkentry(struct dmirror *dmirror, struct hmm_range *range, *perm = HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL; else *perm = HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE; + } else if (is_device_coherent_page(page)) { + /* Is the page migrated to this device or some other? */ + if (dmirror->mdevice == dmirror_page_to_device(page)) + *perm = HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL; + else + *perm = HMM_DMIRROR_PROT_DEV_COHERENT_REMOTE; } else if (is_zero_pfn(page_to_pfn(page))) *perm = HMM_DMIRROR_PROT_ZERO; else @@ -1092,8 +1245,12 @@ static long dmirror_fops_unlocked_ioctl(struct file *filp, ret = dmirror_write(dmirror, &cmd); break; - case HMM_DMIRROR_MIGRATE: - ret = dmirror_migrate(dmirror, &cmd); + case HMM_DMIRROR_MIGRATE_TO_DEV: + ret = dmirror_migrate_to_device(dmirror, &cmd); + break; + + case HMM_DMIRROR_MIGRATE_TO_SYS: + ret = dmirror_migrate_to_system(dmirror, &cmd); break; case HMM_DMIRROR_EXCLUSIVE: @@ -1155,14 +1312,13 @@ static const struct file_operations dmirror_fops = { static void dmirror_devmem_free(struct page *page) { - struct page *rpage = page->zone_device_data; + struct page *rpage = BACKING_PAGE(page); struct dmirror_device *mdevice; - if (rpage) + if (rpage != page) __free_page(rpage); mdevice = dmirror_page_to_device(page); - spin_lock(&mdevice->lock); mdevice->cfree++; page->zone_device_data = mdevice->free_pages; @@ -1170,43 +1326,11 @@ static void dmirror_devmem_free(struct page *page) spin_unlock(&mdevice->lock); } -static vm_fault_t dmirror_devmem_fault_alloc_and_copy(struct migrate_vma *args, - struct dmirror *dmirror) -{ - const unsigned long *src = args->src; - unsigned long *dst = args->dst; - unsigned long start = args->start; - unsigned long end = args->end; - unsigned long addr; - - for (addr = start; addr < end; addr += PAGE_SIZE, - src++, dst++) { - struct page *dpage, *spage; - - spage = migrate_pfn_to_page(*src); - if (!spage || !(*src & MIGRATE_PFN_MIGRATE)) - continue; - spage = spage->zone_device_data; - - dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr); - if (!dpage) - continue; - - lock_page(dpage); - xa_erase(&dmirror->pt, addr >> PAGE_SHIFT); - copy_highpage(dpage, spage); - *dst = migrate_pfn(page_to_pfn(dpage)); - if (*src & MIGRATE_PFN_WRITE) - *dst |= MIGRATE_PFN_WRITE; - } - return 0; -} - static vm_fault_t dmirror_devmem_fault(struct vm_fault *vmf) { struct migrate_vma args; - unsigned long src_pfns; - unsigned long dst_pfns; + unsigned long src_pfns = 0; + unsigned long dst_pfns = 0; struct page *rpage; struct dmirror *dmirror; vm_fault_t ret; @@ -1226,7 +1350,7 @@ static vm_fault_t dmirror_devmem_fault(struct vm_fault *vmf) args.src = &src_pfns; args.dst = &dst_pfns; args.pgmap_owner = dmirror->mdevice; - args.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; + args.flags = dmirror_select_device(dmirror); if (migrate_vma_setup(&args)) return VM_FAULT_SIGBUS; @@ -1305,6 +1429,12 @@ static int __init hmm_dmirror_init(void) HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; dmirror_devices[ndevices++].zone_device_type = HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; + if (spm_addr_dev0 && spm_addr_dev1) { + dmirror_devices[ndevices++].zone_device_type = + HMM_DMIRROR_MEMORY_DEVICE_COHERENT; + dmirror_devices[ndevices++].zone_device_type = + HMM_DMIRROR_MEMORY_DEVICE_COHERENT; + } for (id = 0; id < ndevices; id++) { ret = dmirror_device_init(dmirror_devices + id, id); if (ret) @@ -1327,7 +1457,8 @@ static void __exit hmm_dmirror_exit(void) int id; for (id = 0; id < DMIRROR_NDEVICES; id++) - dmirror_device_remove(dmirror_devices + id); + if (dmirror_devices[id].zone_device_type) + dmirror_device_remove(dmirror_devices + id); unregister_chrdev_region(dmirror_dev, DMIRROR_NDEVICES); } diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index f700da7807c1..e31d58c9034a 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -50,6 +50,8 @@ struct hmm_dmirror_cmd { * device the ioctl() is made * HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE: Migrated device private page on some * other device + * HMM_DMIRROR_PROT_DEV_COHERENT: Migrate device coherent page on the device + * the ioctl() is made */ enum { HMM_DMIRROR_PROT_ERROR = 0xFF, @@ -61,6 +63,8 @@ enum { HMM_DMIRROR_PROT_ZERO = 0x10, HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL = 0x20, HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE = 0x30, + HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL = 0x40, + HMM_DMIRROR_PROT_DEV_COHERENT_REMOTE = 0x50, }; enum { From patchwork Tue Jun 28 00:14:51 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: 12897313 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 47DB1CCA480 for ; Tue, 28 Jun 2022 00:15:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 216D08E0008; Mon, 27 Jun 2022 20:15:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1787E8E000E; Mon, 27 Jun 2022 20:15:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0CC78E0008; Mon, 27 Jun 2022 20:15:32 -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 D6F4F8E000E for ; Mon, 27 Jun 2022 20:15:32 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B23162111E for ; Tue, 28 Jun 2022 00:15:32 +0000 (UTC) X-FDA: 79625725704.02.A5C1099 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2063.outbound.protection.outlook.com [40.107.93.63]) by imf14.hostedemail.com (Postfix) with ESMTP id 54579100023 for ; Tue, 28 Jun 2022 00:15:32 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iqBfDdRvJn8XXJdpv3fakDYBNZAPcMSc+BMzVc76YPNt8/qToxxdyNNTeAoC8UuBpFW+wXtGZ0mSpRKRcsu4LV9MHEnttS1Vda+By5AOo6/cIBAG4esB7tuDh3/Kv69+nBoLejAn+36wzEeCeC66ZACgwSHo5/PO3a/mAGRxuJMT3+SCaC77ZMWeP2BrssHGinDxwglpsZqyo9Nkuwls7upF6ir3UD5XvoIWqDrtYVGPyYKA2mSTyB+S5SDu5jHHd3qOmYOoq2wPFQkyGIGPzeFNziX3KIoEmzSi11DU6voHAIqzRRH2puoESnc66253Qnf+6fVqzW/eIexLxuMA7g== 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=FBYoUu7uH3DDQme91+PAxWkWEbnIBTP5UUW8lp9tsk8=; b=g7muNWPv0J/gpfa+4ClX0FXmgxmdpf/7HzPQLjOh5LKMIs9isr20GMHgIG8aF2hOqbJZqZGfKkDyLVdqNmP4jyiBL/VDF5g2NPSAEdIuFYUJN4nHBH1IwF01AVRBN44edwM8xyWss2AidiC2TUuwo5BrbnlS4H6ap99L6Jjua/J9mRJO0xTwFdTf8/kPOTsso5jGGUUBzU6FqslK8a/u7hnclTCroAoUkEb3EFFn5COq/4tMia6kcSIq50f/11xeLUAUiajRMTosikxXqBtuPgrJJkYvq4STjnyDIeCY3zxSdai6zrCfQaiwhMGsfBG3QYfFBtsWaYc2Ob3EL40gVQ== 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=FBYoUu7uH3DDQme91+PAxWkWEbnIBTP5UUW8lp9tsk8=; b=X12tV0zYGbXzVnnItPtPXeF6udjQc+9g/TfOxYCXTXV7OXS82qtVq7lNPMrgKD1mBTxXiL8weHkDSp7x2sRzqY35KyNYDn7v7DPFbLlXrjqSr/+felY6nD1F1aOO3V1+3Zv4/N/nMEHtnyD8Hc9JokJU4ERZMNRobqINpogzalI= Received: from MWHPR15CA0057.namprd15.prod.outlook.com (2603:10b6:301:4c::19) by DM5PR12MB1642.namprd12.prod.outlook.com (2603:10b6:4:7::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17; Tue, 28 Jun 2022 00:15:29 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::ed) by MWHPR15CA0057.outlook.office365.com (2603:10b6:301:4c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.21 via Frontend Transport; Tue, 28 Jun 2022 00:15:28 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:28 +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; Mon, 27 Jun 2022 19:15:27 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 11/14] tools: update hmm-test to support device coherent type Date: Mon, 27 Jun 2022 19:14:51 -0500 Message-ID: <20220628001454.3503-12-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: 1777ccca-52c4-4b23-f058-08da589b4e99 X-MS-TrafficTypeDiagnostic: DM5PR12MB1642:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: USmvfqqTK2ZmM9Jn5eQiIJ0J8dS1AnYQqqDZmwLaWusntPHbAyspSj9tcuHPQV04k5Dnu8/RZsoAXTJudDOlQOrvoBueYS6RU+bSrFY8avSVw3xr9C00dIoXMHr7y4FJt2cw/Ts08/MXJmoDFBFT6heL046nEHa0QNtiIyj3vGToW8bfkQR4EhjaJbNUX7OYVm11QrEv6Um/IxZYbA806vxbhvzJZU4d1a9DWo3OzckyASTLXXvDB16LQ2eBmkLtqVXS2LRojjBO6/i14GJTBtduveJ+PaaN6xgTIX63a6+8dRkJOVQ68N/ypl1BQLUw5MB7BFCLe3dfgasEYd1J3J9YJ0DHxL4eDdt9CvagsOcNudZa/u0Ykct5g9bC7oKkMxF4Q/rHxxhz4Ed4onTo7qlwU3h0KOdFrjSs1dMCIGhX7CRDvfsMzYTDhAKmCYSM1aMbrnYJih6dQkPclyzA5QiuTqspWURrHJI4mgjtuje1Y0ZtjyvpkER+xmjnFmyGeXL3Wb5sTvnEkr1C8PCrQJAYhoUgBq/aQ+AQTqhWtu2g0xErgf4llBx7IwiNiuxA+Ha3bcux5GtfE0vX/f2p6h8ayUCKtTXFQdH+dd+QKmUddOjF58nVWIB4PaxL+MxVHd2/AfVCfEQSc92SZ5nB9Y61o8o5amgtIjDAgG1rwz/G5JfA5uSSryzLMyjwacYAHAKs08I3vvuGQbhN8/+uEsvC2nP8gxj6ElGTX6bqrP60fLItez1BvAnZ3nvKDHYJc0HVJXeBFnV4bqSWGK3TxXYV6pSJ1mCcQwc7Ykpj9HTL/Mh1hf25xQ0BMJ5EJc42uOvtDbOUzlMPotQ4QVnlzQ== 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)(396003)(346002)(136003)(39860400002)(376002)(46966006)(36840700001)(40470700004)(83380400001)(36756003)(15650500001)(2906002)(40460700003)(2616005)(6916009)(7416002)(81166007)(44832011)(40480700001)(186003)(36860700001)(426003)(336012)(47076005)(86362001)(16526019)(5660300002)(70206006)(7696005)(54906003)(26005)(70586007)(478600001)(4326008)(82310400005)(8936002)(82740400003)(41300700001)(1076003)(316002)(6666004)(8676002)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:28.6358 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1777ccca-52c4-4b23-f058-08da589b4e99 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1642 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375332; a=rsa-sha256; cv=pass; b=aRhivJN2NfoaF1JkXh6kLBt2m8PpJE5IUy4od+L+RMu/1yp0rQcvTb+7GxzwOW9wWJxMTS 7js9XevFrso4hTN36XtwZRoeWTAiD/bDy1gB89BzcS/ozonnmCfmItWj9eIKfM0LQuIM1h 9AoiuiN87+TnmELEzYZ86GiVYFlAd+A= ARC-Authentication-Results: i=2; imf14.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=X12tV0zY; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf14.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.63 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656375332; 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=FBYoUu7uH3DDQme91+PAxWkWEbnIBTP5UUW8lp9tsk8=; b=eotVXPGI5s86YGLy3YC/emBA8Z3EdjFSydkjcltZHn7c0EYSLLJwkxF/geqqDK+y11zJ4a DYw/LqnJsbZFwmKrxoI8m/b63W2LXOzyB56kapWGIbSN04uDfHbSKXjgI7GjEt/2uSyFA/ vMVuneaHxaVuzjXzud/mzW1qhmRVbuM= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 54579100023 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=X12tV0zY; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf14.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.63 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: X-Stat-Signature: 3s8x69scbgps1c94cbthyemsx1fqga9k X-HE-Tag: 1656375332-130478 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: Test cases such as migrate_fault and migrate_multiple, were modified to explicit migrate from device to sys memory without the need of page faults, when using device coherent type. Snapshot test case updated to read memory device type first and based on that, get the proper returned results migrate_ping_pong test case added to test explicit migration from device to sys memory for both private and coherent zone types. Helpers to migrate from device to sys memory and vicerversa were also added. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Popple Signed-off-by: Christoph Hellwig --- tools/testing/selftests/vm/hmm-tests.c | 121 ++++++++++++++++++++----- 1 file changed, 100 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 203323967b50..4b547188ec40 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -46,6 +46,13 @@ struct hmm_buffer { uint64_t faults; }; +enum { + HMM_PRIVATE_DEVICE_ONE, + HMM_PRIVATE_DEVICE_TWO, + HMM_COHERENCE_DEVICE_ONE, + HMM_COHERENCE_DEVICE_TWO, +}; + #define TWOMEG (1 << 21) #define HMM_BUFFER_SIZE (1024 << 12) #define HMM_PATH_MAX 64 @@ -60,6 +67,21 @@ FIXTURE(hmm) unsigned int page_shift; }; +FIXTURE_VARIANT(hmm) +{ + int device_number; +}; + +FIXTURE_VARIANT_ADD(hmm, hmm_device_private) +{ + .device_number = HMM_PRIVATE_DEVICE_ONE, +}; + +FIXTURE_VARIANT_ADD(hmm, hmm_device_coherent) +{ + .device_number = HMM_COHERENCE_DEVICE_ONE, +}; + FIXTURE(hmm2) { int fd0; @@ -68,6 +90,24 @@ FIXTURE(hmm2) unsigned int page_shift; }; +FIXTURE_VARIANT(hmm2) +{ + int device_number0; + int device_number1; +}; + +FIXTURE_VARIANT_ADD(hmm2, hmm2_device_private) +{ + .device_number0 = HMM_PRIVATE_DEVICE_ONE, + .device_number1 = HMM_PRIVATE_DEVICE_TWO, +}; + +FIXTURE_VARIANT_ADD(hmm2, hmm2_device_coherent) +{ + .device_number0 = HMM_COHERENCE_DEVICE_ONE, + .device_number1 = HMM_COHERENCE_DEVICE_TWO, +}; + static int hmm_open(int unit) { char pathname[HMM_PATH_MAX]; @@ -81,12 +121,19 @@ static int hmm_open(int unit) return fd; } +static bool hmm_is_coherent_type(int dev_num) +{ + return (dev_num >= HMM_COHERENCE_DEVICE_ONE); +} + FIXTURE_SETUP(hmm) { self->page_size = sysconf(_SC_PAGE_SIZE); self->page_shift = ffs(self->page_size) - 1; - self->fd = hmm_open(0); + self->fd = hmm_open(variant->device_number); + if (self->fd < 0 && hmm_is_coherent_type(variant->device_number)) + SKIP(exit(0), "DEVICE_COHERENT not available"); ASSERT_GE(self->fd, 0); } @@ -95,9 +142,11 @@ FIXTURE_SETUP(hmm2) self->page_size = sysconf(_SC_PAGE_SIZE); self->page_shift = ffs(self->page_size) - 1; - self->fd0 = hmm_open(0); + self->fd0 = hmm_open(variant->device_number0); + if (self->fd0 < 0 && hmm_is_coherent_type(variant->device_number0)) + SKIP(exit(0), "DEVICE_COHERENT not available"); ASSERT_GE(self->fd0, 0); - self->fd1 = hmm_open(1); + self->fd1 = hmm_open(variant->device_number1); ASSERT_GE(self->fd1, 0); } @@ -211,6 +260,20 @@ static void hmm_nanosleep(unsigned int n) nanosleep(&t, NULL); } +static int hmm_migrate_sys_to_dev(int fd, + struct hmm_buffer *buffer, + unsigned long npages) +{ + return hmm_dmirror_cmd(fd, HMM_DMIRROR_MIGRATE_TO_DEV, buffer, npages); +} + +static int hmm_migrate_dev_to_sys(int fd, + struct hmm_buffer *buffer, + unsigned long npages) +{ + return hmm_dmirror_cmd(fd, HMM_DMIRROR_MIGRATE_TO_SYS, buffer, npages); +} + /* * Simple NULL test of device open/close. */ @@ -875,7 +938,7 @@ TEST_F(hmm, migrate) ptr[i] = i; /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -923,7 +986,7 @@ TEST_F(hmm, migrate_fault) ptr[i] = i; /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -936,7 +999,7 @@ TEST_F(hmm, migrate_fault) ASSERT_EQ(ptr[i], i); /* Migrate memory to the device again. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -976,7 +1039,7 @@ TEST_F(hmm, migrate_shared) ASSERT_NE(buffer->ptr, MAP_FAILED); /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, -ENOENT); hmm_buffer_free(buffer); @@ -1015,7 +1078,7 @@ TEST_F(hmm2, migrate_mixed) p = buffer->ptr; /* Migrating a protected area should be an error. */ - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, npages); ASSERT_EQ(ret, -EINVAL); /* Punch a hole after the first page address. */ @@ -1023,7 +1086,7 @@ TEST_F(hmm2, migrate_mixed) ASSERT_EQ(ret, 0); /* We expect an error if the vma doesn't cover the range. */ - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, 3); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, 3); ASSERT_EQ(ret, -EINVAL); /* Page 2 will be a read-only zero page. */ @@ -1055,13 +1118,13 @@ TEST_F(hmm2, migrate_mixed) /* Now try to migrate pages 2-5 to device 1. */ buffer->ptr = p + 2 * self->page_size; - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, 4); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, 4); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, 4); /* Page 5 won't be migrated to device 0 because it's on device 1. */ buffer->ptr = p + 5 * self->page_size; - ret = hmm_dmirror_cmd(self->fd0, HMM_DMIRROR_MIGRATE, buffer, 1); + ret = hmm_migrate_sys_to_dev(self->fd0, buffer, 1); ASSERT_EQ(ret, -ENOENT); buffer->ptr = p; @@ -1070,8 +1133,12 @@ TEST_F(hmm2, migrate_mixed) } /* - * Migrate anonymous memory to device private memory and fault it back to system - * memory multiple times. + * Migrate anonymous memory to device memory and back to system memory + * multiple times. In case of private zone configuration, this is done + * through fault pages accessed by CPU. In case of coherent zone configuration, + * the pages from the device should be explicitly migrated back to system memory. + * The reason is Coherent device zone has coherent access by CPU, therefore + * it will not generate any page fault. */ TEST_F(hmm, migrate_multiple) { @@ -1107,8 +1174,7 @@ TEST_F(hmm, migrate_multiple) ptr[i] = i; /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, - npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -1116,7 +1182,13 @@ TEST_F(hmm, migrate_multiple) for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i) ASSERT_EQ(ptr[i], i); - /* Fault pages back to system memory and check them. */ + /* Migrate back to system memory and check them. */ + if (hmm_is_coherent_type(variant->device_number)) { + ret = hmm_migrate_dev_to_sys(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + } + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) ASSERT_EQ(ptr[i], i); @@ -1354,13 +1426,13 @@ TEST_F(hmm2, snapshot) /* Page 5 will be migrated to device 0. */ buffer->ptr = p + 5 * self->page_size; - ret = hmm_dmirror_cmd(self->fd0, HMM_DMIRROR_MIGRATE, buffer, 1); + ret = hmm_migrate_sys_to_dev(self->fd0, buffer, 1); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, 1); /* Page 6 will be migrated to device 1. */ buffer->ptr = p + 6 * self->page_size; - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, 1); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, 1); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, 1); @@ -1377,9 +1449,16 @@ TEST_F(hmm2, snapshot) ASSERT_EQ(m[2], HMM_DMIRROR_PROT_ZERO | HMM_DMIRROR_PROT_READ); ASSERT_EQ(m[3], HMM_DMIRROR_PROT_READ); ASSERT_EQ(m[4], HMM_DMIRROR_PROT_WRITE); - ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL | - HMM_DMIRROR_PROT_WRITE); - ASSERT_EQ(m[6], HMM_DMIRROR_PROT_NONE); + if (!hmm_is_coherent_type(variant->device_number0)) { + ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL | + HMM_DMIRROR_PROT_WRITE); + ASSERT_EQ(m[6], HMM_DMIRROR_PROT_NONE); + } else { + ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL | + HMM_DMIRROR_PROT_WRITE); + ASSERT_EQ(m[6], HMM_DMIRROR_PROT_DEV_COHERENT_REMOTE | + HMM_DMIRROR_PROT_WRITE); + } hmm_buffer_free(buffer); } From patchwork Tue Jun 28 00:14:52 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: 12897315 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 82D53CCA47B for ; Tue, 28 Jun 2022 00:15:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 523B38E0010; Mon, 27 Jun 2022 20:15:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 40FFB8E000F; Mon, 27 Jun 2022 20:15:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2155B8E0010; Mon, 27 Jun 2022 20:15:34 -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 12D558E000F for ; Mon, 27 Jun 2022 20:15:34 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D4F75344CA for ; Tue, 28 Jun 2022 00:15:33 +0000 (UTC) X-FDA: 79625725746.15.0DECAC3 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2082.outbound.protection.outlook.com [40.107.93.82]) by imf07.hostedemail.com (Postfix) with ESMTP id 66B2240038 for ; Tue, 28 Jun 2022 00:15:31 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MYQ5O25gHVrumu5rZ/NB0P6zATeJH884EQIONj/C9B1SfPrQ0C/y6c8cXz/9zQ0kmaGacuL0x4Q5fiH2fOThg0mgjeNKGaF9fmctFpRfDFrn5bWLRtK/A0c9Ksk4LOUcAZs/zyNep/h9Pxvtg12xrb29bOWp2st8ml8Ep0zroGtYs7aqKaJdnPid4HnWYynXaOlJfQ/vwiVUSDHAjd2+XDnFlpTzvavHCVjgxyQo7Oa3h3cXUgMSBIid6mdlEZwuRQGLRioIv6Ia1rAru+nrU3valgjuqpkSVmfstkSQFWqtoHKufwyXaEPrlAsE/1qBgw1uVDfaJpLuDYlKtAasQw== 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=Ds2C6hKBCPm3LMFGvWFrTQmYNyEijOJ3/DIUhvifx8M=; b=GFywJp0jLkZBOgm/88WhHd7N/gTvX2dXTMHsm9uCqcMgdxzUqfNQKga2b0fGlBnqkySf4t5mr+/BF4Cdya0is0H6iGl/pFqB8QhQOaziuF4v6yZMmumFZ5bT1YPaiiAuZOV0yP/mQB9aF+loZb79WYx0ySw7WVzXYVYpTlKKd1ujgH56asLAiUTcATxt+IQ4N6gmKTcW5nKCZWHMDNTjuYyYtjE5ojvqlM5mYBzisFcOGnX20CEFy/hoQYkAIyJCIlO86/gPDFxVWKTI4WMQtNBATsTl2NCNYdDao5uAk6njQizfHeOM0xQ1noL/s3lt6HlXW31pbHv8KMrlh0zJoA== 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=Ds2C6hKBCPm3LMFGvWFrTQmYNyEijOJ3/DIUhvifx8M=; b=chqsM+7/CYkrcvM0BdccFmEqhz7w1V/wZBOz5jHDoIekgAgX1BTLtjYa7WfZv00QfKC7Cw+6lkQQBqGrZ6Gb07RYrS6Z1q8IznXxSlvqxhfLE4o79mmr1w6f0p3gV5spx+K0a8aSX730g6Lyq6XAoEYAtvToXAfBrOHeIzhoP8w= Received: from MW4PR03CA0162.namprd03.prod.outlook.com (2603:10b6:303:8d::17) by CY4PR12MB1752.namprd12.prod.outlook.com (2603:10b6:903:120::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.18; Tue, 28 Jun 2022 00:15:29 +0000 Received: from CO1NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8d:cafe::46) by MW4PR03CA0162.outlook.office365.com (2603:10b6:303:8d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17 via Frontend Transport; Tue, 28 Jun 2022 00:15:29 +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 CO1NAM11FT057.mail.protection.outlook.com (10.13.174.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:28 +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; Mon, 27 Jun 2022 19:15:28 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 12/14] tools: update test_hmm script to support SP config Date: Mon, 27 Jun 2022 19:14:52 -0500 Message-ID: <20220628001454.3503-13-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: afe1ffe5-a0ac-4f9a-8fc3-08da589b4ec9 X-MS-TrafficTypeDiagnostic: CY4PR12MB1752:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4PoYjEUcAlbxZj+TO0q4e4jAxfTSJY5FFy2DNI43ZLLheh0t5Me60bILIJoHW50lmTjYJqMeMtPnNFEfS82h0dwzqWnQm5ORfX2l3D99DXXJ/e/gr35ovKZKXyJ79UPNS5GGT3os0/Y3tdsOTS4PNY1T0KZ4xompIUcGwuIEdMCPcQpAAwY1C4PkekSkGkBZ68NIKTXa4IXa5EKxEk7AzmUlXQWT+VK6X4rR5gSn9Sfjmddz7I1uqnwHLz/pR3KkldHbWGqPTQP27QjY1Tw3u7tCVVYwjcKCT2cavK41E/cdYxiDhujdvqj18hHJPAeLVIfzyIJeP8jg+8vYn5PDP2EaCr/QE46EI5wc37ckk+CzQnUDCdXLx4W2IyfEE1IPdry5JwUqeNQD5J6wrKqODGI8OyigO9o/4Jboks9816oIyCtjaQyX9JYfYn9s4wWmdSZtWqB6GzWqxaq7BWJGhEWWqBMCUs9e/Yust7rOvlCkjlWrsXj1pSwpBKyMhmIm4r7wFmH3A8N2j3LglPT0Vn0l1lM2ALq+oHxdYnUXxCZq7f9p3Lw4SL9zvhjq4rbrC1T8dcg76RUf66jdNCHNGyWznocWuoHk2LAsMeRKNZeRDnHiE7pYfgZm10MUNvBO1FZaMr2lBJsw6O8xbDcI7S073fsCCKT1hHywny2g+mKAIrHYm/dqPvYVhILwz3rYNTD4yraBU3kZUOGsUsPGkqmou7nZXqxEPKLBufRKuvz+p5/kWOfnJqlLeCjZSN7MmhMfzwnyoNDdKuwqYfbsiSBDJSrspEKdXpwMR+LeoiFdi13Nb3cb49HDi3BmRIWyykpx/nGxfRUwUzhafZMZPw== 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)(346002)(396003)(39860400002)(136003)(376002)(40470700004)(46966006)(36840700001)(16526019)(186003)(41300700001)(336012)(6916009)(7696005)(83380400001)(8676002)(426003)(6666004)(47076005)(54906003)(2616005)(70586007)(1076003)(26005)(81166007)(36860700001)(356005)(82740400003)(40460700003)(44832011)(4326008)(36756003)(82310400005)(7416002)(5660300002)(2906002)(86362001)(478600001)(8936002)(316002)(40480700001)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:28.9479 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: afe1ffe5-a0ac-4f9a-8fc3-08da589b4ec9 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: CO1NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1752 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375331; a=rsa-sha256; cv=pass; b=qYfyI11N+vf4Klry5cLB2hlrnSd0V5yE4sMblITZkIq36mlePhECVXK0orU5JC+a+wiQfj PIG2aVthHf53FQWGuWUwM2QU2vh36/uGAk3bSgwCrPjS1JpFRhU/qkZODlB60aL7k6Q/LD pXMf3ZAm0LLhm1FHB28QXVz1skv5Tao= ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="chqsM+7/"; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf07.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.82 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=1656375331; 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=Ds2C6hKBCPm3LMFGvWFrTQmYNyEijOJ3/DIUhvifx8M=; b=R4pGYs2y69MkyRflA2UTfT147aYVwT8mVKqf1mLFWmX/OzTrqRHmUnP5J01v8Sy3G/FqhI t9akl2noMI7lgMfM8AYm2vXH6ZJptkQp11P+Gt2xsB+FJ6NHclBmlRjgEgGJ1mVargrACh C6mMMnoj6XHS0PHarIABBpPfxKURpEY= X-Rspam-User: X-Stat-Signature: b4cmg3gw6j1b4m5if97obfm96ywc5zgp X-Rspamd-Queue-Id: 66B2240038 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="chqsM+7/"; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf07.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.82 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam03 X-HE-Tag: 1656375331-625633 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: Add two more parameters to set spm_addr_dev0 & spm_addr_dev1 addresses. These two parameters configure the start SP addresses for each device in test_hmm driver. Consequently, this configures zone device type as coherent. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Popple Signed-off-by: Christoph Hellwig --- tools/testing/selftests/vm/test_hmm.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/vm/test_hmm.sh b/tools/testing/selftests/vm/test_hmm.sh index 0647b525a625..539c9371e592 100755 --- a/tools/testing/selftests/vm/test_hmm.sh +++ b/tools/testing/selftests/vm/test_hmm.sh @@ -40,11 +40,26 @@ check_test_requirements() load_driver() { - modprobe $DRIVER > /dev/null 2>&1 + if [ $# -eq 0 ]; then + modprobe $DRIVER > /dev/null 2>&1 + else + if [ $# -eq 2 ]; then + modprobe $DRIVER spm_addr_dev0=$1 spm_addr_dev1=$2 + > /dev/null 2>&1 + else + echo "Missing module parameters. Make sure pass"\ + "spm_addr_dev0 and spm_addr_dev1" + usage + fi + fi if [ $? == 0 ]; then major=$(awk "\$2==\"HMM_DMIRROR\" {print \$1}" /proc/devices) mknod /dev/hmm_dmirror0 c $major 0 mknod /dev/hmm_dmirror1 c $major 1 + if [ $# -eq 2 ]; then + mknod /dev/hmm_dmirror2 c $major 2 + mknod /dev/hmm_dmirror3 c $major 3 + fi fi } @@ -58,7 +73,7 @@ run_smoke() { echo "Running smoke test. Note, this test provides basic coverage." - load_driver + load_driver $1 $2 $(dirname "${BASH_SOURCE[0]}")/hmm-tests unload_driver } @@ -75,6 +90,9 @@ usage() echo "# Smoke testing" echo "./${TEST_NAME}.sh smoke" echo + echo "# Smoke testing with SPM enabled" + echo "./${TEST_NAME}.sh smoke " + echo exit 0 } @@ -84,7 +102,7 @@ function run_test() usage else if [ "$1" = "smoke" ]; then - run_smoke + run_smoke $2 $3 else usage fi From patchwork Tue Jun 28 00:14:53 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: 12897314 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 B68B6C433EF for ; Tue, 28 Jun 2022 00:15:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 880BD8E000E; Mon, 27 Jun 2022 20:15:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 720F78E000F; Mon, 27 Jun 2022 20:15:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5495D8E000E; Mon, 27 Jun 2022 20:15: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 312CC8E000F for ; Mon, 27 Jun 2022 20:15:33 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 09D2C340EE for ; Tue, 28 Jun 2022 00:15:33 +0000 (UTC) X-FDA: 79625725746.27.2AF6338 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2054.outbound.protection.outlook.com [40.107.243.54]) by imf24.hostedemail.com (Postfix) with ESMTP id 8DCC718003C for ; Tue, 28 Jun 2022 00:15:32 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KBz57H87qwXpBAHo1mHMH8Wh/J3slfRMbxA9lv9WlgSw7Dd9C5u9VoHRFOkENOOGJGLIWN5QSEdu3yqqgxxqhkDnIQJY+XOq57gKNDcnXkKTxGjQbz8Tj6QHgperCJu8dJVELrVkv/fU20vhoSEJVudLY4NNOUIpLGlWAk1ZLNZQrXMYfj8MnKABOb16WjVIA67Mj4E82XSx6InthBw1xcWhq7oFBqR6g24XUfp1AEyQ+xQjO1jyTPB6Y2t/oHz5g9sY1OS2cqtcEE9QRjflvTt+VQCymNAJ07Upw6oJ22ZN6sYJV1jCxKb35G+EDAx8K4O+emGZ31jOy0nNpWgquQ== 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=GP3ikngykfp62hqgKGCY9CKncoZ/5EVzq4BZbbmWmCY=; b=agOrR8A8jDq259B5RWFo5Opwinjn+PnAvuJkC3kutsr0C4SlU3F6Tkycg9u1V9Zwm3Yxu0Bu2oQiAC8WK8j5o1GYrYXXQwVi+jK8hxUTkqKljKdVU3ARM4CDcdo44a9sPLyuLJGM29F4A/kIEtTtKmY3cwb2ZsceKMSg+6ssVT7kFKh7QOu8S/wBrKc8YlHq2CO6JjZ9H92tUIUGvRr8M0pMe1tgc/EAl1wL9bO4DVWGl+8IShKLCmU670naHqFsUt1QjGPLlWIxUGYH8v2OL06Ib7zzwwvkm90sLbdBcM77QOjAx2ZKymiRpWt0C+gTvx5jfDzipk3ECVLU04JrUg== 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=GP3ikngykfp62hqgKGCY9CKncoZ/5EVzq4BZbbmWmCY=; b=G6lxvVYdPMJ2rH4uUqKCdGDP6pH3Zmpl09KZNXiRx3On6SlqW/ivy3B9OJ/eZyDVF358oj4H12FH3oahPMZjMhmbE+9g918Lx7MUble3iE1xBpYJpMueO188ip5GEHvP2/IDvTQcAT8ecM3XvosI1ST4E2Vi1C35u54UQT0W5T8= Received: from MWHPR15CA0057.namprd15.prod.outlook.com (2603:10b6:301:4c::19) by MWHPR12MB1600.namprd12.prod.outlook.com (2603:10b6:301:f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17; Tue, 28 Jun 2022 00:15:30 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::d2) by MWHPR15CA0057.outlook.office365.com (2603:10b6:301:4c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.21 via Frontend Transport; Tue, 28 Jun 2022 00:15:30 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:30 +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; Mon, 27 Jun 2022 19:15:28 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 13/14] tools: add hmm gup tests for device coherent type Date: Mon, 27 Jun 2022 19:14:53 -0500 Message-ID: <20220628001454.3503-14-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: d70d9523-0b21-4b89-9269-08da589b4f83 X-MS-TrafficTypeDiagnostic: MWHPR12MB1600:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L0rE9rkuu3OrNG5ucWEcmA/fXh3OexsxLG82bEsJSFXOyYON45H8UtvUCc+EngKqomAXltN5ACBkQFWOxY6dMuhfsHTKURDocFReMn1Uf82285bqu4k3Oby7hTWAbbzOxn/tQOJQB8zLfTuPgQNdEg2xt8dHfJa4PRjQaaBTvf3ZufDFLZpnqtEgqN4ClCINY0az2QoE4MW/XTMYK4vm/3jcB/4J/RrTuDnDZJF27rnJhwM411zqV9cv5ZE9zSy+Hvcibsmrh77TWm4vTRu7M+edzPl4FU7MJyWw1swq50Sl0i+mEGhgIQpo2bXrvSEdTPCGA1UZoERiiry3XcDofk19MfnuaxCdAkH/mfed/5Qy1tGQa9XZNn1vWmYP7Jrd4UOjuE2mIvZMDdu8oHG7b9PIgTp6Bj9rT3PlNymcB0jDWckglGc3yGHD45AxUvGjhnan2lQeNmaED5oK0Lh898p9pYWBssIF3/zENmfKfhkzkPUpB73s1smsZxd07E5JLbB8M6XZ0kfsf6xJW5ABjqb9/3PJ1wOuZhFok/5qo1Y/3OPRKQ8UcL469a5UucJE+NCyGqx3QH5NdbFxHgr7SlJyK77H+sXtLwI0tWdpKQ0+bDNfppeYc5s+zLEP0Xxpyu3YjeyXg3UufAGY+Xr0WpFOyOJtymgFv77fbpfm3V4z1P8PZYE8Vixd1aubV94DDjmdC1PL/ZaZLrX3WK3HaLxZDsP6ymPV3WVoDP7ArFYNq5hvcO/IqN25l0m9I5+Jcv5Yxdi1z67qJmbMbe13ocUAPek72/f5GV0KwcWCRPqFj5uKt7pp7UHHoBzqOSMCIDIRYY7tZoa/QS/IH6njfw== 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)(39860400002)(346002)(376002)(136003)(396003)(46966006)(40470700004)(36840700001)(316002)(336012)(16526019)(41300700001)(36756003)(2616005)(44832011)(6916009)(54906003)(47076005)(70206006)(40480700001)(8676002)(478600001)(4326008)(70586007)(7416002)(186003)(1076003)(7696005)(8936002)(26005)(86362001)(40460700003)(81166007)(6666004)(82310400005)(356005)(83380400001)(82740400003)(426003)(5660300002)(36860700001)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:30.1669 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d70d9523-0b21-4b89-9269-08da589b4f83 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1600 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375332; a=rsa-sha256; cv=pass; b=q6/uOrZjPrn6sV2/AQK/J8VrereyFyHmwQVC24bv+ob/sAfjdkfNuQ17vhdqw5CUBs7608 DI3g/xbfxna1iuvIghbm/4PxQ2Is0ITgIgaLpQLn8QUDxrbMfIgM/WOe0L+ie7M8TafCR5 oCk9iUqo7pNbpJUsAvDMLQT2ybbJJvo= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=G6lxvVYd; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf24.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.243.54 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=1656375332; 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=GP3ikngykfp62hqgKGCY9CKncoZ/5EVzq4BZbbmWmCY=; b=Nh9B/C/4DyPxoL64Bx1Z+GZ98jjFXc671NB3HjYFbLshXsTEZXQ357Ibna6yQ9ZaOpF3tj A8VIXjUtNxggoPTWrH9ebQgJzOb03L8K/47ys09jCsUu5dXTcxV5FZFn0ekePhsjcbZM22 Jj/MWiomimvjWuVb0RmkfY+JHb02Jq0= X-Stat-Signature: dyc9qmd1bmc3cqyqmuxmuyzkh7soc45k X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8DCC718003C Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=G6lxvVYd; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf24.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.243.54 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1656375332-27234 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: The intention is to test hmm device coherent type under different get user pages paths. Also, test gup with FOLL_LONGTERM flag set in device coherent pages. These pages should get migrated back to system memory. Signed-off-by: Alex Sierra Reviewed-by: Alistair Popple --- tools/testing/selftests/vm/hmm-tests.c | 110 +++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 4b547188ec40..bb38b9777610 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -36,6 +36,7 @@ * in the usual include/uapi/... directory. */ #include "../../../../lib/test_hmm_uapi.h" +#include "../../../../mm/gup_test.h" struct hmm_buffer { void *ptr; @@ -59,6 +60,9 @@ enum { #define NTIMES 10 #define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1))) +/* Just the flags we need, copied from mm.h: */ +#define FOLL_WRITE 0x01 /* check pte is writable */ +#define FOLL_LONGTERM 0x10000 /* mapping lifetime is indefinite */ FIXTURE(hmm) { @@ -1764,4 +1768,110 @@ TEST_F(hmm, exclusive_cow) hmm_buffer_free(buffer); } +static int gup_test_exec(int gup_fd, unsigned long addr, int cmd, + int npages, int size, int flags) +{ + struct gup_test gup = { + .nr_pages_per_call = npages, + .addr = addr, + .gup_flags = FOLL_WRITE | flags, + .size = size, + }; + + if (ioctl(gup_fd, cmd, &gup)) { + perror("ioctl on error\n"); + return errno; + } + + return 0; +} + +/* + * Test get user device pages through gup_test. Setting PIN_LONGTERM flag. + * This should trigger a migration back to system memory for both, private + * and coherent type pages. + * This test makes use of gup_test module. Make sure GUP_TEST_CONFIG is added + * to your configuration before you run it. + */ +TEST_F(hmm, hmm_gup_test) +{ + struct hmm_buffer *buffer; + int gup_fd; + unsigned long npages; + unsigned long size; + unsigned long i; + int *ptr; + int ret; + unsigned char *m; + + gup_fd = open("/sys/kernel/debug/gup_test", O_RDWR); + if (gup_fd == -1) + SKIP(return, "Skipping test, could not find gup_test driver"); + + npages = 4; + 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); + + 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] = i; + + /* Migrate memory to device. */ + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + /* Check what the device read. */ + for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); + + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr, + GUP_BASIC_TEST, 1, self->page_size, 0), 0); + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr + 1 * self->page_size, + GUP_FAST_BENCHMARK, 1, self->page_size, 0), 0); + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr + 2 * self->page_size, + PIN_FAST_BENCHMARK, 1, self->page_size, FOLL_LONGTERM), 0); + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr + 3 * self->page_size, + PIN_LONGTERM_BENCHMARK, 1, self->page_size, 0), 0); + + /* Take snapshot to CPU pagetables */ + ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + m = buffer->mirror; + if (hmm_is_coherent_type(variant->device_number)) { + ASSERT_EQ(HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL | HMM_DMIRROR_PROT_WRITE, m[0]); + ASSERT_EQ(HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL | HMM_DMIRROR_PROT_WRITE, m[1]); + } else { + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[0]); + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[1]); + } + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[2]); + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[3]); + /* + * Check again the content on the pages. Make sure there's no + * corrupted data. + */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); + + close(gup_fd); + hmm_buffer_free(buffer); +} TEST_HARNESS_MAIN From patchwork Tue Jun 28 00:14:54 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: 12897316 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 E137BC43334 for ; Tue, 28 Jun 2022 00:15:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 23DED8E0011; Mon, 27 Jun 2022 20:15:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CB778E000F; Mon, 27 Jun 2022 20:15:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E99148E0011; Mon, 27 Jun 2022 20:15:35 -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 C90408E000F for ; Mon, 27 Jun 2022 20:15:35 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 9FA601205AB for ; Tue, 28 Jun 2022 00:15:35 +0000 (UTC) X-FDA: 79625725830.30.8BB98EE Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2064.outbound.protection.outlook.com [40.107.101.64]) by imf29.hostedemail.com (Postfix) with ESMTP id D6DA9120032 for ; Tue, 28 Jun 2022 00:15:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PTJaNPkXxJECM1mmbxif8iMSIYaFjIU2sBnej5cKLn7w2gUDBNhs0ha+PXj1SrbSb6tNi39JpsAPUzDS4CnghQMRBkOLJDoIwEGbmZk4QWNXuIoOjtaYBHnWobVU6KIAYUz9ykjaDOpctc2KuUaU4KMwV865gSwUHI/18XseErGIvzPbcEg5W9dTA107ihYBNyru5iWyF4EbB/Acjy+Y62QBOokpwJyv0TolIqJg02JW+0mhghZKBXIFWnZTb3wHgr98nhUGTAKa3BKlz+YzT/285pouLPgZdiWIv25cVQkJbaYlcNGS/Gon9hXlGEhS9t0IrAgiLwqNtFqU864atg== 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=ghINYxYAaP35msqhqy+uXLJjlA8u9eNbkgf4YFEOveA=; b=IgupSAdNkkFXpuCFifL1ydvkSxkrLrdoyCgFXIRAcnFpTG1bfSMgyYB24wWxed2QzWEIB84m05OjhkO95ti3eCw91yb8gDEGUROv2xZ6WI84+IEb1RLYw+99diz22OU5ZBS91adPVS9EbCTfAMpxjnZe0XoCMoNC13CyVWuFFPZ9AZI+q0+XQ3OHua0m8il/7tkR1Yal17hbiqB/m7DLGuApPG0t7mIZowchyNLnhiehsfnU0O35KRkdaRrxhPz8qt1xT04x7jAQIAp5rF1jLh2apPwW5X3kGhTH6XGoJ6/xuWvR/v4xalQyAPHq+rSr5RJauLHTaHqoExPBXIK6xA== 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=ghINYxYAaP35msqhqy+uXLJjlA8u9eNbkgf4YFEOveA=; b=yXISrZtzHgk5rLZehdPClC8Vh1JT6Sm5ePwXzLkBkfDEgQx1u9U9BFeYDQQdSKZB/cOTmdy3GWQbYpXLLOQE8fqGl0pGyrmeh3vKKQKWwSeQX9SLaeJDIKv7Tal+mv0tRWn9r+oOS5iVgLcLFvgAe2P4ePR+MotuNrDrIy3CIe0= Received: from MWHPR15CA0051.namprd15.prod.outlook.com (2603:10b6:301:4c::13) by DM6PR12MB4012.namprd12.prod.outlook.com (2603:10b6:5:1cc::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17; Tue, 28 Jun 2022 00:15:31 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::2) by MWHPR15CA0051.outlook.office365.com (2603:10b6:301:4c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.21 via Frontend Transport; Tue, 28 Jun 2022 00:15:30 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Tue, 28 Jun 2022 00:15:30 +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; Mon, 27 Jun 2022 19:15:29 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v6 14/14] tools: add selftests to hmm for COW in device memory Date: Mon, 27 Jun 2022 19:14:54 -0500 Message-ID: <20220628001454.3503-15-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220628001454.3503-1-alex.sierra@amd.com> References: <20220628001454.3503-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: c37df3f6-be3d-440e-6576-08da589b4fd9 X-MS-TrafficTypeDiagnostic: DM6PR12MB4012:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XrjNh2KlBDpqiIpVSINi8xseJUH5NoI9P9/R3Dc6llXKF5EC3t7CRojNU5d24mHAdKi4GoeDGu7dz3R9ZHJ1dS42evo0JTCZsMwaPzsqko+8/eJQv3BtsFrqo9o8YvRbPDYhlbb01NRzRI8ZxVc/rT+DHGGuTf2l6Iq4kuEIHBI46VYTslHeHfjRjOxD10U0dV+QUv8/oDbaOm5dMdwhJowjud7DD2mcRTTzY4d5Pzenbvjpl3ptjbg6E1ou63btxrZ5RFXTfSxHP/NLQPS1+7NAwWnCyq6UrQpibwMSuprl0QoJ2MWsR65igcpAGwR47gaz8c8W7Un1tCo26GhgsrelNcl4baf7ebBaR7/XAyhXDGCESgH0QRylihEK+fyE955lTE0R6FWbT/dAuJg/VX+Xvzb353LXwQ68leb/Jv7x+RfqwVmtmibNIUN6WRWcZ3ss9G13L73IAOEDnAXmirq3K9ypO7KtLz3d3PoFK7t6QxrgP40gbju32zioZ7QtE+vWhpV5o75grl3N/WzHOWqH8lF2GWupv1eg0rWiWR3k7gREXYMQsP+aWP9vBiY+d1bNh3GYL9n78Boet0Wfv/SKzlvWNaaFrA0WUgSgnw7bWfF6By2Gmzj65+KnbfAJTsDziM5hfunUYbYwhmhH9TZrWn8y6REAtf4CEnO43cz0EhtO2m4TQt8AcZxGp9p5sDmHjdaaG0/M9aKFnzgqLGiLuivByhVC8C26tW2R1/TGRKTtnlbv3lFkZBsVcgN5zO3g2X60Ogblpx0/TPdA9pjeJe/m57la8ncWEzizATCsIrtR1+CDFonjFX5UNBMdiYzWOXEuz6PD36+U29dXHg== 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)(396003)(376002)(346002)(39860400002)(136003)(46966006)(36840700001)(40470700004)(478600001)(2906002)(44832011)(26005)(8936002)(8676002)(70586007)(36860700001)(4326008)(7416002)(86362001)(54906003)(316002)(41300700001)(2616005)(6916009)(70206006)(40480700001)(16526019)(336012)(5660300002)(186003)(81166007)(82310400005)(82740400003)(6666004)(47076005)(7696005)(426003)(1076003)(83380400001)(356005)(40460700003)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 00:15:30.7294 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c37df3f6-be3d-440e-6576-08da589b4fd9 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4012 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656375334; 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=ghINYxYAaP35msqhqy+uXLJjlA8u9eNbkgf4YFEOveA=; b=PyMzQLi/zoefJQQRIy/PgfbaoYOOpLJ5XxVZVtgIoUE6Seb4SGiyI18mFQig0X1pPqzV0e S/Rff9RJDrSIDBv7lgqNN0vua+1a8oqgOhgnaRCMJP4GFzTVqxWZwkC+kDJtpH8Kj5hYch zxistD53vAaKDOIexr8FChb4Wlfy9sU= ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=yXISrZtz; spf=pass (imf29.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.64 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656375334; a=rsa-sha256; cv=pass; b=JMxE/9JpsfwideL760DdC4LMrfp0DNfFC6VLidvML/O62z8GZxEG/glhiKAHcrrcOXMw7A dfudJX2ivWXlvv2iLIYh1xdnClmRnVE8ni9UN9cb6n1XIgwrXO6JnbP4G2Sb/RELKA4Qyf JoMrAm0lrv9G9B2OnqyUcuvZeRvXqhU= Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=yXISrZtz; spf=pass (imf29.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.64 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: hem9p3j4z6qfje8wah1pq4b13zairm5w X-Rspamd-Queue-Id: D6DA9120032 X-HE-Tag: 1656375333-643628 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: The objective is to test device migration mechanism in pages marked as COW, for private and coherent device type. In case of writing to COW private page(s), a page fault will migrate pages back to system memory first. Then, these pages will be duplicated. In case of COW device coherent type, pages are duplicated directly from device memory. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling --- tools/testing/selftests/vm/hmm-tests.c | 80 ++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index bb38b9777610..716b62c05e3d 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -1874,4 +1874,84 @@ TEST_F(hmm, hmm_gup_test) close(gup_fd); hmm_buffer_free(buffer); } + +/* + * Test copy-on-write in device pages. + * In case of writing to COW private page(s), a page fault will migrate pages + * back to system memory first. Then, these pages will be duplicated. In case + * of COW device coherent type, pages are duplicated directly from device + * memory. + */ +TEST_F(hmm, hmm_cow_in_device) +{ + struct hmm_buffer *buffer; + unsigned long npages; + unsigned long size; + unsigned long i; + int *ptr; + int ret; + unsigned char *m; + pid_t pid; + int status; + + npages = 4; + 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); + + 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] = i; + + /* Migrate memory to device. */ + + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + + pid = fork(); + if (pid == -1) + ASSERT_EQ(pid, 0); + if (!pid) { + /* Child process waitd for SIGTERM from the parent. */ + while (1) { + } + perror("Should not reach this\n"); + exit(0); + } + /* Parent process writes to COW pages(s) and gets a + * new copy in system. In case of device private pages, + * this write causes a migration to system mem first. + */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ptr[i] = i; + + /* Terminate child and wait */ + EXPECT_EQ(0, kill(pid, SIGTERM)); + EXPECT_EQ(pid, waitpid(pid, &status, 0)); + EXPECT_NE(0, WIFSIGNALED(status)); + EXPECT_EQ(SIGTERM, WTERMSIG(status)); + + /* Take snapshot to CPU pagetables */ + ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + m = buffer->mirror; + for (i = 0; i < npages; i++) + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[i]); + + hmm_buffer_free(buffer); +} TEST_HARNESS_MAIN