Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3108916ioo; Tue, 24 May 2022 13:18:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/54XBrHn0BwVIl5RnFHhNUsB280KYgnrZ+Q2yLNRpqy6Kl+InwE59qhdnRqdkLIteRhT+ X-Received: by 2002:a05:6a00:168a:b0:4f7:e161:83cd with SMTP id k10-20020a056a00168a00b004f7e16183cdmr30380493pfc.56.1653423487403; Tue, 24 May 2022 13:18:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1653423487; cv=pass; d=google.com; s=arc-20160816; b=UNzqB3iHFvoaUi8bmAKwZNwZQgFBiQmVsVQdwfJyDTn3Eu4X2Og3QeVVO1Za4o8idZ Tx7KByO4wmq1m1R5Jl9HInKCbcmqCDH3kvPcY6ldx8yEJoiU/F3uzuyytB8FqNozFZrn mIKpqhFgWKwm/mSQCllm46Tp0bN8KuBpDjkhkwo5sJL+GU/2l5QJhvgvWS4odY+S6SQf u4SKt+cDkF8Vs/b1pezjcGMa8EAkXhFZYj/wtFwmilm1MXoz/rCotOcuA0MXGNtBB0rR /JVfU0ef9ZM160rYHGxjkuxEgtRDX/EZcKtk2opMl7SXAfY3i0isdx/nZ7DCE5VR22vl jg5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EBC8zbdByiow3Ar7kghS8CNIwlQlMj13Ni6WUh9t/L0=; b=bW80Tgf7n8BuuikPNzAH/0t1/8+mF9s+OuV8W9h3lX+XndLK4aGMAXf1+C4u1JAeqZ gpD9euIBK8IkcrG8KPfPdgLx4qdkp3ddxE/vWTDztVRYngdZ1o1rFaZ2d8jkfFjz0O34 b37evwikq5r8ZZhhJD6+KDm6BiRJke7dQlTFKNbSh2oCLU3zbVxeTjs7M9PVM4GNPskT D9rw/Y4zgW11S56ukcFZFbHA++iXGAb5ngGoecf637CPTjc9oL2BKxg3utz0mj3YX+zz BCZMldFY0xY4dkZk87GObs5rwDkdFwRK+4zvEYlmGNxMVcYlgAPnhYozme0ZoAiBq+Dz 4Vwg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="FMux20/o"; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e15-20020a65678f000000b003f5ccb1a239si14968578pgr.113.2022.05.24.13.17.54; Tue, 24 May 2022 13:18:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="FMux20/o"; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240620AbiEXTH5 (ORCPT + 99 others); Tue, 24 May 2022 15:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240966AbiEXTHf (ORCPT ); Tue, 24 May 2022 15:07:35 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2077.outbound.protection.outlook.com [40.107.243.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C54F938BD0; Tue, 24 May 2022 12:07:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LfEffXtM68fLcX0EqAdEzXTmPJldm97Rc5WYkZh0ZO+NPOlWP5I+WV/rnZD3pKgGLU9/hfeVNS3cuQudueLA1nQUBJQc0RduFhIY2z+QsOvmJEjGtbw7NxHLwtau79ZvVQigyg7IoWNXln6fe9+g4FokcgWD8gPW+lI07JIL3QLAMNgwLoJbA1fJULyYRh9qUx4P/tQS/qSYRZm26MGED6WMsVcpXULLqHkgt9LWiCY/3BgxgPHdMmt1KTfB7lNkMUvccjvf0VkOw9tw3UXV1j0TIxljAGXbl5aBfdw83eqRJaFSiN8ckPHFtksJ9iGGRHQ1LRpfF9ZmLmohkLZXLQ== 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=EBC8zbdByiow3Ar7kghS8CNIwlQlMj13Ni6WUh9t/L0=; b=eu7Zg4SoPxIM7Hdj1AwDsdIysL4EfxcsRHc5S0E07OJlzsfRzfGbCdwR3/+MAwt+clD/MBZco5BUA9eRuNw5LOPmJgRwZAwuqop0ei32XPtrkULJ5GetzyeJeF+hhAjbpb2JtQR6jpXRZ/mrJLrrG+eh3A97sgOcEeoO5Eum3DPeYrZAn2BZw6xqALLMk5ZPEvvWuKAlkm2ypTEzMHGDOaowpEZSLWinenl+9w56kTJCU2cgkmlJJrjFIEbCQnsFa1Jyp3T7vNczDA6GbhuB+/R/H0cbFAwPnb2wKMC3DnGXG++KRtWbP+r0oQEz4dmoJf/tW71pRl3OHp7IUR7fUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EBC8zbdByiow3Ar7kghS8CNIwlQlMj13Ni6WUh9t/L0=; b=FMux20/oti11pTFioDA5muuAYCIhBEGwrOt5lWOF/rA7TCgoloXWKtYV7pkmn+Jsu3zk6IC4E5W+4cQQpbD1BAnDoQFUTe+1L+Bd6IczygEk9Ve3OWugn3kAYT6DApT1XaN5DXuzT1OTMWpwnGPmyFSI33UJpNKAtAqgZtBCVCM= Received: from DM5PR17CA0058.namprd17.prod.outlook.com (2603:10b6:3:13f::20) by MN2PR12MB2879.namprd12.prod.outlook.com (2603:10b6:208:a9::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.17; Tue, 24 May 2022 19:07:26 +0000 Received: from DM6NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:3:13f:cafe::8) by DM5PR17CA0058.outlook.office365.com (2603:10b6:3:13f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Tue, 24 May 2022 19:07:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT016.mail.protection.outlook.com (10.13.173.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5273.14 via Frontend Transport; Tue, 24 May 2022 19:07:26 +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.24; Tue, 24 May 2022 14:07:22 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v3 08/13] lib: test_hmm add module param for zone device type Date: Tue, 24 May 2022 14:06:27 -0500 Message-ID: <20220524190632.3304-9-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220524190632.3304-1-alex.sierra@amd.com> References: <20220524190632.3304-1-alex.sierra@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: 798dd893-ee05-4c71-f567-08da3db8a444 X-MS-TrafficTypeDiagnostic: MN2PR12MB2879:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RTWN7BjWmkVvqxHdXBRbKVJg1sNraz7E2SRDxbgjykDcVKGZZluXVn638X/+sUojYhmiu5K2SXAIb/ymFrvsqd1nLhZdMvPXgGPRNqyMmnO16y952R/xq8LFSeR5t/8fL4bSwrSuuniQkwopAcGY3R/G0cAUXd/H8IDxG1/5VZO+3e+qBmI4fdM8fqXBbVQUPnp/wiSyQEsdDOLBYH5eBO+e6bc7wIS9VaJY1S2yHq8vsg/Q821nursJ7Vb8JoLDo6bRz0twNa18hzblKnCT+SsntPRzABHw3VHUG8Wb1g0uf+vsAozqs1MhYwMwl5vDEHe6m3ialPg+ahZe/mQVjJ/YiaqPQj9DtTVlxemWcOXyl5l6dzLEknHQ2cR9ke7SXRPAtkgCGnLH8WNvI60Ty6Q0Z6n1clfNUzoestFNh8z2mJ5F8YucvcacOJKYS4mAjq4YB3bivMKqisqpZimnD/+cGAobdePK7XriLP35chXBy/m6TENi2rabhdBpxMjwRxRxZpOZjP7917thpN661s7O5MNi4DoUADouu7sUbgsG2VUnPIo/zxS2WPONr5kDd5pp1yMNaYSuJUCMqsnFXJlHaUlL/XK6dsG1xsj+Nvhre5N4LpDfsNZkWpHIQUrCtAANuyhoAemRywFA8nINtSV06sNH1TcjwYb+yl2PH31wMo3azEHqJJVbo+2WIhZf5H81TJrS/FsnJsbyJWS++w== 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:(13230001)(4636009)(36840700001)(46966006)(40470700004)(36860700001)(426003)(336012)(316002)(47076005)(26005)(8676002)(70586007)(1076003)(16526019)(7416002)(2616005)(186003)(36756003)(70206006)(6916009)(54906003)(44832011)(7696005)(81166007)(4326008)(86362001)(8936002)(508600001)(2906002)(356005)(40460700003)(5660300002)(83380400001)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2022 19:07:26.4512 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 798dd893-ee05-4c71-f567-08da3db8a444 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: DM6NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB2879 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In order to configure device coherent in test_hmm, two module parameters should be passed, which correspond to the SP start address of each device (2) spm_addr_dev0 & spm_addr_dev1. If no parameters are passed, private device type is configured. Signed-off-by: Alex Sierra Acked-by: Felix Kuehling Reviewed-by: Alistair Poppple Signed-off-by: Christoph Hellwig --- lib/test_hmm.c | 73 ++++++++++++++++++++++++++++++++------------- lib/test_hmm_uapi.h | 1 + 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 7a27584484ce..15747f70c5bc 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -37,6 +37,16 @@ #define DEVMEM_CHUNK_SIZE (256 * 1024 * 1024U) #define DEVMEM_CHUNKS_RESERVE 16 +static unsigned long spm_addr_dev0; +module_param(spm_addr_dev0, long, 0644); +MODULE_PARM_DESC(spm_addr_dev0, + "Specify start address for SPM (special purpose memory) used for device 0. By setting this Coherent device type will be used. Make sure spm_addr_dev1 is set too. Minimum SPM size should be DEVMEM_CHUNK_SIZE."); + +static unsigned long spm_addr_dev1; +module_param(spm_addr_dev1, long, 0644); +MODULE_PARM_DESC(spm_addr_dev1, + "Specify start address for SPM (special purpose memory) used for device 1. By setting this Coherent device type will be used. Make sure spm_addr_dev0 is set too. Minimum SPM size should be DEVMEM_CHUNK_SIZE."); + static const struct dev_pagemap_ops dmirror_devmem_ops; static const struct mmu_interval_notifier_ops dmirror_min_ops; static dev_t dmirror_dev; @@ -455,28 +465,44 @@ static int dmirror_write(struct dmirror *dmirror, struct hmm_dmirror_cmd *cmd) return ret; } -static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, +static int dmirror_allocate_chunk(struct dmirror_device *mdevice, struct page **ppage) { struct dmirror_chunk *devmem; - struct resource *res; + struct resource *res = NULL; unsigned long pfn; unsigned long pfn_first; unsigned long pfn_last; void *ptr; + int ret = -ENOMEM; devmem = kzalloc(sizeof(*devmem), GFP_KERNEL); if (!devmem) - return false; + return ret; - res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, - "hmm_dmirror"); - if (IS_ERR(res)) + switch (mdevice->zone_device_type) { + case HMM_DMIRROR_MEMORY_DEVICE_PRIVATE: + res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, + "hmm_dmirror"); + if (IS_ERR_OR_NULL(res)) + goto err_devmem; + devmem->pagemap.range.start = res->start; + devmem->pagemap.range.end = res->end; + devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; + break; + case HMM_DMIRROR_MEMORY_DEVICE_COHERENT: + devmem->pagemap.range.start = (MINOR(mdevice->cdevice.dev) - 2) ? + spm_addr_dev0 : + spm_addr_dev1; + devmem->pagemap.range.end = devmem->pagemap.range.start + + DEVMEM_CHUNK_SIZE - 1; + devmem->pagemap.type = MEMORY_DEVICE_COHERENT; + break; + default: + ret = -EINVAL; goto err_devmem; + } - devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; - devmem->pagemap.range.start = res->start; - devmem->pagemap.range.end = res->end; devmem->pagemap.nr_range = 1; devmem->pagemap.ops = &dmirror_devmem_ops; devmem->pagemap.owner = mdevice; @@ -497,10 +523,14 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, mdevice->devmem_capacity = new_capacity; mdevice->devmem_chunks = new_chunks; } - ptr = memremap_pages(&devmem->pagemap, numa_node_id()); - if (IS_ERR(ptr)) + if (IS_ERR_OR_NULL(ptr)) { + if (ptr) + ret = PTR_ERR(ptr); + else + ret = -EFAULT; goto err_release; + } devmem->mdevice = mdevice; pfn_first = devmem->pagemap.range.start >> PAGE_SHIFT; @@ -529,15 +559,17 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, } spin_unlock(&mdevice->lock); - return true; + return 0; err_release: mutex_unlock(&mdevice->devmem_lock); - release_mem_region(devmem->pagemap.range.start, range_len(&devmem->pagemap.range)); + if (res && devmem->pagemap.type == MEMORY_DEVICE_PRIVATE) + release_mem_region(devmem->pagemap.range.start, + range_len(&devmem->pagemap.range)); err_devmem: kfree(devmem); - return false; + return ret; } static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) @@ -562,7 +594,7 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) spin_unlock(&mdevice->lock); } else { spin_unlock(&mdevice->lock); - if (!dmirror_allocate_chunk(mdevice, &dpage)) + if (dmirror_allocate_chunk(mdevice, &dpage)) goto error; } @@ -1244,10 +1276,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) @@ -1260,8 +1290,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 */ -- 2.32.0