From patchwork Thu Jan 27 03:09:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12726205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82AD8C433EF for ; Thu, 27 Jan 2022 03:10:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C2926B0081; Wed, 26 Jan 2022 22:10:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 945C26B0087; Wed, 26 Jan 2022 22:10:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77ABA6B008A; Wed, 26 Jan 2022 22:10:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0235.hostedemail.com [216.40.44.235]) by kanga.kvack.org (Postfix) with ESMTP id 5AFCB6B0081 for ; Wed, 26 Jan 2022 22:10:10 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 13B69181CA35E for ; Thu, 27 Jan 2022 03:10:10 +0000 (UTC) X-FDA: 79074588180.09.50FF7B9 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2067.outbound.protection.outlook.com [40.107.93.67]) by imf19.hostedemail.com (Postfix) with ESMTP id 857591A0012 for ; Thu, 27 Jan 2022 03:10:09 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nynlwH1XA9LqiU7g0OOqe12uQs7Aego0VvaU6Xz0MbU16Wb4+wtT2PXCUICSpxg20M6AMVXoAmCAKUKWg44t38guzeeZOAa7jQs8KORUW7FI1w317frfpR48ApZMnF6GAOWDcIr+ukcUixaZAVsVq4tijsp5ttm6Wn35wyRyoUsSL/yXW/61otjJ88DuMMGviB16G3F1ptpglMaP/Tu8Rso0POQMjnZ8PXdSUHKUnETRue9eFbKi6HnzXUiguwIRYVzZgZcq5U4lXNyqB1eDYZp4bsX4gtjCRBNY+3cGFLAlEYxtjHOzsarQTFZoXypTjqRFK4kbQOBDxKdU0MJuKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=m+GJAC43XZGR8kqXA3YdgEYPG5jeb3awGMO5dcj4F3k=; b=DolapNPEtroANi1kqq57QtlEC5tVmTGpyRIIREa2wnD50hV+bN6QeIZnRLwm1bYQYGqm3UedgunClIGhmVt5Q06vrtLZBChRP54ucGUVMRc8lQFpUDeK0R3OM5925h5qiNeOnA6FYF4NRg1ep6mTiVvh8aBRKYEGXBWWhxrCv3CdM52KGMRjdPY9LDe88yRW6SfYIDVx2IFopwij3Ugk6V4UnPYbnJKQz+mfM8K2MgfGddtMpf0llFmIAFpdPRss09JQlzpWLN3Cy+QyO2lJ9/Sv4ODMVgX8/WETB2cUuMgsefIQJ3zm2uNnQCn2lGDE3+kb22z8LGNu8YNAJeyEJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m+GJAC43XZGR8kqXA3YdgEYPG5jeb3awGMO5dcj4F3k=; b=2YkrTmEDxCu/jhbvgBIloV+NPyunTnqSQudYRFnuUn23J/0Buo23zHXjg5iizAtD18RUDxBBOppaJMRCoDCsz39Fwigp8DOF2OK75k+NOT9XRvJmIhcnBvQv0RthO34S35pqew5tJjiXHR2qTjTtJdByHOvzyahStmqSfQwbiuw= Received: from BN0PR03CA0038.namprd03.prod.outlook.com (2603:10b6:408:e7::13) by DM5PR12MB1531.namprd12.prod.outlook.com (2603:10b6:4:f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Thu, 27 Jan 2022 03:10:07 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e7:cafe::dd) by BN0PR03CA0038.outlook.office365.com (2603:10b6:408:e7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Thu, 27 Jan 2022 03:10:07 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Wed, 26 Jan 2022 21:10:03 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v4 07/10] lib: test_hmm add module param for zone device type Date: Wed, 26 Jan 2022 21:09:46 -0600 Message-ID: <20220127030949.19396-8-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220127030949.19396-1-alex.sierra@amd.com> References: <20220127030949.19396-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 60dbe854-def3-470a-d513-08d9e1428570 X-MS-TrafficTypeDiagnostic: DM5PR12MB1531:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1923; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ItVR9pAn/dYfDhT1LiguA81luVW+KW4IGL1R93qdKhd9oEagOdVXMbMZpAXYrruMc0DYFMwxm+B/uARax96Fc+a3JN8WAs3FFjCtosOuVJHVK0+POPZK1yhxFzPeL3Nz+qOHs2qRIySIiUtJDiUb0D4L0na0DPURe3H8vUMyFoHL5x0Z6TfAlwPPWXgQbLPfk5iGAWGGorNnuFtD4zHQY1/jlgUnun11uVtMHHoWWnMJptQYzxba4dXxq7P19+AvW+zf1lCWivJ+C5XPMIDhqli2L2qVWW3JY7fecipr0je6mVOfUjgzLCChpx9pCW17R6Qt4k54WYvkxfVgke/qswagwg7149LSfl/ZxF9qaHlPYJmobAN92FTQroiH3Q7JXU5yhpantzj1OuiFYOVfxesADgRIQZgeXfgovgPgYAWWh8TwJl7n+om68+KpT2Nr+yDqgXsrbV1dgkUen69Xw0Hj0WkxMEJNC/CISrMLIok7U0aVDAJvZYYQHZC6vHoczJhjYMQfjFS/thyaiZBQeGnJAkujf3uePvf9DOuevcS8SFBOOpBJqL1mtsScGOraE2hUZZS5JY9Rc8izD9/ul5SiqxwIzjCOt4APvzlXMYPhBzdpH7VWtrDEpqD7Lv2TOElM4W6JcROCWLhdiU/owgjCVqkUWkDpcvmBj9/6AbyZo+LFaxpom8OWPYzZqy4RXbaaqhpt+m5/xy93nT5RPNj4WYeCgU1XWAJ9tlRenVXVcwU6zZfnSuNjsMzgSKipgP546mDW9TUKSVk6OHkkV+2AgO0EH+1XJ1jNXJ8kewU= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(40470700004)(36840700001)(86362001)(40460700003)(356005)(8676002)(47076005)(336012)(8936002)(54906003)(508600001)(44832011)(81166007)(426003)(186003)(36756003)(1076003)(26005)(16526019)(4326008)(83380400001)(316002)(36860700001)(6666004)(2906002)(7696005)(110136005)(2616005)(7416002)(70206006)(5660300002)(70586007)(82310400004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2022 03:10:07.1866 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 60dbe854-def3-470a-d513-08d9e1428570 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1531 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 857591A0012 X-Rspam-User: nil Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=2YkrTmED; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf19.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.93.67 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-Stat-Signature: zxjkzeaqcmhj6t9ys1qap7kkc5i8gqha X-HE-Tag: 1643253009-322865 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In order to configure device coherent in test_hmm, two module parameters should be passed, which correspond to the SP start address of each device (2) spm_addr_dev0 & spm_addr_dev1. If no parameters are passed, private device type is configured. Signed-off-by: Alex Sierra Reviewed-by: Alistair Popple --- lib/test_hmm.c | 73 ++++++++++++++++++++++++++++++++------------- lib/test_hmm_uapi.h | 1 + 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index fb1fa7c6fa98..6f068f7c4ee3 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -34,6 +34,16 @@ #define DEVMEM_CHUNK_SIZE (256 * 1024 * 1024U) #define DEVMEM_CHUNKS_RESERVE 16 +static unsigned long spm_addr_dev0; +module_param(spm_addr_dev0, long, 0644); +MODULE_PARM_DESC(spm_addr_dev0, + "Specify start address for SPM (special purpose memory) used for device 0. By setting this Coherent device type will be used. Make sure spm_addr_dev1 is set too. Minimum SPM size should be DEVMEM_CHUNK_SIZE."); + +static unsigned long spm_addr_dev1; +module_param(spm_addr_dev1, long, 0644); +MODULE_PARM_DESC(spm_addr_dev1, + "Specify start address for SPM (special purpose memory) used for device 1. By setting this Coherent device type will be used. Make sure spm_addr_dev0 is set too. Minimum SPM size should be DEVMEM_CHUNK_SIZE."); + static const struct dev_pagemap_ops dmirror_devmem_ops; static const struct mmu_interval_notifier_ops dmirror_min_ops; static dev_t dmirror_dev; @@ -452,28 +462,44 @@ static int dmirror_write(struct dmirror *dmirror, struct hmm_dmirror_cmd *cmd) return ret; } -static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, +static int dmirror_allocate_chunk(struct dmirror_device *mdevice, struct page **ppage) { struct dmirror_chunk *devmem; - struct resource *res; + struct resource *res = NULL; unsigned long pfn; unsigned long pfn_first; unsigned long pfn_last; void *ptr; + int ret = -ENOMEM; devmem = kzalloc(sizeof(*devmem), GFP_KERNEL); if (!devmem) - return false; + return ret; - res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, - "hmm_dmirror"); - if (IS_ERR(res)) + switch (mdevice->zone_device_type) { + case HMM_DMIRROR_MEMORY_DEVICE_PRIVATE: + res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, + "hmm_dmirror"); + if (IS_ERR_OR_NULL(res)) + goto err_devmem; + devmem->pagemap.range.start = res->start; + devmem->pagemap.range.end = res->end; + devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; + break; + case HMM_DMIRROR_MEMORY_DEVICE_COHERENT: + devmem->pagemap.range.start = (MINOR(mdevice->cdevice.dev) - 2) ? + spm_addr_dev0 : + spm_addr_dev1; + devmem->pagemap.range.end = devmem->pagemap.range.start + + DEVMEM_CHUNK_SIZE - 1; + devmem->pagemap.type = MEMORY_DEVICE_COHERENT; + break; + default: + ret = -EINVAL; goto err_devmem; + } - devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; - devmem->pagemap.range.start = res->start; - devmem->pagemap.range.end = res->end; devmem->pagemap.nr_range = 1; devmem->pagemap.ops = &dmirror_devmem_ops; devmem->pagemap.owner = mdevice; @@ -494,10 +520,14 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, mdevice->devmem_capacity = new_capacity; mdevice->devmem_chunks = new_chunks; } - ptr = memremap_pages(&devmem->pagemap, numa_node_id()); - if (IS_ERR(ptr)) + if (IS_ERR_OR_NULL(ptr)) { + if (ptr) + ret = PTR_ERR(ptr); + else + ret = -EFAULT; goto err_release; + } devmem->mdevice = mdevice; pfn_first = devmem->pagemap.range.start >> PAGE_SHIFT; @@ -526,15 +556,17 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, } spin_unlock(&mdevice->lock); - return true; + return 0; err_release: mutex_unlock(&mdevice->devmem_lock); - release_mem_region(devmem->pagemap.range.start, range_len(&devmem->pagemap.range)); + if (res && devmem->pagemap.type == MEMORY_DEVICE_PRIVATE) + release_mem_region(devmem->pagemap.range.start, + range_len(&devmem->pagemap.range)); err_devmem: kfree(devmem); - return false; + return ret; } static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) @@ -559,7 +591,7 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) spin_unlock(&mdevice->lock); } else { spin_unlock(&mdevice->lock); - if (!dmirror_allocate_chunk(mdevice, &dpage)) + if (dmirror_allocate_chunk(mdevice, &dpage)) goto error; } @@ -1219,10 +1251,8 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id) if (ret) return ret; - /* Build a list of free ZONE_DEVICE private struct pages */ - dmirror_allocate_chunk(mdevice, NULL); - - return 0; + /* Build a list of free ZONE_DEVICE struct pages */ + return dmirror_allocate_chunk(mdevice, NULL); } static void dmirror_device_remove(struct dmirror_device *mdevice) @@ -1235,8 +1265,9 @@ static void dmirror_device_remove(struct dmirror_device *mdevice) mdevice->devmem_chunks[i]; memunmap_pages(&devmem->pagemap); - release_mem_region(devmem->pagemap.range.start, - range_len(&devmem->pagemap.range)); + if (devmem->pagemap.type == MEMORY_DEVICE_PRIVATE) + release_mem_region(devmem->pagemap.range.start, + range_len(&devmem->pagemap.range)); kfree(devmem); } kfree(mdevice->devmem_chunks); diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index 17f842f1aa02..625f3690d086 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -68,6 +68,7 @@ enum { enum { /* 0 is reserved to catch uninitialized type fields */ HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1, + HMM_DMIRROR_MEMORY_DEVICE_COHERENT, }; #endif /* _LIB_TEST_HMM_UAPI_H */