From patchwork Fri Jul 15 15:05:08 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: 12919360 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 46A37C433EF for ; Fri, 15 Jul 2022 15:05:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BC2C9401EE; Fri, 15 Jul 2022 11:05:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 568F39401E5; Fri, 15 Jul 2022 11:05:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4312C9401EE; Fri, 15 Jul 2022 11:05:43 -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 2BE479401E5 for ; Fri, 15 Jul 2022 11:05:43 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D9EF72042A for ; Fri, 15 Jul 2022 15:05:42 +0000 (UTC) X-FDA: 79689658524.16.695BBF8 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2080.outbound.protection.outlook.com [40.107.101.80]) by imf09.hostedemail.com (Postfix) with ESMTP id 615901400C8 for ; Fri, 15 Jul 2022 15:05:41 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DjhifKcBytrYgzZC9z/PUvajTeF8ZJTx3USW5CxBCkwBFMl0kchC3/Q9wdO7h+mmQUPHTc5iA2oGM6OqHI9hgYb4xHwDu/ZjyWAXv2UwOYTUwa1RPEovAwlhY+kBZ4gCLa/eeGIK3KPdVmUDGAG5nSW5EPkKIFFKRzrpYhRZZYhAnQYU/x3IuOTdJjvOqQw8Bf9YM62PqYe8rJ8o4E3Gh/HLPirsKdcu/fTjGwr4MGdS0UXYP6b6Lst9ghyebFSq/dca/KmLXys5/rWHY1yLPqcbk9/w91zqxZPe4DqdjPdvG6gdt3d4+7DYlG2snXoPBW8f4NO6A6Vql6ENMlBuyw== 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=5n2hQHCIkvFC4l9d3FiHxLrUEGiyzBAfhaflBazYrk4=; b=Q4ev6KTCOzDqR5wMunHxb6HKudoE/nAf1zROqcwgg+TEh+yhTXrby9PkrnKOws1FpBMxxZu5R8y6eWhAloyI+UfMs4J/QD+TdUykCynQuinnoEGGxCI6uE3syPcfYXE8W0ZyHupGIOAQBSnm+iwmCdvpNqoQig+yQDO5Idas1MJxywj/a5PcSxrmt4WyHH0JGONXwljrSxBTCAHgFb+3EZOXaVnSD1eXQaLvXX6J0xkp+ODj5dymBKcOuyGdCShCmxqhfgcRMVY2rUB4rIlWr5eHZiYwgWFn10BBWxMBaAS1jlolF/PC4kOO8/RHXIpforW0izI/2kbWnSJ4eOmLbA== 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=5n2hQHCIkvFC4l9d3FiHxLrUEGiyzBAfhaflBazYrk4=; b=MvNk0p4ohFoKQQ/xf+9KVsUYBpKrBMh3havX+JDoXMAqm9LSszf9a3N+J+0br5PYLd57FqlWa5Cmd+gJ1sD+nACjnXLfHO0QZsJoNQgKzGLag9jJe+LvOR+DfZ6+s6vBxIze11zcbeSGoXUDS0/b11pgJTp3bLMa0Ho2HUjpHds= Received: from DS7P222CA0028.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::21) by DM5PR12MB1516.namprd12.prod.outlook.com (2603:10b6:4:5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.14; Fri, 15 Jul 2022 15:05:37 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::2d) by DS7P222CA0028.outlook.office365.com (2603:10b6:8:2e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.17 via Frontend Transport; Fri, 15 Jul 2022 15:05: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 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.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:36 +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; Fri, 15 Jul 2022 10:05:34 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 01/14] mm: rename is_pinnable_pages to is_longterm_pinnable_pages Date: Fri, 15 Jul 2022 10:05:08 -0500 Message-ID: <20220715150521.18165-2-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: 63b1943f-f149-4519-0855-08da66737961 X-MS-TrafficTypeDiagnostic: DM5PR12MB1516:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wahF/034h1E+EVpWojE1N11gIsqSWW4I559ZJiotBt34DNL1VuQckJeTvHEZuOp0pouTOX3tgU9c4rPcfL6sc2yiMJvaJvdvkzXiqtIzIoSGs7zhBxdwaLWfqLtnNG55LM+bGw5CqXA7AoOojrTzit+14krCsKpF2TY9Wo9LNs0mRGwXztrkJmIGoDDCXn0dBaRJZc5Hpscrr91n9QPANZ8g1SdHMjm6rEXJkZqgQEK14aihX587+a27lT8+BymeIdLI24yIe6eXMx+rQwbNPbMTbO8G0OgiY63wY2Q4GYaeKQ7MrSjfob700US8e62JaJuKx6subZWRzHj9ph8V+9sIBJ1bM7jq4c9tyfqoH09Q2bQZ5qCz8/I87yrGsL2wNWPdBRlLxrDpcDQs8OexJGsVk7CD7U4J3uyCjL69x+K07Jp48z90vjmL5t2ZcpwB6UX4h+zl81MjBji3+2GUCJ2mapY1b2YfP6AtMIgskjI/5cf5E3cJLCvAK1be2AKIXr7MPuvxdjIngXltPyrycW/PtLYvV+vrUKtoCBNh4RBZY1HMY29sPYYWBGFuVmzFuLxvfkKWpy0bD/fp1NA1Vwjj526hc77mvqQsr4/IaFVYC91YWAgvRa6gw7iffRE+9c30Eo2sgRfvjAp3rc+hz/gZvPUe7lw86uzlH3e1E/kOrFwutBk8qv350z2UD8lpROZWcDLvO/OFKhUk6gKRmeGPEhAZ+AiyqgFjucdNvgp24O82F9uxsPyavAfYyEYfilNf0JnAnURVD8YMcru4m1hT2j7O714iAzOaGcvXy8P2LlmyyT5XewNthAlqH0zT80pD80x1JXBm06oa9TzNJL0s3kYoOQ4XXXG6zvQyI3A= 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)(316002)(26005)(2616005)(54906003)(41300700001)(478600001)(6916009)(7696005)(82310400005)(86362001)(6666004)(40480700001)(81166007)(82740400003)(40460700003)(356005)(16526019)(426003)(2906002)(44832011)(186003)(47076005)(36756003)(7416002)(5660300002)(1076003)(70206006)(336012)(36860700001)(8676002)(4326008)(70586007)(83380400001)(8936002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:36.9083 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63b1943f-f149-4519-0855-08da66737961 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: DM5PR12MB1516 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897541; a=rsa-sha256; cv=pass; b=VZzKb6Bz4CQULwWeqiG0Z52CmNYhx+izaOhmSEdIUxprNDva7vCyIBQHVHDKSNmL0NrFb3 GChG7gwEdWRu8I8hprynfHxr3Eco0yaDI+HCv79ZaxAIPrSRsq6Ep32IF4vJeqYPQSFWJM vWdRv3RW3Rk7gMpW7fCYMnSuULMuamo= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=MvNk0p4o; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf09.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.80 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=1657897541; 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=5n2hQHCIkvFC4l9d3FiHxLrUEGiyzBAfhaflBazYrk4=; b=1ZhHC+ouWxFSJQVrt2L6QOyTuM9CgzkX2elk81IbvOFFNI1mQSXjfyy9+D47Ucmnnu/Uqp 7xZXU5ZyhWbLMEFJdvHTv8XCLMgyfQL8zmUDyah2wdVhk/wuUR7QiaMzrFlF532p7G4IYH p7a8rkUtOYSgm1pt7XuUcG4II6qPXLA= X-Stat-Signature: so476qh9r374xfx1r1q3dyauebwfgudt X-Rspamd-Queue-Id: 615901400C8 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=MvNk0p4o; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf09.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.80 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1657897541-150497 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 Reviewed-by: David Hildenbrand --- include/linux/mm.h | 8 ++++---- mm/gup.c | 4 ++-- mm/gup_test.c | 2 +- mm/hugetlb.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index cf3d0d673f6b..3b31b33bd5be 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1592,7 +1592,7 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma, /* MIGRATE_CMA and ZONE_MOVABLE do not allow pin pages */ #ifdef CONFIG_MIGRATION -static inline bool is_pinnable_page(struct page *page) +static inline bool is_longterm_pinnable_page(struct page *page) { #ifdef CONFIG_CMA int mt = get_pageblock_migratetype(page); @@ -1603,15 +1603,15 @@ static inline bool is_pinnable_page(struct page *page) return !is_zone_movable_page(page) || is_zero_pfn(page_to_pfn(page)); } #else -static inline bool is_pinnable_page(struct page *page) +static inline bool is_longterm_pinnable_page(struct page *page) { return true; } #endif -static inline bool folio_is_pinnable(struct folio *folio) +static inline bool folio_is_longterm_pinnable(struct folio *folio) { - return is_pinnable_page(&folio->page); + return is_longterm_pinnable_page(&folio->page); } static inline void set_page_zone(struct page *page, enum zone_type zone) 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..12b0a91767d3 100644 --- a/mm/gup_test.c +++ b/mm/gup_test.c @@ -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 Fri Jul 15 15:05:09 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: 12919361 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 27C88C43334 for ; Fri, 15 Jul 2022 15:05:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 828E79401E5; Fri, 15 Jul 2022 11:05:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 743219401EF; Fri, 15 Jul 2022 11:05:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B7C39401ED; Fri, 15 Jul 2022 11:05:43 -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 39F129401ED for ; Fri, 15 Jul 2022 11:05:43 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EA36C34B0E for ; Fri, 15 Jul 2022 15:05:42 +0000 (UTC) X-FDA: 79689658524.06.FC7F453 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2064.outbound.protection.outlook.com [40.107.244.64]) by imf29.hostedemail.com (Postfix) with ESMTP id 3DF6E120090 for ; Fri, 15 Jul 2022 15:05:42 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TXXdYX2eriNb55shXXzSGEHiPqiXGxz76ofmliLPwflr2903fY1DtjwIN8e+UoVE6cL0R08+oJ1bnTLvlwOCVIOUJXkxa9yumeesW1ZTPLnrvJJ6P2XDKTNpJvJTvds/ttacGg4O6vEysLnnJlsZ4yJ8XTLBsMWnOFUDcPKWk27JAwvOjP2o7+DhmMkX5Fl4SLxHOPZhEe8h1O+JwrAc5/xiI9vYvPLeiW0xLozGDOliwYFKvi4TQjmhICfXr/uCcXQO9XJDCQ1y7s5Ks+gW8yIUkjDKew3mwLJRUxb6on1b3vrFUzwcIU5pPf8MWnGHDC3vTs/EazgF8CVKVa8Aww== 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=mBW4h10J7XAhyaHtTT9wydlVynoCzg0kQPS8qrn77OY=; b=LhKmQqhgrofkxInd6wbdfoYSpAZCldKTh8iO42EQ0mspGKMEPdf/UObWnlZMFN0DJSEUFr7miEZbu7dXAVvyepC/nm95CD3ZgsUD3/7DMQXiSHtV9qUkmy6SpF+lLS6+sQy7k63SHZfUXqnJnebWvFtvvrJJGx2Lhd5FcVwfPiNPPPeyqRVIyRDAVkxAgrYEW/XI5mxlCBMu6PomCoMXA6vT2PGfCiJFvu0J5mdiatVoJTJgaXuDn7AgRC+2zS2R+WiQj9UQHphzMR4tQFMG0BTPs5sf3KJxyyxQzWnpoaXHrFz0D7ZPOybI84vaEeoenc/Ek6baKyJDHHCxuuqlZA== 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=mBW4h10J7XAhyaHtTT9wydlVynoCzg0kQPS8qrn77OY=; b=Gq7PmTRmVDY902OOCG3pY2cyHCh7da5Bojw9mPrxdbaGAPyZ/Gk5QQ2Z6/yOfIZzXHp5MntfNR2VLVtDn7rb5tmpM1PVJOzwtBD3Lkfy/eGa1ajeq6wRw/xBoPMMRODXJjKt7VjbrTdoz6jhe9WpuyTmucLekC76L1UUjUgphlM= Received: from DS7P222CA0030.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::10) by MN2PR12MB3583.namprd12.prod.outlook.com (2603:10b6:208:c5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.14; Fri, 15 Jul 2022 15:05:38 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::6b) by DS7P222CA0030.outlook.office365.com (2603:10b6:8:2e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:38 +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.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:38 +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; Fri, 15 Jul 2022 10:05:36 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 02/14] mm: move page zone helpers from mm.h to mmzone.h Date: Fri, 15 Jul 2022 10:05:09 -0500 Message-ID: <20220715150521.18165-3-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: 7e364758-2e71-473d-3470-08da66737a54 X-MS-TrafficTypeDiagnostic: MN2PR12MB3583:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zsQRNsqTIe04LCmYdaYqn0qITXKzgZoJxoOuUCmNAR7poOdEEqqqs7UkNGAgdHe58liRuC48ake0poPBiLTQalgvC4ZQ+ZZKe+NQwvTdovS/0u7Uq4Pf5F8/BYzappJLC6XUnFiTgB1QqyCghVOulDicO+LhgQ6iLq/kK+zHdiDo4hCxvJq1B0ixom1TvE05Nl/hpZqyJZB8Dz0BJUck3TdD1Bs6xcksBQEzUvayMl8AsBhZXnxt7tkZnu9tcMvfrMJfiCj4sbPYqbS1f0AhO5gGbPaXk6e8CmavCYFZDfHwwpujvqeT+5B42B2Elc9n1JZEwUQTRiA1G8YYgmi7TNUQGtmQfLD/JVkxWSggA4pfXyZYud5tGchfOrdHTS9QiWwpO0UpxaLQnJc+A2xSP5n8V+lG5ZbOJeIB+dm7VvGgbaZBaEWCguim1bDebCeX0QO/LcgSVXzhbzICFelHeaKkHMVxrKdyORyZ/Mcl4KRlbmrjf4E21Dot2ymmevPfbWIZJhlItDsud/Y7HeYLzq6B+drFIzq3qfzlUh+OhsYbxval/u/FIPplRPGIinaiIStdZG9IARy9XvzUTgYPfinMnSqqG/WC5ova0gwzYkcCKtj53I6joT34OXMUf+rIpgsxlrf152LUN19NjwP0iK+JY1DXnlm0/acHycW9bg9lEWlIgqv4KOkcadt80OiMpcOAb0U6B62bGSHvym0GDEEiAiSwkM3YCtIA6jSd7wCh69Sj0+CxhHN2cw0Zpmpo9DZQ76RhKeBv2gXT7uL38G1YMbKSjY8Nhn53goJ6aiCw6+xTMwGRb4ktGFkf9H5rjJgauBCSqqC+snWf9bGBJdir+rDL7AZcKRL942cJnQ4= 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)(396003)(346002)(39860400002)(136003)(40470700004)(36840700001)(46966006)(5660300002)(44832011)(2906002)(7416002)(82310400005)(40480700001)(8936002)(4326008)(8676002)(70206006)(70586007)(316002)(54906003)(6916009)(40460700003)(36756003)(86362001)(478600001)(6666004)(186003)(81166007)(426003)(16526019)(336012)(41300700001)(356005)(47076005)(1076003)(2616005)(83380400001)(36860700001)(26005)(7696005)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:38.4863 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e364758-2e71-473d-3470-08da66737a54 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: MN2PR12MB3583 ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Gq7PmTRm; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf29.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.244.64 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=1657897542; 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=mBW4h10J7XAhyaHtTT9wydlVynoCzg0kQPS8qrn77OY=; b=fBjNoABLs4BaAZktFym8rbiGp5xt6GqmOxfMxDJqGwHUwAYTkftRGUZvRttXdMRm0y51Y3 i0/NafhOxsjsXDByXrRFwsgwIQvKJBwOOdZU5YzGoK7oNgQKToQIdH3+lrk3ZUudgIbod2 8jso62qmua+Oc5jzfoVEbbGGbc6f1w4= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897542; a=rsa-sha256; cv=pass; b=OK8OoWDth+fB8IyjemRkD/W/FrkIy49Rl0yuTguczG636xTuCn4nEl/WhByoBKs+8qe+ZT b+ZjS0dQC5XL4L8xouh0/EV2Y0RBGHc2dPHcVtJK+Mmm+VavfpCzV5q1OF9cytFs1QmWAr 74f6mnS67MfFgRBGQsGrEy0T97zXTaM= X-Rspam-User: X-Rspamd-Queue-Id: 3DF6E120090 X-Rspamd-Server: rspam02 X-Stat-Signature: m57xxc6o3o9e1ra3oex5w4xxru4bjre8 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Gq7PmTRm; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf29.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.244.64 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1657897542-690487 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: [WHY] It makes more sense to have these helpers in zone specific header file, rather than the generic mm.h Signed-off-by: Alex Sierra Acked-by: David Hildenbrand --- include/linux/memremap.h | 2 +- include/linux/mm.h | 78 --------------------------------------- include/linux/mmzone.h | 80 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 79 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 8af304f6b504..77229165c914 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -2,7 +2,7 @@ #ifndef _LINUX_MEMREMAP_H_ #define _LINUX_MEMREMAP_H_ -#include +#include #include #include #include diff --git a/include/linux/mm.h b/include/linux/mm.h index 3b31b33bd5be..2df8c2b98d36 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1049,84 +1049,6 @@ vm_fault_t finish_mkwrite_fault(struct vm_fault *vmf); * back into memory. */ -/* - * The zone field is never updated after free_area_init_core() - * sets it, so none of the operations on it need to be atomic. - */ - -/* Page flags: | [SECTION] | [NODE] | ZONE | [LAST_CPUPID] | ... | FLAGS | */ -#define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - SECTIONS_WIDTH) -#define NODES_PGOFF (SECTIONS_PGOFF - NODES_WIDTH) -#define ZONES_PGOFF (NODES_PGOFF - ZONES_WIDTH) -#define LAST_CPUPID_PGOFF (ZONES_PGOFF - LAST_CPUPID_WIDTH) -#define KASAN_TAG_PGOFF (LAST_CPUPID_PGOFF - KASAN_TAG_WIDTH) - -/* - * Define the bit shifts to access each section. For non-existent - * sections we define the shift as 0; that plus a 0 mask ensures - * the compiler will optimise away reference to them. - */ -#define SECTIONS_PGSHIFT (SECTIONS_PGOFF * (SECTIONS_WIDTH != 0)) -#define NODES_PGSHIFT (NODES_PGOFF * (NODES_WIDTH != 0)) -#define ZONES_PGSHIFT (ZONES_PGOFF * (ZONES_WIDTH != 0)) -#define LAST_CPUPID_PGSHIFT (LAST_CPUPID_PGOFF * (LAST_CPUPID_WIDTH != 0)) -#define KASAN_TAG_PGSHIFT (KASAN_TAG_PGOFF * (KASAN_TAG_WIDTH != 0)) - -/* NODE:ZONE or SECTION:ZONE is used to ID a zone for the buddy allocator */ -#ifdef NODE_NOT_IN_PAGE_FLAGS -#define ZONEID_SHIFT (SECTIONS_SHIFT + ZONES_SHIFT) -#define ZONEID_PGOFF ((SECTIONS_PGOFF < ZONES_PGOFF)? \ - SECTIONS_PGOFF : ZONES_PGOFF) -#else -#define ZONEID_SHIFT (NODES_SHIFT + ZONES_SHIFT) -#define ZONEID_PGOFF ((NODES_PGOFF < ZONES_PGOFF)? \ - NODES_PGOFF : ZONES_PGOFF) -#endif - -#define ZONEID_PGSHIFT (ZONEID_PGOFF * (ZONEID_SHIFT != 0)) - -#define ZONES_MASK ((1UL << ZONES_WIDTH) - 1) -#define NODES_MASK ((1UL << NODES_WIDTH) - 1) -#define SECTIONS_MASK ((1UL << SECTIONS_WIDTH) - 1) -#define LAST_CPUPID_MASK ((1UL << LAST_CPUPID_SHIFT) - 1) -#define KASAN_TAG_MASK ((1UL << KASAN_TAG_WIDTH) - 1) -#define ZONEID_MASK ((1UL << ZONEID_SHIFT) - 1) - -static inline enum zone_type page_zonenum(const struct page *page) -{ - ASSERT_EXCLUSIVE_BITS(page->flags, ZONES_MASK << ZONES_PGSHIFT); - return (page->flags >> ZONES_PGSHIFT) & ZONES_MASK; -} - -static inline enum zone_type folio_zonenum(const struct folio *folio) -{ - return page_zonenum(&folio->page); -} - -#ifdef CONFIG_ZONE_DEVICE -static inline bool is_zone_device_page(const struct page *page) -{ - return page_zonenum(page) == ZONE_DEVICE; -} -extern void memmap_init_zone_device(struct zone *, unsigned long, - unsigned long, struct dev_pagemap *); -#else -static inline bool is_zone_device_page(const struct page *page) -{ - return false; -} -#endif - -static inline bool folio_is_zone_device(const struct folio *folio) -{ - return is_zone_device_page(&folio->page); -} - -static inline bool is_zone_movable_page(const struct page *page) -{ - return page_zonenum(page) == ZONE_MOVABLE; -} - #if defined(CONFIG_ZONE_DEVICE) && defined(CONFIG_FS_DAX) DECLARE_STATIC_KEY_FALSE(devmap_managed_key); diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index aab70355d64f..47fc41f43c48 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -730,6 +730,86 @@ static inline bool zone_is_empty(struct zone *zone) return zone->spanned_pages == 0; } +#ifndef BUILD_VDSO32_64 +/* + * The zone field is never updated after free_area_init_core() + * sets it, so none of the operations on it need to be atomic. + */ + +/* Page flags: | [SECTION] | [NODE] | ZONE | [LAST_CPUPID] | ... | FLAGS | */ +#define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - SECTIONS_WIDTH) +#define NODES_PGOFF (SECTIONS_PGOFF - NODES_WIDTH) +#define ZONES_PGOFF (NODES_PGOFF - ZONES_WIDTH) +#define LAST_CPUPID_PGOFF (ZONES_PGOFF - LAST_CPUPID_WIDTH) +#define KASAN_TAG_PGOFF (LAST_CPUPID_PGOFF - KASAN_TAG_WIDTH) + +/* + * Define the bit shifts to access each section. For non-existent + * sections we define the shift as 0; that plus a 0 mask ensures + * the compiler will optimise away reference to them. + */ +#define SECTIONS_PGSHIFT (SECTIONS_PGOFF * (SECTIONS_WIDTH != 0)) +#define NODES_PGSHIFT (NODES_PGOFF * (NODES_WIDTH != 0)) +#define ZONES_PGSHIFT (ZONES_PGOFF * (ZONES_WIDTH != 0)) +#define LAST_CPUPID_PGSHIFT (LAST_CPUPID_PGOFF * (LAST_CPUPID_WIDTH != 0)) +#define KASAN_TAG_PGSHIFT (KASAN_TAG_PGOFF * (KASAN_TAG_WIDTH != 0)) + +/* NODE:ZONE or SECTION:ZONE is used to ID a zone for the buddy allocator */ +#ifdef NODE_NOT_IN_PAGE_FLAGS +#define ZONEID_SHIFT (SECTIONS_SHIFT + ZONES_SHIFT) +#define ZONEID_PGOFF ((SECTIONS_PGOFF < ZONES_PGOFF) ? \ + SECTIONS_PGOFF : ZONES_PGOFF) +#else +#define ZONEID_SHIFT (NODES_SHIFT + ZONES_SHIFT) +#define ZONEID_PGOFF ((NODES_PGOFF < ZONES_PGOFF) ? \ + NODES_PGOFF : ZONES_PGOFF) +#endif + +#define ZONEID_PGSHIFT (ZONEID_PGOFF * (ZONEID_SHIFT != 0)) + +#define ZONES_MASK ((1UL << ZONES_WIDTH) - 1) +#define NODES_MASK ((1UL << NODES_WIDTH) - 1) +#define SECTIONS_MASK ((1UL << SECTIONS_WIDTH) - 1) +#define LAST_CPUPID_MASK ((1UL << LAST_CPUPID_SHIFT) - 1) +#define KASAN_TAG_MASK ((1UL << KASAN_TAG_WIDTH) - 1) +#define ZONEID_MASK ((1UL << ZONEID_SHIFT) - 1) + +static inline enum zone_type page_zonenum(const struct page *page) +{ + ASSERT_EXCLUSIVE_BITS(page->flags, ZONES_MASK << ZONES_PGSHIFT); + return (page->flags >> ZONES_PGSHIFT) & ZONES_MASK; +} + +static inline enum zone_type folio_zonenum(const struct folio *folio) +{ + return page_zonenum(&folio->page); +} + +#ifdef CONFIG_ZONE_DEVICE +static inline bool is_zone_device_page(const struct page *page) +{ + return page_zonenum(page) == ZONE_DEVICE; +} +extern void memmap_init_zone_device(struct zone *, unsigned long, + unsigned long, struct dev_pagemap *); +#else +static inline bool is_zone_device_page(const struct page *page) +{ + return false; +} +#endif + +static inline bool folio_is_zone_device(const struct folio *folio) +{ + return is_zone_device_page(&folio->page); +} + +static inline bool is_zone_movable_page(const struct page *page) +{ + return page_zonenum(page) == ZONE_MOVABLE; +} +#endif + /* * Return true if [start_pfn, start_pfn + nr_pages) range has a non-empty * intersection with the given zone From patchwork Fri Jul 15 15:05:10 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: 12919364 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 20948CCA486 for ; Fri, 15 Jul 2022 15:05:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 914A09401F2; Fri, 15 Jul 2022 11:05:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 877F69401F1; Fri, 15 Jul 2022 11:05:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CB599401F2; Fri, 15 Jul 2022 11:05:50 -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 5915A9401ED for ; Fri, 15 Jul 2022 11:05:50 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 22D31207BD for ; Fri, 15 Jul 2022 15:05:50 +0000 (UTC) X-FDA: 79689658860.20.9BBED9A Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2086.outbound.protection.outlook.com [40.107.223.86]) by imf15.hostedemail.com (Postfix) with ESMTP id 497D7A00B0 for ; Fri, 15 Jul 2022 15:05:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RuI2q8NGZFsHcU0rgFVQx6OBNYELYZzo3ZB4Tbn1m5q34AAn6WWh8sZQ2n4CkmrZ9yjYApwQReHf9PIJG1VwzAIpRhvaKWaGXVOt6GA45BUuI/DacDYjPhHyUbSRFuNdr6TRQALfuUF5lYUYOBtvjalJPaIdkYvI1FjqnYCdCd4H0YTeSGbbYu/rOb7SFlb+yoZXWAAe2AQkBWRwh3veqKz5xsXNGdUuP9kWJfhXHbKvS4IbXY9Bn4ztJ6gNueQvJcYgTrxZM3rAqKpIAPOC7T+ejxr+orh/IfNKqn9kSUU713oeXhJb7Aow/dK/r1KWMRrvkliMBl+rP4d2xirgHQ== 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=pl3vpLHWcXBhanSoe7pGRKR9ds6OjoPRrsbyvrGQTWQ=; b=bzXCB+j0k5M0P4NwcBMtGSRdrkNf9yIQoKMiB/BxLlRxLGbqlAgxVuX0JFTUTDwYpnybHvzy4OAskF4o/3Zcx5pbOI9sbmPLUKWhOmc88swM+BhgHLPypvll79k4DtT194p3043JGiCxp3FUZZ1jI8dw7p0M+CGR9yAQOP8fq6dQ/fiXJdWfVgPEKn6lzO19VNjYnuNWxe2rSiHX1noWpA2KDRGOxa++PuFZM9oxmzWoJFXRtd05ebpTrYb0+m4oLZCcHlaMSOOXoGeCGv+Vb+cmLcbKzk5mDfFzEegOaJSv5Zwtj+uyCRH33OSnypk7C+fSZACs1ItC3LjfmyCo5A== 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=pl3vpLHWcXBhanSoe7pGRKR9ds6OjoPRrsbyvrGQTWQ=; b=pGNmgmW6sv8lasELW7Q5jQjyzGeigMW4Zdk02uMYz6pgsNZXrDQIBLXun20W+KV/1Ee56fMhF6kgCmM/sLzEiDFtO1G2iitP5PsCWAzl8Xa+Slt7tovvrHHNwi2FymssD345TW3sLCZ/zr07z0DSxpx9ZeR7iJQLsSpgfgYhIFM= Received: from DS7P222CA0023.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::9) by BL0PR12MB2819.namprd12.prod.outlook.com (2603:10b6:208:8a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.13; Fri, 15 Jul 2022 15:05:40 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::bc) by DS7P222CA0023.outlook.office365.com (2603:10b6:8:2e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.20 via Frontend Transport; Fri, 15 Jul 2022 15:05:39 +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.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:39 +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; Fri, 15 Jul 2022 10:05:37 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 03/14] mm: add zone device coherent type memory support Date: Fri, 15 Jul 2022 10:05:10 -0500 Message-ID: <20220715150521.18165-4-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: c2a38a62-6060-4d0d-9fc0-08da66737b04 X-MS-TrafficTypeDiagnostic: BL0PR12MB2819:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7D9pZUz+MejFaivwLhwL5dxt900IGIWJGESAOYT5x958EAnTXSg+pqVGajHxGcQLq+N/S+lpf4nZdNFHO4SLIa7Ts6aFlW2pd8uDQPReIMzJXRUC1CelSVIqtUv6WR+PKSIfzuD89ZbHoOYZ3f/7NdOE6uzSoCnYlIiDvKBMQrKmfKTVzbqPpthpJ0vEEoTNAYkpKDAguD4GXnmmvoW0zEPoPQWeEYSwtHX38wbXvAhePEcL5NbiVZmyo9xxQWlnHbaFvCyZHqGEzhbW5svwNiHuH5cQT62xk0cJC9dRaQtCJOc4datgjxnapqnc8WGZAgD8jk5W4oHJ5TT/8aulnTGFVfiN+7x8KkjhXylwDpBdHBEZ/pMq9Y4NgvibFui2QBX9F4/nqUhsOLGo4s/bdBhc3KGQoRQluk5PmJTyl185fQ7isuOO+FcXo+rn6wp97CjmouxsEUlJ+KO510GfxbF4RRcFwd5YxCaB3FQw70zVTDz0jA3aOnv7ZYkOi1aaj+UbJwHArQWORi8iz8MHxwyBiCtoT96GcEUsfVETyijXOY24/Yit1SBHg0/oe/PtMTePTmkAuvnWHJjs8zGZGfKud/3fRt/TOyPDfoZWWg5GonX+XzEeNWb+kTdD78SGoR1vHZSoukVDn+omjg3BBqY6Jhsy5hEyEORXz10asCvlOJkhPKtO+s7YJNc5h1mbHWCnuivKkqNCt+UMxYUv2U6hqEW9C9lu6tC7rk5fH/ux56v5lXbVNjD0v2GQaGhYpWg1VBQHmNwcTRpx3koHTgMRvwSVJPRthgDT0tSegOQG3l2dqMHBDFbcafhaGBN5YzzZzDXKfpjx/M4CCnYDt32FjRswOdxf0oJXC8NF2TE= 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)(396003)(39860400002)(376002)(46966006)(36840700001)(40470700004)(81166007)(36756003)(36860700001)(44832011)(82740400003)(83380400001)(7416002)(8936002)(2906002)(336012)(5660300002)(47076005)(426003)(54906003)(186003)(8676002)(16526019)(7696005)(41300700001)(1076003)(2616005)(40460700003)(316002)(86362001)(4326008)(70586007)(356005)(70206006)(40480700001)(478600001)(6916009)(6666004)(26005)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:39.6425 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c2a38a62-6060-4d0d-9fc0-08da66737b04 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: BL0PR12MB2819 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657897549; 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=pl3vpLHWcXBhanSoe7pGRKR9ds6OjoPRrsbyvrGQTWQ=; b=zHdaG7ZW7Fo4dDxEA2oV+s1EjcWJMYKLldgzzYQAk0JD8SJoE5o2Vl5X0aUnRVWMAe1/Dm /Zv9NjvfG7J6/nPlIgKan5ka6Iug+Y7SngbzmayDmA7Q1cme/uOmOgvn9JYA+U+OI+5v6d YXf8Idi674f0OJ/TtGQu7jEZFA1hlYc= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897549; a=rsa-sha256; cv=pass; b=6j+AS954LTszm2syfxej8aY9/JHCqGxQRFVOd6x5vNzYJZq2vI0xciHRIi0BCoOIRnoJ6r zZjDzfYR0JeNGOz541Ip0ZAXRETc1zVCcWEgDoSyqdurKhGWaSK7OtYfBG6+GJ0BwuhhNG rRadL/D5OYPdTI0mlQwkXtI5QSt5vkQ= ARC-Authentication-Results: i=2; imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=pGNmgmW6; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf15.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.86 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Stat-Signature: 6gg6ot8iy38z93fp4cri8qjwzt1qgeu3 X-Rspamd-Queue-Id: 497D7A00B0 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=pGNmgmW6; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf15.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.86 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1657897545-15388 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 | 19 +++++++++++++++++++ include/linux/mm.h | 5 ++++- mm/memcontrol.c | 7 ++++--- mm/memory-failure.c | 8 ++++++-- mm/memremap.c | 10 ++++++++++ mm/migrate_device.c | 16 +++++++--------- mm/rmap.c | 5 +++-- 7 files changed, 53 insertions(+), 17 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 77229165c914..f27b142fd3d0 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, @@ -150,6 +158,17 @@ static inline bool is_pci_p2pdma_page(const struct page *page) page->pgmap->type == MEMORY_DEVICE_PCI_P2PDMA; } +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); +} + #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 2df8c2b98d36..3ed101dfbfab 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -28,6 +28,7 @@ #include #include #include +#include struct mempolicy; struct anon_vma; @@ -1522,7 +1523,9 @@ 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) || is_zero_pfn(page_to_pfn(page)); + return !(is_device_coherent_page(page) || + is_zone_movable_page(page) || + is_zero_pfn(page_to_pfn(page))); } #else static inline bool is_longterm_pinnable_page(struct page *page) 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 746c05acad27..d28a0ab725b6 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1972,7 +1972,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; @@ -2138,7 +2138,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 Fri Jul 15 15:05:11 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: 12919362 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 D2CB7CCA47C for ; Fri, 15 Jul 2022 15:05:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA90A9401EF; Fri, 15 Jul 2022 11:05:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7F339401ED; Fri, 15 Jul 2022 11:05:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C20FF9401EF; Fri, 15 Jul 2022 11:05:43 -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 B3D0C9401ED for ; Fri, 15 Jul 2022 11:05:43 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 89F97344CA for ; Fri, 15 Jul 2022 15:05:43 +0000 (UTC) X-FDA: 79689658566.12.E3348FF Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2069.outbound.protection.outlook.com [40.107.93.69]) by imf06.hostedemail.com (Postfix) with ESMTP id 02EA7180033 for ; Fri, 15 Jul 2022 15:05:42 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QnJazViVN56ZOkUqnSuEXD9gwN+w81Ty8NZH+sAE/ccZDECAefhh3UAbFH19CNwA7xP6zXFcdPLZX7MxhEzHw1gavXIAKQU5SIUc+OSmlpmLgmMrAiwLgRHSHqKsyzLLl2eBBc30Xs3yws48+16v1h2JU7xbi4UGkrtg5MwMQLmiQDbIw4qp3ssiWqg6FG6DMeBDLvSg1rYnJ2794qKS3vMWDHPj9+l/3z2BuTdrLSWrVyDGlWIsbzmFd3nIAlD6hkVQD1iSXATJ+DmgyebvByzZV+S+uNa0H8L3clndLflIzF2Lx8c7Nt1UqjvRbBtWf9DZBLiuqFnMoCzMrk3/5g== 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=l7KEXeC3QAbxMHsFgSJMAkiGsYbORg+uuhIqq3gFxLw=; b=bVacYqAOjfA1kqRUMJelMW3ligbJ0tKfVw3H5YwrXOy6k/4gNiCXXmmLYMFeiy1xSOElIZBZFX38FUnPds/4nYhDb9K0ub/ayqaVoqjwVje5cyJIIU73Zm3Xcjd4JwFGgsG2fLPIO82J9b81RtTkEiJ5CXB1+dSDEIiqbZ8i9hspRFNURV6joiUOk5DQYFjUXbBka2v7bAoblewQKnMfkqn5C7YfehM4lrfs+cnEY9cjoID3gWpcU14XrXrTpwj/Z3VrBWVsmW9J2O7mlMtgKzAXM0fX49j3lbf3SHiY64is9QmGxMHmq+2BJGUqNAVR4NtCvK8t4yf1RF157GZCow== 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=l7KEXeC3QAbxMHsFgSJMAkiGsYbORg+uuhIqq3gFxLw=; b=dIVHMHp9OsVT5zMszZRkW/bLenbuSJzSKS2BTsyZYF9tBz+i68QnICDgPB0zEjyMnWgrYVdwpOt4j8alaQOgIqVhbhSQStSIn40wP2779orWB6UwHIW5pYKzMDK5k8LAZDFacY/1Js+Ywmun+wXQPrlhmBP1LtDPIqGmsKq2o7w= Received: from DS7P222CA0007.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::24) by BY5PR12MB4917.namprd12.prod.outlook.com (2603:10b6:a03:1d1::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.13; Fri, 15 Jul 2022 15:05:40 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::d2) by DS7P222CA0007.outlook.office365.com (2603:10b6:8:2e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.19 via Frontend Transport; Fri, 15 Jul 2022 15:05:40 +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.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:40 +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; Fri, 15 Jul 2022 10:05:38 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 04/14] mm: handling Non-LRU pages returned by vm_normal_pages Date: Fri, 15 Jul 2022 10:05:11 -0500 Message-ID: <20220715150521.18165-5-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: 82e6a23a-a628-48a8-fc5b-08da66737b63 X-MS-TrafficTypeDiagnostic: BY5PR12MB4917:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xp2CKpQqeLZ1f9qKLjVA9Kg7NSxFK//yA3R7GSskPREVVRNaxe0nrgJDtw+s14kSwhzG0BKQ5fc6KilK2R2IjeSPpyv/ibMLHbAcHtcWfTvCzGdFrchgOC7mr9wtDtC1GJERRsa3fU4IM/H1lUQ4gWPOGp0kP4LpTHMhR01d3x8w5hKtTg6ipN5FKlzPqhOlLu0HQfEBylmcQmkZwngcS4EQWCuJ/Jitim5z4CgjrVnTMhrp78TqpS+YGKZ/bdTvAqk+i73CTP65WgesrcUYAjS1grxRLYvgZKvzqLdgj+zW+fP2msAwNpwGeWPQTPDUA0uPH2BPnoqduEtAeUWXCxf0cC7UT5wSVJoQnSgvwU7bhrGTMxJTwEf3vxqt1eN9oCa2Q3Ah5ZeaT47rPOdZSwcglcwfAB5acjIJ1CEEUWjTv9PqHqonpw0jPdc3Swsem2hVZ8jnlCkVt706hrRY8egx04pVDkNQRwN0Ih75+crMrKA2lFXVFScE1NfR9RUibH09bkdxUCFeFhRi9FAa889uXUdWI6WPUbnCd0dADugg7sD5a7Eex5PE9WMYg5hZbvG8daVM2WdCBXqEq3H36SqloOi1cgGzG0AnWe1XRYz97u9E1RD2hdLTuISjqo3chRrfPJxJac9zJT/XAelELFpocBcpNOcpx2IL+ui7Hxh8cpqvIE6bcJ7FOaJ6JVFjSZYz6W8x8rKJzfmliEjnHSRx9ZvKSsTIqT2Zi63F1F06Ru1xO37xhHbhGE67M0RvjFZuAT+hHeOfJBnU/70iaMqK9OHH7g97hcaEqqM3Glr88SAbfGWkaAWAw18SrGIIHASjhMI7I1p/i8eslkCMJfp2Tda/Yqz6I8d4h8YwIjs= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(376002)(396003)(346002)(136003)(36840700001)(40470700004)(46966006)(82310400005)(2616005)(6916009)(54906003)(316002)(86362001)(36860700001)(7696005)(26005)(36756003)(16526019)(186003)(40460700003)(1076003)(47076005)(426003)(336012)(81166007)(41300700001)(4326008)(7416002)(6666004)(70206006)(70586007)(2906002)(8676002)(82740400003)(44832011)(83380400001)(356005)(8936002)(5660300002)(478600001)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:40.2675 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 82e6a23a-a628-48a8-fc5b-08da66737b63 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: BY5PR12MB4917 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657897543; 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=l7KEXeC3QAbxMHsFgSJMAkiGsYbORg+uuhIqq3gFxLw=; b=Od29sfSpD/gBlRsiHuZzdR0uZ3o1m9IlBP1rB302J+OBOBb0SEGJXIGA5mw619jJUVaQQZ 9PbOmKfRj8CR7ZH4cz/kHqfFqKNW6eVGdhMmr21LoSDd8CAyYQ7T0GPR8ezOT9SvaFX4AT /wkEeUkZizC6o/r73N8Cr0M7KmEegfk= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897543; a=rsa-sha256; cv=pass; b=qETLGgzTry+qP+SHMJKme4RW5dXPynO/2fjdJWScxKj/7DJLbYK0S1xUNI1gpBvroL7Ycq HTJdVhywiz5CvWdB+JZMOnJz8teLXs+GrBKYhjh4Il9jcyxjQLQa0+duy3QkqUVSI/RShC T3HQsyUAQKJBqubo0TxofVjyPC24V2o= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=dIVHMHp9; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf06.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.69 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=dIVHMHp9; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf06.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.69 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Queue-Id: 02EA7180033 X-Stat-Signature: ba8refydho44nwjjqg97ua93e4idcdwb X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1657897542-492149 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() currently don't expect ZONE_DEVICE pages, however, with DEVICE_COHERENT we might now return ZONE_DEVICE. Check for ZONE_DEVICE pages in applicable users of follow_page() as well. 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 | 10 +++++++++- mm/mempolicy.c | 2 +- mm/migrate.c | 4 ++-- mm/mlock.c | 2 +- mm/mprotect.c | 2 +- 10 files changed, 27 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 4cf7d4b6c950..e939cc851a0e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -624,6 +624,14 @@ 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 users 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 +4701,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 Fri Jul 15 15:05:12 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: 12919365 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 37DCFCCA480 for ; Fri, 15 Jul 2022 15:05:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B68DF9401ED; Fri, 15 Jul 2022 11:05:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEF699401F3; Fri, 15 Jul 2022 11:05:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7654F9401ED; Fri, 15 Jul 2022 11:05:50 -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 5B6A99401F1 for ; Fri, 15 Jul 2022 11:05:50 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3FBD320A6E for ; Fri, 15 Jul 2022 15:05:50 +0000 (UTC) X-FDA: 79689658860.18.C52D474 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2079.outbound.protection.outlook.com [40.107.101.79]) by imf18.hostedemail.com (Postfix) with ESMTP id 933C81C00BF for ; Fri, 15 Jul 2022 15:05:46 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IOC6GziTPn+qimKUDipKx9IzoQDfSMXK6oxiveM/o5MeF0UbZ9mJcpaGfkkdrXYixibhomFcpChUdSv2+9PB0CzP85fIH+aZuAxlk5Lnqv3qYsakPoE12je83bbdFUYA0GkReGhIRUspGErJAdn/rg5YyfYGv4hQ6nr46Z3N7Te/4AP+Cn2CNw7YsVpU0Ne7mfqTKD7xuVVVw3Y3VSxZenO9k7okpbwZWI+QHEYWDq2wNm74T/j0Nsnz6JQACR16a0eB5yRbhuFHIYhrtHVKnS1p1EetZjDLY8r9HvbsLVRFr+Ev/njdr7SPWuhG6BTU53oGoyXm1gEhc91U50rplw== 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=FufDotkIE3bdjczHZAIIAyLhAtHM05ZPrkv0yNJ6rj0=; b=QRlydB4cQU/ykWs4I4wRcnUKNVDmp3KN5225nJ0V3UYUd5OVzPikG4bdmMqDZyWURJf4rzhbXd/c2nxI9Ei9lGi/MPqAIoNvD6QmRxB+VQ/m+5GxhC/LysdVtW4KMLxGMf0w0z4y44XL6a/38sDFJPkym4n/kod914Zini9tgeBsYNzKipM0dQUMgdxOOKhu/lDOJ6Vd4PZzzHpC61lpbrgwW7LN5MzmCqJlwSIKA3d2dvBbxu34AY3SSQ8wSysgczuiVtDJQnQDAFnLCaqEwhuYyiZZ1VGBGWxpIUyr1gVw2Fxyyniz40pfvWqVeo0tIYKucqlZe3BJOAk5dAE9hA== 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=FufDotkIE3bdjczHZAIIAyLhAtHM05ZPrkv0yNJ6rj0=; b=pvfJ4UZfVZ+Lrbb85UYtODyfEdylvP5Ka9rraduUOqH7734m7c2+DNxXSU2CxNShrgdUGDkIo8+pFfZTSFg1VR3ZA248k/6Gh8KS7y3dIHrsR7ai8+brvBsRPHcudnhDrJs2jbeNR1/jnusu8XGART2lO1dLWeCiUz3NGGQ5KEY= Received: from DS7P222CA0004.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::14) by LV2PR12MB5750.namprd12.prod.outlook.com (2603:10b6:408:17e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.18; Fri, 15 Jul 2022 15:05:43 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::e4) by DS7P222CA0004.outlook.office365.com (2603:10b6:8:2e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:42 +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.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:41 +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; Fri, 15 Jul 2022 10:05:39 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 05/14] mm: add device coherent vma selection for memory migration Date: Fri, 15 Jul 2022 10:05:12 -0500 Message-ID: <20220715150521.18165-6-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: 1a2f3484-bb6c-4f4f-4f6a-08da66737c5e X-MS-TrafficTypeDiagnostic: LV2PR12MB5750:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2jQfFetPKdPb69TlQ9GJdiRSwpgh6CG9O9j4i+0A2InL4kpJOY5zOcgpP/nVAiH31gJWqDScpM3jNSXJ4arijUOJqSobM9+vbtXx88PQsjQn5VKynqYnGzAXIw4cYbr/dx28RXhEi55um2YGQTzJC03C3wI8+pfYE99ky5vwNOSWyTWDF6PvHr6zCqi7i9I4/Ps3Q/Pjo6exKQT7rxRkBMp7/L/hPCYnep7dnx9aP4w/KRtQuPLRNCx+Rc6HBnEHKpoJy4N7QrLhk4aHAqBpAaPWKYQ7/0jovuxWfTd3Y+9ZLrxfaaz2hcpTnTYkyf57fKYc23aZzO9tEkxbZL8BncphcMU79fioiuH/zFOMd/qL5hgItEd2skQTH+ie0QB6bpVudTrxFrF4LkmF/MwWNaqLGgKzFq051L4W86zkl/s3eRWkR9GZhYCpT0tK8zbwgGoiXM1+MoYfFty175rPK/4TYsZPb0UTBAG4jq0/25vVIDXQnTNyK2dN77ZMHDyHJtnivyevZZSrKsjiwClUNrMXhvjTcoMc1PWoqBoX5g5lmphHIEM4GaqqSbmf4eY2Jt4yYerPzbJ6nlMhgS4KKvzpU7AcbJm3APGQXEgxyGDnTj70Mj+Vdj9+w3Z/apwtA7qpZjc9JGuXDYuKlWbmWLuQEROHyoG8ZfO8jHKbEWWM2zzJBanITIcG6fGhqg629N29a66btg8823wNi/pX4hmdvKTH7yd6+alWoUpZ9SOhQI2S2Gb4vp4ia515mzZ1xLFjvSFS0qkqxV3seRlMln8zpp624WCozzvOvD/v05k3+fSX+bID4Wp3sbomF+zOYR3C68E+PXsuBI/HK07/YeW6j0ZIGDTXIUzr1mC1hos= 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)(82310400005)(316002)(36756003)(82740400003)(40480700001)(8676002)(4326008)(356005)(81166007)(54906003)(6916009)(70206006)(36860700001)(70586007)(26005)(7696005)(336012)(426003)(8936002)(6666004)(2906002)(2616005)(1076003)(86362001)(44832011)(40460700003)(83380400001)(478600001)(47076005)(41300700001)(7416002)(5660300002)(186003)(16526019)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:41.9236 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a2f3484-bb6c-4f4f-4f6a-08da66737c5e 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: LV2PR12MB5750 ARC-Authentication-Results: i=2; imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=pvfJ4UZf; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf18.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.79 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=1657897549; 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=FufDotkIE3bdjczHZAIIAyLhAtHM05ZPrkv0yNJ6rj0=; b=LmKzBQOBwizusZp6/z/DlT9c3pgeQAyGhEHW+VH6xco1s8YNt0fnUuCj/EXFVci2HIIb5s NRqOI6OxXhGT2JjbNXFXkhOseARbwYljZ/0C46CrTG6huwjYQAu7osTJ8OZqhhicJTMFJp pJSNlRlzxegw+me5YKR7/F6alGswsl8= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897549; a=rsa-sha256; cv=pass; b=V+eiiWuNHnGGZf5Er12e/qiGVBLmi9vqs1qLN9LWIWVmVBKiXz5CnTxZ7LdoxAqSwS1zhK g3uCqCQXqzPeh8Mrfb6EFx1qbm0f8oOHbRrsJgACK/wiAM9THCionBI4o4RZfr95y8LYIK izNUy7Y7QlS27JAF7lwY47qln4GyyeM= X-Rspam-User: X-Rspamd-Queue-Id: 933C81C00BF X-Rspamd-Server: rspam02 X-Stat-Signature: bgc8f6sntrdyqh1zgw4smyw97qbxcy59 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=pvfJ4UZf; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf18.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.79 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1657897546-724348 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 Fri Jul 15 15:05: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: 12919366 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 EB761C433EF for ; Fri, 15 Jul 2022 15:05:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4335F9401F3; Fri, 15 Jul 2022 11:05:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31FCE9401F1; Fri, 15 Jul 2022 11:05:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 199CD9401F3; Fri, 15 Jul 2022 11:05:51 -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 0BC999401F1 for ; Fri, 15 Jul 2022 11:05:51 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D6FF61502 for ; Fri, 15 Jul 2022 15:05:50 +0000 (UTC) X-FDA: 79689658860.04.81E9A9C Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2079.outbound.protection.outlook.com [40.107.223.79]) by imf09.hostedemail.com (Postfix) with ESMTP id C17391400C4 for ; Fri, 15 Jul 2022 15:05:47 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RuxfDi8WJjxQr6f+IOcXOi0gzWpwqBAxG6LW+7k9C9/R7Nhg/5jQGBpZ9/52qtYEuTOeFlbMKSUL5LCIjrNigeTbWJ4tcUIv9u/IuMz0OUbo+XS4QaibfCnfXzZdrJ9E/Fl1ye/PodfWDhjoZF7CMXtysqjhGa2xrCHDp09D+lsjNICXrD6MPqujkTxKYbrp3Z+6doWFLE74f6Lnrk3fknLIa8/g739SGYyy0Ez0gw6qZxtRtKyY3dkU+uCS7yXcf5cG6l1dpzIc67x4FbeEnj2bcR8C/Ml7IRRZtRMG9XNVsC29ietKIvF11nA+EnDJZIC5XgwU+U+Cnep0BOdUyA== 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=W3l0gEneWCJT4Ri2gf2TD+v66/MIF7719Km5cR/hjO0=; b=YaENBHD/sAkJg9HXvHkPOLvpg0w9ICjzRtKFkA4nPHh7qnPy25p4pNH6/Ed4FKUN5tLp2E+eR56EU7K4PUtnFD8bpqPrQ2bk69Y7f2Tv5HGrw5KtK1II6VJOVqt84QgjnAQoTvBrsGFvK6MH0cg5Y2eQG7vPK84DqPDa0HLzNqEGx1GrZyUKCQZnJaa8sKBdAjxj7gF3kuPW9QsehI10lmPaULYvfNgyEQWMcl98HowbNljpAUbPo2Zbs9wWkleXP+coPCtzHdBz5+xbWviL+V1QExqJGxvBEFQEs4OuvbQMvg4p+wc0IvALrTvNkfYwPIFB3dp/rLqTPuyDKzpfGg== 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=W3l0gEneWCJT4Ri2gf2TD+v66/MIF7719Km5cR/hjO0=; b=nyJwpsWRmjn51UnkJaii6DfqQ2vgHxwT8gpPV1BVD9XcGNicr30szpnKzdO+QQ/JF0QlcpF4UM2nZckAscgIeiYdtQRXah4N3+06ZJrwDQhsF5eyVwAnLCTCk/VN6IEjYJMeKworEaYVOuqR8RcDj9EQKxgipjruK7Uaku/cRRo= Received: from DS7P222CA0005.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::17) by MN2PR12MB3630.namprd12.prod.outlook.com (2603:10b6:208:cc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.23; Fri, 15 Jul 2022 15:05:44 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::4e) by DS7P222CA0005.outlook.office365.com (2603:10b6:8:2e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.17 via Frontend Transport; Fri, 15 Jul 2022 15:05:43 +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.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:43 +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; Fri, 15 Jul 2022 10:05:41 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 06/14] mm/gup: migrate device coherent pages when pinning instead of failing Date: Fri, 15 Jul 2022 10:05:13 -0500 Message-ID: <20220715150521.18165-7-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: d3452268-56ce-42ce-50d0-08da66737d88 X-MS-TrafficTypeDiagnostic: MN2PR12MB3630:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MXxToRlP+XuoGQ1xwl0Wp0Hyf0j5KsWqDggjqCP/S9tQuSXJN2OIsf42dKc6+ehXN6QPZNmj7ULfYxhBBNeYiu+LB+GWusjb7morTAtkDpaPA8UH7AlfGsd6H7/SWWBOnuextJgXRSV/KwATUsXYYs984/xdbtzmf7T4wrKBfNzbZndPkd8/T877QAn/YvLTaFa80dvCUpqBT2AV7406zNSrWhalF2+yx2jWeZ8BegdtIPFNrcQccGZmxnCzLiZ4KYl6g06o7tbk0X9gR7VfDl7ZvC7h2uz2IUb1PpX+HnQFIX4OA2DettoyMBarFIZdz8iTdcBKdzwPcIcgzy3eFJxzclin8oqbUnQ+J8gjemAzoPsUJoY56avh+ts3ldhMTkcp7XmnT1dnLWj8uJBg6EKsNYNDNLeqMQoy0g8+qH+ejcmNbiuQ/b92MKSC4sRsY04a2LifXJ4qVW6P4ezliOg9XNgroK5dr6988Nap2d5T4ACRf5k6nAXgGUJurhW1ITmWL7oJZJ6Uqpu8lSsByxNLeqO6/CD8Jm3IFXj2c1suT8i819QlzwP04K+Le6bXZlyFUVvjb7z1cK2jealMOcQyTzX691mYUbl7tqzCjIn/OIZ9k7a/5yKjX19ABEg57iwrpoBProvIm0WAmTKsUpmsjwvg8I8qF3yV0JkaEh50SIGCBjmYhaCDd8uXXQYZJiIJsakAMQOlFtwJMqswHSSUBP6++CoBqSSmFrrNeK8d9Zq+gkJeG+JHx/zVPUQRDqeh6h89lkVrCm4sWfxLGWY9xrP2jtpZOG3oAFEl9WIa4v9GyaAdxT1ecExTnVUthO66EH0ejfpn2DKBWh4ecs5+DeMftZQd+qCy6AuFDkE= 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)(396003)(376002)(40470700004)(46966006)(36840700001)(44832011)(7416002)(5660300002)(2906002)(40480700001)(70586007)(316002)(8936002)(70206006)(16526019)(478600001)(186003)(54906003)(82310400005)(26005)(6916009)(7696005)(8676002)(41300700001)(2616005)(6666004)(47076005)(426003)(336012)(81166007)(82740400003)(86362001)(83380400001)(356005)(1076003)(4326008)(36756003)(40460700003)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:43.8610 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d3452268-56ce-42ce-50d0-08da66737d88 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: MN2PR12MB3630 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657897550; 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=W3l0gEneWCJT4Ri2gf2TD+v66/MIF7719Km5cR/hjO0=; b=hjDHyDjp9dSuBv95bmIpXYmwIezX5YpKcbyFH4kNIzdzvJU9MWo4IrzVWu998tvZBgHGpa sQLlxH/kXNy/QD9g7iCL1L1GZiAAGFduq45v5agmJ08i1KrusNhcnnWJ5q4UsiIGgpMgtn /7PIs9rC+SQmkATvS0GQwicdm+xs1/U= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897550; a=rsa-sha256; cv=pass; b=Jl4JHha1jZJiXb2IEEdV6z7TNSqyQ0mM/TizQYN06XqcnKARccI/2bYaDCL/Eemi8jMNTr P0y9XdVgUbLKZkiFOuuoDOXKB9DkfI5u+5nyzetwbRET+1CF8mNT4tU1jNuw30bpgmK9DX H0b9gxiQfPQYHmrAWj84xomWpwyDe1U= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=nyJwpsWR; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf09.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.79 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Stat-Signature: ghc8jqor7ggthteubds5qzp38ijzsmza X-Rspamd-Queue-Id: C17391400C4 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=nyJwpsWR; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf09.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.79 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1657897547-693987 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. [hch: rebased to the split device memory checks, moved migrate_device_page to migrate_device.c] Signed-off-by: Alistair Popple Acked-by: Felix Kuehling Signed-off-by: Christoph Hellwig Reviewed-by: David Hildenbrand --- mm/gup.c | 50 +++++++++++++++++++++++++++++++++++++------ mm/internal.h | 1 + mm/migrate_device.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 7 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index b65fe8bf5af4..22b97ab61cd9 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1881,7 +1881,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, unsigned long isolation_error_count = 0, i; struct folio *prev_folio = NULL; LIST_HEAD(movable_page_list); - bool drain_allow = true; + bool drain_allow = true, coherent_pages = false; int ret = 0; for (i = 0; i < nr_pages; i++) { @@ -1891,9 +1891,38 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, continue; prev_folio = folio; - if (folio_is_longterm_pinnable(folio)) + /* + * 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)) { + /* + * We always want a new GUP lookup with device coherent + * pages. + */ + pages[i] = 0; + coherent_pages = true; + + /* + * 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); + } + + ret = migrate_device_coherent_page(&folio->page); + if (ret) + goto unpin_pages; + continue; + } + if (folio_is_longterm_pinnable(folio)) + continue; /* * Try to move out any movable page before pinning the range. */ @@ -1919,7 +1948,8 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, folio_nr_pages(folio)); } - if (!list_empty(&movable_page_list) || isolation_error_count) + if (!list_empty(&movable_page_list) || isolation_error_count + || coherent_pages) goto unpin_pages; /* @@ -1929,10 +1959,16 @@ 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++) + /* + * pages[i] might be NULL if any device coherent pages were found. + */ + 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..899dab512c5a 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); +int migrate_device_coherent_page(struct page *page); /* * mm/gup.c diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 18bc6483f63a..7feeb447e3b9 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -686,6 +686,12 @@ void migrate_vma_pages(struct migrate_vma *migrate) } if (!page) { + /* + * The only time there is no vma is when called from + * migrate_device_coherent_page(). However this isn't + * called if the page could not be unmapped. + */ + VM_BUG_ON(!migrate->vma); if (!(migrate->src[i] & MIGRATE_PFN_MIGRATE)) continue; if (!notified) { @@ -794,3 +800,49 @@ 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. + */ +int migrate_device_coherent_page(struct page *page) +{ + unsigned long src_pfn, dst_pfn = 0; + struct migrate_vma args; + struct page *dpage; + + WARN_ON_ONCE(PageCompound(page)); + + 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; + + /* + * We don't have a VMA and don't need to walk the page tables to find + * the source page. So call migrate_vma_unmap() directly to unmap the + * page as migrate_vma_setup() will fail if args.vma == NULL. + */ + migrate_vma_unmap(&args); + if (!(src_pfn & MIGRATE_PFN_MIGRATE)) + return -EBUSY; + + dpage = alloc_page(GFP_USER | __GFP_NOWARN); + 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 (src_pfn & MIGRATE_PFN_MIGRATE) + return 0; + return -EBUSY; +} From patchwork Fri Jul 15 15:05: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: 12919373 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 0D054C43334 for ; Fri, 15 Jul 2022 15:06:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1CD89401FA; Fri, 15 Jul 2022 11:06:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D82179401F1; Fri, 15 Jul 2022 11:06:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B366E9401FA; Fri, 15 Jul 2022 11:06:01 -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 A47EA9401F1 for ; Fri, 15 Jul 2022 11:06:01 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7667A32A46 for ; Fri, 15 Jul 2022 15:06:01 +0000 (UTC) X-FDA: 79689659322.04.19121FC Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2046.outbound.protection.outlook.com [40.107.237.46]) by imf13.hostedemail.com (Postfix) with ESMTP id 2C063200D8 for ; Fri, 15 Jul 2022 15:05:56 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OB0OIfBRAQ5exqkkeCT4v4DWeQgh2bLkFIxlLQgvO/4JsVvEVSAugOV1cSRiCewnCdZjWSX/NWuE4A/wz0pHfQVtyTBCGrd1EpWZkGqySp/6mUOvsACsX+BRg85I0/fsIxKdpglTHUFeJ3akD9Pagj13vY9jRFWzCjFNXRJzcOVd3/vKyculoZ8JA8J1kY5cDjfnPom7R5bCnYdWcflL5cC71CTzWgN1hW1aSRtkEkcdLoIie+bpjLQjqACpgScu2fNCgQ5hFxI3gz25x6moBGjtKs/Wg4R8EgsMmEzbXjBYGwRRu3n9zMDsDhlv+mOx6qwniKyY0KUzbSuYWgLKhQ== 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=HOGo0LyikZc9WD5IKrtvM+t1D6KUQJEP7pmEX/d5mFHXCEARA4gKBagrfzjKj5krT0rm8JxGhWv4wVm0M1dPk3F2OopkaUPsk/leiAqbmSS3XwdmYqNxLwFC99CCcjUvvsiGeC832tpvtXkDFSPhqzsF8U8pkt/3rm/ESBSc5a0m6nCqIMaiPgi3a0HLH8ugpk8xHWkxMw2tUuOC67i9NWqzD4SNLLtLJ3XlJNvs7TL830+fzb/ovCIrWWW1K3GKgFrUGJHRm+mX8IpW/ofl7I5a5tUW2aTArsQFGjmRid46hFaoC2qxth+5X1jn7e0WYhA82OUEi7BMHYWBm/73Nw== 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=JOjT9d05ZXCOySImmdY788C5dlpM+7MNqpbtzCGRVXzYw1quao/ztqzXK67I2YiWtEHzALfX/+cwxhMXxP/gEUiKDKKIGLqLgVij1p69KXULjsfbAFZDetVb3HUR/Qfm8Zj4YaoTnJw3jmoyYI8YflyzWD0k6dY9KpT+0EF/PkU= Received: from DS7P222CA0007.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::24) by BN8PR12MB3059.namprd12.prod.outlook.com (2603:10b6:408:42::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.14; Fri, 15 Jul 2022 15:05:44 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::b7) by DS7P222CA0007.outlook.office365.com (2603:10b6:8:2e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.19 via Frontend Transport; Fri, 15 Jul 2022 15:05:44 +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.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:44 +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; Fri, 15 Jul 2022 10:05:42 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 07/14] drm/amdkfd: add SPM support for SVM Date: Fri, 15 Jul 2022 10:05:14 -0500 Message-ID: <20220715150521.18165-8-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: 5b8ce66b-7895-4694-720b-08da66737dec X-MS-TrafficTypeDiagnostic: BN8PR12MB3059:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X9s7+ESVJUBcu39zP92JQ9LAXjRjyVYWg3BT6GXuApuEpHcL5wkDxiauMEL0DVnmDMpWdyF+c6FVkSXFfukhrizwTo+vSkux9jkqm5SKbUrgp1Q/7RrsATmw0xsE5nzyndvoUcImoLjgLRcabceLpZYgcktBpRTJzQRtgSCfSmCKuaFMFmD30ScyeMG81CLRloKbpBqGMgamJNnZ+g1U5rQO+MLawjTdnZlekBuFNsoIHBwHcczIuN/XWNXkLv7cKpNaPw5wRa/O6p1Zy/AdKc0MSiw+fuWcenpPeQpsFhvnZSgIMW1326nrmEro+t1n/BxzGDUUwc30WXqKPhA7FKqt7R4tSMlQGa4SRph44gTJXm59q6aOkMrJNbKxPGYNohm6hy0nmjfNaMXuCpRgZVU0rSjTaoM46KbTMniaJ/voQuoHT1OJzDL83xqfiHhX1mHbqvYuqTYdYYZhuIAeLc/yrez7qdQs5Vyymisy+UQysXXhaWMOqmGPZrQpMioCFyr/pZKIy3de+m6K8IpgL54oR/8DcNUyljcPQZ2Dz5Py6JBI3Y17nrLtAznbrxMh/lp++WVHOLdd9pUUWx6gQS7uhqFUIZ/0JDjscFnla3Dsr+euIUM/hq2hZUAjKF6Tk76hFS85xj4TVQDsErHFT0PmT2/OL840mgzGl41PJ7LlBYBGm2v6SJ+WsH4k8ZjwkDDngvQyaJnr1mEWeRFmxKCkJdqvFphcYD/C99GU4qYprPLcSCHnff9aNM/DF4JpbaXiE2fS/pHa/hIfIspqLPtja75JWjbuaYpeDgd1IklqBQ5d5j/pGEndK2xNBacYl1Oq71qc8iAm5rTESoDkjaqyDkddv4w4rgWacNm7ddA= 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)(376002)(39860400002)(46966006)(40470700004)(36840700001)(26005)(4326008)(316002)(6916009)(82310400005)(54906003)(2616005)(40480700001)(7696005)(41300700001)(86362001)(478600001)(6666004)(82740400003)(356005)(40460700003)(81166007)(186003)(1076003)(8936002)(47076005)(426003)(16526019)(83380400001)(2906002)(70586007)(7416002)(70206006)(5660300002)(36756003)(8676002)(44832011)(336012)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:44.5172 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5b8ce66b-7895-4694-720b-08da66737dec 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: BN8PR12MB3059 ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=JOjT9d05; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf13.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.46 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=1657897557; 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=HuS3vldIStBC0zd5WaxpOCKv4uQS5oGwv/VdsL3dxHa9NVcRKVJsjG+cRG6NFqkL0ckkz1 C+z3YCsEXceob08P5xhykJXBhTMMyMCNQbGcmcDs5GyyI3tA3XlfaIeCACBSzMPrYmcy5z IfVagrT7gxyJf9t55BOFJZlRvDeB1tI= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897557; a=rsa-sha256; cv=pass; b=mqiP1qMWAxpzRZuDOGfQXk56Cd7TmfGNgF5T434Vx3Wum6yzfgZ0Ypswe3YzqLbyIBKLkM t5Pdh+zdjaoNaRE7O+5vCIPoEewd7F/j5C1dGwXyNz2YaoMro33Icn9moBGSzxsfnem3kQ szaZ4jA05Zk1WJ5nfH4Phq8U6WTtDqc= X-Rspam-User: X-Rspamd-Queue-Id: 2C063200D8 X-Rspamd-Server: rspam02 X-Stat-Signature: mizaoifzqnh4az3wh7w4iwpsjzprup47 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=JOjT9d05; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf13.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.46 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1657897556-332968 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 Fri Jul 15 15:05: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: 12919369 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 783DBC43334 for ; Fri, 15 Jul 2022 15:06:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6563A9401F6; Fri, 15 Jul 2022 11:05:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5DF5A9401F1; Fri, 15 Jul 2022 11:05:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D1839401F6; Fri, 15 Jul 2022 11:05:54 -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 1D6FE9401F1 for ; Fri, 15 Jul 2022 11:05:54 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EA78D3432F for ; Fri, 15 Jul 2022 15:05:53 +0000 (UTC) X-FDA: 79689658986.12.FC369B0 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2042.outbound.protection.outlook.com [40.107.220.42]) by imf05.hostedemail.com (Postfix) with ESMTP id 74BC6100086 for ; Fri, 15 Jul 2022 15:05:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b5M9No4geiePklwmMfBMmz/xEnMrvtHv6hW4QCULhd3/oshMVNadTBoWjWXjnM60Q2VQbb6B5tBEgoD+KzUpyW3HkThTrdLtvhcqO/7k1DhxDlsjR2KiBiqlWAN00b/NnOQ4gXKKu6NQG8LM4mFo/mNMpmjad34PqIWSq+a/DxZbHorZG/Zfw6C0Z/HHz5ubMbRbqycEAWYhRAAGIC08chIcQjpp6UZWr8zrUOfYF2UD/6C4OfAekqj4AoByHAmmLFOnUl8SJnGT3tQG+wWoOKQGUkXYLKDBhelqmUaEvwHCYR2OHbKCiF2VtRVUf0BgI6CdcUkbgV3DtSfrScQoBA== 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=SAA6ZJV0yHUosCi1y+61teVyyJYa899BHn17bBrVn7QWQRsCepnGJqKt2iEJ6L+STgde+6lxW2CN8gyCpagZ7fwBvRdUnAwflcypmPh/jXkgkXiJI7IjmVqBhH5Xx27ss228dLZZRaViSkodrqhIrODyPgqE37Y2mMcBkIh8EujIe/SBMG6EKboJ2EVqGGJD/IbI/7AyegzxKJm1RYa4mqQFv3YOpYJNvX6XxszMiexDHSCYBaXlPTgKQVb/3v2O7kC5+1YL2ppAd039euSMcUOaCdaeWFqEz2pHW7PwJzlOz6dtCo9w4vDiXeaUISSfda6zDBg0tMQrwiJkn/xKzQ== 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=QEGXLUC1KK+U5WJng+HhzJNljtPLaZIA55bRf34M8Zyh+DorlY0vFTnjGIPGmcM8CKn9/B3z97f33ETX9tgPeW8YkAT07FVr3Uqs/PCrS2yNebjA0BPHFm3pG3QG6yAMAoCQ7x/7sXoye+CczmFYA0jbkRnwHi5ojNk0l0uRTYA= Received: from DM6PR07CA0057.namprd07.prod.outlook.com (2603:10b6:5:74::34) by BN6PR12MB1937.namprd12.prod.outlook.com (2603:10b6:404:108::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.12; Fri, 15 Jul 2022 15:05:48 +0000 Received: from DM6NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:5:74:cafe::da) by DM6PR07CA0057.outlook.office365.com (2603:10b6:5:74::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.23 via Frontend Transport; Fri, 15 Jul 2022 15:05:47 +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 DM6NAM11FT010.mail.protection.outlook.com (10.13.172.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:47 +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; Fri, 15 Jul 2022 10:05:43 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 08/14] lib: test_hmm add ioctl to get zone device type Date: Fri, 15 Jul 2022 10:05:15 -0500 Message-ID: <20220715150521.18165-9-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: 0d23c36a-44d8-41e3-593d-08da66737fdc X-MS-TrafficTypeDiagnostic: BN6PR12MB1937:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QpAuV0rNSBZN+20uXTRBBkk6sZZzgGTg5Ijp4jl2IpAA7xtAAnOldNIOXTplX4p0UbI0DjvK8w/nbmZIEGTNE8VZdv1JGBryl4+EPA2hl8xYFaf/HezOxEwJmZF3NMQX2SSK0EME+46UO3RzTbP9wbNPNaFJfim5IhK8QxrGhVX91Hql1u4CKFt/xCSDbJ5ubH6X+QnWPlibn/WEo0LVw5uQ73V2IR1TTxWR2p68kCiiytk2QpfgMVwFdLAM7Ce+JDbqkMKEeejXRkzmDA7yv3M+tk7KTBQ3T/4rddmmUuIBNQbC5/IguXC+MDgVv410odUEy6qgZ8dxj1zb3SHlyEjEiSAq0rN1Dz/XLPTHTn2RCjUDw79RChvTCgvmeokumsWutwoB5Rql1O60vdaf90O2MHjDtyUBm4sTsm+oyEELyMjsXnijM5lDp8zSQwEuFlSCZdK/8MRIqPt1uHu87s1aabxQtAwTfIoKgdYAx57e8aM4jhlls5R4o/3BhRB9ypulLV7TKH3hUSL3zLnaPBJS+HQpouGoR3IVXCrFkap0JocWZ/FrjKkYQ3XdzzWmBR1t8x9Iw29g89ewZ0w13y+NNW/dQJE3EoBs48PNxGhdVWauy2t4grHZWZhSC/NCIZIhU2LJjOcuW7r5j4Oakd11W5oQZQqVzn3K5IxgW3ifu8LwI16OXF6sr9OT9WR6bdV3OeiHPQeQyqa0dzdpW0sazzeU4+LhMcoL9IsHN0lzzfpzGQBG9yDrdpTY5Ckm7w2POPaG/TeGQ3YmZ1uNNPmSu2v3XSoWupGPawI3p7zw4+IIpXz7jUTGDQmEMn4qMfpHcVWLD7o7jEwJ8YcTAgWfyazorrzJurDu6ehtWKE= 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)(39860400002)(346002)(136003)(396003)(36840700001)(40470700004)(46966006)(6666004)(26005)(7696005)(70586007)(478600001)(70206006)(8676002)(7416002)(86362001)(40460700003)(4326008)(83380400001)(316002)(81166007)(82310400005)(54906003)(41300700001)(2616005)(8936002)(426003)(336012)(36860700001)(16526019)(82740400003)(6916009)(47076005)(1076003)(356005)(36756003)(40480700001)(186003)(5660300002)(44832011)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:47.7672 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0d23c36a-44d8-41e3-593d-08da66737fdc 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: DM6NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1937 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897551; a=rsa-sha256; cv=pass; b=eKWBjU/XdTg2J93qwxFVjp0DLaP3RRPOwH0kx8txoywjq1kPfk4Lh1MbN7/kwwXMAkk8eQ IhIDHtjUk+CBv8EnFqee6MLE2GX8bi4F0Oa42p+EBUPxXY+h7XGqw8ePK8QiE0VTkQt8UL E5vRGgwdUl8n+s/VtJlfc0xUGW0KQaE= ARC-Authentication-Results: i=2; imf05.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=QEGXLUC1; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf05.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.220.42 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=1657897551; 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=qimcmzYrEvJmBSfeJkbbNIwHSs9DZwb8mI3/o5d2Zxi+Vy2J978acU2O+EgM2UvC7KumUy D2jNMLL51LPzBL4HVFCuAb82fUJpAv+L7NhmFaneVy3kpqyTNMkLBjJFZvnVlUaAdGg8l3 y5h3XybROtnFWxbbbOsqBTiKNnUCYpA= X-Stat-Signature: ghzci79hio4617kxco38396xiniops5f X-Rspamd-Queue-Id: 74BC6100086 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=QEGXLUC1; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf05.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.220.42 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1657897551-896784 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 Fri Jul 15 15:05: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: 12919374 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 ED7E1CCA47C for ; Fri, 15 Jul 2022 15:06:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12EC29401F1; Fri, 15 Jul 2022 11:06:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2FCA9401FC; Fri, 15 Jul 2022 11:06:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0B0E9401FB; Fri, 15 Jul 2022 11:06:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B6BA39401F1 for ; Fri, 15 Jul 2022 11:06:01 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 973D61203BE for ; Fri, 15 Jul 2022 15:06:01 +0000 (UTC) X-FDA: 79689659322.29.71971DF Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2049.outbound.protection.outlook.com [40.107.243.49]) by imf13.hostedemail.com (Postfix) with ESMTP id A6721200C8 for ; Fri, 15 Jul 2022 15:05:58 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F7Y9C2oB1lTulVjwUnOgLzCJuwLDNPzx/VEHKddhvFICjKnT70HoiKLD8WGa1ZCM73IhSfUUtT1jAe6xcMYPys2K+rblHDwk4qvkvwf+IyVbDV1UbV6kab1mzMQv5gt/bPb8sPMka3KCfJbBUqbY5HEXgAurYdXQJRJNeW5+XDwYONd3NmNP8yGKzyjX0bJLPYEVKBFdibkLgf4xq3oL5CUUQMA3Iw+JUDR43PtzYY6P0r2VQWP7ZBARnQZkchfOZa5eTo6gDbgng4x7qHdZepd/AE4eQ9GPk4pyodVqloqXwUkOJfPF5s4fOK1fiBFMP1oUVBZhbQ37LcdhYsqi/A== 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=mi0PBiJ5XKCqeXeY46poO/Z1lYqnDQSJa6jX9WACpQL9C2MNP+gm12l4fgnkI7I/Vra74V2q979G7fbmpYbtveQZR3UoiKZEv1N5g7n1qmWAhXmGBzitH2AH+8O6iffSlKIThL8t+QjwCApQgmLmj9vOtEf/x9HOMMFqZe0FBG10zPPkTsUAL2/Y7YCTJ15Qi08r3QfCklWL9hv9OiopLFQE5mM9532b9G7AGqsKXOB1cQ7LQAuvMbvxsVvvaYsYsjMkklBCqRYy2yQKTolN3zAUlrcQaeWgrOAw7zyTYhS6nd7nY1UO/vehxqrYYIxFYB/EvSeczyl9c9XRwSUkSA== 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=XxrI5wDLbB87B5uGesHyFKbVWFHWIZMFjR7wcfeKhZ+jadLxKTftJDSI4CU4ZxurlLfTi5QKNXCzWOOIlzvjszi6uX0ehfSF2lpnCJjjKuEPG7BZpHQk0B6TNbyPW9eKro039JnoA4HL0YzvZ5XOP/lpjCRZWimMXSCNJ2zVkh8= Received: from DM6PR07CA0072.namprd07.prod.outlook.com (2603:10b6:5:74::49) by BN8PR12MB3345.namprd12.prod.outlook.com (2603:10b6:408:64::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.12; Fri, 15 Jul 2022 15:05:48 +0000 Received: from DM6NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:5:74:cafe::a1) by DM6PR07CA0072.outlook.office365.com (2603:10b6:5:74::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.22 via Frontend Transport; Fri, 15 Jul 2022 15:05:48 +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 DM6NAM11FT010.mail.protection.outlook.com (10.13.172.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:48 +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; Fri, 15 Jul 2022 10:05:44 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 09/14] lib: test_hmm add module param for zone device type Date: Fri, 15 Jul 2022 10:05:16 -0500 Message-ID: <20220715150521.18165-10-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: 1f6cdcd3-8dc6-48f6-ca0d-08da6673802f X-MS-TrafficTypeDiagnostic: BN8PR12MB3345:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qpvLoJN34PB8ff2kwHYBEsY7fzRAdM3RyzerGOqQM5lTM0gIfV/5ecK5lho7fcVOXtE9aswU5krELxocFXJ7Cr0+c8WEQwuCU3UP/WmygvZkXttpuGNmaKiaRUJDXKF/FT8Z3MgnMcT4rOMo8hGYTr0zOo2/zjjgANm+E+Mico9y6G8ExaU7ZGxNbIKx0koX9FMgBwz6FqlOtvz3denl97wCnxoxOuIQ6CEXNhzvYoHnHS6L8u4JeUZTKW4mg6vBZX/o7ZbJ2F0Q9pnGl+evcZJtttVI4vuxD5nzUA0lxbj40j45yPo59RCvOOK6iQGbVoluXLmheiUOrGfiNJzQ0qdGzvtQafI/EGr0pFZ5L4GQUVGxC0/yNkf7DvWXWwISptL7Q+y4Y3vJ1ZqzrxOxolU0uRUIzMGLjRC+FUkpj4pweZoQb80FON+xUkD3DH2aFCcjt2FsfEfvphvHhHH4zHTFknOYKWq5OUFtgOzsnZMemNI5LtdZyfZb9FDTIK440vvXg3x1kMd+qWAsRW6ccrTT0ju84WJLdBKXxnqj3Ch1kI0cRG4Wv7QPnLjoO/AiTV7NAzaTm6hOJheiCwITTYQqiNvZe3PCyqvrKrRtZrJ+O96ApO3ePTdc/36aUdlPhdtNnpWPjhXjGulMutpc5jMpG84WbUCJ9B61rDMpy+SLChuL1nqOSKFuxGMCbS6CeVQWwH716MT5lZ8pIPOYUs2bF/fx+GoyUPRi39RZjmOaQzbOlfgWpv5OohiFX3BxU5VQj7mU/0oGXs6UKUobUtmMq0xnaVC5wUEkPZF9xe4oTl7o78gv/ZM6IyhAfYHDZjlwzUbfmE7izZHOiC8USHwELzNcovYKDGN0afF6IzM= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(396003)(39860400002)(136003)(346002)(376002)(46966006)(36840700001)(40470700004)(81166007)(36860700001)(82740400003)(356005)(36756003)(40480700001)(47076005)(83380400001)(54906003)(6916009)(16526019)(82310400005)(426003)(336012)(186003)(8676002)(2616005)(1076003)(5660300002)(41300700001)(2906002)(70206006)(6666004)(4326008)(70586007)(8936002)(478600001)(26005)(316002)(7696005)(40460700003)(86362001)(7416002)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:48.3140 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1f6cdcd3-8dc6-48f6-ca0d-08da6673802f 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: DM6NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3345 ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=XxrI5wDL; spf=pass (imf13.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.243.49 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-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657897558; 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=gsnCOCUygfFPOYMG/w+XKTxAid7AwjpFX8KB2TEkZKpbkyn6wBTXPQUso891pKQcnnIBvV nc0LWMcXJ9MlJBhlhdjHLqTNNFJYTw82J9np+FrmloLw9iP4dB7rJg3m0X2buLp7lKUXN0 0AuVkPTAsi+RH+DgKqkzbsLx0o3sHfg= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897558; a=rsa-sha256; cv=pass; b=bu7fuJI2pArMFPITaOU3tic8OVk45D7XVuMwckuJA7k94BkRKtWTjpMTZDTxldRI+NBp0j Xt/QQOYCoSUJS90iS1k+VhI224cF/lfQmiW+sCp5blUGCszVfoc7oQAw2Ftbyv0IhqS6X8 hnro/dKFSjKEf/mzRN2wX8DcibvE2f8= X-Stat-Signature: 5yabbuzbatp8dwn7thiz57pqxqtx49eq X-Rspamd-Queue-Id: A6721200C8 X-Rspamd-Server: rspam07 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=XxrI5wDL; spf=pass (imf13.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.243.49 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-HE-Tag: 1657897558-303414 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 Fri Jul 15 15:05: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: 12919368 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 832DECCA47C for ; Fri, 15 Jul 2022 15:05:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A77279401F5; Fri, 15 Jul 2022 11:05:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C6379401F1; Fri, 15 Jul 2022 11:05:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60B469401F5; Fri, 15 Jul 2022 11:05:53 -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 470D69401F1 for ; Fri, 15 Jul 2022 11:05:53 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F157634B9E for ; Fri, 15 Jul 2022 15:05:52 +0000 (UTC) X-FDA: 79689658944.15.418C175 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2054.outbound.protection.outlook.com [40.107.95.54]) by imf23.hostedemail.com (Postfix) with ESMTP id 110DF14009D for ; Fri, 15 Jul 2022 15:05:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RZRF1TDyYTkePpm5UDFvaa+q+RKtdpelBSC1EW/APmomeYGnnO+BTjoaRFrUTc1Yl4lAOSMoaBrYpVQttN2QqKYx0gunHXMiRqXsWeYyEdKanHHoLND3pY8MRgPBhmdXPJBuYVJDWD1lXhJpOOjT3SJh49R8atkKrotkWXO6soRzU/jD2Ts1kRcjaBZaP6aW6y2nWzqkVjmVbKehXiCdNyo+93EIqSw747z6HNhXM01m9Bz7FiIDh1K1Nvw34q0F+WxZ+07EM4c/lIreErIInpYWKUD166vEuZ6209eGz0B+H5rVLU4QDSfBwCRTWZB0JfSAKjDIYjTjSAXs7016Yg== 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=azAGDWIfDRmjXUhYY5FoQGOt58JdoS6x3YLXu0G+2aecRttxCigJHxiMXV6FdQwma/Cd3E0HaemtQsFGeujzRE4j9bRhxdUphnWwZDpz8NTxS0S5fsZbvEd+d+j8vqCKTBJshLDMIjBG88LTX+GAJ8HpyvXZx2SrDFAM/sXZIugeil5OhpNBpb3yB/GA9o4cyLGnYV27zoYi+7LQmjS5DwEDybYkK9CG8CD2pWZy6z7pFad9uDIqllDbJ7G4O3kU688G5IwUrQlZy+uScJ9Q3Oct8PMO6WIhAhTCu7ZQkQ4ngUR3wOtvIt9dgI+pSAWQa3sbvhFYPII1YYnLjro7lg== 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=TMjSy7Q2kE1lujecROxMW0O1xxin2NAFjPQaY6QXNXPWp/AkqkWF2Op07KEfhIdETr/1ZbAKAcCK7tusflJziptW6AEPrLXIXKFuhhe2kY8LtdfPR252kYvobHoM97Jmu9t2q9sUJt8hEjKLdX55S6Gxezud9CqmpTYy7G0HN6k= Received: from DS7P222CA0010.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::6) by BN6PR1201MB0132.namprd12.prod.outlook.com (2603:10b6:405:4d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.12; Fri, 15 Jul 2022 15:05:49 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::20) by DS7P222CA0010.outlook.office365.com (2603:10b6:8:2e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.15 via Frontend Transport; Fri, 15 Jul 2022 15:05:49 +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.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:49 +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; Fri, 15 Jul 2022 10:05:45 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 10/14] lib: add support for device coherent type in test_hmm Date: Fri, 15 Jul 2022 10:05:17 -0500 Message-ID: <20220715150521.18165-11-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: 34a8bad6-141d-474c-e1fe-08da667380d1 X-MS-TrafficTypeDiagnostic: BN6PR1201MB0132:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M4CUOyIxt1XqmueQbDN5PbNGG1yZoJfCK8rdcPpt8pnApGfF9Vna94uux9MqCXl8ToW+g3YhRVzLSVGQooR0bgkKvjyL8Sr+hWlZszjW5+mlJ7ZFqCno72BsMlDJ/tlMJFHzII9LHi/0jKGIOZUgsTvVHBTquhzFtUO1QTWY4mnbOtF7F+PoAXn7Zzb9+oyWivgWyzYPhaINo/tmnJGzTo6UsLOOQqvyy1Bf0F+amB+QA/enSAqGbcrW8N2DxKMT56cDZ2y1W3uDG84Vg1eGOgY/fo2ivOozgDIFjYwvBLH79t9zAb/Ni/2/02E08JQjVrsL36LofZtaf8b67OyOqCrkZL2Sj5Vs3cj1Gc3dDxLSIarMWGUN98H66jJ+xCwtoM9d7lyK9wwHsYLvYfYRAUmmT5BFCdiTq7hLvpbjURJ+D/CSgJX2uSAKJ0vr4oNQHZJhT/9PqGw6OaHops4RwuIgFSeXF26hTh2YtM7OOGf6obYazpEU6Oebb3r1uJtORR6PKRNJKM+wsShUxzHbpRNRK8cvI5nI4QAxWR2GwQ93HKKpUuP31T6Hez+7wMVZoliyq/6/pjOarXVzDxwfE2x1ntLWRLn4xvutWzbF32MlB4B56/iOwZC9eItyuh1Z4+dqR/dLibSmFJ7lHjC2IWmQ00oMClpFKw5VgqTVZLsnEfgquQ/VJKCsUEKdR6QFexHvRbM3NNt42okewxAkkn8o3DvKUAeqAOZHDEOlETRJw1Dg3/QspFyYEXLsYKTMWOOe2kc+O9/RKMa5u/2pRFGbvO0Kz+8ten/GxorkzSAAcGIqT16qRwcxNnj5cTY/O4SLUTGbJgeoPIkJ9qmWJ0mz7PlyU4KJCtD5Q46FGmc= 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)(39860400002)(346002)(136003)(40470700004)(46966006)(36840700001)(8936002)(36756003)(356005)(70206006)(54906003)(478600001)(6916009)(426003)(44832011)(30864003)(316002)(5660300002)(40460700003)(81166007)(82740400003)(70586007)(86362001)(4326008)(8676002)(7416002)(47076005)(83380400001)(336012)(2616005)(16526019)(82310400005)(41300700001)(7696005)(186003)(6666004)(36860700001)(1076003)(40480700001)(2906002)(26005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:49.3919 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 34a8bad6-141d-474c-e1fe-08da667380d1 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: BN6PR1201MB0132 ARC-Authentication-Results: i=2; imf23.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=TMjSy7Q2; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf23.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.95.54 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=1657897552; 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=BG0o630dP++EU4RNGIxFsYlWndYBMXsQvZYa3GlVQ7R2RVixQO6pwgnKgf+eIkGKB6A18W Tam8itH0iXQM4q47GEsajw+RDeFYoW8ML3SRT/EvMdy1LJD/gxblvxEkhfo4tPM0LcXpWs +KZsrSGEtuQHtaUIEMvEtqP8NN4TjYI= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897552; a=rsa-sha256; cv=pass; b=H5pws5Gs1wsLtHZdYrcVg+6YPqmqoYHc7vS0zMrMsJVxQVB1k9GVTMex/+sisJfH96fXmr 1Ew6fQINKy4DFdrTlwgUGXl8JGLZJXlePVCXIsu0qDcGpp0I5DPL6QsFuKV2bq7V9P+2Zj L2YwX6ErPe7fKzW+74saphbQMQcKzas= Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=TMjSy7Q2; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf23.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.95.54 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 110DF14009D X-Rspam-User: X-Stat-Signature: ow1r95k6fq8tumxnjb6dcgxz1qniuzgj X-HE-Tag: 1657897551-280023 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 Fri Jul 15 15:05: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: 12919367 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 9C575C43334 for ; Fri, 15 Jul 2022 15:05:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 768D09401F4; Fri, 15 Jul 2022 11:05:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 67C539401F1; Fri, 15 Jul 2022 11:05:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 346D49401F4; Fri, 15 Jul 2022 11:05:53 -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 259459401F1 for ; Fri, 15 Jul 2022 11:05:53 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 054BE805A1 for ; Fri, 15 Jul 2022 15:05:53 +0000 (UTC) X-FDA: 79689658986.09.B4164C3 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2059.outbound.protection.outlook.com [40.107.223.59]) by imf21.hostedemail.com (Postfix) with ESMTP id 473EC1C009E for ; Fri, 15 Jul 2022 15:05:52 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GnN5Xdgc9ZCNHDOOYHVq3zMkcmhbNrGHEF5RiRIDXi03V1fgPU8RDJ8HFmQ2TF+7CSZUYKEVARvzVmUBH/p0iEioR/7gT3kVhyl+sARKnlQ73L6VQoEqVuf+cu/4nVAgb9qRD1e8I1lVx4OX13BHjSFeDWDq937QSToDZKNmIOrW7ZxQ0YxEiWURNLn6gA+UgPaCmyJb5lcW51wfYWF5nELpy1EsjWCqHiPTf9128zHBCL2xbwHV1IhU02qiyECIGc9MkL2tJMu9z106FYp4VLySV/qiG41nJL/nIOcLJd0nfQ5dQejzcIFiWNJElJE+De7/q3w7+pJmHj1skXTQjg== 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=nUDK49xDNBg2yDXr8cz5O272U+dgcVmRHJwufi4zSW9WMGsVSKogEBx/ZAqf52zwgciZn7JbQrxkzg/pKEriWkw6WgPGg1J0gu4tO1+cAZECXkLbi1f2ZDHBTBZE/YdNeF7pn4HgWjU3SoLY+A21PKnAfjsRqn57od82spVR8OfrIKb3pdJsXASs18517b1p4Q+Wx/L0uj0eeCVpm+wYUh58iuw/x+CcoAvHurYg9MZoI6gyjlXs+ml+Z8aXxHzQ3N3j/+MAlUyNvrNq97gqD687klHM8mCtsJA9Dvy5mCqbOr7RaxD0jbdQi3SIRUgKvqSdIwQJSHGjy5qP+sLF+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=FBYoUu7uH3DDQme91+PAxWkWEbnIBTP5UUW8lp9tsk8=; b=xwp0Whuyu621ottdglPoiwm3tJhPuFqkLa2f82H44Ta0MO8Fn9504YmeQn7bywXNrriCBAR+EYXtGn5c/pv1gtSecbSUImwLORCJlNJAxAreBBB6JouHwsNCCKtkfrbcZpUeZDQIK1L3id45CmjhO9YFc0MvswaWp2nlol0p+mc= Received: from DS7P222CA0017.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::26) by BN7PR12MB2660.namprd12.prod.outlook.com (2603:10b6:408:29::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.19; Fri, 15 Jul 2022 15:05:50 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::13) by DS7P222CA0017.outlook.office365.com (2603:10b6:8:2e::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:50 +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.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:49 +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; Fri, 15 Jul 2022 10:05:46 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 11/14] tools: update hmm-test to support device coherent type Date: Fri, 15 Jul 2022 10:05:18 -0500 Message-ID: <20220715150521.18165-12-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: b6146424-3dc7-4ed5-52fe-08da66738125 X-MS-TrafficTypeDiagnostic: BN7PR12MB2660:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +CD5iilQbPHY7Z05cwIO2+jYU1j/rXmueLFzi9mjfRfp+PF+M9KcntgHMbl6T5a1aUnrszSQnog/pjx7syuhxp+mRr+gZnzb3FPMxuWgsgcKXZoYE1SexjlIuNdory62U2I5Nu0K2lO+VOVdqRtIcBgfnLcvO068SkOzGsnQ1RV+llsFkTbVZULDDz4kEtrfmnJ6PRworG2n3eWhfBxF3cqrkdUTWViZycp1jTgJioocvIsWsE+XBfEFM4jgN9Tv7o6RLi5/hJXJUwev79rQyLmp+Q8XQPEgirRdqLh4ISJeXQr4ZiaBfbZf9QHFoUJN79/Xxzh72bTY4RebcUXLDnWK++rfnKgEOIxA4SM00WpUsFNk+3WrRCXBE4tZ2hoUSgrHSFHBIuTxJ+pFm14HFArqReYVozb6015cRBYc8a2pQiQgU/xjW+Qae/lr3+1gxsCvEtHaGrGN42nC94tcOq2zZxcKD5KYgtJQtYGbpqiR6l27SWT5zNSzSqmtTga+aAb4Q2oNzwMpmL+bToiv/hj4TpTjcyIDIAZDTM4RUJnnl1ZNrekuYoR0WZfqf3fkBMxFr0lpZBiuwiv2Ir91TWJmJEwu9VaF18cXXReq6lTM2NjreH1N3lEIxcdch6E6a+ZN89KOJ34HFZ99ciF2jh77GAmJbVVhEz/t5U82GfHbcKXW0+MXLeaJyY4rkddYWoxJ3MLDmsQ1VJpWUwp/QrG1K3Cszol0tMnoWNMOGZLKVXYzmbSjeSlduxnyuSKDoPYCX5Ecf20/0KZsxSx8mI35vqzFz/FX2Oy5y33e5sFW/d2hJv4oLTtF9SKPY/m4vnvCsTf9YnS5rI9t/JEQLhJ3kAVMRHN1Y6ubnyZuw/s= 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)(396003)(376002)(136003)(36840700001)(40470700004)(46966006)(44832011)(7416002)(2616005)(478600001)(47076005)(426003)(336012)(356005)(2906002)(6666004)(7696005)(54906003)(6916009)(316002)(40480700001)(15650500001)(82740400003)(186003)(16526019)(40460700003)(1076003)(41300700001)(4326008)(83380400001)(8676002)(8936002)(70586007)(70206006)(82310400005)(36756003)(26005)(5660300002)(86362001)(81166007)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:49.9231 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6146424-3dc7-4ed5-52fe-08da66738125 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: BN7PR12MB2660 ARC-Authentication-Results: i=2; imf21.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=xwp0Whuy; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf21.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.59 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=1657897552; 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=zClLhDh+13bFimaGQq6du5bw3+SFpMxBpJ3E+HXrObIoui7ETM5CHgKhGTHtlTtj4FyGEL JdK65PIkmsVzD+WrNJyckI+4VENsZelmsrhC0anTbOHJMwCEKIWZyYr81c/g+f6E9ZRbyG beg6yx4q3pwzyRWhVg23zfHPNEtcxhw= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897552; a=rsa-sha256; cv=pass; b=cjn970hNQpkjGGWyVaKoahPrp2xuREv4HXyJDEfteR4jDaFWJ6Q3CTzyFKpaNzzfvpNzkO Yrgp0bvUQ8hl4es9No/JsJL/3w/vjwIEIVg3KpNvXhiPzW4zkHpDs/qxfo6RTj851dFcZj /Ez0D1Dpo/sih2K4B0FTjpiaQj5Fzr0= X-Rspam-User: X-Rspamd-Queue-Id: 473EC1C009E X-Rspamd-Server: rspam02 X-Stat-Signature: gyasxmqky8kkbo9z3xmhgg5kg9ztkqkq Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=xwp0Whuy; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf21.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.59 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1657897552-905012 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 Fri Jul 15 15:05: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: 12919371 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 41BFCC43334 for ; Fri, 15 Jul 2022 15:06:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E95429401F8; Fri, 15 Jul 2022 11:05:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E44639401F1; Fri, 15 Jul 2022 11:05:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C21BB9401F8; Fri, 15 Jul 2022 11:05:56 -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 B1C9E9401F1 for ; Fri, 15 Jul 2022 11:05:56 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8DFA51539 for ; Fri, 15 Jul 2022 15:05:56 +0000 (UTC) X-FDA: 79689659112.23.564F576 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2058.outbound.protection.outlook.com [40.107.101.58]) by imf02.hostedemail.com (Postfix) with ESMTP id DD6AF80042 for ; Fri, 15 Jul 2022 15:05:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QTudni9d/7eECfnm6r5HwLFcjVR0l06sWNmnAtJiKPv5PCvAJIBFLMBqjx0hG1GJNzBMTRtqyuCyxPFCC+9E3I1uECVsHnBEngMJ5EPFBn02XBN9HfcTxBJSmux4KnibZTDXhhG2GBsGtI/4jNSjjXSpg1Us+S2keUl0AQBpWo1eN5bFyZAVTwqZB10vCi+InL0hghQ20d08tW3S9Zo8z5woF2JA8TbPLkQnYagxTXa3R1sbWzHH3jvd0GBcGR6YTFzo1vCOPwPwqB8nRS/qvcUzF6PG+WeZXOTKZjCcVBr+wDtyJM3ClI28opzx/yPeWwvBtrOcZbI6tsTcgf7Nig== 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=NqlVcfA9WUJO3WGqLXRI7P50BflhYPP+v1RCqUVTDw2mv88hJyPhnM3/zzwU8PTQEj3hYgsXNSv3bTAjMVtMq9GiopLrZW5hgj/T5aFqIx8+ANwn9//rnbvIgjvT9zmHFWxPwOpzXesZ+D/6C5h7XuYs1Phfo9SlReoAPFyOr3Srcq9a9S5a3uk4pw9uWcKGDRYMNnT5v11DJ/CV9Ok0fdGaNqTm2551JTiigQGBpx5E/3hSRtcEDbXzTEqM84FAuh2SGgtP0PlzKpYMI9y0r9rA9095le1ge+C3WmkLTUvVz3O6E0LH8RgqtKZLI/vF/0uNpLqnxCTPjmbyvFeTpg== 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=En/2Oe20ruj0pbPmWdnh17SdS8PB1r7yMIjshvGZOjJXtRrnwaWMl7nUODvAPQl2rpUDNAY1t+mjMa6sjKGvF9UF+wKn+70wPugkd3jkfZP2waS6K49e+PuK9s/QQEVhubrln7vSkGEp5S+9ENBX94E11ytudQNmhx2IkkCijKU= Received: from DS7P222CA0027.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::35) by CH2PR12MB3989.namprd12.prod.outlook.com (2603:10b6:610:23::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.23; Fri, 15 Jul 2022 15:05:52 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::1f) by DS7P222CA0027.outlook.office365.com (2603:10b6:8:2e::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.17 via Frontend Transport; Fri, 15 Jul 2022 15:05:52 +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.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:52 +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; Fri, 15 Jul 2022 10:05:47 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 12/14] tools: update test_hmm script to support SP config Date: Fri, 15 Jul 2022 10:05:19 -0500 Message-ID: <20220715150521.18165-13-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: 29220a42-15c5-4ee2-dbb9-08da66738277 X-MS-TrafficTypeDiagnostic: CH2PR12MB3989:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /VYrSA2SS9Qkj13md4crjZzx7QSMBibevN8VWzZaIQ1PPuAZ3XfG0m7vbz1c15sS8qLlqa/jrjVOqbp41hHaLXVopPbruqi4wO0Xp5w303vfrdcKV04wn01G73iAZ/Q/XN95tFQXqLmN2ABPlcF5VAa1eVvFnYRBOCiVhJ/OHqWans1IKniUPWpYleGY7bYDoiwK5NFLe1Ygz1KrafPmTipYfzqk+il8s3R+b2mKoELnbmk51rUn29ItLt18UY/J81Bxu7l63A9tRl0OvPnkiBAUntfTOo7m102YFDsqScrUdhkSiPxImrkq2ODLDx0lTuYLwkrEDrEGl9r96ueNYjg5fjBk6DdJw0UfgbnZCZZJs+HSotbcX/eZvVXde8RP3VT9ofgdXVl1mEIGrtl4Fga7HvkFKFKDZ49arfg+vJ5vYfAPUPOTrH5gLcTpYZwnd3BZavxvRGbKze25Mor4LlEzL7+bFJ8KP7wmjvHeJWJMsePmmmXyKn7gF6/qVz/ZScosc+fj/f4K7seFhDSl8SaIccz773310NQHYyhKk2+vOsyBkGx2dRN0Udzyv06ixUkUIrnWeWlhni5uhl9kVUwsfjQNYRBEFiBWXRVT/sG4FN3Th097vziCoxSkY65O7jq1jbhm98s8EElt2A3NYyNG1ZhBGgrc6Llfkmo7nuSfNPBBDvSwKRXeGGEX9PE/VV46gjWZUHYy3WLQxVE8MTVB25xpB7d/zJDEDrViMEj/nuhDXDIWhiQjTESHnQy+S8IWYGiO+9HkFcewHHCYNFNSPs19c46FUL7QDanhRLaQXAS/gIg1+xO60BXokQE9P0eCKAUE7eE96gfD5dh7JrzDTt1t3NEatk2CYI9OJRE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(346002)(136003)(39860400002)(396003)(376002)(46966006)(36840700001)(40470700004)(478600001)(40460700003)(5660300002)(16526019)(54906003)(316002)(26005)(7696005)(2906002)(6666004)(6916009)(44832011)(82310400005)(41300700001)(36756003)(81166007)(36860700001)(7416002)(8676002)(4326008)(2616005)(83380400001)(40480700001)(70586007)(426003)(47076005)(86362001)(1076003)(186003)(336012)(8936002)(82740400003)(356005)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:52.1574 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 29220a42-15c5-4ee2-dbb9-08da66738277 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: CH2PR12MB3989 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897555; a=rsa-sha256; cv=pass; b=bIyCLFJjT7qBFNlsNNXkKMJeJ11hxhuY6vMyf+a++Rq3p3QXN9/xjUsllg4HvnYmAutqYy vvACvsMnM1pDPAzKytfOoIwOu9Gf4X5j8tjhRzMaEoGWr61r9wBQoyqghTx9ZoZXRwPijj ZtF2QhqDUNF7cm4GwCWxq57sdevf/jA= ARC-Authentication-Results: i=2; imf02.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="En/2Oe20"; spf=pass (imf02.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.58 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-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657897555; 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=Rq9uSArDT8JllVGtbbQjwTkhHQN3iVx4PLIm3LiJXevB0sj83vADOBwjvmS99J5AyXxppG WhWMNzf4rNn6dCGMcVo2E1d2i3v7gkB/eQwBM/UImSJpbfsMfZHJB43Enc3WBygmsfZOMN qwTFMetofyO3hxPiIwSdr6nd/j0MAbk= X-Rspam-User: X-Rspamd-Queue-Id: DD6AF80042 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="En/2Oe20"; spf=pass (imf02.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.58 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-Rspamd-Server: rspam04 X-Stat-Signature: dwrs6gyg3nw4j7nsacyhekfirxwch8cf X-HE-Tag: 1657897554-621021 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 Fri Jul 15 15:05: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: 12919372 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 2CF4CCCA47C for ; Fri, 15 Jul 2022 15:06:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F0169401F9; Fri, 15 Jul 2022 11:05:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 877259401F1; Fri, 15 Jul 2022 11:05:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F1119401F9; Fri, 15 Jul 2022 11:05:58 -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 597AB9401F1 for ; Fri, 15 Jul 2022 11:05:58 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 29E4361577 for ; Fri, 15 Jul 2022 15:05:58 +0000 (UTC) X-FDA: 79689659196.29.A7EC8DD Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2068.outbound.protection.outlook.com [40.107.100.68]) by imf04.hostedemail.com (Postfix) with ESMTP id A30A34004B for ; Fri, 15 Jul 2022 15:05:57 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W7QtJcwHyfmu1gRRtFFPjNgjP5Z8OhCnNZ6juvkGgSJxC8zFYOGmt3thxqn+DkURlbAqiSNIwNvVb+EQv251FKE6pBe5L6dbDrIw2mWh97lBtqL3HyWcV1rY6bI/Upup+w7biFJ0QhLA370xixVQnw0Dpo4o+0eJ0OyLa5EP8pZAN4ysO0Lp56npXpXyRN1VIbhhcBPhDyDMpl3UBgqz5E4lrzE3020c1A96uDZUfKmMeDWlluJ5OjmZZ4lxHRGEcW+gzGrVJk5a6EUPlp4WzqlsnEPIEepsu2MLwBLrx0i58ayjlGb8xvRuFuWnBDgyP3QqgZZPX27P5oboz9ezTA== 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=eFVRQ3FqlBnVxBUhzFMrWao6vZkAqBNtY0LO+/eYE2j47AC+NVOe7qaFj0jzJBFjs8kftBOjSC0m/DDlPdJPJLYd/L4319x02QldaAWf/zil7xcy7HJwDm4fbP8AfmnSwy/plWqWblJQ5yBzYjSOPNkmE0yXfphhtbTj4MR9oBKLA7E6pFy9c2MAcUCflupy2cgmRgEK7xczG7FyZhqb8mp3Aebzjcl2/OGbc53atqpLt2F9RrHa+71tklvyGE2dSZlx2Ecy5U9sq8hHV60aOSaGkzvi6eHBow2Ch9ctOY2u4oUmBCUcDej2x4WLZfKBQBm4kJUDPoX7rmOT0jVw0A== 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=gl9t2K1Y/rtyNNjxh5mvYTs82rggHqmyNxhAW4OwsZ14Egn9DM8HSUfA3nzocaL58IdM7zXQ+34GyVIE5BF4nD9m2eI5z23euv+LRLOJTaITJpKuICpMrjY1pOrXFZt/b8Nkp2qMuFkduELbXxg3eJdzDBVRQ26vTeh4+vaUjJU= Received: from DM6PR17CA0021.namprd17.prod.outlook.com (2603:10b6:5:1b3::34) by DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.21; Fri, 15 Jul 2022 15:05:52 +0000 Received: from DM6NAM11FT067.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1b3:cafe::c5) by DM6PR17CA0021.outlook.office365.com (2603:10b6:5:1b3::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.26 via Frontend Transport; Fri, 15 Jul 2022 15:05:52 +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 DM6NAM11FT067.mail.protection.outlook.com (10.13.172.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:52 +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; Fri, 15 Jul 2022 10:05:48 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 13/14] tools: add hmm gup tests for device coherent type Date: Fri, 15 Jul 2022 10:05:20 -0500 Message-ID: <20220715150521.18165-14-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: 395ea720-d326-47e7-07ac-08da667382d1 X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rBdeFIjFRmVmSjrW6UaitFF0tc1tq0YlIC0wocoAHKevLRVgxx1WXTWwIkA2cvYAVvc83/kd+Tce/ZQcjDCSI5QID+QkdCII++ZNGlP3zOpzOd4Ok+pgZDSI6g8Mq9cvqA2AD7QSqQG9LWc36e1U8sasOc3pkh+Ie7Hc/dRFnHxS6OMkBHziQNU2CDjMfEDWkvkXkrJpKAaTIoJ2Fzu0xeBddgTxgTcsvzXw43b/ScgOWOiQv08RhYejxIJE5c3dk0q0uZnmdrSkY6sSiBxwondDhufi7hMM60c6lxHO4fE5/FWyJu8RhaYfumiFQ5vpm2IrGX6yo35wasyzS+j842Pn3yTNFh78/UgRIrRarSnCN9YyYoJ3Xn9JgqNCHgpidDAVKueMDyJu8PACkqKoq0ifuKMSh7hv93ndLE8Fdlc4Ng1Pf8sMi1VlS3XSPaZRHg3FE2A/IdO2QFgsNnIrrZ1z+cC48OB3dL6fwxZCaT1sH7/GasOcivV63HyDQxvi9cUynHkcpyqx4GLUUiJSPk+vNCGPXN1hybOQoJxlRqjIPyXSw5QymnEyeRiyBliYw4jZuDEjtvOIYGoZg/wHg5flebSw3SinDQfA4fqNTp1Xw3RC7SVovbHpfrs9REBmQJIOoHNQDioi0vydqq73tI/kFuTBktLiK6jhCozNi58dNAQMyrCOgYh/b3/InbmbhH+mdbAzfHZXkekjnfOvtz1Zt83bAUmIdb3TMkYcNaIPZmwTQ//Y/CCqUTHZzvKCLwAIF2CSKhhtIZzORLT7wjJ6XhWbEwVX2u4uKZ9MJZLUjN9TsvIDu3ze30mmsK8nwtSUDtqwVo5cPMNBVgveTWM2AgTVBdXPWWOuwIJD5lw= 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)(136003)(346002)(39860400002)(376002)(46966006)(36840700001)(40470700004)(4326008)(44832011)(54906003)(6916009)(70586007)(26005)(41300700001)(316002)(2906002)(478600001)(70206006)(6666004)(8676002)(47076005)(16526019)(36756003)(426003)(186003)(86362001)(336012)(40460700003)(7696005)(1076003)(82740400003)(40480700001)(83380400001)(81166007)(5660300002)(8936002)(36860700001)(82310400005)(7416002)(2616005)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:52.7418 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 395ea720-d326-47e7-07ac-08da667382d1 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: DM6NAM11FT067.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3849 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657897557; 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=E06kMIAB2Ar0Eku7GZBOAAznSPtumqPdijl+pIU59rN97k212XH+XsT8IckIhI5KkvmSz7 wctxWgStby4RPM38MFuJ1t+pUVraWlPd3bch1HqwW5d4XZFdUCzuWKhtxosE8aBfLhor0i d8Tw/M+OcAhIFJrsTSNQ7kHvY+YJozQ= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897557; a=rsa-sha256; cv=pass; b=ZVzTgQF0VYf/bYGk6Cv98j16xrAokhIUUhcP2Q026dRi+3JSSSgl+wCOCQDMcmKgih3hyf sby4HCfee0RzxYvAlFmkc9p1uCtqgtdCuwTBytQ9FKxGI0uLgAxCb+UUEvhURK4Zw5dBZ4 uvLJqXFxKH3xKC+J9miCakgJvaf0s6w= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=gl9t2K1Y; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf04.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.100.68 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=gl9t2K1Y; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf04.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.100.68 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Queue-Id: A30A34004B X-Stat-Signature: 9uwpbu3skh19s8kodpitp69dgu1tsnja X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1657897557-158507 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 Fri Jul 15 15:05: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: 12919370 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 60C62C433EF for ; Fri, 15 Jul 2022 15:06:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C73539401F7; Fri, 15 Jul 2022 11:05:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BFAB59401F1; Fri, 15 Jul 2022 11:05:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4BAA9401F7; Fri, 15 Jul 2022 11:05:55 -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 915F39401F1 for ; Fri, 15 Jul 2022 11:05:55 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7210061542 for ; Fri, 15 Jul 2022 15:05:55 +0000 (UTC) X-FDA: 79689659070.07.A4820E1 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by imf14.hostedemail.com (Postfix) with ESMTP id 0650B1000BE for ; Fri, 15 Jul 2022 15:05:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CcmG4GNmbrB2tfag4fHOEduFQO34ba7GDMbT4EHr5kS0+GjSEV5T/hWV/b2BFSTwk+MhXIwyqDYfXO3g/JUoHygVEZU5wL9CwjfpmX9nZbV4/L3A320Frl/S8d/D2jYiiuuP514jR3dye1k4smeJPu2CzqClgSWhdfuw96i9eel+sYkME7u9SccnOigF1hGqcWGj3SmVLOejNL9t9bYB9HCVOyeG7AsoZTS5wDE2rc1r+XvG2MFACl3wR+kiwYqVLNzGvN8iLw0dWu+Rce12PeGdozVMink8SlWqhw3mHxuXhNgX7ySyhuTd+xMz8pTwvgNVNQuqxZSB0G0eKhntow== 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=LVq2X6qCcI7LLAEroBx3pZbOaV8vi0h35tneNYEGs7L6nhDQ/VISrytyDTuVvW68fw3pN/H3ntJkxV7AT8exCVqEsoIjGKQFkOS+DdS0KjxtlDn7DhBLpjMKy+JLDSx7shqdi6fVXcKtf4I1KVUcMc7lPzMjhhOWCrXkkcbmQBN7pPZdn3h78JDXgq8uAsoVRD1/WU+ZinUVD+OIJV4hcuN4fD4lDft7IuG1a09pX4lNHQ/3CBOJoYgtaJqfLLU4RvAyu1d3cEoeGAIBWEreng7zT7xTF49L20Z7W2oVhJeiUC4MvJrNPXdwCw8n2tDhPFA8xQOt+QJn0SRgbalg4w== 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=c++1AQwSq+Ph+FBOcYUKzUqAREwGjmebjvjilZTYsf4Axq8ZzoVpU80NiIG6Dsg6ba+/f7IBJuXvFj94MJkTE8wR7RwpQoawTtOFxgDQbXSSXS1EeYbE+AXjhFjRn9++aDYwBnO/pXyLv8YdQHTlX2oiuVzElm3ZHOwojbDpfDQ= Received: from DS7P222CA0015.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::27) by SA1PR12MB6972.namprd12.prod.outlook.com (2603:10b6:806:24f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.14; Fri, 15 Jul 2022 15:05:52 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::2c) by DS7P222CA0015.outlook.office365.com (2603:10b6:8:2e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.17 via Frontend Transport; Fri, 15 Jul 2022 15:05:52 +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.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:52 +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; Fri, 15 Jul 2022 10:05:50 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 14/14] tools: add selftests to hmm for COW in device memory Date: Fri, 15 Jul 2022 10:05:21 -0500 Message-ID: <20220715150521.18165-15-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-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: 35a4cc4e-ab65-4cc9-3a3c-08da667382b8 X-MS-TrafficTypeDiagnostic: SA1PR12MB6972:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /bY27H8ENSJl9dTI5r557agMFt9ob9FbjXMrmBV92gmMpMV9txC1Cum05rYW3SeTQ7c7BM5o3oMJUyjRNCX5uTcMEW+5rmxBmbOc4z9fcm9p0Sfny6mqpWt7/g5GmSJNRtcMk8iKnvkcwp3hg5xiIH6a3lfdHP29giztQ1YjL1TjTLOwZU3zpkEdghe2Qo1PDniG2u+xo06wBPfvCo+pWxYFQkJk86ntrrd0Acc3iG6cChpLP2e/RY8nEoZJaS75K58yHxoODCcmp9rLEmekzdRFJtOpVOlwatJ0afJ/8FgBBtcpicfhkSgg14w7P/Kb20XvTXqq3IVFgrLakKcZGcZcA/SSpFMueTp45vBu8DbfPSX319fDgMEIMHOlaWe3jhNwzblMHDe3ipbEoAtJJ/3AtC9ix2gtpYrmGWtMgHvlSC/UQRTNK3x/OJD/yaoEh40ADz273fcByS2aWQn5nsHY2kcUJJhxmPTPKTKwv6hxRHqMVU+8UcOhBiF8fpQNQMCjEMg5sPkgL0d4TMkjw/ParA1Lg8iGYpcKG4FNLKvfd+BZjePIvO5D+u7nx031A8W/EidMallOwdrt5owM4LhcN3HjG9PVRMOIPGz1wRwHqaZNPyCaaCV1erQ+JaGBdRWBldZjS+qL+SmKMvjSm/I+n48HOMfvo3v4bX9uGZ4mqA/Mn4PRkYYz8wDLGsbPxNSX/3gnmGc2bkvVDIGlaB0KIjEkqM4JZt9qVZwqLBCAc/KHZACItxXzlfLK/yhJmKgHJHXZSFFYNeJhwPOcNPa2UGfnJv0DZpAWVIo3Jp7VWCNrbH/cVcJjnughdi77vPZbGKY+AM3qzTHh6mvcL0gThhrmFf1RTn73B2pVAhA= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(396003)(39860400002)(136003)(346002)(376002)(36840700001)(46966006)(40470700004)(82740400003)(2906002)(36860700001)(47076005)(7696005)(82310400005)(6916009)(83380400001)(2616005)(54906003)(36756003)(336012)(6666004)(356005)(426003)(41300700001)(26005)(478600001)(8936002)(1076003)(5660300002)(7416002)(16526019)(44832011)(316002)(186003)(4326008)(81166007)(70206006)(40460700003)(70586007)(40480700001)(8676002)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:52.5792 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 35a4cc4e-ab65-4cc9-3a3c-08da667382b8 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: SA1PR12MB6972 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657897555; a=rsa-sha256; cv=pass; b=DSa374V+ahpJ8fht/uyN+ngm+SESDbAambfm2zTZRx5RIhhZ4T7RGIJi+GMfPDm8UztVZn 04n5yq161B690nTZdpMU92KZ/wYgqX+ghFcUAAHLvcqhnYoKW7qeIjgOzKFNb96pR5JOfm CIpchmOc4FFjlkm0h5bGHiiXRfsVGjg= ARC-Authentication-Results: i=2; imf14.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=c++1AQwS; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf14.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.41 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=1657897555; 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=bH0HrQ9ziJpIbVJXMa0THaaC5yBxVFnAPKcQkQk2jft4vXusWDUeZ5WPOarNiF/VzgpWwy iBBUncQHAZSo6R+/rPYc8wPSmosiMd7/accAO3uxDC9c/Ax5yQJaXcQEqWOCoqhjkn2zKd qytD857x34batSOFISlubqbp6I1oBOw= X-Stat-Signature: bs7oxy46d8ixzseosmgtm6jhfcwexm75 X-Rspamd-Queue-Id: 0650B1000BE Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=c++1AQwS; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf14.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.41 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1657897554-106676 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