From patchwork Mon Dec 6 18:52:47 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: 12659553 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 0EA68C433EF for ; Mon, 6 Dec 2021 18:57:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 161746B0085; Mon, 6 Dec 2021 13:53:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 079A26B0088; Mon, 6 Dec 2021 13:53:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6B0A6B008A; Mon, 6 Dec 2021 13:53:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0028.hostedemail.com [216.40.44.28]) by kanga.kvack.org (Postfix) with ESMTP id BBEB16B0085 for ; Mon, 6 Dec 2021 13:53:19 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8443789578 for ; Mon, 6 Dec 2021 18:53:09 +0000 (UTC) X-FDA: 78888266898.28.1F28FA7 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2053.outbound.protection.outlook.com [40.107.244.53]) by imf20.hostedemail.com (Postfix) with ESMTP id C0CD1D0000A2 for ; Mon, 6 Dec 2021 18:53:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h23JtWPi/aZs8zxztMPZqvt+fVbrYHa9BmGHQasDDts3CLVbcUMhPNSOntcWmY/EcpMgZJ1e+zGOAd0ERCBqFaFMfCbRBmpVroo3N+oYfwdr4ejehdBMqnfF/YO9kfpQiNae9ZI/s3GRKNkKc6F82s/zdI+rW9eZUfitOYDvRq4loDkKMd689oWn40XvQDfYf2EoTvKof7mREHrHnR4IoR9xhmLquCj4Oi6G+tkKOsYhWDEMiYJFzJF1YY1UIaheAadGbygbTXMvmhnCLvljKCBKxjwyBSNhjpLV4nrTs3dbQQgB4wZ49S+NVEQc14hsTnAulN5goKDlra+GCrR+Xw== 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=J1tAAOpYRHdEyMNidRApJJb3IRDrfH0Xu9uLVZ8DSqg=; b=J6ze7v5ZYe2zbLVQcoSx2okl5CUWiXREcIYxgqF8pegI1iNUzwUSy03GkxH+6aukWGpXM1nV4MN1goz5zCtcRgbbCGHk3vwADAOK81IsxfNEXuN2jrlScqB9XMO8LPd+sFd0fDJoQPgWRMJGM+tJZa5an6Kf8hqOhkZg0mL4Ji9psWXUP+QgsJnWpIrAK1U48QIMkPmToVof2oFSLYkYzhp5jS4e6ukL/ilfnDsYrG2cR6IlMeW3cg3QonBzmaITW1QySi/0K5AvsWwtN21mmYzgOSyFsA2hqA79MsAvHFb5ZUJvL3jv/FXz1J1iXKEqHdBpRqJj0++Ts2ZxNfFFPw== 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=J1tAAOpYRHdEyMNidRApJJb3IRDrfH0Xu9uLVZ8DSqg=; b=j0JCPfPdYplmGMdiIagBnF4n9W90cKYCNgTNOqdk2FsApj5w9dITYmgQPfcKnN7uxgeGh566bts//rbWk6H9BAQ8xxHoP38b5P2mS3ZK/vIyqYl7y84wfsJAbFvdvXfuTJ+Qn2XPhBpwXuRiDlIV0FOlm5dplYjrQV+MW/BbFOA= Received: from DM5PR15CA0053.namprd15.prod.outlook.com (2603:10b6:3:ae::15) by MN2PR12MB4584.namprd12.prod.outlook.com (2603:10b6:208:24e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.16; Mon, 6 Dec 2021 18:53:06 +0000 Received: from DM6NAM11FT050.eop-nam11.prod.protection.outlook.com (2603:10b6:3:ae:cafe::f1) by DM5PR15CA0053.outlook.office365.com (2603:10b6:3:ae::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.19 via Frontend Transport; Mon, 6 Dec 2021 18:53:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT050.mail.protection.outlook.com (10.13.173.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4755.13 via Frontend Transport; Mon, 6 Dec 2021 18:53:06 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 6 Dec 2021 12:53:05 -0600 From: Alex Sierra To: , , , , , CC: , , , , , , Subject: [PATCH v2 07/11] lib: test_hmm add module param for zone device type Date: Mon, 6 Dec 2021 12:52:47 -0600 Message-ID: <20211206185251.20646-8-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211206185251.20646-1-alex.sierra@amd.com> References: <20211206185251.20646-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: c87875ce-ef96-42e5-8be3-08d9b8e9a3ce X-MS-TrafficTypeDiagnostic: MN2PR12MB4584: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: xrt5s7yP02k2mWJ8g5JS1QYD/eJAIXdArcV2zfKMQ9fvsPubT6RIEkwbfrRL0wd6UjDgOVxYQEK4xhfGb3WEEY+D+xF+dT1oX1bFSUkTrnrQWlK9X6uJQRnM1JZMh/yKpDJUlfSMOx35DJs+DrGaXuY5C9SEvQLMNA5RjyA9r2v+Fe2qMok3hGJVmz0s9LlrRM22f+GH5GBmcnlrQUyG54bWSwlusgGVRBcWO+GoO3I7CbRQ+XWXhGqW5qeLPdHqyIgR4XzMxpgMLvOZAhkYSdNe4QGBJjC0MeBPBooBXNs3bkxAws9oUQFi8BKI2Vyi8OyFYtMbyzkhoCRr2Vt+fpbhh0sB1HsPp6PrQhC6wRIwMrwE2mZFLsYdqFdQs8kzH8IEiT8CEZgZQS06llpa0yU6huUSp7ZEOCnwg77WQ9FIn12H9WRZsnPeWMQ1O8/Y0rsyZ77G3X5k3jq+bjursARKB7937NwyPi/bNxSdx1hoZzCC0WzQUgTnuJsy19uH5fERjSrrJYZbuS0Yw9a6oDPqOEvDiVa58xq24xzJkWzZxm7Vhe/eSHnCdPGueCazyXn2T/IDNBhdPRfBRZisGpu6rZbYsFaYYxox3WElRuJI8jyg9s+Uen/cWS/Gq9ks54lAVjLDmtLWHWklNbtDQQfg8VycpEMFUSjDXoZC7fpJpfAmrSurlV5cMKHU4iKw7aX/KcGefVVrS/R3ZNl88wowr093rrr+8aiG1X9e1MeuQ8CbHh+ghdp4IbZF2hV6bQJxf61/7EzY952DNYUTQM9sbVP8hGb3vQNpLFxQLTJ8Y6hbraKeRuRNH4diOIyH 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)(36840700001)(40470700001)(54906003)(7696005)(36756003)(40460700001)(36860700001)(6666004)(110136005)(7416002)(5660300002)(82310400004)(86362001)(70586007)(70206006)(26005)(426003)(4326008)(16526019)(186003)(8676002)(44832011)(316002)(81166007)(2906002)(1076003)(83380400001)(336012)(8936002)(47076005)(2616005)(356005)(508600001)(334744004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2021 18:53:06.3967 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c87875ce-ef96-42e5-8be3-08d9b8e9a3ce 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: DM6NAM11FT050.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4584 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C0CD1D0000A2 X-Stat-Signature: q8ennqwzcn8ag6dd5cs5bje3yiozd844 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=j0JCPfPd; spf=pass (imf20.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.244.53 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1638816788-820769 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 --- lib/test_hmm.c | 74 +++++++++++++++++++++++++++++++-------------- lib/test_hmm_uapi.h | 1 + 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 97e48164d56a..9edeff52302e 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"); + +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"); + 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,29 +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; + } - 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; @@ -495,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; @@ -527,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) @@ -560,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; } @@ -1220,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) @@ -1236,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 */