From patchwork Thu Jul 7 19:03:42 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: 12910131 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E070CCA483 for ; Thu, 7 Jul 2022 19:04:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236651AbiGGTEg (ORCPT ); Thu, 7 Jul 2022 15:04:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236616AbiGGTEV (ORCPT ); Thu, 7 Jul 2022 15:04:21 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8415A1EAE7; Thu, 7 Jul 2022 12:04:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WkM74iZDjwAsq8bn6F2rE5xQYa7ulRSVKm5iFlyud7I6PH3ei1nC9LWXmGgXIVHTGt7P6nC8aoSHuM6nXsqU5oKeKDdQtfqZz1LdYai/u2tmE5pRLYfCWbjIdrSAx+c0y/6yx/wsuycKbJvX+h8TMuMu7duHEj187rc5ZwBE8xdCEk3M0PGv7hO16WZQNgegdOqfPvYziBEqTbX5XuLsw2YkFP17DlP/SXbFf7j2GFys5m1QRL1bUOKtfjAGsKOtZTh8eHTbP7oz7tPx5l5Str6npqy1iFVr+dhm8IEk4eBfhR6kp2yX6jN6HcK5z0aTgNTkIUo42unYY0cb7r5jOA== 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=HCXWiNEvF3TUrQgA6hemuT7kHRIWD5ROdsIgulORq7M=; b=nz93uYe41gHdz8+5p0Irv0C2vl8SvScLpJbvWVAlGoZN26GNGYMqRhUwRd0/AaD4xHMIHr7uii3R5r99IJdT++jIfUvzEbl7G0HC1pQ92YWYRmujLH2mm24Fr0BVExfiDGCMx6fU5jbBXls7vPYZ29dnOyHOS9Z33+BbhYvzyvc8MNYMaUAaJHS0wRcgz6aOLWT0RsMbLofPE8MHI7WUqjLMY9gBuOso8GQLxDf50+X39sz8SyKJL4eFiSv86UVCvrbPko8iMimjWK296zQjVsSYlV8nkb5kapXYtJwvIe3Xvi2+miZ8JBF0RCW7hpP68L2TK856bvgpreM0E4Oz8w== 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=HCXWiNEvF3TUrQgA6hemuT7kHRIWD5ROdsIgulORq7M=; b=neObB/Abpsghc4MwMO2d1j5NhBRfGmZTgOXdB5XdJ4PQkLtsvdgyQdXibYr9WNICvE4ZuJo1PFXYDU8z8Mkl2bn2cqTLO08Ryrx4lzfAqblTMTzyy7zTLms3nHFQtxJw6KU5ZgI7hql9oFXuc3lsq+ixqa5z3UT36VgLOtxfaWU= Received: from BN0PR04CA0151.namprd04.prod.outlook.com (2603:10b6:408:eb::6) by DM6PR12MB4356.namprd12.prod.outlook.com (2603:10b6:5:2aa::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Thu, 7 Jul 2022 19:04:15 +0000 Received: from BN8NAM11FT049.eop-nam11.prod.protection.outlook.com (2603:10b6:408:eb:cafe::9b) by BN0PR04CA0151.outlook.office365.com (2603:10b6:408:eb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15 via Frontend Transport; Thu, 7 Jul 2022 19:04:15 +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 BN8NAM11FT049.mail.protection.outlook.com (10.13.177.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5417.15 via Frontend Transport; Thu, 7 Jul 2022 19:04:15 +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; Thu, 7 Jul 2022 14:04:13 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v8 08/15] drm/amdkfd: add SPM support for SVM Date: Thu, 7 Jul 2022 14:03:42 -0500 Message-ID: <20220707190349.9778-9-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220707190349.9778-1-alex.sierra@amd.com> References: <20220707190349.9778-1-alex.sierra@amd.com> MIME-Version: 1.0 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: 95477ff2-244a-4ba8-aaff-08da604b7c81 X-MS-TrafficTypeDiagnostic: DM6PR12MB4356:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: y5JqmsoasGdqYPoMBAQaNsAFVQd38OBxD6ar0AJNfVC6epB+r0OYyVgxRmYqjkLAYi0sQKTW6YhE/S7HJzXzgAPkLZAHwaJvy6GUL1bfey8eQ/9e0TJVNPQ+Usyi6rG8JzlzG1buLOXSKBqjr6onJ1FAOb0FTd7YAy9g+PjBhRuC5uubyF2KmtzmGhfNvQcE71ZSmrnSmPq+ezJk/ZdIgBu01XqIokmpW8Xq2zsuQ/qAfw+7sn6IXRhRwLVa9tTtR9d+RvTuJCvxOkFK4PkONP8UX8UgvNDZvkhE0yToUilFScyyL2XXnUDLvV9pxZ/mb+B6W+h1Tffx3mpgWIYT3o3zX6dxcP0Rfd2ZRcZgwrEKr21Mp7gdh1znokhW1SUY6PIAlnJ5y1rL0AQokU7sgqiCptn6fSJBP7n9/Og84dQE481wEL9rJEpSYnBOnHfeR1Tz+m1tDmAyv7XFM4iKfltNxUc8nLPh2DId3+K778qszHxmqI8hJr9BWbFOKKVxBGb/iKtQy5KxYOOT4k+GVemK9K5f9ukH1QaXjh9k7iZBcVZGASEDr4VYs6e/lkCS0ODIPevd9nfJl0GeEECVzLOtEzbEnBy1iUy6k5KanoVaqyLGl4NH8PRoY5thZecw3irEAijOYKzm9p1ESol4yRYUt/616Sc1toj64TUNDld6ddFRnmaapCv8s/qLd89fiAvhyrbK8E8gek9HSS933oKn5heB4LgQCFNWXg/VF25mNQ0QL+fT3JlF53ReUfN5INZFWSoq/LzcQzlRls13pZ9UAFjvMmr0Fxdsx6Y3LxVSVqV8n2XmG74QGpBA3CxbCZrk2Pmf3eSnRSUutcE31MeSja6clFTdqYRPDeXkSNd4QKoAlefuURdjTWfz//iZ 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)(39860400002)(136003)(346002)(376002)(396003)(46966006)(36840700001)(40470700004)(7416002)(83380400001)(5660300002)(316002)(34020700004)(40480700001)(36860700001)(82740400003)(36756003)(82310400005)(2906002)(16526019)(86362001)(41300700001)(2616005)(4326008)(8676002)(356005)(8936002)(81166007)(6916009)(426003)(70586007)(40460700003)(1076003)(26005)(54906003)(6666004)(186003)(336012)(478600001)(47076005)(70206006)(44832011)(7696005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2022 19:04:15.3407 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95477ff2-244a-4ba8-aaff-08da604b7c81 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: BN8NAM11FT049.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4356 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org When CPU is connected throug XGMI, it has coherent access to VRAM resource. In this case that resource is taken from a table in the device gmc aperture base. This resource is used along with the device type, which could be DEVICE_PRIVATE or DEVICE_COHERENT to create the device page map region. Also, MIGRATE_VMA_SELECT_DEVICE_COHERENT flag is selected for coherent type case during migration to device. Signed-off-by: Alex Sierra Reviewed-by: Felix Kuehling Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 34 +++++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index e44376c2ecdc..f73e3e340413 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -671,13 +671,15 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.vma = vma; migrate.start = start; migrate.end = end; - migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; migrate.pgmap_owner = SVM_ADEV_PGMAP_OWNER(adev); + if (adev->gmc.xgmi.connected_to_cpu) + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_COHERENT; + else + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; buf = kvcalloc(npages, 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t), GFP_KERNEL); - if (!buf) goto out; @@ -947,7 +949,7 @@ int svm_migrate_init(struct amdgpu_device *adev) { struct kfd_dev *kfddev = adev->kfd.dev; struct dev_pagemap *pgmap; - struct resource *res; + struct resource *res = NULL; unsigned long size; void *r; @@ -962,28 +964,34 @@ int svm_migrate_init(struct amdgpu_device *adev) * should remove reserved size */ size = ALIGN(adev->gmc.real_vram_size, 2ULL << 20); - res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); - if (IS_ERR(res)) - return -ENOMEM; + if (adev->gmc.xgmi.connected_to_cpu) { + pgmap->range.start = adev->gmc.aper_base; + pgmap->range.end = adev->gmc.aper_base + adev->gmc.aper_size - 1; + pgmap->type = MEMORY_DEVICE_COHERENT; + } else { + res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); + if (IS_ERR(res)) + return -ENOMEM; + pgmap->range.start = res->start; + pgmap->range.end = res->end; + pgmap->type = MEMORY_DEVICE_PRIVATE; + } - pgmap->type = MEMORY_DEVICE_PRIVATE; pgmap->nr_range = 1; - pgmap->range.start = res->start; - pgmap->range.end = res->end; pgmap->ops = &svm_migrate_pgmap_ops; pgmap->owner = SVM_ADEV_PGMAP_OWNER(adev); - pgmap->flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; - + pgmap->flags = 0; /* Device manager releases device-specific resources, memory region and * pgmap when driver disconnects from device. */ r = devm_memremap_pages(adev->dev, pgmap); if (IS_ERR(r)) { pr_err("failed to register HMM device memory\n"); - /* Disable SVM support capability */ pgmap->type = 0; - devm_release_mem_region(adev->dev, res->start, resource_size(res)); + if (pgmap->type == MEMORY_DEVICE_PRIVATE) + devm_release_mem_region(adev->dev, res->start, + res->end - res->start + 1); return PTR_ERR(r); }