From patchwork Mon Sep 13 16:15:53 2021 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: 12489901 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBFB8C43219 for ; Mon, 13 Sep 2021 16:16:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 86BA160F58 for ; Mon, 13 Sep 2021 16:16:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 86BA160F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 75D856B0071; Mon, 13 Sep 2021 12:16:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70AB3900002; Mon, 13 Sep 2021 12:16:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D2D06B0073; Mon, 13 Sep 2021 12:16:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 5054F6B0071 for ; Mon, 13 Sep 2021 12:16:19 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 04177181AEF32 for ; Mon, 13 Sep 2021 16:16:19 +0000 (UTC) X-FDA: 78583052478.19.B18A7E3 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2060.outbound.protection.outlook.com [40.107.223.60]) by imf02.hostedemail.com (Postfix) with ESMTP id 91BB77001A24 for ; Mon, 13 Sep 2021 16:16:18 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nFHe7zu4BhD/jKo6qkecbh3vufwvPPv1Yw0Gc90qQQnO/HIJwk+CElO3H9Q/Lhdx0S5P4cpkrVCdBty/SUPKAcfCuN6+7Hj5sMfK0xtDpVOYXdAZjFMcadx/0elh+Gd3qPsWUXS5j1itbDTeSQITmsS05ZzqUj4M1XvRGfIjRCCILhf/bg0Tr1fVa/KmRTmfXnuSi/FmZTEb5y8p4x6uG+GU9UrdkTXUwE289oILO/QYN85uPzO/YOvzDT3PNhS/PGVkWX1BNp6YG3iG0x1z2R+LziOVwJdw5hHeiLeZTx37Lf9krqnpb1xF02CKgGQblOa7AgxW8Fx0jqEQWwMMug== 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; bh=prqqgRWlNmUY+FCzPMwMlLKkTVbC2ZOWpWdIq8n/6hw=; b=LdQCcTq3oDTFTCvSTCtAObvQ6LTJgK31U+DPEUD8RTS06aneh61EJsPYGpR/1WAx/AXvbA4U2PFnWz/+CQ++LOXBFdg4oY76aYvlCbxt8v9ilmjAfmrS0tKlP9wngz61pny1IWKuufVOmVQLZzt1Kbrn1qa2u3ObN73MbTbpE7USiUwdBJ0LVBeU9WKQosulTZw3mHigbF/XN3APOZa0j3V8EI/eUjkajdX67N5/ajlaon7xQOJFYTL739Zn6zZDtecaOKdbgIjwBCFLxhnyKgnJT+2MJT6+5f3m+AUMvWR4i1vv/y2u3bBkjGTY26Aa7PtaeffOrRzxrXyTmtzsgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=prqqgRWlNmUY+FCzPMwMlLKkTVbC2ZOWpWdIq8n/6hw=; b=L0/JjL2qdYNF8let9rNeEhvsCBy92JwiUd9lAWJVllBuooO74VT3GsLTk2zDtT4mcAAJo7GJBIWAZyP2f+hGeI3yeoQQPzb6771FU2VMf7j+QMEXyJEX7D07qKG5McQIGjAXGFgCZLO7EzsyNTemdEhIFaKNpD4ce/IgnoRqcGQ= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.18; Mon, 13 Sep 2021 16:16:17 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:17 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 01/12] ext4/xfs: add page refcount helper Date: Mon, 13 Sep 2021 11:15:53 -0500 Message-Id: <20210913161604.31981-2-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 69264dcb-8374-4f31-4981-08d976d1d082 X-MS-TrafficTypeDiagnostic: SN6PR12MB2767: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jIxnHDwg2MuCUWzYHPHdrApjYVVLGDwgqMB1IfvXS9XDhXOgeOmOyV9Xhf5cZx5iFV8P7Zo6gScfeXPahYjVwNRLI1pNq1uK5UEsp6gvNh8ZgjwLOTBVoPyw3kf+K1hVHWfOje5fYmTeFmCaVuTxOCkGUGwj3FBi0KLOyikvJDcBYV6kIw29cMmeqOjD28MtyL8I7L6FgAEWvgqVQWjCEGKTkPkgrgbaBO813OSzZkVhHVClzrvU1EIyMqAqIqRBBVlCQJI3jMSOGnVJTNfkVFn35RpLACvGYnhkm5IieCYaw9PVz5tH0n7/P+5GB8UJNkrU0giRS18UEDNek/j69GsqTz3C4F6FkpH6HP53/ZFC8tD5XucaDcOXkNA3XvE1YXIQt67zylNVi8EABQyz/hpq+PuxmoBLrF4Qw9hIggo2ObPilJrpld6b8Ve87YUMYp90aPCN14N9sOqF68Yow9+98soeJFt5sZL7FtaUojvxKcSwjqbt3c01al3/LF865npLSDXCajhpMLqvU1pAHVGsLDUcnbE9708RtU5IXZTX6fZmcgErPOzuXgK1iWDBTlVwa5Azu2Gu6IFJI1CyFQzNUSS+Ik6BZEFT7R/j4xovLiF6+RiilI/mj850nblbr+L5WR9QpPjBxkEQ88j9v4LlPpXRbLJScZrejdHVgkxIq85T18fd8rDUCm5MbNi1piOKOhJl6sG/EEj8eRVGZQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(376002)(39860400002)(366004)(136003)(396003)(1076003)(7416002)(86362001)(66946007)(44832011)(478600001)(2616005)(6666004)(6486002)(52116002)(7696005)(956004)(5660300002)(316002)(83380400001)(4326008)(38350700002)(38100700002)(8676002)(66556008)(66476007)(2906002)(186003)(26005)(36756003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fTi+aXQfAkcNxYktuyQ2DrVcCyy2f0vXFUXYE4jlJ2VfAkodrq3cCkUN8B6QJxsa32p8xbivmwbDPTlvuCyN8SZmptcJt3K+VzPUNPW7brjVs3yT43lopiY0dUNiSggY77bmtmfTRF0tC9IYFXrrPWrUqvOP8/PVgplEmFdTOcqX1TW8Y6JxDkHvxLmAhG/INzT391i0/xvDb3Be9mXXHLSuM3Uofn1I47T1VBgA7UL55ktZZbDgT0txpsZTly7Jr3Mg15AbhvtpDP+u4Q882TbC0bKDdOa0K8uDBj5j37SwxfVU2AGb9SXlzhTsRdfRmH8Wp5+mXGwEYVw1iyyejxk+idkn44cRw7kW0WqPDaeFiiTmEg2TeY5oRDO3I+AIr5/Ej/LanAZ8jCSoCyEaXDI6XAyMWXXdwAeaOBaM6L1VRdzt9xV/dyxNdBfiPNBms3p6Uqne6SRE39HTqIxEWFBSEko33/4dOjQJsRT/gLsQFHHWuGvfthhzh7jBJ0pztrRVPsOSFEscCkSug/jVl3iutB0KeBssKC1LGbC+VFGfcw+IsEbdxyOSnecwihlTqk5LfsydanyRnxsYNXjSoSr5ViUkt8ky3n3pDqy4kkh0smxAZxW7rs9RFhAkpoRinWTkQyLtpOMPLc5ftqcL0HrLJTjEKQUXbPPy3ddVPn574Z2owJen2zSTZn8blcSTyDuugiZOggH+BvuNzr4L21pvGN7rmFS8d0B7SCWxUfQ7to8gGL735uanOvCxZTS7IyRnHIxgV04kHtx9+hTx5sd9Eo71zASUDSbdzUv6fSvQZWnS2sj7HLgBH8yFZNquyO6JMbkYA452oQFvcu1bQGBctbmz1i7gASNCvOSyYZYU79OHhy2afvTJA0dBAOOh2+4wdN/igVARmgu72b3np/03NdiNj0Q9lNpHoV47GOSqtY85Bcali+xpkAUPrW1uDINVjZkNlTxOyWLI6+1sR+SJlWxww1iRaYkkad9ZH0KawIXgGxCVycKj4BY26UIukx6xVGVqzYOMpPf7G7UqaLLm/v7csde+Bi/r/QE7X6zlgM8q5pneU3BGjlxrYlxnJffVVMKnhNDRq8R+/YuYmR83oQc6c9AvvKFrCMznwYaYxkn+FKjO1oeLn3n80zoDrnZn5sdIOEdTR9HAA4LCjQv7JSGJK3aHdO3X9rrxuXM3u0GBjJJdNcdyJdHnArzHOjGz0kWXP2YtdqnbNAejlcnccrkriDUKcJ2dSntlBkB1Di/o0ibENDUf4jklWoz0z4fxpNdQQPTCp96tHA/uKa5vwZV9838o1raYm2PfotADeOs+ioIV5eywOa7meGAf X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69264dcb-8374-4f31-4981-08d976d1d082 X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:17.0148 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IljKvBIXiJKxTsL1jTdiC/8mHQbn+ye/zHTMbD6+BdY4Qez1d1WzHgV5uB2zFlTzhB+/cH/eTP1DtLT+j6/AEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2767 X-Stat-Signature: kyu59af8i3oodwu63gk3o5xxy9xtbrq3 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="L0/JjL2q"; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf02.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.60 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 91BB77001A24 X-HE-Tag: 1631549778-300724 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: Ralph Campbell There are several places where ZONE_DEVICE struct pages assume a reference count == 1 means the page is idle and free. Instead of open coding this, add a helper function to hide this detail. Signed-off-by: Ralph Campbell Signed-off-by: Alex Sierra Reviewed-by: Christoph Hellwig Acked-by: Theodore Ts'o Acked-by: Darrick J. Wong --- v3: [AS]: rename dax_layout_is_idle_page func to dax_page_unused v4: [AS]: This ref count functionality was missing on fuse/dax.c. --- fs/dax.c | 4 ++-- fs/ext4/inode.c | 5 +---- fs/fuse/dax.c | 4 +--- fs/xfs/xfs_file.c | 4 +--- include/linux/dax.h | 10 ++++++++++ 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 62352cbcf0f4..c387d09e3e5a 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -369,7 +369,7 @@ static void dax_disassociate_entry(void *entry, struct address_space *mapping, for_each_mapped_pfn(entry, pfn) { struct page *page = pfn_to_page(pfn); - WARN_ON_ONCE(trunc && page_ref_count(page) > 1); + WARN_ON_ONCE(trunc && !dax_page_unused(page)); WARN_ON_ONCE(page->mapping && page->mapping != mapping); page->mapping = NULL; page->index = 0; @@ -383,7 +383,7 @@ static struct page *dax_busy_page(void *entry) for_each_mapped_pfn(entry, pfn) { struct page *page = pfn_to_page(pfn); - if (page_ref_count(page) > 1) + if (!dax_page_unused(page)) return page; } return NULL; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index fe6045a46599..05ffe6875cb1 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3971,10 +3971,7 @@ int ext4_break_layouts(struct inode *inode) if (!page) return 0; - error = ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, - TASK_INTERRUPTIBLE, 0, 0, - ext4_wait_dax_page(ei)); + error = dax_wait_page(ei, page, ext4_wait_dax_page); } while (error == 0); return error; diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c index ff99ab2a3c43..2b1f190ba78a 100644 --- a/fs/fuse/dax.c +++ b/fs/fuse/dax.c @@ -677,9 +677,7 @@ static int __fuse_dax_break_layouts(struct inode *inode, bool *retry, return 0; *retry = true; - return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, - 0, 0, fuse_wait_dax_page(inode)); + return dax_wait_page(inode, page, fuse_wait_dax_page); } /* dmap_end == 0 leads to unmapping of whole file */ diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 396ef36dcd0a..182057281086 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -840,9 +840,7 @@ xfs_break_dax_layouts( return 0; *retry = true; - return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, - 0, 0, xfs_wait_dax_page(inode)); + return dax_wait_page(inode, page, xfs_wait_dax_page); } int diff --git a/include/linux/dax.h b/include/linux/dax.h index b52f084aa643..8b5da1d60dbc 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -243,6 +243,16 @@ static inline bool dax_mapping(struct address_space *mapping) return mapping->host && IS_DAX(mapping->host); } +static inline bool dax_page_unused(struct page *page) +{ + return page_ref_count(page) == 1; +} + +#define dax_wait_page(_inode, _page, _wait_cb) \ + ___wait_var_event(&(_page)->_refcount, \ + dax_page_unused(_page), \ + TASK_INTERRUPTIBLE, 0, 0, _wait_cb(_inode)) + #ifdef CONFIG_DEV_DAX_HMEM_DEVICES void hmem_register_device(int target_nid, struct resource *r); #else From patchwork Mon Sep 13 16:15:54 2021 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: 12489903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35350C433EF for ; Mon, 13 Sep 2021 16:16:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C88C560F9B for ; Mon, 13 Sep 2021 16:16:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C88C560F9B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 00FEF6B0072; Mon, 13 Sep 2021 12:16:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EAD606B0073; Mon, 13 Sep 2021 12:16:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D73E66B0074; Mon, 13 Sep 2021 12:16:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0114.hostedemail.com [216.40.44.114]) by kanga.kvack.org (Postfix) with ESMTP id C89356B0072 for ; Mon, 13 Sep 2021 12:16:20 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6E9EE1808BB20 for ; Mon, 13 Sep 2021 16:16:20 +0000 (UTC) X-FDA: 78583052520.38.BE0BF17 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2088.outbound.protection.outlook.com [40.107.223.88]) by imf18.hostedemail.com (Postfix) with ESMTP id EDE744002098 for ; Mon, 13 Sep 2021 16:16:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FXnneMBYXZrFNucPey/A2AnMkw4LbPdNxfNQzfx4TQc1H2RGLYCiRTg1EvzBhcCmCQ823yfARZi7am+DwQbAyNHtPpfNdSxBddP5gKNCKJSfFczi2qdyjh2w50EJQJCRGJ6/8x6vjiScwlEzVXWYBisf/Ii4JZy7ORPfl3DD0tkqZK45cbnEzpX3FwobVkQpUbA1Aq8Xg5f3KtmF20FTMoWe9t0D7kQ1r0uVlAsn/i5TVdVLfE2rSP3YitTeLrSZJSL7c2AO9fi4qv0lDQ2cxTkNK/vfhMzNFAvIXFpzMNLg00Ci0aUtv6e3bQETmeEE6uIGfedPu9yUsmVHJJg6dQ== 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; bh=Z/dmt0Ms+aUMALBFM4yLtNUqpaeot3GwnAz3IGbDbXo=; b=Q5G/UONZqB66fWXAQa1FHhKa4JpwMv1rv16/65bOfHpZ8yH4GIuXe735xz4Nir90gOr+ZEraVB/WSr+EUZMd2X1JnrHR/ZyTNkGj3dBy/f14O7lcj9taMN4y4EHq6Fv/tIjVrNDw1nAwmem7y5jPoU5nrAFbsvv0GR4aOGc00IevdhH9GLu3I4+YfOUnG02ujkygv079gFX8e/u+DIJo0RXP6i8ZPzYeuoAyCfP3UxwusAnaiPL0L+lPPjvwzRg6YG8uigRWLUbni8/hDuY/Fi8kmHALxQ4S+RrakB/56Woo0om+JI3w0rmq3bGOTwDI3IgWWZro9e8By8oCdcxJFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=Z/dmt0Ms+aUMALBFM4yLtNUqpaeot3GwnAz3IGbDbXo=; b=PHb4yuMOxlYjW+qEH1d4vfZf1iMEW1AyER592Q2UdDXxZdSgabdY19CjeavBt3/jFMeFzBBu4HzHshtZam58KfZQHreJvjtvYZTAb3sBnw0EXPYcFamBmuQiatCmswqbuiAzYpHv9UC0m48PQQ5OmL6ES/K/QKRpeZTQqDQJKJk= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.18; Mon, 13 Sep 2021 16:16:18 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:18 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 02/12] mm: remove extra ZONE_DEVICE struct page refcount Date: Mon, 13 Sep 2021 11:15:54 -0500 Message-Id: <20210913161604.31981-3-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: aa013362-2dcb-4a04-14a6-08d976d1d118 X-MS-TrafficTypeDiagnostic: SN6PR12MB2767: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GNzul2IQfQi1tX87VkmABX3Opb0gHNlYpFs7vymF77iL3FdE8UyIPRYj3pl3GXnU/NBpZ2L2cssbHmYh6a6g+81Cy8RGTQtbzhPU+Wc2OjEmoCkVkOfpeX+hHJArYTd7xWcu/kuOwOL+HgFKiX4RERWsckjFvaObUrgZ6WkSTwfuaLd2hv7hRPju94/5Bm7DLoaZ/AZLwr2I1wGKmwzICio1uZYdcEJO11FFgp2felDNiHXkRKixcpyY8GYyqszJPR0YMAwIRrcY39KCceLOOVPvoKxYsNJ1dH0Q/CaGj4GsfIzcyGh1EHAuoz239Opy0+y2M3sRwXYBcJPcuBfptHlEDsok0qQZWEukIWeuJVJhr6pEM0YG8QSiR4qGI4siBMYnnl8f+xJ8W0NnzZ3rlN8sR0W18BN+6JZ/IOX8vHdej2nS0gVNLRjCXNFPRwhqegWaB5SEVCA1vAVlIB0p0t6S4zqz9cvR+I/hsOad9GP2vgWcC3LrvDhGrqzVh+GTvd6vj9vqqtkInuXqV5wr/vtD/XDAxkAjUG0d9qMmwqgtOEVGTQkeIUoaNXy7wc+wyP6BWwxE9sei+S5ZasgmMGpTlEIIOqH8diYWVQUcHkd819nyq4oM6VmcXWrlt1d9YACFfUInyG9HUqkZX2U3+fTIbUPnO6ER3RlZ7X+6rYmlRqj+u+zTk/FshwrwjgfY2dgFNoryauXUNKVEHaFHmvqg+izhgH5Cp0EidyDZvOxC0b6gbAkEcuOzL9eMTuw4COM/TFNsN7QQJc6LwFD8nuTvFd9mrlV0P5mgCjCKto/I2/iPd0Sq0ZTbWkBMM/Iig2Nfijm0biBWew2MJ0rkjQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(376002)(39860400002)(366004)(136003)(396003)(1076003)(7416002)(966005)(86362001)(66946007)(44832011)(478600001)(2616005)(6666004)(6486002)(52116002)(7696005)(956004)(5660300002)(316002)(83380400001)(4326008)(38350700002)(38100700002)(30864003)(8676002)(66556008)(66476007)(2906002)(186003)(26005)(36756003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: moFLADnQv7EvAR5UPeEatfQszSM9abTfvHpvAuRy5fW34t2yNdpr/NG4sSmz0JTYWLGUGpux12045a3iIVa/SX+p6MeCqSu/K/ZJ98/i/HywUGQLjwskOgCJMmN64QOccWeTVQg7WmMrteexJS/zdBbv0x780FMErLxoRi4GzEEBjlPzFUlo3Bm6eOEiboMN1iEmPgry1luaQVCm7gF8o1Fx4gsVHtLpsZISJZwzPo457p9I7rhcNGm6sHyHWa2KA5nBUZ3b9zlNs2B1pJl1zRjtIcekjD9QUSS9y7afoemcsHrNo+9HNjKqCqNq5d1H1gXaG2yMXUDAX9Y+xuRSscjJoHek6XKIZS1w0AQC4HB82YJr5NQTCykc7aNbjVN2MGq1+oQI2eUnK9gE5oJVImV7NMRQKo1PNjDtGCS+lLzTMlEZm1aNNiOg2J37iJxxzlV8X/7oGoJf8aWum8/bsD2Kr96bxi+1MPC4T2hGQ3aVrM8NOuIw7SvIJboR+diDkVx4w7zHteBqQTRPKkfISz0Lhxa7JuFhGnSoceI8P2/OoduPQz1LU/31qjHjo6n/MhXo3hh4h2FGqJUaCRyRVF3J5OIPm3uA4GkffaJp1eB3rAW6RSecx6TybGNlHkqabod0rNnTmLZ1dksItWWs35vfoaTyjun4z3/SfuVap42r1FheT79gtvIqXCuSScd2i/D0jJfEGkp/yZ36/zQe+zRK0AFxF/lGL8EiWO97pwk1qQkfHev2vErKAh30sVp5VLMCKgE57aeCU1PzEwdVI+Y9QlUbpfwit9LBNzT7pkOv408plOd+X9fO2cOLj729C3TU9uLslUfkJxAOzgq81ndEfcX8LYH/zBYUSExhf0D1h0sDzmWf0kWuA8/12CF6aoKb/NFvJUL/faMrDI++tPrW3fhPS58rl/pjKcteSM9qHzwGU+0TRrINTxJfGg59dqqnCxHorToYkQJhdhJJnmUENsqMHkMSQ968nPSzliuOAV8wlgKy4XfbiXxYyDPmd+xy8FEQuNuPQB3C3mcN1CtpefjKDwdZYFqsEL7BMDRvIsr9EiuWRIQd1Rur5ILz01U61K9HTpbzZQkINSCntxtgf7CbeXNQz5JhneTSJ5tDDWNiETH0gIUIZvxoGn0Pt9w0SUvgOrmpnbITuJR/YMMmkOSWYGErJhQmg6971+pBn/GHYo/IEhJRWzY8r8+mpIZctd8L9cUPH9XDm6i64p3TpPbaTo6Ghc/yPlpVKe9mmR84qiOIkjlU6lhZ/ShTdRgtj1RyfeSRQptKqSTaaI0vqDz0navQm7tFR6NBx9sncoY2hioWWe9Q09zUjscn X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: aa013362-2dcb-4a04-14a6-08d976d1d118 X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:17.9457 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QSVbJH7U23UA1Iyey6EcxozDENrIDtQ2eHFjHEEV+VBooSX1TdKl2ykoDkk3vnHF2/pH/AXCR6PSNxSgNXqOdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2767 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=PHb4yuMO; spf=pass (imf18.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.88 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: EDE744002098 X-Stat-Signature: 4p9hw8jzkkf9wz5yb6kcjsyn37xu5cfu X-HE-Tag: 1631549779-165310 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: Ralph Campbell ZONE_DEVICE struct pages have an extra reference count that complicates the code for put_page() and several places in the kernel that need to check the reference count to see that a page is not being used (gup, compaction, migration, etc.). Clean up the code so the reference count doesn't need to be treated specially for ZONE_DEVICE. Signed-off-by: Ralph Campbell Signed-off-by: Alex Sierra Reviewed-by: Christoph Hellwig --- v2: AS: merged this patch in linux 5.11 version v5: AS: add condition at try_grab_page to check for the zone device type, while page ref counter is checked less/equal to zero. In case of device zone, pages ref counter are initialized to zero. v7: AS: fix condition at try_grab_page added at v5, is invalid. It supposed to fix xfstests/generic/413 test, however, there's a known issue on this test where DAX mapped area DIO to non-DAX expect to fail. https://patchwork.kernel.org/project/fstests/patch/1489463960-3579-1-git-send-email-xzhou@redhat.com This condition was removed after rebase over patch series https://lore.kernel.org/r/20210813044133.1536842-4-jhubbard@nvidia.com --- arch/powerpc/kvm/book3s_hv_uvmem.c | 2 +- drivers/gpu/drm/nouveau/nouveau_dmem.c | 2 +- fs/dax.c | 4 +- include/linux/dax.h | 2 +- include/linux/memremap.h | 7 +-- include/linux/mm.h | 11 ---- lib/test_hmm.c | 2 +- mm/internal.h | 8 +++ mm/memremap.c | 69 +++++++------------------- mm/migrate.c | 5 -- mm/page_alloc.c | 3 ++ mm/swap.c | 45 ++--------------- 12 files changed, 45 insertions(+), 115 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c b/arch/powerpc/kvm/book3s_hv_uvmem.c index 84e5a2dc8be5..acee67710620 100644 --- a/arch/powerpc/kvm/book3s_hv_uvmem.c +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c @@ -711,7 +711,7 @@ static struct page *kvmppc_uvmem_get_page(unsigned long gpa, struct kvm *kvm) dpage = pfn_to_page(uvmem_pfn); dpage->zone_device_data = pvt; - get_page(dpage); + init_page_count(dpage); lock_page(dpage); return dpage; out_clear: diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouveau/nouveau_dmem.c index 92987daa5e17..8bc7120e1216 100644 --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c @@ -324,7 +324,7 @@ nouveau_dmem_page_alloc_locked(struct nouveau_drm *drm) return NULL; } - get_page(page); + init_page_count(page); lock_page(page); return page; } diff --git a/fs/dax.c b/fs/dax.c index c387d09e3e5a..1166630b7190 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -571,14 +571,14 @@ static void *grab_mapping_entry(struct xa_state *xas, /** * dax_layout_busy_page_range - find first pinned page in @mapping - * @mapping: address space to scan for a page with ref count > 1 + * @mapping: address space to scan for a page with ref count > 0 * @start: Starting offset. Page containing 'start' is included. * @end: End offset. Page containing 'end' is included. If 'end' is LLONG_MAX, * pages from 'start' till the end of file are included. * * DAX requires ZONE_DEVICE mapped pages. These pages are never * 'onlined' to the page allocator so they are considered idle when - * page->count == 1. A filesystem uses this interface to determine if + * page->count == 0. A filesystem uses this interface to determine if * any page in the mapping is busy, i.e. for DMA, or other * get_user_pages() usages. * diff --git a/include/linux/dax.h b/include/linux/dax.h index 8b5da1d60dbc..05fc982ce153 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -245,7 +245,7 @@ static inline bool dax_mapping(struct address_space *mapping) static inline bool dax_page_unused(struct page *page) { - return page_ref_count(page) == 1; + return page_ref_count(page) == 0; } #define dax_wait_page(_inode, _page, _wait_cb) \ diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 45a79da89c5f..77ff5fd0685f 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -66,9 +66,10 @@ enum memory_type { struct dev_pagemap_ops { /* - * Called once the page refcount reaches 1. (ZONE_DEVICE pages never - * reach 0 refcount unless there is a refcount bug. This allows the - * device driver to implement its own memory management.) + * Called once the page refcount reaches 0. The reference count + * should be reset to one with init_page_count(page) before reusing + * the page. This allows the device driver to implement its own + * memory management. */ void (*page_free)(struct page *page); diff --git a/include/linux/mm.h b/include/linux/mm.h index d8f98d652164..e24c904deeec 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1220,17 +1220,6 @@ static inline void put_page(struct page *page) { page = compound_head(page); - /* - * For devmap managed pages we need to catch refcount transition from - * 2 to 1, when refcount reach one it means the page is free and we - * need to inform the device driver through callback. See - * include/linux/memremap.h and HMM for details. - */ - if (page_is_devmap_managed(page)) { - put_devmap_managed_page(page); - return; - } - if (put_page_testzero(page)) __put_page(page); } diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 80a78877bd93..6998f10350ea 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -561,7 +561,7 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) } dpage->zone_device_data = rpage; - get_page(dpage); + init_page_count(dpage); lock_page(dpage); return dpage; diff --git a/mm/internal.h b/mm/internal.h index e8fdb531f887..5438cceca4b9 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -667,4 +667,12 @@ int vmap_pages_range_noflush(unsigned long addr, unsigned long end, void vunmap_range_noflush(unsigned long start, unsigned long end); +#ifdef CONFIG_DEV_PAGEMAP_OPS +void free_zone_device_page(struct page *page); +#else +static inline void free_zone_device_page(struct page *page) +{ +} +#endif + #endif /* __MM_INTERNAL_H */ diff --git a/mm/memremap.c b/mm/memremap.c index 15a074ffb8d7..ab949a571e78 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -12,6 +12,7 @@ #include #include #include +#include "internal.h" static DEFINE_XARRAY(pgmap_array); @@ -37,32 +38,6 @@ unsigned long memremap_compat_align(void) EXPORT_SYMBOL_GPL(memremap_compat_align); #endif -#ifdef CONFIG_DEV_PAGEMAP_OPS -DEFINE_STATIC_KEY_FALSE(devmap_managed_key); -EXPORT_SYMBOL(devmap_managed_key); - -static void devmap_managed_enable_put(struct dev_pagemap *pgmap) -{ - if (pgmap->type == MEMORY_DEVICE_PRIVATE || - pgmap->type == MEMORY_DEVICE_FS_DAX) - static_branch_dec(&devmap_managed_key); -} - -static void devmap_managed_enable_get(struct dev_pagemap *pgmap) -{ - if (pgmap->type == MEMORY_DEVICE_PRIVATE || - pgmap->type == MEMORY_DEVICE_FS_DAX) - static_branch_inc(&devmap_managed_key); -} -#else -static void devmap_managed_enable_get(struct dev_pagemap *pgmap) -{ -} -static void devmap_managed_enable_put(struct dev_pagemap *pgmap) -{ -} -#endif /* CONFIG_DEV_PAGEMAP_OPS */ - static void pgmap_array_delete(struct range *range) { xa_store_range(&pgmap_array, PHYS_PFN(range->start), PHYS_PFN(range->end), @@ -102,16 +77,6 @@ static unsigned long pfn_end(struct dev_pagemap *pgmap, int range_id) return (range->start + range_len(range)) >> PAGE_SHIFT; } -static unsigned long pfn_next(unsigned long pfn) -{ - if (pfn % 1024 == 0) - cond_resched(); - return pfn + 1; -} - -#define for_each_device_pfn(pfn, map, i) \ - for (pfn = pfn_first(map, i); pfn < pfn_end(map, i); pfn = pfn_next(pfn)) - static void dev_pagemap_kill(struct dev_pagemap *pgmap) { if (pgmap->ops && pgmap->ops->kill) @@ -167,20 +132,18 @@ static void pageunmap_range(struct dev_pagemap *pgmap, int range_id) void memunmap_pages(struct dev_pagemap *pgmap) { - unsigned long pfn; int i; dev_pagemap_kill(pgmap); for (i = 0; i < pgmap->nr_range; i++) - for_each_device_pfn(pfn, pgmap, i) - put_page(pfn_to_page(pfn)); + percpu_ref_put_many(pgmap->ref, pfn_end(pgmap, i) - + pfn_first(pgmap, i)); dev_pagemap_cleanup(pgmap); for (i = 0; i < pgmap->nr_range; i++) pageunmap_range(pgmap, i); WARN_ONCE(pgmap->altmap.alloc, "failed to free all reserved pages\n"); - devmap_managed_enable_put(pgmap); } EXPORT_SYMBOL_GPL(memunmap_pages); @@ -382,8 +345,6 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid) } } - devmap_managed_enable_get(pgmap); - /* * Clear the pgmap nr_range as it will be incremented for each * successfully processed range. This communicates how many @@ -498,16 +459,9 @@ struct dev_pagemap *get_dev_pagemap(unsigned long pfn, EXPORT_SYMBOL_GPL(get_dev_pagemap); #ifdef CONFIG_DEV_PAGEMAP_OPS -void free_devmap_managed_page(struct page *page) +static void free_device_page(struct page *page) { - /* notify page idle for dax */ - if (!is_device_private_page(page)) { - wake_up_var(&page->_refcount); - return; - } - __ClearPageWaiters(page); - mem_cgroup_uncharge(page); /* @@ -534,4 +488,19 @@ void free_devmap_managed_page(struct page *page) page->mapping = NULL; page->pgmap->ops->page_free(page); } + +void free_zone_device_page(struct page *page) +{ + switch (page->pgmap->type) { + case MEMORY_DEVICE_PRIVATE: + free_device_page(page); + return; + case MEMORY_DEVICE_FS_DAX: + /* notify page idle */ + wake_up_var(&page->_refcount); + return; + default: + return; + } +} #endif /* CONFIG_DEV_PAGEMAP_OPS */ diff --git a/mm/migrate.c b/mm/migrate.c index 41ff2c9896c4..e3a10e2a1bb3 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -350,11 +350,6 @@ static int expected_page_refs(struct address_space *mapping, struct page *page) { int expected_count = 1; - /* - * Device private pages have an extra refcount as they are - * ZONE_DEVICE pages. - */ - expected_count += is_device_private_page(page); if (mapping) expected_count += thp_nr_pages(page) + page_has_private(page); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ef2265f86b91..1ef1f733af5b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6414,6 +6414,9 @@ void __ref memmap_init_zone_device(struct zone *zone, __init_single_page(page, pfn, zone_idx, nid); + /* ZONE_DEVICE pages start with a zero reference count. */ + set_page_count(page, 0); + /* * Mark page reserved as it will need to wait for onlining * phase for it to be fully associated with a zone. diff --git a/mm/swap.c b/mm/swap.c index dfb48cf9c2c9..9e821f1951c5 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -114,12 +114,11 @@ static void __put_compound_page(struct page *page) void __put_page(struct page *page) { if (is_zone_device_page(page)) { - put_dev_pagemap(page->pgmap); - /* * The page belongs to the device that created pgmap. Do * not return it to page allocator. */ + free_zone_device_page(page); return; } @@ -917,29 +916,18 @@ void release_pages(struct page **pages, int nr) if (is_huge_zero_page(page)) continue; + if (!put_page_testzero(page)) + continue; + if (is_zone_device_page(page)) { if (lruvec) { unlock_page_lruvec_irqrestore(lruvec, flags); lruvec = NULL; } - /* - * ZONE_DEVICE pages that return 'false' from - * page_is_devmap_managed() do not require special - * processing, and instead, expect a call to - * put_page_testzero(). - */ - if (page_is_devmap_managed(page)) { - put_devmap_managed_page(page); - continue; - } - if (put_page_testzero(page)) - put_dev_pagemap(page->pgmap); + free_zone_device_page(page); continue; } - if (!put_page_testzero(page)) - continue; - if (PageCompound(page)) { if (lruvec) { unlock_page_lruvec_irqrestore(lruvec, flags); @@ -1143,26 +1131,3 @@ void __init swap_setup(void) * _really_ don't want to cluster much more */ } - -#ifdef CONFIG_DEV_PAGEMAP_OPS -void put_devmap_managed_page(struct page *page) -{ - int count; - - if (WARN_ON_ONCE(!page_is_devmap_managed(page))) - return; - - count = page_ref_dec_return(page); - - /* - * devmap page refcounts are 1-based, rather than 0-based: if - * refcount is 1, then the page is free and the refcount is - * stable because nobody holds a reference on the page. - */ - if (count == 1) - free_devmap_managed_page(page); - else if (!count) - __put_page(page); -} -EXPORT_SYMBOL(put_devmap_managed_page); -#endif From patchwork Mon Sep 13 16:15:55 2021 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: 12489905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89A0EC433F5 for ; Mon, 13 Sep 2021 16:16:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1FC7760F58 for ; Mon, 13 Sep 2021 16:16:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1FC7760F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7AD3C6B0073; Mon, 13 Sep 2021 12:16:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70C846B0074; Mon, 13 Sep 2021 12:16:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55D7F6B0075; Mon, 13 Sep 2021 12:16:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id 47BBF6B0073 for ; Mon, 13 Sep 2021 12:16:21 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id F381118077B24 for ; Mon, 13 Sep 2021 16:16:20 +0000 (UTC) X-FDA: 78583052562.08.4DA733F Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2088.outbound.protection.outlook.com [40.107.223.88]) by imf18.hostedemail.com (Postfix) with ESMTP id 82CD64002091 for ; Mon, 13 Sep 2021 16:16:20 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VzCEV6qD0KfD6JcrQyAKfw7tJ/IXVq3VAmxpaybnIuU9sAJi+JnDJvMS/UvMicGUXs81QNz1OGlV78gmBQFfuCla0JNzP0qK1UNoYmn7h8VO8j8pbR6VsN2rm6yDxKvBMIIQHgHFaFLtQl9YB39rnYHW6E1W7HlLmrlogzy1tZFcl0PQTuQFz5DgQhYar+vrJ1Bsmeettbu6CB7Hw5VBpvZ3HjVD1H4/aokQ3sZWbYvUvCnmcUnjm2Rzu3Il014sWBn+dr/oZ88Pk4C+zmAzl1Xp9jXafOELSJUmOxjYyDCobFOZS484H4Mw3C9eKzczp7FO4kKUWzj6W1eDjZI4QQ== 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; bh=UOXVlxXjaV/L2Md0yFUOqN8vU589Vv6EPVl/uvpFxgA=; b=kh+mD2sP7Cmh27EA6PJiJi9KWmE8R5K2TptZwA8Zwaallzw4uYwTsCqSd/jJKapBMP9FRFIIGCFY39TqhSnh2f6HsFEJh1ASmnYTPFqLLtzndpsMXHKcioErYG6wj2PDZTKOfy3U7Lh/ryd4ChmWUMJJ2pOB3sq7LnFwZMEyofx6hcjsw0h63V0zVyfAJtMfHK32XiE0HwDy2IX+R1Sf8oNfIJdyxnWVzaWihnz3jiku+nyb/6HANpq0+jDJXQQcF//rfKB27j0eernv9GG36IpVq7Gwu2k3vgvVx9IKOalm3/nz32JA2nj14vU7Yu/nrt/H7IRLVN8p5q/js/heUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=UOXVlxXjaV/L2Md0yFUOqN8vU589Vv6EPVl/uvpFxgA=; b=yKYL+lywsCwV/W7AgvDPAmLTH0oHngxjaMvsMxlV0KabRDHcMilsAjgcH8i+EZWxUgTddpJxqSz7nK9vnXCQFkm9DZxjaxhT7eFdZ85y9cZ7YF74Mn7QBEANol/axXueXvU1RLQ7e8Mb/OLkT+bTcOC3v6QDX7S/zAQAHJlnLik= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.18; Mon, 13 Sep 2021 16:16:18 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:18 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 03/12] mm: add zone device public type memory support Date: Mon, 13 Sep 2021 11:15:55 -0500 Message-Id: <20210913161604.31981-4-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cbbfa199-f354-4441-f58b-08d976d1d194 X-MS-TrafficTypeDiagnostic: SN6PR12MB2767: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uOobYzhMsMxYofykOjqleizIMSN5tDfiVE0hsdY0YIuOIytnfol5wEG9aZcb2LanI2q5wnnR851nzCi00KZvdIQhKrDHOJLwP41cSNkD+/Ha9a79O1ormnI7xxJ7hXFtKVB0scSGTpBeQwwvFnUQwuHvnxuEJR5LqzMCQjoUCwaLLBV/eJ2wAAIdxlWM1jI0Hg+hD52yStm5ywjfabfhGy2LP6naC5yLSNtHi7BTBifQ1GYTeaYWaZGbWQh4YrbPpG0blpUPdBegm6LOj613WaEaaxFXJ+xFWtPX7lCLuJnk6g4P67UN9rExMJxgh23mEXs86+x6trce9NQheDmvAxvFJpOyLaUTwlqdiQ4JLuhiVKQC5T7eGTk+g1/VxcGfin6voPiNdVB1W1cRiNoNGo9j3rKQpfcW1xl5J7EqZ8E2fDkx3tSO07LPCCVWf8GQ0tScTr1Yb4rhGUztEsJ5ZHVNstEUBDD5YZGmSGji4ViWtRC21i101DLqMYaw0Pmyyk4a30h4cJRdox8MM+7TcLbKLHqqQpoE0qYKOIL20xjqOIO81gjqzhN8pSXSSB4p6ouohT39a5RflkewQtgXPyB0DS5xjprqycCrZEM9XIAw5vQSuMJzmTp7TpSaDnV+Y6CVFD0tl36SQPZbPyfdwmKgqQGxZ3vsJyeauNuCqbX4zKJAJobMRJf0DkLZcfyeEw6sc5DLhHcK4zNqsC+Gqw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(376002)(39860400002)(366004)(136003)(396003)(1076003)(7416002)(86362001)(66946007)(44832011)(478600001)(2616005)(6666004)(6486002)(52116002)(7696005)(956004)(5660300002)(316002)(83380400001)(4326008)(38350700002)(38100700002)(8676002)(66556008)(66476007)(2906002)(186003)(26005)(36756003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Gk8w+pI3/M7xYZxqJXhwHh5Lc8eSZiZU8ZRdbyg/UTtr0H7VDG8rohpfjZVXNhNcRWS3oTBqIbZfGm60eGJCNBVieNxKANZvYZoYlDw14HFmgu7BMontEFoZHPqgIk+wwBiQ5NUeZFsvBi4Egg3bw3sBt/dVVy1NubagmB4SJ/91Fpt2rkiFZK/LCnGifKw25Bu/RxvPhFqbXGscMH7e1NA34O2q1nJETDhsecPB4BKH+6YtFWd2or4H8W8qAuuePybfT/1Ber4UsuY71Ad0ZNjBCnz3eKEbJ2EXQzrahCb2yNCGgNi50eN4xGjK3fZuEOo2UfNMXSo9c9PeGospqkykZNjQS8j8Qc0jRjFEgPgwvthmVCPm7H0LGRoYGPtgzE0lHajNrigWB7Y0TslqNclgJpXpr5fDhJnA1m8qdyPzm6Jmz3Kqn0BwJRSplx1grT0iEsnFbQ/PPb5DwdeLO4Ggq9uvfX8K25sBoEjDr7jKsKUxxu1XRHgTnPvFZC/4TFhZjxqLR6iiDiYJH3FLvPxEbpqLke4cBbeY2yK2+8zq1Eif712GAYVyqRsANN4cx4fPWSARDeYkpcJcaZoAaBP5LzRaQof2WY1GgYLRgoYHuebkG5NiIHLz8t3npIg1d+31SV+pMtaW6nxoYVWpyTr13Eao3L/j27wsW09pEfqM0jbtBpFVM3tWOrOoEypEaWR4tjazuN+/pzdwY2iizfFFMHr8jcTkbTkxYg8EaznMctTm/FB95guFWbNU6CrePx4jdlpoV6bEWgaAEZCBz8agBCvW7bldPIOmMz+AFheqaGAHyx0ujbKP+qJsccpTRZBPKEuh0IRmUDl4GHpQteRYG/rpjrCbdPQYGqCEN1QIS3/XOroY5A5CqTHHw3sxIGK5ERqGCEOvL5g9VSCpCMidcGuxTZD/BFOces9jQWTvoJtCPjCWu0Idl4s8Wl4r8CUfikEbRdkimKjov8klIPCNv8GcgB5ai+dFRbwpsrrOmJHWhhF1MMocW2GhAKu+S9Wq2h3hC8CAxtnyQiUMwbm9AftjxIru9tIXX+Ui+8rkiE98ceTCrmYJ6ZpAAsVYqhcw1YkoCWBQOQol20in/YGI2R9s4ClMzcLYpOgIMRMriyKQWyNsmeZCS1H6EgQC4bYJUHxZAXVNPzxeV9WCxfh9/V5sCrEM1kbe+QBCjyfwKERmkH/EUx6eX8aO4heN5hauggKBMWlTNeEjiwp3t4fAewzhQBUEmnrtI7NAyIn+b5LiCiD52j7h2y9i2m5mN4GnBEBf6d1nN4G7Mo5L+7gxWo/QnN8gm2InDUsYNy+jEwVswq0sCSSJovHJB5xj X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cbbfa199-f354-4441-f58b-08d976d1d194 X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:18.7392 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: btLU2jXT/AIXtTa905LBpfsfJzLxy3odS1Q+MVKTX4bivmm6ezK6L/PfLI+mRHlfJRkexGXCtuBFBPI7TtIG5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2767 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=yKYL+lyw; spf=pass (imf18.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.88 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 82CD64002091 X-Stat-Signature: bpo5x96hrtf5a9f3mehgcb8bewn8fbs4 X-HE-Tag: 1631549780-384631 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 use on platform that have an advance system bus (like CAPI or CCIX). Any page of a process can be migrated to such memory. However, no one should be allow to pin such memory so that it can always be evicted. Signed-off-by: Alex Sierra --- include/linux/memremap.h | 8 ++++++++ include/linux/mm.h | 8 ++++++++ mm/memcontrol.c | 6 +++--- mm/memory-failure.c | 6 +++++- mm/memremap.c | 2 ++ mm/migrate.c | 19 ++++++++++++------- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 77ff5fd0685f..431e1b0bc949 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -39,6 +39,13 @@ struct vmem_altmap { * A more complete discussion of unaddressable memory may be found in * include/linux/hmm.h and Documentation/vm/hmm.rst. * + * MEMORY_DEVICE_PUBLIC: + * Device memory that is cache coherent from device and CPU point of view. This + * is use on platform that have an advance system bus (like CAPI or CCIX). 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 allow to pin such memory so that it can always be evicted. + * * MEMORY_DEVICE_FS_DAX: * Host memory that has similar access semantics as System RAM i.e. DMA * coherent and supports page pinning. In support of coordinating page @@ -59,6 +66,7 @@ struct vmem_altmap { enum memory_type { /* 0 is reserved to catch uninitialized type fields */ MEMORY_DEVICE_PRIVATE = 1, + MEMORY_DEVICE_PUBLIC, MEMORY_DEVICE_FS_DAX, MEMORY_DEVICE_GENERIC, MEMORY_DEVICE_PCI_P2PDMA, diff --git a/include/linux/mm.h b/include/linux/mm.h index e24c904deeec..70a932e8a2ee 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1187,6 +1187,14 @@ static inline bool is_device_private_page(const struct page *page) page->pgmap->type == MEMORY_DEVICE_PRIVATE; } +static inline bool is_device_page(const struct page *page) +{ + return IS_ENABLED(CONFIG_DEV_PAGEMAP_OPS) && + is_zone_device_page(page) && + (page->pgmap->type == MEMORY_DEVICE_PRIVATE || + page->pgmap->type == MEMORY_DEVICE_PUBLIC); +} + static inline bool is_pci_p2pdma_page(const struct page *page) { return IS_ENABLED(CONFIG_DEV_PAGEMAP_OPS) && diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 64ada9e650a5..1599ef1a3b03 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5530,8 +5530,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 MEMORY_DEVICE_PUBLIC + * or MEMORY_DEVICE_PRIVATE (so ZONE_DEVICE page 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. @@ -5565,7 +5565,7 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma, */ if (page_memcg(page) == mc.from) { ret = MC_TARGET_PAGE; - if (is_device_private_page(page)) + if (is_device_page(page)) ret = MC_TARGET_DEVICE; if (target) target->page = page; diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 6f5f78885ab4..16cadbabfc99 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1373,12 +1373,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_PUBLIC: /* * TODO: Handle HMM pages which may need coordination * with device-side memory. */ goto unlock; + default: + break; } /* diff --git a/mm/memremap.c b/mm/memremap.c index ab949a571e78..685be704b28e 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -294,6 +294,7 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid) switch (pgmap->type) { case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_PUBLIC: if (!IS_ENABLED(CONFIG_DEVICE_PRIVATE)) { WARN(1, "Device private memory not supported\n"); return ERR_PTR(-EINVAL); @@ -493,6 +494,7 @@ void free_zone_device_page(struct page *page) { switch (page->pgmap->type) { case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_PUBLIC: free_device_page(page); return; case MEMORY_DEVICE_FS_DAX: diff --git a/mm/migrate.c b/mm/migrate.c index e3a10e2a1bb3..7392648966d2 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2565,7 +2565,7 @@ static bool migrate_vma_check_page(struct page *page) * FIXME proper solution is to rework migration_entry_wait() so * it does not need to take a reference on page. */ - return is_device_private_page(page); + return is_device_page(page); } /* For file back page */ @@ -2854,7 +2854,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 public page. */ static void migrate_vma_insert_page(struct migrate_vma *migrate, unsigned long addr, @@ -2925,10 +2925,15 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, swp_entry = make_device_private_entry(page, vma->vm_flags & VM_WRITE); entry = swp_entry_to_pte(swp_entry); + } else if (is_device_page(page)) { + entry = pte_mkold(mk_pte(page, + READ_ONCE(vma->vm_page_prot))); + if (vma->vm_flags & VM_WRITE) + entry = pte_mkwrite(pte_mkdirty(entry)); } else { /* - * For now we only support migrating to un-addressable - * device memory. + * We support migrating to private and public types + * for device zone memory. */ pr_warn_once("Unsupported ZONE_DEVICE page type.\n"); goto abort; @@ -3034,10 +3039,10 @@ void migrate_vma_pages(struct migrate_vma *migrate) mapping = page_mapping(page); if (is_zone_device_page(newpage)) { - if (is_device_private_page(newpage)) { + if (is_device_page(newpage)) { /* - * For now only support private anonymous when - * migrating to un-addressable device memory. + * For now only support private and public + * anonymous when migrating to device memory. */ if (mapping) { migrate->src[i] &= ~MIGRATE_PFN_MIGRATE; From patchwork Mon Sep 13 16:15:56 2021 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: 12489907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EB31C433F5 for ; Mon, 13 Sep 2021 16:16:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 53B0360F58 for ; Mon, 13 Sep 2021 16:16:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 53B0360F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 2CB116B0074; Mon, 13 Sep 2021 12:16:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2542B6B0075; Mon, 13 Sep 2021 12:16:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0558F6B0078; Mon, 13 Sep 2021 12:16:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0229.hostedemail.com [216.40.44.229]) by kanga.kvack.org (Postfix) with ESMTP id EADE66B0074 for ; Mon, 13 Sep 2021 12:16:21 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 723C918066 for ; Mon, 13 Sep 2021 16:16:21 +0000 (UTC) X-FDA: 78583052562.13.CA36DC5 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2088.outbound.protection.outlook.com [40.107.223.88]) by imf18.hostedemail.com (Postfix) with ESMTP id 050484002098 for ; Mon, 13 Sep 2021 16:16:20 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qe8yKQlvNjE2E+VDJ6UI0yPFHKEN3SYbQ8MKMcBP5t+8YKazyniBfrCGULsumbgL2S3Eq0I02+JQpDJ4UiSH5WFAsGj6rALzI8aBZHB1aK7nydPOyf5N4xJRu9TZ9M7crWzHf2iEGdMWnXRpMaUkGYAyupxYnHWY1BNPJZPmlpQD7lix3+/jtO7qoh0gLQmdf1o0dfq34ZHj/KuQg5SE+Yf0U+hPH8jDO4A2EZYst6PfdgBcFdB4pPGyDAqNWBqORHrjF0dpEWAz2unfZFKwhztZvqxgWedHjOE8W7JIwVBFwTfTATn5MBW9budI4M199XcfBNif75tiRYhUPCGWqw== 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; bh=82oeVwrYnrtoo3t65wmfHCT585AIRkrgZr2iPzW4COc=; b=NxziQBkI1RHoURCFg3Dk/U5t3vzRADJfFlu6j3DBBJiaoBt5yZT+XGs+2X8thPpLoo1CLWf9vn30FUVaU4Do7JXyAjWzoajaKL8PARwpTmx8Q0T/cgHnJtRjRWzmKAzY3rwH5IWojIh73ESOxiU2JfR7LPK4x2WgITbKgOy8NWLwZWz4Olmw5qtRH+2LHnc3FFteEq1+iCIXFNFrYSnTLmKKJFuIrLHMuyey0ewFxkLU0OcAo4SMTOSK6FgLtJ1KfzrXaJ6+DulicUibiJQQtGHuWrnRe2QWHhDfQa8oqCWPmYI3AkSnd9pmBwW3hesQ8sySMk/EQnlMNa6muOeH6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=82oeVwrYnrtoo3t65wmfHCT585AIRkrgZr2iPzW4COc=; b=EUy21Vz9/NRMJvAW6zSJDrL2DIa0UcrGjA4rfCBaGpZLthQryqMA5lEQuVQwzLJnKBBNPvJK6jnhgEFWiVMgLBX2i//cymA6vme5AnrAxYNqM7ckTfgyjr0zC5xEm5emaVzdE870oAncUI/eWYnKQQl7WZgWVBE8voAmQpYgqyo= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.18; Mon, 13 Sep 2021 16:16:19 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:19 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 04/12] mm: add device public vma selection for memory migration Date: Mon, 13 Sep 2021 11:15:56 -0500 Message-Id: <20210913161604.31981-5-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 97ed0f33-e87c-4b9a-57ef-08d976d1d20e X-MS-TrafficTypeDiagnostic: SN6PR12MB2767: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:635; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O0sJXvWo8eoW8JhnXOuP0bp3kpa709Vsc2EBjQTRMZfF56mfydhQ/bxXqPorQTjjP614wafUH3UpZmUJ/JwQcGUW76XOnJ+to9Ot8QQjdvpuiOe6wWtp20iwVhQoc6V03t7S0Glq6+nrk2M+fOUc8i/UYFHYLysaEI7Ut8jf0L4nzAoEAVxrBe1jXm25zd2Lpl8U7l7xJp7LlXhmCxlTH8fCtCO+RRRf+2+f4dc6D75lXuZugtMEpi0SprzHtTQtsreKWMEoYSVKoecP9JK5CmeSvHcxQDV+YX/T+BbdV0XZjaeKH+9zlMLNB+RlN9TZLPL6CAfk2EAQdvoHyQnFWIvJ9wPf43+nUUUKESvk20nuW9bx6h7duOMM/lV1xg/1+M70K791CstuO/vSuGgsV+93/8bbEP/IBoPaq/4+aqv6vn/bz3ZhRZ7dOnDLbhfMs3ctF0OdWR0aVQB08gZR3RcWmLB75fyFtyRBtLaBl+M4sGqTSMwpTOVyt2GG4lY1JqUu2jlHEEkcDJk7k9lvXvW8JmkOuMKnGUWghlz9mpjX8uu/SdrrceKqKMkcfLe80bphQYC6m281UWFByZ8SK7wVeVntcExjignPGqQiqLHMBMMNiyE1pIm6NvMUDREq+FwfXzQgZaPQP1+fLWJQOskJHsO7OxJBUno788KdxRcTwKpNuVYrBsMNhBTzKfA3+DqAa10Slwlk/CsZJoTVRA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(376002)(39860400002)(366004)(136003)(396003)(1076003)(7416002)(86362001)(66946007)(44832011)(478600001)(2616005)(6666004)(6486002)(52116002)(7696005)(956004)(5660300002)(316002)(83380400001)(4326008)(38350700002)(38100700002)(8676002)(66556008)(66476007)(2906002)(186003)(26005)(36756003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z+pL25j8ZJy4yO1jnKqNnur5kroCEWNuUO3X8HZ4JrzDZGBXaXz5DQrwJ0C76zkijUcDitYS+yxY8PevXLWLsBafg51teV0r7QVidu2/u8uu6X7l7JX9iLySDGd41b40T5l0YPPZA0BJXE5nxEf7wGwPKmKsCkcmLmYJ4gHAZO4ZJ5c8yELAYjYiRZK/70wdNccl0BMJKzsJekQ08bnpiq+qmVYmBiHhrc33O+YdEKox76zzgeXOTk2EMIUmAegnoF4mhhz5YowYCilxVwANxhTd49LaIkbgekx0+SyU7xOuOcpp8f+Za+g9Zw14DEKecr1a6Q9DpJ2pxTIjz7x6J2tH5kjLauWjRe/yvxhIAOu0MUtLY1WDqYETcFT5+4iVRCSu76DChxWjrBR5NY978HfltMUYYmTNZUxRtvu10pxABa8QKNpPEwiRSQ2UaZE1VlHZaxlIeE13oVhKVrs8IJg2Ye2kyJO1z7/XTOmRgslu0wlzY/iTchLUbI1mnoguDF2NY9O+IP8+V6GVnrE+DkzwH6dXNL5a3i2COVsIdkNBcjdHNvjp1S0gqvci/FyUyVlkylSm3dTn/sExQB1PfeqqLuwpb6ktfuSzc21BT9/CRG4SwR6Fvc5kE+kpDajJWNyL49r0CWRCrakYo6yPEuMfjYuSQ/yYD2RAB5Y54TAn520q4W7cgw8LTqZRxxIfD7D4Ldmi8sbZaJjH1MjpKeVLAmm9k54BT2kp5YffPbi9/8Z8rdkD4DvGr1X7rb0Fk5OhUgUBuNAEEiLRBs0OgKhmuL1srJtH/UnhOM+Vt1cwamfr4JdsNVD4Ce8e4Ub7JipFIMVWwutzOJGbeR01Akj9ZBkWP1gNCQ4jFlDoYG/eHbDV5V1ZQUTNMkE4CiOw7a2ovGUuKlRPMYSkwUDyJm1VFaHCjPAeu4Ow6gB/r0RvSAds6VtnR6MyuNdbEhQ7WK1Gjzl3Gxi0S/0ExNLw0QlJTeH+ppAIC7UuQMmjyRbO8yrc5xohMggPm1iuvENB2cqGap3b3DXy2vbxS6RvgP4E+DA4uLy83/V6YKQychuCJPEwaHLT8dm0IOc3ityvO664sOFcz8VZDyU9LvMmKF2/03In7mok3puUfvcS3aLV6XmK/3pw1RUhFLvnbSi/58uL4auZo29oyeUbri+jN9FduzjKxkvBsyKUBt3asG8+HH4Ujy9gdmQvRjt4PgS3Rcgi5GoVACHliI3emnAFRX1nRgsRDp8EbR/nxy9aUod2sk+icCxnPnRn/heG3Dr70qIwZlYA2bQHvJ2YwqKxrvEPB5eJMca9lY28f6niA8Od0d49Oxsdt0Oxybxiouxz X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97ed0f33-e87c-4b9a-57ef-08d976d1d20e X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:19.5756 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: C343408cN/DD7mRbmMs+C4oMWEgjx6dftyKMIYEqnHbv87ZNfd0MIWIII885qX2HaHFQL5R+E3qC5Irzr3mc4g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2767 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=EUy21Vz9; spf=pass (imf18.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.88 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 050484002098 X-Stat-Signature: jgtn91ixeqq6i9dprun6eqz59rg5h9k5 X-HE-Tag: 1631549780-459701 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000005, 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 public type memory is cache coherent from device and CPU point of view. Signed-off-by: Alex Sierra --- v2: condition added when migrations from device public pages. --- include/linux/migrate.h | 1 + mm/migrate.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 4bb4e519e3f5..2fe22596e02c 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -156,6 +156,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_PUBLIC = 1 << 2, }; struct migrate_vma { diff --git a/mm/migrate.c b/mm/migrate.c index 7392648966d2..036baf24b58b 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2406,8 +2406,6 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, if (is_write_device_private_entry(entry)) mpfn |= MIGRATE_PFN_WRITE; } else { - if (!(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) - goto next; pfn = pte_pfn(pte); if (is_zero_pfn(pfn)) { mpfn = MIGRATE_PFN_MIGRATE; @@ -2415,6 +2413,13 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, goto next; } page = vm_normal_page(migrate->vma, addr, pte); + if (!is_zone_device_page(page) && + !(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) + goto next; + if (is_zone_device_page(page) && + (!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_PUBLIC) || + 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 Mon Sep 13 16:15:57 2021 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: 12489909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE1DAC433FE for ; Mon, 13 Sep 2021 16:16:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8164C60F58 for ; Mon, 13 Sep 2021 16:16:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8164C60F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D015D6B0075; Mon, 13 Sep 2021 12:16:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD9576B0078; Mon, 13 Sep 2021 12:16:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0318900002; Mon, 13 Sep 2021 12:16:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id A1C2E6B0075 for ; Mon, 13 Sep 2021 12:16:22 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5584C267C8 for ; Mon, 13 Sep 2021 16:16:22 +0000 (UTC) X-FDA: 78583052604.37.9539D27 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2086.outbound.protection.outlook.com [40.107.223.86]) by imf17.hostedemail.com (Postfix) with ESMTP id E5370F00039B for ; Mon, 13 Sep 2021 16:16:21 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RKweG7Wx6hfU78SNcLP/ZrxC/aGYMVSwCgtDk5KGcXUENQ5eyNlV0i6jwTulN5A08RA5DFpEeRUwuJno9klFvHuTtY/TtNJXtniPXHZ3zIUHtaGW1aBZZ9L0UsPqPIGp0d1xHu5tImBW/nJHX9urtWudozVl5Bp/ALVUEW11W/Hw3KvUI1PAO0Z8xTMHMDAFwgug+sDB5X2yHi8oABiYflsFLaWQxuxUCJ6mRA5Oiv51qzKx4WTkTDOymhCxFSnhkhn7Dzyqgl3ec2HH0nBWbd5zw/NKIGi669vfB2p/bykk6rdCti4rBLgzJolQyKrO9QUzxcGRWh7auG83na7NGQ== 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; bh=DtslbnmgwcmVuw3/IJPuNMBAqQP2tzGnRh8lFmQvcmg=; b=oAaR3GtSJx5M9sA/G6TAkAE3rVlAYUYH8wl/C6ppVrBv4+pPYlJ2cX6bC/gZkQcWL/3/Zpex9m9QzcmN3ulTIIS/3rFSnjCuU1Cbteq12l2pipzkV++0/scQuSIZPDxwOvzrUudXWN3LqQF7G58XT3G4BwHHOYiMXsH9gGiSEyAg19MDPs8MePxtFcNyvaoZXLI5L3bYD4YBDIBEgzSugsJBWIw9wHnFMn0cCfXBWlMNJ2rEHR/j/6NxK08N/hkZuCETXck3cmt4r2CpYj+59O82pkObGzCt2BSzFuxAJh7GagXbHXzSpMLPLr0CDXU6OLmBCscJA5w0EbyiOJxESg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=DtslbnmgwcmVuw3/IJPuNMBAqQP2tzGnRh8lFmQvcmg=; b=WysfpxMJgNIFvpKm6atq9yT9N72N9MTzx+x3x75Mt3xm946+ZOc7Q71WMCXHPy6BM42i9zrGujKIdRR2ORSasN5hAq4Y2L5Hor179Ex7Sx2tprxhKkeKaKN5sx5/nNdNZWzT0VoDpnlC6Nt6/GRtxA24lEC/eXot0WTP5OYuJeI= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.18; Mon, 13 Sep 2021 16:16:20 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:20 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 05/12] drm/amdkfd: ref count init for device pages Date: Mon, 13 Sep 2021 11:15:57 -0500 Message-Id: <20210913161604.31981-6-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4b8218a3-a963-4a0f-56d7-08d976d1d2a0 X-MS-TrafficTypeDiagnostic: SN6PR12MB2767: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1265; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6I2Zus+O0FBgz+1ApIpd52hkvk3S/pKvqSH6SZyg/pxvtFZCooyFOC/uazIWNuNCSra9FCc6mDySHB32l+VQq/5GwyNfGk+v6vOC6kus6/wLfEKv0bLUVghhn+97AG5ce/R0BZsTFGiONXkWQLu3+LISz145QUj/YjicksLb7EWWtA7X6KrSDhHQ18zMSgcuSADTCldhnDla8uxcOf4XJCvWhnU8mfduMiR8AbWeV66c0xLPqyeJ48MFLb0sLJW7yN0nxXfn23AxVyhsUl6v++s30C+QmDMHiKgna6JhtaBLuPPum3avU1bFD1fPGj1vMECI7h5/+SznvQhK8R/XOE+UfxMnHrkXMzF8MK7RUhDNGyFbcLcDPAfkbr04uBAaKp2KSpm2kczmg/YTp/6/TLMpf8UW3OJ2SK0T0H0gzeeSbJhSjbcmQNlm5unQYWyg9rYPKB3nLX80pbXQcYXJSTu3/bHhO5uDC+IeG/lb6WY6azkSp15finwW6H+sx6Y2oiUyOXjj1UnSIGYquV3by3kkk592Yml8XtrsqDAiUdnjrWCIqU5782zWaYwdip4mC1IgHCzJ4jxx2ipjXryN/w2zJxj7EA2bgCw1InH5dzLnZPAkJH3fMMHiHX4YRY1sxvlHVDUS3iKRDPDTw7XXcTDooWUiSpEeH2QMz5B7uFgzbEeaCwInk7OPX6pGDgTSRh5I0Fys/1VjlpzcjN38Ew== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(376002)(39860400002)(366004)(136003)(396003)(1076003)(7416002)(86362001)(66946007)(4744005)(44832011)(478600001)(2616005)(6666004)(6486002)(52116002)(7696005)(956004)(5660300002)(316002)(83380400001)(4326008)(38350700002)(38100700002)(8676002)(66556008)(66476007)(2906002)(186003)(26005)(36756003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BhpBqPIwpLB38UvGlkdXfdJtLyHgl9MBt4DFfigJYgW2X4M++DT1RuKo3ya8URhYnoDD8nLp0dB7BD/sflUcjyiAq3f0hsZIpq0VahsPbIruP3clUNF78KW7BipnORAHErGFaAVXNiJyoC6k6Qw3ZvhVPomM2OMldXLgCAKDjEpMl7FkY2I5XVz3Ai+pKPDHhsVqMPLShgYsI/EWPM8Nxxi9CBIWMx9SecElgcOwLOVWceK/DXiavDqfqOREbBuQtw56hFhdSBsja6IO2OmpeTpBOW4IUBbM2/gwu5/aRF0i6NyN+SbcFImdhSu/UXsG8TkzRhtMj7SiN2iXQZ+MD0PXc7Fo9XPymeYffU9VqHeNsHo73XtADAPEzVbApUJJptgy/AmWOZQLj0/ItGKACI9CP/w+3BznkwlnYtuXvHuzVPCsN7vSmu4luUDZ66nWzLnPvFLaSwVUTIFHfD8+p2PKpognr6etP9JU8u14xM9lrUWvOGzdynH8jU88r+hB7/HHf06wsOE4wCt6UubFb4XwqSVfNTi8+1D22iHACTaqa2WC1Ul2gBSvhsAugjtzMNjh2imXzBIgWTt+/3K5w9PLKVRu/eUKeTwmBeImW6aG9DSlIyzvtdEAANRj6gIsHB26+U02KXiO2ppKmjHUIDxqlQD71Pjwb9+g9nOAhAXv/eB9PQ872ee96m4GeWGgmKlRfsIGaZzkfypDti+CjfmyrKXtHyVrHtxkfyZtwkXQIaJCruD9UfRUcjwkyqOLNi0q2Yj6rkxEBcg3BIi1BWZG+hVG7MFDZcMfZVdT49cxgAu4lg2FAR9MaENFHHkiLAHMymA6+4Il9vpSuwkVHwbQ5QICww1BvZm7G/EIB+n2L5T6R7JOoyxf21EL6vBYXayaopw30qnuQSeiKAuY6YbCiYZvuOM+zUEvojjjfFWuEXxknlFHVD4Y84F6uIDaDzP5bZb8VrlFn583oh4ay08VBWJnyQG4LwI21RfJ96m+WMBAnTBJpDXvSKaJHdzc7d164UJ2FRiQ2ShBYy5xrppPiF+IHeZYQDlTFDqr9qGZtVFK0cXvo4Dp/kUpy8Kin640RFuAI8atDHvVb15s0Zns5zrjDzp96Wd1iqNbw/dLPjE7NczAyVpZQBcdhc8qNUujZFPiARcHt6bSSa2QqGWHjE+aC6JDfzX09Tk5wFRQFuO+SDb3KKFIH2YpUr9bnB4PrirH87Qsf7m0J56H4FGiTEttrxcJmo7d3zyMrMFyjhjcr4bu8kTb8J4KUf5iGP27HcHi6Mi/2AAzD+4aFSxof/LeYFkVk49QwWloJVncRgfO8bDfX8kNil0q2J3o X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4b8218a3-a963-4a0f-56d7-08d976d1d2a0 X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:20.5214 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RtoVzQaTrJcpN4z1dnO3PyEiWFygZvUUjqPlwQXWxlo3OsVwhhD1a/g0e97wE1QVZa9wDfzLsD99eUzQvsHJ+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2767 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E5370F00039B Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=WysfpxMJ; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf17.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: d6dqqf6pegnqpzb91qz1gbfmu7shoh8g X-HE-Tag: 1631549781-837432 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: Ref counter from device pages is init to zero during memmap init zone. The first time a new device page is allocated to migrate data into it, its ref counter needs to be initialized to one. Signed-off-by: Alex Sierra --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index dab290a4d19d..ffad39ffa8c6 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -220,7 +220,8 @@ svm_migrate_get_vram_page(struct svm_range *prange, unsigned long pfn) page = pfn_to_page(pfn); svm_range_bo_ref(prange->svm_bo); page->zone_device_data = prange->svm_bo; - get_page(page); + VM_BUG_ON_PAGE(page_ref_count(page), page); + init_page_count(page); lock_page(page); } From patchwork Mon Sep 13 16:15:58 2021 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: 12489911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23CC1C433F5 for ; Mon, 13 Sep 2021 16:16:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C764560F9B for ; Mon, 13 Sep 2021 16:16:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C764560F9B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BF2346B0078; Mon, 13 Sep 2021 12:16:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA0586B007B; Mon, 13 Sep 2021 12:16:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8FA5900002; Mon, 13 Sep 2021 12:16:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id 96AFB6B0078 for ; Mon, 13 Sep 2021 12:16:23 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 55BD982499A8 for ; Mon, 13 Sep 2021 16:16:23 +0000 (UTC) X-FDA: 78583052646.35.F3BC4DE Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2066.outbound.protection.outlook.com [40.107.100.66]) by imf10.hostedemail.com (Postfix) with ESMTP id BDC9A600198C for ; Mon, 13 Sep 2021 16:16:22 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rccdmfw7i2HI6J5FzSzxqSsKhoiu0glCnBuKce53CDTSsi4tAfnz7t41jgcZTAvdSXIiEmuMvH+HbKdq29+gVUpJEVzwWy+241EbCC/YIAxZ45giUsJZIk/S/zEWedtzH5BdsQfDEbYSmPzf3kOwdTRAXSksJtVRXfNwttRZ3+P7vLpBcnxRN3tXY3t+SX3ZU4WGVoSLamwycXHMQSWa0d0DNNBoDUBi2QMznyMg7G3k0PiO+r0+e+vMke6vYJsWx/avXiODPwdRgmqp7xkNiac5YFI8IfhWRFBU4cS43PY/OiMBB9JpIFZfNmOzOnFE+VgetC9PsH/jp2HEmwg58Q== 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; bh=dgBVJdw5GCMpxWJ5Jn6UKTT8DtbGRCSPuoWxVWP9HLg=; b=csV+/QVAGXF9zHLGL1hOCdoRVF2aF+1pOwbOQaClUTYsy+xmAkcLsimf+Hw5UhuQrrZ7cU3jVRFYfhMiHldVC8RkEFvAATHfEGhTHtN2Z1bVEAakqEdH4Jj1K2MdJ9CyAqB53WOEKRMVY42+5wq3QwHD5QJ7qNcFeo4nG6VsIKbM43/bzJrWzTARWr1at9sy4Sv+ggu8HQFW15oaqYcg8g5lDesg7KbiK/RAmYhP57ZXOvN6rCTalpAD+4fPpp5USfjC2PKnnWxamEGsYhkfpLgn7ObUkEqyi9dIVfdARFBvz/8OFVeSIzqt7gHtMFggQ/7nZ+JAEdBY6u3pUNLAKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=dgBVJdw5GCMpxWJ5Jn6UKTT8DtbGRCSPuoWxVWP9HLg=; b=HezgMxQlEQzq38TMsEoI/8zhCUvWcF0LfuOMjRrtqDxCDgx90hba5qrBF03VEK45j5PBb+cUDmuz8pLoRlP45Pcl48I5wUW1xiVMOqOYZXrKucLvdN/w5u9xUpcLVAxsPxzyI4UhBXHldpIVtW454oJD3Wggncxc9ueny9G7Wk4= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SA0PR12MB4349.namprd12.prod.outlook.com (2603:10b6:806:98::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.25; Mon, 13 Sep 2021 16:16:21 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:21 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 06/12] drm/amdkfd: add SPM support for SVM Date: Mon, 13 Sep 2021 11:15:58 -0500 Message-Id: <20210913161604.31981-7-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b15a3250-dd1f-4b49-06fb-08d976d1d31a X-MS-TrafficTypeDiagnostic: SA0PR12MB4349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xra5nwwcBvnYaNhTCR6lkmPoXCz1/EcIsij5Awm5CBTN4b51Oa0bsVVK1hrGLl1IS62KH7YO7CJw79C09L1IVDbJ1Ddxy7mAJNE13QQb0LRjNLB2mMABNnbePo488QtttH2RvY9cmRijol9oRD35s0DeQrBkA8yWkFSU5aoXUFAN6hZpIVky2tgWlqG4p9PMtr57VckfAuLxV4OW/iEkwsGQCvZUeM2ymGVWPx3RvatfTquZVklz7dbMRavZ7xL7UzwhKFv94EekHnyGAf2BZxyuE/EyOsbncdYdmnGOuNWcO66i7qQp8wYX13qW+Rot3sQM+PlEOPCsyhpoR/HbI8sbAQ75HU1hPObfa87DO1/cUxcVzLASHRfwe5aN7X6KvitRFWrEioAd3I7N6KmnaDAHofBpRGZMb7gyi7sJXUEUNe0MPsUAd4N64LU4ok0SuX1PWjXFKsryu136QtjXmn1tRrUBkZtAkP94QyWatO4MTeJOtV8W52doGZoYpyrk0zU2bmBlHyNt9fZwgfNVoYJquBpdTQ9Qu5stXfiGRPi6qJQSpfugK2qvV7n0vGvXky/h9rx+GagSgRrg3n17VC0Ez8lQeWuBF1jGqiR0GYi9RVZGVlWeRiR0RFIAMSudjFPsQl2OnIDHqGPHr7KnnBsEHzPGD72hbuLJfzkqFxFQ7htI0r1RwhuOjE8xtpUUWRM7E9bOe7F7ZLs/F0xTqQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(366004)(396003)(136003)(346002)(376002)(66556008)(52116002)(86362001)(66946007)(1076003)(186003)(7696005)(478600001)(44832011)(6666004)(38350700002)(26005)(38100700002)(66476007)(316002)(2906002)(83380400001)(956004)(2616005)(4326008)(8936002)(36756003)(8676002)(5660300002)(6486002)(7416002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PO2pryC76K3JPilDnjEuWaINdh0pgih37cgosoqupJGcjjYEuPSc581H3Rt5PEw+qObgcDSuisLSZFOO5JvExgcwXP0huN0ZhhP5iqmG/m5te0eALHvnI5wcyu4YvlhT45eKM5cptujnnHhXiySbMQFWNkEzUWziAjzBtFqsDIo6g1Tys+eP49EG5XUYMlOk+sHziG+08DY+3MGn7f5gpU6yZ9oQPSqg7IyL7Kw7ny5Wda2g4FzG2hSgdV8aX4z52GiL3E006KYpUd2bQYrhXmNRlC8T0FU7aOgYTjhQEeZP4Mp7FI388ggd4ygMPtMgupatsMVD4uVY9zil8T9vdu4/4BJTixouwygIHnJQgeglM6awT2DbtkPshfDHqLaF3mY1iG+S6mX6vL1mihh+V27yXSuZAbp3nGxoWo8g7/2e5uKadpdwS6CxPxeP6tGKf91smv9bJxBcW0rcxAK8ea0oxN0pvvN2ObTl6DL7V5hs6Fh6yW3NoqiTFSS74L8K6VgNsRJ7SRWfJQMA7dcXOWzURYtm2KU8Md+FyAwSJM1cr3E1ypePYfnE+lJALiWPgDEG2V8Dre2gA5avEy4WwkD8wqlqSymoa+Jk6S8/rFi4zsGo9aDXlTdpyG8R0u4HAn+trKmqADl6Jo0HN4zB6lHNMTqL/IO8tZwi6A9IgUkwf3bIqwTgQUoFX3SchaJL5zymBgNb8YcrbI3ehpVh5Wlc1NKPXbMsES4RnHXvrfsfz9udEuayc3bEPzcY3zaOvBadDw91sIncRnIAK1LMbgVqOqfn9gPTss6jTc25W+ZZJKJbbnU9s90ZrE1hzJdn3mtmCVV1qiICimBEN1s+VgEKNU4A4l+d3aXcBPV/C+Uob/D3ueaL0AmDaIe7StYtW0k6TJR7D8K7YmXuRfYSlPZQz5XDJMtSXzzGliIacW3c32fVSvU10fEE45uSfx84mh5BiK5gqPtNLfIdS5VpQZAbNG/stveSRBYipb1gQ7r5EAPs/14DuixtlU1PKbiwas2fiHG9XdQxpH0hrhtQt3/mTLoJpyqWHqg7bbb46itm32BU3lqnhw+yWP/gTj6n3tM/Y2yJopABHZgzVrV0XIy6pFkvs56DoSBSMldAL/jaJKTvBwa+gIS//0IWhnP11HP0J7JHzR3Oru8lEW0scflhG//uOOmgkCZsz3c5B6upyMUMSos3iHUJbMC11SqUMg7vTXB4eZ4CKrgXDW5cZ4UR6Sz6coZC9v7Sr+/mtxicO+K/NtmM4qMutuPclrQC9OFI9u0tpvLSLN/Xf9evI8DHbLkItMFCHX3xrdkIXJBeVzgeMnNGmlU8oGdmyTCW X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b15a3250-dd1f-4b49-06fb-08d976d1d31a X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:21.2940 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mQdOScBOU/mAg4BEre3gT7P2TfD90DabV+g3JBWRAhFtQTSpIJV4YNUkvBNrH5SeymqXqXHMrfiTl8vIweozcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4349 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: BDC9A600198C X-Stat-Signature: erzrb8ndgmoooqn157561d6kbspfr6ye Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=HezgMxQl; spf=pass (imf10.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.100.66 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1631549782-64956 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_PUBLIC to create the device page map region. Signed-off-by: Alex Sierra Reviewed-by: Felix Kuehling --- v7: Remove lookup_resource call, so export symbol for this function is not longer required. Patch dropped "kernel: resource: lookup_resource as exported symbol" --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 32 +++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index ffad39ffa8c6..d0e04f79a06e 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -866,7 +866,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; @@ -881,22 +881,29 @@ 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_PUBLIC; + } 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; r = devm_memremap_pages(adev->dev, pgmap); if (IS_ERR(r)) { pr_err("failed to register HMM device memory\n"); - devm_release_mem_region(adev->dev, res->start, - res->end - res->start + 1); + if (pgmap->type == MEMORY_DEVICE_PRIVATE) + devm_release_mem_region(adev->dev, res->start, + res->end - res->start + 1); return PTR_ERR(r); } @@ -915,6 +922,7 @@ void svm_migrate_fini(struct amdgpu_device *adev) struct dev_pagemap *pgmap = &adev->kfd.dev->pgmap; devm_memunmap_pages(adev->dev, pgmap); - devm_release_mem_region(adev->dev, pgmap->range.start, - pgmap->range.end - pgmap->range.start + 1); + if (pgmap->type == MEMORY_DEVICE_PRIVATE) + devm_release_mem_region(adev->dev, pgmap->range.start, + pgmap->range.end - pgmap->range.start + 1); } From patchwork Mon Sep 13 16:15:59 2021 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: 12489913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E1FAC433EF for ; Mon, 13 Sep 2021 16:16:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3DB3E60EE5 for ; Mon, 13 Sep 2021 16:16:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3DB3E60EE5 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 623396B007B; Mon, 13 Sep 2021 12:16:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 58554900002; Mon, 13 Sep 2021 12:16:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B3816B0081; Mon, 13 Sep 2021 12:16:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0008.hostedemail.com [216.40.44.8]) by kanga.kvack.org (Postfix) with ESMTP id 23B8B6B007B for ; Mon, 13 Sep 2021 12:16:24 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B1FE527761 for ; Mon, 13 Sep 2021 16:16:23 +0000 (UTC) X-FDA: 78583052646.01.6EA054B Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2066.outbound.protection.outlook.com [40.107.100.66]) by imf10.hostedemail.com (Postfix) with ESMTP id 39BF36001981 for ; Mon, 13 Sep 2021 16:16:23 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ATGUpx0fn1DTHNUn3yeeCAawi1pbBzvL66YCFRYmqJU470Wud74MfjZcH7bZwJUwaKLbU8HQ4CQ8T6FPCvpFYtSFzNS8C5J3AAhODJ11aN9IMCxZfbzum6Sda3r6DcZmk1+bNnubSEFGPn4MOKvx917XZXYiA3JkBlMv1c7Icp7RZRHGIDvQB0lGghZcgncQC0XhIn0ThmSSL+CmCIG/MbhUaVRJ8awnr7z9bZwX61Pgz3uc8eViU9VZm4ZDnfALaNd0Sx4mxSvRsIaUmqxwAcZavMaRS3IwC6OqFdiq+rjg1JK8L5/EXW+B73dJMHjEC9CzACyRnjwvmQvV8TkgdQ== 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; bh=yGCdRI6fFPg1mwUequG95R/0vCAEuQnzJ4fOflokHM8=; b=H+e72Jf04KM5bR0JkweIC1kwKVfXnwbh5wEKSC4S6TjIS9xDKRv9Ji63N2jg6zhjdKOD81mlZqKN0KB77rqOqBsdX+3nVl5SRRRT3mZWIWfn3E+1BvJ/KkejrDAJ2CsaNDvsEn8ShnCeF6njkW28F4KJlK1zhZasVjmxgTZ7Xe+VZLAxOb7iJIOQt9vycuApVmwmOGR2VBasFj9oBSYWhWLbriUTWlxBRafljP2dJxSFWmp2OnSLcJ7RusosfFrY9OcQ6G2TUOJoGl53o/3DmTS0JVQ+vfcrQnpboe34t3Yy1nlYX8wQL5N8MDM3G52BLT5BZRSrTtrj5K046OjC8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=yGCdRI6fFPg1mwUequG95R/0vCAEuQnzJ4fOflokHM8=; b=Qeio2KYOXaqBRmGd1kmgtJi8bAUDiiFpCPT+04s90yypsU4wMlXN/uooeAW39eJz21wAtMRcKJgoUSy4un210Sn1XIeipL4lu6VuErCLqvICajfOJnhSNKPPck5hMS9gA5TyGMA8KJJZRTmjWTDKqr07+b7AMSQxqt2rs0rSlDc= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SA0PR12MB4349.namprd12.prod.outlook.com (2603:10b6:806:98::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.25; Mon, 13 Sep 2021 16:16:22 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:22 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 07/12] drm/amdkfd: public type as sys mem on migration to ram Date: Mon, 13 Sep 2021 11:15:59 -0500 Message-Id: <20210913161604.31981-8-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3d6b7dc9-51e7-423a-1531-08d976d1d395 X-MS-TrafficTypeDiagnostic: SA0PR12MB4349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8qdM7zbPxz7/S0GEWadD1hRoIT48LLm34eWWDm07C4UPAOO1mlSrm1aIUXRdWbGevffHaz8zElJhXL0vw2HXMROxpnVKhYC8oVq4jYEi1o4Qa/4inr9DCFdlMlyx7/runRZ/RLuu72Iqj/WN5TrZbqsZrKBK58NC18KQOd9pFOhqbXM2LImD0bulDvip5aN6YLQgIqF2XX1xMOc3bcWIAUkf26TkQLea+RACArozeKF15wdt1trkyW8sjXYzKSRAb2QeUkVkEanzUPo82Zr+ffL9UVI9mVuSG/7hYoeYVxgUQJLmVQ7hyqfar7MqVVGHUOqDQVX+xdHxvnikhcJjAJBfaSzsjhuY+PdAvSPbc8JtGkUMW119/HPu34Qao1PsKKa21q8jRtnX7dx1W3VIO3PBeOaHSU21UwC6jnSKdXtomuxdV0bdrIo+5qgU7fUb3feXAUHLOr3Wmg8aJZcf4agc5PISbAHLRMysuWsUirhEc+R3+/WjVmJYro5L+lkCN46dsry+7nPDMis5IjTGiwDoCn/f7A+mJaaK3JJJxPoLE48F/DjUJRPf3fFpC3TIK+t70W7TCCTIzqPg2YYU/NJHZ3UIQa8FIRKqGUfhFWKzeAKoFk9M6AAyEiIWJGXhFLvJi7LRz+GctMylkWLheMG2rHQo81b0QqN3te2e/nO6wVp9M3bdA0kEozUcKYK3W/3yMogsnWHTpzTweTC9iw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(366004)(396003)(136003)(346002)(376002)(66556008)(52116002)(86362001)(66946007)(1076003)(186003)(7696005)(478600001)(44832011)(6666004)(38350700002)(26005)(38100700002)(66476007)(316002)(2906002)(83380400001)(956004)(2616005)(4326008)(8936002)(36756003)(8676002)(5660300002)(6486002)(7416002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DHPQ05IZ2gkNLpdT4htMZ7TCRhYuwQUprk9eNKIsUel3LdsERHuES6sDOcHrlMqe1QT4vey3DnU+dvL+37+bnmjfKc1AJ5y/AXyVhpLE7Mp04TpOfK3kX2La8hzrVC3ynmffmrFy5++YbDVH3RbCSF679hhaBM+lMTvD/OpKOiEDsU98X0mudeBjVdF2cYRMbvAGvVraqvJuwW5imPWjODhs9hsqVDShvNxND0VRhclCO/lcOEl2l12OYhjQck0qLc4YfK/MdZwL0XmBWyZnw/FrqGfm3TykUmY2yHdeGAeovfviA4KKoDsvyT1TuAcpTMTkUb0uqPhMfhT6zaPMb5G9Ocp3jIW/BLhF3twUWSWH4qicg1wzA5DXyOx9IIjP+KAOMrETy8P2vL/gGi0Ppnn1X9Nbp95e6DrFspmBgn9Q+EFUhtz+Mt4ZoKMsTFHrgvU6MLtQog/ebLqlniHY/oZHClc/oLqtKOdZlmN5cd3x/Xtv2Ny5sapiLQFZ0O6k6AY5hRgQToY+YmzsQJlzlgQ9n7ZYRmrU3svEKRuHJqmKoAHAi1NWK2SaygaObk8iDZFnDl1OX5074snbsyk8o0RN5diz5qXFUmhO3AqQWRpxnuablt8wh44K+A3gKmbRRdzBz1187mC8K+Y7/id8rkG6HY/tuJMXkaz/lakBO+3TUAcnjtzjFvQUeJotTpoQPuup8Ek2Mhm/YYnUl6siZrOsYS4V6XNuh13th/cyjWOZB3xor0CcoEzKSFie7pxSjt9L9BGV7/+gm6kYeYZzzkGNzGpzKQJ6Y6Kb/MWe7Akcxs4FbwjcCGLvTid9EYaV4/5Cb1xnQ6m7X8a6LGx51shpIwKGaM8ET6zChXw110MBr8KU/C7imF0T6XBkKijoVGJ13lxZuwj32QeRrmuiKGZNSeecJ5LtRnmwrL22K2CdH3hZDPwfh7rrPossgTQK/aWJkKxhkuXIyum1PDBxjEWtfqY8EOFq46p0L0skDZILyli2z4VHvGBPSRr8MdC246c1UhWEnLfVeU/KPJ1wrJz2VtLfRUSvOPhdwTfk2mQ5BegM7OuatSVeG2D5n7XvX6sB31wK9ZMWm4Zcu5RWqyIgMHuvt1Ux/0k7Ukw5XxCdCgCltgm8f6/cf4ilMGbuj+T0uyShP0uuLXOP+ozITCcpbZ4LMo24mW/B84IuRKoYPZDqC49Mb8LbYsPI2MJvHsaUGCafo5AilIL6yfX9kWfayjBPqgaNh7AsUNe+IUsNPKcemUjdqrJDs/jVX3LbSZidRUezBzgLwLovkSeKDjM72s7jRxzcv7ZQHM/B2N1T4+9N/jXkBnYTjCt/pu1T X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3d6b7dc9-51e7-423a-1531-08d976d1d395 X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:22.1791 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xQxJM1uG0Bsm8AAb1uTeJSafFqAk5psuJpaUpKi3gH3tF6hBKnR981eLfCIQs8zCtVhkKSEg1T7oNTaZvM5V3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4349 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 39BF36001981 X-Stat-Signature: 5d48twq83qmwrdoyg1jwjqy3wrqy3sbs Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Qeio2KYO; spf=pass (imf10.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.100.66 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1631549783-970824 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000005, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Public device type memory on VRAM to RAM migration, has similar access as System RAM from the CPU. This flag sets the source from the sender. Which in Public type case, should be set as MIGRATE_VMA_SELECT_DEVICE_PUBLIC. Signed-off-by: Alex Sierra Reviewed-by: Felix Kuehling --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index d0e04f79a06e..b5b9ae4e2e27 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -617,9 +617,12 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.vma = vma; migrate.start = start; migrate.end = end; - migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; migrate.pgmap_owner = SVM_ADEV_PGMAP_OWNER(adev); + if (adev->gmc.xgmi.connected_to_cpu) + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PUBLIC; + else + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; size = 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t); size *= npages; buf = kvmalloc(size, GFP_KERNEL | __GFP_ZERO); From patchwork Mon Sep 13 16:16:00 2021 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: 12489915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3B61C433F5 for ; Mon, 13 Sep 2021 16:16:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A6D9860F58 for ; Mon, 13 Sep 2021 16:16:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A6D9860F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 1B80A6B0080; Mon, 13 Sep 2021 12:16:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 169FE6B0081; Mon, 13 Sep 2021 12:16:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F26DE6B0083; Mon, 13 Sep 2021 12:16:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id E3F076B0080 for ; Mon, 13 Sep 2021 12:16:25 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8DF05299A4 for ; Mon, 13 Sep 2021 16:16:25 +0000 (UTC) X-FDA: 78583052730.40.C26F5A9 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2076.outbound.protection.outlook.com [40.107.100.76]) by imf16.hostedemail.com (Postfix) with ESMTP id 2A251F00008E for ; Mon, 13 Sep 2021 16:16:25 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TX3w5kUexJUMhoC5qIyYzd0gVokdEVhGrOOnrOYrTDTojF1MLBBeiuYjmy5Tv6fZjtS8IyTL7PgjvSitU5jiyiyOg9La/DGEHUWXZJ9IXjSmqtmDHwNHdmWaO/K4xtHUQyLtmRx9JX8/Qmr2/2QkghWJzFXa6eoe/Z1lQ/tIyzkP+j+z6W4dr5HgpVUnu0RxnfX6HdmDkZrIDbE2ObRc1v+bq2Ptxp6lqTEDg+KIs34hbhhMfDxxFBRdhCiNep53/bwue6iBzitCzLyRl8z/uXtKtZ3wHOaJO/fvzIjDWFaQuOPAKBZEfJOSOaSvcLGg2UEVFpKPxGNwfTUMubDDvw== 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; bh=dKC0SDJcXNMoavar9nuqOgDG5SsEzpi3aevSualtrlA=; b=NzL4yqV7kgRABOtmIJHdflqS2WaQtDrTgWs+a4D3DW70NKfX0shYmDtpK30as6Uy14O9G54S4K8hn4uWxxiSfaigyVQRodxu4gBJY+UqoyRTgERUXYv5vkDjb15OoFdCrsCa+OkqJnxTNKA+YRd5lA6687WY3fMsSCkhsMfnZ5d7bWheyOK7zohZ1/2p3YzAib2NT0zXlmjslqJCMLFWUvC7LF1JQaCpacJ27JeOau+HBlGEAxIRRerlcGUdZFQYAp7LnOIT5pAQEFXA3opDFTXoESGLVgqarUYs3hZ9xJYq2lBzPguXrJU6qQgWNxENzsVW41Y4oKPv2N2uYyjkGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=dKC0SDJcXNMoavar9nuqOgDG5SsEzpi3aevSualtrlA=; b=keO9mHR1ET6lgbJZbLNocY0/3JsE6uFHEUNadunKKVfhh1LG1E7zI4HGRETTteLyGc8giqFeze+5d2WSHuJaLP00KeQdWQ4RGY+/VJOmiNm7p5+81rjOilGpZH6lMTVqC3yvg5DfFuLCU0II442NJQKbqwTqsr4BvqAhwNoM/B4= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SA0PR12MB4349.namprd12.prod.outlook.com (2603:10b6:806:98::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.25; Mon, 13 Sep 2021 16:16:23 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:23 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 08/12] lib: test_hmm add ioctl to get zone device type Date: Mon, 13 Sep 2021 11:16:00 -0500 Message-Id: <20210913161604.31981-9-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:22 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4f7d4d8e-e771-4e9c-1771-08d976d1d42c X-MS-TrafficTypeDiagnostic: SA0PR12MB4349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2399; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gt7CixnATMIwlAqO65soFRDWyZfxO6BJMk8dcRb2pCP5LqTuq4N99uyluTgA+1hYAwXMPEBLkqSi3srqRxDYU3FYDgBZuOV6/V3e8vorj/CnBBqOeajH/J3/HucKCvfvXAAN0KZn0t7ZYQILnBJh0zPbJ3BxPF0kdFA7bV8yTdJcp7Q8bnk3CB37kZd3f5C7Ua1Hkj+ItnKR4oynv9R5x1YyJxxVMOL7dVeZRQNA9o9/hImepSwJRsRUzaQMFqFmSBo580YvOZQtIJyzn2fpeTTHQWI12Xz3lChj5aL5WMSRF9w5IbAFcKfinpxDSk68MGrs0mSLbrjWQ5++Am4OCwcvBXV5fPuXRfbq19k06EUrWg4skxm0eOBn1WcG4mBJAgM3RXZG72NZdKHVicRJGKuht9ft49e7jLU7CzMeZRM51vf9qqPBN+mqGpi134qOaINQw2GILmLlGCWdTMVGSrzf1fy1bkqCq90650wp5cTLT9GXf3HcpbHO2yC0YFcNiPf60JuZvCFLXHRht5ojzEORiNX7DPRl2Et0WLIjNXJRNonjMXVzWxphGaZNdFQWTFcIKJlYv3Z04aXXl0tjVoYdEJi0h2G/PImpvcJy19sYCH1ouXn9R7QeyoRwrf0KCsN43IaSu3nMxfWLKF14f5y+OYoec3xNZbBimvzaTd9Mw55PAPnGMhXfdwPWppya X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(366004)(396003)(136003)(346002)(376002)(66556008)(52116002)(86362001)(66946007)(1076003)(186003)(7696005)(478600001)(44832011)(6666004)(38350700002)(26005)(38100700002)(66476007)(316002)(2906002)(83380400001)(956004)(2616005)(4326008)(8936002)(36756003)(8676002)(5660300002)(6486002)(7416002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QJZpihtJDtk9j3wSmqFQsJPY6gdWi6fVuAzkn0jfueGyyxg3d7oPlpgU/IlMXEnBzi7YEzY/PVbh75Fy2Gzw8I3BTJb3yK4Nv0KH2347UruRGuTT190gdnHuWumSVV7iiKKCMgBXrpGmI+9uIinFVI4rCHO0udowL6CaQjOaXDjdI2pPU02WMDSY5c917BTcaPTNXkF2fxA4bo9Ws/dsQJydVjnnStirDV9EW+QxfNUza0Hib4X0U0xnGFMh26MbxMQJcIfqMCX6mUOdg5/mrW8YoWvvXpFerkKBub4pQVmWshRILfOYkMQx8IQPOARHGlAGlQePyYf8Yx9lxWEZGzL3CXPDxoVjKi3LW0MDej+2I4NAx6iZTwZbF6m91swjYaF6zz0mBVb/hU48TOT2iVn1soxFbryFzfiM6lyKw5ZarJIUh9al21e00kN2IkwyHQY6sJsBq2+vkTAfO0TJ6PYtCciqhiiSV8cp9fxpvEzXe1xuBxp/w+x8K82vUn+ZZkQyU6w/osPyLbCI7dDcUHIQl8nT+khucQ2I3Ng4vhdHSeWspdAjIDjSDf1K5RwLkTifru9ueOGeWjP6qClf3i7WZqlakKCXXblIU0JOcVFNAEtoxSt8JkygSTgpGoz1gUwJUlWscGsySNVJkIodQnh98vwT1Redus/Ce+I0MImDu+tJYK+warb2UawJGo+jpZg0diEYcAiVQ+jeQ8wSJGS60C2a2l08JsHhc4FPjtOu24pkgo8Hdllafqzb9lIBGeVgGlVAFj412m31j7L3e7F6lDVQNWMjf0po8zkLH4fDLl0brVPn2afZPNF8j7rAS3UxUsMReqGIRUm4LRMPFoGNTLyXw5bm51N0mOGIdOopmcyTQN+lRDGk9srJqu4XjKmxDZ6W7hxnvyUBsqB94QJHTFmXrrw4ahFc32AUHdt6KPv9ZTk41gg9zlZZ9o3gVzkBMbWj9HNhBCwbJK0YN5HEgDXsKzU3YlSS9AlojcVxbA363XsC4ZtDRfEm4dBvJB4knOy7lxeUw9M7D4X8rjsawxREdXUCLdZJfGZQfgW3CxVpmI9416cHO425KxFjJWdaQVuE+SDkICOvmC20lz75pFqX/Qf+irpne1Qn/5INFqF0gmkIUVTr+mmg8v4KoRZ6VklGbYvlVbj32osFGNwkXM78VUGJNQ1wC1cPeIprsOA5x8ikC+KKTmgYbONAxxuFusp2UkF2A/ySi5WQPfAWBpgSmgdW5v6QDpNaKQiXwz2MXjiyrB9YW/l4JWXoIvYBdSwKGe2ZztdjmCrZKfgdP0MroSUUMYsd1uX3Hq0Wqbu/HA+9KEoqOWF1hmUX X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f7d4d8e-e771-4e9c-1771-08d976d1d42c X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:23.5820 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pgne6P/mS3B5DWF1burbTt8qgSDrHjYRawWXBMGwDGL//PwCdZrQlgNctGJNTLfW0/KjauHU5Vx+zjC7Sh7SLg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4349 X-Stat-Signature: yjumzfu8umkhqud6p65qmct8997fiabh Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=keO9mHR1; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf16.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.100.76 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2A251F00008E X-HE-Tag: 1631549785-927869 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 public type. Signed-off-by: Alex Sierra --- lib/test_hmm.c | 15 ++++++++++++++- lib/test_hmm_uapi.h | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 6998f10350ea..3cd91ca31dd7 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -82,6 +82,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; @@ -468,6 +469,7 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, if (IS_ERR(res)) goto err_devmem; + mdevice->zone_device_type = HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; devmem->pagemap.range.start = res->start; devmem->pagemap.range.end = res->end; @@ -912,6 +914,15 @@ static int dmirror_snapshot(struct dmirror *dmirror, return ret; } +static int dmirror_get_device_type(struct dmirror *dmirror, + struct hmm_dmirror_cmd *cmd) +{ + mutex_lock(&dmirror->mutex); + cmd->zone_device_type = dmirror->mdevice->zone_device_type; + mutex_unlock(&dmirror->mutex); + + return 0; +} static long dmirror_fops_unlocked_ioctl(struct file *filp, unsigned int command, unsigned long arg) @@ -952,7 +963,9 @@ static long dmirror_fops_unlocked_ioctl(struct file *filp, case HMM_DMIRROR_SNAPSHOT: ret = dmirror_snapshot(dmirror, &cmd); break; - + case HMM_DMIRROR_GET_MEM_DEV_TYPE: + ret = dmirror_get_device_type(dmirror, &cmd); + break; default: return -EINVAL; } diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index 670b4ef2a5b6..ee88701793d5 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -26,6 +26,7 @@ struct hmm_dmirror_cmd { __u64 npages; __u64 cpages; __u64 faults; + __u64 zone_device_type; }; /* Expose the address space of the calling process through hmm device file */ @@ -33,6 +34,7 @@ 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_GET_MEM_DEV_TYPE _IOWR('H', 0x04, struct hmm_dmirror_cmd) /* * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT. @@ -60,4 +62,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 Mon Sep 13 16:16:01 2021 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: 12489917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F4B3C433FE for ; Mon, 13 Sep 2021 16:16:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 42A2C60EE5 for ; Mon, 13 Sep 2021 16:16:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 42A2C60EE5 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 44E4F6B0081; Mon, 13 Sep 2021 12:16:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FFBF6B0083; Mon, 13 Sep 2021 12:16:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 277F76B0085; Mon, 13 Sep 2021 12:16:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id 1903B6B0081 for ; Mon, 13 Sep 2021 12:16:27 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C56FC276FD for ; Mon, 13 Sep 2021 16:16:26 +0000 (UTC) X-FDA: 78583052772.09.F64A1DC Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2068.outbound.protection.outlook.com [40.107.100.68]) by imf28.hostedemail.com (Postfix) with ESMTP id 4806490000A4 for ; Mon, 13 Sep 2021 16:16:26 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aFfJxNSeP3zAJeYPKE9x4A1gKBkN0nx+1XIBHfU0R45lgag5MzkN9oE1ZIX51IPAWeqf9CACFEcG5gwsVXmjeZfroS4pEKg7FF1gyP6FE+rorJ6u9oiZN6IG1+mCLg2okKuqiC1+LY0IIf86rR7mmYGaUi5dGjx1e3he5mlOMWUlbtuXipMZ8yO2Ht6n7Qp9jJaUiz8d6iThaBsVR5HuyZ9+wIxaWRJJA5WU1wy9ljXQeRT6Q+c/PEXl3JA1FmLjROyqQe/syMGzhM9ZiLzX5vT1vkWCuc1UB2C/IJ2yxqOK0ze5XZw56TlS8VmE2VvQnXF9SlmnbZwcKhL0x2wdug== 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; bh=Vezipz8HAGylYBhfg6EP5x9zGWoGwLSUmkbOu5ZdCTY=; b=Mw19/o1tZsNhU59jHBaq0lhgvRvnAyKBoiUD0cpWcucS0YX2kxc3iCHnGb86gzCTNyyJ2w+1k84SGqYSiVAfyTZ0Vv/8SECWND7Ynl4FpBiKdnBEWfnD0BrioDLnozn1mAzTbKwmMYieWtqE+aXzz0/9fWpP51HJF8nElebjjg+e2HrNj0aGaM4U19Wfw6G9TQzxqMSzj31SMLjeXKIdQJreje5gJ1ikZ2/SHjGf8IfMxeuFQvOY1OXOH/0NKVLmN6ecOOkYcULbtuWRkQ7I3PVPZnegXME5nkVCHHo8k/ObJJN6RlI7Ps3SX9iMeaFszdplUbV95qCUzjO+H4wfFQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=Vezipz8HAGylYBhfg6EP5x9zGWoGwLSUmkbOu5ZdCTY=; b=Lm1Q46bIc7RVx6BbuZVnTT2e1ZG8NFrmwErqSixvVXTRDqBPOhEcnCbPdYdFnNABpghRH5210azfL+dmL9enfQO/o0DNI7h+RbpwWYQcNyexghGaO+BQ7Kg5sIHGRx7NE3/RMAsLQOa7TrCMXroW5T1dqhwplZekY6GHa7osufs= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SA0PR12MB4349.namprd12.prod.outlook.com (2603:10b6:806:98::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.25; Mon, 13 Sep 2021 16:16:25 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:25 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 09/12] lib: test_hmm add module param for zone device type Date: Mon, 13 Sep 2021 11:16:01 -0500 Message-Id: <20210913161604.31981-10-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d922d66a-e5b4-4717-6273-08d976d1d544 X-MS-TrafficTypeDiagnostic: SA0PR12MB4349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e1x2q6NwtQfM/zIjmtTEGJ2BfeGeL8nLWSrLW47rwrVflz3qa0pIaWsvYuZ31n6neGQzXVvx5oGnJ48idsGPc4UMP/t7+lPbyJLmHCL7FWrMarCPfLkqns2ilxH6zq3FRFb2BGoTDqJbId+PO5F47Ww/fIY8c86tf2f09d88WRHXMmdO+WhkRPB6FTrh3CnlcH96PrFWXEkM44SYWx9f5rsBS3iQwhJjENpzs11fmcfb/8bep3DZ2y68u7fiKHjy65/mtxisfUWrBpMllgD8JbHqp4Gg6hrOsWbEV36++UlEO8s96XZd5ST8fwtIu3IJtjT13xtZvbkFHMotx7g/u1oXIiIcWwDVhyoar3p8inuZffJUhvs2h9/2rSAZqME3dcguvfNiRRqbCZCXCGHcbTBwxMRiNjta73LP5UXHYSr1ncRFjGUcOlFRIKmfivsPHS0JkIWrEVfHgOcQoQEMxIq9sXcgz40XZLU3yKykyDU8dDbOHxcljM1BO/KG4ApN2utMsLQFmYDEMOWlHiIQESkAHEo9svlHRAN4V9q7cNwxi8xOmE52WO0i+51ZAwldPXy62DTOoC7KU8H8uEn4qmeAGrYCNTdmxktBttfddp9hsRoHowO6EK92EI8rxcu27OvPKPsDMWhLj8ypVGjGjrF9u9mnO8RLtMG5Zf4J3FjUCtY/aGGOW2mVuEUWuWTayML+07lgEzA7PAFRuQvGgg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(366004)(396003)(136003)(346002)(376002)(66556008)(52116002)(86362001)(66946007)(1076003)(186003)(7696005)(478600001)(44832011)(6666004)(38350700002)(26005)(38100700002)(66476007)(316002)(2906002)(83380400001)(956004)(2616005)(4326008)(8936002)(36756003)(8676002)(5660300002)(6486002)(7416002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xA7YQYVn4yIkIsThlcQlYCvHw5vWrhOKN+XHx8QM/yA/WCe+MUt8Wr+PiZYisCy6J3Y7xqaPGQjA9TlxR38oVWhCm2bfllRmJCPFN+EOlapaC2ysf2W6+1Ej3ISVQHdNSlERou+xLLs9zo9+EQ9tH7PFoqw30We9APYnxA6x4gOdYaQM0W+pw9nc6+puNxME3EzL2aim4OEpzbbb9aZm0XVSj/mUkogoGDwGa9w0WUa25fTvd6mjWWHB1lk7xAOfo+CkozYeOwbHP0KirsSQ7oen7SpcAAmtf0r0mxIIIiCbunzZmze78J14SJtE5H9ykcuoJFNYAZBWvMaFj+fv64FHeSu5hKrnMTc0gWHubGgkyGRFhbFZPBzSUejNcLQhQdifbkpUC0rcwSP1TwjMDDycdgMuXUTbxH8mmQpYQzQ0/bT1UMB2Pnbs4Upj55/ud+W+GWnzUcSh5tsV9gVnshWD+/JPVjmoTFcFMeeTBR7XV+uGMUMN23T7lh4Mm3y+2LZ1q2a6K21fxzdeA5/gcGSGrGi/4qFQmgw5cZ4sUF0+TarnM6TeDWSl1q3pW1tHzHwWUcZOTJZWAzltDOBm0JuJEDsDnbp8DVc/RopEtThJ8SIq1K8QXVOwX90zCruUmG8jQo2Wt36NiZFyROt9lc4LyAShl//ulExDyg3+vNh+Wu9eHD+JGkWLCAS5GKjXvO2TaDIT+lpslI8MAQ4q5JkRu+RRcW9LWghPKRfvCrN/St5apAmNvBqcF0FfmoT8YlhpXeKZ3iZpmRy10pUSD9bsrE9erRJfngLfc8xQat6ZuFcvxe0Wf7KuTB3reXhQAwsE7dRTGSR7dhsDqPTbz5RepM7zuzjK3gO6TGHR7lt8H7GNWZkrfotAJeRzjc9uBwfUrbdMjpa5QbczcrbAvaGogT6Nu7YAHWV29dj61Z2+/MAZgmsFuK7HZIBS9xTvCXhp40Yfjprf9/LIqC5gel0Xyg4QB57zhsepQDm/l6hfAdkRfEkxx8N5ZisNvXgIpoU0qDmrv/381WriDh+CN1m3OvweKX3uFcgJurguvn0yYSV9Cw5PviHYquM77YYhzHSiLRIfASjY/gFN9awVBVMnz9Oq1hoNJ/scRnwUzEzFOMsVg2UgEZJOlRk+TVmZUhxXwRdeDsNeFC1WyWlRafihB1etP7h4R/Wbch3MkVFLCcuYNR/8PuBpFzQpOBCBrLVV8dAbbrX5GcD6CyfhYBctCNMH27kHP0S8OViUQOjsb/Wz4xePbMkPVCTDDy2NM9822YU2nfOE9bx18y1J3D9ledUNSL41zO+YdkYrNQvrrxe70h1LzCj0ar0PTqQy X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d922d66a-e5b4-4717-6273-08d976d1d544 X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:25.0216 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CtyRMt9ps6dzS2Nlu8G84wGfH1O2QW77ATHum7TiN+xW1EqhCg+HkVZwv0ACMtEUpBq75r1mO0pGDZFS3Pc8mQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4349 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 4806490000A4 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Lm1Q46bI; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf28.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.100.68 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Stat-Signature: fe1t1adi1rbdeztfba853wfg68m64fgr X-HE-Tag: 1631549786-188641 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 public 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 --- v5: Remove devmem->pagemap.type = MEMORY_DEVICE_PRIVATE at dmirror_allocate_chunk that was forcing to configure pagemap.type to MEMORY_DEVICE_PRIVATE v6: Check for null pointers for resource and memremap references at dmirror_allocate_chunk v7: Due to patch dropped from these patch series "kernel: resource: lookup_resource as exported symbol", lookup_resource was not longer a callable function. This was used in public device configuration, to get start and end addresses, to create pgmap->range struct. This information is now taken directly from the spm_addr_devX parameters and the fixed size DEVMEM_CHUNK_SIZE. --- lib/test_hmm.c | 66 +++++++++++++++++++++++++++++++-------------- lib/test_hmm_uapi.h | 1 + 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 3cd91ca31dd7..ef27e355738a 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -33,6 +33,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 Generic device type will be used. Make sure spm_addr_dev1 is set too"); + +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 Generic device type will be used. Make sure spm_addr_dev0 is set too"); + static const struct dev_pagemap_ops dmirror_devmem_ops; static const struct mmu_interval_notifier_ops dmirror_min_ops; static dev_t dmirror_dev; @@ -450,11 +460,11 @@ 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; @@ -462,17 +472,29 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, devmem = kzalloc(sizeof(*devmem), GFP_KERNEL); if (!devmem) - return false; + return -ENOMEM; - res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, - "hmm_dmirror"); - if (IS_ERR(res)) - goto err_devmem; + if (!spm_addr_dev0 && !spm_addr_dev1) { + 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; + mdevice->zone_device_type = HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; + } else if (spm_addr_dev0 && spm_addr_dev1) { + devmem->pagemap.range.start = MINOR(mdevice->cdevice.dev) ? + spm_addr_dev0 : + spm_addr_dev1; + devmem->pagemap.range.end = devmem->pagemap.range.start + + DEVMEM_CHUNK_SIZE - 1; + devmem->pagemap.type = MEMORY_DEVICE_PUBLIC; + mdevice->zone_device_type = HMM_DMIRROR_MEMORY_DEVICE_PUBLIC; + } else { + pr_err("Both spm_addr_dev parameters should be set\n"); + } - mdevice->zone_device_type = HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; - 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; @@ -493,10 +515,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,7 +555,8 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, err_release: mutex_unlock(&mdevice->devmem_lock); - release_mem_region(devmem->pagemap.range.start, range_len(&devmem->pagemap.range)); + if (res) + release_mem_region(devmem->pagemap.range.start, range_len(&devmem->pagemap.range)); err_devmem: kfree(devmem); @@ -1097,10 +1124,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) @@ -1113,8 +1138,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 ee88701793d5..00259d994410 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -65,6 +65,7 @@ enum { enum { /* 0 is reserved to catch uninitialized type fields */ HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1, + HMM_DMIRROR_MEMORY_DEVICE_PUBLIC, }; #endif /* _LIB_TEST_HMM_UAPI_H */ From patchwork Mon Sep 13 16:16:02 2021 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: 12489919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27866C433EF for ; Mon, 13 Sep 2021 16:16:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BACE760EE5 for ; Mon, 13 Sep 2021 16:16:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BACE760EE5 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BF4096B0085; Mon, 13 Sep 2021 12:16:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B53686B0087; Mon, 13 Sep 2021 12:16:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E1296B0088; Mon, 13 Sep 2021 12:16:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id 7DEF06B0085 for ; Mon, 13 Sep 2021 12:16:29 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 30E0D181AEF32 for ; Mon, 13 Sep 2021 16:16:29 +0000 (UTC) X-FDA: 78583052898.11.6D6D0D1 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2078.outbound.protection.outlook.com [40.107.94.78]) by imf06.hostedemail.com (Postfix) with ESMTP id AC29F801A89F for ; Mon, 13 Sep 2021 16:16:28 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T+aSiqO4FkJXu9XP+Iiw5SmtZkSgEpGPQjV1dNzrohWffpWdaxKTRpAR1//UUK5n4IcSuWqJDg6sxabkGCjXw2E39679RBykmuxvE4pgZEZq6NuTQBRQZnQl5BhbjqQWxO9Q3OzZIzXfIUJqwe+UrNlGDwT+hY78l7MLbTp0j8JD0oRhS50yF1JtSGfKy4jQyflx1P+0RiaD4d4whnrhzSsXtOFG0RSE+z1mHBSb3Nh13GY3kR/N6ZQuLqM3WJbIqIZIExkaQjZGhIfq6O6sG4y/bot4Cc1h9jWwlKS3WLhy36Z2Vzr2Wm5TUbxBnpCyE7kWtIa8YLpav9zb0cMqsQ== 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; bh=leJttb/LFh2M/wzwUmywQ7bX9zYZjJvBAUyOE4AeRxA=; b=UGFSojk5QxzkXgucMAWWP8YBoQVIcuz7rnpBtkG3D46jVuHe8Lgkn+tVuO7LvKqu0NF9ZqvD24pQCpW9I1k4xIjmou0hVb/d+MR7FCmcoW0I1VDFbiaoNCdsEtixHnk9KZ9RYON+HEJJliaiHK5dXkz3Zn/S1g80MeEnfCZBDNzZWMKLZrfC/TNqo8Tm9lQ+g5b2/mqYG0qlNlcyPbLCZzccbhtDwbcuBOaTeHW6BjixfzJ7LTkr2Z9yoi6sqc8nNOgX81ReePzNeUQm/4SvU3uce/yisHiDzWd1WfIBH1Q3fQq+YeP2ODYS4YXZoXltTyAuI8r/M5Ac91pCahq4PA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=leJttb/LFh2M/wzwUmywQ7bX9zYZjJvBAUyOE4AeRxA=; b=kFruh0RMEebHvQ3VZr7j+Oh7fbW98q0e7E+6JwgrW32uCnlO93MFOiGBQgM/Lq9SCaJncjalcRT3xUB7hvHMoscCzdXlsIWZVAG5Od5Y41+qQu7aT6Ug7IIom51gBW/qg5/uvKMEz4neVBEli+5qdqY2FtbPoPh2QvD4ZUCDhIg= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SN6PR12MB2719.namprd12.prod.outlook.com (2603:10b6:805:6c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Mon, 13 Sep 2021 16:16:26 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:26 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 10/12] lib: add support for device public type in test_hmm Date: Mon, 13 Sep 2021 11:16:02 -0500 Message-Id: <20210913161604.31981-11-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f12efe75-001d-4a5b-b878-08d976d1d5cd X-MS-TrafficTypeDiagnostic: SN6PR12MB2719: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pTgQ5l/NOhik3UqQFbw/dM1/2OvedBQTuTrlcp7NU8JarKpKc2ZWWWNCXGDRSFStVnD0LmE0RmWnWjH1ngNgxWDadTOpQ01Con/yegHlzzHpFArduhHSuPa+mWE/NJBgODwMeM9Bf23XufgeMRt2pnTBFKEjLdh9zoaijqHPQ9CUp69FMf8xUugjz0URsULKlEkb967Myx6IDNdkTTQXJw02h/RCiWDz5ZmHfftzpEv5fQaK4K1ZuqTX1uodQawPZF2kZOUtHhBEcN400c8FzHDUNrMtjiO4BLCIyaMytDkrxBGZUwQU2A6pYbfurPNhnz8cp9yuk3LXvoLYsz4+GM8uPF0rdE5wqDxr+AaYkiuuT4IDBlsVC9IJkxNnLe9JXa+0vcrUAvuHAdv228Uy+EdxxUqSqmqht9/TcSmLqGSZALuBCRecAjg5vy+dLaFWYzuV2moGIg9ZSwK4iroz142ehaPEkJoQIITOYi7CSedMvpGVBbSktixcrx+OGqQwmEvvwIgOuuKMV0u0Xt62GjoydcfvCLSy0SiCqMCGzhITYdb8mXIIlm1tmpY57oByoxnENwoBPS75nm/At504lS1CLDpY32L2P/wuaiQLWfu1f2dVhVtvhFcR3wx6z8aoxdhQ8KpT3OPD7/WpWiyYHZMVVxz45kCr7Hm8TBJi4D3bupG/JDovdLaKOOBdwJK1Tp/zIKILHGoN3wAS13inGQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(366004)(136003)(346002)(376002)(39860400002)(30864003)(6486002)(316002)(4326008)(956004)(2616005)(2906002)(66946007)(5660300002)(7416002)(1076003)(52116002)(26005)(7696005)(186003)(478600001)(38100700002)(6666004)(38350700002)(36756003)(44832011)(8936002)(66476007)(8676002)(66556008)(83380400001)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FbjCKcXzrIroX9/4tvj9ZReZatnpI+OtZlbxoD9Cj2nYoPvxRT47KkoXnkRtAVWKHMq0VKmrOxKtIULdyAKJle5mJx/ZoqIM1UXT5S2aVx42fsrY1zVG9eV/HrKdTHuSPfRiOew/XnrXs+UdoJhRtRepkTG0mWSlx/XtCzxG3EtDJSgcI4is/ru4CsmdJJEmZRVIMbl4NfMq+Yy45Q1jDU+YHWnUNzjDRYN/CMSNvSBzQ3zMonaY1c4KeBj4dXlZaGxmwVPLgJLVpAr3uOYmL49SR7VHLcqFOuix4vj9Hn0mq5J+qm0vnW22flTBgKtH3UxzD82FjdT+D3W3w3TQz/m/wo15DGKjzI65v00p2qeCbne5K2KkqeYqzPNzbK5yFkeBBkTL7imFViOntkKY+2j+syFfZ/ysgtYzYtUk1jGTUW1PsmBexipRPEtlnOkfnDOVLpBge2ejxP9nJyW28Mvyo41B+JP7Yyp3erDGIFRc0vgInTuExqadamZEv1u4q1Vx4/XlyKmHU14r0bw4hcS4Od8MG8byAHcQ+svUGK/O0/zJ4r9HkISYUeI7DkxSuhV2viOHwRntDKHBsaRwFlEszZQ8V9L4HYbBh9vUVAXqiYGd4MUitJA3XtJgRzbk74MpdZ2ospzP6YDmBsmoTYwTl0+zliyOXJ/hAB29wqIwu3fwedA/iEcu/h5F7ycII7UeFSwWyjHwO7VOFzhN0+bty57TcP6Ku4feSFX7XC6zOGpR++fyZtkjwjVOUNdIguXZQpg6dDR/wjrirgWSxX7CJkVwBBAqq2ueSgjgMK16B6XuAvsYB1npwoFTmKiawD7B8Fa+/EZiC0v+HD35JcBmY3FLkBdbiQZ9c0hlMrsJxWNppQX8c2S2f5ladklefqA12CjwLvLZqTgPhvDLMsvrpUs4klCAhMrSmQgbUxb/hDAgW9q7yJ5UatfS/UwyNTHMRs9nKRe62V9VKeVilbjW6Ry12m19ptMNMf+Hs909guMKmTSXSC8IgzkEHvRKAAdIaLiRyLmSy8j2vAU8GWqES5x3w1IQZUahTaQhET6rFcVh1M6HalUu3RuFCg+UATQg9QImUfbC4SUhmmgHfzq1vI/bXSv2kSWo8VQxNOuFcvufOJ+IpeFU5hpgW8ip6Vp1NFcmOLxrJSoIetQyfxgD/QC93wSG/TUr7FfOODv3LwWplwrHWIWrSy1urwSkJMrraVkL1MLOmJ304rns2+kSJUEHbBx+dTlMtDOR9JD0fmgSjOEtrCbJiB/AIx3Yi0j1WhIZNEqcJ5yBUDwLpmJvOuY5uXAN6oZGT0A9Wps51J/dIBrMaKXqnDk5c67F X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f12efe75-001d-4a5b-b878-08d976d1d5cd X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:25.8609 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TRyimG5ejx3XyLqu0a/k+XfU8+dBDKf9H/fUHyNA8BQjkYl6NnCLQ3PA7fvYI5rHmiH1nJxEzbkcQiJdB+RfVQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2719 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: AC29F801A89F X-Stat-Signature: gejrnwrxek1ug4jjqu8ekhni7ncdgmhq Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=kFruh0RM; spf=pass (imf06.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.78 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1631549788-621954 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 Public 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 Signed-off-by: Alex Sierra --- lib/test_hmm.c | 166 +++++++++++++++++++++++++++----------------- lib/test_hmm_uapi.h | 10 ++- 2 files changed, 113 insertions(+), 63 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index ef27e355738a..e346a48e2509 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -469,6 +469,7 @@ static int dmirror_allocate_chunk(struct dmirror_device *mdevice, unsigned long pfn_first; unsigned long pfn_last; void *ptr; + int ret = -ENOMEM; devmem = kzalloc(sizeof(*devmem), GFP_KERNEL); if (!devmem) @@ -551,7 +552,7 @@ static int dmirror_allocate_chunk(struct dmirror_device *mdevice, } spin_unlock(&mdevice->lock); - return true; + return 0; err_release: mutex_unlock(&mdevice->devmem_lock); @@ -560,7 +561,7 @@ static int dmirror_allocate_chunk(struct dmirror_device *mdevice, err_devmem: kfree(devmem); - return false; + return ret; } static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) @@ -569,8 +570,10 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) struct page *rpage; /* - * This is a fake device so we alloc real system memory to store - * our device memory. + * For ZONE_DEVICE private type, this is a fake device so we alloc real + * system memory to store our device memory. + * For ZONE_DEVICE public type we use the actual dpage to store the data + * and ignore rpage. */ rpage = alloc_page(GFP_HIGHUSER); if (!rpage) @@ -603,7 +606,7 @@ static void dmirror_migrate_alloc_and_copy(struct migrate_vma *args, struct dmirror *dmirror) { struct dmirror_device *mdevice = dmirror->mdevice; - const unsigned long *src = args->src; + unsigned long *src = args->src; unsigned long *dst = args->dst; unsigned long addr; @@ -621,12 +624,18 @@ 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 (spage && is_zone_device_page(spage)) { + pr_debug("page already in device spage pfn: 0x%lx\n", + page_to_pfn(spage)); + *src &= ~MIGRATE_PFN_MIGRATE; + continue; + } dpage = dmirror_devmem_alloc_page(mdevice); if (!dpage) continue; - rpage = dpage->zone_device_data; + rpage = is_device_private_page(dpage) ? dpage->zone_device_data : + dpage; if (spage) copy_highpage(rpage, spage); else @@ -638,8 +647,10 @@ static void dmirror_migrate_alloc_and_copy(struct migrate_vma *args, * the simulated device memory and that page holds the pointer * to the mirror. */ + rpage = dpage->zone_device_data; rpage->zone_device_data = dmirror; - + pr_debug("migrating from sys to dev pfn src: 0x%lx pfn dst: 0x%lx\n", + page_to_pfn(spage), page_to_pfn(dpage)); *dst = migrate_pfn(page_to_pfn(dpage)) | MIGRATE_PFN_LOCKED; if ((*src & MIGRATE_PFN_WRITE) || @@ -673,10 +684,13 @@ static int dmirror_migrate_finalize_and_map(struct migrate_vma *args, continue; /* - * Store the page that holds the data so the page table - * doesn't have to deal with ZONE_DEVICE private pages. + * For ZONE_DEVICE private pages we store the page that + * holds the data so the page table doesn't have to deal it. + * For ZONE_DEVICE public pages we store the actual page, since + * the CPU has coherent access to the page. */ - entry = dpage->zone_device_data; + entry = is_device_private_page(dpage) ? dpage->zone_device_data : + dpage; if (*dst & MIGRATE_PFN_WRITE) entry = xa_tag_pointer(entry, DPT_XA_TAG_WRITE); entry = xa_store(&dmirror->pt, pfn, entry, GFP_ATOMIC); @@ -690,6 +704,47 @@ static int dmirror_migrate_finalize_and_map(struct migrate_vma *args, return 0; } +static vm_fault_t dmirror_devmem_fault_alloc_and_copy(struct migrate_vma *args, + struct dmirror *dmirror) +{ + 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 (is_device_private_page(spage)) { + spage = spage->zone_device_data; + } else { + pr_debug("page already in system or SPM spage pfn: 0x%lx\n", + page_to_pfn(spage)); + *src &= ~MIGRATE_PFN_MIGRATE; + continue; + } + dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr); + if (!dpage) + continue; + pr_debug("migrating from dev to sys pfn src: 0x%lx pfn dst: 0x%lx\n", + page_to_pfn(spage), page_to_pfn(dpage)); + + lock_page(dpage); + xa_erase(&dmirror->pt, addr >> PAGE_SHIFT); + copy_highpage(dpage, spage); + *dst = migrate_pfn(page_to_pfn(dpage)) | MIGRATE_PFN_LOCKED; + if (*src & MIGRATE_PFN_WRITE) + *dst |= MIGRATE_PFN_WRITE; + } + return 0; +} + + static int dmirror_migrate(struct dmirror *dmirror, struct hmm_dmirror_cmd *cmd) { @@ -731,33 +786,46 @@ static int dmirror_migrate(struct dmirror *dmirror, args.start = addr; args.end = next; args.pgmap_owner = dmirror->mdevice; - args.flags = MIGRATE_VMA_SELECT_SYSTEM; + args.flags = (!cmd->alloc_to_devmem && + dmirror->mdevice->zone_device_type == + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE) ? + MIGRATE_VMA_SELECT_DEVICE_PRIVATE : + MIGRATE_VMA_SELECT_SYSTEM; ret = migrate_vma_setup(&args); if (ret) goto out; - dmirror_migrate_alloc_and_copy(&args, dmirror); + if (cmd->alloc_to_devmem) { + pr_debug("Migrating from sys mem to device mem\n"); + dmirror_migrate_alloc_and_copy(&args, dmirror); + } else { + pr_debug("Migrating from device mem to sys mem\n"); + dmirror_devmem_fault_alloc_and_copy(&args, dmirror); + } migrate_vma_pages(&args); - dmirror_migrate_finalize_and_map(&args, dmirror); + if (cmd->alloc_to_devmem) + dmirror_migrate_finalize_and_map(&args, dmirror); migrate_vma_finalize(&args); } mmap_read_unlock(mm); mmput(mm); - /* Return the migrated data for verification. */ - ret = dmirror_bounce_init(&bounce, start, size); - if (ret) - return ret; - mutex_lock(&dmirror->mutex); - ret = dmirror_do_read(dmirror, start, end, &bounce); - mutex_unlock(&dmirror->mutex); - if (ret == 0) { - if (copy_to_user(u64_to_user_ptr(cmd->ptr), bounce.ptr, - bounce.size)) - ret = -EFAULT; + /* Return the migrated data for verification. only for pages in device zone */ + if (cmd->alloc_to_devmem) { + ret = dmirror_bounce_init(&bounce, start, size); + if (ret) + return ret; + mutex_lock(&dmirror->mutex); + ret = dmirror_do_read(dmirror, start, end, &bounce); + mutex_unlock(&dmirror->mutex); + if (ret == 0) { + if (copy_to_user(u64_to_user_ptr(cmd->ptr), bounce.ptr, + bounce.size)) + ret = -EFAULT; + } + cmd->cpages = bounce.cpages; + dmirror_bounce_fini(&bounce); } - cmd->cpages = bounce.cpages; - dmirror_bounce_fini(&bounce); return ret; out: @@ -781,9 +849,15 @@ static void dmirror_mkentry(struct dmirror *dmirror, struct hmm_range *range, } page = hmm_pfn_to_page(entry); - if (is_device_private_page(page)) { - /* Is the page migrated to this device or some other? */ - if (dmirror->mdevice == dmirror_page_to_device(page)) + if (is_device_page(page)) { + /* Is page ZONE_DEVICE public? */ + if (!is_device_private_page(page)) + *perm = HMM_DMIRROR_PROT_DEV_PUBLIC; + /* + * Is page ZONE_DEVICE private migrated to + * this device or some other? + */ + else if (dmirror->mdevice == dmirror_page_to_device(page)) *perm = HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL; else *perm = HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE; @@ -1030,38 +1104,6 @@ static void dmirror_devmem_free(struct page *page) spin_unlock(&mdevice->lock); } -static vm_fault_t dmirror_devmem_fault_alloc_and_copy(struct migrate_vma *args, - struct dmirror *dmirror) -{ - const unsigned long *src = args->src; - unsigned long *dst = args->dst; - unsigned long start = args->start; - unsigned long end = args->end; - unsigned long addr; - - for (addr = start; addr < end; addr += PAGE_SIZE, - src++, dst++) { - struct page *dpage, *spage; - - spage = migrate_pfn_to_page(*src); - if (!spage || !(*src & MIGRATE_PFN_MIGRATE)) - continue; - spage = spage->zone_device_data; - - dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr); - if (!dpage) - continue; - - lock_page(dpage); - xa_erase(&dmirror->pt, addr >> PAGE_SHIFT); - copy_highpage(dpage, spage); - *dst = migrate_pfn(page_to_pfn(dpage)) | MIGRATE_PFN_LOCKED; - if (*src & MIGRATE_PFN_WRITE) - *dst |= MIGRATE_PFN_WRITE; - } - return 0; -} - static vm_fault_t dmirror_devmem_fault(struct vm_fault *vmf) { struct migrate_vma args; diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index 00259d994410..b6cb8a7d2470 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -17,8 +17,12 @@ * @addr: (in) user address the device will read/write * @ptr: (in) user address where device data is copied to/from * @npages: (in) number of pages to read/write + * @alloc_to_devmem: (in) desired allocation destination during migration. + * True if allocation is to device memory. + * False if allocation is to system memory. * @cpages: (out) number of pages copied * @faults: (out) number of device page faults seen + * @zone_device_type: (out) zone device memory type */ struct hmm_dmirror_cmd { __u64 addr; @@ -26,7 +30,8 @@ struct hmm_dmirror_cmd { __u64 npages; __u64 cpages; __u64 faults; - __u64 zone_device_type; + __u32 zone_device_type; + __u32 alloc_to_devmem; }; /* Expose the address space of the calling process through hmm device file */ @@ -49,6 +54,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_PUBLIC: Migrate device public page on the device + * the ioctl() is made */ enum { HMM_DMIRROR_PROT_ERROR = 0xFF, @@ -60,6 +67,7 @@ enum { HMM_DMIRROR_PROT_ZERO = 0x10, HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL = 0x20, HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE = 0x30, + HMM_DMIRROR_PROT_DEV_PUBLIC = 0x40, }; enum { From patchwork Mon Sep 13 16:16:03 2021 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: 12489921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C739BC433F5 for ; Mon, 13 Sep 2021 16:16:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 676A360F58 for ; Mon, 13 Sep 2021 16:16:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 676A360F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5D6766B0087; Mon, 13 Sep 2021 12:16:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 55D336B0089; Mon, 13 Sep 2021 12:16:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D7D8900002; Mon, 13 Sep 2021 12:16:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0002.hostedemail.com [216.40.44.2]) by kanga.kvack.org (Postfix) with ESMTP id 3104B6B0087 for ; Mon, 13 Sep 2021 12:16:30 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DD43E82499A8 for ; Mon, 13 Sep 2021 16:16:29 +0000 (UTC) X-FDA: 78583052898.05.0D75A9A Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2078.outbound.protection.outlook.com [40.107.94.78]) by imf06.hostedemail.com (Postfix) with ESMTP id 45066801A89F for ; Mon, 13 Sep 2021 16:16:29 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZHTbXJ4JulT234LhU1+9886O4xzrCgcjjVKgmqJlDTaWVRJ/e950xe3CkjRlNKMI0XGjv+1sBl7cFpgjWU+DRkOugxMzwKvh6IKr+G0c0bEsJtQYng9Se0KO/GTl6Hk5XIkRPSKh7mnjIkZ3wvfZuUIi6QNK5st843EKQgFOwkr7/TdcuDC9nXeM5cpnU31UmY6DMeRcGbq4ni0cheBV5iTxEFPkZJJU+AjHvEfrOsV930Bb7xRmSN5GcaFvuPw5N4vX7XGXL7dx5+To6HKk8/jB1UactNFctlI1WFM+Amjv3KSLEtRP+i4SivlS8qBPu63zH9wx5FBtR6KSrQw4jA== 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; bh=PfsDeDPTrxHJIIQdDj4G6ondzbiB2t/+YrLe1QVCDLk=; b=dLkhaPn4myDbeesEXEO33EkXY1jKSSYrEI3odXwH/mHUL19by+kaESWapvStpplR2q+IHqc1oIhLmuD9TkUUe8mvsBNwm+z4eGyVTmgA2KuJJE7yL3B4Rfroqa8zMQx3g8Erj08VWraCuyDJJWTiWerU1tEQ0ZkoAtTzGKl8xnmZkws+6QYyGb8Y6IcFPcepcK/+sLvx7hCM1jiMT0AlY6E4+HkN/+zPf3dlrEfAz39vvaIj+yMR9mcc+GlvatwQ8JK3rRB60VjcBFdYfK9CoDDNbhQvA038Ze5M69YuS9GVNEqwVeja/vNODiBd5bpSv+QMgxqFcFcXdJYnVTXOpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=PfsDeDPTrxHJIIQdDj4G6ondzbiB2t/+YrLe1QVCDLk=; b=lkxx6opVnZEE5WuMfgesy3UO/c2579fQ6haZE1YYOspviu6GDgJmi1b2VDnSbXby4C0tUZRxz1Mdp+T3bQhQFin7z4HGiUnDjnOO6bFMN4P/+4p1CUTiTOqQNRh7u77BZ3MN4OwV/yKYTXf1T8roOaN0eGoEhFqQE/sESgjLxL4= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SN6PR12MB2719.namprd12.prod.outlook.com (2603:10b6:805:6c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Mon, 13 Sep 2021 16:16:26 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:26 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 11/12] tools: update hmm-test to support device public type Date: Mon, 13 Sep 2021 11:16:03 -0500 Message-Id: <20210913161604.31981-12-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a76e47c2-edb9-4444-1de2-08d976d1d640 X-MS-TrafficTypeDiagnostic: SN6PR12MB2719: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IfO4c1ql0+faGjsdCrN59AHW4/AjlrR+dQRNAQ0q1x1RD8PvtcKv8kEBRdorvlgNZfjxVnf3vq4r4feuKcJESCN9eyvzrMeP9JVjV+nnJtY7qTXzcM6g3/5Sdsx6M/z31rrAglbhTi7abatbcDXXZHqpccSJzT8UJq1mZl/TdRAnqdnKhE8A9GX7gryn2O3DrIyUUO1vu+GFPaSb8/HVWsjYml43ROCz/8dHGbSszjaIEhrt2pMPfcB0ve+jQTE8sxHC/wet5a+G8XGrSlhl0eaUroxD+nsAIkXsFBQ7lo6hAbVDzwxw/68BCgRPZQbX5Odk7Vpps+84P+zUb6s/KXBBP4hDyK6eH0KoneR3NIjZnMlx2SpgVyoMnm2hxgroM6b7Gzs3owRbSsnl2CEJ7gLasahkLySTbJOqFPFn3+jY4ZfSWIfqp0B7BE0U/0jeB//RzMHBkot9kAq+ZioPzl/+yXsVT5fPmECrBpv3IM2PwOXDZsYznpZUY/lQcDnjprO2C4sPU/JMKnn3zmdm3qK9n8aNsXEkydRm7ks4c8ucS0MBWxuWlJTbXv3iQQwqMk8y30PYfez7tgMUgteXHhXHlJt3OSwKe30OTmVUL5lo3WIobfLWQyi6Y+IF7YJWsijI584iFkcihbHPCU72GEwgjx9NhVvXQpX1vjmlWg+3Gk0aQ+dCWOt5DepqsatxuiK2z89JvJ9RH4RKXe9PIg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(366004)(136003)(346002)(376002)(39860400002)(6486002)(316002)(4326008)(956004)(2616005)(2906002)(66946007)(5660300002)(7416002)(1076003)(15650500001)(52116002)(26005)(7696005)(186003)(478600001)(38100700002)(6666004)(38350700002)(36756003)(44832011)(8936002)(66476007)(8676002)(66556008)(83380400001)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8XawayjXBuoKp4OMg0R/tczJNlmrRSnclJcClXyWoOJikJSYFbjJhP/YaCEdxxf9Oiw2l8au11TV5wpitNMZFJAAB1rf+tyHkxz97/OfQgy6Z/zsTw0L/+daZJD7Ae6eCNJHASt37n2PjQdwq2yb6RvDOBi+xbXkbNvT/zRMgOkSl0JVb0HK3kIqgPg+177e4x0xxDHXX3NiAXvaNB3S0xHbkS4JQD0O09jbiR7v/quhtwNHRVKyEW2WcSF6m2pmE0n6jeGEgcOHhC9kGWSSwRZG83X4hxI1RLbOTczdUglaek9hZ+3RvkeItaSgf2USJuX4+frALyGUKI+bA0Z4XP6nuxIdPfLoRI67UgtNdQNdvfYdP27Balf5zaeMr2LIrJ3oVOdskZMMq/lCYp/tqKJ8Yrp4RGMx8fgRYXbF6Uy1d8IaoTJ2O+G0iRCCkHlzwyg/aWavUUyW3tW4OUYQ31uQFkqJZDkjlgmgTlrrnKLNTrdkkedWoOcLkdwYPscgZCdBVCBhRUWNTEZTuHSXVdR7I7czzQPTIojm0A5A7ziFh3TqePbMuOwsdVg/8XHOenH364x3T8Rp0s0jX6RWwMa9WFTeMqSoR6aGLtHSMt1c7yb+OWT6ZBQpASdWfkCewGnhhm1NBGfoVlOUW8DMBuaMssr7rMGqBKcDW3nWmYNQhi2uxhE+GKW0nmrRIvUwqc2+K6JSCQ02z0o7PZQKLFPqAr+Y7eEQGChz4cZmYBrtgsU3AmGLhzBiX+Tvo8Lvzg1D9N9u+7G4XVjsoLru+ODT/LgzP3qvO9SWx0oUTGvSNDJ5i8o2p/IiWsKzNV3YMr7gC5Bng8SN43PPUYuNgjh8HKmx9LNLHQORHkuwiEYtGV1Xu1ND0o8w8vmExU2ceVDNw0WS68kj29JJIczJo4nVlcWPKqXMdvfyfnecicqqCCJ5BphsQHYq9IgbwOmp/Vg9XObcTE+N5+SN8myYdRyX47xX8OH7KruhXyyM13Lo5xvNAGjDGNqEFEtgXkBzXL5/my22LiS1zZH63ryKw2bi6+9eNqectxretcQQy5iJc0OQIInWsOF0dngHpcM6e+YeKHkYThNrpwn/6bnaydXOYtBorXufYue9h9HNw2E2f+ZTHSBQb3TdDZhSpYfh77AX7N6bBJ1oJrWdlr4loxlF1BD2MnY3zYHLBYT90LLgSWK/kuAJPhbkiHyT4IGbhrf2Kgqf2ybcZi1q5X4qglp5b+iubmtq+IroMo/NOdCiKzZZphug8XMyUtflVrRsBsUCzY/AaPfvMGXBwDBErajcytEL3P5c/Pg0l15pqUvwJEVS+uGrGVVgGXFGQ7sh X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a76e47c2-edb9-4444-1de2-08d976d1d640 X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:26.6335 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sVL2NAMB0Bqf8pw9GEBo3DoW+6FT6qeT9N7uQYIHKkdJgRjXlayeuayeD3ip7yMa8HId6fmVDFlV1rS5lYmepg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2719 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 45066801A89F X-Stat-Signature: zkphhy6ct4i6un476j6g6cc3rwu9mxtk Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=lkxx6opV; spf=pass (imf06.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.78 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1631549789-287322 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 public 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 public zone types. Helpers to migrate from device to sys memory and vicerversa were also added. Signed-off-by: Alex Sierra --- tools/testing/selftests/vm/hmm-tests.c | 142 +++++++++++++++++++++---- 1 file changed, 124 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 5d1ac691b9f4..477c6283dd1b 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -44,6 +44,8 @@ struct hmm_buffer { int fd; uint64_t cpages; uint64_t faults; + int zone_device_type; + bool alloc_to_devmem; }; #define TWOMEG (1 << 21) @@ -133,6 +135,7 @@ static int hmm_dmirror_cmd(int fd, cmd.addr = (__u64)buffer->ptr; cmd.ptr = (__u64)buffer->mirror; cmd.npages = npages; + cmd.alloc_to_devmem = buffer->alloc_to_devmem; for (;;) { ret = ioctl(fd, request, &cmd); @@ -144,6 +147,7 @@ static int hmm_dmirror_cmd(int fd, } buffer->cpages = cmd.cpages; buffer->faults = cmd.faults; + buffer->zone_device_type = cmd.zone_device_type; return 0; } @@ -211,6 +215,34 @@ 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) +{ + buffer->alloc_to_devmem = true; + return hmm_dmirror_cmd(fd, HMM_DMIRROR_MIGRATE, buffer, npages); +} + +static int hmm_migrate_dev_to_sys(int fd, + struct hmm_buffer *buffer, + unsigned long npages) +{ + buffer->alloc_to_devmem = false; + return hmm_dmirror_cmd(fd, HMM_DMIRROR_MIGRATE, buffer, npages); +} + +static int hmm_is_private_device(int fd, bool *res) +{ + struct hmm_buffer buffer; + int ret; + + buffer.ptr = 0; + ret = hmm_dmirror_cmd(fd, HMM_DMIRROR_GET_MEM_DEV_TYPE, &buffer, 1); + *res = (buffer.zone_device_type == HMM_DMIRROR_MEMORY_DEVICE_PRIVATE); + + return ret; +} + /* * Simple NULL test of device open/close. */ @@ -875,7 +907,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 +955,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 +968,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 +1008,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 +1047,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 +1055,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 +1087,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 +1102,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 public zone configuration, + * the pages from the device should be explicitly migrated back to system memory. + * The reason is Generic device zone has coherent access to CPU, therefore + * it will not generate any page fault. */ TEST_F(hmm, migrate_multiple) { @@ -1082,7 +1118,9 @@ TEST_F(hmm, migrate_multiple) unsigned long c; int *ptr; int ret; + bool is_private; + ASSERT_EQ(hmm_is_private_device(self->fd, &is_private), 0); npages = ALIGN(HMM_BUFFER_SIZE, self->page_size) >> self->page_shift; ASSERT_NE(npages, 0); size = npages << self->page_shift; @@ -1107,8 +1145,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 +1153,12 @@ 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 (!is_private) { + ret = hmm_migrate_dev_to_sys(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + } + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) ASSERT_EQ(ptr[i], i); @@ -1261,10 +1303,12 @@ TEST_F(hmm2, snapshot) unsigned char *m; int ret; int val; + bool is_private; npages = 7; size = npages << self->page_shift; + ASSERT_EQ(hmm_is_private_device(self->fd0, &is_private), 0); buffer = malloc(sizeof(*buffer)); ASSERT_NE(buffer, NULL); @@ -1312,13 +1356,13 @@ TEST_F(hmm2, snapshot) /* Page 5 will be migrated to device 0. */ buffer->ptr = p + 5 * self->page_size; - ret = hmm_dmirror_cmd(self->fd0, HMM_DMIRROR_MIGRATE, buffer, 1); + ret = hmm_migrate_sys_to_dev(self->fd0, buffer, 1); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, 1); /* Page 6 will be migrated to device 1. */ buffer->ptr = p + 6 * self->page_size; - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, 1); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, 1); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, 1); @@ -1335,9 +1379,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 (is_private) { + 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_PUBLIC | + HMM_DMIRROR_PROT_WRITE); + ASSERT_EQ(m[6], HMM_DMIRROR_PROT_DEV_PUBLIC | + HMM_DMIRROR_PROT_WRITE); + } hmm_buffer_free(buffer); } @@ -1485,4 +1536,59 @@ TEST_F(hmm2, double_map) hmm_buffer_free(buffer); } +/* + * Migrate anonymous memory to device memory and migrate back to system memory + * explicitly, without generating a page fault. + */ +TEST_F(hmm, migrate_ping_pong) +{ + struct hmm_buffer *buffer; + unsigned long npages; + unsigned long size; + unsigned long i; + int *ptr; + int ret; + + npages = ALIGN(HMM_BUFFER_SIZE, self->page_size) >> self->page_shift; + ASSERT_NE(npages, 0); + size = npages << self->page_shift; + + buffer = malloc(sizeof(*buffer)); + ASSERT_NE(buffer, NULL); + + buffer->fd = -1; + buffer->size = size; + buffer->mirror = malloc(size); + buffer->alloc_to_devmem = true; + 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); + + /* Migrate memory back to system mem. */ + ret = hmm_migrate_dev_to_sys(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + + /* Check the buffer migrated back to system memory. */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); + + hmm_buffer_free(buffer); +} + TEST_HARNESS_MAIN From patchwork Mon Sep 13 16:16:04 2021 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: 12489923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32557C433EF for ; Mon, 13 Sep 2021 16:16:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D8D8960EE5 for ; Mon, 13 Sep 2021 16:16:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D8D8960EE5 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D783E6B0089; Mon, 13 Sep 2021 12:16:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2600900002; Mon, 13 Sep 2021 12:16:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA00C6B008C; Mon, 13 Sep 2021 12:16:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0209.hostedemail.com [216.40.44.209]) by kanga.kvack.org (Postfix) with ESMTP id AB6C66B0089 for ; Mon, 13 Sep 2021 12:16:30 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6EC25180AD804 for ; Mon, 13 Sep 2021 16:16:30 +0000 (UTC) X-FDA: 78583052940.32.80D62DD Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2078.outbound.protection.outlook.com [40.107.94.78]) by imf06.hostedemail.com (Postfix) with ESMTP id DD620801A89C for ; Mon, 13 Sep 2021 16:16:29 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XcwLs3Fki5+jVWIoy2sVGc4lUbrQ13nAY1rvcSqTdz7DnLY7qdin66pRj4fZfu6CVYaP1ej6B5B/t9Kr1+omqu/o1+K4ZN7ChB/D3v2ic1txB1tvXOGBYXFK++YbGstsG4p4T4uuGszVNvSeSm+Rlo97td03kz+0x0S5JY43O14+RIyscIczuV2q4W8ZMORqkh4iqHm5lYyGkac6ulieNn0VpxflIVZVzLaeYi65kf+LvGYtgzak4TsYZlbS/YZ/IKcJJlTOftC+zNPVM4boZyu8ZpgeX/eUE6GC8edaYmRES7fy0yr1ZiA7qyXa4dg+vNof2YrbCZ0mnNviURAVQA== 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; bh=K/HtW1JAM3zl/llSyGWWwvnXjZ+I+rn1LvUfc29p62Y=; b=KTph9eul9blD/mih2D5nTJ6fAni+JhSOGeLImBXJPAh6HjnY1gxkMDKrQHKpOGU53/TXMAolbXvxoSgno5jMpUQqcO1cA7YOIwhuEPvC749oA6EWVi+GwnAe6ihWZRWjFi2gTgw7cjnVEmc/AlBJKjlfoc7+7/SEptjqKLq8Yjm8HPdY9hkokKfg+RZe16jyKJ/F+45ea8jR4pLjYBBYUfWOu7V669fJOwImooLIpWC8rmoV22fSSaSWS8meuV853qoPVjhV2vVDNRE3gGpGw7RYCFmWNxgcM77GCgPU7cYJBzAG4UMDfFMU1VOAmvZO5NhTXzI0U/6l312lbjLcdQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=K/HtW1JAM3zl/llSyGWWwvnXjZ+I+rn1LvUfc29p62Y=; b=RIPjnlwkg1x+qxqzfHhlVxilo7OrrH4SzR5Pcdy9Z/k/auY3AG5J8Gp/gLkIzYH5oMYEvNUcPat5PYEqYiUtWjK1dYBJ4kfWJaNm+HPJACNjY6AMPSWHicNMrOa7WnHDyILkLjPbhB9VWt7GKNFbGr99n5IFajNRYYClFIbA1k0= Received: from SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) by SN6PR12MB2719.namprd12.prod.outlook.com (2603:10b6:805:6c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Mon, 13 Sep 2021 16:16:27 +0000 Received: from SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14]) by SA0PR12MB4430.namprd12.prod.outlook.com ([fe80::f1aa:9adc:b4f:4d14%7]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 16:16:27 +0000 From: Alex Sierra To: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: [PATCH v2 12/12] tools: update test_hmm script to support SP config Date: Mon, 13 Sep 2021 11:16:04 -0500 Message-Id: <20210913161604.31981-13-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210913161604.31981-1-alex.sierra@amd.com> References: <20210913161604.31981-1-alex.sierra@amd.com> X-ClientProxiedBy: SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) To SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) MIME-Version: 1.0 Received: from alex-MS-7B09.amd.com (165.204.78.1) by SA9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 16:16:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 92d6dd4d-5132-4bd8-dadb-08d976d1d6b5 X-MS-TrafficTypeDiagnostic: SN6PR12MB2719: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qf9MfAWJW1E084ej0zHRenqDPd1/jepm8JXikpXrINYlP4Awlfid68hsf5ozxlrk+ORn+fV+AmLg0Keka/um3lJ43I90uV13IZuKCJj0w/ojc9wuEIhlRY/GnJX78w1bGSqLhu15enk/wmYhl/Sx4UX/gx/vbGNxirDSdcfO1B00lvNyUEhBrQe9+KWCx+pM68WcvXIKR1XR3fucCIVuOfIcOGmDiN1Tc6e9heXDVL3sCU0A4IpImuMvoY/dRBbS5UmfaC0liiLXanGfy72MtGDKJIJ0ar1+3A39dJBmc+B7kzZqBP6NXxV6QSkNS2T23PRqKVLwmJOT2MkmNw4vEvn9cMYdd5Ed1CPOXofdy/lLlTTOw5rHR/Nlr+Eez6aj+GVW6F954srz/tmcNlsU+KSaLHnqHwAlNzLgPsHFbZ5kyZzNDQ0eheAuGS+cO+WiYVK0viHqE9DJFai26oSf/cFvzliUzsAONqOcJx35b3lnY3/hRCnPV7hnsWIYVLg4mclYPSXyHnSS3phjFBPbd9jYcpHuzPawfxj7CVFUJCuAjYQ1Cs0SpxVFb7KR/VqH1gqGvuVMnIC1MsuRby7Ww5rOPkoFI5pF8Yg/7yhE2W7laZ8dBKteggodYctN7re7eF0LjuV+BmNimYnCMhrQajLBoWYmMlSIT9Xx+BM7TwnzEmxVp1VyUvrhPZqWJo6wOJhXyKLxjrHLL9+LsP9JRw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR12MB4430.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(366004)(136003)(346002)(376002)(39860400002)(6486002)(316002)(4326008)(956004)(2616005)(2906002)(66946007)(5660300002)(7416002)(1076003)(52116002)(26005)(7696005)(186003)(478600001)(38100700002)(6666004)(38350700002)(36756003)(44832011)(8936002)(66476007)(8676002)(66556008)(83380400001)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uEa4M/N8bVu5Eb9U5WEUngKpJIawEsSweW1/2QAbH8UWrGKg5B0JD2s8mQ//jRPcEt0BtJG3qglGiwUogMJ3AxkNV5CwV26iP+4cVtZ2U15FH5JYCS8NHqcT23PEOdrEkt5iOqxV4YU1hErMlRkLpRmvm3vL+C7pVKpomXYdzRK9sF/o05oLaO5lpQv7NzS50aeTVe9mPS4QEuHi+T3aSYn/ShDsJnrQ8i1Y/t4UZ4vSc23H3V3PHe7iy4+oMRWXbH+U0W3Z0t1v52PXcpEQTYliNlnqe+03VzJFrcmOYgcdw2JbQxtjOAQKhLtkeT2kE/S1R4dY4IAP056Tqagpms7s3FVQ0GOwW2wU+YlyEE957vK971b6eZTFfKSnojXGkNVzMx00TNB2IhMX0fMDeXaAVuRxAGyUf91/QsqgxdRIAhBErFbr+IbbNs4HAPp/1q931YCgmb10gHrB+h8Zhr5QFNhlNbT0/IA8xiVDrlLs1jgZijtHvdddGcH535hvDkGjhXqXMKmoC5LG/FaFT0zxMD9kJOKdQLU8FKCg/lh0F85oeQe5BT4JHvVr4TBD/3z23o28uYrPUOupIRpdVyyW7VOZ6dx+GZUdO+BGyMboPtjkQqAO8Zs8UME2j4+PUekAElMPbztMAfOyr5JfaYxIleJNx6my8rgBRtDivN/hYO4ERNDJ5yWfv0usykcz8Hp228rpOo+Pap+5lg9L8puxOSj+Uw6cb4aErQ+d2Jl7/q/h3PmLq0+7jlOim3cNZ1552Q5ZwcoJhIfx+UH8X/I8zUnZ4KackmqIYTqmiLSnk9DC8mrB9HRwRQzpmQuXdfkHC8x4GsuNfWwr0ezWcCDWKD1qFCVQrPk2jvvDRdzC5zituyumG6Aur4g4MjzM+pmfbsBICrmQxTc0GS2NmEuTM7v5BaE3A7vSk58pl4aQtXO+7kGpnoCSe02ua5alpj9lJnMOapa80odMLl1aww5N+69EpGxvQpKCY345uz+Wo+IUHuBj1dMmVbhKs+49WDHWg8r48dzVAeEwxG730xIWugyS3Cz9t9hqFIsjzqlfiUjg3DyyTegEY8zgQCKKajp4B63L5R1n+CUoeH+JPp8RpaO9zjhyjxwAltPP8dWO/JxR/Eu0MPUlOOfhySo8poACOv4TFp8/8vwIJm1zieP0QpRCC2422wTzluDg+nq2w8D8n4IlYyugrnS4Knpc0Z5mPbgQ2U8plHYIHJwnwml+eDJidoDUyfKw2PP2nSMtCl+0sX9PViLN0OsS6sg0MB52jUdbvFJYgcGIHYNVR9GhJPZ9EpjbxIZ5uip08jrMpRDa6HuWQ3W9KstbFCzR X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 92d6dd4d-5132-4bd8-dadb-08d976d1d6b5 X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB4430.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 16:16:27.3623 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qp3JnAhW1IbwykQpZe7Zlqr7dHr/3WmQBd7zyokC6dRW2nFB1IcAiA9ThBsFgXXKd7DYmHsk6is9vkpOMmQEEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2719 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: DD620801A89C X-Stat-Signature: f1bw4swhpa9zwq67z48jywsz33ba7hb8 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=RIPjnlwk; spf=pass (imf06.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.94.78 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1631549789-673195 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000019, 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 public. Signed-off-by: Alex Sierra --- tools/testing/selftests/vm/test_hmm.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/vm/test_hmm.sh b/tools/testing/selftests/vm/test_hmm.sh index 0647b525a625..3eeabe94399f 100755 --- a/tools/testing/selftests/vm/test_hmm.sh +++ b/tools/testing/selftests/vm/test_hmm.sh @@ -40,7 +40,18 @@ 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 @@ -58,7 +69,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 +86,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 +98,7 @@ function run_test() usage else if [ "$1" = "smoke" ]; then - run_smoke + run_smoke $2 $3 else usage fi