From patchwork Thu May 5 21:34:24 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: 12840192 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 D046DC433FE for ; Thu, 5 May 2022 21:34:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 520106B0073; Thu, 5 May 2022 17:34:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CF196B0074; Thu, 5 May 2022 17:34:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FA586B0075; Thu, 5 May 2022 17:34:59 -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 1DA986B0073 for ; Thu, 5 May 2022 17:34:59 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id EA16361389 for ; Thu, 5 May 2022 21:34:58 +0000 (UTC) X-FDA: 79432994676.16.9D8786C Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2086.outbound.protection.outlook.com [40.107.92.86]) by imf13.hostedemail.com (Postfix) with ESMTP id 3C4E020006 for ; Thu, 5 May 2022 21:34:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xp0USbcOC2oFOdwXYCqWZzUltHaGai+2U4DXOjPpoJcY87s7jdMw1gRQW7Rz42Z6mQhnCRtDgULY9xm1ge/zM72egKl3Z/+eycS27KDZ9xq9JOXUHBeKIwih6UvygEJBimLfmoBi3oG3IVzUTSrpPX0QMMk8XZb3HB1iZT7V1m1gyqSGIZlA5ZiJP6sirshwAMDeyGGhlLbeXySduTDQBO9J7oiEs36hfdQF0hA9dAl1FETl8Y+Jd1m3WnGQm3reriNIuFiXALYEy1p4Zot6y45pWfKwTYpVMzAy9ZcvRldwe2fpjUZVQG/kFNrj/oTcEcPCRQie2AsdiWgZYFL5mQ== 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=5xvWy4v01Zl4AyNww5RhtfNWE1yxChL7uJIdY1JtZ+k=; b=dle8UdFSmPuWyeg8SBmcRNTLkW5Cl774rQQzYPZBXTizUbsHMq3YM1mYEmQNv5v+c2dlsYlzwyMDo6MvXIHHneT/h+7ux08bTxt/ncqQmEcwi6O1GKoQIAdm89hyGuM7BxSG+qsDMxywNHPlsLLU0/5EFWIuk9NZsDmlGgKWFatJL+n5P6zuLLAA4PeIXj273ZwPtjKB4aUkBz2Imkzk7HYvAna2z02d3zrCdCxHRry2mckR+we93UGaAw4K89kmvCWsY6gD7y2KKtSl5b+gzeNyO3l0WtBlG/9l/g9l1lj8KmjauIMNx1YxDYwBMpS7IPsIRVKLVg+LM5ppBdqHHw== 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=5xvWy4v01Zl4AyNww5RhtfNWE1yxChL7uJIdY1JtZ+k=; b=VCRGNR4DMlVgk2VWkuHZjxvCbIRR68UxY2GegnQe9o2TwzDPR8Q+xSYryu3y2BK8wsVb7NA5u4YV6x6y5i3BU1tpU+TPh7gMwGNjqssCOwvXues7eVuYWPrfl5Wv/ZxqFn06IZaQ0kwaPlJLJhNb8Lxk8XekaFiQuggOcpoZtkQ= Received: from MW4P220CA0024.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::29) by BYAPR12MB3447.namprd12.prod.outlook.com (2603:10b6:a03:a9::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 21:34:55 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::fd) by MW4P220CA0024.outlook.office365.com (2603:10b6:303:115::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Thu, 5 May 2022 21:34:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:34:55 +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.24; Thu, 5 May 2022 16:34:54 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 01/15] mm: add zone device coherent type memory support Date: Thu, 5 May 2022 16:34:24 -0500 Message-ID: <20220505213438.25064-2-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 2c8c29df-6b20-400a-95ee-08da2edf18e9 X-MS-TrafficTypeDiagnostic: BYAPR12MB3447:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S3s4gjknHUDlESTIz9Sexnbn6qX8fLHi2YDdoXjULzgbSedSV/AK1CH6x5ZFLiufTgs8ucsAlKjbwZDlLheCmT7v9jOS3U8PSIoMVy1NoWPS6P0WRZ3OXg95QdN0yilxT3iNujZYa7Li8DC3cNan6MT0ZgjFixkGvBouSQzrKm/EI+4YClXCSgZflIQ/0AEpgsB8YfCqO/eQ4kH7q9kT5gpPG8bhBFPnj7A1/p1ebfIZefQwzITfvA1I/IkXjPoKAjSQZ6k7wN73WxKmY6NaRTqJWC26p/LK7pKdkd//y31fDedBYYS9AT/yEZFcJcj2ILrQG7AMZj+n3/Qe76c/tGIso0ffmCUjeWQ2Ob8bLq9PI8ll6he+TYlSwCBM5HtxHIpdZDewRHQDiQakY1DQKkhUcDj3OV1+km1NvrqqxKfxjrdbVJ8bVMdlXUPdHTmAC7rDA1Jx0kvRueTf6BGQHFOJH8KE/nnxdKCVZlc3BxP9cSU2m9WOf2fhK9rW7BJJmukydvOZMyB61+3x8OAIa7aKJcr+oarvWWQOSF4yFjoS/7HViy4HHR6eSAK2tJECnY8xIWznjSra4VOMUH6DzLAXtJ+yd4XoV4WIWum0TOx/HfmFL5g3XRILFnIVvmRyceQTDiV3LwFuy02ct9rNBqLG9cYjoRYOqGz4jffZmPiZ7+ka7RxydGH9AuxKU/5GIxxBdyo1IwilNkbnw/Y6FA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(8936002)(4326008)(36756003)(1076003)(36860700001)(5660300002)(6916009)(8676002)(70206006)(70586007)(6666004)(54906003)(2906002)(508600001)(82310400005)(47076005)(40460700003)(7696005)(26005)(356005)(336012)(81166007)(83380400001)(426003)(186003)(44832011)(16526019)(86362001)(7416002)(316002)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:34:55.5174 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2c8c29df-6b20-400a-95ee-08da2edf18e9 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3447 X-Rspamd-Queue-Id: 3C4E020006 X-Stat-Signature: kgmc1dc78ukxa1e11ymcdxm1z38npjbt X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=VCRGNR4D; spf=pass (imf13.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.92.86 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam09 X-HE-Tag: 1651786485-521766 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 | 3 ++- 6 files changed, 48 insertions(+), 15 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 598fece89e2b..3e1f97c9fdc6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5629,8 +5629,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. @@ -5664,7 +5664,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 27760c19bad7..75d013df86a9 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1695,12 +1695,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 af0223605e69..471ec84ed82b 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -314,6 +314,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 70c7dc05bbfc..7e267142ea34 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -499,7 +499,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, @@ -575,11 +575,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; } @@ -682,10 +679,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 fedb82371efe..d57102cd4b43 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1995,7 +1995,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 Thu May 5 21:34:25 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: 12840194 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 2F0CCC433FE for ; Thu, 5 May 2022 21:35:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1ECC08D0001; Thu, 5 May 2022 17:35:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 175076B0075; Thu, 5 May 2022 17:35:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAF938D0001; Thu, 5 May 2022 17:35:00 -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 AFC616B0075 for ; Thu, 5 May 2022 17:35:00 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 964C8613B7 for ; Thu, 5 May 2022 21:35:00 +0000 (UTC) X-FDA: 79432994760.17.59AD7CD Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on2076.outbound.protection.outlook.com [40.107.102.76]) by imf10.hostedemail.com (Postfix) with ESMTP id DCCF9C0087 for ; Thu, 5 May 2022 21:34:42 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VVJqdS99E1wZ/fYUQGXYDxkim1W89LAUgTZWkCp+uxKypjJFtHmgaiXXrwXdF5qVx4Pj90328CP/46UVl/X8u1q4LkhrsPBfDFsd4jSm/+yDkFcNqZCO6C2ByJWcimeSSPikLHvNzfrDQBYlFXbiq4wOItYXLkBMcYoC2eqXTo9LAGxn0Gw/vSnzUQaKg2oFrXVgE79ZgRie/lHhtqYwc7amZZ1ZWAkS/hikKoANATiYTaYgi32ISmBeoW2YNDe4EdTRDnSXyofCVqHWiS1Lw7y2TqWcOxU0+jGIcV6klV8/9uR+YHXQR/DAEhnfejeRT1zJ4HhOghCdCsVhcuNiPA== 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=vW0Kci1BxH/G6MOqRePi9dIvH+J6rgyknG8pfmabAb0=; b=YkPFAi2Na6rgBG42PT47EFBBwKkqpZfG+wwO9dZo+awyCaXg1KD+1IIRWjorQfDjvXQiMSMyGi9C0TIb6m+F24mirSzjBCc1v0f6APXUDdjyEjOhdYYxLv2IcTEdAA9UJ/lz/PkzykIFJaGg2ikvJGLVAks2dP2jCbdLvFw+vTPG5RthqKueibI/GvhrWC/8HWjMbZoVFZT+pc33olUTw3caSKhSnoCxO6ATtI1jg82Km//UbkRv17Jne7tQOmOrEKZv0fYn7vewhwn7FwnJk6sbt3dsNBZoftZthi4mljOWIhkHpe8/MAsF9Nj/pDZGNstPtJzOX0Xb2KPd3hoPeg== 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=vW0Kci1BxH/G6MOqRePi9dIvH+J6rgyknG8pfmabAb0=; b=TGcc1AwLaagePAHbESpUJM4QbC20l45dQ+ISIULHbsmRvMIzfPKvAZpjeG5R6TymhDD41ThQEBJwsu9mXhQz22zoLBcIHmU+betfK1pnJvBxKETeRfSdXjPTlRXCduRuI+C5HNKbFtSEcxCnfREQ9T15lbVuYJv66awWf8PBpsw= Received: from MW4P220CA0019.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::24) by SA0PR12MB4367.namprd12.prod.outlook.com (2603:10b6:806:94::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 5 May 2022 21:34:56 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::e) by MW4P220CA0019.outlook.office365.com (2603:10b6:303:115::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.12 via Frontend Transport; Thu, 5 May 2022 21:34:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:34:56 +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.24; Thu, 5 May 2022 16:34:54 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 02/15] mm: add device coherent vma selection for memory migration Date: Thu, 5 May 2022 16:34:25 -0500 Message-ID: <20220505213438.25064-3-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 44e4f8a5-72ef-4318-c8e0-08da2edf1960 X-MS-TrafficTypeDiagnostic: SA0PR12MB4367:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oo2Sw0eIgGIKOwOZ7KkTPCe7Q8JerGkFJpNWNgFTi3AcEpdjWyzEzv7YHQrdI4+abpqypkbTw05/F3/If9AX+YCMGFpCTxAlDiP/zXlAp2CibRw68LlOGoSHFL2abtrBwNaTGK8WJl5ksXptSEayIlWfUedu6Lu7sheDjbhIwbys1w+dEacrQKSMy8QK0vMdCKFN+5gwRHEpIy2J8aM1i9u5D0TenDn3SiLV2T1djMZl6bpZZOgE+c+WZ1XZDxq5B0yIqUiESror9e99/wNP4O6K2s5/nIvRRh5XSiKrFwR6FjPEcVclidDr9GTq5z2RzB16UCp1VBqxOnrqhoWeuVbmuVts70h+1xgAfdXIfTc5IyFr7UiwQKWg8ZD0Fi7De5an+uDNSP1GXg2ofFH0+jEGxlpOhZAaw4Ee3ZGrQMDldVE+DPG6hXZSNyg9+WDyiDML1R5JkRWaVgofbu2CQogIL86yJYQxdyWxJbafciJofaibHN60OxKM2o+t3r5EoaivMVX/m88wW0n29qDa7Axw0IyMbqsmL27/nqTkaEKlKjuiZBCAER4DtJDClieNbLR39WnMKnTb1r4FB6jboKF2NK67GIpX9oyDC3Sl6qucGJQht5jvRqZvZzGwhfn95HIUJKG/m0xHOn9i7mGx+PUE7pxDUP5IK1dMVkDco8NfA9SR/DS1EdkSXNki80ukBe2N4+RHuhc8FFMVcD4pYw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(26005)(186003)(1076003)(47076005)(2616005)(16526019)(336012)(426003)(81166007)(83380400001)(36756003)(86362001)(36860700001)(7696005)(82310400005)(2906002)(44832011)(7416002)(356005)(6666004)(5660300002)(54906003)(6916009)(8936002)(508600001)(8676002)(4326008)(70586007)(70206006)(316002)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:34:56.2985 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44e4f8a5-72ef-4318-c8e0-08da2edf1960 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4367 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DCCF9C0087 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=TGcc1AwL; spf=pass (imf10.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.102.76 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: X-Stat-Signature: 3r8hewtzkc9wda35e9parouoe8o4rrp4 X-HE-Tag: 1651786482-521431 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 90e75d5a54d6..a4a336fd81fc 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -138,6 +138,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 7e267142ea34..a0b997935cf9 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 Thu May 5 21:34:26 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: 12840193 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 84AF8C433EF for ; Thu, 5 May 2022 21:35:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C016B6B0078; Thu, 5 May 2022 17:35:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B47B96B007B; Thu, 5 May 2022 17:35:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 917916B0078; Thu, 5 May 2022 17:35:00 -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 7E91C6B0074 for ; Thu, 5 May 2022 17:35:00 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 5BD1E613B7 for ; Thu, 5 May 2022 21:35:00 +0000 (UTC) X-FDA: 79432994760.26.7CE9385 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2059.outbound.protection.outlook.com [40.107.93.59]) by imf31.hostedemail.com (Postfix) with ESMTP id 3FC1D20095 for ; Thu, 5 May 2022 21:34:43 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OZjA1wGQB25BLbjKVnJQyyu2pEGCPwdr+dTRfkW96tkRzlv9by4h9/1xvz9cP3DNLQRPFuHWotH49hyORDpLaptgvTXdPDiGYlvaIjcHuayxVsjZGJXfjuTLavJhQf/9pQ/jiUqgmNc9VloqU7I0JWU1cJTm40YzkgEScQADnNV5wjbl93no03WmZlKo6p/eshb4RS2WFOwSSxSi1XuGcKn0dbrbCIPdvQf1WXta7a4Wbapt4AjfXHYD0ryqnzzt1OVaXakhnUpzOis5jVEvutLZi4UAMRn/tnDI+Nqmvfn5uc6W1K4LhAZ0lmxkgNjAzie+fir4cYZ+lE4MHPb53A== 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=519oerrRDEbTv7GQOYa1mMQ+Fz3ORBOf1G9j+BglRrg=; b=oXOtADay8SNay0O1GNXp+c+309NRuzq1KVH4IZ4gfxQRJCAO22DVo4QVEYS7/F+0/Bsosz938ZTKvySlV3K8GTsOAONGTOaOf2sPRUegnsdimdswqVSLBrQ+9jQpp5bR44eMyAlhYxrbPGn0hseXq74RwtcImDWlTQirQZKo2Pd1Dz0s028gnKHCx7gPxXPY8ge1jP46a8P2usMODt0kjqIEObx94ih/oYtyRq3wOtd/QPc5zmGgFzWTtWQOFe00GVl4PyEVNax19/ZcoO3h4pJIa++iv3C4k00N3uyqHzNTJV25x77dwoH5E+CXaZzQ4QqTqrornBobNGOxwO9klg== 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=519oerrRDEbTv7GQOYa1mMQ+Fz3ORBOf1G9j+BglRrg=; b=3DypaFBL2avF42OQI26/Dvo2JhTGumkPOfxWRg5Ty8mz+mMCi4YrxXgqLB3GoNIOPz9tGTcb+RYQ9E4DHf0ADpucajcPReKKfvB05mI2prVXWcUY7O5ipgdFDugoPs9bT5rtoIFAhYlU9l0LfsOeFOVPLtI0pG3qmcxjeMlNBZk= Received: from MW4P220CA0027.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::32) by BL1PR12MB5207.namprd12.prod.outlook.com (2603:10b6:208:318::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 5 May 2022 21:34:58 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::e6) by MW4P220CA0027.outlook.office365.com (2603:10b6:303:115::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14 via Frontend Transport; Thu, 5 May 2022 21:34:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:34:57 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 5 May 2022 16:34:55 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 03/15] mm: remove the vma check in migrate_vma_setup() Date: Thu, 5 May 2022 16:34:26 -0500 Message-ID: <20220505213438.25064-4-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: cb9748ec-f5af-4eb9-0e37-08da2edf19eb X-MS-TrafficTypeDiagnostic: BL1PR12MB5207:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4RBjvpmF3Mj+krfdfyB2/1/UJNz0905tZcAYulQeqqAsy0cW9mD+g62ok1bhnKdskX7ktj1E+BcnVbEFRqGDfpVwTM5l+RuxNk1ISjpmRCLWwD+bHEFA4uqK9dZbldKLfnKvyN2m5xkU+ka6vSRCYq93OE/cUaFTVgDexMr4T6UU5J8v59bW2UIiKtg/og9NlfQrrt7pwp9e0DYq0ud7aHy7T9bQHaCOjv/YfxKfjvg7r7+oiWMCh/CYNNG09RTVLv4C5kzBnpdph++ldLzeflKyCXkQl7S8tRmjfyX7PFYSm0TIduzx3w9JRaExyAv+eDVR456L5Y7zlLqBCXNeslXns8yuK2h0s640dRufy++dji5BoHSw1KTuHXQRwU8HUx5QckP5oZBzKiYAPkWkIPhDRQqSqLHOKke4n5+/ecPnYuPXMoNcE3fJsYI0V9S9LD80RTkf0vbEbx3I8mlcXQlkIU7x0B/2dUb0HNUWi+ElOT1Q8k4qprBccF/gPuhsJXqbyPCMJVOtJiKx0nwxdio9LtTgUIqeRMm73YEeaGEecTZadK6A8toojn7KmeIhW7mTPSdGVV/YQsAfLXBqXtvd76VwS5FizCeF8diUO8299Our8G6kYIQPW9DJc0+zTtm6Z24XuDYLhp1E0Sdsnpdw3Z5APw4YqcHQ+V7bT7n5VfFuwuf4FOb0Qq1rf8cohtuKJr8VOEEBomsc9R2ZRQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(36756003)(36860700001)(7696005)(2906002)(356005)(6666004)(8936002)(81166007)(508600001)(82310400005)(426003)(16526019)(186003)(47076005)(6916009)(2616005)(44832011)(336012)(86362001)(1076003)(4326008)(26005)(54906003)(5660300002)(316002)(7416002)(8676002)(83380400001)(70586007)(70206006)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:34:57.1891 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cb9748ec-f5af-4eb9-0e37-08da2edf19eb 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5207 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3FC1D20095 X-Stat-Signature: x3g4ba5e7rnku4q9txfetsypfgpanmrj X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=3DypaFBL; spf=pass (imf31.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.59 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1651786483-386259 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 a0b997935cf9..b399c498f0aa 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -467,24 +467,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); @@ -666,7 +666,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 Thu May 5 21:34:27 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: 12840195 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 90731C433EF for ; Thu, 5 May 2022 21:35:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71DAA8D0002; Thu, 5 May 2022 17:35:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CA6D6B0075; Thu, 5 May 2022 17:35:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56BA78D0002; Thu, 5 May 2022 17:35:02 -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 431336B0074 for ; Thu, 5 May 2022 17:35:02 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 202381211C9 for ; Thu, 5 May 2022 21:35:02 +0000 (UTC) X-FDA: 79432994844.11.DAF6515 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2068.outbound.protection.outlook.com [40.107.236.68]) by imf17.hostedemail.com (Postfix) with ESMTP id 5EC0440094 for ; Thu, 5 May 2022 21:34:47 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mfek9NK68GyPn8/ZdjENfTJ5kIGmAg2/+q3mAlt5nY2Y1z6yPetWQwY5T0dHhjVsVuRYyhty98yWo4VY67DM28xwOUU75HjW+uH3Zsw1kUSrF9+ungB4GhZQCNgwMnknWnuBTcPxbDe6OX8iqtFY1JRijuRjypT2ihY5xVsGvWGRaEtui3znxf/dgrgF/EELq1u2NlFzsGBKeBU8664QZPSRb130g4sigG3eo5PmMC9tK7ll11IacM2TQ/K5sKEHVEOISVYBEH/Muk9BHtbdlqvjzeL8WyGevyRranuWyNLo3+/2KPjEUb2TVx5rJmzcAi/Tf4CxsUY0to5VwZlJBQ== 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=0cD99Dx8pfAlPZd73o6wd/TUonMRb1bs7nyuiWO/hrI=; b=k7wZmkHfspoc+u5EDRsTaqtnwWZQ694qnozZHIItKDkhIUaRE8styUxtRTTzit/7PQa59H2bDu8oq8Y91VK1w9jpdSJK4fTgi+t0RmM3TMBYjpy88PlOWSrRydkN4M0zVynaNiK9ngzoHJ+1cXivkGZIdxCW4VByLXx+mD7riLweUBGtd9EmN+ND7643xPaJvrz9U+P5QKyoWL7krX95kTMluUZonWuwwANz0YUOJd4nHdWpbYT+P3Ea8WHTgdqr9pQtuXrZVe7PH4Rk6yGyEd1oejONJ0ULV3WUWh7Sd6w26iJW5mg9NYohQAFuAQEIFsjZPC0NhRjdKKA2chHiqw== 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=0cD99Dx8pfAlPZd73o6wd/TUonMRb1bs7nyuiWO/hrI=; b=X6qJUFkAqyW4DRqnTlKubsCVITPnnElHq39I8AHHkjFbZw8PASJnC9/rfEjx9auN/4MFeaXd5QINENbfozzug7Gn1py6TTmtjcXHtii4d5oYuy/gyhd8VhxufYC/0Bu65k5/6Lzkta/Zhrdy0i6iAXnhzsiFRuuFI5MilzZSIHI= Received: from MW4P220CA0002.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::7) by CH0PR12MB5025.namprd12.prod.outlook.com (2603:10b6:610:d5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 21:34:58 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::16) by MW4P220CA0002.outlook.office365.com (2603:10b6:303:115::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14 via Frontend Transport; Thu, 5 May 2022 21:34:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:34:58 +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.24; Thu, 5 May 2022 16:34:56 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 04/15] mm: add device coherent checker to remove migration pte Date: Thu, 5 May 2022 16:34:27 -0500 Message-ID: <20220505213438.25064-5-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 64a417c8-e792-4c9c-da9f-08da2edf1a9d X-MS-TrafficTypeDiagnostic: CH0PR12MB5025:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bOQqz8Vx0G/RVPYEMJXeTy6ckEBPmnYfxqBQ1X2XsOXqeFLpGDg1gpohH+FMFl+iW/Rkuldub1c9E9QoJFCK0otHuwzI75kS0Esm8f8lOXVYglDMo43bUrbWSLjFeFi8c69vQNyKrcDNXtqXvcpC1AvRlPrMtaDcB3CCGa1rpwEeUEerfySeoB8hVecyDmEU4t4Gv+i4ltk1ntJ+X5ZiHxQKHW9O0O5U2GA/xc87Xy6Mp+o+nTI38axYqvowg4HUtf4Um77izS02Rrfbe8lHlb12WiTWRBrwwqT42PIUgFNRG1SsTXRIAXmFlnWCmv2zm+/TA/qlVYb9X9sn9h2sEiVIAynXBH/gHsZmWRHIlIdcFvGKB09rvtWpaulJz88BO8hOQOblr02iw+F9OuqcnDKLUce1beh0kgupCG59ZsU7t3NUmB/Q5po5ejuLF2bokvE5dclM7pqhdQ7B54YZJ29PQhZULQP7vxO3KwSf8RYdl+lDE/1Po8Gv/wQ8mqCIj3j14U+DjwyeWg+uBuGDxyZWxUr1H/G+8kwPd3zkTrn8wxwdVMFXddMKkBYRsEA5wZ5RRlnwRlma0NFBHIIPZVVvRbsPmq139z/iVbOaNwLmrFPokpSHkY3e+WtG5Tra0D+lOPSwJ5ZFQTU2frrLBqJ8CGnLDF3gtBssMrHic4E+Z0gfO4LDsu8VOokOzROp22+Q4IltdXpIlqcpJdujLg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(186003)(316002)(54906003)(6916009)(2616005)(1076003)(16526019)(4326008)(8676002)(82310400005)(336012)(47076005)(426003)(70586007)(70206006)(7696005)(81166007)(8936002)(2906002)(83380400001)(36860700001)(6666004)(44832011)(508600001)(26005)(36756003)(86362001)(40460700003)(356005)(7416002)(5660300002)(4744005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:34:58.3609 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 64a417c8-e792-4c9c-da9f-08da2edf1a9d 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5025 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5EC0440094 X-Stat-Signature: m7zmhhq69admas5tchk7e1asnd9mak6d X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=X6qJUFkA; spf=pass (imf17.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.68 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1651786487-103917 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: During remove_migration_pte(), entries for device coherent type pages that were not created through special migration ptes, ignore _PAGE_RW flag. This path can be found at migrate_device_page(), where valid vma is not required. In this case, migrate_vma_collect_pmd() is not called and special migration ptes are not set. Signed-off-by: Alex Sierra --- mm/migrate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index 6c31ee1e1c9b..e18ddee56f37 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -206,7 +206,8 @@ static bool remove_migration_pte(struct folio *folio, * Recheck VMA as permissions can change since migration started */ entry = pte_to_swp_entry(*pvmw.pte); - if (is_writable_migration_entry(entry)) + if (is_writable_migration_entry(entry) || + is_device_coherent_page(pfn_to_page(pvmw.pfn))) pte = maybe_mkwrite(pte, vma); else if (pte_swp_uffd_wp(*pvmw.pte)) pte = pte_mkuffd_wp(pte); From patchwork Thu May 5 21:34:28 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: 12840206 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 7197DC43217 for ; Thu, 5 May 2022 21:35:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F31BE8D000A; Thu, 5 May 2022 17:35:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE1A98D0007; Thu, 5 May 2022 17:35:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5BA98D000A; Thu, 5 May 2022 17:35:27 -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 C40E88D0007 for ; Thu, 5 May 2022 17:35:27 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A392C409 for ; Thu, 5 May 2022 21:35:02 +0000 (UTC) X-FDA: 79432994844.03.837F720 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2063.outbound.protection.outlook.com [40.107.236.63]) by imf15.hostedemail.com (Postfix) with ESMTP id 97D34A008C for ; Thu, 5 May 2022 21:34:52 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J46CjfPWmjeptaJYbtn93Lmppn+liiCQfEe8bdthjP4TnbW6GQ3urbVk+Aj7rauzTzX20WURFBIn/GzoBPZGMwaNAoFlImp03+k9Xjv3+hBxM0mUfi6bIi3NrBYs9MnmSWyaaHRAKpzHqPIBC8F8mPmZHtwEI84ZHg7HOCY+IYYUGx/HIOApASbG4P/F4P6GpORrpkClf6XYD8b3aZMytkWLp4sq3Qx26rE9hWFXDJKj0u/U0FHUdzNo36NrBo/ZqrKTdLfMmvOH7QI7dbc7jvXN3LrnaoZPEdZBRAQvuGvR7ICUmpZ77wB6ApUO93l4k8mgOQYyAq6kricxRN3KBA== 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=cLboctgqtU8q+2w0PX43DNmgl62uyxYt9SRLY3lWywg=; b=JvqFDxanKqy08RPnI3hskjxrTF1FICmfyI31GQVicWzTiSzhdZAu8t35+KdAKtsQHH0KzYWmnINTjD+9VldC2KVZ9L1nd89p6gqPMy19dFBt6NDUfPWUJMoQO571fRs3h8sENEgQ2yvdtDrDMiPmfJap9hUGT/w5xPLF5FE0xDJkHy3vO7uRumALhAKIiqewQnSypkaM8MUHltsII9i9hZvSJknpTA92xg5rBdEJfp4mePypsYvCJsCIyg+iFtBihjQqeapnqdppnP9iJp7+gFDMDUlg+OqdZ/q/M7MazG39VgVxh8Oo7lk09PRSA64OBwSjD/HuCAWj1vVN8UHs1g== 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=cLboctgqtU8q+2w0PX43DNmgl62uyxYt9SRLY3lWywg=; b=0NM2RqTzEg3H4k23AjkrP+u/PI6CWFoe5vRuI8vMOM0yfKWBk961f+lTcPk8hF/nwSxPeV+PBfylBTh+GcgmOg3UM4zU7+K4TWVva/BGTqYTC+Ve1SqKM4ZZY5gV0D1UeEXhLtIQmbXaAhLS8bDSd8eQkRw6HvjNy+pw1cCmao4= Received: from MW4P220CA0027.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::32) by CY4PR12MB1479.namprd12.prod.outlook.com (2603:10b6:910:d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.20; Thu, 5 May 2022 21:34:59 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::4) by MW4P220CA0027.outlook.office365.com (2603:10b6:303:115::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14 via Frontend Transport; Thu, 5 May 2022 21:34:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:34:59 +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.24; Thu, 5 May 2022 16:34:57 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 05/15] mm/gup: migrate device coherent pages when pinning instead of failing Date: Thu, 5 May 2022 16:34:28 -0500 Message-ID: <20220505213438.25064-6-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 410125b0-2053-44f9-48ff-08da2edf1b10 X-MS-TrafficTypeDiagnostic: CY4PR12MB1479:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /fQ3C7AkKQnx0naTBRyk6f0U/S/CQblwDQ4L/RaC+S6tTnJUeJdNE0FNoj5pZU/h+ZWGk3Fu4Mk8wH1ygRL/SYMcaQ1HoXa+qyXytPDt7XkhB5ks/Ru2G7t/XCBDbX49lkhJM/kaXQkbOlRKehCsR/lTMh9fH9OdUyJTpLTR5GXANc/B9h16enc4wOT6mq49/aSvfSks5PY4thSVj6HBBZM592dg3NWYBAV75ye23PMvMABAV2yIvqWd55pReZ39mw7iBfK/K58oG1zlkg4Oa0+5ydPPKtf1o9faO1ovbKLGni/DGeaP3X1QjXA2e+3TbfqpuYywiXOVd1JS8p1ofwYptDzkaORMgjo3EmTuWIj22eT5QHjqZfGFSZ8kkGKdq7hd30L50NLrdRQAQqbiToMWsIJ5yTHNQA2yDhI9a+GwnV8+5j14vOi0hpcM1cZvmDmTAoOprCZxfU4xJO05kvayhn+jJ+ylgTe/0mXJkCQHTVxygQVtGyRkDdH/0dNko5jrPjjOmIu4vJ8siKDGa3ZL3tnrhMYmkZeHtjuHfbAi53+UymUuOd6ypz/8pDcWb7MbDly437l+m+2KBpwsUslsmutk3zqO699JUn7HSNfsT1n5H8H9X+ox5Fsqs/eEIv243YLRl5pGXUppHcqmT5O/Lb45FftY4nI0nWaCDexq0/doqdmCvQlETNrl5UFtLh3RVnNlXVJwu2BcypZtJA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(82310400005)(36860700001)(7696005)(6666004)(44832011)(2906002)(86362001)(426003)(186003)(16526019)(83380400001)(336012)(2616005)(47076005)(1076003)(36756003)(7416002)(26005)(40460700003)(316002)(4326008)(8676002)(6916009)(54906003)(70586007)(70206006)(508600001)(8936002)(356005)(81166007)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:34:59.1264 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 410125b0-2053-44f9-48ff-08da2edf1b10 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1479 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 97D34A008C X-Stat-Signature: khdsirmmn7kywsaghwcp5k6bm89ufbfb X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=0NM2RqTz; spf=pass (imf15.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.63 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1651786492-58577 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 | 47 +++++++++++++++++++++++++++++++++++----- mm/internal.h | 1 + mm/migrate_device.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 5 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index f598a037eb04..a214c8df7140 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1786,9 +1786,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. */ @@ -1824,10 +1858,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 cf16280ce132..32c621416966 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -750,6 +750,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 b399c498f0aa..1e74aa7ab580 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -775,3 +775,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 Thu May 5 21:34:29 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: 12840196 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 9061DC433EF for ; Thu, 5 May 2022 21:35:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA0A58D0003; Thu, 5 May 2022 17:35:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0CC26B0075; Thu, 5 May 2022 17:35:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 805718D0003; Thu, 5 May 2022 17:35:03 -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 5E31A6B0074 for ; Thu, 5 May 2022 17:35:03 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 3C20312124E for ; Thu, 5 May 2022 21:35:03 +0000 (UTC) X-FDA: 79432994886.22.1151130 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2076.outbound.protection.outlook.com [40.107.237.76]) by imf15.hostedemail.com (Postfix) with ESMTP id 39FC3A0094 for ; Thu, 5 May 2022 21:34:53 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MpzJl8peQneMVsQIsy3Ue9eFN5SxN15jbafPJlW7AxGwnJGG4QSlK5UTmKF+5cswdUrfhFc5hsnVc2O5B9/3LxAhAJbb9e/Ay84/N7Qha5fv95BsizGx0iDVf5dib02+WdPoLwwtDhSvrIvDgl0yACce+x4igGE1FApfxI37gGgnPaU8xhxHLTC70GBK6Hr2KrTuMca/Rk+N7hZzhbsPNgDL54U/RBC8te0BRhCrGwyKPSXhAu7O36CRetIHiWDvLXa0hwfUorwkMqqAgkXryy9jr+Ehg8YtVRUhRdWstfiE0PUcH5jA7bqqVmWIZbJhWaz/QEYjkIECXmLnT7Zhbg== 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=6li4CXTFMpIC5kEC/f1k8myx/ij3/qwqcmvQ89j1Gos=; b=fJ2co/Sw7kktz3uM7Nb/ltiOZ3JMU2MUPN38mSPCjmqO0RElMIK+82pE/F10P7A9YpZylD5GsfXR06eS4yCb8eLi2oariGdMxZ0fNL9r9EAhryAfSh7jUkkvbJcLkRxKJvP9fQmfQJtxrcmO1iUwVEIU7rjN6VcVAjgKCvLV1WZja59Jpp+HyEM5EJyPB6Xorr0HMsJy/E1+vaqtSctBMC4UDTovc/Ndgc69pBAeR75OkQa5PxSDesi3SU17sB7Zsff5GydfZ+Ar4azS5fgvjpqOgf/E7koRJLCMB63TX2SIsnuF6gc1TFXpwth/rWaV8Ye2hPA7oxRNeSfIs1PlxA== 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=6li4CXTFMpIC5kEC/f1k8myx/ij3/qwqcmvQ89j1Gos=; b=FJqOpSvy9bZPADl8cfffztc6Nu7AmreuxB0c0fLoiILRdlewKfeTOU8F3LraPFDtpKU6+47KHcRN3aJE+Qs/FTyGOSqjg1CrCp7a0FmYp6jhtbdAeM0A0BxMDdXSAdrDKyG036EpzbaBdWcfC080OwbfoSFYhJIZHbAJBB2+ZJw= Received: from MW4P220CA0027.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::32) by CY4PR12MB1191.namprd12.prod.outlook.com (2603:10b6:903:44::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Thu, 5 May 2022 21:35:00 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::33) by MW4P220CA0027.outlook.office365.com (2603:10b6:303:115::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14 via Frontend Transport; Thu, 5 May 2022 21:35:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:34:59 +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.24; Thu, 5 May 2022 16:34:58 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 06/15] drm/amdkfd: add SPM support for SVM Date: Thu, 5 May 2022 16:34:29 -0500 Message-ID: <20220505213438.25064-7-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 7cbe5edd-2c99-4ff1-9091-08da2edf1b7b X-MS-TrafficTypeDiagnostic: CY4PR12MB1191:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BjMsXH6ZhtFWg1djbHB0Q29F1VyT4h8mFyPWxPWotWeRKPcTtCypVWVAb4+bgxNZshxBygglHO9oEjF75HcXgHVTo3HYqkiUKzeeLo/S0IQH918dACqq+TYW82aLvIgHVtl719JivMvldo/cBczhaYg6khH6RB4PBpsmFIU5tNZ0Icnpnp4tKpAiR7Vq1fJxKt6TWFUUWM/3RbEpzjy9ocQ4PI2yXdgoRrw9W2hHGsxS7IyXqgsIKRbU1DUeyDb6d79vE9rXaJsjhTO/1LIV4PTFt3r3ecl21dYmOVwNSydY4OsGrFWKlQBdNpCNe2RiNrRorG8JmTMvv4OmFuM1MeIS+Nxelcfg8W5CegE7IETyKJp0wtKVmlDKmsnEpO19W3Y3s5wwcpN9i1vmN4a55dRhp3APQ91Ev5WK58spZzs1hzwt3KpUyscUZ/LyAf8bDMQrV8eX2FCh9JO9oayfGNx8FMSShtxrypfp2Eu7mjO1/EjYQha0AizgM1++RD3b5+Ja+cSVn0sHV4Hk6QBtIXO4jjgzd6zYiNhNXRA6+tJRE6DdHGlaYRJQkrg6489hYsCVrxeFNKRDMI4TOeqSxcR42votlruo2tW6LJMFFG8ZLuAv/cyPXOjbpJzim3vqs7YuxWYlL0au6jzOLgOAEFMibHoVxhiJMqGJcHqeK5LoEVJuTxESQDfFLxPtVm58xBCK5ryHNjnPoZep8KVt9Q== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(4326008)(86362001)(8676002)(70586007)(508600001)(36860700001)(82310400005)(54906003)(316002)(6916009)(336012)(70206006)(2906002)(36756003)(83380400001)(2616005)(47076005)(426003)(1076003)(186003)(40460700003)(16526019)(8936002)(7416002)(356005)(6666004)(81166007)(5660300002)(7696005)(26005)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:34:59.8139 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7cbe5edd-2c99-4ff1-9091-08da2edf1b7b 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1191 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 39FC3A0094 X-Stat-Signature: g56srfi1wfnguoosdsb4izt8zw5uhyc8 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=FJqOpSvy; spf=pass (imf15.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.76 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1651786493-75582 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. Signed-off-by: Alex Sierra Reviewed-by: Felix Kuehling Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 28 ++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index 7e3a7fcb9fe6..52bd3fa6a582 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -948,7 +948,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; @@ -963,28 +963,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 Thu May 5 21:34:30 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: 12840201 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 E9476C433FE for ; Thu, 5 May 2022 21:35:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 152096B0075; Thu, 5 May 2022 17:35:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 066B98D0007; Thu, 5 May 2022 17:35:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC0428D0009; Thu, 5 May 2022 17:35:09 -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 926868D0007 for ; Thu, 5 May 2022 17:35:09 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 705BA81146 for ; Thu, 5 May 2022 21:35:09 +0000 (UTC) X-FDA: 79432995138.28.72A8F83 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2057.outbound.protection.outlook.com [40.107.212.57]) by imf26.hostedemail.com (Postfix) with ESMTP id 84BC714008C for ; Thu, 5 May 2022 21:35:06 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RzXG4sqOH6lFrTZOipAHwo9e1egBxB9YNWhpW1+vfdJRqdW58rjUvsB72rkmsOG5JYqMHXPC5/9CT0TTj4JSeoburaYrsvNs087YJ5eMpUMSz3jlml3vilgkaUrd4QQ3XvSeux+d1LMVPloDMhu0Olyuc3AkaPM4v3JRm55l2V8FCf9m3gqQg5LPdEUbXRCU75iUd4l2BSJw0c/nVR1+Ycl7/XTfLs8crMr9SX2F0m8Kd4OI4mkpmrXrkDJZyxZHE+VbhemrhQAXwydWaZIkebwu/zhYjv1kk16znSX5ZY9lny5gGk46PriTHq0YDQt63wB5mvtCogG/TWE3gTZ1JQ== 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=HYbAtd0kToehVPLGYK7/o/+Q5EJHAtvHQwnJELfJscA=; b=DTmzbaR6GRbdUxC5kVPZHKllpYMBt9yUFOYdlsjhGYd1r1BfMuHlyzu/fbIHRQepCk3q6WGh/7H/RF6tNCYa8VsY5qemkL1+u8/vBgL8UrDCiJnsDxclVPzC6XRUiYvWit610Jrj29ahDsbhIbXjLoMFALL09lVBenv2N5fnWoZirLIY0TfvY7bLB+y5mP9L1FDi0TFT08c6jnNTT3eOjtViZYvreC/jg8kTpx1d6/JaBF1zhk/QoEQtpxlVHW++szmGBJTm/PMRi78zPzySkL7123gs2Qkk9qhtNiPXOgeGr+s2+n7/1fe+aL9wxGZ5PS8mCRiLJ6xdC56gV0Zu+A== 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=HYbAtd0kToehVPLGYK7/o/+Q5EJHAtvHQwnJELfJscA=; b=Broi0jYz24Wav6sj9iDD1kL8878IUR2x4kxJdj9sjCkgRYJaJu2ZPwPDtJFBcijyafpxMy0sTofGRZ81fdwCplTP3gzvJ+fL7wnB691VJ7FKQ391wgSoHWQPSAGX/gqJ0leV3nx+PgEewxrjl1cF8NF4inEuY072D8hWtG9OfYc= Received: from MW4P220CA0023.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::28) by BY5PR12MB3826.namprd12.prod.outlook.com (2603:10b6:a03:1a1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 21:35:00 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::ef) by MW4P220CA0023.outlook.office365.com (2603:10b6:303:115::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24 via Frontend Transport; Thu, 5 May 2022 21:35:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:35:00 +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.24; Thu, 5 May 2022 16:34:59 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 07/15] drm/amdkfd: coherent type as sys mem on migration to ram Date: Thu, 5 May 2022 16:34:30 -0500 Message-ID: <20220505213438.25064-8-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 1ca766d6-35f4-4135-75a0-08da2edf1be4 X-MS-TrafficTypeDiagnostic: BY5PR12MB3826:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: syfprjBHeZv3SQRTOX9/jrEkRNX+2KrLdR4P8rdvfPxyowKZ5YRD5ooyDvSiTnOOKKuIWQrHa41IlDKuVeSk7vI90YiqXqycE8nvqAk8QvpdG0JalnQ4wMVCInJyLA2iu4ve03K1RKwaT950/q9WUZ8RmR6NW28tffmjd37J73Ntau3Qen4SyAbY+5VlvrOGNNNmAiKNHfUMz3vnb63BT1rC0d6mP1S5Y4sQ6v+5c8tmxwNog6o3oePY/a+tq/dxRXkYqc9guvmkmUYU9DEx5j972vgNw07b0MEEzoIGWH3gatOlcTEa6Cm91+Jt0s5xS8Oy1khOpoLfK0uB/5UrXKLeP15ZTTrXaCVwyWYwnwzs8+vvNW9tWGODFrDIRNzchwicv5wglR3ah0Au4z+ABQDYlPeqXA4RTp5ExPb5f/Cdg0GzX+JTuPkk8ZzyINu24mpKUOFiXQvLkubpGDeX9/nmFD+FoTVoGR0XcUvhlSs2TfFir2F9fYFiu6Ag33bk6wkbNNV73B6CWQII8VwBKqitrXO/4yLan5ksxvfzb7usnlorUMl4+m0tHsf1elThrHYWh/qkdBPQ3yvKqVx3zJxydNkVm7l4SmbWchSZUu+k7ElM9Nu0GE1aMCAbPc2oZ2IyNIB5PqpD1Bhmtnp9fc9l2BzqcqwOE1BFlylaj+8jyqWKNx1fcK+9NIn34Du2vN9RFvbhr+YR/pMjBQpMXQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(81166007)(4326008)(356005)(7696005)(2906002)(426003)(83380400001)(2616005)(8676002)(186003)(54906003)(86362001)(26005)(8936002)(6916009)(316002)(5660300002)(47076005)(7416002)(44832011)(336012)(6666004)(70206006)(70586007)(36860700001)(508600001)(36756003)(82310400005)(1076003)(16526019)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:35:00.5169 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1ca766d6-35f4-4135-75a0-08da2edf1be4 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3826 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Broi0jYz; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf26.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.212.57 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 84BC714008C X-Rspam-User: X-Stat-Signature: wthkq9oj7a7fh5q87d941hrgxqwtjciw X-HE-Tag: 1651786506-250969 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: Coherent device type memory on VRAM to RAM migration, has similar access as System RAM from the CPU. This flag sets the source from the sender. Which in Coherent type case, should be set as MIGRATE_VMA_SELECT_DEVICE_COHERENT. Signed-off-by: Alex Sierra Reviewed-by: Felix Kuehling Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index 52bd3fa6a582..25c9f7a4325d 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -673,9 +673,12 @@ 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; size = 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t); size *= npages; buf = kvmalloc(size, GFP_KERNEL | __GFP_ZERO); From patchwork Thu May 5 21:34:31 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: 12840197 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 C0A2EC433F5 for ; Thu, 5 May 2022 21:35:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62FED8D0005; Thu, 5 May 2022 17:35:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E19E6B0075; Thu, 5 May 2022 17:35:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E66C8D0005; Thu, 5 May 2022 17:35:05 -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 14EE66B0074 for ; Thu, 5 May 2022 17:35:05 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EEBC42E99C for ; Thu, 5 May 2022 21:35:04 +0000 (UTC) X-FDA: 79432994928.11.E140FC5 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2063.outbound.protection.outlook.com [40.107.94.63]) by imf13.hostedemail.com (Postfix) with ESMTP id 118E92008C for ; Thu, 5 May 2022 21:34:50 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GW7YsxNmOUz9TiWECylOO8fpmWtvm9xOQaxllZz+QEMKC/CdPMU8Dc5AV7uQrOmV+q486Cp0X5R825wEBB1ElM+KJv59y4D5GwbPFLrx8qFCcEBrbDX6n9TTYcvKXgfUz01FPYXGhi3kD/svuz2/rvrgs8zIsbW77fwKRR+84qvGZ1i8nLtdnM9Qp8pablb80eoOg/7bpvN4svT310PZ4DzIh6sO/OFloiqaTgolD/egffV1CcB7UkY7h+MXoF9PakP4cxAl6RwMehGb18b5lPP9YO9Hu6zt0M8Af++WByZPHBX6M4+a1Ai7OdUy1HSqyPYtU3C3sPxmS/d2BTA0Ug== 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=BO1XgdLChGhcmXQYgQRlktGItGh1h3zZzS9U0EV0V6A=; b=jveCmmwU98/BwcfHTZwMGw9Jnk7LHVG4ddrz0BCVZkNBo1AX966VL73UFmd2ewID+Ya8YklqUDi1i/PrFx+uq6QmS4omKrnfusMEBbA1/vYDho859kSIxxzZQlXecRal+MKh6z3MfmeXRhIuxNgkR49qxwlm1Yw4IdZlsIUOUXEuc0i6lSXlJE3D6D+y3sWZVIpK7Iv1adR7jOPSyzCRE/MjguYX3f/no/hySL231vmt8Y8rfuajqa6s6EiB8SpPmiFXXKNuyZCmiLsCEIXvlOgIuTSSIQJwPU2m+1upoAJvgjGALJ/u/qy2a2CiHaP8Xxoq4hrFv3XQYqbrIhqzlQ== 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=BO1XgdLChGhcmXQYgQRlktGItGh1h3zZzS9U0EV0V6A=; b=MF4/wnnSR5PLjvJVzH+k1fbIisVhcsu5kmgbaug+7wtbr493PdT8/Wrx4fNg1LMbvsJl4ZqG+Maqk3WXu2Lu1diFVvUU6b7FSYtqbru+26DsQADLjBrHBL7pE6jzd0gTmYyM3p9VU4cHR81mlFIxWNzY7PPQGK8GwMoE+VMJilU= Received: from MW4P220CA0012.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::17) by DM5PR12MB1898.namprd12.prod.outlook.com (2603:10b6:3:10d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 21:35:01 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::3d) by MW4P220CA0012.outlook.office365.com (2603:10b6:303:115::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Thu, 5 May 2022 21:35:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:35:01 +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.24; Thu, 5 May 2022 16:34:59 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 08/15] lib: test_hmm add ioctl to get zone device type Date: Thu, 5 May 2022 16:34:31 -0500 Message-ID: <20220505213438.25064-9-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 5659c407-724d-4e23-33d9-08da2edf1c46 X-MS-TrafficTypeDiagnostic: DM5PR12MB1898:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sZ98FxZtIb07U5h0EdSiCjjL/h8Am1RwtH2k8xEcMwItPhN+5Y2KXyGi0fqUOuYLz1ITta0cfA6HIHDGHkpW50rJtLA2jZDk8e5EHm1m+Qqhv4lHGm0MQucbD+rdOz0ixkfM8ldaROX6b07bR97oYc2XsKXsGYlShrUZCP/pMA6J9b9TZKCHdtf0Rprg1ls20TtHtazoIOyKSVNZzGdJVxAOfjoWS+x/OvQssmpEkaWi2JVXqjpI+pDmZNi6NZ1EBfSnqfe10aZuDEXcZTiDrWyq98oN01sVvqs5L/CldA+QePLHYtaT7cgGnlWAwypmdPhT26dznsypdpgcHC7iNQqSMAxc4tE3oNELOH8f2XQw7ukhV7wTrZCuGZuesaej/vNNXz9FNqHzs2s87o6NP9QEOf5zS8A6LZS7vpxMIJNyULYHq8Rq/v6dANDEbuNcT21iV7RLwu4RzdiAVCCsIdtoYIiX2Odc68CG5oDizjHfu3YOlGQQdExRU1np6bnacP9oBxgJWom5XHkvxkLKNVoWdqLjdeUkIwFyr2bMc2Npmc26R4fUh3mdDDFGJX3sM6cO3/l6FJgXC/Eiu0AlWrsu+n1N75nwUbxHyR73JQm132Mzw4dVHJ8LfJsfN8S1kloRu/07YKQtmID9Tyc4RPmiAj29V/KlB1LcecXsYJgf0PHe+IdvEn3tBu7UOR7Ly/oUl2SBcvuksErt1jT/Tw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(86362001)(26005)(7696005)(6666004)(36860700001)(16526019)(186003)(426003)(81166007)(356005)(47076005)(336012)(40460700003)(1076003)(2616005)(5660300002)(83380400001)(70206006)(4326008)(70586007)(8676002)(316002)(82310400005)(36756003)(44832011)(7416002)(2906002)(8936002)(54906003)(6916009)(508600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:35:01.1419 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5659c407-724d-4e23-33d9-08da2edf1c46 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1898 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 118E92008C X-Stat-Signature: x87dgfexxwm56x6adwkj9y76hyjdruh1 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="MF4/wnnS"; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf13.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.63 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspam-User: X-HE-Tag: 1651786490-795008 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 | 23 +++++++++++++++++++++-- lib/test_hmm_uapi.h | 8 ++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index cfe632047839..7a27584484ce 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; @@ -1026,6 +1027,15 @@ static int dmirror_snapshot(struct dmirror *dmirror, return ret; } +static int dmirror_get_device_type(struct dmirror *dmirror, + struct hmm_dmirror_cmd *cmd) +{ + mutex_lock(&dmirror->mutex); + cmd->zone_device_type = dmirror->mdevice->zone_device_type; + mutex_unlock(&dmirror->mutex); + + return 0; +} static long dmirror_fops_unlocked_ioctl(struct file *filp, unsigned int command, unsigned long arg) @@ -1076,6 +1086,9 @@ static long dmirror_fops_unlocked_ioctl(struct file *filp, ret = dmirror_snapshot(dmirror, &cmd); break; + case HMM_DMIRROR_GET_MEM_DEV_TYPE: + ret = dmirror_get_device_type(dmirror, &cmd); + break; default: return -EINVAL; } @@ -1260,14 +1273,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..17f842f1aa02 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -19,6 +19,7 @@ * @npages: (in) number of pages to read/write * @cpages: (out) number of pages copied * @faults: (out) number of device page faults seen + * @zone_device_type: (out) zone device memory type */ struct hmm_dmirror_cmd { __u64 addr; @@ -26,6 +27,7 @@ struct hmm_dmirror_cmd { __u64 npages; __u64 cpages; __u64 faults; + __u64 zone_device_type; }; /* Expose the address space of the calling process through hmm device file */ @@ -35,6 +37,7 @@ 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_GET_MEM_DEV_TYPE _IOWR('H', 0x06, struct hmm_dmirror_cmd) /* * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT. @@ -62,4 +65,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 Thu May 5 21:34:32 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: 12840198 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 24277C433FE for ; Thu, 5 May 2022 21:35:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 03F6B8D0006; Thu, 5 May 2022 17:35:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBBD86B0075; Thu, 5 May 2022 17:35:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBE2D8D0006; Thu, 5 May 2022 17:35:05 -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 ACBE56B0074 for ; Thu, 5 May 2022 17:35:05 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 8F176613B5 for ; Thu, 5 May 2022 21:35:05 +0000 (UTC) X-FDA: 79432994970.30.925A8F4 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2063.outbound.protection.outlook.com [40.107.94.63]) by imf13.hostedemail.com (Postfix) with ESMTP id C502A2009A for ; Thu, 5 May 2022 21:34:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GdT5WvVDeJ9QVpx/NdZsF6JhpmCJLBYq/0xzEoOs2hSZeYU1zwvAS0np3kiWZh0mshDEVjtnIxT9j59WYYmptFQm0wUOGUsPtb9msW0mRQRJLrZP6Qxb8buibyofgtidEU43Oz1NcJN32id6W/8oBctY4qlLqgA+v8vNef+LLnPe82fCmEbGFR2MZkIcr4EsKRHzxzOT/R1SSLjyUkYBM6ab/9GZVVjSEFGRP4ptExpYqj12NdeaiySpmkv5NHK21/x2XoYjFpZkGldKCUY9JvjT4EFkjHOsG8oiP8u99MtcK0kjHFaVKxRQmIN/auPkFY47WhuKRd6+3H2OwOma5Q== 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=EBC8zbdByiow3Ar7kghS8CNIwlQlMj13Ni6WUh9t/L0=; b=OFZBbLy/ok79q6vv6/DKLFOkhiisRWLSi/YKy7QliH7Y9h0HFkuIrjI6UUo81B8ah2bh/YDOWW1ZXECEPUVRoF2Om/+dLTBWiVJT1dKBUkSR5vpmOchXVQg6062HhSFStHJJeE3u1xdpyMc01Uvkhjs2xG6mkDJnh/p3rYKEZQP0xao3vsh+D9LA8Kk84pv3HwIB2sEN5nVLF86YMMNEVnVCQMeJ8R7SHYvaExdsESmb36lPML9rvmcrFUcZCFwTY5frGRXhS064reSkJi4BIrp8eMQWjni8gwf/lE1eM9umPKbT2ROHJB48Rl8nWFGOJyfcFswt+cQSp5Gwl2y+1g== 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=EBC8zbdByiow3Ar7kghS8CNIwlQlMj13Ni6WUh9t/L0=; b=yrpL3KMCGAuh84Bbqji+xq2XY5niVnFgzPo0ewLx/mK3LbVbVoRtXhyrM6JjW9x/RflxrEL7t+YjNlnohedVodDn4krQ2E4C4ZuYGx94jsAqCT0D6dJVpJP3HioVfOGmPias3rpc6JmMcZHX6bKvIG/fcJJdjOTpTQzLjLINY+M= Received: from MW4P220CA0012.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::17) by DM5PR12MB1898.namprd12.prod.outlook.com (2603:10b6:3:10d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 21:35:03 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::3d) by MW4P220CA0012.outlook.office365.com (2603:10b6:303:115::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Thu, 5 May 2022 21:35:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:35:03 +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.24; Thu, 5 May 2022 16:35:00 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 09/15] lib: test_hmm add module param for zone device type Date: Thu, 5 May 2022 16:34:32 -0500 Message-ID: <20220505213438.25064-10-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 13b38283-929e-4e20-e566-08da2edf1d61 X-MS-TrafficTypeDiagnostic: DM5PR12MB1898:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gmkqnRHz8v6XedgA251CYNFvtac43d5KLPXEiGIYQRyJLTpvsdsmN6WfZEanFkpJaOZfZDSyAHg0IkXj2Br5rjYxG3OXTABmWmFFrqcTW/fM8AaHiHFczoO5LDUyC6QzfWOGxAKwqdsiY95mTUbclK88OgU5HEK9Y5luaOqtsxVJbasuG5Sy+6DDLOgHOQZGBbwtQ/+AsYraZe7zmhrhleg8Dg00aiI/TPfhZU003uga7YC6i5S2qcnCl428pzxMPhHmgxvo2M9+pjVsmTywKtxQEqXa6Hr6dLpjMwnZQOobdQ8o6IvnRKAfYZnhLVHUyDTEhSscvY1f7ufJDwixz5vsR2MA33PBaamz9wrXd0It040zvd2LuseFo3UiJo2/3tnTMTmzoNMeJAlP/OYGHWdLYTG5qOvIsqM1k/oFtaj6HH27SdeZ5DZcJfYsa/OdnsugcQKZdLMZRZrprOkSPR8GnZdp5qnNNFYCcgwNyY+dqYs+KehD5o8BbrEQoXtnBChSnCx5Mv4BvFIqGwIG8EVV9hcUPwO5NgEjloeVX3457bbfLoQpjbDcKsxiKtKJRRV34dt39NpOM8HCVCaahAVnQ82HuAE4c226NXpSOx1RUPWiibVMTAAI/McQFXT4+WAOlyzo+stc3wcwctB5FG1FyousQrFgjsQTjyq8CG9g0geIcfSSejbwyhKmXh7xwox8u2kS2wlAOiafZtVnPA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(86362001)(26005)(7696005)(6666004)(36860700001)(16526019)(186003)(426003)(81166007)(356005)(47076005)(336012)(40460700003)(1076003)(2616005)(5660300002)(83380400001)(70206006)(4326008)(70586007)(8676002)(316002)(82310400005)(36756003)(44832011)(7416002)(2906002)(8936002)(54906003)(6916009)(508600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:35:03.0011 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 13b38283-929e-4e20-e566-08da2edf1d61 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1898 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C502A2009A X-Stat-Signature: bcha6fxh7oygjciwxx6qxrf547oyt77f Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=yrpL3KMC; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf13.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.63 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspam-User: X-HE-Tag: 1651786491-989432 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 7a27584484ce..15747f70c5bc 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; } @@ -1244,10 +1276,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) @@ -1260,8 +1290,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 17f842f1aa02..625f3690d086 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -68,6 +68,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 Thu May 5 21:34:33 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: 12840199 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 AA2E9C433F5 for ; Thu, 5 May 2022 21:35:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E99AA6B0074; Thu, 5 May 2022 17:35:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E45B28D0007; Thu, 5 May 2022 17:35:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B84D66B007B; Thu, 5 May 2022 17:35:07 -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 9F0636B0074 for ; Thu, 5 May 2022 17:35:07 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1862A20ACE for ; Thu, 5 May 2022 21:35:07 +0000 (UTC) X-FDA: 79432995054.08.9880A8C Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2050.outbound.protection.outlook.com [40.107.237.50]) by imf12.hostedemail.com (Postfix) with ESMTP id 104F640083 for ; Thu, 5 May 2022 21:34:48 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E9+AMwWAToWMcjP6AZ6ZlY1rlBE6bdzmQWRMWi/NnsqnYMj/tE+Q3mX4aNiNB4YAREEc315kzNvXRNFFwciTkWSOiWU22py/RuNXVZFA9q6JACnxZr8Sj+4BkD7FFQ8NTSu5yfYRy3VEF33TXO4cJdG/xiAS0TblXJpZ5kJ7toIRsO+snZ4b6uZf21Us26bwnxkBhpSX0hPXnwPQ70C8nWqsgVASpGTZHB4rOtfHXj1TWtgP6N6VvEdKIw11R814y2qaT5r5UTdrjZ8kupGntGW/arKZPTM5GZtlD8RiDBdrs8EFC/BUKUN7H4djRCYsdY59PmFxoK9W5DrQWXtd/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=7NnrGS6YZU8gQt+7tgfyVxU1Jq6fVp8xiHVCSF24jGU=; b=JKNnxmnzkuU/GUrsSnG0KtTaZYoPAjXP7XpCXoXz2cmjgs+3UheG9LQ/yS/tjrF92jn8QFJ00dRRizwO3Pq7L/CZdImMXTMtF7wOEfE6I8XcBhziB5BWzjHCcJSKZizYx169z+JhAq3t7Qeq3ECkDU8G+wT74mNiCzJsxaG5GZFLELgCf7RFNGBDo0V/I25IMCug2H+dirj4uV+pkv91A/UjJKeIOE6sDYlC4nCFoPZ2DsDveOKI1ERZ95DvvANoXqajQ63H/9Pq9iVcX+HmfpMkWtG2NRdLYGCEhwA6qq6WSJf6wtBvsk7cCiQkNHnY7ZUxVjvteVo5VSzVzdrNhA== 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=7NnrGS6YZU8gQt+7tgfyVxU1Jq6fVp8xiHVCSF24jGU=; b=VO+lVdaj+5PbpNO4Y0gmLcLfBBKTXq1/hKenuH6yf39w+COenk9SYAe7t8+d9Ce4nBXi/bYQc7qS8L+uqu/+YED5DbTcBLY0SFL6PtSx35v/1ss4EkmG7grNWcIatX8OgW5pDSmcoLQBZaa1MDlmnE7obXCGZbR0/FVE8HSpJpg= Received: from MW4P220CA0010.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::15) by PH7PR12MB5687.namprd12.prod.outlook.com (2603:10b6:510:13e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 21:35:03 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::87) by MW4P220CA0010.outlook.office365.com (2603:10b6:303:115::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24 via Frontend Transport; Thu, 5 May 2022 21:35:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:35:03 +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.24; Thu, 5 May 2022 16:35:01 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 10/15] lib: add support for device coherent type in test_hmm Date: Thu, 5 May 2022 16:34:33 -0500 Message-ID: <20220505213438.25064-11-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 612d8f0c-bc0d-4682-4160-08da2edf1dc1 X-MS-TrafficTypeDiagnostic: PH7PR12MB5687:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1XcExLZbRUOfrR0jdyCweutb7C4/Qhj0f5G17/TO3lYQ34Oclt9D78GZw7jjAMDR1ftyvGDPpWRWa8nEx4aVPfmTb6BVLOmKB66dczcbUs44dXcNZMPSO7Ul3hTjVYpNuPddbGVHPAiSm3LJYnb2L4UCtu7phfDq4Z8k//ENEsUDN9aG54MpsbY0gTDSg5wU0FMqwnI1M4hXdxFj89E3ebLzB6TfwEXopecje/ASV68hJxAz0vZfAyZuthOLg/4qDYleKwJc9XqiRXFt+7Yc4ekzx0QgqE/Kh89V/mS8VqRitOqmeCr6dYsSvCuXowm1uL/K8UzXkRHIFTxABjNml5YwZhDlKPpfSwEB94Zy/q+Vi79cCVQZBvIlcCcD84f0WcsgvyTN5+bSFf9BvRkRIF5Ug4ijiP05BLrNdgquZdyEwlY+6dEeMePNdVYAYlOSZZn2pZ2eOeWyYPy5ZAMOFiwrxI6ca/ZZnP8JbxCnS4pgHgJWyv3VTCYtS34kMZftol4k2UPTdij1kwUxGT1JKOyz9f5yht6kDY1rthAAIMO52IV4Ls7sKMv0rEh7NTijGbmKvbRPIJEgvTj8lcfvycyYc4NlypN/9IVdR7hSXCx2MahsjWaYQdI+TBE+pRP5ct06JjJ0+64uBMveMyfnHkVaj6+gJS4YvbhVcOC0K4IssqqYiHhNLAMFsEbE2kWiMPDsP8wHfjF4qVAB1ECPJA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(36860700001)(6666004)(8676002)(16526019)(4326008)(30864003)(186003)(86362001)(508600001)(8936002)(70586007)(44832011)(70206006)(7696005)(426003)(5660300002)(7416002)(336012)(47076005)(82310400005)(81166007)(83380400001)(54906003)(6916009)(40460700003)(356005)(1076003)(2616005)(26005)(316002)(36756003)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:35:03.6260 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 612d8f0c-bc0d-4682-4160-08da2edf1dc1 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5687 X-Stat-Signature: 49g7pcx9c4mdgnaibbx4gjmzj4ubg9z5 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 104F640083 X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=VO+lVdaj; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf12.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.50 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1651786488-693606 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 | 15 ++- 2 files changed, 202 insertions(+), 66 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 15747f70c5bc..361a026c5d21 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 @@ -1101,8 +1254,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: @@ -1167,14 +1324,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; @@ -1182,43 +1338,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; @@ -1238,7 +1362,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; @@ -1317,6 +1441,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) @@ -1339,7 +1469,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 625f3690d086..e190b2ab6f19 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -33,11 +33,12 @@ 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_GET_MEM_DEV_TYPE _IOWR('H', 0x06, 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) +#define HMM_DMIRROR_GET_MEM_DEV_TYPE _IOWR('H', 0x07, struct hmm_dmirror_cmd) /* * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT. @@ -52,6 +53,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, @@ -63,6 +66,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 Thu May 5 21:34:34 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: 12840202 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 7E96BC433EF for ; Thu, 5 May 2022 21:35:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A8776B007D; Thu, 5 May 2022 17:35:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 609E88D0008; Thu, 5 May 2022 17:35:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45A578D0007; Thu, 5 May 2022 17:35:11 -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 26DD76B007D for ; Thu, 5 May 2022 17:35:11 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E08002E024 for ; Thu, 5 May 2022 21:35:10 +0000 (UTC) X-FDA: 79432995180.05.54BD20A Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2043.outbound.protection.outlook.com [40.107.212.43]) by imf15.hostedemail.com (Postfix) with ESMTP id 011D2A0097 for ; Thu, 5 May 2022 21:35:00 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dxg691vpQ6xz4zkhMFXtvMnRhDFfsIvuLA3b0oV1UV3nEJdoQgFKmbJta1W1CJxZ6OhFCKjL2tDl3ihbTgGT+5h3/fso4fISV0SRbqiDErrdRB2vAxvZJqohyD6VhJVyJ/ccDvpimsowaIEVC89hzE8mj+WD4oQexWeHKTxlaARAajxesGOEmfn9fq0FhasLPEFUphUUpIqAnJ/yXWEL6EPI7xo+42cgBc9hPoD1fiJavzH+7Yv5lIaacZTBIq7NKhFQonTxVYBoXfj2MEBeRGv5+v0NMXdjteFyxHIS6ScXgQ7h10AFIeur4C4cGb39rEe4+V+2I8ewPHgXo6QZ7A== 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=wiZRZSmKoAHg2kQsT+4ka7fOS9kQUakT1QrbMGC56FU=; b=MVG5whYFrB9YQknv4/1JhMTbHPqU0dM/HlaEB0tEB8hZrprkeQLwI3kSMv93HrbnR2j5WIMcMVHDH1STvJwWk0HTwGAMtva/ch24SwCGkczTMZaHf9+pjNA0C2n7Oz/dB04Ymz7mxS9dGQxiJLVIdstHTZxEN1RLmQhNw1n4bVgZojKJNhEK+ZzgHurIuGIkeCaEO2QiOS4tXdJo4j3g9G1hBhz+CWSg2n9yRYw4Cye9c5u/t/MGEjATmvKmjGEZgLCL1Ay6MzOoAuTzCOQfhSBB14JxE0EOdYhajwHJioQDJB81yFn2xhvU9JY7CgZLk0uevqoDaTglkVHJIe30HQ== 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=wiZRZSmKoAHg2kQsT+4ka7fOS9kQUakT1QrbMGC56FU=; b=kFab1DBQcT3rYh2lRlRB6r//PUYaK7nYZXRXxk7BEMURFpnIMFj1w5YNuXomtCb5yeFhn07QkShzBFHByOzEalKcm7doM6AyFfLYXSmYRJNdbprrkmuy8NP382HHpJaVW04zWvGGxvq7Db/om7wwA31SvQdy/ojkerO/A/y3t0o= Received: from MW4P220CA0028.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::33) by CH2PR12MB4134.namprd12.prod.outlook.com (2603:10b6:610:a7::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 21:35:05 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::38) by MW4P220CA0028.outlook.office365.com (2603:10b6:303:115::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24 via Frontend Transport; Thu, 5 May 2022 21:35:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:35:05 +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.24; Thu, 5 May 2022 16:35:02 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 11/15] tools: update hmm-test to support device coherent type Date: Thu, 5 May 2022 16:34:34 -0500 Message-ID: <20220505213438.25064-12-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 9078915d-90e8-4396-a529-08da2edf1ece X-MS-TrafficTypeDiagnostic: CH2PR12MB4134:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9GXlDLon8MSrY2FmO7mNIfad1kI7To2KrWb12neD3DQWDhshfWOne5eihzoO86rKYe6hAW6rItnzPmpPIwezBzEWvUrffWhVA4DgeXoFyzv/DJnXTtg9pn5ru18xF8+D0qjI04oZ4CaHFpwama3WzsY/5e8DKPcr7WOCCkjOHtAK61RHJOT8DoFfkeYnbe0nS9wCb2AddpS4iKy7XCe34AdBeGLcJT2sqIlg2V0w8ZMMRnzFFc9B1G+TCVqK1jpAEgcdvQM8HTp8CmkUmE/AsMoFDNuIdp9XeZRZ6L+0aKThYq0Vwg1MBlumGo0Vb6a3hmz9jWs8RrPMvVDk3tPbFfq3aYZ4JRRPbAvPl8I/7XyIeojsA+G3VzFbvDWtcoCG7G56LGgSFl5z7hvBFMRvDEf/QqsagCUhJJadlLMrOeS+dd7hqAyGffPadCtKGRz+RHiR3UHnJVmoxyB5169ryOD2IFy+eRUEGxazzaevFfA+IjwwwLiWVsL8n3Cl0x6T2wWGmNjtEfboGDJSB4pJ663hrW0GVi1VswU8ggtVFOyRjPl9pl849C6CAS1u1Jz7/uTXqkY4j3wDAMvYHw9C/6oCgCVaTKygAEPSyM4QEMgCPbcYy2qoGjbnRASUlrQqioIzHbVE5qfzal4BZ+CJ5+a4//yiMmORk4oKJsDMPWpMEYaOQNfJhuFD+VDgiI7nX4o+V/QFI0cC0Yt5u7qAZQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(36860700001)(70586007)(26005)(15650500001)(70206006)(8676002)(86362001)(4326008)(8936002)(82310400005)(6666004)(2906002)(44832011)(7696005)(36756003)(316002)(6916009)(54906003)(83380400001)(2616005)(5660300002)(81166007)(1076003)(40460700003)(356005)(47076005)(426003)(336012)(7416002)(16526019)(186003)(508600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:35:05.4071 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9078915d-90e8-4396-a529-08da2edf1ece 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4134 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 011D2A0097 X-Stat-Signature: apzi6u3hhmgisxh6ybzykp1ux6tju6i6 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=kFab1DBQ; spf=pass (imf15.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.212.43 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1651786500-476557 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 | 123 ++++++++++++++++++++----- 1 file changed, 102 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 203323967b50..84ec8c4a1dc7 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -44,6 +44,14 @@ struct hmm_buffer { int fd; uint64_t cpages; uint64_t faults; + int zone_device_type; +}; + +enum { + HMM_PRIVATE_DEVICE_ONE, + HMM_PRIVATE_DEVICE_TWO, + HMM_COHERENCE_DEVICE_ONE, + HMM_COHERENCE_DEVICE_TWO, }; #define TWOMEG (1 << 21) @@ -60,6 +68,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 +91,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 +122,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 +143,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); } @@ -144,6 +194,7 @@ static int hmm_dmirror_cmd(int fd, } buffer->cpages = cmd.cpages; buffer->faults = cmd.faults; + buffer->zone_device_type = cmd.zone_device_type; return 0; } @@ -211,6 +262,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 +940,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 +988,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 +1001,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 +1041,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 +1080,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 +1088,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 +1120,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 +1135,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 +1176,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 +1184,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 +1428,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 +1451,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 Thu May 5 21:34:35 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: 12840200 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 530CEC433EF for ; Thu, 5 May 2022 21:35:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D87566B007B; Thu, 5 May 2022 17:35:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D355A6B0075; Thu, 5 May 2022 17:35:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8A958D0008; Thu, 5 May 2022 17:35:09 -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 7CEB86B0075 for ; Thu, 5 May 2022 17:35:09 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 52F3220ACF for ; Thu, 5 May 2022 21:35:09 +0000 (UTC) X-FDA: 79432995138.08.20BE0CD Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2080.outbound.protection.outlook.com [40.107.237.80]) by imf10.hostedemail.com (Postfix) with ESMTP id 913B7C0088 for ; Thu, 5 May 2022 21:34:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=baQW5YHLjkk/FgHtwlxLUHnjL5hT3sbhjnHkBugX9TA4TGi00BhlVFn90lhbd1RHxxViBoil0xL9rKNEzCu8fSMaS/EknLqjbIEHM9k4Y5d8t5jN2yc/ZWazaY7fRLXsRD/i4u2SVYKiOo2AiaiVzhvp2cyVx1phoIdQoRPTltNy8YQYqWNxC4OLRM+xMPjP1hMQYZ0tBdBIxxiXdc//kFNTLrmlx7JFfbaZvoIbpk3k24fQVWz/WARRDyhUanTE58aMrx9mF/BFjbOgl5PK4qKEBkiYdmbuB+BaiRiF/a89thOjLd05CmNJV6+zTQJFXIAWMDDUce75OU/tfh4fQg== 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=SKFcgrLxZ9oRhqNLPwalL5O9cv1kNEek5g8KdFvRDSHpJmLP8CDaBzJWYOD6eAl/QElBmdO23yUh2VHUR8E2hjPAKNyEXO07Zg9yTGuHnabR9ASBEa42fgg6DW9wWXtOz24qf73X0R2x5fTTv/Q8Huqh/vueNYgIN749AF722CMEAvqiDbuv5iea04jkwmI2oZKJc1Bz7D0ABVWw3rnb+b2RTwbgf4MwIWFn6WWKbq6hG9evv+tJw8kOoaU29n1tZUfjSrJ+fRlKK3uHAuE712b9uVxLQhKsLSdx36vv6FWtixjVNzvcYpMHqsjYgLErpJj389UqCwlkZuKmv5eQCg== 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=or5Eeell3+xuGjRDQVchEauOVec4oO/J0B0hPxTh45Mv2Jejfr6Fd/4reLaNMAVjLfD4CF0FMz5XMTjsdRZoNHGPHUBCDSNqVZWN4RdEAfN6xc/TWoCNusDz5ciDznon6zXVD6KOgebNNhx1SPoXZkBr5nEwwZ0jJDWhb/Y9UJ0= Received: from MW4P220CA0021.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::26) by SN1PR12MB2512.namprd12.prod.outlook.com (2603:10b6:802:31::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 21:35:06 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::30) by MW4P220CA0021.outlook.office365.com (2603:10b6:303:115::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Thu, 5 May 2022 21:35:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:35:06 +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.24; Thu, 5 May 2022 16:35:03 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 12/15] tools: update test_hmm script to support SP config Date: Thu, 5 May 2022 16:34:35 -0500 Message-ID: <20220505213438.25064-13-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: d0e19951-302f-4ce9-75d0-08da2edf1f43 X-MS-TrafficTypeDiagnostic: SN1PR12MB2512:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lLEfd19q8VJ/pHMfsikQCLxYlJ4GdTvH4iMPFgZUD4MVPQQ/XVIdmEJ4gKQNuxmt/S56kIOPbDq5PXOTsC1Oyhm3UwR7hfEraSEoXMHfN3OmF++7X0bcE/fXGWbT5ZIq93nv6scFHIdIYLPlWhWjQxVRBg1BYkx1pZhuWfWJF4uFgnM4SO/M/71it9D3AU7XjXfC+iWU9AB6G8c+cVhvDIP02VfquML7ZzX0cdJLqVlz1X7yYE2hxtOmLmoGbrV++u6r82EKegI9Q1W15AQ3wjmoGm4NlqLG3QGV2LU19ZH8+of8vaEQ4MJq1JmKROq6U8k+YQjlCqL7dvPWKHF2exEa9fN/S+oZYVaVJzWEUNga0d+ylQt5+KxKG4/wRmn5vOO+R6ALmZJjUHIFFZOutkNX+Y8zTWzafVLgfmWety6+Shqj4iHdAq7Uzaw14isRbbRHu++YrcFV7Tc4ntKK0BP6kfw1t4eO6UhUMm5lSGoG901C3Amu/1tS9Y65jrawWGvMhsNJzeA7+jWYs57B9PaHxZwqWps9QYwhp16fwVCd+s2lvAWkDFgwren9RgeZAkqsHANxbticG2b5938yyqp+XwN8aYvx+NxVBM8sPYLPz0fzjKAC6qEuNblbN4569G/aUK4YyYCKmRGK49rFpPJ/sctYq00pR08IHmXaYNga9aph6246FlBm+XN6IEw0l6eLMoJuowRER6nTZakJNw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(7416002)(44832011)(356005)(40460700003)(6666004)(6916009)(2906002)(508600001)(316002)(5660300002)(83380400001)(86362001)(36756003)(81166007)(82310400005)(36860700001)(47076005)(2616005)(16526019)(186003)(336012)(426003)(7696005)(26005)(8936002)(4326008)(70586007)(70206006)(8676002)(1076003)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:35:06.1727 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d0e19951-302f-4ce9-75d0-08da2edf1f43 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2512 X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 913B7C0088 X-Stat-Signature: 1bfe4tjchjqxcri566m9e3o38kromfmo Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=or5Eeell; spf=pass (imf10.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.80 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1651786491-585171 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 Thu May 5 21:34:36 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: 12840203 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 1C035C433FE for ; Thu, 5 May 2022 21:35:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CEA36B007E; Thu, 5 May 2022 17:35:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 62DCA6B0080; Thu, 5 May 2022 17:35:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 482938D0007; Thu, 5 May 2022 17:35:12 -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 22EF36B0080 for ; Thu, 5 May 2022 17:35:12 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id EAC3B121249 for ; Thu, 5 May 2022 21:35:11 +0000 (UTC) X-FDA: 79432995222.15.88E0B60 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2067.outbound.protection.outlook.com [40.107.244.67]) by imf28.hostedemail.com (Postfix) with ESMTP id 3398DC0083 for ; Thu, 5 May 2022 21:34:56 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f4iZpmqu19080OM2YqGzuCdtKix8AAjbePvqBBHuvpqDWC5RSBN3zsPQMTt8E/i5DBmqtViUfNkBA+7kCOG6/2ChIqgeo8FUUtwaP+n6TxqseM2/LK8urmWd2vdaQiJRZtXXjAmma7OCZ4e/Ry0aFAFURObc1KOQLO+tbnXr0nIepF/6VH4GSWzDiJTKt9iI6lQMMxvB3okxboTtRkVs89nf/hz7Csgt8aIXrIhdZr2ZjYunwi0ZQheP3p2iormGiXho3Y08nwfDA09Vu1n8G8vQMipybu2eD3Uqrevor5lAVnl64nLNi7GrwY5qEbdnm5v7WFDuRlaz2SzmGwGXqA== 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=if0H0QCoyRo0sJv9gd+yO7kqUKukXawMx0XCaW35lkQ=; b=JLmFb109uEfu2feeYd/S6jPbSDxlDuQLGK+8i7CxV0ecjdoYlpfgBGmRuLvmBy8Xp2GfI8ZejveNm3+SEAAy5+FsxHsQCTfG7ab6g3Cx9+J8eOZ3XHuUBOuK6WmQksBqhBZ9RwMwIcG/KGtuuiUkaF4fDcJSeFlIs4isg66iyO+Fgve3TM8soa99dh9v5ET6W7YyDv1rMTa4ZOBe2473NbfcJfspPfKViGuqwnRrSWPt88gm4e5wKrLSZ+EOCNpBgvTUmITOMPzfIZUhBHdAN++OStWkREW1cwXGnVTuYPi3wokJxY7rc5ZlmuTkrVRULfLSxLE+X3XK4GHPCrgu2w== 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=if0H0QCoyRo0sJv9gd+yO7kqUKukXawMx0XCaW35lkQ=; b=AOBTPBwu1hHCAyelJwNAKU5nNWtS0yqbg+30HBs3vEFCEpxFsPFyZdNkiAy8jHo7daoe+AbZ/MlRDmRwqoYUeciE9zZRP78gOAKiEVPU0sIHQh1aSqpa/a/J98Imc940tV2xgS8VYJmIL4bhqCjunBmbyxC41OW2ZFYq+q384Yg= Received: from MW4P220CA0011.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::16) by BY5PR12MB4068.namprd12.prod.outlook.com (2603:10b6:a03:203::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 5 May 2022 21:35:07 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::3b) by MW4P220CA0011.outlook.office365.com (2603:10b6:303:115::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Thu, 5 May 2022 21:35:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:35:06 +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.24; Thu, 5 May 2022 16:35:03 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 13/15] mm: handling Non-LRU pages returned by vm_normal_pages Date: Thu, 5 May 2022 16:34:36 -0500 Message-ID: <20220505213438.25064-14-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 37c935eb-650a-4dc5-0b38-08da2edf1fbd X-MS-TrafficTypeDiagnostic: BY5PR12MB4068:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0Acqge5q3nGDWWMYzxvFwFYyXCL3RxUBAmJYh59rM+LY58AOLPJJw6xmUa79Kojdm1cKmKICcpBo7Drsg2jYpikGBULUpwQtwtlGfwPazxXXwl2w4cBctBejgs3MPzgUp7PqqhMPekzPDMFH0x2Dp7Z2gLQab0Qieprg/0ruKyO1j7cBj+xgRfIhTa8MPKsvJUy+ZZriPRIWUrsJhFQBHrcZeCjXhZm5mwKk/3RiJ9x41tAXyo1iGeekcKiEQb7eFNZL9L8PfjlyOMIDBpmIp7A7PWu1MA1M9pKTmt5SduQQUlbMmn6uROCTIB7twiimv92xJO3Di+EYIUON2ezqaFSubr2RDvSiu5cI/BUcyZ0Y+Y1XkxjXvcCUEnyHM52MJdsoTk68uhpXBxbMpJ2JlPkVUjkCUty7JGW+/pCPgPn8FgS0j9g8EOpnHwXr0BLqgzH3eM3TcHoxx3waR5uvL+3xB+9Xh3xgX3Np5ZIAwH9MpWpV8VpYGvi+K0I33A9xXa8kADSm03YdKLts6ovzThxpGDb+IOYUAH5CQwIPfD19mF6RmTKAM6Z1G5WKjp982kwtsMTTUn1Bkl4C8pePRH94yGpClhpOur06ibuTuhIi1PcR5tnVg6oHt6RPLVzYrtNFvR/hMnq/QKFPif+IfW/zN0B3n0YpAWl1J9uB6t+vWM0fKN7rnVd6YRhTSghG8uTFX9iFFCBmxNSoTglLMw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(44832011)(2616005)(40460700003)(86362001)(7696005)(6666004)(356005)(36756003)(508600001)(83380400001)(70586007)(8676002)(2906002)(81166007)(70206006)(186003)(4326008)(16526019)(36860700001)(82310400005)(54906003)(8936002)(1076003)(316002)(47076005)(26005)(5660300002)(426003)(336012)(7416002)(6916009)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:35:06.9070 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 37c935eb-650a-4dc5-0b38-08da2edf1fbd 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4068 X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 3398DC0083 X-Stat-Signature: iqcmbyu3gpsexyzjdz9efbjnur3qwp6d Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=AOBTPBwu; spf=pass (imf28.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.244.67 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1651786496-760696 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 --- fs/proc/task_mmu.c | 2 +- include/linux/mm.h | 3 ++- mm/gup.c | 2 ++ 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, 30 insertions(+), 17 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index f46060eb91b5..5d620733f173 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1785,7 +1785,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 9f44254af8ce..d7f253a0c41e 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, @@ -2929,6 +2929,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 a214c8df7140..13bf04bce132 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -479,6 +479,8 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, } page = vm_normal_page(vma, address, pte); + if ((flags & FOLL_LRU) && page && is_zone_device_page(page)) + page = NULL; if (!page && pte_devmap(pte) && (flags & (FOLL_GET | FOLL_PIN))) { /* * Only return device mapping pages in the FOLL_GET or FOLL_PIN diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c468fee595ff..dc572bc9fa1c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2851,7 +2851,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 a4e5eaf3eb01..eb3cfd679800 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -627,7 +627,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; } @@ -1276,7 +1276,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; } @@ -1484,7 +1484,8 @@ void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr) goto abort; page = vm_normal_page(vma, addr, *pte); - + if (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. @@ -1502,6 +1503,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 (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 063a48eeb5ee..f16056efca21 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)) { @@ -2288,7 +2288,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 1873616a37d2..e9c24c834e98 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -413,7 +413,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; /* @@ -628,7 +628,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 76e3af9639d9..892c4cc54dc2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -621,6 +621,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: Technically this should goto check_pfn label. However, page->_mapcount + * is never incremented for device pages that are mmap through DAX mechanism + * using pmem driver mounted into ext4 filesystem. When these pages are unmap, + * zap_pte_range is called and vm_normal_page return a valid page with + * page_mapcount() = 0, before page_remove_rmap is called. + */ return NULL; print_bad_pte(vma, addr, pte, NULL); @@ -4422,7 +4429,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 8c74107a2b15..e32edbecb0cd 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -528,7 +528,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 e18ddee56f37..ed7ea77de539 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1612,7 +1612,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)) @@ -1803,7 +1803,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_DUMP); + page = follow_page(vma, addr, 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 b69ce7a7b2b7..a6f3587ea29a 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -91,7 +91,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, 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 Thu May 5 21:34:37 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: 12840204 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 AFC66C43217 for ; Thu, 5 May 2022 21:35:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96A8E8D0008; Thu, 5 May 2022 17:35:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A7618D0007; Thu, 5 May 2022 17:35:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56A6B8D0008; Thu, 5 May 2022 17:35:12 -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 21E426B007E for ; Thu, 5 May 2022 17:35:12 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EB90220ACF for ; Thu, 5 May 2022 21:35:11 +0000 (UTC) X-FDA: 79432995222.10.AFD9C61 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2044.outbound.protection.outlook.com [40.107.236.44]) by imf10.hostedemail.com (Postfix) with ESMTP id 39CD5C0089 for ; Thu, 5 May 2022 21:34:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JZbfoJlBCLdTu0z6wRgbRKSzhziJpeeA9X8nkrR92ZZjZOSs06lBsY8MSrxNlR8Udu3EXZJL/QkC7viXebbadVRyPpcRO/WA5C5ngWlPgBdO+wMGc2isXrdKdsqh3BVzMepctm7W4srWFYT0l3zUwak9XiErcd+CThpMTECELyxOP/kfpOR019aDyN64iQQYgPH5N6h57C1ONrmec5W8CUXfQc45OwgJkhpgNfW91s+FhIwCW2Wcbs9I4s0wp51TPSP9gVvsojN5Yodnp7lCZfkaDcSJqtT30hk6+TmvIntQp/kAcS9GNifJ75Ek2ebFClx3aDWgrtWFbey4CSNi6g== 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=VrS9HrUH1LeQW+9lM86CVpRR7dCkow2uCtC4hBLoPZY=; b=R0RLm5VaENRPLZhqSU8aAi47QvoBDfc5V8BsxUIrTSSZFbCX1WBKQTIaixoHKuOc+wiVoBQAOanAp8wcT6ZdvDbSGK5aLfeYNhJ86+jSgMUB0opwkZqeO8Yn8MMAW/qusJ5X/mBHUdOyf5iEvPYU5gUauEJDlJTQkZkElAeo+nsqx6ezY9kb3fBJah6mFDpWSeEan3OP0evQy8srDUgHWV1BX5NTdJ+mBY7cwBBRlAsUagPS0S5Ijs+nwme5TLxRprPjVvBm5+hUjhOyEsj3HpBJ1e4xjxkzrz/tN6XFxl2/5urVfwJyI69HnT25btMBlknwC32qK1sTCdOjYBe0Yg== 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=VrS9HrUH1LeQW+9lM86CVpRR7dCkow2uCtC4hBLoPZY=; b=AWR/0KsP1gp1PlooUrsFdqI6tkUTPWkAmtcS8iZKQYYqDjtMBUKj4Hki3daR7vc5lp5c8DO6YiHKk+/0lgeR9yi7IO6DnDWgGPj3nq0bj5lFO9JYKBegTfsJoxh0FjkCcxu9m50eUaAG1pT30lmfRQ5h5DPHX2+a1DhF0ViPpv4= Received: from MW4P220CA0007.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::12) by DM6PR12MB3754.namprd12.prod.outlook.com (2603:10b6:5:1c4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 21:35:08 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::2b) by MW4P220CA0007.outlook.office365.com (2603:10b6:303:115::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Thu, 5 May 2022 21:35:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:35:07 +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.24; Thu, 5 May 2022 16:35:04 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 14/15] tools: add hmm gup tests for device coherent type Date: Thu, 5 May 2022 16:34:37 -0500 Message-ID: <20220505213438.25064-15-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: f4422ace-138f-4185-401b-08da2edf2015 X-MS-TrafficTypeDiagnostic: DM6PR12MB3754:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2YUBEx2OQhABYoOxfepX95pGHs9nDBiLvT5CtRxA476Ci7el5YwS/uQ4Rf+/xcWW6SFu4mP8VZS4Z2j/+b/wViAC6K5KS1AdKE+EgC05Bb6K35lVhc/UbFEYAAwirLkGNcGSp/zihdtLpvWZxK4808Jh66nAEodp7Pagq7qM5kxz0RswJLvXO8ecLOSf4rxB8um8yoFcahvmU0BGCNq6/DD4m5V69CqO5RObaA4FAW2K2P1GAJL8s2OkH9URaT1hNRbjz273JgnZnWz4K3vsBfOmjaUc9G/6/47CaphuNmg7JHr5Fc3ZGDIc7pGgSDTxFAzxGRJQX2sQAGm+bYd3hNbOe/9jCKdL8PFGjh0MgcTSG2aAKqLDD/Y6RbLRKhOejj8LLlm1KlVt7iKbcl7y+SITxOi8uWTSXu8FRYZOVqxGRSK/P3jjib2Byq5Yk0QZxMCt4q+JsB7O+TkWbp1S/N77Fx0cM9itAhYjhpL7aUUxnRJaXhsfBY1+tpWC/7Z1FrLqKsX8cqdbEfc+INrtYWQ5X6hEl0D6EwM7xzd4UbcKwQIkjSI8SB7cxzOWk2Cs2D1a96xeib+DRZ7NvOouB3Sg+SnFY62+b4bmYD4GFjdByBSFZJDttU3DJG/Nyu9WBNFEuBizbClQVMEq213WSXGQ8Bn8k5wb309/lG+NfEQwcEEtEJuws7t5SFcHfbflXnwGaYLT6k9mxPTQCNvtjg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(7416002)(44832011)(356005)(40460700003)(6666004)(2906002)(6916009)(316002)(5660300002)(508600001)(36756003)(81166007)(82310400005)(36860700001)(47076005)(16526019)(83380400001)(86362001)(2616005)(186003)(336012)(426003)(7696005)(26005)(8936002)(8676002)(4326008)(70206006)(70586007)(1076003)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:35:07.5319 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f4422ace-138f-4185-401b-08da2edf2015 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3754 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="AWR/0KsP"; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf10.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.44 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 39CD5C0089 X-Rspam-User: X-Stat-Signature: ptxqsnfj6cr3idztaso5b4ipxd6eb1jm X-HE-Tag: 1651786494-531772 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 | 104 +++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 84ec8c4a1dc7..65e30ab6494c 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; @@ -60,6 +61,8 @@ 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 */ FIXTURE(hmm) { @@ -1766,4 +1769,105 @@ 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) +{ + struct gup_test gup = { + .nr_pages_per_call = npages, + .addr = addr, + .gup_flags = FOLL_WRITE, + .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 = 3; + 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); + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr + 1 * self->page_size, + GUP_FAST_BENCHMARK, 1, self->page_size), 0); + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr + 2 * self->page_size, + PIN_LONGTERM_BENCHMARK, 1, self->page_size), 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]); + /* 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 Thu May 5 21:34:38 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: 12840205 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 6D2A4C433FE for ; Thu, 5 May 2022 21:35:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45E248D0009; Thu, 5 May 2022 17:35:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BF688D0007; Thu, 5 May 2022 17:35:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20F938D0009; Thu, 5 May 2022 17:35:16 -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 048568D0007 for ; Thu, 5 May 2022 17:35:16 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D048761165 for ; Thu, 5 May 2022 21:35:15 +0000 (UTC) X-FDA: 79432995390.11.C02AF42 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2068.outbound.protection.outlook.com [40.107.101.68]) by imf12.hostedemail.com (Postfix) with ESMTP id 20FC94008C for ; Thu, 5 May 2022 21:34:57 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fcZkF5d5Swf5dspJvhDvxsDLpUyXOu9siD4m9TqBWZmezETDicCaXM/g/6feh/pP93h6cfOBcdbsaWwbYpB3+7t8rwrIup5ksidtQ4UE/FAspN5DhfrsEJjYTSmpcGUoEKUGCNM4l9ohiPPnxh4mIe+lZaBR9S5kbOkqmO6cIoMSI3VVB6qSoIW3DWknPZ1PQRg22ZweLLhYGVqZJoXdWPgADklBjaVv+2O0Ej2kElKa4dP/QqsQFGxzoKIbzjEFtqVdKcg7zxfW76mvOphawoVm29aoEQwampMBsQ0QgiiErJ7JyHjq3fbUIPBPBGw+kSHzDM1c2suOic103RroLA== 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=+v+1UPaPthHsygapXxuY4sqVDC3cvlVfCyGWQ0h08FA=; b=FDOWVixT+7Ge2xV+HYgOb4F8Asbsm/gWf4Tf6R0U+VUBwEpU0177waVnP6WOt5dYi+eDqMvSOIrBzLRXvfIEXPB9lBXynazCtqtZrnf3MxIkMUEDiFvMP97j7f5pJUWSZc/2Q4Lv+ostg3LM45kArISqCNZqwGiO/dBcFjpmRqw9HjrhdPiFsySReWvli7N0ANaWiT/LFgJD2Fu1rhpgRvFvctnfZAqqEHEbL0yoxtQVKE7RR9YQ6EDPLrCuePjiJrsOkTY2iUfIMgXuiUHl0ocOHMQrJ/zqe/aYqCGU8earYZSlvSfJ+MNFdF1BFg8UnDIYf97jahZW0iR6w9sg5A== 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=+v+1UPaPthHsygapXxuY4sqVDC3cvlVfCyGWQ0h08FA=; b=BU+ZP2k4XFl6VahBRO8AjeeXqVgDaXOQvnYWvLTvFrBjhFNM05vr+8zf1hAY/4gAI5Sn1NI+ZsuIwAb9HLA4I5qkbWwyfyvHFfo765lqFPCZ/CPGyY2phhbSuW+CIJB3Z5sllKto7mAVCWRUc+VK/pCNuOhVz84MCN/858Ik240= Received: from MW4PR03CA0027.namprd03.prod.outlook.com (2603:10b6:303:8f::32) by MWHPR12MB1376.namprd12.prod.outlook.com (2603:10b6:300:13::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.17; Thu, 5 May 2022 21:35:10 +0000 Received: from CO1NAM11FT050.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8f:cafe::48) by MW4PR03CA0027.outlook.office365.com (2603:10b6:303:8f::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.12 via Frontend Transport; Thu, 5 May 2022 21:35:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT050.mail.protection.outlook.com (10.13.174.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:35:10 +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.24; Thu, 5 May 2022 16:35:05 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 15/15] tools: add selftests to hmm for COW in device memory Date: Thu, 5 May 2022 16:34:38 -0500 Message-ID: <20220505213438.25064-16-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: 18397a44-07b2-427b-c428-08da2edf219d X-MS-TrafficTypeDiagnostic: MWHPR12MB1376:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o+FpmzbRPhi6/A1DyxrxbPiO2wzcHSkkhDZxbnT9+cU3YjUR1KfzC3hCKc8f3Dtfwgp9QSN+fNqRgVRNhTNw0PAWz/lSlHtPGfuAoJpSRrrYqIrwwARRNlVR0zw9K5DfXYWJO7wZ4WkUNr/D1rmPj2ucz5/m9tpCpaaABn/ERujJwJIWvGKVtTsw6JihF+GSFfxwKpPoxOHzkOKNFRGSFC4DL39Oq/Jgn/8rmpusGp5G30pB2jSYkF4dHMq0yxNBdyUbALHBaWskSSuHw5bkfgiNu7WhXKX/bIrysWmaFcg7NtxPOmdHRw3fEQlQt9P3SQP1W7Nx4FLhl8yMD/Vgm+cMH0qH25SbcjfpF03U4QQxp9RdQB3uiixaFByieDBCgN83alNrouoSPSSE2VKyOSWUlse1dBGlhqo2rO01RtPgpFtpn0qB8zqG70HA3bsc5Cz+Isu2Btm+Wicd5HM5S7wipAmNcdWQemrytsVb6hESI8D7PRmj6G+QpUldlQJYoHRdpuLt0ISmIsxLz+aT+IhJ1RsIM8hBskTdMCvLrlQg49elduCBaRHoigUOa1gRTPIRSGrX5wB+EOGFJDZLjy/EbuqOoQdN10NQGGOXaEWK8Gol2lYjsaBapXp0gAnrPBYjCnDPmytRXh9dwG1AhrwuqRM46ATFT4MvmV8WpebzC3xx+ZNRyyhj3La93JJ9mVgJtDejW8Mi+nd2ZyoPYQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(1076003)(426003)(83380400001)(186003)(336012)(47076005)(36756003)(16526019)(40460700003)(2616005)(44832011)(82310400005)(36860700001)(2906002)(70206006)(8936002)(5660300002)(26005)(6916009)(7416002)(508600001)(316002)(70586007)(81166007)(86362001)(4326008)(7696005)(8676002)(54906003)(356005)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:35:10.1043 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 18397a44-07b2-427b-c428-08da2edf219d 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: CO1NAM11FT050.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1376 X-Stat-Signature: uq6uubdkk7w3mc81j34s8w5m77wxosg7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 20FC94008C X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=BU+ZP2k4; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf12.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.68 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1651786497-781952 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 65e30ab6494c..d70b780df877 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -1870,4 +1870,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