From patchwork Thu Jan 27 03:09:40 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: 12726198 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 0A823C433F5 for ; Thu, 27 Jan 2022 03:10:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C1266B0075; Wed, 26 Jan 2022 22:10:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7711D6B0078; Wed, 26 Jan 2022 22:10:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59D036B007B; Wed, 26 Jan 2022 22:10:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 428F96B0075 for ; Wed, 26 Jan 2022 22:10:05 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id EC62789942 for ; Thu, 27 Jan 2022 03:10:04 +0000 (UTC) X-FDA: 79074587928.16.DF17B92 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2069.outbound.protection.outlook.com [40.107.236.69]) by imf13.hostedemail.com (Postfix) with ESMTP id 0C48B20003 for ; Thu, 27 Jan 2022 03:10:03 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ePAgcvv4jHtThxAunnSK/WXTLiG4RNXx4Qk1AdSC21sGApMNOPyhDwQTnTHpLNF9YsiVjgBeqBTZ+PvqxUhZXoQEuC7Xwokx4cnm35lpnixoI5wL+FfgTD22/NZbVMVaGUrCfm1kY0eK+EYoK9A4PT4ftV/ZK5SWfr2r9ndTz4+Xb2vzFn7Pi4AUrhzaO/V0ZJGU+veMteHJxEQtUibdixCILtukREBnI3+32xz9fPLxRDup9bLxZgqPCNjWQ63KDq4r+rb4I15dmtr50XfzebzyWT7iPZ7+5JpB3uJDTcU2/wEFt39CmrrtbNSGHEiUsvSbPfl2K3u+NmTa2CNzAg== 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=qQ/QG800USP94AspSL5Y3DvHV42AvDV6ZHFP44omgck=; b=jBG4LD0DKQiAJpklNTJtNFOr0TMY7/xFunC3/21MjdikyVzshWK7MB54n+fdOJmgt/ZnLJr9ppcmu6hYReEs3v14+0lFWvKbJY9OKMsVrjvkJ5OGniOUjDnvW8lyEbTZOtgBeFmWxu//NNNE0SnpzGT5DRU7o/QAsBFpjyEWfhfsTvunylBsd9QFT1xgVt+kFgNUZug0gakT/MQ2G0H+o1n73nCeOer/jEpb3gVpCpTmpBXrqWVLUiOJKr5Vn2CMEu2xr2HNf4IsjBZ61UwE1DEw5Nb/oWwm/uw7bUXaCSKkIjJYws2zoupn4b/WXJ3G0OZ8k67pwrSHnn/WF88AAg== 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=qQ/QG800USP94AspSL5Y3DvHV42AvDV6ZHFP44omgck=; b=sgHS+vxxjveFQOXr5PY/2c0paSMpmbsnc5hCdosFfDJBH4AMOF4fAL7urcyK0gpf+P2hsLTSgF8uXR5h+khLXpZGySZx6udvZfGjMNGE2sX5OP9cTkKoFesOqG7GDMLUMI9MQNu3UJKU4BCTbJqFSjLLWESQeqgMiTecB4kaiwA= Received: from CO2PR05CA0094.namprd05.prod.outlook.com (2603:10b6:104:1::20) by DM6PR12MB2843.namprd12.prod.outlook.com (2603:10b6:5:48::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.17; Thu, 27 Jan 2022 03:10:02 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:104:1:cafe::26) by CO2PR05CA0094.outlook.office365.com (2603:10b6:104:1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.5 via Frontend Transport; Thu, 27 Jan 2022 03:10:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:01 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Wed, 26 Jan 2022 21:09:59 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v4 01/10] mm: add zone device coherent type memory support Date: Wed, 26 Jan 2022 21:09:40 -0600 Message-ID: <20220127030949.19396-2-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220127030949.19396-1-alex.sierra@amd.com> References: <20220127030949.19396-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fcfbca92-ec70-443d-170e-08d9e1428221 X-MS-TrafficTypeDiagnostic: DM6PR12MB2843:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pp9hvXhxi/3buucFXc0NxSOgQvhT/8ldV3LcyzX847fxjETKbU/LYMGwu0KzhRkDISUXTMSwdeD9i7V050L6QRBDgjW0rw3O4Z8uTnXd8LDdYIKXDoaXb8U5RGjOAz6OgQlBgETCw7dV8HMK94IYh2phgh5ZCI4vnEBMgiP3crQnon7AcLrzB93T3BE+FEkLZe4wrRU2/N7jj6HCzz7HqNgpQQWAePhQ0AjzTMWdf15tzQ+06A7pDi9eW/h5muHR1ktReq1z5SurTpdaei0R2fr0uPkt5OKg5KbQMbtYiNRxLrWmheLNhXWptOPMVntda4ElK5NIxtHu3yILQiEtZfL/skJAD8+KaaN7GpcqiPaDv/I6ZWUnvRb0X5sbI0NTH9lBWsLXayOKYTuyHbtfUGSntrU8J1gaoZe1szgpxKUrvfKzX0NnmhlVMSZon94+73zx5PngaYRmXanKmxjGr8GdTjsBLCfBbQ0WKkHZ8hw8uoqbCkk1TR61FS4b9FD67ImI+FBuctcOrMIGfR6hkhLKJ1FlD0bZ19Au9gBlYiYIYbsoSQmCimJNedSrhsRd4Yt9LUILdovG70Vx+N9kWJdFMh6r1x9KsK385gzKcCGlVf6RXCG/fuTsJPZDTczLk8aO9iPToNPfuC/PQfKPrt6Ox3vRVRbAxk4A4T9eKNwF7mN1eCImbR20BzyatfaWHWInH8ydFWQ+GA4m9u4wJpDJ0mlhoZ23B8x0LamJPlsNryl8KGkBhWK10Pl9gjYkgTZpBowhgaKwa7sKB9jgWhANfRD+B4cr1l/3Io9dDyu3IxpIFhzQDmg805KAyoc0MPErejKMhEcc9gXbNRNkxx/FTn4YnXLfF3qS3o87Cb8= 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)(36840700001)(40470700004)(46966006)(36756003)(1076003)(316002)(36860700001)(86362001)(16526019)(7416002)(7696005)(5660300002)(186003)(26005)(83380400001)(8936002)(110136005)(8676002)(40460700003)(82310400004)(356005)(54906003)(47076005)(70206006)(508600001)(4326008)(2616005)(426003)(44832011)(6666004)(30864003)(336012)(2906002)(70586007)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2022 03:10:01.5058 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fcfbca92-ec70-443d-170e-08d9e1428221 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2843 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=sgHS+vxx; spf=pass (imf13.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.69 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: 0C48B20003 X-Stat-Signature: uz77wa8ipsk1856imtfkm9a53w1m1ux4 X-Rspamd-Server: rspam12 X-HE-Tag: 1643253003-637331 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 --- 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 | 47 ++++++++++++++++++++-------------------- mm/rmap.c | 20 ++++++++++++----- 7 files changed, 83 insertions(+), 36 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index c0e9d35889e8..ff4d398edf35 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 73a52aba448f..9c0bf1441da3 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1162,6 +1162,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: @@ -1191,6 +1192,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 6da5020a8656..b06262c3cdf9 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5695,8 +5695,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. @@ -5730,7 +5730,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 3e6449f2102a..4cf212e5f432 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1554,12 +1554,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 ed593bf87109..315b7715348a 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); } @@ -345,6 +347,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)) { @@ -498,7 +510,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 1852d787e6ab..277562cd4cf5 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -362,7 +362,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 += thp_nr_pages(page) + page_has_private(page); @@ -2503,7 +2503,7 @@ static bool migrate_vma_check_page(struct page *page) * FIXME proper solution is to rework migration_entry_wait() so * it does not need to take a reference on page. */ - return is_device_private_page(page); + return is_dev_private_or_coherent_page(page); } /* For file back page */ @@ -2791,7 +2791,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, @@ -2856,25 +2856,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) @@ -2976,10 +2975,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 6aebd1747251..32dae6839403 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1823,10 +1823,17 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, * pteval maps a zone device page and is therefore * a swap pte. */ - if (pte_swp_soft_dirty(pteval)) - swp_pte = pte_swp_mksoft_dirty(swp_pte); - if (pte_swp_uffd_wp(pteval)) - swp_pte = pte_swp_mkuffd_wp(swp_pte); + if (is_device_coherent_page(page)) { + if (pte_soft_dirty(pteval)) + swp_pte = pte_swp_mksoft_dirty(swp_pte); + if (pte_uffd_wp(pteval)) + swp_pte = pte_swp_mkuffd_wp(swp_pte); + } else { + if (pte_swp_soft_dirty(pteval)) + swp_pte = pte_swp_mksoft_dirty(swp_pte); + if (pte_swp_uffd_wp(pteval)) + swp_pte = pte_swp_mkuffd_wp(swp_pte); + } set_pte_at(mm, pvmw.address, pvmw.pte, swp_pte); /* * No need to invalidate here it will synchronize on @@ -1837,7 +1844,7 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, * Since only PAGE_SIZE pages can currently be * migrated, just set it to page. This will need to be * changed when hugepage migrations to device private - * memory are supported. + * or coherent memory are supported. */ subpage = page; } else if (PageHWPoison(page)) { @@ -1943,7 +1950,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 Thu Jan 27 03:09:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12726200 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 10984C433EF for ; Thu, 27 Jan 2022 03:10:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E050B6B007B; Wed, 26 Jan 2022 22:10:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CC8136B007D; Wed, 26 Jan 2022 22:10:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B69996B007E; Wed, 26 Jan 2022 22:10:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0060.hostedemail.com [216.40.44.60]) by kanga.kvack.org (Postfix) with ESMTP id 9D0896B007B for ; Wed, 26 Jan 2022 22:10:06 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 641C1903D0 for ; Thu, 27 Jan 2022 03:10:06 +0000 (UTC) X-FDA: 79074588012.31.DF43C5A Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2080.outbound.protection.outlook.com [40.107.220.80]) by imf25.hostedemail.com (Postfix) with ESMTP id D2561A001F for ; Thu, 27 Jan 2022 03:10:05 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z+Ug+HUuMQa5+feJEDtmkYuUuKpWF/LTs9veYB9lpT196JBBohTjp2NlhbuG1/AZxbHDtjogBVRbBeMVSX5uLZHIeAvHG/aaSeF7qNb6647lgPYx3dJ3yaLnrsJpB106RcfwaSnDje6+dXfmrZUq6mY3u+ucbW1DJ/8owvX2J5hMxHCsd/2ahJsolPIlBinU89gtbQyaYlmJGi+wBiV2KVujQTQQbIYPa+OAM9WCt/vSKk3zx/NUdd2yw3zgklTn1KWpkJxEAjprvmYF0jB2xit6wVkLtmwzVFJgs9Leb6d0gADsivB+lOd7N8UXXoC7Vu1AGAUwNV7mwbK1YjpWDw== 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=OWDM69tVcCu3/7sDv6tQ0MrJh3kz8/wwZi72uPu1Edg=; b=Z22dABpQZwU4G5inhSMdOpUf83VkkJ8o6Gpm9C+NIhu5OGAiokkb/aDCwGBFBSR0RsiVg0sB4IwhAea/0K7nDhWoHSscnq9Nh3AbUnZTuaM7k+RQMB8GTWD09ug2WKLa1+Rp+VeipjUC92QcoiPpVIrFbhz0rnURzXl83UrCaArb5BPk+ypQAnRvzS6WNMcq0MUvdPJ5F6F30mKzJA6+1+oHR6x3cz6zBPqXpUdH0KiDhnenJRe2J5JpEgpnjMAA7SM6iaZf54bMuMq5Q0es2hyxf///3euHhOQkZqjS8g0QBNEzfTTHsLqM6VUUmKtLm/LcvpjytBoCzJBIbBzCrw== 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=OWDM69tVcCu3/7sDv6tQ0MrJh3kz8/wwZi72uPu1Edg=; b=GMp55czC4a3WjqWP0SKIXqK43JaDaZJeIQ80y+bRwEa2t7JpF7PZ1CWy0L9/2aMF2PmDV1ahAOPgCLWg6E5lyLeOVC5w2u3zPVkBjiKnYi3xQ2H0X7gtQ/fVihsbB9Tyxz1nMxxF+sGlIoO+KPI4I30BRj5kJgTb9LQuz5TcbyU= Received: from CO2PR05CA0092.namprd05.prod.outlook.com (2603:10b6:104:1::18) by BL1PR12MB5271.namprd12.prod.outlook.com (2603:10b6:208:315::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Thu, 27 Jan 2022 03:10:03 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:104:1:cafe::65) by CO2PR05CA0092.outlook.office365.com (2603:10b6:104:1::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:02 +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; Wed, 26 Jan 2022 21:10:00 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v4 02/10] mm: add device coherent vma selection for memory migration Date: Wed, 26 Jan 2022 21:09:41 -0600 Message-ID: <20220127030949.19396-3-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220127030949.19396-1-alex.sierra@amd.com> References: <20220127030949.19396-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 84bf4b59-de14-4c2b-aa64-08d9e14282b9 X-MS-TrafficTypeDiagnostic: BL1PR12MB5271:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:635; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O6YczEsz69AvTvEsW9/oMmWH1FlSpMmjnz6TYlMF6eq2XpxF88gFtIKe3ONiepFntTYHafJPKwmmFaA89KwuXn/9Iyqy70gE9Vex0XKzm1ySvEWCyu1/Q1mzR8ui2Q2hakC+A8cjRZIt95kJOJ0aV8XxXBpTsH1MtGLdITOxeyZUKKq47l3FjiIe8bHmIihT9+xIDtFUqvtAvLAzDJqOq2qVUvsr5JV42yA8u5VpyE9/1z2tFJ7H/Aweq68GZQXyZeVr3RlWiXWoGrLxZJbIH4IbyjefuMg0jvyyTZLA6S3DYaQGMpck7U9uxdHy49C1pVJyJk2SHdECMDS3mnUVxc0k2m01KWKt3Dp4tpUQ5nHoOpTtzcJFc9RWbI2ruHNXCtwVl490jQ8pp/4m3oPI3VG68phmZuXYbd52oXnciUvrE8FobdNAJieoEjNkXpzi1VumFtdndYgSBPvS3CfEY4cp8VzktUW94wad/5OeXOccYaXtZP8XsByT4M7H9qIlBXuAPFy4EWkx24UVG0rUiEh77Qqat2iIhwn9V0Jteu9VBmKfk8aF7cJjQMspmqmCEILuoWCsN9oSVREn8fs+8OerAhvQ5ceCpBwRPtsCw9Qeg8uJ6vP4ypK/0OtJKf1tkueczR1gCUsWsbcS7PmaMe5skBw2YUOamA0DzEp41/Sr3yeUAaI2m2jM6EL3IelKwps2Ej7eyJnJMW56/qdOIA== 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)(83380400001)(86362001)(336012)(2906002)(36756003)(6666004)(110136005)(54906003)(40460700003)(47076005)(426003)(5660300002)(7696005)(508600001)(8936002)(186003)(16526019)(8676002)(36860700001)(4326008)(44832011)(356005)(316002)(70206006)(81166007)(26005)(1076003)(7416002)(2616005)(82310400004)(70586007)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2022 03:10:02.5057 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 84bf4b59-de14-4c2b-aa64-08d9e14282b9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5271 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D2561A001F X-Stat-Signature: nq6hhxbcsz3da9qjujqwigbtwri8qj3j X-Rspam-User: nil Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=GMp55czC; spf=pass (imf25.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.220.80 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1643253005-913073 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000102, 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 --- v2: condition added when migrations from device coherent pages. --- include/linux/migrate.h | 1 + mm/migrate.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index c8077e936691..e74bb0978f6f 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -138,6 +138,7 @@ static inline unsigned long migrate_pfn(unsigned long pfn) enum migrate_vma_direction { MIGRATE_VMA_SELECT_SYSTEM = 1 << 0, MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1, + MIGRATE_VMA_SELECT_DEVICE_COHERENT = 1 << 2, }; struct migrate_vma { diff --git a/mm/migrate.c b/mm/migrate.c index 277562cd4cf5..2b3375e165b1 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2340,8 +2340,6 @@ 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)) { mpfn = MIGRATE_PFN_MIGRATE; @@ -2349,6 +2347,13 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, 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; + if (page && is_device_coherent_page(page) && + (!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_COHERENT) || + page->pgmap->owner != migrate->pgmap_owner)) + goto next; mpfn = migrate_pfn(pfn) | MIGRATE_PFN_MIGRATE; mpfn |= pte_write(pte) ? MIGRATE_PFN_WRITE : 0; } From patchwork Thu Jan 27 03:09:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12726201 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 3B943C433F5 for ; Thu, 27 Jan 2022 03:10:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9790C6B007D; Wed, 26 Jan 2022 22:10:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 74E8B6B007E; Wed, 26 Jan 2022 22:10:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 576406B0080; Wed, 26 Jan 2022 22:10:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0244.hostedemail.com [216.40.44.244]) by kanga.kvack.org (Postfix) with ESMTP id 3E4316B007D for ; Wed, 26 Jan 2022 22:10:09 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E82A089942 for ; Thu, 27 Jan 2022 03:10:08 +0000 (UTC) X-FDA: 79074588138.28.911AFAA Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2058.outbound.protection.outlook.com [40.107.243.58]) by imf04.hostedemail.com (Postfix) with ESMTP id 44B7040005 for ; Thu, 27 Jan 2022 03:10:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZFPyhWoJOyr41NNB8gRy9eT4b0XACv+neGzyo+oWFj5P05bul2fTM78j7wrcvtEgekGiVMcIPa0eQmPubaAyhEzl3BANO0ZI+b7eJ+oK1zUmNbgkZ0KlKn0Q8gkTNR61ny1jEMidGbiitKOuq/GG1bwsM08ZWRYZ25uFCyRc/lmXvWrEFmSaB1ob6qC+BBGwoCQm6I5pWrX/qbu4QHoQ7sYK4VyAb1lX/EqS+3oWMUNpptOi8EsLaiTPBUILo2F5MAfj+osv0Knh9SqaRuu5UPZSsOalVDJc0uoNL1by2HLFcL/Vu5IJcRRnQlsI8ZClZtYnd6dBOBV6/aFSY/o3LA== 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=A8qBl4zLIvmc52Whswdyv9hi+p7IyTpTN/04HVb9g+4=; b=kJBFbLe6YcX+xYYJaVd+/bvXd10QhCUkSadwwIFgitjjFAdLonEGQYCIVSOX5JEvOrG7M5aVbbwYbUuEDAZABlKyClqENXLRlx3bXqSPxpJyS+Y003p65Cj5dMBx/h78ZsNDOm2Pyl7zvl2BRo4krrzLOhmfFwMdKjOcEI3yv8wOLeyhWvMJH/VT1QMIQHRLIeJOcWhRulnDJp96f8KJq7mElfRbq2mUc4qu/Ud+xPscmrc7aGH6BnycDFzuQS4UsIfmB5uwRimIzY5lHRzsAp67sORpU8/h6plOonzoyOOHyp+9O750kgTnyxyQeZ1WQJM1W/B7ZbkEZ1xSdGdUYw== 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=A8qBl4zLIvmc52Whswdyv9hi+p7IyTpTN/04HVb9g+4=; b=nP+GVeKplRUBEeOKRYabFHxGiqBbFZLB7Z/rFxN+MtaXW+bxOlWvrjbctetHKdynt7XAqxSEcKHwR0Sy8N3VWsE8Q6149VDPA8373shFuZaolTRLm/29A7bjjI0Sjjc9s0vtqiLOoOU21glDwNZG02kGn08YwXZ+vZ33NPu4zCY= Received: from BN0PR03CA0060.namprd03.prod.outlook.com (2603:10b6:408:e7::35) by BL1PR12MB5269.namprd12.prod.outlook.com (2603:10b6:208:30b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Thu, 27 Jan 2022 03:10:04 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e7:cafe::5a) by BN0PR03CA0060.outlook.office365.com (2603:10b6:408:e7::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:04 +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 BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:03 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Wed, 26 Jan 2022 21:10:01 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v4 03/10] mm/gup: fail get_user_pages for LONGTERM dev coherent type Date: Wed, 26 Jan 2022 21:09:42 -0600 Message-ID: <20220127030949.19396-4-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220127030949.19396-1-alex.sierra@amd.com> References: <20220127030949.19396-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d66c0973-9f16-4070-1b97-08d9e1428388 X-MS-TrafficTypeDiagnostic: BL1PR12MB5269: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: wttG2xJqVS+/RNQHtuDK1axstrKrPKFY5gtz4/7NQgjaR/X+OT3z13/3wc3Xmk7ur2x+MkjUa/3RB1V/mdYaSIvNeMY7GO07wZ4Ps/5CHCmrQKTYsldnbuJaVlJOvIsBXwEz4Nv3WzU35aQrgMe8cP7h8XTkxb7CUNgMxt0b6+QFBze02I9xio+FKZuRpWT+J3p2lUwSIZ06TDEone0VgjxPxb/TmCgn9h/e5XTNo1+NGhw4iKdYWL7YCsInc2XJ+msmU9D6yxW9wjFRqeykdlHkWkhj3NZwJjsE+3C6pvcGOhh05fY58YDh0taf/qJCBz+eI0r7fb2+S0KBvUAHUxCMrzO9oadN1hJS+pi64tG3IlvjNq70HpQJobBUn0vnbF9VLaq5+Lg+ZaXVyA4PjPsg9RxoiZqHXkjy6Ecm+Os+rdMfERaKQvyunm/HuOSdIauJUzvy0Ki+9RVAi0E0dmJ2M/7YZ+7yesezCp3heJmpqo6wEvmv75FO1mCW4JPfz2j4uVzTa3GPPSd92fZOpm79BNLggjq+PtyvbQV1ZGPiP59R+5CsOSjH+Vq5MYgIKnKE/X5ZC5u7s7Sy2hUChsBhGietzOZj1xna1viKIh/BfUagfjCpq/1yeiAHQUWYSK9VzkGDfoM6I3EYuo6OMZiFLtsU/80Jy2uwYi4QyfgbBeNR502b7tYUr9/pyY0BX0cOOKrpWoDd3Hk0ffrqsQ== 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)(6666004)(47076005)(7696005)(2906002)(2616005)(36860700001)(54906003)(82310400004)(16526019)(508600001)(1076003)(26005)(186003)(336012)(426003)(4326008)(44832011)(5660300002)(8676002)(8936002)(356005)(316002)(70206006)(110136005)(70586007)(81166007)(40460700003)(86362001)(36756003)(7416002)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2022 03:10:03.9680 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d66c0973-9f16-4070-1b97-08d9e1428388 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: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5269 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 44B7040005 X-Stat-Signature: t71mr5q3cdgi86kqaxht5545sz3ayazs Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=nP+GVeKp; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf04.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.243.58 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspam-User: nil X-HE-Tag: 1643253008-286864 X-Bogosity: Ham, tests=bogofilter, spamicity=0.036567, 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 Reviewed-by: Alistair Poppple --- mm/gup.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 886d6148d3d0..5291d7221826 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1720,6 +1720,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)) @@ -1750,6 +1756,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 Thu Jan 27 03:09:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12726202 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 3FCAEC4321E for ; Thu, 27 Jan 2022 03:10:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA5986B0080; Wed, 26 Jan 2022 22:10:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E282F6B007E; Wed, 26 Jan 2022 22:10:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C103B6B007E; Wed, 26 Jan 2022 22:10:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id 759DB6B0080 for ; Wed, 26 Jan 2022 22:10:09 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 39BE98249980 for ; Thu, 27 Jan 2022 03:10:09 +0000 (UTC) X-FDA: 79074588138.15.3DEC209 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on2059.outbound.protection.outlook.com [40.107.102.59]) by imf24.hostedemail.com (Postfix) with ESMTP id 9C7F6180022 for ; Thu, 27 Jan 2022 03:10:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fXN/du3ozvdYHrYqJXv5yWq93Kbd8iTHpyxpxlLfYSr6jtEyhbJ+qzjW3RiRFuH15eFpUyX0Klt1xOLT1ZhOBHKBQ+5Yruyed4fZh0973SdvcuNTdLOAHMhR/HhPrgofERnjkjBFqb0urYn2kjWJTjAIe3D4JDSEMBkTxcC7YnxkdFC/BQfdO+vLO8a5JOsD4RbbH8ay57IsXAjdIKs7LF2xWXXeMEtQqelLbZNa5du23dWHW+1pO4mITaeKy+lWtDC8S44gC0zUppM5KW6bPwCHyPAhgq1IugFxgaIm2eQ7u45s1ZbheO18myitdZmOv+OxtVSjFmd5T5uVa5h82w== 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=GAF0C1Az5E7eNTp++D6wdqoKFJy/vdeyTKmR/88xqyo=; b=dud5Kb6XbxG42rdpzm4ssKlpcE/YRw01lnBjSZZ3ZhN8LpTUTllPeKS7zuVjH2LJPdG6AXUjUZMeP4gfvqekX8hXVxWyvFIDTrw6bgwZ8McPvPSAWUQvcjeNdorrIaVhSlIAdEYxOmiU0kCnn/jYyojI/cKt/jBc7oFcOb5dwqTqZq/WAfzWRYSfj1LUHjxhes6paGrXk7/8Ne+iZNwWK/lSimkEh+vofPzDW9d3/AAygS3h8WVeZ9qAeIY9xJHRMdnNXynu4XT6lXA7Tmv7aOiPv7cxHFYNNhS6ymJTJ8iYJyylpGK6loGF1vt7AI9UcMBLKGuvSwu3p2h7kdnonQ== 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=GAF0C1Az5E7eNTp++D6wdqoKFJy/vdeyTKmR/88xqyo=; b=oyg2VguT4fgT5Bq1A1bQJn+cQF/7AtS2U2zCNM3zUiQQHXgMc1TJnWiiV/t8yI47dpc9ZqZNF/iZw4DXG3TxTEiJ1iK3zLLZlb8uO6yHN0B6eM0jk+r7fLbfdY/2gnW22YJgIqchedn+74/xQvn0UPtiHQJaoy20RCna4NgqBCc= Received: from CO2PR05CA0105.namprd05.prod.outlook.com (2603:10b6:104:1::31) by BY5PR12MB3873.namprd12.prod.outlook.com (2603:10b6:a03:1a3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Thu, 27 Jan 2022 03:10:06 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:104:1:cafe::94) by CO2PR05CA0105.outlook.office365.com (2603:10b6:104:1::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.5 via Frontend Transport; Thu, 27 Jan 2022 03:10:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:06 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Wed, 26 Jan 2022 21:10:01 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v4 04/10] drm/amdkfd: add SPM support for SVM Date: Wed, 26 Jan 2022 21:09:43 -0600 Message-ID: <20220127030949.19396-5-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220127030949.19396-1-alex.sierra@amd.com> References: <20220127030949.19396-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c5afa845-0344-40c8-9978-08d9e14284db X-MS-TrafficTypeDiagnostic: BY5PR12MB3873:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P8xCXVbvMyHTlYOrFyjXrIUl6FyjdvtPugco3FaiMrhR886tqt1ep8rC06DQCjSPE8bsAYD3UNCxx6mAvDBeWatzDXnN0ZBQtg3gpcWL+HU7D85Uii9hz3OoMqd5vbgIDu2RtzNOJJn15RjcLAsADhL8LJw9QLwV99093a3oGKCKyc/iMTeKBDRscPHhP7U7edXGFl1n18BlC3sz/Fa5DOavu9IgigKO9Ty4hX6u3HgHO5BVncmjQNmvjeTqY6yDVxMgZ0h7h44ei2nEXA8WnOz2TNH3Twm6y1rG2Mkr0MqQLxwnpR92ZZfKX5HmUh2l2v+kRTauDUa7p5GT9GB72EG3LuUicyUdoTV6M35L/7ScxXHtmt2JLuZ03ADyXG6HMG47r/0nX7cLs8QXCapVPlLcXfituFvNDM2Q6Jopp3E4d+stJ2ikJuO0biV6ZDAD3TW6BR31jQPln6ThfziIPoEMR9ExAedAZnsJKBWXQ1tefuM6Mn6Dch5x7jo3mhf976A9NAGhuVOhXDYIoTDNQEgL/BqpStji55oxlq7yIg/hasn37u4h1O2hemi1ggsQyw0X/ty+/NQqAO+wAmCHlc957MhlZj4YQD7WxmH4J0mmiPYmwGK+yN8UulXQ4Zy17svKKmm+j5Ky+8woszaF7plFbVpBsxb7C9m+08nmClNcPzxdHRhzhwKzqHv0lE2rnONT8BNcMR0krL/rotG7vD960G26Km8JWse+aJx1MnNzLDBzCatSUCH3reS98QSspI+BLKtdixHUNt2KhITKG2j1RJ0FasB5bgAt5lO5teU= 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)(36840700001)(40470700004)(46966006)(82310400004)(70586007)(36860700001)(8936002)(70206006)(2906002)(16526019)(6666004)(40460700003)(86362001)(36756003)(508600001)(44832011)(336012)(426003)(5660300002)(4326008)(356005)(1076003)(2616005)(81166007)(7416002)(83380400001)(47076005)(54906003)(8676002)(7696005)(316002)(110136005)(26005)(186003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2022 03:10:06.0836 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c5afa845-0344-40c8-9978-08d9e14284db X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3873 X-Rspam-User: nil X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9C7F6180022 X-Stat-Signature: na9ifmgruuud588khzuy3yy4es4aixc4 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=oyg2VguT; spf=pass (imf24.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.102.59 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1643253008-977234 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 --- v7: Remove lookup_resource call, so export symbol for this function is not longer required. Patch dropped "kernel: resource: lookup_resource as exported symbol" --- 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 aeade32ec298..9e36fe8aea0f 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -935,7 +935,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; @@ -950,28 +950,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); } @@ -984,3 +990,4 @@ int svm_migrate_init(struct amdgpu_device *adev) return 0; } + From patchwork Thu Jan 27 03:09:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12726203 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 5E39DC433FE for ; Thu, 27 Jan 2022 03:10:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21FFE6B0089; Wed, 26 Jan 2022 22:10:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 156A26B0087; Wed, 26 Jan 2022 22:10:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D66CA6B0089; Wed, 26 Jan 2022 22:10:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id A75686B0087 for ; Wed, 26 Jan 2022 22:10:09 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5D91B181CAEC8 for ; Thu, 27 Jan 2022 03:10:09 +0000 (UTC) X-FDA: 79074588138.11.ABD8830 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2044.outbound.protection.outlook.com [40.107.223.44]) by imf23.hostedemail.com (Postfix) with ESMTP id CDD04140010 for ; Thu, 27 Jan 2022 03:10:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M9s6CrHD65iWB5JWzWJUHSFj453dCm0kbToXrVl4TeRy9U/5u3sVr0C0D4u4CdFyx8RCdh8ijjeugn3Uq+3B3Uf+bQO/KKfhFd8zg6jLd1xFqju2o9X3Da2th1FMIMW6R/TT060UTxOS0bXeo7XxBADIX6bvEXEGkwzaEgXW7h8NTU5QyGeZCjpUmX0rD2+UYdqXEiFGd5XPvQSnhPPmn9lijcD13OUC/By0riuCeBBhHtxiLUGChagwMGog8CAX+RO20HpXwXMAnFOP+dxoOlB9YE0pp4biQphC8mf9M/xBx82PgifGCv1fge0KUZplKI+e8cddhXg0Ij4Y7twbyQ== 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=5XOWr7fnVYEba5NhGZxd4trx6OZFuB1g3xD2zb3WjmU=; b=g1JIhYHM7Ut8j5BAdTw8gqhlvbqXwYa997KX9dl3ZOzKvDjVpIdOR7Gpwp5Bpjv7+fsMZEbpavWRdv6FkKwoB5M07z7kGvwsCEbg4+QFmlmlenH5CvAsl0RLxpY2uXa9818J8p/jjdzbn2b7oKz8Ftm32J+51MKJPFXvjqq1ihoz9m0DbKt5Y/twP2eIUOVj/KEeUBdiGaJEgszAFl7kEormzCf4dTgiuJ1UpIlX48PXKRbVU/kMX1f+XLrBG+QMIuAKluaYMhGDpqFIyfvQcrROCwAgUrCgcjPVkI3wO4/Eu836acHnyrhDrKr6AqWNnTJ+L++lZH90gpYjhTbkKA== 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=5XOWr7fnVYEba5NhGZxd4trx6OZFuB1g3xD2zb3WjmU=; b=Bqi/85bv5ai7K9yHG3gFtXhVK4cipQ4VqBt3gQDgYkM3vZu6ratTu1He+WBbNEQCASQswufx9U8fstD1isdY9tJBEHiRlpU35c84MyGmd0ISaJJzuNTQf9TCeOUWOiGP3VNTXwYlxf9PaXJ6d/f1lNVZUEknU9CetnrnencWJL4= Received: from BN0PR03CA0034.namprd03.prod.outlook.com (2603:10b6:408:e7::9) by BY5PR12MB5015.namprd12.prod.outlook.com (2603:10b6:a03:1db::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.8; Thu, 27 Jan 2022 03:10:06 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e7:cafe::e0) by BN0PR03CA0034.outlook.office365.com (2603:10b6:408:e7::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:06 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Wed, 26 Jan 2022 21:10:02 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v4 05/10] drm/amdkfd: coherent type as sys mem on migration to ram Date: Wed, 26 Jan 2022 21:09:44 -0600 Message-ID: <20220127030949.19396-6-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220127030949.19396-1-alex.sierra@amd.com> References: <20220127030949.19396-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c2acd24f-aee5-4e50-67de-08d9e14284df X-MS-TrafficTypeDiagnostic: BY5PR12MB5015: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: v2RWzh+1HiZBOGs2vV/HAKTqxNUFGuUUBXDLYqhkBRNsuJrkMAd6t02ID5yuJidDWdIVG9aA1JT2AkxO83GePsxmFD7d3ZoJOuEvyc/kfsXgNTc2pq7HCGGn5LB/TOCL9FbIT9+viou+k1maIeXAxNhL6hqscX2E2ea6VFkVpAPEaVcyHXMbmB9Rw0MYZ9juCZTp1SpfXVu3+rRIxwIf6j1hux5Y1kf8fJ/lSrOYHKrKhuFRLB6d2VKMwslx+xY+cOfFhjZyailebC4tWfCl3UTv3ivdtymkmcAIguXXfSByrEcFle19kg1ShKxA5VOF3gkd4v4o1QDxdwEV8ECRs0cfy9K99x4AtIhOCRt1lVxYvIp4zzAQMFiUWSOmBM+cil9h/HU/mbCP+Hz+blrqfn/RqCbkKE90H9KHtBn6hKpeCC7HB1Ayi2aDfYsz+4JoPCYZ+84JpxKJloIRiIttQZ9Vq7p/D5zGcgqwV+kgJmcmnmwYLplqJA1vN5yTAiT2ewJys1WHR+DJGwnxQ4InYk7E3FIYqc/B5vEVqWdZ2dZ9C0vhSUMziEFn+K9MFRZ/O1uI+PchmlRarvgaSuBSaNj6Pl8e0lQA98UFangc6KdO3e0GGQAdtoVudqdC/JaFjMs19ow7bsvRArgv4rmS5vIst2huyIEw2hfI56JrMO5TubwjwiM4DWzqeuHS8FHTrJ2ZsEdz9B9q3xHYlYAZET6j+R+EhLEtts8EXWbIKficTShf9MWGxk6jsMgvFK6swab52ZvLQZPJhRbwUGE+1V8cMqUYSbwA8tYiaf46YAk= 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)(36840700001)(40470700004)(46966006)(8676002)(81166007)(44832011)(5660300002)(40460700003)(8936002)(54906003)(110136005)(4326008)(426003)(86362001)(70586007)(1076003)(316002)(82310400004)(336012)(2906002)(2616005)(47076005)(508600001)(6666004)(26005)(186003)(7696005)(83380400001)(36756003)(16526019)(7416002)(356005)(36860700001)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2022 03:10:06.2335 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c2acd24f-aee5-4e50-67de-08d9e14284df 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: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB5015 X-Rspam-User: nil X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: CDD04140010 X-Stat-Signature: 113fu9xqbd14a1tmk9fbce4pohr43wj1 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="Bqi/85bv"; spf=pass (imf23.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.44 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1643253008-873224 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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 9e36fe8aea0f..3e405f078ade 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -661,9 +661,12 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.vma = vma; migrate.start = start; migrate.end = end; - migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; migrate.pgmap_owner = SVM_ADEV_PGMAP_OWNER(adev); + if (adev->gmc.xgmi.connected_to_cpu) + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_COHERENT; + else + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; size = 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t); size *= npages; buf = kvmalloc(size, GFP_KERNEL | __GFP_ZERO); From patchwork Thu Jan 27 03:09:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12726204 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 6A3DCC433EF for ; Thu, 27 Jan 2022 03:10:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A2A16B007E; Wed, 26 Jan 2022 22:10:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D89B6B0088; Wed, 26 Jan 2022 22:10:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21C316B0081; Wed, 26 Jan 2022 22:10:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id D623A6B0088 for ; Wed, 26 Jan 2022 22:10:09 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8BEF48248D52 for ; Thu, 27 Jan 2022 03:10:09 +0000 (UTC) X-FDA: 79074588138.29.2E540F1 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2064.outbound.protection.outlook.com [40.107.236.64]) by imf03.hostedemail.com (Postfix) with ESMTP id 11FE92001D for ; Thu, 27 Jan 2022 03:10:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dZHyVm1ZKvTSvBB9UZIaQgSpOPA0VkxDIJ04TjLalAwdBBhjH9f9joWM8xbKrqtj33rmqxrxkTfARMxnyBPXLN5qJdyv+G1sP5iG9g07fwDF+9K+lLNZFjv6ZfzQntqEg2vlqG9qjzNJjrX2bMDwdsTktx+hDDXk95Gks0mGEz7M2nMy4zp98PJJbP62LJkuXqQrq0p9JXssgAZK77MF4FMz+NATcCmbt283BrwCP+DZmOJbSXi7dHMe7vfey7tSul1zhQNdL80LUWlXcHWAX8WNsjJyIFa/RR7aYsuDHw06whnoF27VpNdLEj/dJNfSp7IMv17/L9/mGI9/Ya+Gnw== 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=w4Gx4O56pz11w33yhsqgpm264AySA+e5Qi1ku8UkUqI=; b=kPzq+TYwM+FFpZi6lqOUd0cbbrf6kGPXIwpfjTK/41xIjNnp6OBvDGt6YEwPbQHRfKjsFg5k6wH89OIhBmuuThFdqXpinWl+ZHchE08Vw+hzNBDWQfBZ+swCupah5oYCZSmzPAsnCCj6d3xk5wSMP7JUxVmpYjh+otj8dyh2GLkKHb4S2akD1moboPtDna1UVDeetr+QRxKtOxRAZjerRItgc9KzHJJXBi89TiqF1B+99rcdq2CPJqbyzBURklvvhjZIIs8jkQYFLolXtMF62k4tBmzVwd7iTBE9aUrZekbW3ZUabLMe4iGvC4NU87O5f8EqVgsIjvwxFCqR164HIA== 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=w4Gx4O56pz11w33yhsqgpm264AySA+e5Qi1ku8UkUqI=; b=jrnIxJhE5IXiqEAh3Z+6KHvDXzUNpWiB42oDgORewwnCmEtBCTiPXHoLOyo7wXlTc069jQ12NqTFACQfl4omBejzBN0c3HR7vSwnIk2/jejwtkdTKSyHFWxZlFq8YgEiEuQzTgp986J/ejY3E9Hg5lTVmfHxwN+rrZ4bWRO+qsg= Received: from CO2PR05CA0104.namprd05.prod.outlook.com (2603:10b6:104:1::30) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Thu, 27 Jan 2022 03:10:07 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:104:1:cafe::23) by CO2PR05CA0104.outlook.office365.com (2603:10b6:104:1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:06 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Wed, 26 Jan 2022 21:10:03 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v4 06/10] lib: test_hmm add ioctl to get zone device type Date: Wed, 26 Jan 2022 21:09:45 -0600 Message-ID: <20220127030949.19396-7-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220127030949.19396-1-alex.sierra@amd.com> References: <20220127030949.19396-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a1d93e32-8eab-42ae-55c6-08d9e142855c X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: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: LgLPRb1Q5leI1mGEwMAXiP64r1MD9uGPRdsg9kNjiLePxrlTBwG6J4gDlDe/QcVRmtM8JF9uIBYFij0BPQ5PcC8xGuauV6L0hckEE5CjUalQDQfcMOwRFS+nZyAzTxvudmQF2LiqlM7MFN87G9kPM2eU1hiYRTrq/XVH4gyZ+hs+GUJcUVO4WYHQixsE9wChJDdKwltR577gOF2kbQmnAz6/W36uNWyL9tasXd7bU071FqshdhqU3CZDCeE/Uzp0latAwhqsa3ug4wExjuDLH7T80qdDBbTrb9a7ePlseovC+u6mtGMtrpt7mG983KvldwplIm7U+iMQUuRX+g3HG+tYJrsudAr8m2TeTsV8+l46IDW3/wzw4uollgaheSVK3imlyVifQcb01RFi0Alg8BYyzMl5aXHNokKkMLtD7EGZqwttKDs5vnHw7nFAyTzg6IKgwEsLC7gkmNsC3IvFfCW5PTQtvcDnYg0X+PFCJkiWW+enghmyjgxOujC1B4UNU9fTUNuhaqyaoe+ogFr8abO9moDEBtv1V3YzkT2MzqYDR+EB9fieLu9w6Fb+pazXd2PiMyLa9Hswo2y7SfLtzPfAtM/5Xw9OuLFgHXua0xlNv/yy1bMtn66369f8rctLdxo8GVpA7KY9DqpjXUT1VhIL/R4ue6biLNbUwHmDyKNDaWiNjEK9onzvCOJ0ltCzm9kMSwFrEJ3gjk9LVb8mfg== 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)(6666004)(44832011)(7416002)(86362001)(4326008)(81166007)(5660300002)(7696005)(82310400004)(508600001)(70586007)(70206006)(83380400001)(36860700001)(8936002)(8676002)(356005)(36756003)(316002)(26005)(1076003)(47076005)(110136005)(54906003)(40460700003)(2906002)(2616005)(16526019)(426003)(186003)(336012)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2022 03:10:06.9273 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a1d93e32-8eab-42ae-55c6-08d9e142855c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 11FE92001D X-Stat-Signature: w1n7azpdphidqhgwt3spjxbdkuc3rtnx X-Rspam-User: nil Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=jrnIxJhE; spf=pass (imf03.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.64 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1643253008-819417 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 Reviewed-by: Alistair Popple --- 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 c259842f6d44..fb1fa7c6fa98 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; @@ -1025,6 +1026,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) @@ -1075,6 +1085,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; } @@ -1235,14 +1248,20 @@ static void dmirror_device_remove(struct dmirror_device *mdevice) static int __init hmm_dmirror_init(void) { int ret; - int id; + int id = 0; + int ndevices = 0; ret = alloc_chrdev_region(&dmirror_dev, 0, DMIRROR_NDEVICES, "HMM_DMIRROR"); if (ret) goto err_unreg; - for (id = 0; id < DMIRROR_NDEVICES; id++) { + memset(dmirror_devices, 0, DMIRROR_NDEVICES * sizeof(dmirror_devices[0])); + dmirror_devices[ndevices++].zone_device_type = + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; + dmirror_devices[ndevices++].zone_device_type = + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; + for (id = 0; id < ndevices; id++) { ret = dmirror_device_init(dmirror_devices + id, id); if (ret) goto err_chrdev; diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index f14dea5dcd06..17f842f1aa02 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -19,6 +19,7 @@ * @npages: (in) number of pages to read/write * @cpages: (out) number of pages copied * @faults: (out) number of device page faults seen + * @zone_device_type: (out) zone device memory type */ struct hmm_dmirror_cmd { __u64 addr; @@ -26,6 +27,7 @@ struct hmm_dmirror_cmd { __u64 npages; __u64 cpages; __u64 faults; + __u64 zone_device_type; }; /* Expose the address space of the calling process through hmm device file */ @@ -35,6 +37,7 @@ struct hmm_dmirror_cmd { #define HMM_DMIRROR_SNAPSHOT _IOWR('H', 0x03, struct hmm_dmirror_cmd) #define HMM_DMIRROR_EXCLUSIVE _IOWR('H', 0x04, struct hmm_dmirror_cmd) #define HMM_DMIRROR_CHECK_EXCLUSIVE _IOWR('H', 0x05, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_GET_MEM_DEV_TYPE _IOWR('H', 0x06, struct hmm_dmirror_cmd) /* * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT. @@ -62,4 +65,9 @@ enum { HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE = 0x30, }; +enum { + /* 0 is reserved to catch uninitialized type fields */ + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1, +}; + #endif /* _LIB_TEST_HMM_UAPI_H */ From patchwork Thu Jan 27 03:09:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12726205 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 82AD8C433EF for ; Thu, 27 Jan 2022 03:10:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C2926B0081; Wed, 26 Jan 2022 22:10:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 945C26B0087; Wed, 26 Jan 2022 22:10:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77ABA6B008A; Wed, 26 Jan 2022 22:10:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0235.hostedemail.com [216.40.44.235]) by kanga.kvack.org (Postfix) with ESMTP id 5AFCB6B0081 for ; Wed, 26 Jan 2022 22:10:10 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 13B69181CA35E for ; Thu, 27 Jan 2022 03:10:10 +0000 (UTC) X-FDA: 79074588180.09.50FF7B9 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2067.outbound.protection.outlook.com [40.107.93.67]) by imf19.hostedemail.com (Postfix) with ESMTP id 857591A0012 for ; Thu, 27 Jan 2022 03:10:09 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nynlwH1XA9LqiU7g0OOqe12uQs7Aego0VvaU6Xz0MbU16Wb4+wtT2PXCUICSpxg20M6AMVXoAmCAKUKWg44t38guzeeZOAa7jQs8KORUW7FI1w317frfpR48ApZMnF6GAOWDcIr+ukcUixaZAVsVq4tijsp5ttm6Wn35wyRyoUsSL/yXW/61otjJ88DuMMGviB16G3F1ptpglMaP/Tu8Rso0POQMjnZ8PXdSUHKUnETRue9eFbKi6HnzXUiguwIRYVzZgZcq5U4lXNyqB1eDYZp4bsX4gtjCRBNY+3cGFLAlEYxtjHOzsarQTFZoXypTjqRFK4kbQOBDxKdU0MJuKw== 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=m+GJAC43XZGR8kqXA3YdgEYPG5jeb3awGMO5dcj4F3k=; b=DolapNPEtroANi1kqq57QtlEC5tVmTGpyRIIREa2wnD50hV+bN6QeIZnRLwm1bYQYGqm3UedgunClIGhmVt5Q06vrtLZBChRP54ucGUVMRc8lQFpUDeK0R3OM5925h5qiNeOnA6FYF4NRg1ep6mTiVvh8aBRKYEGXBWWhxrCv3CdM52KGMRjdPY9LDe88yRW6SfYIDVx2IFopwij3Ugk6V4UnPYbnJKQz+mfM8K2MgfGddtMpf0llFmIAFpdPRss09JQlzpWLN3Cy+QyO2lJ9/Sv4ODMVgX8/WETB2cUuMgsefIQJ3zm2uNnQCn2lGDE3+kb22z8LGNu8YNAJeyEJw== 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=m+GJAC43XZGR8kqXA3YdgEYPG5jeb3awGMO5dcj4F3k=; b=2YkrTmEDxCu/jhbvgBIloV+NPyunTnqSQudYRFnuUn23J/0Buo23zHXjg5iizAtD18RUDxBBOppaJMRCoDCsz39Fwigp8DOF2OK75k+NOT9XRvJmIhcnBvQv0RthO34S35pqew5tJjiXHR2qTjTtJdByHOvzyahStmqSfQwbiuw= Received: from BN0PR03CA0038.namprd03.prod.outlook.com (2603:10b6:408:e7::13) by DM5PR12MB1531.namprd12.prod.outlook.com (2603:10b6:4:f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Thu, 27 Jan 2022 03:10:07 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e7:cafe::dd) by BN0PR03CA0038.outlook.office365.com (2603:10b6:408:e7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:07 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Wed, 26 Jan 2022 21:10:03 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v4 07/10] lib: test_hmm add module param for zone device type Date: Wed, 26 Jan 2022 21:09:46 -0600 Message-ID: <20220127030949.19396-8-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220127030949.19396-1-alex.sierra@amd.com> References: <20220127030949.19396-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 60dbe854-def3-470a-d513-08d9e1428570 X-MS-TrafficTypeDiagnostic: DM5PR12MB1531: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: ItVR9pAn/dYfDhT1LiguA81luVW+KW4IGL1R93qdKhd9oEagOdVXMbMZpAXYrruMc0DYFMwxm+B/uARax96Fc+a3JN8WAs3FFjCtosOuVJHVK0+POPZK1yhxFzPeL3Nz+qOHs2qRIySIiUtJDiUb0D4L0na0DPURe3H8vUMyFoHL5x0Z6TfAlwPPWXgQbLPfk5iGAWGGorNnuFtD4zHQY1/jlgUnun11uVtMHHoWWnMJptQYzxba4dXxq7P19+AvW+zf1lCWivJ+C5XPMIDhqli2L2qVWW3JY7fecipr0je6mVOfUjgzLCChpx9pCW17R6Qt4k54WYvkxfVgke/qswagwg7149LSfl/ZxF9qaHlPYJmobAN92FTQroiH3Q7JXU5yhpantzj1OuiFYOVfxesADgRIQZgeXfgovgPgYAWWh8TwJl7n+om68+KpT2Nr+yDqgXsrbV1dgkUen69Xw0Hj0WkxMEJNC/CISrMLIok7U0aVDAJvZYYQHZC6vHoczJhjYMQfjFS/thyaiZBQeGnJAkujf3uePvf9DOuevcS8SFBOOpBJqL1mtsScGOraE2hUZZS5JY9Rc8izD9/ul5SiqxwIzjCOt4APvzlXMYPhBzdpH7VWtrDEpqD7Lv2TOElM4W6JcROCWLhdiU/owgjCVqkUWkDpcvmBj9/6AbyZo+LFaxpom8OWPYzZqy4RXbaaqhpt+m5/xy93nT5RPNj4WYeCgU1XWAJ9tlRenVXVcwU6zZfnSuNjsMzgSKipgP546mDW9TUKSVk6OHkkV+2AgO0EH+1XJ1jNXJ8kewU= 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)(46966006)(40470700004)(36840700001)(86362001)(40460700003)(356005)(8676002)(47076005)(336012)(8936002)(54906003)(508600001)(44832011)(81166007)(426003)(186003)(36756003)(1076003)(26005)(16526019)(4326008)(83380400001)(316002)(36860700001)(6666004)(2906002)(7696005)(110136005)(2616005)(7416002)(70206006)(5660300002)(70586007)(82310400004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2022 03:10:07.1866 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 60dbe854-def3-470a-d513-08d9e1428570 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: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1531 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 857591A0012 X-Rspam-User: nil Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=2YkrTmED; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf19.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.67 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Stat-Signature: zxjkzeaqcmhj6t9ys1qap7kkc5i8gqha X-HE-Tag: 1643253009-322865 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 Reviewed-by: Alistair Popple --- 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 fb1fa7c6fa98..6f068f7c4ee3 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; } @@ -1219,10 +1251,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) @@ -1235,8 +1265,9 @@ static void dmirror_device_remove(struct dmirror_device *mdevice) mdevice->devmem_chunks[i]; memunmap_pages(&devmem->pagemap); - release_mem_region(devmem->pagemap.range.start, - range_len(&devmem->pagemap.range)); + if (devmem->pagemap.type == MEMORY_DEVICE_PRIVATE) + release_mem_region(devmem->pagemap.range.start, + range_len(&devmem->pagemap.range)); kfree(devmem); } kfree(mdevice->devmem_chunks); diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index 17f842f1aa02..625f3690d086 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -68,6 +68,7 @@ enum { enum { /* 0 is reserved to catch uninitialized type fields */ HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1, + HMM_DMIRROR_MEMORY_DEVICE_COHERENT, }; #endif /* _LIB_TEST_HMM_UAPI_H */ From patchwork Thu Jan 27 03:09:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12726206 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 A600AC433F5 for ; Thu, 27 Jan 2022 03:10:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22A8B6B0087; Wed, 26 Jan 2022 22:10:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 17F226B0088; Wed, 26 Jan 2022 22:10:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC6036B008A; Wed, 26 Jan 2022 22:10:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0126.hostedemail.com [216.40.44.126]) by kanga.kvack.org (Postfix) with ESMTP id CDA9C6B0087 for ; Wed, 26 Jan 2022 22:10:12 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8DF9489942 for ; Thu, 27 Jan 2022 03:10:12 +0000 (UTC) X-FDA: 79074588264.26.B1B3740 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2076.outbound.protection.outlook.com [40.107.244.76]) by imf03.hostedemail.com (Postfix) with ESMTP id DD63A20022 for ; Thu, 27 Jan 2022 03:10:11 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WTmoGRyG35/7tI2qQ4De1nD1Sdyot5Ix/CTXOYBwvw1rwMMQIOg4aVC1VCmIYPfQEuFovFzBr5PLxWKLOYsepHVWfLtlssQiO8XNaNAUY+FQqfst1utwyzN/ves8QIwKQCPsZz+5kG/FVKWxYZl0VsufZDuIaTSWg5p4Skl8N0PNxniyWWqFAqQ48iouzREVANSjMmVbgIRmcH0S/nOsy2ytF18hyM22ANU/br5wq6spsM5vLrh1lc920/M5meapPFNkaTpPKxkQHrA+6jLZws7Qq2HF27w+J1zjITAbI5AfWeCWejaQrwY3aM8/VaI5yHClsH/Z1c69ufAP6+nZvQ== 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=w/FnPTvbH/XxGubXq83NoubsOAL/YaboMuCOdsolRFU=; b=IbzeojASUyjC2MvzM+Empm7hVtAi1lacLqt28wugZ1aWR6oD1BhZp2yCqprIyyKvfK5iE2gI40tbS6JWWE0oReAepJfAjjkgc/d4yFkcMDOxKjTg6Lza+HL23kt7pBikU6JEXd4FcdmD4AaJNJPY/UN99vUJyZhTP72gF/UVwdL2syWJ7/SpfCX8+33Rvz0B4Vx2XVK26jc5SyczEszQjstwA0i5U+cMo27gRk0BrJ2aqo0NfA9WyK6n39gMWBiuq138tLMVLBTbddir/lBKVN9M6/HbQXXHhQQUtHVi8MoNapSFGfJ3mHwD4vPfnDeBLG1Cp9kI92bC4PhSbJ+N0A== 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=w/FnPTvbH/XxGubXq83NoubsOAL/YaboMuCOdsolRFU=; b=qZJDaO0yOi0XOSGJDU6RVnbMBSSxV3PnQ04xU8PxulTZPzaJ1xDm6vtpdk2l/124TeRa42Bbg79M32pIXr92INVEi+Z68xmr/WoMQVSEotfClC0GLkvGCSLbfRfxvFINi+8GJuqDQMKDpBRvGpv5v9BB5eH8fvjST3CDb0YVoiw= Received: from BN0PR03CA0042.namprd03.prod.outlook.com (2603:10b6:408:e7::17) by BYAPR12MB3527.namprd12.prod.outlook.com (2603:10b6:a03:13c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.13; Thu, 27 Jan 2022 03:10:08 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e7:cafe::33) by BN0PR03CA0042.outlook.office365.com (2603:10b6:408:e7::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:07 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Wed, 26 Jan 2022 21:10:04 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v4 08/10] lib: add support for device coherent type in test_hmm Date: Wed, 26 Jan 2022 21:09:47 -0600 Message-ID: <20220127030949.19396-9-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220127030949.19396-1-alex.sierra@amd.com> References: <20220127030949.19396-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 68a38074-edb5-4cf6-31b8-08d9e14285d0 X-MS-TrafficTypeDiagnostic: BYAPR12MB3527: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: EgeTifsvWxbT18sRhCooLgP8wA3ghjCHTchnQt7YFoabdpDL1h8n28mQIXy/cF0wzgzrZ3p3r1+9vN6VQ8dd7iBMOs90bOyBnKoAW5sDk+bLHaRBwqgMCSRDOJYBy4iY3F0v/D2Y97h9O9rrGNUHeQjzTYvivp3g5SIesbWLaJDMgrDlkCjdnpz8wuMw3ZUoUjgVPea+mv5UDEEGapdhHpFEvC2CmmIdT/u7TyX3AeGUowbto03ceYBzIeK/zQu4e1D7a5agdq4MdXeUyHAKd8dLdYgxJY2JnnQgtChbkY57jtktFrG/Z1yrSSKfCSSzVKZk/A8nIrXtOOcPWHZvPlJhVuZqdZWgYrTh9JUHRmtdBzA4x1awu9YbWtMBq1iHyp7Mhl1L6VfnJGO16WyblCieehfHrrWo8NyNx+UUFiXE87u3ZedYOqdsq5U+mWZem3qX7ISbEl8ttFjuQqg1pwGbRcTKl8RLE7SUMMAWErYu1lTK5ojg/Yrg9OmKEL9sk/ctA5Qt1AmmZTqbMtG/IpzHIlQF8PDsB89Os4WPiyON6wLuVs7MJSeWd+fnJwGixLs5+AhAaaRyR3mZnHnozjwUne+YpoDhrtVB7Eb6m9qXH4KrNyAXLSQ39dCgxzgNCNRYBJNcTIIJzJ0Z1+YEQRM1VqSeFoKAChx0JXSqYBAFVp8U4OEYSAxDSBPW/C4GWVE6Ox7UsyoKveuyTw3xSvs71/YGeBTUa5Rt7VbMxyU3PcDNK04AbVBru7UPRbK4XbEjHbLYewHYEt9KZH+8i5FGTTtYJNtldx6HyWUxr/4= 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)(36840700001)(46966006)(40470700004)(1076003)(86362001)(70586007)(30864003)(70206006)(5660300002)(336012)(6666004)(426003)(8936002)(8676002)(44832011)(4326008)(82310400004)(2616005)(7696005)(54906003)(508600001)(110136005)(316002)(26005)(16526019)(186003)(7416002)(83380400001)(36756003)(47076005)(81166007)(40460700003)(2906002)(356005)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2022 03:10:07.8115 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 68a38074-edb5-4cf6-31b8-08d9e14285d0 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: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3527 X-Rspamd-Queue-Id: DD63A20022 X-Rspam-User: nil Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=qZJDaO0y; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf03.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.244.76 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Stat-Signature: s78u94gyb53iceyjtuki43ozp7w57pa4 X-Rspamd-Server: rspam08 X-HE-Tag: 1643253011-401151 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 Reviewed-by: Alistair Popple --- 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 6f068f7c4ee3..850d5331e370 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)) | MIGRATE_PFN_LOCKED; if ((*src & MIGRATE_PFN_WRITE) || @@ -724,11 +760,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); @@ -808,15 +840,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)) | MIGRATE_PFN_LOCKED; + 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; @@ -853,6 +994,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); @@ -861,7 +1003,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; @@ -898,12 +1040,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 @@ -1100,8 +1252,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: @@ -1142,14 +1298,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; @@ -1157,43 +1312,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)) | MIGRATE_PFN_LOCKED; - 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; @@ -1213,7 +1336,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; @@ -1292,6 +1415,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) @@ -1314,7 +1443,8 @@ static void __exit hmm_dmirror_exit(void) int id; for (id = 0; id < DMIRROR_NDEVICES; id++) - dmirror_device_remove(dmirror_devices + id); + if (dmirror_devices[id].zone_device_type) + dmirror_device_remove(dmirror_devices + id); unregister_chrdev_region(dmirror_dev, DMIRROR_NDEVICES); } diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index 625f3690d086..e190b2ab6f19 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -33,11 +33,12 @@ struct hmm_dmirror_cmd { /* Expose the address space of the calling process through hmm device file */ #define HMM_DMIRROR_READ _IOWR('H', 0x00, struct hmm_dmirror_cmd) #define HMM_DMIRROR_WRITE _IOWR('H', 0x01, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_MIGRATE _IOWR('H', 0x02, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_SNAPSHOT _IOWR('H', 0x03, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_EXCLUSIVE _IOWR('H', 0x04, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_CHECK_EXCLUSIVE _IOWR('H', 0x05, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_GET_MEM_DEV_TYPE _IOWR('H', 0x06, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_MIGRATE_TO_DEV _IOWR('H', 0x02, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_MIGRATE_TO_SYS _IOWR('H', 0x03, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_SNAPSHOT _IOWR('H', 0x04, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_EXCLUSIVE _IOWR('H', 0x05, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_CHECK_EXCLUSIVE _IOWR('H', 0x06, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_GET_MEM_DEV_TYPE _IOWR('H', 0x07, struct hmm_dmirror_cmd) /* * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT. @@ -52,6 +53,8 @@ struct hmm_dmirror_cmd { * device the ioctl() is made * HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE: Migrated device private page on some * other device + * HMM_DMIRROR_PROT_DEV_COHERENT: Migrate device coherent page on the device + * the ioctl() is made */ enum { HMM_DMIRROR_PROT_ERROR = 0xFF, @@ -63,6 +66,8 @@ enum { HMM_DMIRROR_PROT_ZERO = 0x10, HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL = 0x20, HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE = 0x30, + HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL = 0x40, + HMM_DMIRROR_PROT_DEV_COHERENT_REMOTE = 0x50, }; enum { From patchwork Thu Jan 27 03:09:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12726207 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 54A86C4332F for ; Thu, 27 Jan 2022 03:10:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FAA16B0088; Wed, 26 Jan 2022 22:10:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 85E756B008A; Wed, 26 Jan 2022 22:10:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D5A56B008C; Wed, 26 Jan 2022 22:10:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id 4FF7F6B0088 for ; Wed, 26 Jan 2022 22:10:13 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B0CF58249980 for ; Thu, 27 Jan 2022 03:10:12 +0000 (UTC) X-FDA: 79074588264.17.C3A84D1 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2057.outbound.protection.outlook.com [40.107.94.57]) by imf09.hostedemail.com (Postfix) with ESMTP id 0FB52140010 for ; Thu, 27 Jan 2022 03:10:11 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mxh18DeCpA97r0OaOoY1mXifCRHIihcVweAAltOxm6L7Y/0tVZkqUennmK47S1Cd/KPu/PokHWfQo/7j/u4H4Mx6gZ/vK6MUjgLE6FhqwdQ8NGS6kA0qv9r+0pWjAEdMQtQnNC1n1xD2zTegKryFkyBRviTSyGgiswKcOjKT67U8B28Nz5Me0iXdaHnQ1hi6fLL8hBTYK8zKfw30mcOjJ7xF+BkoUcIwOA3ZPJ/oD1Coxmszebtmr0BWnVY6npJidHsVRg8am0ENE2XuC02nrvfpP8W/j7aUsF6x7oFNOopk+1SyMrXythPzp9U3jFvvcRHCIJkfhpIH048ZX5b1Mw== 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=TkhY73lijcfTMBsuT4SElFuMaAcJe3pUQ8P6LKwXObw=; b=G88fO+hgpYu1jTmW4nvtQr55X7Vhq80u1Dw1Gnd6vPNPFEACX59/BXE90O/uA7nHOnlJCAhYtMSnQBrlnnPqCYHUjIReaofRpSq4QODfZB+69Xe4hId2sI9QqnA4N+hir06lKKOwjcOK17VSaRm3gbsO6ytLd2vRZa2NwW+zQsXRG/bP4QcblVYynShljuCpPeEJcc0QxW+KsvqFRWVzV1wg2jNT9wz+KRcFML7OBaASivDyoCMI85gxg3fXWO56ySs6gDT5PIHY+zcLvIn0Ng8dIQ0VsuLfDnCy3Z6duSSLOOlIeCaCL1pjEEbQTXrARsNmeL6xqfuAHcrgSXSJbg== 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=TkhY73lijcfTMBsuT4SElFuMaAcJe3pUQ8P6LKwXObw=; b=qBJqEX7158baSoCTNKzrNCS2EAq3ayJitm7JppKzL/C3OzSdZp84wYpTIT+zLtY+VwHO3oGndMP7+f7S1f5n2pD75DoMPuesxjx4Wj2hF4TMmDrgWUwyyiHaaFTg1o5+jKxhR1gdY+XpVJnnaZi/vtkSnLVetldJkzMYTNwTNJI= Received: from CO2PR05CA0094.namprd05.prod.outlook.com (2603:10b6:104:1::20) by BL0PR12MB5507.namprd12.prod.outlook.com (2603:10b6:208:1c4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Thu, 27 Jan 2022 03:10:08 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:104:1:cafe::26) by CO2PR05CA0094.outlook.office365.com (2603:10b6:104:1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.5 via Frontend Transport; Thu, 27 Jan 2022 03:10:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:08 +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; Wed, 26 Jan 2022 21:10:05 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v4 09/10] tools: update hmm-test to support device coherent type Date: Wed, 26 Jan 2022 21:09:48 -0600 Message-ID: <20220127030949.19396-10-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220127030949.19396-1-alex.sierra@amd.com> References: <20220127030949.19396-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dab7330e-3347-4a62-d49e-08d9e1428600 X-MS-TrafficTypeDiagnostic: BL0PR12MB5507: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: V+ti4rhnJQ5V7AyRrEtGW8BCgqWV/yGMJNJ2wIYbo3sQWCQznY34RK0/fz3G/1vZcIno4d7t8BDkEztyvjlFZAIUsOMzT75EADO29Mas+riWbarm96iOlXNwLFuuLorwsyIGFYsFB9N96SrwIURGBup1FmKnhEocD5qWRnkxhvFrO3QxtRKFEe8QGymKbVHF/s5KPHrOncoGe35Fi4bUeh+3GaJEwrOoVmGlD9+iery51e0q+ozvQ8HgZHdwaErxjCQiJulAkddHK+GZ88163ctIouruKDzfsIXLiLA9jD9NTlrNJtJN4oV9th/1TXxga+HgQifq0x31mzz060t8KJ11mfxDNowCGkgUxqkBUH/Ot1y0RAmewKpkSl2lltbJxMoWG4oohyRR5pilFY01ELstS9be/RHEw0qwc2GarklsgMtJHOSV8G4NSyrgyKH+vKbJkocLqj4Ol7MR+6WPWCdTpDuqJ9H4PenEiukpseNqyEH+m8pnRp/MehSYD1etu/NnsyRbixHylKWWtULyFYYSs1eHEg/k1c6YxBGKjgeqsSuY1nprPHRLrXVVZHfOY54rVvSmm+fIITthONcy9ut7Z6RrjOvI8Y5btYNEZKRoqlpt92yusv5O7rFityaxHga3fwjz2Vqw/iduY6z8aQ1VNM7ILugGUV7XIInnpbTkF+V6Cqap8fQAlE1BRj8q1U0gk4Dwy/prjw7pz3Kw2A== 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)(36860700001)(1076003)(16526019)(336012)(426003)(186003)(26005)(2616005)(356005)(36756003)(70586007)(4326008)(15650500001)(44832011)(2906002)(70206006)(5660300002)(7416002)(8676002)(8936002)(54906003)(316002)(47076005)(110136005)(86362001)(7696005)(6666004)(82310400004)(40460700003)(81166007)(508600001)(83380400001)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2022 03:10:08.0053 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dab7330e-3347-4a62-d49e-08d9e1428600 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5507 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0FB52140010 X-Stat-Signature: rggw1dmc9tam1yx7rpb3y57ygeu6i8jf X-Rspam-User: nil Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=qBJqEX71; spf=pass (imf09.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.57 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1643253011-99069 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 --- 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 864f126ffd78..99de5e38dbbc 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); @@ -1312,13 +1386,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); @@ -1335,9 +1409,16 @@ TEST_F(hmm2, snapshot) ASSERT_EQ(m[2], HMM_DMIRROR_PROT_ZERO | HMM_DMIRROR_PROT_READ); ASSERT_EQ(m[3], HMM_DMIRROR_PROT_READ); ASSERT_EQ(m[4], HMM_DMIRROR_PROT_WRITE); - ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL | - HMM_DMIRROR_PROT_WRITE); - ASSERT_EQ(m[6], HMM_DMIRROR_PROT_NONE); + if (!hmm_is_coherent_type(variant->device_number0)) { + ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL | + HMM_DMIRROR_PROT_WRITE); + ASSERT_EQ(m[6], HMM_DMIRROR_PROT_NONE); + } else { + ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL | + HMM_DMIRROR_PROT_WRITE); + ASSERT_EQ(m[6], HMM_DMIRROR_PROT_DEV_COHERENT_REMOTE | + HMM_DMIRROR_PROT_WRITE); + } hmm_buffer_free(buffer); } From patchwork Thu Jan 27 03:09:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12726208 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 E66DDC43219 for ; Thu, 27 Jan 2022 03:10:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B453B6B0092; Wed, 26 Jan 2022 22:10:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AF5266B0093; Wed, 26 Jan 2022 22:10:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 920826B0095; Wed, 26 Jan 2022 22:10:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id 8025F6B0092 for ; Wed, 26 Jan 2022 22:10:16 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 40CA3181616BD for ; Thu, 27 Jan 2022 03:10:16 +0000 (UTC) X-FDA: 79074588432.07.5BC18F2 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2045.outbound.protection.outlook.com [40.107.220.45]) by imf04.hostedemail.com (Postfix) with ESMTP id B501340005 for ; Thu, 27 Jan 2022 03:10:15 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PPSf9TwVTJsoMQUEIcvmwae+DIvDBodfvn5hXRAxBzaCigaShjd7AvXTeUbub0eiDpUzlVe99RzmDmw181s4Sx1h6RDyEYsHMTAx1tFPeiF4DUNQxgeB6UIefeK9Tb9FFwq/G5Y0wefGOQQrgA8LpXEvySc5DqqTzwQHj4H0vXOz2rQRTF+R88zamF0w+p9PF57OGFN94/dl4ONQ+UYrrL58/9nSpDBUzZb9dKho7qVg+lVYjHR73VUWpZ3rSECabJsHDO389tEGkV8x41L9O+OXwU40MRPGm3YUtGoiv+trTrzW50/sFlvDmBCydjlY6it0OB06OFolki4xRV8MIA== 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=YIX1UXBqRyvCiCgfbRiu0U9c8QYlKCum6nLn8LfGaYE=; b=T+EHLhazGqMkP3X9lqBOQFJH1xgcOl/MOavKTuKej2+6V6rzTwFUSH6c+2q1SIa+FFDd4Y80IFcy//3BDVgtqM4Ia5VixhFsJQda/tgwf5IealjPjJWJyLK8A1f/BhBA7N4TliGrvLh1j6YguEIfrvC7aF/RGSsg6S+lRZepD8taXlA2HA03tlT2+1fT4gdJXBDIlynJvtkyOpOfC0DOu8SNHg61SNugb4PPD0uGMmyX2zT2E4ZW/uqWN0huuqqLFnO8GSM1v33GNJzOpMcQWHywELIh/qAIkNtuFehli0W41630D5NrvwcYVUpYa93mbPzsPTJNyBIw3zrcOsHfPQ== 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=YIX1UXBqRyvCiCgfbRiu0U9c8QYlKCum6nLn8LfGaYE=; b=TPcc+BDglcCWvHWZCYJ+gFYnr2CCpl4Z+3VhaUx7rhfkVQcdx7Zq+5um4VOEuy/luNcPKZJ+X9rtIX3SBpX7KanOH6Dg/6MGF8JtATpZMnAdT4LZKprK4urEvzRCs0xxAhneb3mES4AD2fE8YJDS+6vwCLUvTVl49NaMLQA12gc= Received: from BN6PR1101CA0001.namprd11.prod.outlook.com (2603:10b6:405:4a::11) by CH2PR12MB4822.namprd12.prod.outlook.com (2603:10b6:610:6::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Thu, 27 Jan 2022 03:10:09 +0000 Received: from BN8NAM11FT030.eop-nam11.prod.protection.outlook.com (2603:10b6:405:4a:cafe::d9) by BN6PR1101CA0001.outlook.office365.com (2603:10b6:405:4a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17 via Frontend Transport; Thu, 27 Jan 2022 03:10:09 +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 BN8NAM11FT030.mail.protection.outlook.com (10.13.177.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:08 +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; Wed, 26 Jan 2022 21:10:06 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v4 10/10] tools: update test_hmm script to support SP config Date: Wed, 26 Jan 2022 21:09:49 -0600 Message-ID: <20220127030949.19396-11-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220127030949.19396-1-alex.sierra@amd.com> References: <20220127030949.19396-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b1e4a33e-fd80-41fc-62fb-08d9e142867a X-MS-TrafficTypeDiagnostic: CH2PR12MB4822: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: CQT/EGkrbaOfjMGTx9YqBpFum0FtI/1v5vQS3S7m03z9lDudFKZR7PjXev9zHCriYl7LZUNpfcs0Id/6P19ZIQ0t7mpmCZ2M2aP/sZuCvIZVOzzwuneNE1IT1FAWleIJGpCdFlckQICPCFEL7syA/lZusOIzvB0U8jX132YC9Fesi26Z5H7zFtetbWZpepIU6wPWW3B5F8l5sQIyTGi7dMBUbj1E19rzuiG4r3CL+SP3z4/lPWoT5PYCZaWH/UaamBWlNEW0I8xeo0IE7U/YTDXZa3mWRRzrP6DEYMeeiUPe+i4omnJWgkFVIEmIesMcPLMi72czw2U0VzGbFjF7+81jUbxPBGpBMIGy8ZbbL+ICmxg8q27BVbMU3r+xH5Dcqgwazeetk6hn4JPjRISlXs+LtWmWRYEeJ8CR4W/13FvcjPOq00aYtJ2c2IRhJvqXk+5FBA8QBeBEuHjYayk/l1p0ghVm7N33xifk2VVSfu8xNaJD6MOoqmdf7BkObjWd/tU/XvEvT3rEOjambUS8vowiFQppwayBpSOTN/xJWDPUsIVZnk/0XYMwfxf1HjICoIzOtJH2qHNt4HP+T6T+9n8+RJhSpHWyT4lfsLf5DmCelSvZfsi0jVC8LsMFFZzU6JQPmjhfkTEv3xuX9EexvGoTlYkKVEI/DkxvBVuHlnHUWWLXHIh2redoYrRxyekllkMgQcOE01eeOi/QbwG7LQ== 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)(44832011)(2616005)(26005)(1076003)(426003)(336012)(186003)(5660300002)(8676002)(86362001)(47076005)(8936002)(54906003)(110136005)(316002)(508600001)(40460700003)(36756003)(16526019)(4326008)(83380400001)(82310400004)(356005)(81166007)(7696005)(6666004)(7416002)(36860700001)(2906002)(70206006)(70586007)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2022 03:10:08.9113 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b1e4a33e-fd80-41fc-62fb-08d9e142867a 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: BN8NAM11FT030.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4822 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=TPcc+BDg; spf=pass (imf04.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.220.45 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: B501340005 X-Stat-Signature: sb97y9yn1rurqc9pa6e6xxa59abo9hhy X-Rspamd-Server: rspam12 X-HE-Tag: 1643253015-159222 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, 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 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