Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2541201iob; Fri, 6 May 2022 05:21:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQgvF54HSHxem1+jzRRgMmzQZQ2B8jVKZkCFpAutcV7W9scOHXgfntY5jjDd3O4v58HLKw X-Received: by 2002:a17:906:6d91:b0:6f4:5433:72f5 with SMTP id h17-20020a1709066d9100b006f4543372f5mr2592686ejt.414.1651839667182; Fri, 06 May 2022 05:21:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1651839667; cv=pass; d=google.com; s=arc-20160816; b=kL+fxwnsgvs6OKDu1JVy9jr/X/Le8jckvF+QjLoAnHhUhBlCm7Y+HoAM2akbHaaePO tOsqMFCCNIpFLnFGzifmEXvAuT8SXUcGolDy2Z9dR09vdaooQoZM8MT5uFyvzi9Yt3VN XKAyfznvwdc6tiqT9040Z+DugXvifyvxISxQ4eIg1NuhRA+9OMAkdcnz+WirPWG5mDZm Llg8r4KUuP1nEmtSvPkGqUvIHGRMkpB2bdnxSFJ9H95+0En3q4lng8txgB/Q+dIIZFaY jFDa5NAOuRSE8Krkkv7jo2NFKMS0hoBdETl63lxwksw2JEXm3Fbw2mx1C4kOkoAN0hpv OQwg== 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=MAzEExkPzjIm9bB+T/l9QE76PKyhGdMZfwR7UqtKtDQBN/vXOIaLi3onol4TjkOd0L ryQAN0wUN5HYccGTAIjjbZOFn/fSEayCLUD4I2GgZpRqNys1sFhp6wrpdHTJQj4BIhgY 7nT3HokjXMvG+hC0ocTjGcacc4DXJi9Y2YpYCkyhdNfRZP80QRHrIw+hVpmfXfxnlP+W 9atK2eaG3nOXesx8RarTU0g/FYim1kBkyoaq7i8LEbH3BDKBU8LA288tSxcJyKG2nXQI KksCpMmi6CBsP9v1KIwP82EP8Ww3zWErFbsMWiaagEp6gWWPx+EhkH3hIE0gQN1wGjUv I8yw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=yrpL3KMC; 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 ga3-20020a1709070c0300b006e8c13a790fsi5718681ejc.860.2022.05.06.05.20.40; Fri, 06 May 2022 05:21: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=yrpL3KMC; 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 S1353176AbiEEVjS (ORCPT + 99 others); Thu, 5 May 2022 17:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385948AbiEEViu (ORCPT ); Thu, 5 May 2022 17:38:50 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2089.outbound.protection.outlook.com [40.107.94.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77A1D5DD1C; Thu, 5 May 2022 14:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GdT5WvVDeJ9QVpx/NdZsF6JhpmCJLBYq/0xzEoOs2hSZeYU1zwvAS0np3kiWZh0mshDEVjtnIxT9j59WYYmptFQm0wUOGUsPtb9msW0mRQRJLrZP6Qxb8buibyofgtidEU43Oz1NcJN32id6W/8oBctY4qlLqgA+v8vNef+LLnPe82fCmEbGFR2MZkIcr4EsKRHzxzOT/R1SSLjyUkYBM6ab/9GZVVjSEFGRP4ptExpYqj12NdeaiySpmkv5NHK21/x2XoYjFpZkGldKCUY9JvjT4EFkjHOsG8oiP8u99MtcK0kjHFaVKxRQmIN/auPkFY47WhuKRd6+3H2OwOma5Q== 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=OFZBbLy/ok79q6vv6/DKLFOkhiisRWLSi/YKy7QliH7Y9h0HFkuIrjI6UUo81B8ah2bh/YDOWW1ZXECEPUVRoF2Om/+dLTBWiVJT1dKBUkSR5vpmOchXVQg6062HhSFStHJJeE3u1xdpyMc01Uvkhjs2xG6mkDJnh/p3rYKEZQP0xao3vsh+D9LA8Kk84pv3HwIB2sEN5nVLF86YMMNEVnVCQMeJ8R7SHYvaExdsESmb36lPML9rvmcrFUcZCFwTY5frGRXhS064reSkJi4BIrp8eMQWjni8gwf/lE1eM9umPKbT2ROHJB48Rl8nWFGOJyfcFswt+cQSp5Gwl2y+1g== 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=yrpL3KMCGAuh84Bbqji+xq2XY5niVnFgzPo0ewLx/mK3LbVbVoRtXhyrM6JjW9x/RflxrEL7t+YjNlnohedVodDn4krQ2E4C4ZuYGx94jsAqCT0D6dJVpJP3HioVfOGmPias3rpc6JmMcZHX6bKvIG/fcJJdjOTpTQzLjLINY+M= Received: from MW4P220CA0012.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::17) by DM5PR12MB1898.namprd12.prod.outlook.com (2603:10b6:3:10d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 21:35:03 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::3d) by MW4P220CA0012.outlook.office365.com (2603:10b6:303:115::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Thu, 5 May 2022 21:35:03 +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 CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:35:03 +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; Thu, 5 May 2022 16:35:00 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 09/15] lib: test_hmm add module param for zone device type Date: Thu, 5 May 2022 16:34:32 -0500 Message-ID: <20220505213438.25064-10-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 13b38283-929e-4e20-e566-08da2edf1d61 X-MS-TrafficTypeDiagnostic: DM5PR12MB1898: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: gmkqnRHz8v6XedgA251CYNFvtac43d5KLPXEiGIYQRyJLTpvsdsmN6WfZEanFkpJaOZfZDSyAHg0IkXj2Br5rjYxG3OXTABmWmFFrqcTW/fM8AaHiHFczoO5LDUyC6QzfWOGxAKwqdsiY95mTUbclK88OgU5HEK9Y5luaOqtsxVJbasuG5Sy+6DDLOgHOQZGBbwtQ/+AsYraZe7zmhrhleg8Dg00aiI/TPfhZU003uga7YC6i5S2qcnCl428pzxMPhHmgxvo2M9+pjVsmTywKtxQEqXa6Hr6dLpjMwnZQOobdQ8o6IvnRKAfYZnhLVHUyDTEhSscvY1f7ufJDwixz5vsR2MA33PBaamz9wrXd0It040zvd2LuseFo3UiJo2/3tnTMTmzoNMeJAlP/OYGHWdLYTG5qOvIsqM1k/oFtaj6HH27SdeZ5DZcJfYsa/OdnsugcQKZdLMZRZrprOkSPR8GnZdp5qnNNFYCcgwNyY+dqYs+KehD5o8BbrEQoXtnBChSnCx5Mv4BvFIqGwIG8EVV9hcUPwO5NgEjloeVX3457bbfLoQpjbDcKsxiKtKJRRV34dt39NpOM8HCVCaahAVnQ82HuAE4c226NXpSOx1RUPWiibVMTAAI/McQFXT4+WAOlyzo+stc3wcwctB5FG1FyousQrFgjsQTjyq8CG9g0geIcfSSejbwyhKmXh7xwox8u2kS2wlAOiafZtVnPA== 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)(40470700004)(36840700001)(46966006)(86362001)(26005)(7696005)(6666004)(36860700001)(16526019)(186003)(426003)(81166007)(356005)(47076005)(336012)(40460700003)(1076003)(2616005)(5660300002)(83380400001)(70206006)(4326008)(70586007)(8676002)(316002)(82310400005)(36756003)(44832011)(7416002)(2906002)(8936002)(54906003)(6916009)(508600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:35:03.0011 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 13b38283-929e-4e20-e566-08da2edf1d61 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1898 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