From patchwork Wed Jun 29 03:54:13 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: 12899269 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 77A4CC433EF for ; Wed, 29 Jun 2022 03:55:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17B808E0003; Tue, 28 Jun 2022 23:55:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12A248E0002; Tue, 28 Jun 2022 23:55:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBDEA8E0003; Tue, 28 Jun 2022 23:55:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DC3008E0002 for ; Tue, 28 Jun 2022 23:55:09 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BC574204C2 for ; Wed, 29 Jun 2022 03:55:09 +0000 (UTC) X-FDA: 79629907938.21.2235E00 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2044.outbound.protection.outlook.com [40.107.102.44]) by imf20.hostedemail.com (Postfix) with ESMTP id 4A1891C000B for ; Wed, 29 Jun 2022 03:55:09 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SKOuhVNMP13J2M4EYH6C1FCYe6XvV3RBieRmuMKKrQCtik9WFRpOcnjfVhfi3MI/1VZCoP20Fpepn08/eeacr0vUpVXXYq7fbCW9uUKkw59ZYNAXOUVTs0m+TQ7mrvazIGVsNOWZskNC6+wZX3blRnFwvYIJWxl7+7eALj3Nnafn/uUM1R4Bj19L+KEbvQDXkwo7B71bZtPfg48ZqmilYCvZrsz1d5EH+VQWFitn7Byzddf258PqzBGiiSdlvvvbpeF2w6XcQEdpBQRdbhiRLGpOl9MzmHedcX5+7vDyFdvTkQR+5mCyXPbbmCreYXW9czMi6O9BTJAosvl4J17Ilw== 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=SJzmZxI7ylEoisFZmRRKonx1JB2nnvTpdQNYsE2eN2Q=; b=V0tU/4+YSSGUaJc5X6MzI+LASwldtCaX5qajf33NJnuB5EABqBFiQXeMdNEeFcwg6rqn+Q6aAPePiT2aq+GU7WLti4FBb0kNBMI/rMOyRz7pKIVP8fiSPgkohz6XjG9PN3pkdSLKFsiLOjsYeWkOeqgua3+nLWx5DBqb9a1Wm5RX2DJMORrtXaaKHC8f7uan+VdDh/zrIw8FbH9uHjC9dNujcyPt6NUr5KdW9UUPTPh+0Yl3zsJ+7WwHmwYI9TxBHa7ObPJPUK1at4hYxvn2C4yiLqsqHFMbzSnHQH4rI2TrI1BNycSPed+Kssd/aJcEODHUqMj0rQpu84KF2g8uBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SJzmZxI7ylEoisFZmRRKonx1JB2nnvTpdQNYsE2eN2Q=; b=xl8dTtyUyCRF4pyhSIffdb2n3Y10WZZMAlX4845wqP098+RJYFgPVs4M0enlPa75EFTsqkC4TPnKUOpPMtidrn/NKjLMcXahW9fQ4+WETzT46XG+Rf5p3H/sb6klPhXP2tLJOzFKbKdnEGeFg1B4yzbp8D4yItYbqYgQCGQDKis= Received: from DM6PR07CA0127.namprd07.prod.outlook.com (2603:10b6:5:330::28) by MWHPR12MB1805.namprd12.prod.outlook.com (2603:10b6:300:106::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17; Wed, 29 Jun 2022 03:55:06 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:5:330:cafe::6a) by DM6PR07CA0127.outlook.office365.com (2603:10b6:5:330::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT045.mail.protection.outlook.com (10.13.173.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:05 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 28 Jun 2022 22:55:04 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 01/14] mm: rename is_pinnable_pages to is_pinnable_longterm_pages Date: Tue, 28 Jun 2022 22:54:13 -0500 Message-ID: <20220629035426.20013-2-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: f018e977-73f1-4d1e-30ad-08da59832730 X-MS-TrafficTypeDiagnostic: MWHPR12MB1805:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X/tUujtEKGc6byh5EB20H/Ke8ACN5RAX1FuDsfiOtOkqcflQAThGNKfC43uXs4fd5MAu6iPLy299w981r3ZpWdsXce0rpGUjmDX7sARx+H6mqtyIZgYWlLK6x7VogQDRzSaY+JM9LhHmyE8XZsv3MlYtBMIpbg1A3vDjFIz1Z0IWjdrf7Q3zPYfPKjEyXmufa3P/mj/tPfozPc2Tsii3mrsNQgIvAAbfD1iKMZSUwb0XRwx917lt0JMiurqtPgpWqCBoXyt1IlVCUDHoRWbFCvL/EKj26yiReg8gm2JJgDs/ngOVAaFRAgj6GD4Zqi/EH5M+wY9cMdBqDLXx8zIYB6k/wFpRt58BZ/14UdNkTlAsx4zv8xjRXPcsVXsDoBOmafi/hQJjPE3qtOQiRCinySg8kZRqIyagcPbiFPqzH3ChkAQG1WuJe7jv+PcdVXIH910E5PDirHtnNnioIPzQZMg5d3A6ZIZKUOsCprfaAbR/k4L5cgMw+goYnECTdwlAFaScExVnvfMLOyCVNpfBARYpRLxg4OPJWXmKUU0jCHeZ28RYP/bBdQx/5VCEWt4vsokt/DCNCo4YGY6/NafQzeLtV0GOHsHizZxylydUoVhz+YNZbzfQB3cYDU3iCOjHUFV70W38XjCeOuqeZcI4fYZG4DjXV+qXrznVG1wC4IX9zjZhljuoAvfPmM4zH7hPfhNyiVZrLglgxc+Ejw/1Aj4DAni975QCxxq18eME64xXB6Zvn8cacsxEHCGpgysSrYNZSrX1kxdYkHJZvCTBTGjQU/SyQ5rR+uo9UVwARD0q/UF5nudQGLdPyhVpXj7fv0nBudhjw0QIT0Ccg6cFRg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(396003)(376002)(346002)(136003)(39860400002)(36840700001)(46966006)(40470700004)(8936002)(16526019)(40460700003)(2906002)(70206006)(478600001)(8676002)(4326008)(36756003)(316002)(82310400005)(36860700001)(82740400003)(54906003)(356005)(186003)(6916009)(70586007)(40480700001)(7696005)(5660300002)(41300700001)(2616005)(426003)(1076003)(6666004)(7416002)(83380400001)(86362001)(336012)(44832011)(26005)(47076005)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:05.8466 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f018e977-73f1-4d1e-30ad-08da59832730 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: DM6NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1805 ARC-Authentication-Results: i=2; imf20.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=xl8dTtyU; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf20.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.102.44 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474909; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SJzmZxI7ylEoisFZmRRKonx1JB2nnvTpdQNYsE2eN2Q=; b=e37PdLIi8t4bYBQ+2g49MPzKwsyZCKwzYww2YMMsIT1m9uq3LwYlC6N0kqgLnSxD46oToT enkKQZ/fPpEjzhk1xtzZR72WTOzPt53J5lPNfDaK1zkbfUHtUsjhlV/SvanFGk2qUV0tYy BzlqwDj4NrVxrV3K5pOZkvth1KtDU38= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474909; a=rsa-sha256; cv=pass; b=ylsdKkezuScQiOPFhcmr8VThFOQ/UIMgdYvShkYMwzSyTdjtcgkJY4zEEAM85sQ/NWe/7A PUpmaFFB5PnckyikZpmbQoX+zp25SNMDxRCeTvUAs7ffDn/EtGLEI840JIXU0Oc0aKIIiX IZdhN/uL5GT2QhTbEZjJHERAEj15D5U= X-Stat-Signature: img7mpu9tefu9kere8hothe6sdtuu3qh X-Rspamd-Queue-Id: 4A1891C000B Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=xl8dTtyU; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf20.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.102.44 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1656474909-377262 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: is_pinnable_page() and folio_is_pinnable() were renamed to is_longterm_pinnable_page() and folio_is_longterm_pinnable() respectively. These functions are used in the FOLL_LONGTERM flag context. Signed-off-by: Alex Sierra --- include/linux/memremap.h | 24 ++++++++++++++++++++++++ include/linux/mm.h | 24 ------------------------ mm/gup.c | 4 ++-- mm/gup_test.c | 4 ++-- mm/hugetlb.c | 2 +- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 8af304f6b504..c272bd0af3c1 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -150,6 +150,30 @@ static inline bool is_pci_p2pdma_page(const struct page *page) page->pgmap->type == MEMORY_DEVICE_PCI_P2PDMA; } +/* MIGRATE_CMA and ZONE_MOVABLE do not allow pin pages */ +#ifdef CONFIG_MIGRATION +static inline bool is_longterm_pinnable_page(struct page *page) +{ +#ifdef CONFIG_CMA + int mt = get_pageblock_migratetype(page); + + if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE) + return false; +#endif + return !(is_zone_movable_page(page) || + is_zero_pfn(page_to_pfn(page))); +} +#else +static inline bool is_longterm_pinnable_page(struct page *page) +{ + return true; +} +#endif +static inline bool folio_is_longterm_pinnable(struct folio *folio) +{ + return is_longterm_pinnable_page(&folio->page); +} + #ifdef CONFIG_ZONE_DEVICE void *memremap_pages(struct dev_pagemap *pgmap, int nid); void memunmap_pages(struct dev_pagemap *pgmap); diff --git a/include/linux/mm.h b/include/linux/mm.h index cf3d0d673f6b..bc0f201a4cff 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1590,30 +1590,6 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma, return page_maybe_dma_pinned(page); } -/* MIGRATE_CMA and ZONE_MOVABLE do not allow pin pages */ -#ifdef CONFIG_MIGRATION -static inline bool is_pinnable_page(struct page *page) -{ -#ifdef CONFIG_CMA - int mt = get_pageblock_migratetype(page); - - if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE) - return false; -#endif - return !is_zone_movable_page(page) || is_zero_pfn(page_to_pfn(page)); -} -#else -static inline bool is_pinnable_page(struct page *page) -{ - return true; -} -#endif - -static inline bool folio_is_pinnable(struct folio *folio) -{ - return is_pinnable_page(&folio->page); -} - static inline void set_page_zone(struct page *page, enum zone_type zone) { page->flags &= ~(ZONES_MASK << ZONES_PGSHIFT); diff --git a/mm/gup.c b/mm/gup.c index 551264407624..b65fe8bf5af4 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -133,7 +133,7 @@ struct folio *try_grab_folio(struct page *page, int refs, unsigned int flags) * path. */ if (unlikely((flags & FOLL_LONGTERM) && - !is_pinnable_page(page))) + !is_longterm_pinnable_page(page))) return NULL; /* @@ -1891,7 +1891,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, continue; prev_folio = folio; - if (folio_is_pinnable(folio)) + if (folio_is_longterm_pinnable(folio)) continue; /* diff --git a/mm/gup_test.c b/mm/gup_test.c index d974dec19e1c..9d705ba6737e 100644 --- a/mm/gup_test.c +++ b/mm/gup_test.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -53,7 +53,7 @@ static void verify_dma_pinned(unsigned int cmd, struct page **pages, dump_page(page, "gup_test failure"); break; } else if (cmd == PIN_LONGTERM_BENCHMARK && - WARN(!is_pinnable_page(page), + WARN(!is_longterm_pinnable_page(page), "pages[%lu] is NOT pinnable but pinned\n", i)) { dump_page(page, "gup_test failure"); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a57e1be41401..368fd33787b0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1135,7 +1135,7 @@ static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid) lockdep_assert_held(&hugetlb_lock); list_for_each_entry(page, &h->hugepage_freelists[nid], lru) { - if (pin && !is_pinnable_page(page)) + if (pin && !is_longterm_pinnable_page(page)) continue; if (PageHWPoison(page)) From patchwork Wed Jun 29 03:54:14 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: 12899268 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 E2903CCA47E for ; Wed, 29 Jun 2022 03:55:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D17D6B0071; Tue, 28 Jun 2022 23:55:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 681268E0002; Tue, 28 Jun 2022 23:55:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FB216B0072; Tue, 28 Jun 2022 23:55:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 259328E0002 for ; Tue, 28 Jun 2022 23:55:09 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E602A212CA for ; Wed, 29 Jun 2022 03:55:08 +0000 (UTC) X-FDA: 79629907896.04.4E5C2B6 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2049.outbound.protection.outlook.com [40.107.237.49]) by imf09.hostedemail.com (Postfix) with ESMTP id 73A72140030 for ; Wed, 29 Jun 2022 03:55:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mAjC96V+enF+HkfVyhngLOdCeVdfQszaDYaLVl82PEQsNSex16EvgFjENwtdC3goshvZ1Z/SqiKxwiWfxF0qiOTTgL6OY/UuD05//SwrKiJ163LSoZITKuyR3Tg/mpIPsssIzoExRY4Ow4Ueyz6KR8ThLIL9b2RUwUgXslamkNaoutXWJ6+UYEZQyePLJxF56dYjtQ2CUfWAxPYIOEiz9SEtw1PdWCE6nPyxL2jq/UnrrLJMwGcQMSCo/0yWWHrTvnjBT1naMZ5fSfD0A5v44LmeNPhBqKzpE/PJu9ZVGHPSz6mPra4Jvpe2d/iR+50yqPySlCSEBVAtJks0I7Lggw== 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=VaeO4CpO6lgNhNxmThByUtktpghZ0UDD5SZJhWAEnj8=; b=FQ4wA/BzLLkauIyM+/1Xix4AFM+C1374j9BhKOPZBOFmFhVewPvex2e6jcZjkDkPkw5Ll1owaqzZvRx4VZllX69AmMOMOFWmC6KJFu3gAxdcbcvwGpDmNYFkkh1rycrsH9E1n2DsvHqjKy17O9pRTms1t809MwCpGOk3w8ADDfYCme/NEwTCXwIi9orxYq6y45djz8X9lyqoaEgNcUbLrVdEXbaEzam1UP/y1/0DL3lh+vhCtafmRvr6KlsmFAVwz8OBr3h5wXrpb653OZFw6bT0CZM3zV50Jlw1lrHJR2MgqJvtoM0YFVTMPchh72i9BpcpFz9iUArAK3K4IjKDiQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VaeO4CpO6lgNhNxmThByUtktpghZ0UDD5SZJhWAEnj8=; b=XRsRGv43Iwc6aFrAjLHRKMD9TdJnXdvJhBhmI9dk4q1bmMz0HjD7cY942IL66nf+/0HtpPso2xAa1V0kWpC2M9aI6d65Gt+e5zGhQm+mwsRcxsEQMb54yavwA0IxM9+ITO7+ZptUzPWp6tjP2Zz+EP97bi9oE9XNsV57Fgl/VOE= Received: from DM6PR07CA0109.namprd07.prod.outlook.com (2603:10b6:5:330::17) by DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17; Wed, 29 Jun 2022 03:55:06 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:5:330:cafe::16) by DM6PR07CA0109.outlook.office365.com (2603:10b6:5:330::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17 via Frontend Transport; Wed, 29 Jun 2022 03:55: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; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT045.mail.protection.outlook.com (10.13.173.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55: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.28; Tue, 28 Jun 2022 22:55:05 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 02/14] mm: add zone device coherent type memory support Date: Tue, 28 Jun 2022 22:54:14 -0500 Message-ID: <20220629035426.20013-3-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: f87d16d4-8353-4d9c-3f62-08da59832781 X-MS-TrafficTypeDiagnostic: DM6PR12MB4388:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ePahJOOuwiAbT1nhEyww9Hk4ukCNrVcZwkTsXsckpLN5aazSxzcvZpzs8fN9wWnesO4fPfd9UlAyocVYTz3hdX9ncCG4yIkAWVQz8Q08Ge8v8gY8Zym89pIAeqYU88LQ6xtM2dUlM9KBelDgwexrGnOSG5Y4biL+cJSyxnJR0hpdrqiVH9qGkkTakSMY9NSX/JgETVcREQfyzVWluTwh29xtlg4zYSrNt+JVsknwVWFLDopjfdtuM8cZq/LDYU0h8qxsFE6FOwTi/uhuTfcAnIEnHqn2afeQNy8x2SpRByewCRBIF7CG5OkSqQExh4V86uyurKAGBYagVKVIG2PflHxDvfGrnVIPMVYziRZ6yP13zSMnZEf7eCmljUGNFA+HqRLSvYB3NrDreIvxNYs3qOQLU7T9Z5nFcJpVPsop5d3oDjbakWLpQoKxr8OFIzNMJ/MpN4c7BcdKlJQlGsH00zWAcWDwBrEoHzaObC5Brke8yKhf8RDMErRe4Rhd6msT4GCEpKIbK1TyL3r3ymctLPc0p8jo6NOW9vDAfGEx5hO68sJKKpU+7u6z8bZQRSV2y18IuTIxCtHroWN28VYS8e2EXWhzborJ9E6LnqHvpIc78gToNZGiatwIPRLWF+WvsiE3ENMkffXGdlK3nCpkY/aDeb2mFhr+aWxFOlUQhRsevRxtuAcvg3o5gA32Ei2gRQRjMq4DFFhBuoKWtpF/tyi7DGhW5p5iha9PjhNsejaRVIcUAfqYIpXmu4x1NAoNS6I/2JwVkGKrnd2LdQ0BNQ4OrNNJUUpsNF0nM/viZrL1iIEThrePIZ1uC5ZZTJVbZ6JZnWjmo/IrlHVMSlX7vw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(346002)(376002)(136003)(39860400002)(396003)(46966006)(36840700001)(40470700004)(70586007)(186003)(26005)(41300700001)(4326008)(70206006)(2616005)(16526019)(83380400001)(82310400005)(7416002)(8936002)(7696005)(47076005)(2906002)(478600001)(8676002)(86362001)(5660300002)(6666004)(6916009)(1076003)(54906003)(36860700001)(316002)(81166007)(82740400003)(426003)(36756003)(40480700001)(44832011)(356005)(40460700003)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:06.3778 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f87d16d4-8353-4d9c-3f62-08da59832781 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: DM6NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4388 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474908; a=rsa-sha256; cv=pass; b=wyfWeZCZhcK+mssdwcjVFJ9la5o42XBDOssBhv1pw6jt7/CsW/ZdO57logvaM+v8Slu6L+ uNODk5op6Zkun8G8/uwcCBO6goolzNWAWbRIyivWKZC8o/bc2z/PQ/+42GYOMxgLhocAMD FfHgNpdGEvAofMLlPZNMute5ih85BhM= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=XRsRGv43; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf09.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.49 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474908; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VaeO4CpO6lgNhNxmThByUtktpghZ0UDD5SZJhWAEnj8=; b=RCuqwZmNDbov+sNU1B/Msf+5Wlkm05Mg2JJwA22T41QuwOosE3kWYUo0l5fn9qEEbkxKHA 5IZgWDYJGvmyQV3XXU+lt3TdFI9OQpcQnW1+ZUiqAysu6ehaqnndF3J2foLWCj5lUj/mwK 2pNVecWEsKQMRMH7ju0RA0Dure8pQJo= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 73A72140030 X-Rspam-User: X-Stat-Signature: niyy5sg3k16jpm3t9dy5cd14xpci1cgo Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=XRsRGv43; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf09.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.49 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1656474908-738905 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Device memory that is cache coherent from device and CPU point of view. This is used on platforms that have an advanced system bus (like CAPI or CXL). Any page of a process can be migrated to such memory. However, no one should be allowed to pin such memory so that it can always be evicted. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Popple [hch: rebased ontop of the refcount changes, removed is_dev_private_or_coherent_page] Signed-off-by: Christoph Hellwig Acked-by: David Hildenbrand --- include/linux/memremap.h | 22 +++++++++++++++++++++- mm/memcontrol.c | 7 ++++--- mm/memory-failure.c | 8 ++++++-- mm/memremap.c | 10 ++++++++++ mm/migrate_device.c | 16 +++++++--------- mm/rmap.c | 5 +++-- 6 files changed, 51 insertions(+), 17 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index c272bd0af3c1..6fc0ced64b2d 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -41,6 +41,13 @@ struct vmem_altmap { * A more complete discussion of unaddressable memory may be found in * include/linux/hmm.h and Documentation/vm/hmm.rst. * + * MEMORY_DEVICE_COHERENT: + * Device memory that is cache coherent from device and CPU point of view. This + * is used on platforms that have an advanced system bus (like CAPI or CXL). A + * driver can hotplug the device memory using ZONE_DEVICE and with that memory + * type. Any page of a process can be migrated to such memory. However no one + * should be allowed to pin such memory so that it can always be evicted. + * * MEMORY_DEVICE_FS_DAX: * Host memory that has similar access semantics as System RAM i.e. DMA * coherent and supports page pinning. In support of coordinating page @@ -61,6 +68,7 @@ struct vmem_altmap { enum memory_type { /* 0 is reserved to catch uninitialized type fields */ MEMORY_DEVICE_PRIVATE = 1, + MEMORY_DEVICE_COHERENT, MEMORY_DEVICE_FS_DAX, MEMORY_DEVICE_GENERIC, MEMORY_DEVICE_PCI_P2PDMA, @@ -143,6 +151,17 @@ static inline bool folio_is_device_private(const struct folio *folio) return is_device_private_page(&folio->page); } +static inline bool is_device_coherent_page(const struct page *page) +{ + return is_zone_device_page(page) && + page->pgmap->type == MEMORY_DEVICE_COHERENT; +} + +static inline bool folio_is_device_coherent(const struct folio *folio) +{ + return is_device_coherent_page(&folio->page); +} + static inline bool is_pci_p2pdma_page(const struct page *page) { return IS_ENABLED(CONFIG_PCI_P2PDMA) && @@ -160,7 +179,8 @@ static inline bool is_longterm_pinnable_page(struct page *page) if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE) return false; #endif - return !(is_zone_movable_page(page) || + return !(is_device_coherent_page(page) || + is_zone_movable_page(page) || is_zero_pfn(page_to_pfn(page))); } #else diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 618c366a2f07..5d37a85c67da 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5665,8 +5665,8 @@ static int mem_cgroup_move_account(struct page *page, * 2(MC_TARGET_SWAP): if the swap entry corresponding to this pte is a * target for charge migration. if @target is not NULL, the entry is stored * in target->ent. - * 3(MC_TARGET_DEVICE): like MC_TARGET_PAGE but page is MEMORY_DEVICE_PRIVATE - * (so ZONE_DEVICE page and thus not on the lru). + * 3(MC_TARGET_DEVICE): like MC_TARGET_PAGE but page is device memory and + * thus not on the lru. * For now we such page is charge like a regular page would be as for all * intent and purposes it is just special memory taking the place of a * regular page. @@ -5704,7 +5704,8 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma, */ if (page_memcg(page) == mc.from) { ret = MC_TARGET_PAGE; - if (is_device_private_page(page)) + if (is_device_private_page(page) || + is_device_coherent_page(page)) ret = MC_TARGET_DEVICE; if (target) target->page = page; diff --git a/mm/memory-failure.c b/mm/memory-failure.c index da39ec8afca8..79f175eeb190 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1685,12 +1685,16 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, goto unlock; } - if (pgmap->type == MEMORY_DEVICE_PRIVATE) { + switch (pgmap->type) { + case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_COHERENT: /* - * TODO: Handle HMM pages which may need coordination + * TODO: Handle device pages which may need coordination * with device-side memory. */ goto unlock; + default: + break; } /* diff --git a/mm/memremap.c b/mm/memremap.c index b870a659eee6..0f8f08f8a991 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -315,6 +315,16 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid) return ERR_PTR(-EINVAL); } break; + case MEMORY_DEVICE_COHERENT: + if (!pgmap->ops->page_free) { + WARN(1, "Missing page_free method\n"); + return ERR_PTR(-EINVAL); + } + if (!pgmap->owner) { + WARN(1, "Missing owner\n"); + return ERR_PTR(-EINVAL); + } + break; case MEMORY_DEVICE_FS_DAX: if (IS_ENABLED(CONFIG_FS_DAX_LIMITED)) { WARN(1, "File system DAX not supported\n"); diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 5052093d0262..a4847ad65da3 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -518,7 +518,7 @@ EXPORT_SYMBOL(migrate_vma_setup); * handle_pte_fault() * do_anonymous_page() * to map in an anonymous zero page but the struct page will be a ZONE_DEVICE - * private page. + * private or coherent page. */ static void migrate_vma_insert_page(struct migrate_vma *migrate, unsigned long addr, @@ -594,11 +594,8 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, page_to_pfn(page)); entry = swp_entry_to_pte(swp_entry); } else { - /* - * For now we only support migrating to un-addressable device - * memory. - */ - if (is_zone_device_page(page)) { + if (is_zone_device_page(page) && + !is_device_coherent_page(page)) { pr_warn_once("Unsupported ZONE_DEVICE page type.\n"); goto abort; } @@ -701,10 +698,11 @@ void migrate_vma_pages(struct migrate_vma *migrate) mapping = page_mapping(page); - if (is_device_private_page(newpage)) { + if (is_device_private_page(newpage) || + is_device_coherent_page(newpage)) { /* - * For now only support private anonymous when migrating - * to un-addressable device memory. + * For now only support anonymous memory migrating to + * device private or coherent memory. */ if (mapping) { migrate->src[i] &= ~MIGRATE_PFN_MIGRATE; diff --git a/mm/rmap.c b/mm/rmap.c index 5bcb334cd6f2..04fac1af870b 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1957,7 +1957,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, /* Update high watermark before we lower rss */ update_hiwater_rss(mm); - if (folio_is_zone_device(folio)) { + if (folio_is_device_private(folio)) { unsigned long pfn = folio_pfn(folio); swp_entry_t entry; pte_t swp_pte; @@ -2131,7 +2131,8 @@ void try_to_migrate(struct folio *folio, enum ttu_flags flags) TTU_SYNC))) return; - if (folio_is_zone_device(folio) && !folio_is_device_private(folio)) + if (folio_is_zone_device(folio) && + (!folio_is_device_private(folio) && !folio_is_device_coherent(folio))) return; /* From patchwork Wed Jun 29 03:54:15 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: 12899270 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 8083CC43334 for ; Wed, 29 Jun 2022 03:55:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AFB38E0005; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45EAD8E0002; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D8D48E0005; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1E17A8E0002 for ; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E5BE23528F for ; Wed, 29 Jun 2022 03:55:11 +0000 (UTC) X-FDA: 79629908022.22.7114BE0 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by imf15.hostedemail.com (Postfix) with ESMTP id 83434A0023 for ; Wed, 29 Jun 2022 03:55:11 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d+37sKLM2zPm1Tpt2kZJzd4AQBevnr5B9nQYN1d2azP3cD7Iuy1hlu2u2Tfg8FWfobXzQ1pzqc7IvJRfdWU96++bcFZTpr1oRNckBHOFUCibr4yv6sVV36b58362zMDN3EPETuRrUt/6zvgCnn1MYpop39lsOHqcOvecXhKswXkYsxpTePUF8OtCpjrS0Kb+0bnwnbSaXtxNuBstRwmhKoUoH59WxcwjZzBsbq3oRkBRYIQSbOktnlfl2MD7MEICnueBCYR3UxAIl4pCGDQB+eWxIk1XrrfATdHp7KxS72vo3VY/iPhhUmgR66zWDeqUHxJPShZatt2NlWTUtOVtQQ== 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=1ro+esyoxspRcCdLcy2c3opq7pjdPJz4su/UKS3EEj8=; b=L5/dd9byXRKiABq+FxM/3bT4vVmqwsukUec6B+O6Ao4202JQD+kZUaSmb1eI96Q+ukmFvBuUP2A+58OB59eyjsFSHMgx8fTWjhhL1NToNbNWhRTpb1shV+w99NueuzQH1kuoy5dmoqagduS2VBNKa4Fvzn/QfWIshuPQfhN/X3ZIi2AZuJj0SrNHx8SGk7shmVAy5DpCz1IbYQG8Oqr34mGuyPHKSAyNLnL1OtBpHYtpw3EdV/8+Zwh2m+To5kaMDhYjrt9V/RtaATmnxhvNE/+mAB1dPHTP9E5qqGna/e3vhYRLgHJ5LRpowamXx7bPId+TobkvzZRFeCrW2XS6lA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1ro+esyoxspRcCdLcy2c3opq7pjdPJz4su/UKS3EEj8=; b=RzxQvGFt0/WA09990l1te3UIfpr6Hob+djzBt1KnvXU+B8ddagrsMEuRQE5ASUkUmhqollT9V8e//LWS5E2Pi/KVLcnbnMzPIxQjW3iJ4Fm67uSM0OdxncSaHvz6ND4KX/xQK4Nwpj5pCKxHZexG0uAKJdr31FOjU4IAaRRXbi4= Received: from DM6PR03CA0073.namprd03.prod.outlook.com (2603:10b6:5:333::6) by BN6PR12MB1140.namprd12.prod.outlook.com (2603:10b6:404:19::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16; Wed, 29 Jun 2022 03:55:08 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:333:cafe::27) by DM6PR03CA0073.outlook.office365.com (2603:10b6:5:333::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16 via Frontend Transport; Wed, 29 Jun 2022 03:55: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; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55: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.28; Tue, 28 Jun 2022 22:55:06 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 03/14] mm: handling Non-LRU pages returned by vm_normal_pages Date: Tue, 28 Jun 2022 22:54:15 -0500 Message-ID: <20220629035426.20013-4-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: e5828bf4-80f9-4764-2478-08da5983289b X-MS-TrafficTypeDiagnostic: BN6PR12MB1140:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aoCxg7DJSQpR/i8OGojddBkZwD0fqxxrxUEQ9wTvsMPlUl+4/cv1hFnrdPVrvnIK8HxdOJFzy7uP3U5arN9s2Zt315iG1OH6yOyjQS8xIZedico4JeiQuJi0jO6hfng8KFhU/ImYyN8nbsiiBA7XwQUTPb1RyXuaS0ZKQnQuSm11L/Mc5T1QPNjXEaIWgvtiAMKFgxt2uzHHln9GK5I6XLa7hh3Co9Lpv5N3E7w15PvIofHu9yWPZp5ChwIGfy9ONULiuFUj98mNiJZRJ7PsW36KsWGnEV6R5I1yWF1WF6okK39dRwkv2FGlkycqtktpdB57hURKOBcIgtxgHgbXnj1EoBHqXPYJjzEAkNC0ER6Nq1O/M/PyjGY62MqV/7FbcGu4BEYmXF8z0hMpRUYYsS04ti1LgdfByHe3e5yIcI+RjG7XiQOevEgQZJxxWyK5wqr1rEH9kzvn1NHcx18unbj1+E/DHxUgOB2SyUJFuEO9lFFOLdXdNqXfE4lytTs6+RQ9gH8DzZzq0Ez1DCB9CYr96YquwZEd+8k8MV0RfPXvwniPPpGFDjpue61R6i84eLIIZrCLVVVAFMjiP/YVsJiQ6vBIG8S0B3NelWBgONd67cCO5yiqo/6Mi0sppJgeO6aKP8P5XW7KStd7VCGMMfzpuhpqBJcqQ8rL8fHi8+tOErFrVgoNwVA2dWosNVnJClaXiJkf7PZ7JJf59/zY1ONoVuQr6oGT2MbUVez1bMDRh8XVVO3RiNL0m44SGpxe4gWf6g1REiAilParmhtMRexxtVbVLK6JndtaujKL3+mFxo/2dXytaBUVLIxVcx5fRfmBEwCDQNFhIcN3TFmUCA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(346002)(376002)(396003)(39860400002)(136003)(36840700001)(40470700004)(46966006)(6666004)(36860700001)(70206006)(2906002)(47076005)(4326008)(81166007)(36756003)(82740400003)(41300700001)(5660300002)(6916009)(40480700001)(2616005)(478600001)(86362001)(7696005)(26005)(8936002)(16526019)(83380400001)(82310400005)(44832011)(356005)(316002)(186003)(7416002)(426003)(54906003)(8676002)(70586007)(1076003)(336012)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:08.2096 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e5828bf4-80f9-4764-2478-08da5983289b 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: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1140 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474911; a=rsa-sha256; cv=pass; b=WvJshiQLgT2uZMPzPM4p/qKGYZwc6ESq+l1afBC47/uwsZjY8FS51moEXXWRxG3OU3J8w5 egwsbTJFr2yxP3yWVX3jWp5fswZdrD9Cve5ina2BqzqgkoFvZlvMzNpXCNx+05bW4bYuYN swN/qdh5A5+vVcPZCf3Setj0J2ecw5g= ARC-Authentication-Results: i=2; imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=RzxQvGFt; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf15.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.41 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474911; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1ro+esyoxspRcCdLcy2c3opq7pjdPJz4su/UKS3EEj8=; b=LA8iQEzdTT+ZLnwJYbo4fJg1ZaWgS/vorQKbfHq1C9Q2QGQPybI7aRON6S5V5iQ8uaJ2zJ dAZIJefzXFz9yws0fscTp2yQJYL66J89Jh0GK99W4wJj8BtWG8n3ajTYWuUGMGdW/FoR12 ghJ/zd2ensLBTxXEj7FC+Yej2Pd3tzg= X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=RzxQvGFt; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf15.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.41 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam02 X-Stat-Signature: hzb84wodsmof7xtjjifxmgsgcsu4crap X-Rspamd-Queue-Id: 83434A0023 X-HE-Tag: 1656474911-625596 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: With DEVICE_COHERENT, we'll soon have vm_normal_pages() return device-managed anonymous pages that are not LRU pages. Although they behave like normal pages for purposes of mapping in CPU page, and for COW. They do not support LRU lists, NUMA migration or THP. Callers to follow_page that expect LRU pages, are also checked for device zone pages due to DEVICE_COHERENT type. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling (v2) Reviewed-by: Alistair Popple (v6) Acked-by: David Hildenbrand --- fs/proc/task_mmu.c | 2 +- mm/huge_memory.c | 2 +- mm/khugepaged.c | 9 ++++++--- mm/ksm.c | 6 +++--- mm/madvise.c | 4 ++-- mm/memory.c | 9 ++++++++- mm/mempolicy.c | 2 +- mm/migrate.c | 4 ++-- mm/mlock.c | 2 +- mm/mprotect.c | 2 +- 10 files changed, 26 insertions(+), 16 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 2d04e3470d4c..2dd8c8a66924 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1792,7 +1792,7 @@ static struct page *can_gather_numa_stats(pte_t pte, struct vm_area_struct *vma, return NULL; page = vm_normal_page(vma, addr, pte); - if (!page) + if (!page || is_zone_device_page(page)) return NULL; if (PageReserved(page)) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 834f288b3769..c47e95b02244 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2910,7 +2910,7 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, if (IS_ERR(page)) continue; - if (!page) + if (!page || is_zone_device_page(page)) continue; if (!is_transparent_hugepage(page)) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 16be62d493cd..671ac7800e53 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -618,7 +618,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, goto out; } page = vm_normal_page(vma, address, pteval); - if (unlikely(!page)) { + if (unlikely(!page) || unlikely(is_zone_device_page(page))) { result = SCAN_PAGE_NULL; goto out; } @@ -1267,7 +1267,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, writable = true; page = vm_normal_page(vma, _address, pteval); - if (unlikely(!page)) { + if (unlikely(!page) || unlikely(is_zone_device_page(page))) { result = SCAN_PAGE_NULL; goto out_unmap; } @@ -1479,7 +1479,8 @@ void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr) goto abort; page = vm_normal_page(vma, addr, *pte); - + if (WARN_ON_ONCE(page && is_zone_device_page(page))) + page = NULL; /* * Note that uprobe, debugger, or MAP_PRIVATE may change the * page table, but the new page will not be a subpage of hpage. @@ -1497,6 +1498,8 @@ void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr) if (pte_none(*pte)) continue; page = vm_normal_page(vma, addr, *pte); + if (WARN_ON_ONCE(page && is_zone_device_page(page))) + goto abort; page_remove_rmap(page, vma, false); } diff --git a/mm/ksm.c b/mm/ksm.c index 54f78c9eecae..831b18a7a50b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr) cond_resched(); page = follow_page(vma, addr, FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE); - if (IS_ERR_OR_NULL(page)) + if (IS_ERR_OR_NULL(page) || is_zone_device_page(page)) break; if (PageKsm(page)) ret = handle_mm_fault(vma, addr, @@ -560,7 +560,7 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item) goto out; page = follow_page(vma, addr, FOLL_GET); - if (IS_ERR_OR_NULL(page)) + if (IS_ERR_OR_NULL(page) || is_zone_device_page(page)) goto out; if (PageAnon(page)) { flush_anon_page(vma, page, addr); @@ -2308,7 +2308,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page) if (ksm_test_exit(mm)) break; *page = follow_page(vma, ksm_scan.address, FOLL_GET); - if (IS_ERR_OR_NULL(*page)) { + if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) { ksm_scan.address += PAGE_SIZE; cond_resched(); continue; diff --git a/mm/madvise.c b/mm/madvise.c index 0316bbc6441b..e252635fe935 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -421,7 +421,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, continue; page = vm_normal_page(vma, addr, ptent); - if (!page) + if (!page || is_zone_device_page(page)) continue; /* @@ -639,7 +639,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, } page = vm_normal_page(vma, addr, ptent); - if (!page) + if (!page || is_zone_device_page(page)) continue; /* diff --git a/mm/memory.c b/mm/memory.c index 7a089145cad4..e18555af9024 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -624,6 +624,13 @@ struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, if (is_zero_pfn(pfn)) return NULL; if (pte_devmap(pte)) +/* + * NOTE: New uers of ZONE_DEVICE will not set pte_devmap() and will have + * refcounts incremented on their struct pages when they are inserted into + * PTEs, thus they are safe to return here. Legacy ZONE_DEVICE pages that set + * pte_devmap() do not have refcounts. Example of legacy ZONE_DEVICE is + * MEMORY_DEVICE_FS_DAX type in pmem or virtio_fs drivers. + */ return NULL; print_bad_pte(vma, addr, pte, NULL); @@ -4693,7 +4700,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) pte = pte_modify(old_pte, vma->vm_page_prot); page = vm_normal_page(vma, vmf->address, pte); - if (!page) + if (!page || is_zone_device_page(page)) goto out_map; /* TODO: handle PTE-mapped THP */ diff --git a/mm/mempolicy.c b/mm/mempolicy.c index d39b01fd52fe..abc26890fc95 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -523,7 +523,7 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr, if (!pte_present(*pte)) continue; page = vm_normal_page(vma, addr, *pte); - if (!page) + if (!page || is_zone_device_page(page)) continue; /* * vm_normal_page() filters out zero pages, but there might diff --git a/mm/migrate.c b/mm/migrate.c index 6c1ea61f39d8..a98a219d12ab 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1620,7 +1620,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, goto out; err = -ENOENT; - if (!page) + if (!page || is_zone_device_page(page)) goto out; err = 0; @@ -1810,7 +1810,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, if (IS_ERR(page)) goto set_status; - if (page) { + if (page && !is_zone_device_page(page)) { err = page_to_nid(page); put_page(page); } else { diff --git a/mm/mlock.c b/mm/mlock.c index 716caf851043..b14e929084cc 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -333,7 +333,7 @@ static int mlock_pte_range(pmd_t *pmd, unsigned long addr, if (!pte_present(*pte)) continue; page = vm_normal_page(vma, addr, *pte); - if (!page) + if (!page || is_zone_device_page(page)) continue; if (PageTransCompound(page)) continue; diff --git a/mm/mprotect.c b/mm/mprotect.c index ba5592655ee3..e034aae2a98b 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -95,7 +95,7 @@ static unsigned long change_pte_range(struct mmu_gather *tlb, continue; page = vm_normal_page(vma, addr, oldpte); - if (!page || PageKsm(page)) + if (!page || is_zone_device_page(page) || PageKsm(page)) continue; /* Also skip shared copy-on-write pages */ From patchwork Wed Jun 29 03:54:16 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: 12899271 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 2E383C433EF for ; Wed, 29 Jun 2022 03:55:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B42748E0006; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA3608E0002; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8092A8E0002; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5BFB98E0006 for ; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 2D93E61121 for ; Wed, 29 Jun 2022 03:55:12 +0000 (UTC) X-FDA: 79629908064.01.429CA75 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2083.outbound.protection.outlook.com [40.107.244.83]) by imf13.hostedemail.com (Postfix) with ESMTP id 654A420021 for ; Wed, 29 Jun 2022 03:55:11 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=foRori54YIgkOCtWCJNRZxciVBBQgLEOepHAZrA2JEzuAMkkk9LwJRFOTWlIStBbeUOiF20RempvtuBJvpmhI3aCPDoUh0YFhXs/LisAH710DgsIUbNtKDLoT8Q0scxohMVaMb4R5ug2GMjmdXb01xNPPzrbcoKNKnvwqbhPwwO0HzLjwCFFMwwJpwXdHH2iQgTHJ/LULCjqSs9FLILSYwUvD34EMksOfIDHZf4bkNLlIkP5JrAyChezYHIVi+T+rmF2TJQh+zCt3dGj3LKQNibiYd6XV3iWTa2omsLLd+Z/Rt6vVyn1tvO6YmNxP6qiv2EFhRkGI92EsfYYucO95Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Tsm1npeQJz5adlkprwdiF30iBrFOX7mFKo901b9QP1o=; b=O97aNftRAgmGKSf6qMxqxC9tC8yXa2Eh63vwfYkb5SKB4bxzl7IMDzOEaujpztgkuVyp/7GwLi3FreOHLhXa3v0vcZbExwJRm6TyaSnxZ7uFgk5kIEZUnX9Q8mDcH4Gu0xpJ3c6GjFDTZlkUodlBX8V4AXPxC0uH3Vz6Rk5SwyH/JZ4E1u12VpfrFTBWfSzyXf9RUFigq/IRHIhq9X9jYgAM9CkEd5uOY6SGc9zpUCRP2VWqdIDbrZ1yNEvm6j5z7XbaM5oe7mxa3JZdESVOnBOaBXQevT5nq+lEzY0uBoloVm56AVxUL4TFWdFwJKIpju5+5N50lRFBnBej1oVskQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Tsm1npeQJz5adlkprwdiF30iBrFOX7mFKo901b9QP1o=; b=PICJoyzxncOk47jyZR1rgoCf8qgUMsbZl9bqjliscdm09P2RLfS7R9wkkwMUJtCOFTH6pXtwImJlWyxy/y2rng6IEQz7V+pgJI/c2KDM5c+2WE4UOqw/5FHrIbzZEJ5Wb11QWnU+8hljHbZCZ2iNBAgOHSjRY0v3MhIzTurWAYI= Received: from DM6PR03CA0092.namprd03.prod.outlook.com (2603:10b6:5:333::25) by MW3PR12MB4442.namprd12.prod.outlook.com (2603:10b6:303:55::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17; Wed, 29 Jun 2022 03:55:09 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:333:cafe::b) by DM6PR03CA0092.outlook.office365.com (2603:10b6:5:333::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16 via Frontend Transport; Wed, 29 Jun 2022 03:55: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; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55: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.28; Tue, 28 Jun 2022 22:55:07 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 04/14] mm: add device coherent vma selection for memory migration Date: Tue, 28 Jun 2022 22:54:16 -0500 Message-ID: <20220629035426.20013-5-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: b40f0858-cdb4-4182-a7c1-08da59832901 X-MS-TrafficTypeDiagnostic: MW3PR12MB4442:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DK585iY9gEgPfYFUevAbU2Awii+SHxPI3M2mNVEMhGyo6dy0SUTi/RtPrjLLduOkb6yos7W8PWnZQ8hEmVVaI7m1tk/3evUjcOM/GwJIDl/PnZrQ+dFUQuWltQdiUlrxgHVa5C8wQ/8sxxiFd3mCYo1uQNOMWqPT8EbT+YGaaavZoAcNpu6FQan0Pz9toYF0dxRQDl09RFYzIqbLOphoQH5k0Hco28lzL+YXQT5czmleCeCyr6msEJtd7svgQPsUd483zq5FRQE31B8OnER0Oagso1MFmOzlmp4Bw5soy403AFrVmG6ODb4a7v0/IU5Dir8qaoCD1T12KJ5Z41eezGktgEYWsdcli+BQ2YitvKTujoGVBr+OU5nZNl7t0gaHWcFEIVU2Vgn4gROnaIfNdtRf0UyT5Ku4N8kHxm5KFYE0t9LqFFS8de9CwLb92ZJypxM2FVQ2yT+JmtumFV9GShRWuLYCsMU8FmIJcWdNWevLGywL/VCq0gm5ZelYztExbG5I4TUDWDVro+WiCLV39Ywpy/aeg/Hd41AtqkLJptOfig3b71gq2cbEajHQdWvZ3GcP8F5vMm+zu41KKb7ASKI+qEPRla7QsX1l1pblTf/0prz7weHtPatO/5Ta3hT4DgQ7rxqjVh/LktGX7LOutestgZ5lXkJWBxnLMxLU53s5XmvU23oNf5GcvweQizamSU8y1jPu7BzBieBDMpLSgjFkJM7lCkz8zmPBH9OzfAlyAKq7iFXwgefq6G3elW80ccxueiYjprOIQ7AXj9h5l4KNpOviAfN22AYk6SdA+wbjZgi5Jm2a5y/mmxazMhU8gbMYQ40e/4hT3rhVrqRnYw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(396003)(136003)(346002)(376002)(46966006)(36840700001)(40470700004)(4326008)(83380400001)(86362001)(36756003)(54906003)(47076005)(1076003)(6916009)(2616005)(26005)(316002)(41300700001)(5660300002)(81166007)(2906002)(16526019)(8936002)(186003)(6666004)(40480700001)(70206006)(336012)(82310400005)(40460700003)(478600001)(426003)(8676002)(44832011)(356005)(7416002)(70586007)(36860700001)(82740400003)(7696005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:08.8815 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b40f0858-cdb4-4182-a7c1-08da59832901 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: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4442 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474911; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Tsm1npeQJz5adlkprwdiF30iBrFOX7mFKo901b9QP1o=; b=sz5FFPWFNotT0EX7F1g/81lgRLNLD76zlTvZgPrjy/pegP///LSH2/+AOudCLQUQkaQkNX vo7qIJFJN9fKtKLIB4IQ1dA+LkTAG2+iA2sZfL4Yqqs4ZfZapViUA0z4cH0YxAT1Ft7xkY IccMUaXf28PtHoO2wolKBPsiHsxJtCU= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=PICJoyzx; spf=pass (imf13.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.244.83 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474911; a=rsa-sha256; cv=pass; b=z9zddCUP0dmE/5iAzBEMXOuFESVyU41niUBxoI4SJoVGHV7y/ci+aKSGsoxAPQbCpy/4U1 Qh2PvspurcFK5UDvZZHfgRV+/Te5yjkAzFODBisdvMj3IDTqnGBjJ5WqsSmf9h9AKeuFbn vkI9stL4AhtHispyTwL0QzcbeULPE1o= Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=PICJoyzx; spf=pass (imf13.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.244.83 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: 97aypzrqo4nkaakzyaed4njwe8a875dc X-Rspamd-Queue-Id: 654A420021 X-HE-Tag: 1656474911-42093 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This case is used to migrate pages from device memory, back to system memory. Device coherent type memory is cache coherent from device and CPU point of view. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Poppple Signed-off-by: Christoph Hellwig Reviewed-by: David Hildenbrand --- include/linux/migrate.h | 1 + mm/migrate_device.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 069a89e847f3..b84908debe5c 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -148,6 +148,7 @@ static inline unsigned long migrate_pfn(unsigned long pfn) enum migrate_vma_direction { MIGRATE_VMA_SELECT_SYSTEM = 1 << 0, MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1, + MIGRATE_VMA_SELECT_DEVICE_COHERENT = 1 << 2, }; struct migrate_vma { diff --git a/mm/migrate_device.c b/mm/migrate_device.c index a4847ad65da3..18bc6483f63a 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -148,15 +148,21 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, if (is_writable_device_private_entry(entry)) mpfn |= MIGRATE_PFN_WRITE; } else { - if (!(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) - goto next; pfn = pte_pfn(pte); - if (is_zero_pfn(pfn)) { + if (is_zero_pfn(pfn) && + (migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) { mpfn = MIGRATE_PFN_MIGRATE; migrate->cpages++; goto next; } page = vm_normal_page(migrate->vma, addr, pte); + if (page && !is_zone_device_page(page) && + !(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) + goto next; + else if (page && is_device_coherent_page(page) && + (!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_COHERENT) || + page->pgmap->owner != migrate->pgmap_owner)) + goto next; mpfn = migrate_pfn(pfn) | MIGRATE_PFN_MIGRATE; mpfn |= pte_write(pte) ? MIGRATE_PFN_WRITE : 0; } From patchwork Wed Jun 29 03:54:17 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: 12899272 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 DF9A4CCA47C for ; Wed, 29 Jun 2022 03:55:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E77208E0002; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D40968E0008; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2AAA8E0007; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8B34E8E0006 for ; Tue, 28 Jun 2022 23:55:12 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 66A2680BB6 for ; Wed, 29 Jun 2022 03:55:12 +0000 (UTC) X-FDA: 79629908064.04.336C8A8 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2060.outbound.protection.outlook.com [40.107.96.60]) by imf30.hostedemail.com (Postfix) with ESMTP id D530E80018 for ; Wed, 29 Jun 2022 03:55:11 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=efbuwCPcfwdQmjRQd8b9UCEDuLMIuDyqFk/DF0O9bOqblxapL/pi5QDZpqqb9QL5EL+OV8N/xEcuo13/Dt/7mzHULvcBZalmFn21ziBsHqlR5S9E0RxgeMyD7TNTXCo9MlfEKxwQ6LUHIJHUvXe2OAyle3msXSNH0E5akaw7fdqTx7ikIr+7ER8xYaOaJ/prRPZ6W+chtEo6zIx8YlvOkH6soG3/cZ16gfyHAgw2aodQlPDYFSSi37gkkw466QO0quJ1KCyHVhsmKJIxr2ETS8Ll4Ahh2bBdN/YzBRY5QlxD03x4Wa60n42jUhd0UQ+Lpefe7GpHUvgtiPSksoziuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4EJHkZDbAdLVpEXXE+RGiJTJBXEdpU2pe/Diqmm86p8=; b=Iu93LlBpCFG1vuWLQhShdjBUwClsLXj63eUyNdyLZwNJ+5+14n6ikNiPgqhnrsQDDFJY8bmY/LL0Epn3uqiuiwN1sv+5cKalztVGLX0jmAGea+qQKO/xWO8WdwA9ilpGimhVkOVTVyd2IDIiISN+tKe6lizK+OuiPj8yamrn8r74SdqvAyIoB7899u6kcamGpHSq2bV4ZnBsTtIGZW0//XJWZARs6gaqnvSJBS07AhNXIfmaC4hlSMdmhj8ux0jkF8i6pZ2oUFGZSEoYcMp8+8nz3J9n0CCuIfNCfhsBjPib/dohpMHQU6fjiiYcdWti03vYdo+VkJfr16hR8NJD/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4EJHkZDbAdLVpEXXE+RGiJTJBXEdpU2pe/Diqmm86p8=; b=p+ZcJkweyTYWzKljk+bZVFaLopAo6NTsDs0hbQfDagK5uYlVw37OlS/LSV8PncqYCZDLH7FiM8hFJHb6nxN5Eb0OLshwEWymJKJsXtN8FNTWscbDQ8GZmZAwRsYVdfJMNstLt00E2N/OG+8F2fZj0sOcl3P4W4EyzYHBi4Bhcbg= Received: from DM6PR03CA0099.namprd03.prod.outlook.com (2603:10b6:5:333::32) by BY5PR12MB4178.namprd12.prod.outlook.com (2603:10b6:a03:20e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15; Wed, 29 Jun 2022 03:55:09 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:333:cafe::87) by DM6PR03CA0099.outlook.office365.com (2603:10b6:5:333::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55: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; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:09 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 28 Jun 2022 22:55:07 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 05/14] mm: remove the vma check in migrate_vma_setup() Date: Tue, 28 Jun 2022 22:54:17 -0500 Message-ID: <20220629035426.20013-6-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: c1fba34d-f4df-4711-cabd-08da59832946 X-MS-TrafficTypeDiagnostic: BY5PR12MB4178:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CACcp/ae7F6Mw2HAT7MD4ge9CEu3ui74pWlKkUylt5MkfahXzACuZlwsjwdas+v/VRMwtRaN4zbGeUrCAcEUoFREsyD7z84Ncy7yUE6qpJ+u+o+TrHkXXpKcqXTo6fBgrFOVTInaI+Vf6+BfnwU3h5S2WG9IBad6guZ8A8UymrU4kc6wFg90qwDBGWWvvE/OKRgSd/OFtqKxhmGCeE+qjbzRKT9XCV5AA37JEJ5tlrzI7Gg2vw1MNqkV1gwu8PfyLBQCA3RdNft9V1gbcY82gdyCqEnsRjpSpKD6DIcEPXxmhRjBUg7y2VJIAECHXH3Z1GorlX4Lweur6xAMFjrhgSHhf7vsCZWH3Mscw98Bv5bQULHinEstoFGqaCAP8XOOVfpeSa8kfvjRL0GQIeN2Z0jfcZoHEzQWKMesNRJo1qDQxUbzz6dHflC0IZsMMuDTCYLPrUTdGHD3EJK0JD7yA1nppt6snai/NQkwzFtIOV5AfB59we6OJ6vq7Glt4GTPyCLoxnlwEBUUOkI2koMZatHLedCewfQNYIAgsNLZ+bxbl5ftfPsWd1FUJ3xJFr2EgeJC4AMOJrWJBEa9xdIO49M68SEnqQaUOdYyXiR0Ig3qAaU85M0Ke4KG1l+kyw9Kaz64k+xWj20wIv7ttoMnUqJfLMpSzHXniknfsXjZEyFvlQHGBVVumRPy0yj1G6NAXrbR0KTHN3OGGx+3wJ9tWpN9kq7gBOU9XmQgd7iIu1KFgdO2V+mLlc0hldOJsymvBSpeeNHPRPtRgi5Q8K3038rU9DhJk5Tllz0pty237kfinMKRGvy3db1PFtpyuyfjyPJVT8PFolAuvEdEkBVh4TSpvYEWsuUH/Ok3dL4RvfixkCff4O/lpca6hFy3hd1P X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(346002)(136003)(376002)(396003)(46966006)(36840700001)(40470700004)(54906003)(4326008)(478600001)(6916009)(82740400003)(36756003)(2616005)(5660300002)(86362001)(70206006)(316002)(356005)(1076003)(36860700001)(8676002)(2906002)(426003)(336012)(82310400005)(47076005)(186003)(70586007)(26005)(41300700001)(83380400001)(40480700001)(40460700003)(6666004)(8936002)(7696005)(81166007)(7416002)(16526019)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:09.3502 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c1fba34d-f4df-4711-cabd-08da59832946 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: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4178 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474912; a=rsa-sha256; cv=pass; b=J5FoYPFeZJEuiMQt7fU0ijpg4vcwVy0gK+bgATefQIAdaq4ui/HZzvaRKh8yfFESD8Uj8f 5dVJiQ3xqTrYhFs0TGpQbOgMXO7uW/GTsDc7P1FAyiVGRBCfjh5tY8aG9OMXREQc6Z1sCq vRTGEIEGT1gpVML97/yresbhUTT710E= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=p+ZcJkwe; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf30.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.96.60 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474912; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4EJHkZDbAdLVpEXXE+RGiJTJBXEdpU2pe/Diqmm86p8=; b=fsu3EGJLSlYTDqqBino7oKvYFGFqx9TOvKlYkpbxrXOf1A0oibRmNyz7YGnsH/l6ZTo+A/ MgDiEspI4hbxmLQ/PwXyPTCiO1TcMXSR7hWGZWskERDsxqqvwX9vtrY2exc6y1uxF1J34V SAjNP6W2Nq+GBNbPT0Rv2YRjlnzw+1E= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D530E80018 X-Rspam-User: X-Stat-Signature: oe6choq8hs96f573ipn7dxhbykqt4cpu Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=p+ZcJkwe; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf30.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.96.60 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1656474911-559949 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Alistair Popple migrate_vma_setup() checks that a valid vma is passed so that the page tables can be walked to find the pfns associated with a given address range. However in some cases the pfns are already known, such as when migrating device coherent pages during pin_user_pages() meaning a valid vma isn't required. Signed-off-by: Alistair Popple Acked-by: Felix Kuehling Signed-off-by: Christoph Hellwig --- mm/migrate_device.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 18bc6483f63a..cf9668376c5a 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -486,24 +486,24 @@ int migrate_vma_setup(struct migrate_vma *args) args->start &= PAGE_MASK; args->end &= PAGE_MASK; - if (!args->vma || is_vm_hugetlb_page(args->vma) || - (args->vma->vm_flags & VM_SPECIAL) || vma_is_dax(args->vma)) - return -EINVAL; - if (nr_pages <= 0) - return -EINVAL; - if (args->start < args->vma->vm_start || - args->start >= args->vma->vm_end) - return -EINVAL; - if (args->end <= args->vma->vm_start || args->end > args->vma->vm_end) - return -EINVAL; if (!args->src || !args->dst) return -EINVAL; - - memset(args->src, 0, sizeof(*args->src) * nr_pages); - args->cpages = 0; - args->npages = 0; - - migrate_vma_collect(args); + if (args->vma) { + if (is_vm_hugetlb_page(args->vma) || + (args->vma->vm_flags & VM_SPECIAL) || vma_is_dax(args->vma)) + return -EINVAL; + if (args->start < args->vma->vm_start || + args->start >= args->vma->vm_end) + return -EINVAL; + if (args->end <= args->vma->vm_start || + args->end > args->vma->vm_end) + return -EINVAL; + memset(args->src, 0, sizeof(*args->src) * nr_pages); + args->cpages = 0; + args->npages = 0; + + migrate_vma_collect(args); + } if (args->cpages) migrate_vma_unmap(args); @@ -685,7 +685,7 @@ void migrate_vma_pages(struct migrate_vma *migrate) continue; } - if (!page) { + if (!page && migrate->vma) { if (!(migrate->src[i] & MIGRATE_PFN_MIGRATE)) continue; if (!notified) { From patchwork Wed Jun 29 03:54:18 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: 12899273 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 954B2C43334 for ; Wed, 29 Jun 2022 03:55:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 327F18E0008; Tue, 28 Jun 2022 23:55:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 28CF58E0007; Tue, 28 Jun 2022 23:55:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 019C08E0008; Tue, 28 Jun 2022 23:55:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D946D8E0007 for ; Tue, 28 Jun 2022 23:55:13 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 96AC5212C7 for ; Wed, 29 Jun 2022 03:55:13 +0000 (UTC) X-FDA: 79629908106.13.BD2D9B6 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2079.outbound.protection.outlook.com [40.107.94.79]) by imf14.hostedemail.com (Postfix) with ESMTP id 12208100005 for ; Wed, 29 Jun 2022 03:55:12 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z0iTNk+I6DwitDyJwv4HgD1wZLRhWsJ99Nyc6/mXjNRB/9Hz9/vbWh+/WFvZ9efopRCoAxT4r4DnOLkJFxfP/6q/tl3HZWm3+Jn6TEw43MPhjNnBkrWMp1u7iKgCExl5sD04VMkNLaBv03PANR8DHp823ojCpAK0eQwyR9xFfVbLQsoV7YLYBqxpMuiJM0rpKl9PyjCzH6v6FpEER6YHalYgVys65ex3gOdu5Z3o8zwQ3CpUA0Cjy69NYcrh/YMHQ9bW4DiOhPFWhL8NtYx8UCPyc6r9tErQwfyeMGF2wROwlt1//29XuBF9jQhTu4rjWKuIOm2QFkHJ2D/yAcEWQQ== 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=5uveC3Yahq2PnoZz8eRTi7g7J4sj8d2pR1muDTcZcOQ=; b=O+Y0m6hLufziSSTtKCmx5sfryBt/GCYY1E4CChANr/TKT76SH4WzKwEt74t8fUWpLLhhRDgFepv1UfhualZqg+zjKChhX1A6iajTp0O77IyyluZ0y4wzW8c52XOnVKHaVl5odEEYbJaO470fEEGH6TH4hG70Fk7tCFEEBuR0A9xMLzU0K43sP6LpBJttMyCMLxngu7tHUD5lwlvnsUDr9vGb712sMXx7mluW7mJdIgUsRnJZHs3j6Jq4N36OC19ADE/wkCnCuL2A9QYFWSzjLwoKAZIZ5jNy+0VnU3SrjolvuK7nhapftVk4Hvu+4zpcXB0GDjzdv66HHXI5P0SCgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5uveC3Yahq2PnoZz8eRTi7g7J4sj8d2pR1muDTcZcOQ=; b=MUvEdX809qJemRr+W3VYNGyBZ4ZwNQBXHDakm08vnnxWfmk7pM5TS0/u6/hjRHaBfo1p47jZMXkCDH9634JjoOTI2yvFT4WYembirb7Lm+27wAA7t1ZGiZqjnoGsaL4ZkUUi464vZXX9Ooe5GTbKOexJMQiJ/0P7zKvFKxsVvKE= Received: from DM6PR03CA0084.namprd03.prod.outlook.com (2603:10b6:5:333::17) by BN8PR12MB2946.namprd12.prod.outlook.com (2603:10b6:408:9d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.19; Wed, 29 Jun 2022 03:55:10 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:333:cafe::ec) by DM6PR03CA0084.outlook.office365.com (2603:10b6:5:333::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16 via Frontend Transport; Wed, 29 Jun 2022 03:55:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:10 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 28 Jun 2022 22:55:08 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 06/14] mm/gup: migrate device coherent pages when pinning instead of failing Date: Tue, 28 Jun 2022 22:54:18 -0500 Message-ID: <20220629035426.20013-7-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: f07dafb2-79b6-4c6e-9a23-08da598329da X-MS-TrafficTypeDiagnostic: BN8PR12MB2946:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D9jZsm/LlKBvPkuQ30Fl+peMn8bo5SgRobkiHcgDgLcZrivNeq7KFVJWBLl35hv1gJIsPXnYdAtmt+9u6klPQJCbMxl7SwzaKjXSOF8rjm/B5mWhtSf2m2W4yFFfMmke61yJILcTZ07iPyNDKgiML2aAeGrn/TWB8QwPgKcp9TIM6jXkxKbLJU8NgSbr1Rf3HlWBGRxWbc8p2OyHNqGqNePKGUbgXAPjVCWTELxZ8QcXcA7e1gKZCCZ89a1iSpcDVpapyTYRlmzGpPqvxm0an1/ukGO+Yy5nGbfzrBXV2YcooEwo/b4Fn2Kb7lDR0DC1BaFzAA9IjFSYFFLXDAbev+BOvX2dvECLbJNMf4KUi3/57P+SFwejs3b42THZUb8D5aXcoUaWmMelrl9sZ3wL8go/Gxy2LIDuzJRbQwYUQUkBjzON6hBva6LyJuBa/eOraXg+ZFh3whEwhkiPy0h/kD4uLPmC6AXYNcjpBkJVgrQZ2YcVyVm5TOAHNmP6/FEC5+zGc5xEvY63BKN9pNOrd29IZtpCS2cBaa+S1+GHE2tNMnmO4Aqg78vc0Q267FzQVFrQm94YmKA9VzTQDUGaJu+5zsVv9hn8GobwOtQjaltpBNhwy5YdtkigG9zytGSmmTMxiKwNT3I7JVlCUK5XHvna4iycwph6/Fs5xrH4H+o48Ddofsror+DINNUBpBRUJzdSfQ3o9jbFdZAgtYtcDjdFu5CrgB/nx+aat3NY0WCDBBwMeaZe4WzZzu99A7MX1B0SbKGkbKS7bL7brJm5W0drA7rbyQIWbiGoP8EC3ZKj3M8hIbk7rLNUJLcZPX1V3XO3u+nGQ5bgQ6olaqwe4w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(136003)(396003)(346002)(39860400002)(376002)(40470700004)(46966006)(36840700001)(36756003)(47076005)(6916009)(478600001)(6666004)(5660300002)(36860700001)(82740400003)(7696005)(1076003)(2616005)(16526019)(70206006)(4326008)(41300700001)(8936002)(83380400001)(336012)(70586007)(81166007)(86362001)(54906003)(8676002)(26005)(316002)(44832011)(40460700003)(186003)(82310400005)(7416002)(2906002)(426003)(356005)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:10.3189 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f07dafb2-79b6-4c6e-9a23-08da598329da 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: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB2946 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474913; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5uveC3Yahq2PnoZz8eRTi7g7J4sj8d2pR1muDTcZcOQ=; b=knH7rAp2ucHaULO42XyIK2PMpt1YlvPmoapfEsl26PhpgQ6RGWMu2vXP0SxmPlpzSv+XBe VpydRP9ifjYxj6y6Ex1HYrPUkWKhjnU6uCwBxl0Un7fM7PMXXMG3RbOt1NbyTwBEIBJf3f EOstn26B+96clFVO/FdxrxYWwJur6+M= ARC-Authentication-Results: i=2; imf14.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=MUvEdX80; spf=pass (imf14.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.79 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474913; a=rsa-sha256; cv=pass; b=g9Wv0SgckTl4ySl9xPVQ6pSEEhh50/Ty6rZLMNspoWvPqJSyGN6w5q4u3Uz0wVmOLamsrz 2JPQvxq7f9FVhQPRiQ8Z0weC5AkhuzQN1xI1dPnsF9MJBS4ecFmeaK51qWLwTBWI6J8xH/ m+3+qT4Q7/heblmBiGYDOouibkqkOJ8= Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=MUvEdX80; spf=pass (imf14.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.79 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: tgmcice8o59fk6uo4xx4jcw8og3a3dgs X-Rspamd-Queue-Id: 12208100005 X-HE-Tag: 1656474912-866074 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Alistair Popple Currently any attempts to pin a device coherent page will fail. This is because device coherent pages need to be managed by a device driver, and pinning them would prevent a driver from migrating them off the device. However this is no reason to fail pinning of these pages. These are coherent and accessible from the CPU so can be migrated just like pinning ZONE_MOVABLE pages. So instead of failing all attempts to pin them first try migrating them out of ZONE_DEVICE. Signed-off-by: Alistair Popple Acked-by: Felix Kuehling [hch: rebased to the split device memory checks, moved migrate_device_page to migrate_device.c] Signed-off-by: Christoph Hellwig --- mm/gup.c | 47 +++++++++++++++++++++++++++++++++++----- mm/internal.h | 1 + mm/migrate_device.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 5 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index b65fe8bf5af4..9b6b9923d22d 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1891,9 +1891,43 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, continue; prev_folio = folio; - if (folio_is_longterm_pinnable(folio)) + /* + * Device private pages will get faulted in during gup so it + * shouldn't be possible to see one here. + */ + if (WARN_ON_ONCE(folio_is_device_private(folio))) { + ret = -EFAULT; + goto unpin_pages; + } + + /* + * Device coherent pages are managed by a driver and should not + * be pinned indefinitely as it prevents the driver moving the + * page. So when trying to pin with FOLL_LONGTERM instead try + * to migrate the page out of device memory. + */ + if (folio_is_device_coherent(folio)) { + WARN_ON_ONCE(PageCompound(&folio->page)); + + /* + * Migration will fail if the page is pinned, so convert + * the pin on the source page to a normal reference. + */ + if (gup_flags & FOLL_PIN) { + get_page(&folio->page); + unpin_user_page(&folio->page); + } + + pages[i] = migrate_device_page(&folio->page, gup_flags); + if (!pages[i]) { + ret = -EBUSY; + goto unpin_pages; + } continue; + } + if (folio_is_longterm_pinnable(folio)) + continue; /* * Try to move out any movable page before pinning the range. */ @@ -1929,10 +1963,13 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, return nr_pages; unpin_pages: - if (gup_flags & FOLL_PIN) { - unpin_user_pages(pages, nr_pages); - } else { - for (i = 0; i < nr_pages; i++) + for (i = 0; i < nr_pages; i++) { + if (!pages[i]) + continue; + + if (gup_flags & FOLL_PIN) + unpin_user_page(pages[i]); + else put_page(pages[i]); } diff --git a/mm/internal.h b/mm/internal.h index c0f8fbe0445b..eeab4ee7a4a3 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -853,6 +853,7 @@ int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, unsigned long addr, int page_nid, int *flags); void free_zone_device_page(struct page *page); +struct page *migrate_device_page(struct page *page, unsigned int gup_flags); /* * mm/gup.c diff --git a/mm/migrate_device.c b/mm/migrate_device.c index cf9668376c5a..5decd26dd551 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -794,3 +794,56 @@ void migrate_vma_finalize(struct migrate_vma *migrate) } } EXPORT_SYMBOL(migrate_vma_finalize); + +/* + * Migrate a device coherent page back to normal memory. The caller should have + * a reference on page which will be copied to the new page if migration is + * successful or dropped on failure. + */ +struct page *migrate_device_page(struct page *page, unsigned int gup_flags) +{ + unsigned long src_pfn, dst_pfn = 0; + struct migrate_vma args; + struct page *dpage; + + lock_page(page); + src_pfn = migrate_pfn(page_to_pfn(page)) | MIGRATE_PFN_MIGRATE; + args.src = &src_pfn; + args.dst = &dst_pfn; + args.cpages = 1; + args.npages = 1; + args.vma = NULL; + migrate_vma_setup(&args); + if (!(src_pfn & MIGRATE_PFN_MIGRATE)) + return NULL; + + dpage = alloc_pages(GFP_USER | __GFP_NOWARN, 0); + + /* + * get/pin the new page now so we don't have to retry gup after + * migrating. We already have a reference so this should never fail. + */ + if (dpage && WARN_ON_ONCE(!try_grab_page(dpage, gup_flags))) { + __free_pages(dpage, 0); + dpage = NULL; + } + + if (dpage) { + lock_page(dpage); + dst_pfn = migrate_pfn(page_to_pfn(dpage)); + } + + migrate_vma_pages(&args); + if (src_pfn & MIGRATE_PFN_MIGRATE) + copy_highpage(dpage, page); + migrate_vma_finalize(&args); + if (dpage && !(src_pfn & MIGRATE_PFN_MIGRATE)) { + if (gup_flags & FOLL_PIN) + unpin_user_page(dpage); + else + put_page(dpage); + dpage = NULL; + } + + return dpage; +} From patchwork Wed Jun 29 03:54:19 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: 12899274 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 64399CCA47C for ; Wed, 29 Jun 2022 03:55:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 684328E0009; Tue, 28 Jun 2022 23:55:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60E9F8E0007; Tue, 28 Jun 2022 23:55:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C3228E0009; Tue, 28 Jun 2022 23:55:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1B4C68E0007 for ; Tue, 28 Jun 2022 23:55:15 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E924F353BE for ; Wed, 29 Jun 2022 03:55:14 +0000 (UTC) X-FDA: 79629908148.06.7E5AB91 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2058.outbound.protection.outlook.com [40.107.94.58]) by imf04.hostedemail.com (Postfix) with ESMTP id 62EA740027 for ; Wed, 29 Jun 2022 03:55:14 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dNbitqI5XsaG/zovofVFpmEvHGLmPszkLKmSQiPvXOzH4Ckh5GULKp6uH2XCkNez+VEjtDFPyyiG8Ujia+H0Lkz+ASdRHHCbXrv4Lto7UK1Y89M209nXzwwB4tXrMrqXTPzhOqBx32Kw6Xr9+KqWFq2e9KlA28JK73Gi7OBRyn2y8+l5m6XCC+Reg/iU0cEvpP0kvRhDG9ar8K/ykWI9SCDGYaoAlBFvUlJOj5s93723CYXbq+SYli3eD128Wa1Aqk+7O83jBTsNR4py6r3sOuG+GP9IBO6EkdGo4DRcEqf9cWFiz9pY1/At1HtkyDJYdsZHfYb5Q8DZSTkpB6jYUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HCXWiNEvF3TUrQgA6hemuT7kHRIWD5ROdsIgulORq7M=; b=MV7jWq1EmDENyC3IHRW1h8gVGLBUvSrvIH4qrDGTW0t+u/xjA7Jit1RoNEd87kq7emLxYnV5T3ottLsd589ZuBYHEuOihQakm+Z+GcxdQF/bFjrRbfYOAsdl9rLQgsOsoCXUNWCNzABUxB9/1+P7PSIWO/yJPuR4GaD36XwkbblVoqZjjRGYjLGW6jw1jdzP+T0YIhE50NcRNW5ZbGr1V6Ixk/LKL4EEBICRHhi5iGY2oulGg1Cgd9L4JjaQotQgmyWwVNIF/bsxT+KInViI47y6aUR2YD7YbqsGRNnEFyURDik9ID43MBW5gRWunsEYDfl0r/BsIJ7iNt9RxIvDPw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HCXWiNEvF3TUrQgA6hemuT7kHRIWD5ROdsIgulORq7M=; b=NGW5Z8sbTXRaugIiswjrQyuG8IfZf8NRnrVRDn1zWSXTaZVf32HogBnRF3ISeRe6YIOVN0jUEcLYWw+y3h6aSiXQWrdMa8GKoAAFN0yHM+vBTnJrYXogMrKxnxr8K5tqQTSjIt0YN9D5h8pa0GXwcu4UyYcltQLdjetpyhsPAD4= Received: from DM6PR03CA0086.namprd03.prod.outlook.com (2603:10b6:5:333::19) by BYAPR12MB3334.namprd12.prod.outlook.com (2603:10b6:a03:df::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.18; Wed, 29 Jun 2022 03:55:11 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:333:cafe::9d) by DM6PR03CA0086.outlook.office365.com (2603:10b6:5:333::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:11 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 28 Jun 2022 22:55:09 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 07/14] drm/amdkfd: add SPM support for SVM Date: Tue, 28 Jun 2022 22:54:19 -0500 Message-ID: <20220629035426.20013-8-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: 9dae6057-6547-408a-f440-08da59832a58 X-MS-TrafficTypeDiagnostic: BYAPR12MB3334:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lFvNe7zou+EEyBCAbwXLt1N+FODR35tJP5D9GdOECbzE6ohDL/ctj+IWvqXcyCUE7QqGuXDqZX+wA5eiN/IM3Ig8KqoVkNJjM1aiPNYN3qXiEkcTrcJVlVYIb8rwPrGBZpJFRyU03oUjmYUBmaK4Ucu6cO/QGK+9EyeesMJan3cVDGzyFex0qtxiaFEyBrWHMaxQZhzIlqAXbfBF2LYqTp4OogVNNPvQDaFh9uYn/3r+nQE4QNmdDcHkT5raUk69JEOCR9CSs/wiNYDi9/CBNhOuWks8VyOzZNN5t6Pc+II4//fDvkaSE8KhkreJqYZU2B0ojJj9uCFw54nAAELvMqurp3vaCcKSLhlJonEfQH30lBRzTmmoBL3vBNxZ5x90z6++iScXEZILgFM6pjOi2LgHjyTidZOFRGA0pGYiQ476bTihmulJcmEEcNMirtJxz07LEPDHChfaF6wUyVcqH01mDqdL76UKw2vMl4tkraOZLzr/1XnYSPbSVCQY7ZjIF1YrFon66LP+BZgECU8jMfm1X1I9FqzuWyxlszvX9f1oh4KFhS3X2m7zkDueQ1K2aCJW+b14k9d3cfQ4xLjB0EwZhKeGU8OSjsDG0gM1pYgC7/fC6kVG/YbRKB1ABzJBgtthfFGBKQE2mqAfzlHxxXYIkg9jDyq0XxD7O0JEN3Yyw71uM8+SanDr0sTv7ZSAQE8957ylGjYVEUy+SZlSOYndGJzIG9fSu0mO0yctrQODIWSqEzuGn1ds82Iko5RSsyXyMU8R1sJj6bTkkqOfJfzwiFYRxhSTsck6sdwNkQXf9Mnsj6M33bmGAoT9FVZN84I9g8idGFfToGacPYY/YA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(396003)(39860400002)(136003)(376002)(346002)(40470700004)(46966006)(36840700001)(6916009)(70586007)(70206006)(336012)(26005)(16526019)(41300700001)(86362001)(8676002)(316002)(7696005)(478600001)(54906003)(47076005)(83380400001)(36860700001)(426003)(6666004)(81166007)(82740400003)(356005)(1076003)(2616005)(4326008)(186003)(7416002)(5660300002)(36756003)(44832011)(2906002)(40460700003)(8936002)(82310400005)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:11.1469 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9dae6057-6547-408a-f440-08da59832a58 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: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3334 ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=NGW5Z8sb; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf04.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.58 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HCXWiNEvF3TUrQgA6hemuT7kHRIWD5ROdsIgulORq7M=; b=pVbupJeZX5xDn8rs+21FYn+Z8cVGjRxB6XsO/DvR0xjeBPGYsQ0o8spGyHpfCUDvmcKQvO L/VjOQdkoD1CWrXirTNO9FIKfZaZ4Sx7MoaGmnXdeSTBiusG1r4tJCyiHIDhnV3hxif6RB Iw3Qyf5VovqOkD7X5QXNkxgZBYJj7PQ= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474914; a=rsa-sha256; cv=pass; b=NrUY6iEVWHVKewCOrhg1tTtL2lS/wuZks07ou4J/4t22ggjTzHm5+2AwsAFeUmhU75aRhW WR9YqDnBtuRxUWNp5GFeMooR/LAaEFPHCKgG9rt/uQKn53JolCr5QW68Yp2wuOnDoJzz+y 0Hc/p7IGYffjlrhJxo8vWC1Z4fKfu1o= X-Stat-Signature: qtimhgbdc9h9k7wzyu1y1rp3qps9n1z5 X-Rspamd-Queue-Id: 62EA740027 X-Rspam-User: Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=NGW5Z8sb; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf04.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.58 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspamd-Server: rspam12 X-HE-Tag: 1656474914-491004 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When CPU is connected throug XGMI, it has coherent access to VRAM resource. In this case that resource is taken from a table in the device gmc aperture base. This resource is used along with the device type, which could be DEVICE_PRIVATE or DEVICE_COHERENT to create the device page map region. Also, MIGRATE_VMA_SELECT_DEVICE_COHERENT flag is selected for coherent type case during migration to device. Signed-off-by: Alex Sierra Reviewed-by: Felix Kuehling Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 34 +++++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index e44376c2ecdc..f73e3e340413 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -671,13 +671,15 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.vma = vma; migrate.start = start; migrate.end = end; - migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; migrate.pgmap_owner = SVM_ADEV_PGMAP_OWNER(adev); + if (adev->gmc.xgmi.connected_to_cpu) + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_COHERENT; + else + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; buf = kvcalloc(npages, 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t), GFP_KERNEL); - if (!buf) goto out; @@ -947,7 +949,7 @@ int svm_migrate_init(struct amdgpu_device *adev) { struct kfd_dev *kfddev = adev->kfd.dev; struct dev_pagemap *pgmap; - struct resource *res; + struct resource *res = NULL; unsigned long size; void *r; @@ -962,28 +964,34 @@ int svm_migrate_init(struct amdgpu_device *adev) * should remove reserved size */ size = ALIGN(adev->gmc.real_vram_size, 2ULL << 20); - res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); - if (IS_ERR(res)) - return -ENOMEM; + if (adev->gmc.xgmi.connected_to_cpu) { + pgmap->range.start = adev->gmc.aper_base; + pgmap->range.end = adev->gmc.aper_base + adev->gmc.aper_size - 1; + pgmap->type = MEMORY_DEVICE_COHERENT; + } else { + res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); + if (IS_ERR(res)) + return -ENOMEM; + pgmap->range.start = res->start; + pgmap->range.end = res->end; + pgmap->type = MEMORY_DEVICE_PRIVATE; + } - pgmap->type = MEMORY_DEVICE_PRIVATE; pgmap->nr_range = 1; - pgmap->range.start = res->start; - pgmap->range.end = res->end; pgmap->ops = &svm_migrate_pgmap_ops; pgmap->owner = SVM_ADEV_PGMAP_OWNER(adev); - pgmap->flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; - + pgmap->flags = 0; /* Device manager releases device-specific resources, memory region and * pgmap when driver disconnects from device. */ r = devm_memremap_pages(adev->dev, pgmap); if (IS_ERR(r)) { pr_err("failed to register HMM device memory\n"); - /* Disable SVM support capability */ pgmap->type = 0; - devm_release_mem_region(adev->dev, res->start, resource_size(res)); + if (pgmap->type == MEMORY_DEVICE_PRIVATE) + devm_release_mem_region(adev->dev, res->start, + res->end - res->start + 1); return PTR_ERR(r); } From patchwork Wed Jun 29 03:54:20 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: 12899275 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 3D30CCCA482 for ; Wed, 29 Jun 2022 03:55:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF29B8E0007; Tue, 28 Jun 2022 23:55:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA0B48E000A; Tue, 28 Jun 2022 23:55:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91B418E0007; Tue, 28 Jun 2022 23:55:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 76D2F8E000A for ; Tue, 28 Jun 2022 23:55:15 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5202A612DC for ; Wed, 29 Jun 2022 03:55:15 +0000 (UTC) X-FDA: 79629908190.08.FFDFE30 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by imf23.hostedemail.com (Postfix) with ESMTP id C42F114002E for ; Wed, 29 Jun 2022 03:55:14 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QFNfeaxabkJ6YptSJEI0kEEv3QUCkawE1rM5pOyRHkwqSXRE5lMtODT0SskM2lRp0TJtA3L3QjpQA6DeYG4jq28vNiK2lVG3SLydJq/heMnYFElDm1nvqFd9Niaj1G48ggk71V2qtUJWz3QTvhI8sZIYs5r+7B4E6oakG+YOAApFQ4Av/hZV1R8MHSfbKO5d62d1Om/GViEftGVMSaRUk8PmKuR6iL3zDPTMcc7+mYPspJkauOEDJgioIADyqbaQJbHE1d6ONQdFgjgzZKcjn2peCgRmrVYH05NSpPImQYc0g1LdI6n/HHQrd16BbocRJ/FCehL69TP67qMIOXjC4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=F8lzcu9Uc51zZ3prS+uZltVgKEco8VgkJ2E7O9HgaPo=; b=chtdXIxaOLDef6OvjuYInL4b6IKDgnS5DRk5rDuYp7BrmVn0z00TNKETkPaIyZteH+dRGviKBYcWVgNHixqFQza5gEpicbfoNlCXZV6kOx1DQDHaEf/iXLoYLc8GAczOfxxwAwv8AVhN8m3z8ABV32M+/1GkOQstiirChokj+uBj5zewzAYwnckJ/zCvb4AobaA5kpwAbjQonNDuLNhNWWFMmNbHhEuv1BqXDDNA77CqbWaCxkQ/DD/HD4g0xUPOC8R9ytqOEUmFk8wYwkyQySaL8zbE1VtgcXfHPk491Bzk1Udc6kP8YRNEndsBkYjSA8k07JCjlnHHklrpwkR2bg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F8lzcu9Uc51zZ3prS+uZltVgKEco8VgkJ2E7O9HgaPo=; b=UTbQirQt2ogzzktIuxnmRcHnjHHRtmVlQL5NyzbV9BpnEkjWEdRqiMlUPOuR1zFeh8xscl3zxXJriBZmJk97ZSX1SnWQr4xLeaLe9GV/9VbbqQdephblPQ8JZOOx2apwup8GOi9RtyhZ+6gyUF60bUTd61k4GtypZh2TfMSUs/Q= Received: from BN8PR12CA0011.namprd12.prod.outlook.com (2603:10b6:408:60::24) by DM6PR12MB4515.namprd12.prod.outlook.com (2603:10b6:5:2a1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16; Wed, 29 Jun 2022 03:55:13 +0000 Received: from BN8NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:408:60:cafe::71) by BN8PR12CA0011.outlook.office365.com (2603:10b6:408:60::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16 via Frontend Transport; Wed, 29 Jun 2022 03:55:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT058.mail.protection.outlook.com (10.13.177.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:12 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 28 Jun 2022 22:55:10 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 08/14] lib: test_hmm add ioctl to get zone device type Date: Tue, 28 Jun 2022 22:54:20 -0500 Message-ID: <20220629035426.20013-9-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: ddd1929c-bd1a-4657-ad8a-08da59832b5f X-MS-TrafficTypeDiagnostic: DM6PR12MB4515:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vPJp0xPGuo+8sDvCrOgSnzj6i3pAW4jRcfnafUJQu1TCoZxGAcWgDQAHnUCwPTTF7mGrcbEQ2EtzIGweBbqS+kpyXUCIj/+BrT16RlszQReTyyVwDz8xQAHOQQykHAzyF2AcsaY+5fz7v/AsDWDL81G4v2fkgdzQZyJfu703zfdO20DBkakNOAiEDPwT69AXtCrHrW7KLKQkwqDy0r4Er1KDEc6r5nW23N5cssEeg30j33xgusM34VD0c3LANLTzEmNiK5yRoiQLzMM5oWtjeNTaZZhtcwOYcIDz1IH7auuSXSZaQLm+fCGhuIUlwgAHitFgpai6i/uPYUp3VAqrECisDPhi//0IFe1PTw7MGD/RiCF6BS22uihyQRXRwEiAW6o0UnLpS3Xf7h6nRamG4HusvC56gB5nrb7NRzlY3D7bHeh8flg3SH7tuhP3hUablGN3F8GnH0fC3NTIP9zMNuBb6vipv6/+C/p4bQc8Ux3nHe9LWrQJHxG6Y9hEuOE831QPYQwT+FM/1rlbLLgnKzA/yWLI9iX9GNV6HqsI2Dtu2JYtR3fzepHuEulIIIlMJC9uy1TfTnBC4K/l4dEJCumFmonSt95GE2C7umKGppBZO53yeoQgkvqUe733xx6jlt/iEWGiArj8Q40UFxPFqitY0GroHaef/Rd2gFNCYaVoW3XaRF7R5eGd1i6M7HIVQ4dsBsVnCEpytzVZo4uuNBQfD0koyCMgrHTuuYswRVJhSzDaIMmhVrf93a2xnvR2Gt/GRxBTmnIU2bhOVJgw5KLPNoYcuokNhi1i7GtYHJVgwyDuyEOv7ynfzzHnpZod8kXsOnspjWcZ4w1/Lc67YQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(346002)(39860400002)(376002)(396003)(136003)(46966006)(40470700004)(36840700001)(36860700001)(1076003)(83380400001)(356005)(40480700001)(6666004)(86362001)(336012)(8936002)(2906002)(426003)(8676002)(54906003)(70206006)(16526019)(316002)(186003)(6916009)(40460700003)(36756003)(4326008)(47076005)(82740400003)(478600001)(7416002)(5660300002)(26005)(41300700001)(44832011)(2616005)(82310400005)(81166007)(7696005)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:12.9000 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ddd1929c-bd1a-4657-ad8a-08da59832b5f 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: BN8NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4515 ARC-Authentication-Results: i=2; imf23.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=UTbQirQt; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf23.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.40 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=F8lzcu9Uc51zZ3prS+uZltVgKEco8VgkJ2E7O9HgaPo=; b=NNH65ar0HBlLSBEIBHtcWzAEYf5+4u97Kxy4TpBOuzAt9qswq+3rQBf4em9eTueVaIFmVR 7RtE2sU5wFtYRTuXyDp1H30QxMcSNAV2il0glQJUgfLNnA/jl7qN5pMse9Bo/b7TeID0WN KYhlg15jtcJrgfkFwUdl8yKdeGQPS3I= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474914; a=rsa-sha256; cv=pass; b=owRl2fh/5+WDgpkuBVmG7ipQDup3cxnbVKzSzw4eqSKdyFEsd5G52hn1l55epPB3utgBXi Vh0VrD5YIsIScsc2WdcZnmv/mr0t3pfo7ODh5x76eo5BEMxBcmqP+p4o1U/5YhIe9k3PwK OQ9RMgVSkJkicsDKZWzaj27CmamrhZo= X-Stat-Signature: w554fw5uceg1qsibt7aetq9nk9s7omq1 X-Rspamd-Queue-Id: C42F114002E X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=UTbQirQt; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf23.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.40 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspamd-Server: rspam12 X-HE-Tag: 1656474914-728702 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: new ioctl cmd added to query zone device type. This will be used once the test_hmm adds zone device coherent type. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Poppple Signed-off-by: Christoph Hellwig --- lib/test_hmm.c | 11 +++++++++-- lib/test_hmm_uapi.h | 14 ++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index cfe632047839..915ef6b5b0d4 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -87,6 +87,7 @@ struct dmirror_chunk { struct dmirror_device { struct cdev cdevice; struct hmm_devmem *devmem; + unsigned int zone_device_type; unsigned int devmem_capacity; unsigned int devmem_count; @@ -1260,14 +1261,20 @@ static void dmirror_device_remove(struct dmirror_device *mdevice) static int __init hmm_dmirror_init(void) { int ret; - int id; + int id = 0; + int ndevices = 0; ret = alloc_chrdev_region(&dmirror_dev, 0, DMIRROR_NDEVICES, "HMM_DMIRROR"); if (ret) goto err_unreg; - for (id = 0; id < DMIRROR_NDEVICES; id++) { + memset(dmirror_devices, 0, DMIRROR_NDEVICES * sizeof(dmirror_devices[0])); + dmirror_devices[ndevices++].zone_device_type = + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; + dmirror_devices[ndevices++].zone_device_type = + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; + for (id = 0; id < ndevices; id++) { ret = dmirror_device_init(dmirror_devices + id, id); if (ret) goto err_chrdev; diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index f14dea5dcd06..0511af7464ee 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -31,10 +31,11 @@ struct hmm_dmirror_cmd { /* Expose the address space of the calling process through hmm device file */ #define HMM_DMIRROR_READ _IOWR('H', 0x00, struct hmm_dmirror_cmd) #define HMM_DMIRROR_WRITE _IOWR('H', 0x01, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_MIGRATE _IOWR('H', 0x02, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_SNAPSHOT _IOWR('H', 0x03, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_EXCLUSIVE _IOWR('H', 0x04, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_CHECK_EXCLUSIVE _IOWR('H', 0x05, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_MIGRATE_TO_DEV _IOWR('H', 0x02, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_MIGRATE_TO_SYS _IOWR('H', 0x03, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_SNAPSHOT _IOWR('H', 0x04, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_EXCLUSIVE _IOWR('H', 0x05, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_CHECK_EXCLUSIVE _IOWR('H', 0x06, struct hmm_dmirror_cmd) /* * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT. @@ -62,4 +63,9 @@ enum { HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE = 0x30, }; +enum { + /* 0 is reserved to catch uninitialized type fields */ + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1, +}; + #endif /* _LIB_TEST_HMM_UAPI_H */ From patchwork Wed Jun 29 03:54:21 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: 12899276 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 1B479C433EF for ; Wed, 29 Jun 2022 03:55:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 747798E000B; Tue, 28 Jun 2022 23:55:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F7238E000A; Tue, 28 Jun 2022 23:55:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FC5A8E000B; Tue, 28 Jun 2022 23:55:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3E83D8E000A for ; Tue, 28 Jun 2022 23:55:16 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id D64876111F for ; Wed, 29 Jun 2022 03:55:15 +0000 (UTC) X-FDA: 79629908190.19.BE9A5FC Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2049.outbound.protection.outlook.com [40.107.223.49]) by imf14.hostedemail.com (Postfix) with ESMTP id 5BE9710001C for ; Wed, 29 Jun 2022 03:55:15 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VSc/uy/mlwyQpoiRnZXKCZ5yjlCZiVTu69M+GEiFtTK1M5yuK/8PAxq1SKnpENaOtE4Utd6AUf33QvzmU1acRGG5rpAaMHXHD8nnpZUj7HTBH8o9cjs/XeV9CSBY7Yqt/qBU+sItDAWwZN+3bCsn/tFknTJunSBbN2H3cXKM9V+siSpGU2xgB4rgS2chwBqfpuq+QwjuTcSyzWw91d9BXNtLz+emJKn9rh6EwhkVJou/PxSoUYb/cWtagNIj6ST1e0nC7AMy60k+2aGvvRpqvu9Q0ryby5hKsg/XrvM5cwFI3nQjm4+adQfA4y33cKPOv+mE9bhgZl34CgNVrIJtzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0Gq5krbSDZgVmQmlPCe18YVS7UIhP8NZXgBaLYb/5yI=; b=NKa8CCUgyToyoaOQe36rNyXX0pN4sNqmvBGk+MSaBatPcUVxvtSx2qBJBmn6AHbDGD8RJINroM4CDobvNhKlMacW24JXC9VQWVmtV79qGrkeCLlotJhU1y0zGPLKnZgchhBYQ831pqpNEFjXbom4FIC4cVT021nB80IkP1ZC2jNGaQb7bvW+bDJRuWLg1+uqfvvPoqxffHE/SKKE6vmZ24ZGsPaUMM4cLukWIfDt5hnqAkPg2PX+Ak/nlCSqKJfsYoY65ioJLcsqyxOvjJGUxb0tm8XEEs0EXP+Y34A4RQtmn6/O8Fr+9bGdtpITRuPkVX8utsOPxKNNLOFS7qjbgA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0Gq5krbSDZgVmQmlPCe18YVS7UIhP8NZXgBaLYb/5yI=; b=HPmMh0uZerII+pcg07XWY/difoooamEOZETXFrSsp9JrsAbn4uVzrIuRwjDmkU4tsxkGGbbbH3NVTlA50GUaJbnmtW45yILeZQ0sJEM9/xnn8spPxBUZnUCYfY9d5sYTUZK/h6BGpEumNHnJEBfG8op79mHMySMz1fKnC0yoXQI= Received: from BN8PR12CA0009.namprd12.prod.outlook.com (2603:10b6:408:60::22) by CH2PR12MB4069.namprd12.prod.outlook.com (2603:10b6:610:ac::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17; Wed, 29 Jun 2022 03:55:12 +0000 Received: from BN8NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:408:60:cafe::18) by BN8PR12CA0009.outlook.office365.com (2603:10b6:408:60::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16 via Frontend Transport; Wed, 29 Jun 2022 03:55:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT058.mail.protection.outlook.com (10.13.177.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:12 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 28 Jun 2022 22:55:11 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 09/14] lib: test_hmm add module param for zone device type Date: Tue, 28 Jun 2022 22:54:21 -0500 Message-ID: <20220629035426.20013-10-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: fe4fd305-d3a1-4ef4-513c-08da59832b00 X-MS-TrafficTypeDiagnostic: CH2PR12MB4069:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3s9T44qM2CUPqgLAutBdi7tV9Rq12N34GOqWk1hLlggN1WKz0vrbPNUwuwkpX0FTjNadYFr50HambekYJU3zobmUY3H3y61CQrAnqEBnykx1Jeg4VqEhde4fa6uwpOhAOem/0tKkqin/I3sX60uO9/mmj0WBoteMssSBYfczM5eVPZbejwUtVjNQyBentiE3O+e6WGSNb0Mqoh8zAKlw+w+ZqumnmROCGxixZrYRLtzHy6fKn4iTvZGyhwxeFn4u1XwQ7XRKvvNQSbz4gBV5YoYl5gN6BRsYlqVIrdCvoXzHscgsyUXfY5dtLxBnxeTau7H//QNNDVoTl4y2ItqXsojgojIFVTVfi2IKoi61jGOEkVbLpEM6I5y4fjMYxIjzG/82V3pcsnLp5PQ9UwMT5Jn95mDv7GtrQE37j8F7sOTdfHkBbC8dGHz9v0vQBwLfhGthC2JyphaSoo1KzAEX4ZW3TDEuLwgn6RFAbY27Xam5geW8JonVDg1SNWriiPENbze7NyhQbfkguLB7HwXP1Ym3FxTctNGLf4fflvPnaeAmoFZmeTl5wjUK1GjhL1UcGZHQigxmTTD9lwSTQHcK33QQH7sIAdAD7Y+nS1eJ3E4sd6eQ/E8iJbeNp0cCLhd9Fki359wxkDU2Wu5rZ49EmlQlJlFjPS4IbZpa8kVtGOIdA7e//4pEO68G8howKFy5nJNUGt/YihyUGaIEURWhXKJYuGPWarQwWExwRH0OxV7Aztpr1OOCaCQSJQKRSLtohVFPZ6wOXput4rPpJK16NZbpWt5UfpET3f0a1OF2Udb1veP3Bx2tMmW2H4sLj/CDqJJHphDuJ1hWlvE0G8i2Ug== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(136003)(346002)(39860400002)(376002)(396003)(40470700004)(46966006)(36840700001)(54906003)(82740400003)(82310400005)(426003)(47076005)(7696005)(44832011)(336012)(7416002)(26005)(6916009)(81166007)(356005)(36756003)(316002)(6666004)(40480700001)(186003)(41300700001)(70586007)(70206006)(36860700001)(1076003)(83380400001)(86362001)(16526019)(40460700003)(478600001)(4326008)(8936002)(8676002)(2906002)(5660300002)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:12.2750 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe4fd305-d3a1-4ef4-513c-08da59832b00 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: BN8NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4069 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474915; a=rsa-sha256; cv=pass; b=xedMAo7IsV6n8VyfBMFk+BWTBHJC0S2EUjY8aOURp56iTdL8PcFhMKeepE4ku/LIPKxPLn bGIiilxWsMTMRQUDCn5uH+Wow5k2YKLGLBXLiuqlHSdQrVfa3GGNCwxd6o0pdl0dsuugVB qPupNZ7UJ9pRiXB2TH9iOEhYWIoAREs= ARC-Authentication-Results: i=2; imf14.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=HPmMh0uZ; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf14.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.49 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474915; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0Gq5krbSDZgVmQmlPCe18YVS7UIhP8NZXgBaLYb/5yI=; b=Tp84Xh3TsBFApeSTL6d97c9nDb2697Pqvt2R7Hn9JodRQ45irwNcizBB/wKS1IypNqlxHo sI8T78VQx+BjA18A3CmVJxpL3/lprYZ6iOGBloUEIc1fT6fmv2hlVI5iyK4wVmxC96d7cV XKJEqjvALeXU/2vgHhWhUh+8SFvAbQk= X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=HPmMh0uZ; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf14.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.49 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam02 X-Stat-Signature: ourkou9zikyxpdddx4r81mmkoa86bowr X-Rspamd-Queue-Id: 5BE9710001C X-HE-Tag: 1656474915-737263 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In order to configure device coherent in test_hmm, two module parameters should be passed, which correspond to the SP start address of each device (2) spm_addr_dev0 & spm_addr_dev1. If no parameters are passed, private device type is configured. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Poppple Signed-off-by: Christoph Hellwig --- lib/test_hmm.c | 73 ++++++++++++++++++++++++++++++++------------- lib/test_hmm_uapi.h | 1 + 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 915ef6b5b0d4..afb30af9f3ff 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -37,6 +37,16 @@ #define DEVMEM_CHUNK_SIZE (256 * 1024 * 1024U) #define DEVMEM_CHUNKS_RESERVE 16 +static unsigned long spm_addr_dev0; +module_param(spm_addr_dev0, long, 0644); +MODULE_PARM_DESC(spm_addr_dev0, + "Specify start address for SPM (special purpose memory) used for device 0. By setting this Coherent device type will be used. Make sure spm_addr_dev1 is set too. Minimum SPM size should be DEVMEM_CHUNK_SIZE."); + +static unsigned long spm_addr_dev1; +module_param(spm_addr_dev1, long, 0644); +MODULE_PARM_DESC(spm_addr_dev1, + "Specify start address for SPM (special purpose memory) used for device 1. By setting this Coherent device type will be used. Make sure spm_addr_dev0 is set too. Minimum SPM size should be DEVMEM_CHUNK_SIZE."); + static const struct dev_pagemap_ops dmirror_devmem_ops; static const struct mmu_interval_notifier_ops dmirror_min_ops; static dev_t dmirror_dev; @@ -455,28 +465,44 @@ static int dmirror_write(struct dmirror *dmirror, struct hmm_dmirror_cmd *cmd) return ret; } -static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, +static int dmirror_allocate_chunk(struct dmirror_device *mdevice, struct page **ppage) { struct dmirror_chunk *devmem; - struct resource *res; + struct resource *res = NULL; unsigned long pfn; unsigned long pfn_first; unsigned long pfn_last; void *ptr; + int ret = -ENOMEM; devmem = kzalloc(sizeof(*devmem), GFP_KERNEL); if (!devmem) - return false; + return ret; - res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, - "hmm_dmirror"); - if (IS_ERR(res)) + switch (mdevice->zone_device_type) { + case HMM_DMIRROR_MEMORY_DEVICE_PRIVATE: + res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, + "hmm_dmirror"); + if (IS_ERR_OR_NULL(res)) + goto err_devmem; + devmem->pagemap.range.start = res->start; + devmem->pagemap.range.end = res->end; + devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; + break; + case HMM_DMIRROR_MEMORY_DEVICE_COHERENT: + devmem->pagemap.range.start = (MINOR(mdevice->cdevice.dev) - 2) ? + spm_addr_dev0 : + spm_addr_dev1; + devmem->pagemap.range.end = devmem->pagemap.range.start + + DEVMEM_CHUNK_SIZE - 1; + devmem->pagemap.type = MEMORY_DEVICE_COHERENT; + break; + default: + ret = -EINVAL; goto err_devmem; + } - devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; - devmem->pagemap.range.start = res->start; - devmem->pagemap.range.end = res->end; devmem->pagemap.nr_range = 1; devmem->pagemap.ops = &dmirror_devmem_ops; devmem->pagemap.owner = mdevice; @@ -497,10 +523,14 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, mdevice->devmem_capacity = new_capacity; mdevice->devmem_chunks = new_chunks; } - ptr = memremap_pages(&devmem->pagemap, numa_node_id()); - if (IS_ERR(ptr)) + if (IS_ERR_OR_NULL(ptr)) { + if (ptr) + ret = PTR_ERR(ptr); + else + ret = -EFAULT; goto err_release; + } devmem->mdevice = mdevice; pfn_first = devmem->pagemap.range.start >> PAGE_SHIFT; @@ -529,15 +559,17 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, } spin_unlock(&mdevice->lock); - return true; + return 0; err_release: mutex_unlock(&mdevice->devmem_lock); - release_mem_region(devmem->pagemap.range.start, range_len(&devmem->pagemap.range)); + if (res && devmem->pagemap.type == MEMORY_DEVICE_PRIVATE) + release_mem_region(devmem->pagemap.range.start, + range_len(&devmem->pagemap.range)); err_devmem: kfree(devmem); - return false; + return ret; } static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) @@ -562,7 +594,7 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) spin_unlock(&mdevice->lock); } else { spin_unlock(&mdevice->lock); - if (!dmirror_allocate_chunk(mdevice, &dpage)) + if (dmirror_allocate_chunk(mdevice, &dpage)) goto error; } @@ -1232,10 +1264,8 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id) if (ret) return ret; - /* Build a list of free ZONE_DEVICE private struct pages */ - dmirror_allocate_chunk(mdevice, NULL); - - return 0; + /* Build a list of free ZONE_DEVICE struct pages */ + return dmirror_allocate_chunk(mdevice, NULL); } static void dmirror_device_remove(struct dmirror_device *mdevice) @@ -1248,8 +1278,9 @@ static void dmirror_device_remove(struct dmirror_device *mdevice) mdevice->devmem_chunks[i]; memunmap_pages(&devmem->pagemap); - release_mem_region(devmem->pagemap.range.start, - range_len(&devmem->pagemap.range)); + if (devmem->pagemap.type == MEMORY_DEVICE_PRIVATE) + release_mem_region(devmem->pagemap.range.start, + range_len(&devmem->pagemap.range)); kfree(devmem); } kfree(mdevice->devmem_chunks); diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index 0511af7464ee..f700da7807c1 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -66,6 +66,7 @@ enum { enum { /* 0 is reserved to catch uninitialized type fields */ HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1, + HMM_DMIRROR_MEMORY_DEVICE_COHERENT, }; #endif /* _LIB_TEST_HMM_UAPI_H */ From patchwork Wed Jun 29 03:54:22 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: 12899277 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 668C5CCA47E for ; Wed, 29 Jun 2022 03:55:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54B5D8E000C; Tue, 28 Jun 2022 23:55:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FD078E000A; Tue, 28 Jun 2022 23:55:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B4618E000C; Tue, 28 Jun 2022 23:55:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 139398E000A for ; Tue, 28 Jun 2022 23:55:17 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id E59CA6111D for ; Wed, 29 Jun 2022 03:55:16 +0000 (UTC) X-FDA: 79629908232.23.F0DD2CD Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2042.outbound.protection.outlook.com [40.107.212.42]) by imf22.hostedemail.com (Postfix) with ESMTP id 4C371C0027 for ; Wed, 29 Jun 2022 03:55:16 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VUJGkSoftnRwD5p9MwsvIjIWQEPu+DuXikkVHNBnSkOT6GG78b0elQZguXmc9ASfD2nEHpt5VJGrgl3MR9TI/fQ3szwouvEwvGnW/b9tahhSpUK6e0WrleUYuhHRI/dJu8sklH6JILy9WzpZ3hwCbIrufbAhl09XJkWlF5pGkDdHnEafQD4uotffDCF7ZdwvoOWV4yX3z/wUq/XYPeS2aJsDM3pcxhhCUbOREDBoBJny4UeuJz8eQP5PFIUsF4DQeS+kAgz9XUZUbMFXRQBBwI8TOf7Ewg5ISeWG7HZfC1wjfm9MbLKuSC48Ra8fe+CstzCD2DI6p+zC2bN1yyXvJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qXHkTMDP9sqYKzMO3NOS8Ic3UgCNCptiqPNyD5wLuTo=; b=Me6LrqO9ZctEUURwyQcMB6rhR78Mpvmp7YZlzclg0SElIdpYMhL1UeuJYnVXMM3IMGE1+MwSw8xeLKSdA9/PNIWpltzVSoLhp6+Sn1zGs7MLluwi1f9pqAixurHQt9bBWPFpn5Gg6Q3tmM/qxwRxArjdqTBYDww5+8+hlyHOWSdUNGg/T/Xjj102IWmVcgUZ2ZVr64+vGURMxSjxm1+kYpGL8t5ldwxRf1nY3O8ae5ElEdBuMVVdKNuh+kTbmmYuteLJBKosTzOKPM1BFveZlfxeM2Trkdn//m3eBhUKvHZwXqTjJIrDump+HLuRQnRHeMtfSTpPmqot4SJl0QINDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qXHkTMDP9sqYKzMO3NOS8Ic3UgCNCptiqPNyD5wLuTo=; b=lDGiuGZ5SfvY2cfgnlQJ2SKQznzbJbl1UF6XLqAlD+PFBltNrnuentQg1HlbhcjXAr9pzvHImEWj9RHLiz6JXnOcIkaLeg3lyiUcKKz2EKBzgjQymTvBtYALGCWkfMbzEs2bs9EOoOmuEMOENPHNYy5Xf2Achfpjn3hSOa7F7CU= Received: from BN8PR12CA0020.namprd12.prod.outlook.com (2603:10b6:408:60::33) by BY5PR12MB4081.namprd12.prod.outlook.com (2603:10b6:a03:20e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Wed, 29 Jun 2022 03:55:13 +0000 Received: from BN8NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:408:60:cafe::64) by BN8PR12CA0020.outlook.office365.com (2603:10b6:408:60::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16 via Frontend Transport; Wed, 29 Jun 2022 03:55:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT058.mail.protection.outlook.com (10.13.177.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:13 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 28 Jun 2022 22:55:11 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 10/14] lib: add support for device coherent type in test_hmm Date: Tue, 28 Jun 2022 22:54:22 -0500 Message-ID: <20220629035426.20013-11-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: a42cf666-f3a8-4cc7-473b-08da59832b9b X-MS-TrafficTypeDiagnostic: BY5PR12MB4081:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GiryfKMTgitP0cV0HCKa6PJQxAMWUP0SU1eWzJSdKCD0FghAPzYGJR7v+R5e2h9E4+fgZJZPvNweqe+qNw9FgsHusjB720GnFE4Z4v1xU+eeQrVv3N07tA/drUzz+w//+PlZtpPi5bg/b6Z9VPjY8O2TxYTBQQnlzMy2H01GrSKyBFdxyT0ZTW4pPTo8DyX9hA6d7nJdwiicOrFAA+fTvHZHUG5CoHl/l15xu0QixLt8nPMr50LlsRM8WpuZnukItW54raokA68p3wvXOVHvfGNzba41AbJSTC5SmJ8CZRoR7qqNJX3USCBQyhsO++cUlzbMOtF9NzRffs32BAe3Ekl1PT2GCInzOvXSzH6FYvrcN0vx+TqA2q1gMLY262UYjXuf9YajcjCuidXugkztkj2mGRdakFne/xDThdVBxR+2neq1pNrIg6BP6pu5rLJ+DASbNeRBQ+hlh2ZHRrIXKNkGC5ETz0xCZ/GOqMExAYE8urWn4o69oq/6rt5oDtIXgECA2+MDe2/yK/I8EI2IlAuDD5tuMJnmppZ5viJB+eXwq4CfQZ/rF+M5UttozwTsUIpphrwvPjHx38rLHIjOmQrhjEbleJgwl5EX1i69SXonC1ZFWBIyGC0aMnTp5ewx4w//uVJl12Pr0HpkMHtb3BUo+dhFjLJRwqrmxVXFeWEjIh/tP9RVqVmCqhew6bkJlotA2QZMExT4W91Oh+9th0l6XXd7xIv3HgPLrP7WUnCYv/LoLXKAWBWZcXfaNoE258gJGufIeeJoQJOgDtA0tRxPw7ka/GK9heVVdFDweQsDgikKdVWZ9aLIfD1Ayb/Cz3P8brIcUI1LYADOb5Ogsg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(346002)(376002)(396003)(39860400002)(136003)(46966006)(40470700004)(36840700001)(426003)(82310400005)(47076005)(336012)(316002)(36756003)(30864003)(40460700003)(7416002)(1076003)(40480700001)(5660300002)(2616005)(83380400001)(81166007)(356005)(41300700001)(82740400003)(2906002)(8676002)(7696005)(8936002)(70206006)(70586007)(86362001)(6666004)(4326008)(26005)(16526019)(36860700001)(54906003)(186003)(44832011)(6916009)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:13.2749 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a42cf666-f3a8-4cc7-473b-08da59832b9b 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: BN8NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4081 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474916; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qXHkTMDP9sqYKzMO3NOS8Ic3UgCNCptiqPNyD5wLuTo=; b=aaDoZcDAl7QMfWAWPb5K1ubP+WkT3gz0QzXP9O0Vrzkv5ej2TaOCI5ABZPvabL39YrJRkZ Rdzlz1snnTP5FhT29QjSHH6OYyIqq8JxWjSngrAYXU5tyryR//zirJgglHoKErruwt3vYM AJVzinJFSHftdcZdKNQmd3qVQMjA9FY= ARC-Authentication-Results: i=2; imf22.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=lDGiuGZ5; spf=pass (imf22.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.212.42 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474916; a=rsa-sha256; cv=pass; b=LeCEjmFpT9dLs6hznvAtWp9VqothOII4RG7XTozIFjPmatUrjy+9I4lpDnpP3ByZXmgtkV Kq8IW89p6EfkcA3NvWFrVn4XHArL88zHJ+UsH3Bt6oP6J0ozexv27kxMqgrRmiRI6luUbe 0YnmnGgG+2L8dCUsiI066GVysuX3XZw= Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=lDGiuGZ5; spf=pass (imf22.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.212.42 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: 9t1d9x8grue3nu9urpgawo4ui571mmmq X-Rspamd-Queue-Id: 4C371C0027 X-HE-Tag: 1656474916-755480 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Device Coherent type uses device memory that is coherently accesible by the CPU. This could be shown as SP (special purpose) memory range at the BIOS-e820 memory enumeration. If no SP memory is supported in system, this could be faked by setting CONFIG_EFI_FAKE_MEMMAP. Currently, test_hmm only supports two different SP ranges of at least 256MB size. This could be specified in the kernel parameter variable efi_fake_mem. Ex. Two SP ranges of 1GB starting at 0x100000000 & 0x140000000 physical address. Ex. efi_fake_mem=1G@0x100000000:0x40000,1G@0x140000000:0x40000 Private and coherent device mirror instances can be created in the same probed. This is done by passing the module parameters spm_addr_dev0 & spm_addr_dev1. In this case, it will create four instances of device_mirror. The first two correspond to private device type, the last two to coherent type. Then, they can be easily accessed from user space through /dev/hmm_mirror. Usually num_device 0 and 1 are for private, and 2 and 3 for coherent types. If no module parameters are passed, two instances of private type device_mirror will be created only. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Poppple --- lib/test_hmm.c | 253 +++++++++++++++++++++++++++++++++----------- lib/test_hmm_uapi.h | 4 + 2 files changed, 196 insertions(+), 61 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index afb30af9f3ff..7930853e7fc5 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -32,11 +32,22 @@ #include "test_hmm_uapi.h" -#define DMIRROR_NDEVICES 2 +#define DMIRROR_NDEVICES 4 #define DMIRROR_RANGE_FAULT_TIMEOUT 1000 #define DEVMEM_CHUNK_SIZE (256 * 1024 * 1024U) #define DEVMEM_CHUNKS_RESERVE 16 +/* + * For device_private pages, dpage is just a dummy struct page + * representing a piece of device memory. dmirror_devmem_alloc_page + * allocates a real system memory page as backing storage to fake a + * real device. zone_device_data points to that backing page. But + * for device_coherent memory, the struct page represents real + * physical CPU-accessible memory that we can use directly. + */ +#define BACKING_PAGE(page) (is_device_private_page((page)) ? \ + (page)->zone_device_data : (page)) + static unsigned long spm_addr_dev0; module_param(spm_addr_dev0, long, 0644); MODULE_PARM_DESC(spm_addr_dev0, @@ -125,6 +136,21 @@ static int dmirror_bounce_init(struct dmirror_bounce *bounce, return 0; } +static bool dmirror_is_private_zone(struct dmirror_device *mdevice) +{ + return (mdevice->zone_device_type == + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE) ? true : false; +} + +static enum migrate_vma_direction +dmirror_select_device(struct dmirror *dmirror) +{ + return (dmirror->mdevice->zone_device_type == + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE) ? + MIGRATE_VMA_SELECT_DEVICE_PRIVATE : + MIGRATE_VMA_SELECT_DEVICE_COHERENT; +} + static void dmirror_bounce_fini(struct dmirror_bounce *bounce) { vfree(bounce->ptr); @@ -575,16 +601,19 @@ static int dmirror_allocate_chunk(struct dmirror_device *mdevice, static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) { struct page *dpage = NULL; - struct page *rpage; + struct page *rpage = NULL; /* - * This is a fake device so we alloc real system memory to store - * our device memory. + * For ZONE_DEVICE private type, this is a fake device so we allocate + * real system memory to store our device memory. + * For ZONE_DEVICE coherent type we use the actual dpage to store the + * data and ignore rpage. */ - rpage = alloc_page(GFP_HIGHUSER); - if (!rpage) - return NULL; - + if (dmirror_is_private_zone(mdevice)) { + rpage = alloc_page(GFP_HIGHUSER); + if (!rpage) + return NULL; + } spin_lock(&mdevice->lock); if (mdevice->free_pages) { @@ -603,7 +632,8 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) return dpage; error: - __free_page(rpage); + if (rpage) + __free_page(rpage); return NULL; } @@ -629,12 +659,16 @@ static void dmirror_migrate_alloc_and_copy(struct migrate_vma *args, * unallocated pte_none() or read-only zero page. */ spage = migrate_pfn_to_page(*src); + if (WARN(spage && is_zone_device_page(spage), + "page already in device spage pfn: 0x%lx\n", + page_to_pfn(spage))) + continue; dpage = dmirror_devmem_alloc_page(mdevice); if (!dpage) continue; - rpage = dpage->zone_device_data; + rpage = BACKING_PAGE(dpage); if (spage) copy_highpage(rpage, spage); else @@ -648,6 +682,8 @@ static void dmirror_migrate_alloc_and_copy(struct migrate_vma *args, */ rpage->zone_device_data = dmirror; + pr_debug("migrating from sys to dev pfn src: 0x%lx pfn dst: 0x%lx\n", + page_to_pfn(spage), page_to_pfn(dpage)); *dst = migrate_pfn(page_to_pfn(dpage)); if ((*src & MIGRATE_PFN_WRITE) || (!spage && args->vma->vm_flags & VM_WRITE)) @@ -725,11 +761,7 @@ static int dmirror_migrate_finalize_and_map(struct migrate_vma *args, if (!dpage) continue; - /* - * Store the page that holds the data so the page table - * doesn't have to deal with ZONE_DEVICE private pages. - */ - entry = dpage->zone_device_data; + entry = BACKING_PAGE(dpage); if (*dst & MIGRATE_PFN_WRITE) entry = xa_tag_pointer(entry, DPT_XA_TAG_WRITE); entry = xa_store(&dmirror->pt, pfn, entry, GFP_ATOMIC); @@ -809,15 +841,126 @@ static int dmirror_exclusive(struct dmirror *dmirror, return ret; } -static int dmirror_migrate(struct dmirror *dmirror, - struct hmm_dmirror_cmd *cmd) +static vm_fault_t dmirror_devmem_fault_alloc_and_copy(struct migrate_vma *args, + struct dmirror *dmirror) +{ + const unsigned long *src = args->src; + unsigned long *dst = args->dst; + unsigned long start = args->start; + unsigned long end = args->end; + unsigned long addr; + + for (addr = start; addr < end; addr += PAGE_SIZE, + src++, dst++) { + struct page *dpage, *spage; + + spage = migrate_pfn_to_page(*src); + if (!spage || !(*src & MIGRATE_PFN_MIGRATE)) + continue; + + if (WARN_ON(!is_device_private_page(spage) && + !is_device_coherent_page(spage))) + continue; + spage = BACKING_PAGE(spage); + dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr); + if (!dpage) + continue; + pr_debug("migrating from dev to sys pfn src: 0x%lx pfn dst: 0x%lx\n", + page_to_pfn(spage), page_to_pfn(dpage)); + + lock_page(dpage); + xa_erase(&dmirror->pt, addr >> PAGE_SHIFT); + copy_highpage(dpage, spage); + *dst = migrate_pfn(page_to_pfn(dpage)); + if (*src & MIGRATE_PFN_WRITE) + *dst |= MIGRATE_PFN_WRITE; + } + return 0; +} + +static unsigned long +dmirror_successful_migrated_pages(struct migrate_vma *migrate) +{ + unsigned long cpages = 0; + unsigned long i; + + for (i = 0; i < migrate->npages; i++) { + if (migrate->src[i] & MIGRATE_PFN_VALID && + migrate->src[i] & MIGRATE_PFN_MIGRATE) + cpages++; + } + return cpages; +} + +static int dmirror_migrate_to_system(struct dmirror *dmirror, + struct hmm_dmirror_cmd *cmd) { unsigned long start, end, addr; unsigned long size = cmd->npages << PAGE_SHIFT; struct mm_struct *mm = dmirror->notifier.mm; struct vm_area_struct *vma; - unsigned long src_pfns[64]; - unsigned long dst_pfns[64]; + unsigned long src_pfns[64] = { 0 }; + unsigned long dst_pfns[64] = { 0 }; + struct migrate_vma args; + unsigned long next; + int ret; + + start = cmd->addr; + end = start + size; + if (end < start) + return -EINVAL; + + /* Since the mm is for the mirrored process, get a reference first. */ + if (!mmget_not_zero(mm)) + return -EINVAL; + + cmd->cpages = 0; + mmap_read_lock(mm); + for (addr = start; addr < end; addr = next) { + vma = vma_lookup(mm, addr); + if (!vma || !(vma->vm_flags & VM_READ)) { + ret = -EINVAL; + goto out; + } + next = min(end, addr + (ARRAY_SIZE(src_pfns) << PAGE_SHIFT)); + if (next > vma->vm_end) + next = vma->vm_end; + + args.vma = vma; + args.src = src_pfns; + args.dst = dst_pfns; + args.start = addr; + args.end = next; + args.pgmap_owner = dmirror->mdevice; + args.flags = dmirror_select_device(dmirror); + + ret = migrate_vma_setup(&args); + if (ret) + goto out; + + pr_debug("Migrating from device mem to sys mem\n"); + dmirror_devmem_fault_alloc_and_copy(&args, dmirror); + + migrate_vma_pages(&args); + cmd->cpages += dmirror_successful_migrated_pages(&args); + migrate_vma_finalize(&args); + } +out: + mmap_read_unlock(mm); + mmput(mm); + + return ret; +} + +static int dmirror_migrate_to_device(struct dmirror *dmirror, + struct hmm_dmirror_cmd *cmd) +{ + unsigned long start, end, addr; + unsigned long size = cmd->npages << PAGE_SHIFT; + struct mm_struct *mm = dmirror->notifier.mm; + struct vm_area_struct *vma; + unsigned long src_pfns[64] = { 0 }; + unsigned long dst_pfns[64] = { 0 }; struct dmirror_bounce bounce; struct migrate_vma args; unsigned long next; @@ -854,6 +997,7 @@ static int dmirror_migrate(struct dmirror *dmirror, if (ret) goto out; + pr_debug("Migrating from sys mem to device mem\n"); dmirror_migrate_alloc_and_copy(&args, dmirror); migrate_vma_pages(&args); dmirror_migrate_finalize_and_map(&args, dmirror); @@ -862,7 +1006,10 @@ static int dmirror_migrate(struct dmirror *dmirror, mmap_read_unlock(mm); mmput(mm); - /* Return the migrated data for verification. */ + /* + * Return the migrated data for verification. + * Only for pages in device zone + */ ret = dmirror_bounce_init(&bounce, start, size); if (ret) return ret; @@ -905,6 +1052,12 @@ static void dmirror_mkentry(struct dmirror *dmirror, struct hmm_range *range, *perm = HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL; else *perm = HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE; + } else if (is_device_coherent_page(page)) { + /* Is the page migrated to this device or some other? */ + if (dmirror->mdevice == dmirror_page_to_device(page)) + *perm = HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL; + else + *perm = HMM_DMIRROR_PROT_DEV_COHERENT_REMOTE; } else if (is_zero_pfn(page_to_pfn(page))) *perm = HMM_DMIRROR_PROT_ZERO; else @@ -1092,8 +1245,12 @@ static long dmirror_fops_unlocked_ioctl(struct file *filp, ret = dmirror_write(dmirror, &cmd); break; - case HMM_DMIRROR_MIGRATE: - ret = dmirror_migrate(dmirror, &cmd); + case HMM_DMIRROR_MIGRATE_TO_DEV: + ret = dmirror_migrate_to_device(dmirror, &cmd); + break; + + case HMM_DMIRROR_MIGRATE_TO_SYS: + ret = dmirror_migrate_to_system(dmirror, &cmd); break; case HMM_DMIRROR_EXCLUSIVE: @@ -1155,14 +1312,13 @@ static const struct file_operations dmirror_fops = { static void dmirror_devmem_free(struct page *page) { - struct page *rpage = page->zone_device_data; + struct page *rpage = BACKING_PAGE(page); struct dmirror_device *mdevice; - if (rpage) + if (rpage != page) __free_page(rpage); mdevice = dmirror_page_to_device(page); - spin_lock(&mdevice->lock); mdevice->cfree++; page->zone_device_data = mdevice->free_pages; @@ -1170,43 +1326,11 @@ static void dmirror_devmem_free(struct page *page) spin_unlock(&mdevice->lock); } -static vm_fault_t dmirror_devmem_fault_alloc_and_copy(struct migrate_vma *args, - struct dmirror *dmirror) -{ - const unsigned long *src = args->src; - unsigned long *dst = args->dst; - unsigned long start = args->start; - unsigned long end = args->end; - unsigned long addr; - - for (addr = start; addr < end; addr += PAGE_SIZE, - src++, dst++) { - struct page *dpage, *spage; - - spage = migrate_pfn_to_page(*src); - if (!spage || !(*src & MIGRATE_PFN_MIGRATE)) - continue; - spage = spage->zone_device_data; - - dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr); - if (!dpage) - continue; - - lock_page(dpage); - xa_erase(&dmirror->pt, addr >> PAGE_SHIFT); - copy_highpage(dpage, spage); - *dst = migrate_pfn(page_to_pfn(dpage)); - if (*src & MIGRATE_PFN_WRITE) - *dst |= MIGRATE_PFN_WRITE; - } - return 0; -} - static vm_fault_t dmirror_devmem_fault(struct vm_fault *vmf) { struct migrate_vma args; - unsigned long src_pfns; - unsigned long dst_pfns; + unsigned long src_pfns = 0; + unsigned long dst_pfns = 0; struct page *rpage; struct dmirror *dmirror; vm_fault_t ret; @@ -1226,7 +1350,7 @@ static vm_fault_t dmirror_devmem_fault(struct vm_fault *vmf) args.src = &src_pfns; args.dst = &dst_pfns; args.pgmap_owner = dmirror->mdevice; - args.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; + args.flags = dmirror_select_device(dmirror); if (migrate_vma_setup(&args)) return VM_FAULT_SIGBUS; @@ -1305,6 +1429,12 @@ static int __init hmm_dmirror_init(void) HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; dmirror_devices[ndevices++].zone_device_type = HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; + if (spm_addr_dev0 && spm_addr_dev1) { + dmirror_devices[ndevices++].zone_device_type = + HMM_DMIRROR_MEMORY_DEVICE_COHERENT; + dmirror_devices[ndevices++].zone_device_type = + HMM_DMIRROR_MEMORY_DEVICE_COHERENT; + } for (id = 0; id < ndevices; id++) { ret = dmirror_device_init(dmirror_devices + id, id); if (ret) @@ -1327,7 +1457,8 @@ static void __exit hmm_dmirror_exit(void) int id; for (id = 0; id < DMIRROR_NDEVICES; id++) - dmirror_device_remove(dmirror_devices + id); + if (dmirror_devices[id].zone_device_type) + dmirror_device_remove(dmirror_devices + id); unregister_chrdev_region(dmirror_dev, DMIRROR_NDEVICES); } diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index f700da7807c1..e31d58c9034a 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -50,6 +50,8 @@ struct hmm_dmirror_cmd { * device the ioctl() is made * HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE: Migrated device private page on some * other device + * HMM_DMIRROR_PROT_DEV_COHERENT: Migrate device coherent page on the device + * the ioctl() is made */ enum { HMM_DMIRROR_PROT_ERROR = 0xFF, @@ -61,6 +63,8 @@ enum { HMM_DMIRROR_PROT_ZERO = 0x10, HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL = 0x20, HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE = 0x30, + HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL = 0x40, + HMM_DMIRROR_PROT_DEV_COHERENT_REMOTE = 0x50, }; enum { From patchwork Wed Jun 29 03:54:23 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: 12899279 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 61938C43334 for ; Wed, 29 Jun 2022 03:55:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 23FAA8E000E; Tue, 28 Jun 2022 23:55:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2151C8E000A; Tue, 28 Jun 2022 23:55:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE8798E000E; Tue, 28 Jun 2022 23:55:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D64928E000A for ; Tue, 28 Jun 2022 23:55:19 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AC322353BE for ; Wed, 29 Jun 2022 03:55:19 +0000 (UTC) X-FDA: 79629908358.12.3F934BF Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2061.outbound.protection.outlook.com [40.107.102.61]) by imf31.hostedemail.com (Postfix) with ESMTP id 39D0E20012 for ; Wed, 29 Jun 2022 03:55:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jYYLNnTehYorhQVcieibaKnJ3gAqICLUsKceV00InD4obbxdLXdO6Ij1mECvUYsjqgjVFWAHwttJFtp8y2fmtvfIFXlHxnFpUvq+viB8Ndalz8MJIJk7UDc/j72Ghxe3ZE90iUTE0takcfdgEOzfIRzkxZJyfvUIysNS8Mz3Hk64fBXIpaBSQvcIj5r1XEL1w2RIb5QOsVNwLibT9kzMEtm69PTuff5q42gCIUh7Juw/f/E5Hm12EfDL0JLL7B40/l5pogFJYNcKJIsCkxduow0qymyda7TgoKsfjRvjgxOU1129cEMo42LnFYETSEIVKfvaXEsPUGghQWZZgLoPtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FBYoUu7uH3DDQme91+PAxWkWEbnIBTP5UUW8lp9tsk8=; b=lxPB8UzNPUlPX7rFiO9ByJxdQlo3R/kUFBMnkhbzEhc9FSQNl1rvauoeQou+E/lUpUkAMDt9+6MCrq1xTKHPpVg78FnyhbNIjaXmGBn7nPmC3MR9HapS5ACaSAbYqXdnlwpV0bLji7EoHl8uTOuaqjw7QwHw+4FJG8gsmJqfKQxEswlCqgHHrnBgzC6Wuw1MDGHvjaluezpjhXTf5ow3bhiNm2N2bSb17NZTDYGFgEvJ5b/YJzbGh7skzQPFNwsz1uGnzBtzkz+oe+boRJ7ydYiVVsKz3XjpnTgacYWNxkEiMt2GhK5u8w1cBfodQldx3YF0Lgx/OWoF6MEAJfmAmw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FBYoUu7uH3DDQme91+PAxWkWEbnIBTP5UUW8lp9tsk8=; b=sGIN+Fhdy9i9XUfgm4ghRbGKboCmiLkyEciM8tMJc8PaNkXApx2MONpO6/xGYiBcWnIrbp0RQ/y+7tufzyNIBEpUyBNZ3DBSROk1orN0awKAQEbG2NdPNB1uCwVe7QmJAtym5WHZvzhfIOzOAVLTlGZjRGsEYQK0n6vMgB941kw= Received: from BN8PR12CA0020.namprd12.prod.outlook.com (2603:10b6:408:60::33) by SN6PR12MB2750.namprd12.prod.outlook.com (2603:10b6:805:77::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16; Wed, 29 Jun 2022 03:55:14 +0000 Received: from BN8NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:408:60:cafe::64) by BN8PR12CA0020.outlook.office365.com (2603:10b6:408:60::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16 via Frontend Transport; Wed, 29 Jun 2022 03:55:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT058.mail.protection.outlook.com (10.13.177.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:14 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 28 Jun 2022 22:55:12 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 11/14] tools: update hmm-test to support device coherent type Date: Tue, 28 Jun 2022 22:54:23 -0500 Message-ID: <20220629035426.20013-12-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: 31ff914e-6678-4da4-1659-08da59832c2f X-MS-TrafficTypeDiagnostic: SN6PR12MB2750:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SzbmQD08SjEGhDjfGSUJmYm1OvLuEo1ommtkFwJnjwpknCmcPJBNOEFahu1h1JnL9zgZ9u4nFKQ8gL9zRyZmvtPG6phIAIlqqf+dVBVlqvbxZNQkbZ1epbst6i/+ID11C+zAE8FagLQclij35IA3zLDQ2ays/Pdu/r7YzU80EjQcoQz+U9NkLACGsQp8T7G4Nq4UCDVCbdzlOzU+xKdI9DkdKqYoaUWpI4tY2buL7xNj2xNNuWZ0I8A2NUhq6UUTL5L9XhQqzRTO75ONBUqnugtuNj03xvEh9hm5hAgBslep18E4f83UkifyyWGakqwMihQrG/QQhNuggDT/rSQ38BWQU9BnVM7kPOQSq/2ehUYTj02A52rtrfzQRdooOOXm3JDkAjLORpQSi9Q/4X+s3qQAN6UC0sEEQN05kihboQZWlFWpFcwry5tONHjTfTffAF4aL2bBN4TrDxpyZjoQZpudeKew8Ptr+oypEk0nfSiuotArh/j9bFZ2rTiqhC6322SgVHLSECmuTQdvtKn1dhnreD7T46rA3ZsGYNyNfYdigr2KmgvEVnMAw86nBPXs66TbKCzHuFsrsdCk259wIJzbPO54UDjxDa/dYAfvjhbDSLYfLmR7P9yqYRUPrLOcQhPZwh++H+vZp2sGR4E73WImAEuUnNNAKIWP7/E1WIW3/RBdQ+6oXVrs+Glr+lu4TlixFT5GR68dPQHmsYXKKV44n9tJkpnIietyuY/+rmM10wjQBnfMHiNnFYVMWQ6y+Uh5FisXeHE07tA4UqRmHWQlPcR8VtlJbhLagR+UHrGUrL2vgy7pZZuWbJgQHZhWgYUSZRJtFMkliMuTo2znHA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(376002)(136003)(39860400002)(396003)(346002)(36840700001)(46966006)(40470700004)(6666004)(41300700001)(2906002)(36756003)(82310400005)(7416002)(44832011)(316002)(426003)(336012)(16526019)(70206006)(4326008)(8676002)(15650500001)(70586007)(47076005)(6916009)(186003)(54906003)(7696005)(82740400003)(81166007)(1076003)(2616005)(356005)(478600001)(8936002)(5660300002)(36860700001)(83380400001)(40460700003)(26005)(40480700001)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:14.2592 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31ff914e-6678-4da4-1659-08da59832c2f 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: BN8NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2750 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474919; a=rsa-sha256; cv=pass; b=gOHdSGcUs/kby5vUPgmReHJOs/sio3IN4GpfQlbOGPDHT0s837qyq1sYxfqdpd1xUcbbbB +37B/hJsfY+hsQajxh1PJsvHoaUU1Mzkaz+WcXogClkFlBGy4XwSRH9xwkYlz4GTaSoxQj Bdhmw1EZGpTJJcwz1OV8B51dzHpQwn4= ARC-Authentication-Results: i=2; imf31.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=sGIN+Fhd; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf31.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.102.61 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474919; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FBYoUu7uH3DDQme91+PAxWkWEbnIBTP5UUW8lp9tsk8=; b=4XHx/RV0OlZDe8jO6ulknXqGErDSYoREaDLNwMxHOSnkyFiqN/9ztUJhnaI/8s36kRnzlY ApNheRTiAVp2OowAG/JkE3aDqfMoSzcfJgbXXkLLRbTdc6XU0ax5tZs6QDyR1DreAQnwTq Rqvbh5j9TDt1pXI0MMRkCG4AKNPFB5M= X-Rspam-User: X-Stat-Signature: skzziksspf96dy6rkyeehpuaaaj6s7py X-Rspamd-Queue-Id: 39D0E20012 Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=sGIN+Fhd; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf31.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.102.61 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam03 X-HE-Tag: 1656474919-592754 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Test cases such as migrate_fault and migrate_multiple, were modified to explicit migrate from device to sys memory without the need of page faults, when using device coherent type. Snapshot test case updated to read memory device type first and based on that, get the proper returned results migrate_ping_pong test case added to test explicit migration from device to sys memory for both private and coherent zone types. Helpers to migrate from device to sys memory and vicerversa were also added. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Popple Signed-off-by: Christoph Hellwig --- tools/testing/selftests/vm/hmm-tests.c | 121 ++++++++++++++++++++----- 1 file changed, 100 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 203323967b50..4b547188ec40 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -46,6 +46,13 @@ struct hmm_buffer { uint64_t faults; }; +enum { + HMM_PRIVATE_DEVICE_ONE, + HMM_PRIVATE_DEVICE_TWO, + HMM_COHERENCE_DEVICE_ONE, + HMM_COHERENCE_DEVICE_TWO, +}; + #define TWOMEG (1 << 21) #define HMM_BUFFER_SIZE (1024 << 12) #define HMM_PATH_MAX 64 @@ -60,6 +67,21 @@ FIXTURE(hmm) unsigned int page_shift; }; +FIXTURE_VARIANT(hmm) +{ + int device_number; +}; + +FIXTURE_VARIANT_ADD(hmm, hmm_device_private) +{ + .device_number = HMM_PRIVATE_DEVICE_ONE, +}; + +FIXTURE_VARIANT_ADD(hmm, hmm_device_coherent) +{ + .device_number = HMM_COHERENCE_DEVICE_ONE, +}; + FIXTURE(hmm2) { int fd0; @@ -68,6 +90,24 @@ FIXTURE(hmm2) unsigned int page_shift; }; +FIXTURE_VARIANT(hmm2) +{ + int device_number0; + int device_number1; +}; + +FIXTURE_VARIANT_ADD(hmm2, hmm2_device_private) +{ + .device_number0 = HMM_PRIVATE_DEVICE_ONE, + .device_number1 = HMM_PRIVATE_DEVICE_TWO, +}; + +FIXTURE_VARIANT_ADD(hmm2, hmm2_device_coherent) +{ + .device_number0 = HMM_COHERENCE_DEVICE_ONE, + .device_number1 = HMM_COHERENCE_DEVICE_TWO, +}; + static int hmm_open(int unit) { char pathname[HMM_PATH_MAX]; @@ -81,12 +121,19 @@ static int hmm_open(int unit) return fd; } +static bool hmm_is_coherent_type(int dev_num) +{ + return (dev_num >= HMM_COHERENCE_DEVICE_ONE); +} + FIXTURE_SETUP(hmm) { self->page_size = sysconf(_SC_PAGE_SIZE); self->page_shift = ffs(self->page_size) - 1; - self->fd = hmm_open(0); + self->fd = hmm_open(variant->device_number); + if (self->fd < 0 && hmm_is_coherent_type(variant->device_number)) + SKIP(exit(0), "DEVICE_COHERENT not available"); ASSERT_GE(self->fd, 0); } @@ -95,9 +142,11 @@ FIXTURE_SETUP(hmm2) self->page_size = sysconf(_SC_PAGE_SIZE); self->page_shift = ffs(self->page_size) - 1; - self->fd0 = hmm_open(0); + self->fd0 = hmm_open(variant->device_number0); + if (self->fd0 < 0 && hmm_is_coherent_type(variant->device_number0)) + SKIP(exit(0), "DEVICE_COHERENT not available"); ASSERT_GE(self->fd0, 0); - self->fd1 = hmm_open(1); + self->fd1 = hmm_open(variant->device_number1); ASSERT_GE(self->fd1, 0); } @@ -211,6 +260,20 @@ static void hmm_nanosleep(unsigned int n) nanosleep(&t, NULL); } +static int hmm_migrate_sys_to_dev(int fd, + struct hmm_buffer *buffer, + unsigned long npages) +{ + return hmm_dmirror_cmd(fd, HMM_DMIRROR_MIGRATE_TO_DEV, buffer, npages); +} + +static int hmm_migrate_dev_to_sys(int fd, + struct hmm_buffer *buffer, + unsigned long npages) +{ + return hmm_dmirror_cmd(fd, HMM_DMIRROR_MIGRATE_TO_SYS, buffer, npages); +} + /* * Simple NULL test of device open/close. */ @@ -875,7 +938,7 @@ TEST_F(hmm, migrate) ptr[i] = i; /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -923,7 +986,7 @@ TEST_F(hmm, migrate_fault) ptr[i] = i; /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -936,7 +999,7 @@ TEST_F(hmm, migrate_fault) ASSERT_EQ(ptr[i], i); /* Migrate memory to the device again. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -976,7 +1039,7 @@ TEST_F(hmm, migrate_shared) ASSERT_NE(buffer->ptr, MAP_FAILED); /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, -ENOENT); hmm_buffer_free(buffer); @@ -1015,7 +1078,7 @@ TEST_F(hmm2, migrate_mixed) p = buffer->ptr; /* Migrating a protected area should be an error. */ - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, npages); ASSERT_EQ(ret, -EINVAL); /* Punch a hole after the first page address. */ @@ -1023,7 +1086,7 @@ TEST_F(hmm2, migrate_mixed) ASSERT_EQ(ret, 0); /* We expect an error if the vma doesn't cover the range. */ - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, 3); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, 3); ASSERT_EQ(ret, -EINVAL); /* Page 2 will be a read-only zero page. */ @@ -1055,13 +1118,13 @@ TEST_F(hmm2, migrate_mixed) /* Now try to migrate pages 2-5 to device 1. */ buffer->ptr = p + 2 * self->page_size; - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, 4); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, 4); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, 4); /* Page 5 won't be migrated to device 0 because it's on device 1. */ buffer->ptr = p + 5 * self->page_size; - ret = hmm_dmirror_cmd(self->fd0, HMM_DMIRROR_MIGRATE, buffer, 1); + ret = hmm_migrate_sys_to_dev(self->fd0, buffer, 1); ASSERT_EQ(ret, -ENOENT); buffer->ptr = p; @@ -1070,8 +1133,12 @@ TEST_F(hmm2, migrate_mixed) } /* - * Migrate anonymous memory to device private memory and fault it back to system - * memory multiple times. + * Migrate anonymous memory to device memory and back to system memory + * multiple times. In case of private zone configuration, this is done + * through fault pages accessed by CPU. In case of coherent zone configuration, + * the pages from the device should be explicitly migrated back to system memory. + * The reason is Coherent device zone has coherent access by CPU, therefore + * it will not generate any page fault. */ TEST_F(hmm, migrate_multiple) { @@ -1107,8 +1174,7 @@ TEST_F(hmm, migrate_multiple) ptr[i] = i; /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, - npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -1116,7 +1182,13 @@ TEST_F(hmm, migrate_multiple) for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i) ASSERT_EQ(ptr[i], i); - /* Fault pages back to system memory and check them. */ + /* Migrate back to system memory and check them. */ + if (hmm_is_coherent_type(variant->device_number)) { + ret = hmm_migrate_dev_to_sys(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + } + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) ASSERT_EQ(ptr[i], i); @@ -1354,13 +1426,13 @@ TEST_F(hmm2, snapshot) /* Page 5 will be migrated to device 0. */ buffer->ptr = p + 5 * self->page_size; - ret = hmm_dmirror_cmd(self->fd0, HMM_DMIRROR_MIGRATE, buffer, 1); + ret = hmm_migrate_sys_to_dev(self->fd0, buffer, 1); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, 1); /* Page 6 will be migrated to device 1. */ buffer->ptr = p + 6 * self->page_size; - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, 1); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, 1); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, 1); @@ -1377,9 +1449,16 @@ TEST_F(hmm2, snapshot) ASSERT_EQ(m[2], HMM_DMIRROR_PROT_ZERO | HMM_DMIRROR_PROT_READ); ASSERT_EQ(m[3], HMM_DMIRROR_PROT_READ); ASSERT_EQ(m[4], HMM_DMIRROR_PROT_WRITE); - ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL | - HMM_DMIRROR_PROT_WRITE); - ASSERT_EQ(m[6], HMM_DMIRROR_PROT_NONE); + if (!hmm_is_coherent_type(variant->device_number0)) { + ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL | + HMM_DMIRROR_PROT_WRITE); + ASSERT_EQ(m[6], HMM_DMIRROR_PROT_NONE); + } else { + ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL | + HMM_DMIRROR_PROT_WRITE); + ASSERT_EQ(m[6], HMM_DMIRROR_PROT_DEV_COHERENT_REMOTE | + HMM_DMIRROR_PROT_WRITE); + } hmm_buffer_free(buffer); } From patchwork Wed Jun 29 03:54:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12899278 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 8F0E2C433EF for ; Wed, 29 Jun 2022 03:55:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 943C78E000D; Tue, 28 Jun 2022 23:55:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A64F8E000A; Tue, 28 Jun 2022 23:55:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F6C98E000D; Tue, 28 Jun 2022 23:55:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5D3E78E000A for ; Tue, 28 Jun 2022 23:55:18 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3B20C212CA for ; Wed, 29 Jun 2022 03:55:18 +0000 (UTC) X-FDA: 79629908316.25.0E98A4D Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by imf08.hostedemail.com (Postfix) with ESMTP id D2235160034 for ; Wed, 29 Jun 2022 03:55:17 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lm5u8lhIDZUNDWB65yF1rU0LwVwiqHzfFVdxBnK4mtgNMg0Bca81U+DosPNgOC+jSNIKTf6NhOKCTKRGzFrOQvSQkImNnx6+9W0TxDacJTndr1WIc8H4gaZMTcHPq14ARd2ECN5BCbfjI1vwpYqfNkOW2ifnFP5zTrENK9QPwqkXQ+yciE5iGoFORK4zCr2n4Ww+gRj4CM2NrwwRYLzLdKROZeQNNyh2TSe4GGsauDQwIiB3aRhoFRyaKuiNRbwNDfpcNmIW9fIllrnYxxzAW4jqCBo5RKwDJX0MGY1SkxJnGRC//9RlZdDrAFR+X33V6jf6yRss2bXUCSkQ3ZN8gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ds2C6hKBCPm3LMFGvWFrTQmYNyEijOJ3/DIUhvifx8M=; b=hzepG4Uspx0L6nXQvLSQddqjhZQXCl/2vT4H1LBlvs7mgja9i9U41VoJiN+ZMVZKhgHo+tdJW885aHl81r0UNc8MhlDQSzfCWU9rxvT9DLoiwGQiXrZOA7ssVB9VbY7KsdRUt/vXEwGTkUpQekkif+ktLPTzhOX6zEZHzt88LVyr0wE/Yjqc2a13/NEHFeM6dyl+lG6Zv/t0xviPEPo4CB3bZq6qsH1vl6c6eeRTEDIfta8gDQva2w3oKoVLEw1JCBPSTdPt5G5/J0YcKex1Orgz25Rj+EsmPj6006hFbzprFunXr3zMzSDggNwcAuUeoH/bjQ38XtL1ODmcjGTeKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ds2C6hKBCPm3LMFGvWFrTQmYNyEijOJ3/DIUhvifx8M=; b=zW+uOEC3v80zhr9Bt/FX/lHLw2zMYs9xjyJqEKr8JZc969gEIFpTBdh7D5w+GBy1TBdU/+fp5XqiDo6dnDOLj7kUyO9lB+g/hxDRndpJ4X9b9y76JzHgff0WjOmXa0hPYf8MiAe40ghcsg+IZJjFo1k4aJIK3TEUNax5SeM9ZFo= Received: from BN8PR12CA0036.namprd12.prod.outlook.com (2603:10b6:408:60::49) by CY4PR12MB1783.namprd12.prod.outlook.com (2603:10b6:903:121::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16; Wed, 29 Jun 2022 03:55:15 +0000 Received: from BN8NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:408:60:cafe::55) by BN8PR12CA0036.outlook.office365.com (2603:10b6:408:60::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17 via Frontend Transport; Wed, 29 Jun 2022 03:55:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT058.mail.protection.outlook.com (10.13.177.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:14 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 28 Jun 2022 22:55:13 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 12/14] tools: update test_hmm script to support SP config Date: Tue, 28 Jun 2022 22:54:24 -0500 Message-ID: <20220629035426.20013-13-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: 27cab191-828e-4623-3751-08da59832c93 X-MS-TrafficTypeDiagnostic: CY4PR12MB1783:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S9RNIyiRYRhBajAypwHhj+a6KL2MJwmklesOyK5Y1LEDXL2XH3/ptW5Vo75crGF1KkduejS2R+bltYHK+s4hHBy2pLxaPXG/vletSeiPvyBdqodbu6SHppyvlRZW9rZjIuhNxSysOOknJp54mEe8KWa4hbbKPznlUcRpb5JhJa4Catw0Zif09busUWZ5Ga3SjKlajNVAj+Q3fSI4/Vs9qokbDdkDs2UmmGSK6+o5KjLLMJz6WgVktRkvdnq8IbQFqEpgVJ6CtOpXIulIOYWOR8KNdNGyqu1N/p/qh7i9OfvEhoEY9+ujUvZL6lZn4MMMUcCUUvibutNraReGGBgswZfDc5J4BFJr0RkNAS82UmnYf92QuRgdPwRQSJ+UZeTNrgeKW2vjYwMlc76oHvbRBYE8ASYF82AZ206qnm6jhdAtEs1Po8yWGCkspmsru+QUCrnsO1dfctw5yYvrT70aPo7vpnjgvoa/Ib1BvEXsn+X3/ImWG+l1uwZS2wdGzPpeRCulp8NyWEzd+Ur/W38jGwwYNwoBWkfst+wsdOEl9cIxpXQS1Rz1GeMUhgrQPMLuiSFK6o9fi4QLd86Cfhza5Z16JEAOmnfeFGVWXysOijXz7/XCTAS1m0n+TsDhnLvJXMNAzWLSuZ/b7HEQNaOw903rhYAeIknzvE+fW65SFcCHsQxBRuuoGRum/rXGJ9zG4klvrfn2K//q9LShYs7ovwqK29pCKShlaqIPEMjiRrVqkyvhZRKqfVdr9X3tLUPUYuFQ8UM6E+I7WHu72Mtv+oIVdKmG2Djc2WjUCfiJYMHE+kRqRq3P6n0rsziHq3+f0egTeIgbW9sp9DAXhg5SRA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(136003)(39860400002)(396003)(376002)(346002)(40470700004)(36840700001)(46966006)(356005)(8676002)(82740400003)(1076003)(6916009)(36756003)(70206006)(16526019)(47076005)(54906003)(316002)(186003)(36860700001)(4326008)(70586007)(82310400005)(83380400001)(40460700003)(2616005)(44832011)(7416002)(26005)(426003)(40480700001)(2906002)(8936002)(41300700001)(336012)(5660300002)(478600001)(86362001)(81166007)(6666004)(7696005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:14.8998 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 27cab191-828e-4623-3751-08da59832c93 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: BN8NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1783 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474917; a=rsa-sha256; cv=pass; b=Dpe/YJkTEdGxFI9tkHFijb7M2/XEzf4iJ/Vw4H1j4lXM3KPIYRX2XDHisxffwFmF7+pd2Q LfOJk+NC/jZNEZ+4qOgTamGkWxRxLQfrWfEt6EF1WV68yl01SvrIPgzkUK/AeCzJ6LpYlT GbphZOZYEDGd8ysSYd4dph8z0yre+G0= ARC-Authentication-Results: i=2; imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=zW+uOEC3; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf08.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.41 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474917; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ds2C6hKBCPm3LMFGvWFrTQmYNyEijOJ3/DIUhvifx8M=; b=OOyzRLfl00Ws3uf98ObKKk68y7PtQ/SFnPEo4i8EUt4u2Gq+XHfWJEYwMm1N9BQjUWCJMh xGlNHSeB/zg2bpTuX6ujMEetRX1X/hl2nWTnDuOFgY2kbJMM8MvKlre4/JCBY3k3187wdW HO3/HqTo1EjIF+8AAkNHWNJtc90jrjU= X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=zW+uOEC3; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf08.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.41 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam02 X-Stat-Signature: pjkby3rqm8zkp9p7wf731n5m6soi36n7 X-Rspamd-Queue-Id: D2235160034 X-HE-Tag: 1656474917-47738 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add two more parameters to set spm_addr_dev0 & spm_addr_dev1 addresses. These two parameters configure the start SP addresses for each device in test_hmm driver. Consequently, this configures zone device type as coherent. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Popple Signed-off-by: Christoph Hellwig --- tools/testing/selftests/vm/test_hmm.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/vm/test_hmm.sh b/tools/testing/selftests/vm/test_hmm.sh index 0647b525a625..539c9371e592 100755 --- a/tools/testing/selftests/vm/test_hmm.sh +++ b/tools/testing/selftests/vm/test_hmm.sh @@ -40,11 +40,26 @@ check_test_requirements() load_driver() { - modprobe $DRIVER > /dev/null 2>&1 + if [ $# -eq 0 ]; then + modprobe $DRIVER > /dev/null 2>&1 + else + if [ $# -eq 2 ]; then + modprobe $DRIVER spm_addr_dev0=$1 spm_addr_dev1=$2 + > /dev/null 2>&1 + else + echo "Missing module parameters. Make sure pass"\ + "spm_addr_dev0 and spm_addr_dev1" + usage + fi + fi if [ $? == 0 ]; then major=$(awk "\$2==\"HMM_DMIRROR\" {print \$1}" /proc/devices) mknod /dev/hmm_dmirror0 c $major 0 mknod /dev/hmm_dmirror1 c $major 1 + if [ $# -eq 2 ]; then + mknod /dev/hmm_dmirror2 c $major 2 + mknod /dev/hmm_dmirror3 c $major 3 + fi fi } @@ -58,7 +73,7 @@ run_smoke() { echo "Running smoke test. Note, this test provides basic coverage." - load_driver + load_driver $1 $2 $(dirname "${BASH_SOURCE[0]}")/hmm-tests unload_driver } @@ -75,6 +90,9 @@ usage() echo "# Smoke testing" echo "./${TEST_NAME}.sh smoke" echo + echo "# Smoke testing with SPM enabled" + echo "./${TEST_NAME}.sh smoke " + echo exit 0 } @@ -84,7 +102,7 @@ function run_test() usage else if [ "$1" = "smoke" ]; then - run_smoke + run_smoke $2 $3 else usage fi From patchwork Wed Jun 29 03:54:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12899280 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 3CD2ECCA47C for ; Wed, 29 Jun 2022 03:55:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54D9F8E000A; Tue, 28 Jun 2022 23:55:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 416CB8E0010; Tue, 28 Jun 2022 23:55:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C87F8E000F; Tue, 28 Jun 2022 23:55:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EF9B38E000A for ; Tue, 28 Jun 2022 23:55:19 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C8878204C2 for ; Wed, 29 Jun 2022 03:55:19 +0000 (UTC) X-FDA: 79629908358.07.7003C55 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2077.outbound.protection.outlook.com [40.107.94.77]) by imf19.hostedemail.com (Postfix) with ESMTP id 440AD1A002D for ; Wed, 29 Jun 2022 03:55:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IsUSwtol4C6h8b87GvjbMrx7NkWibYLz5Smwy0QUOGdfAVpacezI1KmYDGNJuAKJrbnCXia8CuOw1GLXgemwJrJ7rvjHjmaO0okztOsEVuvL/ibQnfamxa2jsbhTnCQXrMPhZ71Q5bZcuIIFK9mi7glrayXVw5oVScM1691gUfO9ve2EsPC5V7CSyXYYck8OGfZ8dG13qphDr16zI4aYU7b8m0Mc+GxB2B6EfPLkhUfUpEPIBSqiB8uNMPATPgdah+nGKIQTCeyufq+5gzZEcWzUkC7M4bRa2ii1nosslTBTZvZ7QNOm013GbHjrbkOtCmqlA/UaCfjE0Io0khWtaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GP3ikngykfp62hqgKGCY9CKncoZ/5EVzq4BZbbmWmCY=; b=AMErRuYkq0NO0Y1IlLcFHtzGWCoFq4Is92Pme3y5XWODbFBhwx98sNmBzqfxNnwUmhxWOK3/hp9WpXs2q3WhJPtyyCxPtOmuDRicAxWyN4bOL3RHQRBE3AszvJAhL2jNGrio4ovnRtFYUbctc36ZuYga7+Z1yVcMnR5Lbgq2jDtGC8Xz3n5g6DBi0IWyCOhEIBRktil5P32jcDVmiuRQwTLIiLDU6Qjgk9W0wSkM9EMFbwFg0P0f2T2uTtCEtxrCSvl4uWB5wN847zl8uCKot1XO/5zcC3nuAL9RfRAAPJY2RUb/X0w6K9jaJl9kjfD4rJwveXPx/R3IggxGQwpB6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GP3ikngykfp62hqgKGCY9CKncoZ/5EVzq4BZbbmWmCY=; b=HQPMkY49fMqSnNKr/LtxHNxTc4EBC9YwhfE3A3VI1RovS6wzo17ciCajZUV9dMgwFEoFetEIRtBoN8+ugknt5NzG0dAqR4rwHlFXbmRWXi0rNbJkfIiszMHOqlqjWRlDgPyB5U+tkDuzZxDaFQxMyHSPU5JUbxeClozdjlE+peg= Received: from BN8PR12CA0029.namprd12.prod.outlook.com (2603:10b6:408:60::42) by BN9PR12MB5177.namprd12.prod.outlook.com (2603:10b6:408:11a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.18; Wed, 29 Jun 2022 03:55:15 +0000 Received: from BN8NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:408:60:cafe::7f) by BN8PR12CA0029.outlook.office365.com (2603:10b6:408:60::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14 via Frontend Transport; Wed, 29 Jun 2022 03:55:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT058.mail.protection.outlook.com (10.13.177.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:15 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 28 Jun 2022 22:55:14 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 13/14] tools: add hmm gup tests for device coherent type Date: Tue, 28 Jun 2022 22:54:25 -0500 Message-ID: <20220629035426.20013-14-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: 3dc08675-f2dc-4912-43d3-08da59832d03 X-MS-TrafficTypeDiagnostic: BN9PR12MB5177:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +67CD9ktETj5jDzqsApf/H7mPjL/hGizzgVv2qhcVu8p00s9y2EEaiZiEgTW9XTdLQijFtlWpQP8QtM9cF1muDAVQ0b1O/ozdOeYgCb+cvT//iCtpPN0/V+gaEZ7xpam55UsJdekpBCtcglf2DUqeSeMgVZuc1+eIkNcviedprhoWyqbAEKf+bHy30fClOEHdysUH7rNYgGe79ATkYsxGHjkFpNAXWpFsh+oILxd0/1eovSGg7B55g3BcnZ2IiBxSAzc/0NVQs/9CnOrU3amVjgXEbd8HycjogqVKfngz9vvF9mq8DCwCvmefzimhs+YiNdC7U4q3BQFzLWDn1JsUw44ure/t2+J3TaoBkdnso7GpKrA8yPlU3fHHG//cz/Mc0xUoXsfcvf3J/ZUGFeYtFFtExsVnkir/rlI8dMutgiTIp6sntXIj2Ck3UQYHhdIgUvBFfJ02B0TRfxhvMzynDi/n5BHPQc6fB90O8v20NNznJdw2GJgE/F1P7GS3nofYuFeu0KXT2vLvVhjpMIhfyhC10FmcfghbWdU+9luC8BhWda3hRl9wFxvLEAiK1S64b1XKgCerLIjZBjr7eHJYSpwYCZwWc/Kq335rLst0euE0W5v25QEZdzph1RToB51L2yIFAOZJNeE2Wv9pvwqWgpmoXn+ahAaRdf3h5GyI8HxKXKllOdKRpBRpdHofqpC2/TwsfuWcyUV2rwt10YpDDjgIjO43VeaHxHD+JWwoDZIppm+cXgh+oJYDXPawrqKRtwYu0d1mZJQ1Nr8PmnhxFLfbZncPMz/k2rxmlacVgywLMfucyTq1itw1tJKXQUy0xXRJVTjR06XxXSujv7Dlw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(396003)(39860400002)(376002)(136003)(346002)(46966006)(36840700001)(40470700004)(478600001)(2906002)(82310400005)(70586007)(40480700001)(356005)(40460700003)(36756003)(7696005)(86362001)(26005)(6666004)(6916009)(54906003)(8676002)(82740400003)(70206006)(316002)(47076005)(186003)(41300700001)(44832011)(2616005)(426003)(83380400001)(16526019)(1076003)(5660300002)(8936002)(81166007)(7416002)(36860700001)(4326008)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:15.6498 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3dc08675-f2dc-4912-43d3-08da59832d03 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: BN8NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5177 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474919; a=rsa-sha256; cv=pass; b=cQ3sKH4cwNTBWhiZlblCrPjt9Dnxdv9ots31J7Q3dgZO7aJWr6mBEreMfJba+PRYASqvJb lMkq0PMcUtZzxvNu5hAV5S18JHXqZQ7oOf9f6cwQCVj2zMA+0GSDBkPU+8GgTN63W42Ax5 tcde/n3vd9u7Uq/Tw0sZmrPpuQUKcyM= ARC-Authentication-Results: i=2; imf19.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=HQPMkY49; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf19.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.77 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474919; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GP3ikngykfp62hqgKGCY9CKncoZ/5EVzq4BZbbmWmCY=; b=Oa+jVbauhhn600HND+SqgUPq/xgalF6RZa33asc98uPf7tNyxuXpWLYPlC19GUb5f79jdX Etk9BxqWxdNPcqiIZVp/fgcqRvHNuZYHTuUkrjkq8tBHqbbAYBr1nuWhKTtEkItP0BjMOc oCyHEdLTdH0TaJ5+VDcaBrbCs6Y8xgM= X-Stat-Signature: wkwio9nefdfqp4cpdshr5xekbbdne5f7 X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 440AD1A002D Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=HQPMkY49; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf19.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.77 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1656474919-330715 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The intention is to test hmm device coherent type under different get user pages paths. Also, test gup with FOLL_LONGTERM flag set in device coherent pages. These pages should get migrated back to system memory. Signed-off-by: Alex Sierra Reviewed-by: Alistair Popple --- tools/testing/selftests/vm/hmm-tests.c | 110 +++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 4b547188ec40..bb38b9777610 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -36,6 +36,7 @@ * in the usual include/uapi/... directory. */ #include "../../../../lib/test_hmm_uapi.h" +#include "../../../../mm/gup_test.h" struct hmm_buffer { void *ptr; @@ -59,6 +60,9 @@ enum { #define NTIMES 10 #define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1))) +/* Just the flags we need, copied from mm.h: */ +#define FOLL_WRITE 0x01 /* check pte is writable */ +#define FOLL_LONGTERM 0x10000 /* mapping lifetime is indefinite */ FIXTURE(hmm) { @@ -1764,4 +1768,110 @@ TEST_F(hmm, exclusive_cow) hmm_buffer_free(buffer); } +static int gup_test_exec(int gup_fd, unsigned long addr, int cmd, + int npages, int size, int flags) +{ + struct gup_test gup = { + .nr_pages_per_call = npages, + .addr = addr, + .gup_flags = FOLL_WRITE | flags, + .size = size, + }; + + if (ioctl(gup_fd, cmd, &gup)) { + perror("ioctl on error\n"); + return errno; + } + + return 0; +} + +/* + * Test get user device pages through gup_test. Setting PIN_LONGTERM flag. + * This should trigger a migration back to system memory for both, private + * and coherent type pages. + * This test makes use of gup_test module. Make sure GUP_TEST_CONFIG is added + * to your configuration before you run it. + */ +TEST_F(hmm, hmm_gup_test) +{ + struct hmm_buffer *buffer; + int gup_fd; + unsigned long npages; + unsigned long size; + unsigned long i; + int *ptr; + int ret; + unsigned char *m; + + gup_fd = open("/sys/kernel/debug/gup_test", O_RDWR); + if (gup_fd == -1) + SKIP(return, "Skipping test, could not find gup_test driver"); + + npages = 4; + size = npages << self->page_shift; + + buffer = malloc(sizeof(*buffer)); + ASSERT_NE(buffer, NULL); + + buffer->fd = -1; + buffer->size = size; + buffer->mirror = malloc(size); + ASSERT_NE(buffer->mirror, NULL); + + buffer->ptr = mmap(NULL, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + buffer->fd, 0); + ASSERT_NE(buffer->ptr, MAP_FAILED); + + /* Initialize buffer in system memory. */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ptr[i] = i; + + /* Migrate memory to device. */ + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + /* Check what the device read. */ + for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); + + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr, + GUP_BASIC_TEST, 1, self->page_size, 0), 0); + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr + 1 * self->page_size, + GUP_FAST_BENCHMARK, 1, self->page_size, 0), 0); + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr + 2 * self->page_size, + PIN_FAST_BENCHMARK, 1, self->page_size, FOLL_LONGTERM), 0); + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr + 3 * self->page_size, + PIN_LONGTERM_BENCHMARK, 1, self->page_size, 0), 0); + + /* Take snapshot to CPU pagetables */ + ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + m = buffer->mirror; + if (hmm_is_coherent_type(variant->device_number)) { + ASSERT_EQ(HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL | HMM_DMIRROR_PROT_WRITE, m[0]); + ASSERT_EQ(HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL | HMM_DMIRROR_PROT_WRITE, m[1]); + } else { + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[0]); + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[1]); + } + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[2]); + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[3]); + /* + * Check again the content on the pages. Make sure there's no + * corrupted data. + */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); + + close(gup_fd); + hmm_buffer_free(buffer); +} TEST_HARNESS_MAIN From patchwork Wed Jun 29 03:54:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12899281 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 1ACD5C433EF for ; Wed, 29 Jun 2022 03:55:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF0086B0071; Tue, 28 Jun 2022 23:55:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA0EC8E0003; Tue, 28 Jun 2022 23:55:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91A418E0002; Tue, 28 Jun 2022 23:55:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 821546B0071 for ; Tue, 28 Jun 2022 23:55:41 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5EECA612DA for ; Wed, 29 Jun 2022 03:55:41 +0000 (UTC) X-FDA: 79629909282.11.FBFA2CF Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2072.outbound.protection.outlook.com [40.107.92.72]) by imf08.hostedemail.com (Postfix) with ESMTP id E45CA16002F for ; Wed, 29 Jun 2022 03:55:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HyvlGl3XuwEPA3DAbviLZj0t6ezx6eS2LvWbFhQ6qwoqfhKuI8n4Vm5A3I8nSj/csCRMg0Sm4TOWXbOcpw++MjxMEJpgAewgMBD2FLBJRLb+y8g59FK71wIIbB3ak/0FY/k77FM3lGj7v/8GOfj/teEY6oM96PH6noQqrpAEKWDWZ/z0xH9TDRfS+zPnqtecLNIzkgN1a4y/188moHUVWiS7qaeLOTp3KJW3D4MpidwwVg1Mpq88itW80NFCE25bUQp80/TIF22hnzVFNaSHrT0JU4f9WxvNqkTD6EyJmOw5ehDPyMaOa/3sE1PrVUIAU89uRoAdF9JOB+Pm0fl5QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ghINYxYAaP35msqhqy+uXLJjlA8u9eNbkgf4YFEOveA=; b=dnSkhpXB6X3ZTpWF7MdLfFP/XAVsh/p905IioKjFd6jUafM3wO2ZsXpoVFYYpMUetu/+hLrUt9m5ZGPa+p/mmXhvPFz6n91wo77g38howRVINhXRig5YmVHYF851iMPFSFDTP2DPBGYQ2MZJ/RwRpAgD6AGUzP/sSarMNS+cvLAwDvRjullIBDEe6jGPqI7zGyQu/YJzE8RMqTGwlMwrp14xI9glaB4G7w3HjiYm+oJscnKE4L60YcjmggBlyeS3vcr7SX0uoZC3LsQr6jF9ufhGEVCXDquw75hXgqRZ0Rxu0ferxAIRLNpYhO1TgQvC6I3ieh/IeL0WZemc2iGwZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ghINYxYAaP35msqhqy+uXLJjlA8u9eNbkgf4YFEOveA=; b=K81oENj98EF1QcQLUJ4pMag6GMJN/mH+DFF7PUGa3mcDfaljWtmeEBMDLK8dKQYLvOOM4tUf5IpMSldGBo9zomJ8BdEQ56HHztvyWgC46uZ3SjMcrMgKmYutDpQjHl1234tIx6KyCZl3S36Zgd9SfnLYZ/y4QozRqeBDSsK1xoc= Received: from DM6PR11CA0039.namprd11.prod.outlook.com (2603:10b6:5:14c::16) by MN2PR12MB3360.namprd12.prod.outlook.com (2603:10b6:208:c7::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17; Wed, 29 Jun 2022 03:55:37 +0000 Received: from DM6NAM11FT026.eop-nam11.prod.protection.outlook.com (2603:10b6:5:14c:cafe::90) by DM6PR11CA0039.outlook.office365.com (2603:10b6:5:14c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT026.mail.protection.outlook.com (10.13.172.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5373.15 via Frontend Transport; Wed, 29 Jun 2022 03:55:37 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 28 Jun 2022 22:55:15 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v7 14/14] tools: add selftests to hmm for COW in device memory Date: Tue, 28 Jun 2022 22:54:26 -0500 Message-ID: <20220629035426.20013-15-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220629035426.20013-1-alex.sierra@amd.com> References: <20220629035426.20013-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: 35ccc442-4936-46ef-d565-08da598339ca X-MS-TrafficTypeDiagnostic: MN2PR12MB3360:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sohPt/tLKahvcUc+fgO7WJRI0HUuXtEEmYQJUojtfwUI5p8JfST88odGxz9+58Q+eV3hQJSesDctosNpnmf5pSA9IWhi/MHqHKIJmJmckFCICqAnKaH/vU7uIG6h2MtY/jLAisfs8aCS7lrptnuYaWE8p/XhWzmnT3/VXjTYfM4gGT5YafvxLjkFpHoxQi0V9ZN8pq4crpnt5Vh7Ksff3p0bn0OxBTYfqJoHZfbrJQatk5nvLOFp84yHDDFNYeoFncjzDkCrMFxcorJ48AyhdviWHgmMEf3svLvbYSf+6KAA9YBB6347YaKGx8A65aJHLYYrc3cmp+39zkv+xIj8ARunLcwd1FFZI/H4QF5poF9drQFKsXYKHY30io28jTuxU4Ri2I5AvHJB6Mt0tEi63EneVg8omJF3qtRvmWgdsJtPtJ7vwDh6u98w9ULeqvKIBBAR1dL3j8so4thL2uNj5qP88W+kr/uBQbbBWKRuN4faE3TzIDPlvXvjk1jakJtsyDWKjc1t0JWoSLVJYveyC293pa7j2uBlY9zZpuwOjHjyatn+Rxa7oRbcyuu16GbslBST0c43dbi80WrOiIti5d5XcaRECoPG12j4gtFdVZWbdET8ZYIX2WOdoxxrNtfHnd5zA8z1+RXjoTgU4460P1p0MxxuIJX4EWzX+6f7+wTQTARVNKxSLPIu08GjUp36ozOnWXuYIPOA19/72Fhrs9UfqTj00vD3S94jWZd3ctNya434Sk+bMLWJLALkddDjxRI5Pl5wqCPBNsiR7xl6vtUsloazcDtlgzDCTZ9Chzblvbo421+qh9hIjhCZECMAOY6obTKnQoZO4aENFhQsuQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(136003)(376002)(39860400002)(346002)(396003)(46966006)(40470700004)(36840700001)(2616005)(1076003)(16526019)(47076005)(83380400001)(8936002)(336012)(186003)(86362001)(82740400003)(36860700001)(356005)(7416002)(36756003)(81166007)(5660300002)(426003)(44832011)(82310400005)(40480700001)(2906002)(41300700001)(8676002)(26005)(7696005)(70206006)(40460700003)(316002)(70586007)(6666004)(6916009)(54906003)(4326008)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 03:55:37.0122 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 35ccc442-4936-46ef-d565-08da598339ca 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: DM6NAM11FT026.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3360 ARC-Authentication-Results: i=2; imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=K81oENj9; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf08.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.92.72 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656474941; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ghINYxYAaP35msqhqy+uXLJjlA8u9eNbkgf4YFEOveA=; b=NZeTHwef7eI9qNYURKVwgSEJ0qnCApEVaoYiTKTMrSyDIJlQ/NvLivtqn3Lx+hYbSRhPIL y7VL5CYWAXye4AfWi9tKtDKyIRQOkWodTNFGkJhEaIdbqmY4cM82dSHscYjC6itCQI7EXS sKDqLuUD6TQEPH8thCcgyoQLe2PlYiY= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656474941; a=rsa-sha256; cv=pass; b=pxJ31H5LetzQW7lTutksgrPdILbxa4o+itIAOsa87tix2srcOsuhgu8AnygDg4mljyhd0k 3nxxb604WqvHuQ2p7vk5FrRDNi57gejYDELPqN+Ldn/TzQ6QN8umGSLm3odYOEhgoJWxO1 LYYVue11MrnS3VNgn//s8zrFN5lLWKw= X-Stat-Signature: st6zt3yia68c7u63jd9aan14665dhzoc X-Rspamd-Queue-Id: E45CA16002F X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=K81oENj9; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf08.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.92.72 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspamd-Server: rspam12 X-HE-Tag: 1656474940-369866 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The objective is to test device migration mechanism in pages marked as COW, for private and coherent device type. In case of writing to COW private page(s), a page fault will migrate pages back to system memory first. Then, these pages will be duplicated. In case of COW device coherent type, pages are duplicated directly from device memory. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling --- tools/testing/selftests/vm/hmm-tests.c | 80 ++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index bb38b9777610..716b62c05e3d 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -1874,4 +1874,84 @@ TEST_F(hmm, hmm_gup_test) close(gup_fd); hmm_buffer_free(buffer); } + +/* + * Test copy-on-write in device pages. + * In case of writing to COW private page(s), a page fault will migrate pages + * back to system memory first. Then, these pages will be duplicated. In case + * of COW device coherent type, pages are duplicated directly from device + * memory. + */ +TEST_F(hmm, hmm_cow_in_device) +{ + struct hmm_buffer *buffer; + unsigned long npages; + unsigned long size; + unsigned long i; + int *ptr; + int ret; + unsigned char *m; + pid_t pid; + int status; + + npages = 4; + size = npages << self->page_shift; + + buffer = malloc(sizeof(*buffer)); + ASSERT_NE(buffer, NULL); + + buffer->fd = -1; + buffer->size = size; + buffer->mirror = malloc(size); + ASSERT_NE(buffer->mirror, NULL); + + buffer->ptr = mmap(NULL, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + buffer->fd, 0); + ASSERT_NE(buffer->ptr, MAP_FAILED); + + /* Initialize buffer in system memory. */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ptr[i] = i; + + /* Migrate memory to device. */ + + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + + pid = fork(); + if (pid == -1) + ASSERT_EQ(pid, 0); + if (!pid) { + /* Child process waitd for SIGTERM from the parent. */ + while (1) { + } + perror("Should not reach this\n"); + exit(0); + } + /* Parent process writes to COW pages(s) and gets a + * new copy in system. In case of device private pages, + * this write causes a migration to system mem first. + */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ptr[i] = i; + + /* Terminate child and wait */ + EXPECT_EQ(0, kill(pid, SIGTERM)); + EXPECT_EQ(pid, waitpid(pid, &status, 0)); + EXPECT_NE(0, WIFSIGNALED(status)); + EXPECT_EQ(SIGTERM, WTERMSIG(status)); + + /* Take snapshot to CPU pagetables */ + ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + m = buffer->mirror; + for (i = 0; i < npages; i++) + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[i]); + + hmm_buffer_free(buffer); +} TEST_HARNESS_MAIN