From patchwork Thu Mar 17 00:20:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 12783352 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 181FAC433FE for ; Thu, 17 Mar 2022 00:20:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 650A110EAB6; Thu, 17 Mar 2022 00:20:45 +0000 (UTC) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2072.outbound.protection.outlook.com [40.107.96.72]) by gabe.freedesktop.org (Postfix) with ESMTPS id C69D210EAB2; Thu, 17 Mar 2022 00:20:43 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nzSpnEZBasxbbs+bNd76vLaRK1WX3XU6AKImf1fKMmXVYbzkIdaI5lwkDjSoJDdSI6eflCnGSnH77K88iR45or5gynfAJ4RD4OWlmrgZoUq/ZY26uOoJ3Ucg29Y1T+V1jrNhu+tB3uKrcRkvjJyjND19xDjhtJJ/ZeqMn0PloBuoWivoqy4dAFgUGRU4RGIZf8Mek4Vh23ioybObjJdMqDCLYhAb4GnJiBzQXGvRXuFikc9H/Qb50g2WntOLNTdw47QSODOCz/e7VCYw5Jx5353gmTWoPj2TpfO4nRxAEBQ2+hdhfuatgfR0IEwwJfw2jTd/3KKkoa3SCTb9j9KUlg== 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=W4a6cLDE8u1pQ/vHugnG1+zNuImyJdWhTF829gyi5Pk=; b=Z3JAqlqbYw4QDTn43M9Wp8mP0r5VkdnLeBNHaHdiuwkEYHLrvFMgW04SSYljCAm2qBhqHADeqr2qTgXTtqddVssedacTfOr0j4kvkRPz/OdOyQhDgzUCyIOEiXGefGLGrdexF+NC0fGVqE14E4hoNZvV7BF3NoNHlb9Kn7k8ftzf5K5phnmlOZHHZSyCBVSSPDHco1qmO/hUS0dbHvG+a5W6QSDnFo3gjzPH1iQXGZQwsFUeLhsVKdIG3gXWzPb2ZV6abuVGMjlmqnBJZ73oOh5beGDwoPOmDjr9wyt1xnIoXGOFrrwf5lYI2OkFvvzg6SRUfd4YrYl9VnW+Q7ghyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.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=W4a6cLDE8u1pQ/vHugnG1+zNuImyJdWhTF829gyi5Pk=; b=Vqu52dmJkcA5NJ7mB90F24nKnA9Whz75b2vUD9gVjHN6zE+jhOuWFnCxjJu8IiHFdyEZJEU1W12KLzu2tQjxr9Kcyz6F9DyOf4WsiuKrJFQZKpADXmfaUXa7psYXlDyhDR5z1G0BO0YbRjgkzw39mGq2rphbKQl25QMsFOQ9eaI= Received: from BN9PR03CA0046.namprd03.prod.outlook.com (2603:10b6:408:fb::21) by BN7PR12MB2595.namprd12.prod.outlook.com (2603:10b6:408:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.15; Thu, 17 Mar 2022 00:20:41 +0000 Received: from BN8NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fb:cafe::53) by BN9PR03CA0046.outlook.office365.com (2603:10b6:408:fb::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.23 via Frontend Transport; Thu, 17 Mar 2022 00:20:41 +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 BN8NAM11FT045.mail.protection.outlook.com (10.13.177.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 00:20:41 +0000 Received: from Harpoon.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; Wed, 16 Mar 2022 19:20:39 -0500 From: Felix Kuehling To: Subject: [RFC PATCH 1/4] drm/amdkfd: Improve amdgpu_vm_handle_moved Date: Wed, 16 Mar 2022 20:20:03 -0400 Message-ID: <20220317002006.342457-2-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220317002006.342457-1-Felix.Kuehling@amd.com> References: <20220317002006.342457-1-Felix.Kuehling@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: 5155305f-4356-4419-1bf2-08da07abf845 X-MS-TrafficTypeDiagnostic: BN7PR12MB2595: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: B6XrkU/+aBMGu15B79eaQH7TOkUQGdteXjQavQs2RYILYprg6oheOj2V+wkTEk/jXcCmo4PRtYk3uWaKhR3jRnvki4gm/c2taee71xWepNNZ/h9CtKnryK3lFhO90wHiGrMPy7zmcHCS8/DMDgArxY8u7caX+1FHr9HwGbrA+v+HsAdktgSmj7xXKQOHxpfo2M3I/Ez25ogzL+sok3P3IgW4nmZCZztTf2pjXPiZ4lr0W5f1jyKuMWS5DrrDyA2lZGhqGaNurVU16qab10a3owQ3zRXpCu89b1Z6R7n4Hlwl3Vsgayzux/LwuPOzeOxlRd2UwphVwZv/Pr5BSh34wzl1NoJhnW84mF1UR9bQYlYbnUIbfdotYHe7tHa1YHlPVqZZgr2VZ5rg4rqlq/NYJSwdzgFHnN1hmNRXK7uPoU0wfMER7dA4deApIbLI/wfH2NYNP40HLcd5LBRutWKmV4qMLImAseKVTXK48AICL0/TERk18bZ+ZdXY4UBNFaPDrun6a1zj82bVGqZed2FOpk8DLMeYfXf+Rzbvtarbc74lOu1IfsyEvts/B+2O/zVZi1zHaoJKNxolDpVDlTGZ7oNIFcy8qqVKEi7sCRLG6H3ONdqICxMQrL9She/t6T+rviFTiPnoKq2JFbytUQlJBuIo5Id9Yi3wJV9XcRI0DWKs3molgfoMEkRUd6j9IDQ1/hJGXVHMpqlgf7oPKh+SXQ== 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)(81166007)(47076005)(450100002)(508600001)(82310400004)(316002)(83380400001)(40460700003)(356005)(6666004)(8676002)(4326008)(36860700001)(7696005)(70586007)(70206006)(86362001)(2906002)(36756003)(16526019)(26005)(6916009)(186003)(336012)(426003)(8936002)(1076003)(5660300002)(54906003)(2616005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 00:20:41.1646 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5155305f-4356-4419-1bf2-08da07abf845 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: BN8NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR12MB2595 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: christian.koenig@amd.com, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Let amdgpu_vm_handle_moved update all BO VA mappings of BOs reserved by the caller. This will be useful for handling extra BO VA mappings in KFD VMs that are managed through the render node API. TODO: This may also allow simplification of amdgpu_cs_vm_handling. See the TODO comment in the code. Signed-off-by: Felix Kuehling --- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 18 +++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 ++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index d162243d8e78..10941f0d8dde 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -826,6 +826,10 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p) return r; } + /* TODO: Is this loop still needed, or could this be handled by + * amdgpu_vm_handle_moved, now that it can handle all BOs that are + * reserved under p->ticket? + */ amdgpu_bo_list_for_each_entry(e, p->bo_list) { /* ignore duplicates */ bo = ttm_to_amdgpu_bo(e->tv.bo); @@ -845,7 +849,7 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p) return r; } - r = amdgpu_vm_handle_moved(adev, vm); + r = amdgpu_vm_handle_moved(adev, vm, &p->ticket); if (r) return r; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c index 579adfafe4d0..50805613c38c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c @@ -414,7 +414,7 @@ amdgpu_dma_buf_move_notify(struct dma_buf_attachment *attach) r = amdgpu_vm_clear_freed(adev, vm, NULL); if (!r) - r = amdgpu_vm_handle_moved(adev, vm); + r = amdgpu_vm_handle_moved(adev, vm, ticket); if (r && r != -EBUSY) DRM_ERROR("Failed to invalidate VM page tables (%d))\n", diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index fc4563cf2828..726b42c6d606 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -2190,11 +2190,12 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev, * PTs have to be reserved! */ int amdgpu_vm_handle_moved(struct amdgpu_device *adev, - struct amdgpu_vm *vm) + struct amdgpu_vm *vm, + struct ww_acquire_ctx *ticket) { struct amdgpu_bo_va *bo_va, *tmp; struct dma_resv *resv; - bool clear; + bool clear, unlock; int r; list_for_each_entry_safe(bo_va, tmp, &vm->moved, base.vm_status) { @@ -2212,17 +2213,24 @@ int amdgpu_vm_handle_moved(struct amdgpu_device *adev, spin_unlock(&vm->invalidated_lock); /* Try to reserve the BO to avoid clearing its ptes */ - if (!amdgpu_vm_debug && dma_resv_trylock(resv)) + if (!amdgpu_vm_debug && dma_resv_trylock(resv)) { clear = false; + unlock = true; + /* The caller is already holding the reservation lock */ + } else if (ticket && dma_resv_locking_ctx(resv) == ticket) { + clear = false; + unlock = false; /* Somebody else is using the BO right now */ - else + } else { clear = true; + unlock = false; + } r = amdgpu_vm_bo_update(adev, bo_va, clear, NULL); if (r) return r; - if (!clear) + if (unlock) dma_resv_unlock(resv); spin_lock(&vm->invalidated_lock); } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h index a40a6a993bb0..120a76aaae75 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h @@ -396,7 +396,8 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev, struct amdgpu_vm *vm, struct dma_fence **fence); int amdgpu_vm_handle_moved(struct amdgpu_device *adev, - struct amdgpu_vm *vm); + struct amdgpu_vm *vm, + struct ww_acquire_ctx *ticket); int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, struct amdgpu_device *bo_adev, struct amdgpu_vm *vm, bool immediate, From patchwork Thu Mar 17 00:20:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 12783353 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 32069C433F5 for ; Thu, 17 Mar 2022 00:20:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7993410EAB4; Thu, 17 Mar 2022 00:20:46 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2060.outbound.protection.outlook.com [40.107.94.60]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1519310EAB2; Thu, 17 Mar 2022 00:20:44 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iEBx2EGGJn9mG1KY7DQZoKp08ewWlAU3XXHlFzCQlQAr1XUDRdKoOmOqYRnxUgmdJOxpO4ij+vAsUXa41ax4KqBP22XzkErl/06xDrM3cvClbTR9l5kTGR5Lkvg4NshDyTTXqQ8XCvbUmprwcI0hFWGiL7YeI/miuv+1zovjYAVF/0z5UlSb9oqgb4F1DaLALpwqF/QGNw8RUqlooei2k1oJk2m0ycY/7P2u7BS6qbM85OAIAi0zlK/j1DKuBWsZ0DTl/SpzbMEPgOXbCfFXdAj3tgRVrjFGHKLQQrAz4k+rEBDnJydlt8PM8RmHPVTwjCcQHAejk554E/MPJPhsbg== 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=vVLlYUIHGHDGSTHJAeTDyjw+b8aJUCpdC+onfys13gQ=; b=er93IXD37AgVgJfJ24aPE6DrCGacWd2C++Exl0NUfE575sJso+39UEKs9+R0ho5A6rWnTCaddzk9kkRd4qqFFNlvGwUN8N0dfe8az2UC1uiheb75fp10YbvPoF5IBKVoKIEPZ0UxNWBh6Pr86RRbVSNMzzY1kz/jiPtgemxqr9u1i33Wr1h8pETN6q/6JNW1Nhd320NT0Ehw4G1XBfjCN36lZXjsI6+h3mz6Kp8TrQ16ttM3f02VcnaXs5rwbl8x3an5q06iVVbnZXA4LG/2dgckOLtDlgaQTmJiKd5G1r2qy1kW9b9H2FXNoZGAGmmLxPhjTg7rhLmXGKvwNqkavA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.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=vVLlYUIHGHDGSTHJAeTDyjw+b8aJUCpdC+onfys13gQ=; b=RnRb2Pje/2td24rsvPLcecmvJ0wNA45IBLiYyEkQRpKZ6nwSFJiNKQFkHfhtTefvLUoMka0D/JtVnhq0Oo4THZA3W3iL5gLoxTpE7mpHm4ULwWL20neS5C+13Fk5mRmwT0uOLEayx3JWQNV64mYjRZZtLvClhLFWkt7aaVoUpJU= Received: from BN9PR03CA0032.namprd03.prod.outlook.com (2603:10b6:408:fb::7) by MN2PR12MB3391.namprd12.prod.outlook.com (2603:10b6:208:c3::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14; Thu, 17 Mar 2022 00:20:42 +0000 Received: from BN8NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fb:cafe::34) by BN9PR03CA0032.outlook.office365.com (2603:10b6:408:fb::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 00:20:42 +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 BN8NAM11FT045.mail.protection.outlook.com (10.13.177.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 00:20:41 +0000 Received: from Harpoon.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; Wed, 16 Mar 2022 19:20:40 -0500 From: Felix Kuehling To: Subject: [RFC PATCH 2/4] drm/amdgpu: Attach eviction fence on alloc Date: Wed, 16 Mar 2022 20:20:04 -0400 Message-ID: <20220317002006.342457-3-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220317002006.342457-1-Felix.Kuehling@amd.com> References: <20220317002006.342457-1-Felix.Kuehling@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: bc57e17d-9418-44c3-b1c3-08da07abf8be X-MS-TrafficTypeDiagnostic: MN2PR12MB3391: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: kCwckgURmFbWJt6F8dmJFo2H5hgaSqpXXxs8+OrNXsYpWPWCAwYAIVggeEPFpTNVzWo0TegHaAfZTlbrCbwtXC80yE/8KKEvYAKjUUbvYFVaObYiCvLl/BMbSPOHAj9ZV58MHkSNqElTZpSfEK5oNJRfQsZS40NPRqWtER0clDa3SOgbjONbBPKbnAMlWZkBjxlxw3Ah6kf136WjytT7wlIJ8yXGagc7g+gvK//rK3UwD/HYK4Usbazbx7Drzn+kR6TU5n7rTHMZYl+iUMNNWbqqdQFy6yggNteU3+8caA4/hrc0vWZCQrf/w18Ig1wLNHGz53gNmzu0MhnHLDAkCxE0+m93EeLJJxBkliUd0vdShSd/gjXDV95ehBiSg7035EX1kpGf3bLHx8tD1FOf/biFkfGUtX6qqz78MtHTEVBsKvBDoOHAaxm0m/2mRU3vI+VhOCFaFG+3XdhuF/demqnZcEKeVdUwPvUoMWhUEpAbZUcpXQShfs++sGX/fFmwdfoSwq29bEse6eA0qc/EzcgNl7ZQLdDdRLCufwTv/0q+29+oBd31nIaW5Q7xWRX8knZZiGFKCFYnhzwTwlb9/MJwO1py1Ja93q52UMxatyjpEZW2Uozwe/75JM184iM9DeJ558uFWtcil8Hp7sUho9ZSgiGReFaCZbuEJuGEH4fgbK6KgDn0VcuU9fV4TfOeK4fyhAgGnER7bptFBvkZRQ== 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)(40470700004)(46966006)(36756003)(336012)(186003)(26005)(8676002)(4326008)(426003)(2616005)(1076003)(16526019)(47076005)(508600001)(40460700003)(6666004)(7696005)(83380400001)(54906003)(2906002)(316002)(6916009)(36860700001)(8936002)(450100002)(70206006)(70586007)(82310400004)(81166007)(86362001)(356005)(5660300002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 00:20:41.8989 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bc57e17d-9418-44c3-b1c3-08da07abf8be 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: BN8NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3391 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: christian.koenig@amd.com, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Instead of attaching the eviction fence when a KFD BO is first mapped, attach it when it is allocated or imported. This in preparation to allow KFD BOs to be mapped using the render node API. Signed-off-by: Felix Kuehling --- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index d23fdebd2552..019e6e363fd2 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -361,6 +361,23 @@ static int amdgpu_amdkfd_bo_validate(struct amdgpu_bo *bo, uint32_t domain, return ret; } +static int amdgpu_amdkfd_bo_validate_and_fence(struct amdgpu_bo *bo, + uint32_t domain, + struct dma_fence *fence) +{ + int ret = amdgpu_bo_reserve(bo, false); + + if (ret) + return ret; + + ret = amdgpu_amdkfd_bo_validate(bo, domain, true); + if (!ret) + amdgpu_bo_fence(bo, fence, true); + amdgpu_bo_unreserve(bo); + + return ret; +} + static int amdgpu_amdkfd_validate_vm_bo(void *_unused, struct amdgpu_bo *bo) { return amdgpu_amdkfd_bo_validate(bo, bo->allowed_domains, false); @@ -1621,6 +1638,11 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( } bo->allowed_domains = AMDGPU_GEM_DOMAIN_GTT; bo->preferred_domains = AMDGPU_GEM_DOMAIN_GTT; + } else { + ret = amdgpu_amdkfd_bo_validate_and_fence(bo, domain, + &avm->process_info->eviction_fence->base); + if (ret) + goto err_validate_bo; } if (offset) @@ -1630,6 +1652,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( allocate_init_user_pages_failed: err_pin_bo: +err_validate_bo: remove_kgd_mem_from_kfd_bo_list(*mem, avm->process_info); drm_vma_node_revoke(&gobj->vma_node, drm_priv); err_node_allow: @@ -1699,10 +1722,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( if (unlikely(ret)) return ret; - /* The eviction fence should be removed by the last unmap. - * TODO: Log an error condition if the bo still has the eviction fence - * attached - */ amdgpu_amdkfd_remove_eviction_fence(mem->bo, process_info->eviction_fence); pr_debug("Release VA 0x%llx - 0x%llx\n", mem->va, @@ -1819,19 +1838,6 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu( if (unlikely(ret)) goto out_unreserve; - if (mem->mapped_to_gpu_memory == 0 && - !amdgpu_ttm_tt_get_usermm(bo->tbo.ttm)) { - /* Validate BO only once. The eviction fence gets added to BO - * the first time it is mapped. Validate will wait for all - * background evictions to complete. - */ - ret = amdgpu_amdkfd_bo_validate(bo, domain, true); - if (ret) { - pr_debug("Validate failed\n"); - goto out_unreserve; - } - } - list_for_each_entry(entry, &mem->attachments, list) { if (entry->bo_va->base.vm != avm || entry->is_mapped) continue; @@ -1858,10 +1864,6 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu( mem->mapped_to_gpu_memory); } - if (!amdgpu_ttm_tt_get_usermm(bo->tbo.ttm) && !bo->tbo.pin_count) - amdgpu_bo_fence(bo, - &avm->process_info->eviction_fence->base, - true); ret = unreserve_bo_and_vms(&ctx, false, false); goto out; @@ -1878,7 +1880,6 @@ int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu( struct amdgpu_device *adev, struct kgd_mem *mem, void *drm_priv) { struct amdgpu_vm *avm = drm_priv_to_vm(drm_priv); - struct amdkfd_process_info *process_info = avm->process_info; unsigned long bo_size = mem->bo->tbo.base.size; struct kfd_mem_attachment *entry; struct bo_vm_reservation_context ctx; @@ -1919,15 +1920,6 @@ int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu( mem->mapped_to_gpu_memory); } - /* If BO is unmapped from all VMs, unfence it. It can be evicted if - * required. - */ - if (mem->mapped_to_gpu_memory == 0 && - !amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm) && - !mem->bo->tbo.pin_count) - amdgpu_amdkfd_remove_eviction_fence(mem->bo, - process_info->eviction_fence); - unreserve_out: unreserve_bo_and_vms(&ctx, false, false); out: @@ -2090,8 +2082,16 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev, amdgpu_sync_create(&(*mem)->sync); (*mem)->is_imported = true; + ret = amdgpu_amdkfd_bo_validate_and_fence(bo, (*mem)->domain, + &avm->process_info->eviction_fence->base); + if (ret) + goto err_remove_mem; + return 0; +err_remove_mem: + remove_kgd_mem_from_kfd_bo_list(*mem, avm->process_info); + drm_vma_node_revoke(&obj->vma_node, drm_priv); err_free_mem: kfree(mem); err_put_obj: From patchwork Thu Mar 17 00:20:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 12783354 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 446FBC433F5 for ; Thu, 17 Mar 2022 00:20:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8DF2510EAB9; Thu, 17 Mar 2022 00:20:46 +0000 (UTC) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on2088.outbound.protection.outlook.com [40.107.102.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4B09210EAB2; Thu, 17 Mar 2022 00:20:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j7gCnZTnfLEMF93HNnqcIbYkGceaH5tfImrrL2h8SPV+W81JJrHlF+itLM/4JEciHcpPFBDY/NKacoA2ZarDe1nNYkkH/9fPDB0OyymHD44ACoYC27hxAoKwmzEXemPzDH8DnBhKpi6THL9Hns73RTV+fBihbBxvdqBIDsAbxeJk0e07D5ZBBuxjYHyvDmeUONDUinv55PxFDI3VQ6dDUe0YXrbQxO4tSLjHB74TK+RvDMeVfiFWKEg8XUmsMI4qbte30YvzshZJpbybiR0TYeBi1jAX+3no9ZG6lj64C6gqhSApfDFaMjqxZiArRfFqmNvgrHrEVl9XuvupCpQxtQ== 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=WDoHN+JZFMvmGS9jKuh/kf6G9e3ZTX4JHS3fZk7+TUc=; b=W7Gpzk0YEChwd/CGX02HadiMPiAZy2B8QZC6MCNehJS6WRihkOTsx/DfqJ1oEIlKi/WynrIQIXwYyYaO+IKbgblF5w6i0kw/qLJtWSRr+n2DIdMuzFy4RecEniBMBL+DDcP8BgUEvZFhIDEh9nfoc4OA3KHxXGEshyLbDEZueeAER/y75JlpI/5l1X/rNWJ5s27VF0lGZq+dqYjpzpLcXkpPMFohUZ4wbx+hSc3BCTIMYRjJcXKlY13U5Uys0Q3H4fgRTPShSSFv2pfQf2I2NNT5fIdoWmN3GovbWms47HZ0zlAp+u8agmvdlna3NPwDp2D6cJqJzE9ko1PJLuJcVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.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=WDoHN+JZFMvmGS9jKuh/kf6G9e3ZTX4JHS3fZk7+TUc=; b=Knp4KLcAKQFrhBovSpsodAn0gxokKTs+DomfIGKPhrnbNty8jlzXtspCzyOwPtRdiocFpOt5mZYNefoGpXc6vj1P3K3KbOR/W6XsOzakNela5oxFJdbb5M/w9kodoiOMUyP+qdZNbyalLK37JjvqRhi2UVbr0+Ez+n9RQS1mDPU= Received: from BN9PR03CA0052.namprd03.prod.outlook.com (2603:10b6:408:fb::27) by DM4PR12MB5722.namprd12.prod.outlook.com (2603:10b6:8:5d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14; Thu, 17 Mar 2022 00:20:43 +0000 Received: from BN8NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fb:cafe::6c) by BN9PR03CA0052.outlook.office365.com (2603:10b6:408:fb::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 00:20:43 +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 BN8NAM11FT045.mail.protection.outlook.com (10.13.177.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 00:20:42 +0000 Received: from Harpoon.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; Wed, 16 Mar 2022 19:20:41 -0500 From: Felix Kuehling To: Subject: [RFC PATCH 3/4] drm/amdgpu: update mappings not managed by KFD Date: Wed, 16 Mar 2022 20:20:05 -0400 Message-ID: <20220317002006.342457-4-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220317002006.342457-1-Felix.Kuehling@amd.com> References: <20220317002006.342457-1-Felix.Kuehling@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: 04272772-7cd1-4593-4796-08da07abf938 X-MS-TrafficTypeDiagnostic: DM4PR12MB5722: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: W25c1lD+1qC+ALEbUrPs36ocOIvJLjasWjvuPAi97zwPQsIh06kVS3kos9Yv0wJRW24dNFMWlxvbxR9Xk2p4tagUKGXQ6+NwFv8/eph2Ae+X4sqSibbn6hwFLItXyx+7kL4QQJM56K24dn96fNJXIP7IyvWPftE7uoV4+jcIDs9ILadAnEmY0LXWlEWwGHSnP1eoIVC1WcSa+FiQcAEd1JMRD0LCwIbW/63obQrWiZgQA8ldbGY5Wr7+Cj+sqmtDN6BnlrZCoU3fsRD5w4J5k5luFj6gT9D+qBMboNInZg4NOsuNr+tkoNBKcBtc42u7BdOiDlKkdIAVwNGB89DiimCvREbLNXKDXTWcGxXIvIUkoDhjjWDTVKx8r70y8Aw22kPkzcUGIGIvSfmf9yk5UT6vyj6qDvh1o1rZbe4306QMCu1mpmal9wA7XmMh/elx2o5fLVKuBfZeNozf15NafGOGD3kpn/q5amhOHc8acMqDfQysTCKB52Vuzw0IVYi0KyhNshlNK8WvaadTuThT8KEtF5ikBpxApKt0YUSrchROflvNCykNydYlEfuSSC0h3j6stxN4t1VEn/iv0Z8hM0+lI/neY7FUD5HbsO+jvNtiosmSR0qA4YCtV/nwwbGgag+KE0FO0xlg09AZR1OG+q5n0bIPZsUnQsD+NDxG1e98RK5Z48CCrYf+SE8l/LyWD1M/DhoeTAD0XmjQXm4y7Q== 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)(40470700004)(46966006)(54906003)(4326008)(8676002)(316002)(6916009)(47076005)(450100002)(2616005)(1076003)(82310400004)(426003)(6666004)(16526019)(86362001)(40460700003)(83380400001)(7696005)(15650500001)(26005)(70206006)(70586007)(186003)(336012)(2906002)(36860700001)(36756003)(508600001)(356005)(81166007)(5660300002)(8936002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 00:20:42.7269 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 04272772-7cd1-4593-4796-08da07abf938 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: BN8NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5722 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: christian.koenig@amd.com, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" When restoring after an eviction, use amdgpu_vm_handle_moved to update BO VA mappings in KFD VMs that are not managed through the KFD API. This should allow using the render node API to create more flexible memory mappings in KFD VMs. Signed-off-by: Felix Kuehling --- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index 019e6e363fd2..6f90ff4b485d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -2535,6 +2535,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef) continue; kfd_mem_dmaunmap_attachment(mem, attachment); + /* TODO: Could amdgpu_vm_handle_moved do this? */ ret = update_gpuvm_pte(mem, attachment, &sync_obj, NULL); if (ret) { pr_debug("Memory eviction: update PTE failed. Try again\n"); @@ -2546,6 +2547,20 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef) if (failed_size) pr_debug("0x%lx/0x%lx in system\n", failed_size, total_size); + /* Update mappings not managed by KFD */ + list_for_each_entry(peer_vm, &process_info->vm_list_head, + vm_list_node) { + struct amdgpu_device *adev = amdgpu_ttm_adev( + peer_vm->root.bo->tbo.bdev); + + ret = amdgpu_vm_handle_moved(adev, peer_vm, &ctx.ticket); + if (ret) { + pr_debug("Memory eviction: handle moved failed. Try again\n"); + goto validate_map_fail; + } + /* TODO: how to update the sync object? */ + } + /* Update page directories */ ret = process_update_pds(process_info, &sync_obj); if (ret) { From patchwork Thu Mar 17 00:20:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 12783355 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF7A4C4332F for ; Thu, 17 Mar 2022 00:20:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7350810EABC; Thu, 17 Mar 2022 00:20:50 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2041.outbound.protection.outlook.com [40.107.93.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7897710EABA; Thu, 17 Mar 2022 00:20:48 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gtJm04GtcTgYA4zFphwXKqN+bDBQG2Jvdh9Y6gYfka89CpPog/OFnBMJiCbkArrqV1P+OBskfjLuQRwvk4IM4Ll5AM+ELlY7kefaduTuLG2z7L/hC2WeIVZ4W8+/tvBeCNI2TBpxNO7X6SYdDS4PFFnBfIXhvSVkW4PuDIbHBbyLRVQPvAVj583Ys17TiTMy8J9rzYeqcEYWiesE2t74fzxeXMTfnsLdom3coG/Lh7v6BiTeedHnJU2dK+WmXVLpRT5WRLidLZuW2gJtDbvfYE3f3oAeiFfr1nxCKWc1bMdPbcduYNsHFHPRlCl7VjeI0jVZyS4ksKcbMGT3sJQphw== 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=y6Ei4IO43jKEUrpU5Q75ITNG3B3tpUZb9RwKIxJcSN0=; b=oDNOrk1JbXAtocu29nU4WTGUyPIgFbFxItv8uzcMotiYCu07h+LtZnB2TZN7O8SCsliMp86dR5sIKiYQVe0C8JSqnPSKTHQg6mwK3bFEdaHNe/QhdNcxIgoJ/bxJkagIjW8oleBD5oyRX0nH/q5+VY7Uin1zW9XrU0FLx4uLe/mt0gPdi3uSnFpxhtWrgoJPFlfk8AA8Pedh36PRYLZ2p6tPmol6T1/BASzWRU/4LSV6g50k/Z83eJHtD2uHrW7QhrdmA2BfWjHKlEb8nMQR9A+FZFPk5LhhbYT8+7/t426kDinJ6YkGuqywS9n6X9IZVItncgkm9gLydN86pOU6dA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.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=y6Ei4IO43jKEUrpU5Q75ITNG3B3tpUZb9RwKIxJcSN0=; b=5c/b8Ey/jJHwYbsrTuP3uvCKHuExHWkemCrnrBje1FVOUjeP0Op9P5BNLI2KXQMFKCp+YS7ABZi0CWhppDnAplTpL7+Aplmy3YZOPeWZTQLaHQFpZI5DNDrISYyGu1B0DFphNyCBqTIGEP6YPtgIdG5P0MWLJsIP/Xocea7sF5g= Received: from BN9PR03CA0045.namprd03.prod.outlook.com (2603:10b6:408:fb::20) by BN9PR12MB5308.namprd12.prod.outlook.com (2603:10b6:408:105::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.15; Thu, 17 Mar 2022 00:20:44 +0000 Received: from BN8NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fb:cafe::99) by BN9PR03CA0045.outlook.office365.com (2603:10b6:408:fb::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.17 via Frontend Transport; Thu, 17 Mar 2022 00:20:44 +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 BN8NAM11FT045.mail.protection.outlook.com (10.13.177.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5081.14 via Frontend Transport; Thu, 17 Mar 2022 00:20:43 +0000 Received: from Harpoon.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; Wed, 16 Mar 2022 19:20:42 -0500 From: Felix Kuehling To: Subject: [RFC PATCH 4/4] drm/amdgpu: Do bo_va ref counting for KFD BOs Date: Wed, 16 Mar 2022 20:20:06 -0400 Message-ID: <20220317002006.342457-5-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220317002006.342457-1-Felix.Kuehling@amd.com> References: <20220317002006.342457-1-Felix.Kuehling@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: bf255dcc-45c3-498a-db6f-08da07abf9d0 X-MS-TrafficTypeDiagnostic: BN9PR12MB5308: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: 1rDzJrZFg6qOhXPBp6ZwGZeCjPlJMqgBsB8bx+1SNYq90V5y+oh7fOIEtrGqD2KWOa37O8HcJIAoeeoAFVAKGrPUiHlVthweHPAjW1ZAORDEVgpTVVPvgMpMo4C2kCxkTcX+a2ZtCFj8Y95FbbAr+75+6jmWVpwhLmiCh2JMCKhDyUsP26Wk5kRdKTgXU++D1dInYvd/uallPvbu+F9hW+1uG5wkXTfor5HeLzFQPcLJ1w17z8VjPQgOhDZ3dvWqSDdcVWaxZOAHfOfS0Uubo3yHxEAAuEOjsTU7S5onvMcvIthCGZyaKtgQd06LQabjK+OtFtKYLDYdbmaHdyXqFnRB82GZ7nmnyv/pTtlNtWxHpwHSYIKOt5XivvpE/3xbekA61VP3Q57joJJUH28lJ1dQyy5LAZLZ9iKo41y8TebwTCoRLWOyCGV/5zVqJSKTVN3j1tqrEGiJWg5vhlWcZ4NGxTEKiVwsb9IM0ho32q4ResI9xiKmWuxJ8LvGFfcXYofFbV6rPahATjSIeMewX061YtkQAdRT2VC0q/HNMeoF2Q0OwCMuOUYY8oKsibFD/+T51wR5xAs9eA3eYMvffxrxPw1OIN+X1UwII3KaU1Ugbwe0rfUbWdVWyn6Ej/jp/fgXVF0Gw5JCf+SCFwqSJIHiohi9bG9j7oSx68zvIVFnaV2bo7RO4e6jzsX4qoMMknO+MNuOKVNcBagnEjCqCw== 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)(4326008)(86362001)(82310400004)(8676002)(83380400001)(450100002)(70206006)(47076005)(70586007)(16526019)(36860700001)(426003)(336012)(2616005)(1076003)(186003)(26005)(356005)(81166007)(40460700003)(508600001)(8936002)(2906002)(54906003)(316002)(7696005)(6916009)(5660300002)(36756003)(6666004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 00:20:43.6644 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf255dcc-45c3-498a-db6f-08da07abf9d0 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: BN8NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5308 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: christian.koenig@amd.com, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This is needed to correctly handle BOs imported into the GEM API, which would otherwise get added twice to the same VM. Signed-off-by: Felix Kuehling --- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index 6f90ff4b485d..bf90b2fa2738 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -371,8 +371,16 @@ static int amdgpu_amdkfd_bo_validate_and_fence(struct amdgpu_bo *bo, return ret; ret = amdgpu_amdkfd_bo_validate(bo, domain, true); - if (!ret) - amdgpu_bo_fence(bo, fence, true); + if (ret) + goto unreserve_out; + + ret = dma_resv_reserve_shared(bo->tbo.base.resv, 1); + if (ret) + goto unreserve_out; + + amdgpu_bo_fence(bo, fence, true); + +unreserve_out: amdgpu_bo_unreserve(bo); return ret; @@ -716,6 +724,7 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, uint64_t va = mem->va; struct kfd_mem_attachment *attachment[2] = {NULL, NULL}; struct amdgpu_bo *bo[2] = {NULL, NULL}; + struct amdgpu_bo_va *bo_va; int i, ret; if (!va) { @@ -779,7 +788,12 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, pr_debug("Unable to reserve BO during memory attach"); goto unwind; } - attachment[i]->bo_va = amdgpu_vm_bo_add(adev, vm, bo[i]); + bo_va = amdgpu_vm_bo_find(vm, bo[i]); + if (!bo_va) + bo_va = amdgpu_vm_bo_add(adev, vm, bo[i]); + else + ++bo_va->ref_count; + attachment[i]->bo_va = bo_va; amdgpu_bo_unreserve(bo[i]); if (unlikely(!attachment[i]->bo_va)) { ret = -ENOMEM; @@ -803,7 +817,8 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, continue; if (attachment[i]->bo_va) { amdgpu_bo_reserve(bo[i], true); - amdgpu_vm_bo_del(adev, attachment[i]->bo_va); + if (--attachment[i]->bo_va->ref_count == 0) + amdgpu_vm_bo_del(adev, attachment[i]->bo_va); amdgpu_bo_unreserve(bo[i]); list_del(&attachment[i]->list); } @@ -820,7 +835,8 @@ static void kfd_mem_detach(struct kfd_mem_attachment *attachment) pr_debug("\t remove VA 0x%llx in entry %p\n", attachment->va, attachment); - amdgpu_vm_bo_del(attachment->adev, attachment->bo_va); + if (--attachment->bo_va->ref_count == 0) + amdgpu_vm_bo_del(attachment->adev, attachment->bo_va); drm_gem_object_put(&bo->tbo.base); list_del(&attachment->list); kfree(attachment);