From patchwork Tue Feb 1 15:48:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12731939 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 73A32C4167D for ; Tue, 1 Feb 2022 15:49:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6F896B01FB; Tue, 1 Feb 2022 10:49:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DCE866B01FC; Tue, 1 Feb 2022 10:49:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C222C6B01FE; Tue, 1 Feb 2022 10:49:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0150.hostedemail.com [216.40.44.150]) by kanga.kvack.org (Postfix) with ESMTP id B40CA6B01FB for ; Tue, 1 Feb 2022 10:49:17 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 780AF181A347E for ; Tue, 1 Feb 2022 15:49:17 +0000 (UTC) X-FDA: 79094645154.25.59B0AA2 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2053.outbound.protection.outlook.com [40.107.96.53]) by imf12.hostedemail.com (Postfix) with ESMTP id CD25E4000C for ; Tue, 1 Feb 2022 15:49:16 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PEDip/9jomnVr7NihwMFTlL/1WSPR7G3NL4pZangvQhZZXt90Opjj+r3NRWs8zbQ/EzU28aBnceBM9kbW/Io3vU3z7A5OiE56Z5HBL7TBGq65ZtP4mNXrg9mjLn/HKKUF7jL7JG+uak/TC20XpMG5KXAu+Rg2vrhJF3P0NskDf/5SZ22OwgmdAnN3r0js9VZJVZtiN3r4UchWLflOOCVAmV/gNerZLDAFhEWTKRlSj2uaXoSJqZv0vcEplUY9tutNFK93uhO2LGcuFFj3IiGYNVBMNvo2jbUJ0aydHD8t3qsgtOPeGGkxRpy3S69wADofq7j1Pb+0AJqFuGukE5YpA== 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=T4njNIIT68+hA4HQaRdLZevr0Po5/efULOp/iluBl5Q=; b=iIoXXzqNS+YCI2N0Pw+pSapdyfFpNFVpGUifZog3K8IsssJq3QNYeYJyKZprt0QK3LeP3W8dWd3fWJCvlvlo4F4bGwnNovRWFpXbcsG0niz99JqEAk/UNVfXzmm3zCoMQR/kVLejnBXr0qQJ2n9LTT2gcGXByEQKCkOqXNqfa0muMpWqbqflG4YiDs5tPXX7U8EYapjSJvwtSBW9jRQO8nT5aDs76w2G3GBODT6H1iLRqked6mQ1ZpVJMBxJNURWfiG2c63jIqhYFsg0Zr5mBKVGR/6s50mxaSQL9aUXMZu/aHc9kmQLRIuLD/JzX8L/p7At6Q4ISPKX8ssT1OXDfQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T4njNIIT68+hA4HQaRdLZevr0Po5/efULOp/iluBl5Q=; b=yBAcTpmLsy/yz3ZCi8UDZJ6cZi0HU3pUQcDZRTq0QqUUTxyTER310wwxMaPrElviNPAGV7HwzyiS8s71GFOpc61isPuMpEDhTk1e3JntWoP/IeKil9eGYfHgtaKIgoPhHzNJW1nMV1VL2A7tsABP6tir/9n7Qx7fpB5xH5n78SE= Received: from BN0PR04CA0050.namprd04.prod.outlook.com (2603:10b6:408:e8::25) by MWHPR12MB1438.namprd12.prod.outlook.com (2603:10b6:300:14::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Tue, 1 Feb 2022 15:49:14 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e8:cafe::c3) by BN0PR04CA0050.outlook.office365.com (2603:10b6:408:e8::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Tue, 1 Feb 2022 15:49:13 +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 BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 15:49:13 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 1 Feb 2022 09:49:12 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v6 01/10] mm: add zone device coherent type memory support Date: Tue, 1 Feb 2022 09:48:52 -0600 Message-ID: <20220201154901.7921-2-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220201154901.7921-1-alex.sierra@amd.com> References: <20220201154901.7921-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: ef455a45-0663-4a2a-ca90-08d9e59a6538 X-MS-TrafficTypeDiagnostic: MWHPR12MB1438:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yVvqZxnsD2cAdNeIC6XIPgAkmQ3DfaGDtSIw53i2DU+AsRo6XpxBZfqVoDT/Lzu1Ww9v3sgRqAbiSd0Zg7Vh1ywac92YMDHPWS82JHjECN5lhFalOFxUJ/nazliXGfDxJvbMRULSIz0t93DpiXQfLmqunArig0LIuzNSP2hV3hJXg13kMV4yKUF7MK63MaTmHjp1q8zKZ1Q5vepaGSUlWgrN4S3QTldt4AGZibx8SXWmnMhEmJRZo7Fuhbzs97VHNKYzytKXmbqG3f2WlX6L1h20t5fNdY+guXzpDg59IoTXe8R892dpHBViQrFgmrjnzZ67wfZkJ9Pz/PUTDKcR2HYT6spWjonC5aga1QFVb0tsmh7IA5rbrHuuiEmopPfKgFoyMJhCerEFM20D0p+lSIHKOuYFx/7F+ERZKx4krAGdDTQlTru7oPpVH4iRr1MKkTkvy3iac3zNYAzO1QV6Siun4dv+mz/B4dzOnnBwrrm9gJv+wytsbuBpOVdQwmxaCXjU6Ensrzh/ZFU8GJctkoenPYJLjMlSPklvHiAt72aEEfvVYoEud4QjSbl2fpAPt0pbBzdy4OiHNk0DEsIfxJJwIawxXc7Mt+D+CdfqxSe+Kkvk7hyDcq14ZwB57rLyazap8rwtI7e891lsL9D8SsPkWgiul6EVCYJ52IJjW7dPhi2jXenn2CAvqRigA1IuyK03MUZfQKsygiy7zxBytA== 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)(86362001)(81166007)(82310400004)(8936002)(8676002)(2906002)(4326008)(47076005)(356005)(83380400001)(7696005)(7416002)(70206006)(70586007)(44832011)(1076003)(6666004)(54906003)(508600001)(110136005)(36756003)(186003)(5660300002)(40460700003)(16526019)(26005)(336012)(426003)(316002)(2616005)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 15:49:13.4799 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ef455a45-0663-4a2a-ca90-08d9e59a6538 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: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1438 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=yBAcTpmL; spf=pass (imf12.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.96.53 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: nil X-Rspamd-Queue-Id: CD25E4000C X-Stat-Signature: 4ppe881zeq3z8c7gqdgjqx86xskqk6jg X-Rspamd-Server: rspam12 X-HE-Tag: 1643730556-640472 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 --- v4: - use the same system entry path for coherent device pages at migrate_vma_insert_page. - Add coherent device type support for try_to_migrate / try_to_migrate_one. --- include/linux/memremap.h | 8 +++++++ include/linux/mm.h | 16 ++++++++++++++ mm/memcontrol.c | 6 +++--- mm/memory-failure.c | 8 +++++-- mm/memremap.c | 14 ++++++++++++- mm/migrate.c | 45 ++++++++++++++++++++-------------------- mm/rmap.c | 5 +++-- 7 files changed, 71 insertions(+), 31 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 1fafcc38acba..727b8c789193 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -39,6 +39,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 @@ -59,6 +66,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, diff --git a/include/linux/mm.h b/include/linux/mm.h index 213cc569b192..545f41da9fe9 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1106,6 +1106,7 @@ static inline bool page_is_devmap_managed(struct page *page) return false; switch (page->pgmap->type) { case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_COHERENT: case MEMORY_DEVICE_FS_DAX: return true; default: @@ -1135,6 +1136,21 @@ static inline bool is_device_private_page(const struct page *page) page->pgmap->type == MEMORY_DEVICE_PRIVATE; } +static inline bool is_device_coherent_page(const struct page *page) +{ + return IS_ENABLED(CONFIG_DEV_PAGEMAP_OPS) && + is_zone_device_page(page) && + page->pgmap->type == MEMORY_DEVICE_COHERENT; +} + +static inline bool is_dev_private_or_coherent_page(const struct page *page) +{ + return IS_ENABLED(CONFIG_DEV_PAGEMAP_OPS) && + is_zone_device_page(page) && + (page->pgmap->type == MEMORY_DEVICE_PRIVATE || + page->pgmap->type == MEMORY_DEVICE_COHERENT); +} + static inline bool is_pci_p2pdma_page(const struct page *page) { return IS_ENABLED(CONFIG_DEV_PAGEMAP_OPS) && diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 09d342c7cbd0..0882b5b2a857 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5691,8 +5691,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. @@ -5726,7 +5726,7 @@ 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_dev_private_or_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 97a9ed8f87a9..f498ed3ece79 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1617,12 +1617,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 6aa5f0c2d11f..354c8027823f 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -44,6 +44,7 @@ EXPORT_SYMBOL(devmap_managed_key); static void devmap_managed_enable_put(struct dev_pagemap *pgmap) { if (pgmap->type == MEMORY_DEVICE_PRIVATE || + pgmap->type == MEMORY_DEVICE_COHERENT || pgmap->type == MEMORY_DEVICE_FS_DAX) static_branch_dec(&devmap_managed_key); } @@ -51,6 +52,7 @@ static void devmap_managed_enable_put(struct dev_pagemap *pgmap) static void devmap_managed_enable_get(struct dev_pagemap *pgmap) { if (pgmap->type == MEMORY_DEVICE_PRIVATE || + pgmap->type == MEMORY_DEVICE_COHERENT || pgmap->type == MEMORY_DEVICE_FS_DAX) static_branch_inc(&devmap_managed_key); } @@ -327,6 +329,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_ZONE_DEVICE) || IS_ENABLED(CONFIG_FS_DAX_LIMITED)) { @@ -469,7 +481,7 @@ EXPORT_SYMBOL_GPL(get_dev_pagemap); void free_devmap_managed_page(struct page *page) { /* notify page idle for dax */ - if (!is_device_private_page(page)) { + if (!is_dev_private_or_coherent_page(page)) { wake_up_var(&page->_refcount); return; } diff --git a/mm/migrate.c b/mm/migrate.c index c7da064b4781..cd137aedcfe5 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -345,7 +345,7 @@ static int expected_page_refs(struct address_space *mapping, struct page *page) * Device private pages have an extra refcount as they are * ZONE_DEVICE pages. */ - expected_count += is_device_private_page(page); + expected_count += is_dev_private_or_coherent_page(page); if (mapping) expected_count += compound_nr(page) + page_has_private(page); @@ -2611,7 +2611,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, @@ -2676,25 +2676,24 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, */ __SetPageUptodate(page); - if (is_zone_device_page(page)) { - if (is_device_private_page(page)) { - swp_entry_t swp_entry; + if (is_device_private_page(page)) { + swp_entry_t swp_entry; - if (vma->vm_flags & VM_WRITE) - swp_entry = make_writable_device_private_entry( - page_to_pfn(page)); - else - swp_entry = make_readable_device_private_entry( - page_to_pfn(page)); - entry = swp_entry_to_pte(swp_entry); - } else { - /* - * For now we only support migrating to un-addressable - * device memory. - */ - pr_warn_once("Unsupported ZONE_DEVICE page type.\n"); - goto abort; - } + if (vma->vm_flags & VM_WRITE) + swp_entry = make_writable_device_private_entry( + page_to_pfn(page)); + else + swp_entry = make_readable_device_private_entry( + page_to_pfn(page)); + entry = swp_entry_to_pte(swp_entry); + } else if (is_zone_device_page(page) && + !is_device_coherent_page(page)) { + /* + * We support migrating to private and coherent types + * for device zone memory. + */ + pr_warn_once("Unsupported ZONE_DEVICE page type.\n"); + goto abort; } else { entry = mk_pte(page, vma->vm_page_prot); if (vma->vm_flags & VM_WRITE) @@ -2796,10 +2795,10 @@ void migrate_vma_pages(struct migrate_vma *migrate) mapping = page_mapping(page); if (is_zone_device_page(newpage)) { - if (is_device_private_page(newpage)) { + if (is_dev_private_or_coherent_page(newpage)) { /* - * For now only support private anonymous when - * migrating to un-addressable device memory. + * For now only support private and coherent + * anonymous when migrating to device memory. */ if (mapping) { migrate->src[i] &= ~MIGRATE_PFN_MIGRATE; diff --git a/mm/rmap.c b/mm/rmap.c index 6a1e8c7f6213..f2bd5a3da72c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1835,7 +1835,7 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, /* Update high watermark before we lower rss */ update_hiwater_rss(mm); - if (is_zone_device_page(page)) { + if (is_device_private_page(page)) { unsigned long pfn = page_to_pfn(page); swp_entry_t entry; pte_t swp_pte; @@ -1976,7 +1976,8 @@ void try_to_migrate(struct page *page, enum ttu_flags flags) TTU_SYNC))) return; - if (is_zone_device_page(page) && !is_device_private_page(page)) + if (is_zone_device_page(page) && + !is_dev_private_or_coherent_page(page)) return; /* From patchwork Tue Feb 1 15:48:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12731940 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 8499DC4332F for ; Tue, 1 Feb 2022 15:49:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 859F88D006C; Tue, 1 Feb 2022 10:49:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 78F468D006B; Tue, 1 Feb 2022 10:49:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 51DB38D006A; Tue, 1 Feb 2022 10:49:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0076.hostedemail.com [216.40.44.76]) by kanga.kvack.org (Postfix) with ESMTP id 305926B01FF for ; Tue, 1 Feb 2022 10:49:19 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id CCB3F182587FA for ; Tue, 1 Feb 2022 15:49:18 +0000 (UTC) X-FDA: 79094645196.31.C10FF0F Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2054.outbound.protection.outlook.com [40.107.94.54]) by imf07.hostedemail.com (Postfix) with ESMTP id C58FB4000C for ; Tue, 1 Feb 2022 15:49:16 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IEIPmtVES7tWmxq1TEpJStOonCJIdfSJLDuhzEIEWOA5k8ToiqWDVxt3vRyMpRfRlGB1f//pQIMIsHdMx/ghS0p4ab1yaSmonm6hskJCW/aZeLaC1p56rvepjmz/z0jKso4Fotq6WSsMlm45mU0AVO2z7mFaejiMVQR6XrYt1PFT05k9SOENPVvp8SAmP9nmcAAH9lU46sRlUQWZTkbzpsIo9WVXJPJ7MQkVJWl/nhfRZLJTST/uMdXe6PpNdbQ8GLrACOmHicLpb7kuqsHnuo6MfF+5DOFFlCpPXDTf95fZHgi+9JuUkEZRrg/GLM+T39iy4wjKzbY3UgLAAXb2YA== 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=R+Ds8XuvIQCliA5UspM8Oc/AcPjUdtndfcKQDOa3/hc=; b=TPHPwnfjbc1q1yk8ZaW8uqjFqvENWOqLjHJXu/xQm2TQ1H6Xk7zWsI5Gd0NJ2g8K9roVRhNBwl2yqm1jFonZWYwETyzfGeZT3u/GYZkdwSEZXSOFSPV67SdJyGBJydCcICeC5aET3efYIYsGoCRkiTE0G+oGBjHYqbl6SRb29RRlnWmTsfczyb/JnQ9vIXrGnxp+oLd+M/9D0Y/b0SZqb3KrN4fP1dJeDZNc7WzYnjoOapuzNrt0AxsKUq6t9b7Zrf8Ez3II5uTV2ZwifnQ0FwMgTk5hZCbP7SxF0Nw0QWAhlO8ayXh5Lem3KJ5AQZYpndhEtJV0IWyct7wjvxtpWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R+Ds8XuvIQCliA5UspM8Oc/AcPjUdtndfcKQDOa3/hc=; b=4AJTY8atc21jijwqwiybIcj/fVE4+vSME8eAlRGYrcPXkc61Xyw4eTYzidrQfncJZXV/RyTGHLswVFg2z2QcVrLqMzZYNFUFWXErjWzbBvA4IzT+dpr/jgqQxCX5wx53T8AX5jh4XWv4ihaoklLwnN+uA0ZkWSDXQEc0HZbMmJA= Received: from BN0PR04CA0035.namprd04.prod.outlook.com (2603:10b6:408:e8::10) by DM4PR12MB5117.namprd12.prod.outlook.com (2603:10b6:5:390::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Tue, 1 Feb 2022 15:49:14 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e8:cafe::34) by BN0PR04CA0035.outlook.office365.com (2603:10b6:408:e8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17 via Frontend Transport; Tue, 1 Feb 2022 15:49:14 +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 BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 15:49:14 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 1 Feb 2022 09:49:12 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v6 02/10] mm: add device coherent vma selection for memory migration Date: Tue, 1 Feb 2022 09:48:53 -0600 Message-ID: <20220201154901.7921-3-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220201154901.7921-1-alex.sierra@amd.com> References: <20220201154901.7921-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: cdd01e16-5b59-4a8e-5e44-08d9e59a65d1 X-MS-TrafficTypeDiagnostic: DM4PR12MB5117:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:473; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ourpP8LM10rGf/GH4g4jISLF0EVHSkqOZEpl/X5KbhAtx9h/RyO4YCh+VvQ4KOjFkckj5l9Nd4tWLrz1AVrcEC+Kd3zjBUdFx1iVAv+KM8hmvdYIH0OuOqwd7mIKm1vhbH0Yw0uDxP4HyTZYp2ud+1IhyGVsWcXaS6T2NVFRIx4xdp7DkmFtvqwaCjxGOPx9glucUcpgDxwWZyEPUl+LZn46pc1PjK9OF7Ih9V38BsuI2yLXFk+lpoLmjqIQg0WHS4Dln1EB8c0yjttBBgjnm0uJga+K8P0oiU+aPMFXhEj7xDAT6aqjxamd1BtuhP+Cb6zOobk+tvhfZlPmE1NujWIWWLSbx1YOYv2zHTKk+fU1xFRvxhLp1WxKhUqpghajxjQHESc/FPzeNi/gT5rvgufo9WYO3bkPeFXJfPPyqsaitS9IboR4BeS7tPjtUIdxcFIH32VAa4dPrIojMq0+uEUeUolTzQEOW6on2g/niLnGjBB6kpvtYMDJXxpgGwhVqPnOMvaS4mClwsLUM7d4kmNbzcELzfOXmuZ67LbeLFYAsPPu3wtbTixXSFARYNl+PUEHapfLSDw2XRQfVIzh9hubwKYI89sVROu6aojR6SRKusM/WOCDIsO/Jm7868kJp1WsRzip8vKDlOc6xCQ/1LZw48TODnSjExk02w6UOehgIU+HXUEJUERKF56pcFZ1i0nIZqN+YIj+ywG6xmCFvg== 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)(7696005)(508600001)(5660300002)(44832011)(6666004)(4326008)(7416002)(2906002)(82310400004)(36756003)(40460700003)(110136005)(8676002)(54906003)(316002)(86362001)(16526019)(47076005)(8936002)(70206006)(83380400001)(186003)(26005)(1076003)(336012)(2616005)(426003)(36860700001)(81166007)(70586007)(356005)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 15:49:14.4955 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cdd01e16-5b59-4a8e-5e44-08d9e59a65d1 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: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5117 X-Rspam-User: nil X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C58FB4000C X-Stat-Signature: mw7bihj8z9ddct8tg7fox953675nxbnw Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=4AJTY8at; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf07.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.54 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1643730556-579068 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 --- v2: condition added when migrations from device coherent pages. v6: Corrections with zero pages, to make sure these are only migrated only when MIGRATE_VMA_SELECT_SYSTEM is set. --- include/linux/migrate.h | 1 + mm/migrate.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index db96e10eb8da..66a34eae8cb6 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -130,6 +130,7 @@ static inline unsigned long migrate_pfn(unsigned long pfn) enum migrate_vma_direction { MIGRATE_VMA_SELECT_SYSTEM = 1 << 0, MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1, + MIGRATE_VMA_SELECT_DEVICE_COHERENT = 1 << 2, }; struct migrate_vma { diff --git a/mm/migrate.c b/mm/migrate.c index cd137aedcfe5..69c6830c47c6 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2264,15 +2264,21 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, if (is_writable_device_private_entry(entry)) mpfn |= MIGRATE_PFN_WRITE; } else { - if (!(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) - goto next; pfn = pte_pfn(pte); - if (is_zero_pfn(pfn)) { + if (is_zero_pfn(pfn) && + (migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) { mpfn = MIGRATE_PFN_MIGRATE; migrate->cpages++; goto next; } page = vm_normal_page(migrate->vma, addr, pte); + if (page && !is_zone_device_page(page) && + !(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) + goto next; + else if (page && is_device_coherent_page(page) && + (!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_COHERENT) || + page->pgmap->owner != migrate->pgmap_owner)) + goto next; mpfn = migrate_pfn(pfn) | MIGRATE_PFN_MIGRATE; mpfn |= pte_write(pte) ? MIGRATE_PFN_WRITE : 0; } From patchwork Tue Feb 1 15:48:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12731938 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 87430C433EF for ; Tue, 1 Feb 2022 15:49:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C5306B01FC; Tue, 1 Feb 2022 10:49:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 14D846B01FE; Tue, 1 Feb 2022 10:49:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2DB86B01FF; Tue, 1 Feb 2022 10:49:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0172.hostedemail.com [216.40.44.172]) by kanga.kvack.org (Postfix) with ESMTP id E560A6B01FC for ; Tue, 1 Feb 2022 10:49:18 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A631281544DC for ; Tue, 1 Feb 2022 15:49:18 +0000 (UTC) X-FDA: 79094645196.27.0ED87A7 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2075.outbound.protection.outlook.com [40.107.96.75]) by imf14.hostedemail.com (Postfix) with ESMTP id 1703B100004 for ; Tue, 1 Feb 2022 15:49:17 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kpLC1zr9+lNrW1h4YPnfpuoPmOY4fggZGpsjcmByQmn8SwSJnNVBxMmLPs9+8A2E613DgFHWtZTza6RNJg/N6HiRp/cx58nttCMAwODoS3nHb9LwRnEh/LTPWwbrSl3c7M4nBu+d/AlMcK5LwE9l68Nrg6cnKDvLYRELWvIAMMETeOZBhJpJWgCgNiWLpCbJhGWziHa8pN6F4ns26V4rvUlCcTCXSTv4HDqP0vN7lloY7s9ImTvAbWeh5Jyxbb1zXyIwUfUnFnn+wTQ/QCX3Mc3Jc1tojaLgAxRWditLY4fse/y50GSU7epx9+PuWvHJFypDyuJQLTacrcHEng9hKg== 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=8c+snyg1lETNsdQ8VpQ4cgA8WAjjh8EpLlh6CLuAWAg=; b=fpz1sG10LX48K0Nmpj4CD813jzPS9rUs/1aXB5RDByvjuiGdPjqTHwQzTX+3Te5NgMVTxA3weY0OrMOPDSfFzmaVDLVWPlHMpfudhyS6c0JgfMOPt9b8SQLoK5yWiyliUM32brEqMvzd0AxQlylBjyTJvTS33PYS0RC1WMJxMYNcxgcKWN6XNoO07RmmMlDP+SK70oab9iNZUnCfy+135qMz473KoHW2ccgKnutQhDRiMXw3WLpUmnO2oQbEgUR1TYwjmwJWNPh4oSks/HBuV/feOo3xid0WxJsUm5xDWxIiMOiTGghXbjFE19K8ynY1+x/utqWku5v8V1uYmBw1Ug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8c+snyg1lETNsdQ8VpQ4cgA8WAjjh8EpLlh6CLuAWAg=; b=Pky2H2XWsD1tWeuvIStPVda6qmGiVe3w4fE/vyzBzUjU2dePHyZk9L8wRm+OiDm/MXjsiuZz3ErRHXPcOnzRIbe1ULaLPWnry3CbmVy8plIqNHLKOJaFzWxSWJhh69HdWShU9Eobos2yXDvYQT51goTu4gIMdIFnHlfJEuqQY9M= Received: from BN0PR04CA0050.namprd04.prod.outlook.com (2603:10b6:408:e8::25) by BL1PR12MB5029.namprd12.prod.outlook.com (2603:10b6:208:310::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Tue, 1 Feb 2022 15:49:15 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e8:cafe::1a) by BN0PR04CA0050.outlook.office365.com (2603:10b6:408:e8::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Tue, 1 Feb 2022 15:49:15 +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 BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 15:49:15 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 1 Feb 2022 09:49:13 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v6 03/10] mm/gup: fail get_user_pages for LONGTERM dev coherent type Date: Tue, 1 Feb 2022 09:48:54 -0600 Message-ID: <20220201154901.7921-4-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220201154901.7921-1-alex.sierra@amd.com> References: <20220201154901.7921-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: 62171b14-3a04-40fb-0270-08d9e59a669c X-MS-TrafficTypeDiagnostic: BL1PR12MB5029:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lsjwECF0oe/Z5/yZvzizo06o4zbyMLd34IFeEwDMY3GYY5p8y15N0b9i1dkhCRsLSahRW2xs7bn+A4RVziD6yAME8LGVkNskimwXG/OM4LdK2PkhssOYi42OruEHvU/WBkesg9Wex0Z7/4AL+/qvq+Hx1hCeiy6ucSwCkhOAJrJ/bwcPKXS+RFBtSSP/c1nuWlnxRzqwwZkbmI+OnJrEIByH+slqA9f0FNpd6c0tpOcHvTkcYB5INuXJfVEkxUFvykWYcn1ElbUw4/0oeOi4pnei8+keQqEQcwew8nW2Ft6B8Oj6LIf1FUMVgemP8sJDAZgw7IE1TumcnQo4LtGAEYIuWijkyhprPypPDsoLeDy7h5AbltgSMWBVRCR23jjwETV+G3pMxt7jb8OUyiR9DvUoEuYjBC7NrzOJBo3W/Soy9IODSwohU4TTOB4A3Na87Jh7nbA2aH4OCAI7MMYjtTTzwBdSi66ZmaGlcRmm+ieNxLK7MQD23yFdK1edIIH/PSmskgDQw+9aXQrCD0WQsnPgFCCoTC0o3E4HO3Fii+EzlJQTHSdADHdP2umJ5FYMhi9jFauIcifwkFtOOiuexxOETjub2VpHCroa3AhUgtPXemHs9KvkPZwA1ekVEKOr7vh6j/ieeV6r8cfFQsxqEb8LG5FcTF9zyUqAJN3JQmrvQ6TGEG/R71Tq8E/xH8VGm9mpw9TMfLi3Qn3Yr9jBow== 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)(4326008)(8676002)(36860700001)(2906002)(8936002)(40460700003)(47076005)(70206006)(70586007)(82310400004)(7696005)(6666004)(186003)(356005)(336012)(26005)(81166007)(1076003)(54906003)(44832011)(16526019)(2616005)(316002)(5660300002)(426003)(86362001)(110136005)(36756003)(508600001)(7416002)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 15:49:15.8235 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 62171b14-3a04-40fb-0270-08d9e59a669c 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: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5029 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1703B100004 X-Stat-Signature: k1f3msf8hjgf5p7dxxnkkmxzs5ys9wpp X-Rspam-User: nil Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Pky2H2XW; spf=pass (imf14.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.96.75 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1643730557-525165 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000008, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Avoid long term pinning for Coherent device type pages. This could interfere with their own device memory manager. For now, we are just returning error for PIN_LONGTERM Coherent device type pages. Eventually, these type of pages will get migrated to system memory, once the device migration pages support is added. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Poppple --- mm/gup.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index f0af462ac1e2..f596b932d7d7 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1864,6 +1864,12 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, * If we get a movable page, since we are going to be pinning * these entries, try to move them out if possible. */ + if (is_dev_private_or_coherent_page(head)) { + WARN_ON_ONCE(is_device_private_page(head)); + ret = -EFAULT; + goto unpin_pages; + } + if (!is_pinnable_page(head)) { if (PageHuge(head)) { if (!isolate_huge_page(head, &movable_page_list)) @@ -1894,6 +1900,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, if (list_empty(&movable_page_list) && !isolation_error_count) return nr_pages; +unpin_pages: if (gup_flags & FOLL_PIN) { unpin_user_pages(pages, nr_pages); } else { From patchwork Tue Feb 1 15:48:55 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: 12731941 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 838A6C433F5 for ; Tue, 1 Feb 2022 15:49:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C99008D006B; Tue, 1 Feb 2022 10:49:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C481D6B0200; Tue, 1 Feb 2022 10:49:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8553A8D006A; Tue, 1 Feb 2022 10:49:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0061.hostedemail.com [216.40.44.61]) by kanga.kvack.org (Postfix) with ESMTP id 6E19A6B01FE for ; Tue, 1 Feb 2022 10:49:19 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 337EB89D41 for ; Tue, 1 Feb 2022 15:49:19 +0000 (UTC) X-FDA: 79094645238.19.274D325 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2054.outbound.protection.outlook.com [40.107.212.54]) by imf04.hostedemail.com (Postfix) with ESMTP id A71C340009 for ; Tue, 1 Feb 2022 15:49:18 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Brfz9RuV4jw9UwqmPA9T2Vp8FgDTDpR10uo6OMQUFoGyDO1aGjYRhGe7JJ2ErCkE+RR1sPpmre9EyYBNy422zCEIeosTvU8tEQCfZXprEGe0ZG+C8RVSghOGFyy+C83xus2AJSYt52+o+j/xnkNRuAz6jYrGMEUHO6Hdjv57CbA3YOlWhMFLK5KqkqVx91KWPkuYbiTCuLuboEslwrpx4HooYAC+lfq9gSrqu7imhFYKV0QcDO8Os4Jrv1Tyu6NYVpsBOUPLmnJjxx5T9Zj5TNgZvE0aCdHcABfH+TQlyJbQdn8hyXQDLpXMD614odHFathawin8YFAx9EA0ChfsQQ== 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=H6Dg+JXQ9T7IJxjdebVIQf/JKMmpP4b0PXF0E4ioiTI=; b=OIAC0IJCfyXQo64Izqbru2GD1U28etDj3GbuZ1FpIPaofZRxtley5D20QnqQLihLR+UujBZzRtASgOyMRtWUgnOICilPZZpgUjtuy7QCE8aJZSgnFEzzhNoS4V7XT87q+7uZXSLrdAwIC67tjGV8/zZdROiveVDQ0SsV6O4cByZKnrXw+I7vAh48qjHjje2CoqC7NF7slqIPR0uV2HGssJAP9xIJ42c9vwJ4Y18T3HqsysTLewJAKmndwQUvV+h0azWVS5mGvAnXTsdPW2lpKnyPy30Qn+OTVe7bWkQuFL8c0Q/R1ZzlCJ04xKRklSrpRO3z9pB2Xfx2sq3k8vGgzg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H6Dg+JXQ9T7IJxjdebVIQf/JKMmpP4b0PXF0E4ioiTI=; b=GRRvDYwF5CUe5hvSR6HaZ/Dm0pUkHtRdidQuo8LdQX4eiP89aa2zNyQUBFgWoTDJpWI2pnSDC1lmgXG3TLO5s2p2HwKgp67KzajyLXopMUK8fZkOUktikYq3jAo5OlfklGHpjXMRNpGpnRI2tKe0R3OIjYC+4n/VZopH+M77JYs= Received: from BN0PR04CA0059.namprd04.prod.outlook.com (2603:10b6:408:e8::34) by BY5PR12MB4035.namprd12.prod.outlook.com (2603:10b6:a03:206::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Tue, 1 Feb 2022 15:49:16 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e8:cafe::fd) by BN0PR04CA0059.outlook.office365.com (2603:10b6:408:e8::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 15:49:16 +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 BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 15:49:16 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 1 Feb 2022 09:49:14 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v6 04/10] drm/amdkfd: add SPM support for SVM Date: Tue, 1 Feb 2022 09:48:55 -0600 Message-ID: <20220201154901.7921-5-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220201154901.7921-1-alex.sierra@amd.com> References: <20220201154901.7921-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: 9d9593a7-667d-4fd4-d781-08d9e59a66d2 X-MS-TrafficTypeDiagnostic: BY5PR12MB4035:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZUDlsgBXXHokhWfBqsNyr8A1TcI3BzZMOtWQK8I/y35cqGp/+FX7+xkyPS37xaMN0WXi2GEuYtICeXCbEgoDtwrq6jteqKCDMPPRL7/RhcSf8BU7qiGno14mMhG0RDgTTR+gOoETDSXJNr3QW1CEtD8ZBcq8CObM7frManV+2AeBZQNhlIJUe+1FdvOq9BL4usfGvbfRX5CIc1l6/V6y1jJOqiTeM7wj9kDGzzPbugAEx0xxVXM8AOFRpW2P10SLivMBdO01rMhvjB0Di/y3KpdFyuGEgbS33lfTdMlqnOAPP63DFv1SWv2u8PUNJJRiJZ9jh1tb4mol1frz3CIY3aXKx3ItPNNHReBxDrS7Dx8WpvIYitgk1p6XJSxQtbq113tZzOMR94Z2XZBDcx9J4wm5CprH7VL3yOV2G5zm3+oyWrBqi/isIhmT0lDnU86kvvlo3Ef+Xwpl4a2+Z69c2DmYOpg1aoWz8NmQg2GeNjbsDVbWlA2U1wMoOCyszqlcncpPE0HBgCX/YZUJg9dVDo3+ENLfqnFfhorO8Nw1I8/mzVlr1CH9Clz89k/OeQC+4XyOxPzNvXjRehssl0tD0A4/J8RuJ8kVBA7XcG3dOozdU8FJP3XpWVZnlZX+6J+6M0ndT2lyYMhKIhDS0Ng2wCNY2b1TyxtKkFWI9gxo4kyKxN1CRtMtUlu8Q81mZbGsnrciFG9iM1T4upkv5Aw3lg== 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)(110136005)(7416002)(54906003)(5660300002)(36860700001)(8676002)(8936002)(47076005)(356005)(82310400004)(81166007)(6666004)(40460700003)(4326008)(426003)(83380400001)(336012)(2906002)(86362001)(186003)(36756003)(16526019)(7696005)(26005)(1076003)(508600001)(316002)(44832011)(70586007)(2616005)(70206006)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 15:49:16.1828 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9d9593a7-667d-4fd4-d781-08d9e59a66d2 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: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4035 X-Stat-Signature: smiu7wd17n9xw9hskfz44jp3rnrakufq X-Rspam-User: nil Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=GRRvDYwF; spf=pass (imf04.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.212.54 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A71C340009 X-HE-Tag: 1643730558-555014 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 --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 29 +++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index ed5385137f48..5e8d944d359e 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -933,7 +933,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; @@ -948,28 +948,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); } @@ -982,3 +988,4 @@ int svm_migrate_init(struct amdgpu_device *adev) return 0; } + From patchwork Tue Feb 1 15:48:56 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: 12731942 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 90421C4332F for ; Tue, 1 Feb 2022 15:49:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0624A8D006A; Tue, 1 Feb 2022 10:49:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 012366B01FE; Tue, 1 Feb 2022 10:49:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C967C8D006A; Tue, 1 Feb 2022 10:49:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0194.hostedemail.com [216.40.44.194]) by kanga.kvack.org (Postfix) with ESMTP id 9D65D6B01FE for ; Tue, 1 Feb 2022 10:49:19 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6362E998B9 for ; Tue, 1 Feb 2022 15:49:19 +0000 (UTC) X-FDA: 79094645238.18.E0C27BF Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2043.outbound.protection.outlook.com [40.107.93.43]) by imf21.hostedemail.com (Postfix) with ESMTP id C93E11C000D for ; Tue, 1 Feb 2022 15:49:18 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MGCedzGovX275HUO5JlmwulXCtDtxetFle6FN1YNkUuviqirX8laCZibgKyiFncEpZGMscP13wJWofUFq3GoltRTR25OcNB8ylc8NPE+VPuBBj+7Dz53Ca6F8deAiWV5IZz68SUlp7aCj3ti+O3w71DZaIjVI7O0K9Bj7U5En943GyHndqXzp5xB2oQXGfA1eptgB7PhOaQ7PVh28ne5OPK3pO+62CRJN/Aj77s7zblHcKWzeTeJo0rBM1k3JO/8CvRRbBuv+cePZ5/I06E/rkLILI9s8Thd0htl5OL01MyN7X6L30vOllA7Kwke62x85UDpJNG3huML4BCHfy8n0Q== 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=cKdah9ociAAjWA8oWytWUkonkykx0MrDTa+hoh93Wfs=; b=Ja5y8b8OpjFmbBUgRCxhtP9sKpMGU6MeCbQGi93R5lUKxAZd1iTvd77R+ojZiX8s1faKDhRt1Qvvpbug7R/A9waEne1ZZxiCvCwFoFnvUQUmvht541fH5R3sQa0NLQwLh6jzRqRP5L2KhJhiO2EuAWGqOenGNmSBR2Xhkl0M1qmrsHHJFbBvUBKhfe8SM+RwIgpycqGUAxen3YPe4qn3qgi1/Q9WSLwOLQ+lcZlHXp9/HifXZEc6zCI++trn0mvZiimqIaeaX8s31ZwLQOz/clyLsvPge7nWu4achEd7LCKbZ9pbXQ+PJzTkndAStCV4W4MJs14Dkth/jgylKxXbvg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cKdah9ociAAjWA8oWytWUkonkykx0MrDTa+hoh93Wfs=; b=jvtpZ9Z9t8/Ruk5IksK1InLUGNbmMpXMrBTifmv01iaRyHleXYbmuGkvanNQV152PKq0T0QfUr8wXf9t8MJV1Z6ghl+H766YTotDYahVOqtvk01ux0STmiDfJ9++Jyzml8gukb5DXSgJmvULA4NhX94fhT9ZkbG/Ezmf8WO5bfg= Received: from BN0PR04CA0032.namprd04.prod.outlook.com (2603:10b6:408:e8::7) by CY4PR12MB1173.namprd12.prod.outlook.com (2603:10b6:903:41::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Tue, 1 Feb 2022 15:49:17 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e8:cafe::e) by BN0PR04CA0032.outlook.office365.com (2603:10b6:408:e8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11 via Frontend Transport; Tue, 1 Feb 2022 15:49:16 +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 BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 15:49:16 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 1 Feb 2022 09:49:15 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v6 05/10] drm/amdkfd: coherent type as sys mem on migration to ram Date: Tue, 1 Feb 2022 09:48:56 -0600 Message-ID: <20220201154901.7921-6-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220201154901.7921-1-alex.sierra@amd.com> References: <20220201154901.7921-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: 7a3f5b76-3736-4d2f-e5f7-08d9e59a6723 X-MS-TrafficTypeDiagnostic: CY4PR12MB1173:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WYOdKsIBE2rsmnZoemwhr4trvhjFMbgPvvwllFIx4/ZDIaxundRejzDXP9KxTb37I/UCVKMzU0Vlyt/dvC79CDLbqP2FQVJfmy6Z7GLTtjJ0I0bQgssU9+IlW263IwHl+kCobVsR3sPCgaS/AfOS6eieqqWFayAwltq/XMgwALKcGwF38kHhtVQFMMYm7G5mYczxGeF3uwxs1RJRakHrR4Lf2T+ZeFMacfom3UtBvGEj3nMJ7LaI2MZdvZz4zDSHxHS/FGPt3YTtHHAm5qqT5+0nfOyXeDCLNPAxkKjuKRjaQ/41El1bkGV3iFx6dCT/FlPFXaW+V5ElrAu6y1kJZfC1z5aLKNgSVVLqwZrFCRX4fXBzGEGdpOzePdF0KcW6IO962bYQSTMe/fLKsd9vGOsdstmryZ8idA0cYcgMq7YcN6p50bN3LNtktSbONE8oJ+cYu7j1ZcSO+UkbbgrFBGdLSdh8iC2tMRXaXRk3tERFWeoaEyagU+4fEj2UeiqnI+vYcmKB7gaihrasgUfmnb0ZgrdVtN9pQeNsmXvOiCS13uvwS7WGwvmTHj4Bkn9wYiX2nYy1Y73rQ75wpjPMRCFwnNVvAb3C2Dy3K8ZUhCLds6N0pZAwwlQYq/8s917f7mn1Bf2lRJo/zPNtz2aKsKEKBeBSy35bMm1h2NfvxSsyx5SFFw8LU8DBymycUOQzpB2x+tHJ65lTpeRAa/9Dkg== 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)(26005)(16526019)(186003)(1076003)(336012)(2616005)(36860700001)(426003)(83380400001)(47076005)(81166007)(356005)(82310400004)(86362001)(7416002)(4326008)(508600001)(5660300002)(40460700003)(36756003)(44832011)(54906003)(110136005)(8676002)(70586007)(8936002)(316002)(7696005)(70206006)(2906002)(6666004)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 15:49:16.6984 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7a3f5b76-3736-4d2f-e5f7-08d9e59a6723 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: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1173 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=jvtpZ9Z9; spf=pass (imf21.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.43 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: nil X-Rspamd-Queue-Id: C93E11C000D X-Stat-Signature: aup7sxjatihqwjww76ij3rxbm5y73ixk X-Rspamd-Server: rspam12 X-HE-Tag: 1643730558-148160 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 --- 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 5e8d944d359e..846ba55723fb 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -659,9 +659,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 Tue Feb 1 15:48:57 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: 12731943 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 7822CC433FE for ; Tue, 1 Feb 2022 15:49:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBB296B01FE; Tue, 1 Feb 2022 10:49:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E6B3F8D006D; Tue, 1 Feb 2022 10:49:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0C936B0200; Tue, 1 Feb 2022 10:49:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id C1ACE6B01FE for ; Tue, 1 Feb 2022 10:49:21 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 839D3180AB9E3 for ; Tue, 1 Feb 2022 15:49:21 +0000 (UTC) X-FDA: 79094645322.26.E503FC0 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam07on2053.outbound.protection.outlook.com [40.107.95.53]) by imf22.hostedemail.com (Postfix) with ESMTP id DBF7CC0003 for ; Tue, 1 Feb 2022 15:49:20 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RUoyonWhQ0Yb4Q1SD/i6edk79HycyzECMkucScUFhKIe6zrBSKRXCvuujvV5ywWkEXpKajQM07s6Lnryyur8CAp6Y0bC1u1wl4UgNkIK5AUPSRFYtL7BfPiLRCDITz+dpesagKsXmrFK2VLKcnkbAw9cjvCF3akX5VXJ92pQ6IOLx/UfX7qwWrtkpjZ17thIR2UXmRpFPU6CODHD8v6f6mAV1VZYuf9H7SIj9h34IURqDXQ37Di/3DO3Ntjp+BILEuSh82hs7ediIHpra1rKx3/gT6bbzorf74RNd9v5FGQSGliFfL9SbNSiSqAB3eRGUDVPPCnCcf5kXj8je/cynQ== 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=3B2SEKvTANX2JRyraqAhhc9gtOSoTtrAVSBb1B6KPZM=; b=X/49pYKE+VY7RWQc0H6ZXrqgY6vEx0MNjB2PbUkj/f3Y5WZzZFYQcQgMg3xShuaguvosHqlDvCHcCLODDh03ivW3ZPAbHvO077JsTck0orSjrB5fSmFq2zz3W56WaHlBdqXWFfJty1qSL/tm+Abq8igp9BaoydFfq4UdDY+o01dYQOJj8jGidx/CF7jGd1Hayod1pVxci5V+iIgOrJFlUCAu1Of1rQxvvGi7FSY3UUabIky7XlfxfeQiV5RejPKnb+GJBhqRotfk7qGHY7byBi+fuyraiqTumaa1ZNaIoPxfASVJbq9LxTD4KYVYXkzGP2apNHRCYySDR5+zuumlIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3B2SEKvTANX2JRyraqAhhc9gtOSoTtrAVSBb1B6KPZM=; b=xbJVxBTFd3I3la6wJhtfJz3eyRYHMaVRJHcu7p1HQ/1hUnRkxVy9HHE3z9jlTSYCLc6SYzzVMW2mzhOWsnSATzubBr/wzNudRHOar8MUtUlIXgN6CB1iBwJdKzod8BPWXDar6SHiN1hXrQSYqGw43N8iLaj2PaHpu+DepY2AcrA= Received: from BN0PR04CA0048.namprd04.prod.outlook.com (2603:10b6:408:e8::23) by MN2PR12MB3824.namprd12.prod.outlook.com (2603:10b6:208:16a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.18; Tue, 1 Feb 2022 15:49:17 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e8:cafe::fc) by BN0PR04CA0048.outlook.office365.com (2603:10b6:408:e8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17 via Frontend Transport; Tue, 1 Feb 2022 15:49:17 +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 BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 15:49:17 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 1 Feb 2022 09:49:15 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v6 06/10] lib: test_hmm add ioctl to get zone device type Date: Tue, 1 Feb 2022 09:48:57 -0600 Message-ID: <20220201154901.7921-7-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220201154901.7921-1-alex.sierra@amd.com> References: <20220201154901.7921-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: 95ac99f3-db3b-4d7a-195d-08d9e59a679b X-MS-TrafficTypeDiagnostic: MN2PR12MB3824:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: klz3y3Z97OtwByucdbobwC1/v8C1EF61+KTzAlwdyzB08lLseQ8GVgilHlgljgaVLjTQQpCxdpedNcZp42/RzHWaDzdkVYkO6+8skTAfLFXItbM1hvFkKLyC3k5T9gjmo3C/wxin5NpLhkrIskdkbUy4wllFzl14zkdp5ffC2OD8y/mbP9qoLdphCYnSt9hzwJKnTKNqNcgm8y2BGMufb8H1DF7SvrU+ig+5agmzHSXjjXQr/oOnLgFf22GrUDy6oLwzhWDMrTi+D7/M+vAFgk8Ew5FJ01tT57owOwXHqtBsaNCv07cvxV1JN79OjaBJvaceWCN7BPT0thwU+1wz2C0G+kMUzDDXYKfmaWqX2QgT0tAVagEDIP3KcJW1vnmguS1XxVrukUijqbklWgkN0zuhWJiaJW02N0TRowKTQOP2GEqPVL7WCjQjiQlffmift3yrdik4tdUXjAFLiTNpqr1fw+m9ObHDsU/aJfdzgPnJe3P1z3ZaTQpJxQsGnqWw+7/vKnvVA3GsA21dn9K47QArlJYyFY7+1CEifaaSWG9dS0ecDG5dqmUrdgATBH9Cwlc54quMlCzfgS/Ib5zwMl9+HHfoEJcNGosaZ7+En45/5l6rTfE0PcXZ+YUuO2/dr8Ok0A8l5e0bC+i5/Mnk8yRar6RW1zazWLGlmvdfRUpwrJFSTr/INFpo3MYHOl0PFtBsClNDizgOWgBJomU8/w== 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)(426003)(336012)(8936002)(316002)(44832011)(4326008)(8676002)(81166007)(26005)(16526019)(1076003)(186003)(86362001)(36756003)(508600001)(40460700003)(83380400001)(2616005)(2906002)(82310400004)(54906003)(110136005)(7696005)(6666004)(356005)(5660300002)(70586007)(7416002)(70206006)(47076005)(36860700001)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 15:49:17.4796 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95ac99f3-db3b-4d7a-195d-08d9e59a679b 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: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3824 X-Rspam-User: nil X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: DBF7CC0003 X-Stat-Signature: fgdis1wpj37b5sb4hcsup7p4ow5tskys Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=xbJVxBTF; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf22.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.95.53 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1643730560-529360 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 --- 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 767538089a62..556bd80ce22e 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -84,6 +84,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; @@ -1024,6 +1025,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) @@ -1074,6 +1084,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; } @@ -1258,14 +1271,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 Tue Feb 1 15:48:58 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: 12731946 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 AFD39C433EF for ; Tue, 1 Feb 2022 15:49:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93FE88D006F; Tue, 1 Feb 2022 10:49:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C5358D006D; Tue, 1 Feb 2022 10:49:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73DBF8D006F; Tue, 1 Feb 2022 10:49:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay032.a.hostedemail.com [64.99.140.32]) by kanga.kvack.org (Postfix) with ESMTP id 60B6F8D006D for ; Tue, 1 Feb 2022 10:49:24 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 31EDE20E6B for ; Tue, 1 Feb 2022 15:49:23 +0000 (UTC) X-FDA: 79094645406.03.84C8F50 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2086.outbound.protection.outlook.com [40.107.223.86]) by imf04.hostedemail.com (Postfix) with ESMTP id C179740004 for ; Tue, 1 Feb 2022 15:49:21 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Azj+I6ZQjY5WevzSFYaeRA/tDozTAbw0gL6Yyc3X0hKhr6LxYE8d0XLoaVLKgUzBV94mgnwb/J+V8VjoIdYU4iKI9AtWb1TBLvnP8tWqgw089IJuD3JZOyTLg2cEIn7XqttzMVfM6tVZ0v+6cvU/+wIB69gfn9eRjZdm8Xq4jzzoOYRE6Gv53CrZ4erJ+q6qCFnBAAk5sOxGP1iYJK+Are97poDtQSQ6LyWORsyLEPdnWXwZtU+EzbcTjHrbOUKU2z6LfyL2aWJEK2SkD3anlzydexfq8FRWbij978hAscsj1i5mrbjRCGio2NqNquu2dt59f9nLqdPLQzRHzSu9cA== 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=hIkRxjdiMCIarckjXFr9wmIp2NOEFYMNIxQxsR44EmA=; b=S1lDnOMq1gdEbKfEF+HSHC3Nmk5MPVm6opru50uHn+yOsbA71+52btxwhUtgHoeTXJTv/f0m+WgRbx770wNBnxeLE2R4XOsAgu0A123maQpQxfEDcfno4z5gMcdpvT+tG3vjILuZWfOea/Txbh4DLfUpQyqjKzMQ4SxkRpLdCu9cG+4DkZyx4EBr//CnBwrvDKg5TjvcIQb4xM4lncYfXGhveuuYf9D58fRBYq747HH7L3kicuXOcCHr/Lv+MP24iwXobB+XTPJ7ngWTEveuvR63aG0Q5Onn9Esw+fDx34xtLRJdXUj/JR5lyzlJncyGYwdmTrJt72VKiMPU2T8JDg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hIkRxjdiMCIarckjXFr9wmIp2NOEFYMNIxQxsR44EmA=; b=22IJapjnBVOfPiiHYCWCuEMwai/3yX9ZaYw1W+gbpasLt/fYgkdwWY3D+utpHUpUjEexmeknbYrGXNDKb+npHuB3n64kqxhtCu3XBVBAo0gYIsSxOGLthgITo7TAtB4pirmBOvVmzFBUkMinHiRqUo3OokMMitSsGMyaKaKa64A= Received: from BN0PR04CA0032.namprd04.prod.outlook.com (2603:10b6:408:e8::7) by BN6PR12MB1809.namprd12.prod.outlook.com (2603:10b6:404:106::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Tue, 1 Feb 2022 15:49:18 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e8:cafe::e) by BN0PR04CA0032.outlook.office365.com (2603:10b6:408:e8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11 via Frontend Transport; Tue, 1 Feb 2022 15:49:18 +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 BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 15:49:18 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 1 Feb 2022 09:49:16 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v6 07/10] lib: test_hmm add module param for zone device type Date: Tue, 1 Feb 2022 09:48:58 -0600 Message-ID: <20220201154901.7921-8-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220201154901.7921-1-alex.sierra@amd.com> References: <20220201154901.7921-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: eb571aee-fdce-453e-27e0-08d9e59a67ec X-MS-TrafficTypeDiagnostic: BN6PR12MB1809:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1923; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VTM8NO9m0cdOZw48axkEnKjIZRIBiARUZBhC9L/CEga5GkmoulJ+Y2H7OjxfobNljaS+PtR/gXQtl+Id+8YYFSrWITMaCx2shFhvM51CgNjcEwQ3qSiJ7VFtM4DX0aE47QN8jnwxplEZmzVOUL8z3HN3seHM4tmSNKg5dZdm730maQfwo1SwYSMf2kwIZDRjSJaJ80ZnB/tYoCx5SL9REmLr9ZZXBX17AUSz0PjD85QIbiLmybyixhv5CYp+SUo9NIwBKCrtrfuxVVH2PXw60TyD70yWPyYHBB0CywHSsqw1VQPU+f5w0lMFxJLhX7JA5KHgbMhjDvr8VQ8BudzHtJLa69N0wfB9KjKEk6/oHZe+Lcxi8ZnzkKtHQwmzwIcr7d5DPfDy8hz30ZlsqihUS+9SieC2Uma7esFmPjdqs1H41RIkjrwAiqqmCpYvLPi2ZgGqd7iM9hN0vY3qi+9M4KGfl05evXx0ecK6IYEhb7uhDNLDiT9e7WDsA/xxOqa2B3Ik3fdJXuQs9nJ50H3ZQJfRJ1hfW5enu10SFP8Bf4BIXa2xnFq1WZfQtHazdlCRso9LvP8r47JBBdoV1mcXTHqQYz8kDizqqHm9qXrb6xobVmAFjkabcmLe+xl0NNzsponl+gghOaIIDEIPMyu+OxpQNOWQYeFhtac07/Kd3zFS4WtRj/XdksaI/HlYzScUJrx66shNSMsa4j7ghSklqA== 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)(82310400004)(86362001)(8936002)(40460700003)(356005)(81166007)(70586007)(6666004)(70206006)(8676002)(5660300002)(7696005)(4326008)(508600001)(36860700001)(83380400001)(54906003)(316002)(110136005)(7416002)(426003)(47076005)(2616005)(2906002)(44832011)(336012)(1076003)(186003)(26005)(16526019)(36756003)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 15:49:18.0108 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eb571aee-fdce-453e-27e0-08d9e59a67ec 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: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1809 X-Rspamd-Queue-Id: C179740004 X-Rspam-User: nil Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=22IJapjn; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf04.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.86 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Stat-Signature: tardcchpx9t7uni3xbwhqn6zd8rnc346 X-Rspamd-Server: rspam08 X-HE-Tag: 1643730561-656858 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 --- 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 556bd80ce22e..c7f8d00e7b95 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -34,6 +34,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; @@ -452,28 +462,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; @@ -494,10 +520,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; @@ -526,15 +556,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) @@ -559,7 +591,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; } @@ -1242,10 +1274,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) @@ -1258,8 +1288,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 Tue Feb 1 15:48:59 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: 12731944 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 7283DC4167B for ; Tue, 1 Feb 2022 15:49:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7973A6B01FF; Tue, 1 Feb 2022 10:49:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F0B16B0200; Tue, 1 Feb 2022 10:49:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 594C78D006D; Tue, 1 Feb 2022 10:49:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0215.hostedemail.com [216.40.44.215]) by kanga.kvack.org (Postfix) with ESMTP id 3EDEE6B01FF for ; Tue, 1 Feb 2022 10:49:23 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0089D89D41 for ; Tue, 1 Feb 2022 15:49:22 +0000 (UTC) X-FDA: 79094645406.17.0465788 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2069.outbound.protection.outlook.com [40.107.243.69]) by imf27.hostedemail.com (Postfix) with ESMTP id 5BEE940002 for ; Tue, 1 Feb 2022 15:49:22 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VB6eQnX2dKoMbZo7BATTsW68IaErGEVZr5jhDdq6wVAyeCsSQkVNWQZSTZhOojlnvyYpjQ1VcF53wMeNdPPtyWgGTbcExFmbDZWGSNaLyIG1Itw/XJxmSflaLvWXiSacfho6jA2FpO9Ak/PROOHcXy5kxLyyI5rs0cnyqK6epwxNOMowpNiBXBRu6JjCWFkZQIWMmmXKdNeVE2HmZEo5It8/973c/+cxLaIPwUt3Cy9egHRGKRF2+MPmPUO27e6kUW5F2CLf2pa1Qeg4sCvHzaEg3bCJWNx4Cvzo2HoUoMH1m4im6VJ/KEbqpS+UU2F9i6fedyyag7AOp90pa40w+g== 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=eDbeuJ/8CJltuNfZUog8Bre01h6TIiK1NNkipPVUKjE=; b=Z+0zGZ4oUIezMOFQHok9lasocqwKMcbfPxnTVbsqmCMa1z1DzlLeTRB9JzR4FA/JFpEigC/ofZidbJoeflmuVk/HTuofXKElVOs4ngEuxKf52WYZH13VilmViOaoD5T+yl9o13cl9q6S89PFnFY/+lGKSL3oCkXtw066Onln8v68xcV1x8ZkZHxcNIUsR35LOMXBEOhF4j5B/dtdUCk40ZiFZVDoqrQlKibUQQkDBj/288OrerazhS/haF/g64DBZcGBCEMWDxFTlnIG0tkFur8sZBnuATHHGEUcp9xJtfZR54XRkiyVcMBI/kyqKsLQTC1n6baxajbbE6STPW3Sdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eDbeuJ/8CJltuNfZUog8Bre01h6TIiK1NNkipPVUKjE=; b=3B7KKskt/aRmuPsMItNB80S1Jfr0CGABDq31TThcsvJLzhEE5OIabdw5/5gNNsj8GBPt5PHdr4tA6L0aRtm1post8W34/S4FghhOxYbSrfOVb70jZ+VUnAqSp21/S4B/nPamLig/1+DkvUir1l9+9fXGgzKT8+Kssdu8ihZGYXU= Received: from BN0PR04CA0050.namprd04.prod.outlook.com (2603:10b6:408:e8::25) by SN6PR12MB2605.namprd12.prod.outlook.com (2603:10b6:805:6a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.20; Tue, 1 Feb 2022 15:49:18 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e8:cafe::1a) by BN0PR04CA0050.outlook.office365.com (2603:10b6:408:e8::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Tue, 1 Feb 2022 15:49:18 +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 BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 15:49:18 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 1 Feb 2022 09:49:17 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v6 08/10] lib: add support for device coherent type in test_hmm Date: Tue, 1 Feb 2022 09:48:59 -0600 Message-ID: <20220201154901.7921-9-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220201154901.7921-1-alex.sierra@amd.com> References: <20220201154901.7921-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: 214220b5-05b9-42fe-fce5-08d9e59a6822 X-MS-TrafficTypeDiagnostic: SN6PR12MB2605:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3dZLD5xvyrYl7s1WbMo3bzLLoiQRRwMDm3GIwxb1w82C49Oh6TSmW2RXFFa9o1GKp3lsYHA4MVNxueRtZVV1kahDLvNoL7ZbC5kO3TIN6kWYStSzO4AmtoEKykfGCO3SdfY4rfNCnRApYCw3lqjRlVpXiwwhn0dRic2oPaavgTvXG1qvZEtjm7/sk6rOUIYFeNElZy3BD6y6Jzp8RwsjY+idbrFHR/0iBe+3yTqMIY5JYJIIAWO25m+u1GBqdvOjMXD4M+HAnDO+a9vZz7OUNkRajzPoZwYiTzXf10HwsUdU70B8cH0Cf1jHtK3QGzOf7TOJGx18ojJyaNlnRh7jKtMHJWkhkLPjFqyEteqo0DBSzWyp5ujZH4llQlGmSwk3gst+273ltCmEZ/7Uj8hBQA16YjvrTEq5JrWnGlKSSSTMWE4p23c/bHOcEdCRmyL2ArUEONbYVxh78SmucUpUlnL/hKh9leD476d5WIu/y4vgh1+ZOxOMmd389iK+XpyiBGMyqH1HD5jQLY/sQ2ZADFSAsLG7X+4Vi7QQ58jfFhyysQIo+N8+Zz4UtYhHDiCcENHzjmPsFphEjRU/9+Un1mbDu686GYUIxkJr0bupQeFCDmG3yujmkUdHWDlsn7PXR2y6wfcGdM/oOQkKhNUzJ7U2+k2h6M7mz5BOdGGz+KGeRQ6Tm/BdKImIZsdd+g8KUeT6kht+oHEQBhGseTBiSQ== 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)(16526019)(2906002)(36756003)(81166007)(70586007)(6666004)(7696005)(82310400004)(26005)(1076003)(426003)(2616005)(336012)(186003)(54906003)(70206006)(8936002)(8676002)(5660300002)(4326008)(316002)(83380400001)(110136005)(356005)(47076005)(86362001)(44832011)(30864003)(7416002)(508600001)(36860700001)(40460700003)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 15:49:18.3858 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 214220b5-05b9-42fe-fce5-08d9e59a6822 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: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2605 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 5BEE940002 X-Stat-Signature: yof97f775d33kumkekrbdka3o8bd3ihn Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=3B7KKskt; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf27.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.243.69 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspam-User: nil X-HE-Tag: 1643730562-298038 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 --- v4: Return number of coherent device pages successfully migrated to system. This is returned at cmd->cpages. --- lib/test_hmm.c | 260 +++++++++++++++++++++++++++++++++----------- lib/test_hmm_uapi.h | 15 ++- 2 files changed, 205 insertions(+), 70 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index c7f8d00e7b95..dedce7908ac6 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -29,11 +29,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, @@ -122,6 +133,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); @@ -572,16 +598,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 alloc 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) { @@ -601,7 +630,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; } @@ -627,12 +657,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 @@ -646,6 +680,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)) @@ -723,11 +759,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); @@ -807,15 +839,124 @@ 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_dev_private_or_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] = { 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]; - unsigned long dst_pfns[64]; + unsigned long src_pfns[64] = { 0 }; + unsigned long dst_pfns[64] = { 0 }; struct dmirror_bounce bounce; struct migrate_vma args; unsigned long next; @@ -852,6 +993,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); @@ -860,7 +1002,7 @@ 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; @@ -897,12 +1039,22 @@ static void dmirror_mkentry(struct dmirror *dmirror, struct hmm_range *range, } page = hmm_pfn_to_page(entry); - if (is_device_private_page(page)) { - /* Is the page migrated to this device or some other? */ - if (dmirror->mdevice == dmirror_page_to_device(page)) + if (is_dev_private_or_coherent_page(page)) { + /* Is page ZONE_DEVICE coherent? */ + if (is_device_coherent_page(page)) { + if (dmirror->mdevice == dmirror_page_to_device(page)) + *perm = HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL; + else + *perm = HMM_DMIRROR_PROT_DEV_COHERENT_REMOTE; + /* + * Is page ZONE_DEVICE private migrated to + * this device or some other? + */ + } else if (dmirror->mdevice == dmirror_page_to_device(page)) { *perm = HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL; - else + } else { *perm = HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE; + } } else if (is_zero_pfn(page_to_pfn(page))) *perm = HMM_DMIRROR_PROT_ZERO; else @@ -1099,8 +1251,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: @@ -1165,14 +1321,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; @@ -1180,43 +1335,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; @@ -1236,7 +1359,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; @@ -1315,6 +1438,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) @@ -1337,7 +1466,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 Tue Feb 1 15:49:00 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: 12731947 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 8F7A7C4332F for ; Tue, 1 Feb 2022 15:49:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B8908D0070; Tue, 1 Feb 2022 10:49:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 012BC8D006D; Tue, 1 Feb 2022 10:49:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DCE668D0070; Tue, 1 Feb 2022 10:49:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id C8AD98D006D for ; Tue, 1 Feb 2022 10:49:24 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9025396760 for ; Tue, 1 Feb 2022 15:49:24 +0000 (UTC) X-FDA: 79094645448.10.8F33278 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2049.outbound.protection.outlook.com [40.107.94.49]) by imf30.hostedemail.com (Postfix) with ESMTP id 4BB2A80005 for ; Tue, 1 Feb 2022 15:49:23 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nZu0re7CU1a1yhDvEEO9oMNeyDKFfrtQsHsvIGx86LZ0hSjCQYxu9nU/qP/vIOAE+dLBksQzpL0TtsfD2c+YjjlPc8/5nE9aSpdo8b6rPTjX83QRim/tVqGqq5UB6dcbuVbX4MVm0W6JW6IpOOD1DuhBEw4Z5fAFmU13zS1zLy9HXCznOTiDAvYqKzUWrT+lsd38omM47Xxs1MRnlqsczJr8665eD3WHBe8Cz0quHaZEaTGf1G7sfZnkonZ44E+5K/g0FXsh3SXn8/SexS141DZv3Eg8xWUPNrWH4NXecrUwU43Zq/oZZnShRw4RIqp+mzUq/OLP0lP/sh/3Txq1og== 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=W9rC74gVH3TzGfZ41DRrV22/9KcZPzdWDspIRK+SX1M=; b=kfi3/SjgT0WDokAzRDssE+IMqn06gH9BVFkKoH1q+6Y4FZyl3mzx/LkhSJkLrE+7s9HDoiLyTu8bObA/9HuXQ4Ayfs5ZtQY1EE/+oOt1VADRzI6NcD0qNEWpBJWsWph43LjVP0AEZZuqqoydMDsbjK9uhG6ps3uZ9+e7UdODQRi+2AlrlxIF1XoPQcJSh7eDmEp3s5EkuRPEI3V9x5nwEEfPnA+2nen0wAw7uBbVzy/Ph//T9LqPQhZhXUNwHV6ePp1YxzYvqu3+1R6Yfe5Iazdb4J5ORTsfnfZF3qvSdV/gCgTo9/C+nG3pBLKLKlp5eckdVzcWFC4NjZ4V+jhxyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W9rC74gVH3TzGfZ41DRrV22/9KcZPzdWDspIRK+SX1M=; b=OrUHtts5FSzaysP+/0yMomtSlGsrByOZJ0rKsdL36aen2OKZz/od6xDodAGKMTHHoQiO2HyIyu3eWs1Ic2u0g0E0eEpRdrz177gR3KrmPurq0xpsvzilcTOT+9PbeW/PECgNO86qkYPjMwN+KdTqKzqDbEDg5BprzCWaOAdisb8= Received: from BN0PR04CA0050.namprd04.prod.outlook.com (2603:10b6:408:e8::25) by DM6PR12MB3465.namprd12.prod.outlook.com (2603:10b6:5:3a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Tue, 1 Feb 2022 15:49:19 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e8:cafe::a) by BN0PR04CA0050.outlook.office365.com (2603:10b6:408:e8::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Tue, 1 Feb 2022 15:49:19 +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 BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 15:49:19 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 1 Feb 2022 09:49:18 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v6 09/10] tools: update hmm-test to support device coherent type Date: Tue, 1 Feb 2022 09:49:00 -0600 Message-ID: <20220201154901.7921-10-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220201154901.7921-1-alex.sierra@amd.com> References: <20220201154901.7921-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: 52aa12cb-da1a-4a41-055d-08d9e59a68d1 X-MS-TrafficTypeDiagnostic: DM6PR12MB3465:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l5i9X/bcz6mbM8h6kDu68bkH80PW+GZpYF/9kWH0jvpgDgAweTMwj6fMp8OSgxoLCXt8akbALdFf0QoT66lfJLPKgR7D3GZqoy8oeacN0siuaoum52eLTO9hCv05HQhLQ2GgIxzEtxkf0AztsZf7TC1YxO2Mj1IvJg6NVn9akP/XwYDP0jbt0u4qaa9qLFlhYJVTpiOWprGXNP6q96ZUaMT9kqh28WMVc0Qrj2Y5UIrTb/wxBlam7AtA4tpb/TBYigm6Gc3zRmaoWqo11FQ5H/Hm1Ea0k/MffeIxXaFgXPgcCXZxocXw6f0DsTu57Icoizqbh9d8X2w7leY30kbZ7z2McBePx8xO/JSf31e5TyrOzu+gNqYD1K3EJjZfC3YAndvCKCkXC5DZcwGfGw76j/2k4DxhD9HeZ1k1xYvo2e79kWde6Ffx217fM74D4jDXl9lKY48/OJ+PXCTbt9bHIY0zysDS9IZ3iuOV5nvDqJdPGKSsUeUQGwEOOUPgWDKttehSZtLvelCbp/7+afsGq48MI+I5aCFK5OForBCVd7P4+zY6vEgsja13fngl6IdlZQhvOjPWHoLX33oLLixNXf6TCiGCiTLexHiUTqc5U7FYEsBt43vaReI/qpbMLR9tdcuddoeKARXH4O4csRAnKlzl3WfUQvwtPswWEZh/xgsWU5a1iJixjBlhTJR4L8xP7d2JIfjvCi0qZwthZHQcNQ== 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)(15650500001)(7416002)(70206006)(36860700001)(8676002)(5660300002)(47076005)(36756003)(2906002)(44832011)(110136005)(8936002)(316002)(54906003)(4326008)(40460700003)(70586007)(86362001)(83380400001)(508600001)(1076003)(16526019)(81166007)(6666004)(7696005)(186003)(2616005)(26005)(356005)(82310400004)(336012)(426003)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 15:49:19.5264 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 52aa12cb-da1a-4a41-055d-08d9e59a68d1 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: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3465 X-Rspam-User: nil X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4BB2A80005 X-Stat-Signature: buzrofrjf7i4obeaeksjzxq98hy5gmjr Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=OrUHtts5; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf30.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.49 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1643730563-434594 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 --- v2: Set FIXTURE_VARIANT to add multiple device types to the FIXTURE. This will run all the tests for each device type (private and coherent) in case both existed during hmm-test driver probed. v4: Check for the number of pages successfully migrated from coherent device to system at migrate_multiple test. --- 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 Tue Feb 1 15:49:01 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: 12731945 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 BA5B4C3526E for ; Tue, 1 Feb 2022 15:49:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AE6B8D006E; Tue, 1 Feb 2022 10:49:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 20EAD8D006D; Tue, 1 Feb 2022 10:49:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03A418D006E; Tue, 1 Feb 2022 10:49:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0040.hostedemail.com [216.40.44.40]) by kanga.kvack.org (Postfix) with ESMTP id E75DE8D006D for ; Tue, 1 Feb 2022 10:49:23 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A792D181B5EB7 for ; Tue, 1 Feb 2022 15:49:23 +0000 (UTC) X-FDA: 79094645406.30.26B9170 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2076.outbound.protection.outlook.com [40.107.223.76]) by imf26.hostedemail.com (Postfix) with ESMTP id 0E0A7140007 for ; Tue, 1 Feb 2022 15:49:22 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CgAt9O8rY8I55rJmjdVSQFFnuI7RJU9ofADgI/XESc3N3og/tRd/NsxrexEDbLc+NBc/zhZfyv8LYrtRSD4fVQOqTTeR6EQ64EfE+DRCZQdJVOzsk8HiKyQRCVrgDKNOgns5Aq+ovXGotSIrFolunkYLq3UccRG7ElphBsHpbpLZpYzJiMYUDrMigUWbqq/2JXlNH22cTQWM1mQh/awHc8+OATE8EkEI8CtYYjoVK29/0pfIUO8NZKw4en0GcUG1hZF1O9Lx0T5Vto5uNWp41xuYv3rHmQ9nXwyub1wt7X2JfUL6uotaZUsEnghKaa44J243knpmu1EO3a8ozpVXJA== 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=UDL5uDl4x5PP58sGfZzqW2twsdvQmLh/V7W17HRkHFY=; b=c31Y53Ni4Z2O057h8mAGa1dIahRRHNFlGA4LS/S85VGjnbHpNz4i22lKvHFiUR+qcAh6bX2fF2BV0HiR0DuLtTJhyClH8RNQVsJu2FuH3uKP3J8/2AyeFETlMxm+Q5gHhZNtQkv2DoYlL4D06argiitW8a6cLfvn64IWc1BUkmYBUbHyzktS85Deq5hOWyCFblQUOBdT0YivmvYQYtXVlvOhJdJ2WH14ElYfamyBwdXR7q0TspqUn+aidzmZTBujpHT9fPy/CbJtv37fftoii6U2Ds2opYXNxIuWqLJarLcOcBM907QSKsT8f1ZxGHPMq+F1HQ2tShNm1SwvIutMCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UDL5uDl4x5PP58sGfZzqW2twsdvQmLh/V7W17HRkHFY=; b=Hic/RHKFtk1PF1S7u8QtPEpVCuNyJ0+pH3iAQf9z1vWBUelfbvEpRNxL+5dragckv7IOqW75rbk10oOL1GzQbEFM5LgOTW3aVBHfeRt/oCf40CSAO6Kjpd1iElN0bq2tkRUHE6SHxAZxCbpDbCGD6OK64vlmqT/2C5JNgzpxcmc= Received: from BN0PR04CA0047.namprd04.prod.outlook.com (2603:10b6:408:e8::22) by PH0PR12MB5607.namprd12.prod.outlook.com (2603:10b6:510:142::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.17; Tue, 1 Feb 2022 15:49:20 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e8:cafe::fa) by BN0PR04CA0047.outlook.office365.com (2603:10b6:408:e8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17 via Frontend Transport; Tue, 1 Feb 2022 15:49:20 +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 BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 15:49:20 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 1 Feb 2022 09:49:18 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v6 10/10] tools: update test_hmm script to support SP config Date: Tue, 1 Feb 2022 09:49:01 -0600 Message-ID: <20220201154901.7921-11-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220201154901.7921-1-alex.sierra@amd.com> References: <20220201154901.7921-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: 1e45e681-d14c-409e-c3fb-08d9e59a6932 X-MS-TrafficTypeDiagnostic: PH0PR12MB5607:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /A2m+NXYHiQaJuzy55uHOz6JmPRwk2RBeBq+YVDw+mQ+HfINP1CtgFuYbot+rceFIoCzg9a30fAku9QhM+kPEH7rFqEeRw8iefTRMul27xk+Tv5MsO5ds8+XZlMu9qDPPfB4ZH9J6FzHwSNOYPmfsZjF6iyd621zhMdLog4uts2B8a8MMmL1H/ILfUs7hIwaMWlPgP7ey4fomOryYW6LxGOjfVEoFJUsD0J4cxEAjG5kfsTzgc+C3nmGJCvEIhoqKJCmS09c2LB028fon4jBeYSBYUOlHDVNatJ9KpmmHboxuqn76VTF1M7S+G4sc9ZqikO6yOFIOtiJvB+ASHAER6Op3YStAETv8xR27fqrGRadoznxL0T4bWFpcnjY9o/+NTDZwihtylgh9yRkfnXv7zwAPjy3Z/CLwGRV7k22CjyHi9SrOFch7poNxUS7OlXhlKvTq5m82rG/x/JFWLYckW+KfxzHgYryF+ovH8NBEtjHxK0U69U9slB/2HYMY53m8ip/GGF0+HO/0d9aIJ3g4tgmPdMfKXzdn681A3Q31FjxuR1Jp0cm2oyfre8+A4+Mh4IsoCZ464OyR1sSx0qb/2OAQyfDgGK+MNMbvs1rYWuytWLgxYKIIU5WyKygKHclzuraiUzNUVeEZ1BOfPaAyIyikUzPQwz5pkJ+i/QZB2jjvFpbzv7azOoH3qKmkQrdPRlCGrAGz2rASEd6WIn1NBr2H/2ht9YF7nurrRZuGi0oxy//FV8CgmRpUGEY9qjfVw+ysahqon2egWYmN95ABE0i+eOSAkNs9atRIDkpu7w= 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:(4636009)(40470700004)(36840700001)(46966006)(2906002)(16526019)(82310400004)(83380400001)(81166007)(316002)(508600001)(356005)(1076003)(8936002)(6666004)(7696005)(47076005)(86362001)(5660300002)(40460700003)(426003)(54906003)(70206006)(186003)(8676002)(2616005)(36756003)(26005)(110136005)(7416002)(4326008)(70586007)(44832011)(336012)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 15:49:20.1669 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1e45e681-d14c-409e-c3fb-08d9e59a6932 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: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5607 X-Stat-Signature: figmz4em7b8cenbrdma1jepj1453s6gr X-Rspam-User: nil Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="Hic/RHKF"; spf=pass (imf26.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.76 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0E0A7140007 X-HE-Tag: 1643730562-671229 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 --- v2: Add more mknods for device coherent type. These are represented under /dev/hmm_mirror2 and /dev/hmm_mirror3, only in case they have created at probing the hmm-test driver. --- 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