Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp537376imw; Fri, 15 Jul 2022 08:08:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vcJ4MfOutt+j6QjqCO2gUd5OL+Q/Xrzf/TQPpwxmNSpbJIN/Y6iNIndXvOUihcpil2XlCj X-Received: by 2002:a17:907:7349:b0:72b:4f05:e17 with SMTP id dq9-20020a170907734900b0072b4f050e17mr14150673ejc.307.1657897696629; Fri, 15 Jul 2022 08:08:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657897696; cv=pass; d=google.com; s=arc-20160816; b=HmjiEoZYI1owLVF3unffECBwWZLfp5egsLf+AAIiGjaGtvfhILqhPkr3LwePh98w5B U6j4lpB0jI1lNXrWxfAOoMOuQooUMGU7g34NMRC5v9mgvMhyZ0/VVY37viQ0dRAEF4fZ kHTO0PgfgOR58taZif+3sCeU3cHMpZArTcHV7yhmwonw4qJrYTMDOoKYUjRk5Q25B+f+ 6xPWbAumK9fqSQQ6uh1IZV5tFqPqvv+DC5+qx0m7ntgAJCuwvSPYRpaIF5yAJVxTJb+i GAZTefEgmUYcBJMnJtxTXJpiSh7R21kJxFzr4eKxGPDeHIz0Shtteiwb1DXQmrimzG7+ 1DXA== 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=0Gq5krbSDZgVmQmlPCe18YVS7UIhP8NZXgBaLYb/5yI=; b=YsAPY+Jo8/Zgfk0mHY92s3n95yYOd09R12zgJWdrCEj/akpPnxpYVsOlkSwr63G7D6 0G5HjFP5QdC4VU1uWyNAxgUtON9DEK/wUCg1pi4ly4bsO5tIFZSFQYbibxFuILBWrASH 44Ykldp7Og5mK83ucDh0KU41Ah5T7WKUVpjFEs0sPUwr9gPco0V/7ZGvx3mIajJBWvBa zp5cgb8pUir28Usx3Kr6BSGC3zcMVVdQ5CrfnT0E9PAwFeaPBmxLiXHwpUPaqw/RjGLs JiFMuoGGGqTL9dM5wcTnayE6oVHj7CTWJX7VSOOmdP+g8P3CkTiMN7DqGoD1U0lypA0s eBQA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=XxrI5wDL; 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 v2-20020a509542000000b00437be5efbf8si6537831eda.358.2022.07.15.08.07.52; Fri, 15 Jul 2022 08:08:16 -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=XxrI5wDL; 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 S234403AbiGOPGX (ORCPT + 99 others); Fri, 15 Jul 2022 11:06:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233519AbiGOPGD (ORCPT ); Fri, 15 Jul 2022 11:06:03 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2078.outbound.protection.outlook.com [40.107.243.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 727AC7D1CF; Fri, 15 Jul 2022 08:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F7Y9C2oB1lTulVjwUnOgLzCJuwLDNPzx/VEHKddhvFICjKnT70HoiKLD8WGa1ZCM73IhSfUUtT1jAe6xcMYPys2K+rblHDwk4qvkvwf+IyVbDV1UbV6kab1mzMQv5gt/bPb8sPMka3KCfJbBUqbY5HEXgAurYdXQJRJNeW5+XDwYONd3NmNP8yGKzyjX0bJLPYEVKBFdibkLgf4xq3oL5CUUQMA3Iw+JUDR43PtzYY6P0r2VQWP7ZBARnQZkchfOZa5eTo6gDbgng4x7qHdZepd/AE4eQ9GPk4pyodVqloqXwUkOJfPF5s4fOK1fiBFMP1oUVBZhbQ37LcdhYsqi/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0Gq5krbSDZgVmQmlPCe18YVS7UIhP8NZXgBaLYb/5yI=; b=mi0PBiJ5XKCqeXeY46poO/Z1lYqnDQSJa6jX9WACpQL9C2MNP+gm12l4fgnkI7I/Vra74V2q979G7fbmpYbtveQZR3UoiKZEv1N5g7n1qmWAhXmGBzitH2AH+8O6iffSlKIThL8t+QjwCApQgmLmj9vOtEf/x9HOMMFqZe0FBG10zPPkTsUAL2/Y7YCTJ15Qi08r3QfCklWL9hv9OiopLFQE5mM9532b9G7AGqsKXOB1cQ7LQAuvMbvxsVvvaYsYsjMkklBCqRYy2yQKTolN3zAUlrcQaeWgrOAw7zyTYhS6nd7nY1UO/vehxqrYYIxFYB/EvSeczyl9c9XRwSUkSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0Gq5krbSDZgVmQmlPCe18YVS7UIhP8NZXgBaLYb/5yI=; b=XxrI5wDLbB87B5uGesHyFKbVWFHWIZMFjR7wcfeKhZ+jadLxKTftJDSI4CU4ZxurlLfTi5QKNXCzWOOIlzvjszi6uX0ehfSF2lpnCJjjKuEPG7BZpHQk0B6TNbyPW9eKro039JnoA4HL0YzvZ5XOP/lpjCRZWimMXSCNJ2zVkh8= Received: from DM6PR07CA0072.namprd07.prod.outlook.com (2603:10b6:5:74::49) by BN8PR12MB3345.namprd12.prod.outlook.com (2603:10b6:408:64::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.12; Fri, 15 Jul 2022 15:05:48 +0000 Received: from DM6NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:5:74:cafe::a1) by DM6PR07CA0072.outlook.office365.com (2603:10b6:5:74::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.22 via Frontend Transport; Fri, 15 Jul 2022 15:05:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT010.mail.protection.outlook.com (10.13.172.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5438.12 via Frontend Transport; Fri, 15 Jul 2022 15:05:48 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Fri, 15 Jul 2022 10:05:44 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v9 09/14] lib: test_hmm add module param for zone device type Date: Fri, 15 Jul 2022 10:05:16 -0500 Message-ID: <20220715150521.18165-10-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220715150521.18165-1-alex.sierra@amd.com> References: <20220715150521.18165-1-alex.sierra@amd.com> MIME-Version: 1.0 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: 1f6cdcd3-8dc6-48f6-ca0d-08da6673802f X-MS-TrafficTypeDiagnostic: BN8PR12MB3345:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qpvLoJN34PB8ff2kwHYBEsY7fzRAdM3RyzerGOqQM5lTM0gIfV/5ecK5lho7fcVOXtE9aswU5krELxocFXJ7Cr0+c8WEQwuCU3UP/WmygvZkXttpuGNmaKiaRUJDXKF/FT8Z3MgnMcT4rOMo8hGYTr0zOo2/zjjgANm+E+Mico9y6G8ExaU7ZGxNbIKx0koX9FMgBwz6FqlOtvz3denl97wCnxoxOuIQ6CEXNhzvYoHnHS6L8u4JeUZTKW4mg6vBZX/o7ZbJ2F0Q9pnGl+evcZJtttVI4vuxD5nzUA0lxbj40j45yPo59RCvOOK6iQGbVoluXLmheiUOrGfiNJzQ0qdGzvtQafI/EGr0pFZ5L4GQUVGxC0/yNkf7DvWXWwISptL7Q+y4Y3vJ1ZqzrxOxolU0uRUIzMGLjRC+FUkpj4pweZoQb80FON+xUkD3DH2aFCcjt2FsfEfvphvHhHH4zHTFknOYKWq5OUFtgOzsnZMemNI5LtdZyfZb9FDTIK440vvXg3x1kMd+qWAsRW6ccrTT0ju84WJLdBKXxnqj3Ch1kI0cRG4Wv7QPnLjoO/AiTV7NAzaTm6hOJheiCwITTYQqiNvZe3PCyqvrKrRtZrJ+O96ApO3ePTdc/36aUdlPhdtNnpWPjhXjGulMutpc5jMpG84WbUCJ9B61rDMpy+SLChuL1nqOSKFuxGMCbS6CeVQWwH716MT5lZ8pIPOYUs2bF/fx+GoyUPRi39RZjmOaQzbOlfgWpv5OohiFX3BxU5VQj7mU/0oGXs6UKUobUtmMq0xnaVC5wUEkPZF9xe4oTl7o78gv/ZM6IyhAfYHDZjlwzUbfmE7izZHOiC8USHwELzNcovYKDGN0afF6IzM= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(396003)(39860400002)(136003)(346002)(376002)(46966006)(36840700001)(40470700004)(81166007)(36860700001)(82740400003)(356005)(36756003)(40480700001)(47076005)(83380400001)(54906003)(6916009)(16526019)(82310400005)(426003)(336012)(186003)(8676002)(2616005)(1076003)(5660300002)(41300700001)(2906002)(70206006)(6666004)(4326008)(70586007)(8936002)(478600001)(26005)(316002)(7696005)(40460700003)(86362001)(7416002)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2022 15:05:48.3140 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1f6cdcd3-8dc6-48f6-ca0d-08da6673802f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3345 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 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 915ef6b5b0d4..afb30af9f3ff 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -37,6 +37,16 @@ #define DEVMEM_CHUNK_SIZE (256 * 1024 * 1024U) #define DEVMEM_CHUNKS_RESERVE 16 +static unsigned long spm_addr_dev0; +module_param(spm_addr_dev0, long, 0644); +MODULE_PARM_DESC(spm_addr_dev0, + "Specify start address for SPM (special purpose memory) used for device 0. By setting this Coherent device type will be used. Make sure spm_addr_dev1 is set too. Minimum SPM size should be DEVMEM_CHUNK_SIZE."); + +static unsigned long spm_addr_dev1; +module_param(spm_addr_dev1, long, 0644); +MODULE_PARM_DESC(spm_addr_dev1, + "Specify start address for SPM (special purpose memory) used for device 1. By setting this Coherent device type will be used. Make sure spm_addr_dev0 is set too. Minimum SPM size should be DEVMEM_CHUNK_SIZE."); + static const struct dev_pagemap_ops dmirror_devmem_ops; static const struct mmu_interval_notifier_ops dmirror_min_ops; static dev_t dmirror_dev; @@ -455,28 +465,44 @@ static int dmirror_write(struct dmirror *dmirror, struct hmm_dmirror_cmd *cmd) return ret; } -static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, +static int dmirror_allocate_chunk(struct dmirror_device *mdevice, struct page **ppage) { struct dmirror_chunk *devmem; - struct resource *res; + struct resource *res = NULL; unsigned long pfn; unsigned long pfn_first; unsigned long pfn_last; void *ptr; + int ret = -ENOMEM; devmem = kzalloc(sizeof(*devmem), GFP_KERNEL); if (!devmem) - return false; + return ret; - res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, - "hmm_dmirror"); - if (IS_ERR(res)) + switch (mdevice->zone_device_type) { + case HMM_DMIRROR_MEMORY_DEVICE_PRIVATE: + res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, + "hmm_dmirror"); + if (IS_ERR_OR_NULL(res)) + goto err_devmem; + devmem->pagemap.range.start = res->start; + devmem->pagemap.range.end = res->end; + devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; + break; + case HMM_DMIRROR_MEMORY_DEVICE_COHERENT: + devmem->pagemap.range.start = (MINOR(mdevice->cdevice.dev) - 2) ? + spm_addr_dev0 : + spm_addr_dev1; + devmem->pagemap.range.end = devmem->pagemap.range.start + + DEVMEM_CHUNK_SIZE - 1; + devmem->pagemap.type = MEMORY_DEVICE_COHERENT; + break; + default: + ret = -EINVAL; goto err_devmem; + } - devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; - devmem->pagemap.range.start = res->start; - devmem->pagemap.range.end = res->end; devmem->pagemap.nr_range = 1; devmem->pagemap.ops = &dmirror_devmem_ops; devmem->pagemap.owner = mdevice; @@ -497,10 +523,14 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, mdevice->devmem_capacity = new_capacity; mdevice->devmem_chunks = new_chunks; } - ptr = memremap_pages(&devmem->pagemap, numa_node_id()); - if (IS_ERR(ptr)) + if (IS_ERR_OR_NULL(ptr)) { + if (ptr) + ret = PTR_ERR(ptr); + else + ret = -EFAULT; goto err_release; + } devmem->mdevice = mdevice; pfn_first = devmem->pagemap.range.start >> PAGE_SHIFT; @@ -529,15 +559,17 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, } spin_unlock(&mdevice->lock); - return true; + return 0; err_release: mutex_unlock(&mdevice->devmem_lock); - release_mem_region(devmem->pagemap.range.start, range_len(&devmem->pagemap.range)); + if (res && devmem->pagemap.type == MEMORY_DEVICE_PRIVATE) + release_mem_region(devmem->pagemap.range.start, + range_len(&devmem->pagemap.range)); err_devmem: kfree(devmem); - return false; + return ret; } static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) @@ -562,7 +594,7 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) spin_unlock(&mdevice->lock); } else { spin_unlock(&mdevice->lock); - if (!dmirror_allocate_chunk(mdevice, &dpage)) + if (dmirror_allocate_chunk(mdevice, &dpage)) goto error; } @@ -1232,10 +1264,8 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id) if (ret) return ret; - /* Build a list of free ZONE_DEVICE private struct pages */ - dmirror_allocate_chunk(mdevice, NULL); - - return 0; + /* Build a list of free ZONE_DEVICE struct pages */ + return dmirror_allocate_chunk(mdevice, NULL); } static void dmirror_device_remove(struct dmirror_device *mdevice) @@ -1248,8 +1278,9 @@ static void dmirror_device_remove(struct dmirror_device *mdevice) mdevice->devmem_chunks[i]; memunmap_pages(&devmem->pagemap); - release_mem_region(devmem->pagemap.range.start, - range_len(&devmem->pagemap.range)); + if (devmem->pagemap.type == MEMORY_DEVICE_PRIVATE) + release_mem_region(devmem->pagemap.range.start, + range_len(&devmem->pagemap.range)); kfree(devmem); } kfree(mdevice->devmem_chunks); diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index 0511af7464ee..f700da7807c1 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -66,6 +66,7 @@ enum { enum { /* 0 is reserved to catch uninitialized type fields */ HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1, + HMM_DMIRROR_MEMORY_DEVICE_COHERENT, }; #endif /* _LIB_TEST_HMM_UAPI_H */ -- 2.32.0