From patchwork Fri Jan 31 14:30:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13955438 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 2846DC02190 for ; Fri, 31 Jan 2025 14:30:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C344F10E1E4; Fri, 31 Jan 2025 14:30:58 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Bszm6tdq"; dkim-atps=neutral Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7ED2B10EAD7 for ; Fri, 31 Jan 2025 14:30:56 +0000 (UTC) Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-438a39e659cso14723905e9.2 for ; Fri, 31 Jan 2025 06:30:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738333855; x=1738938655; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=jkJ00bQPlHyacSDxXMVR+WVEfXofLdMgzS8qb7ZbIsw=; b=Bszm6tdqTUMf02jLT6e5JPxS6ArhlA/+dvkeUWSZm23zN2I+0xkSDgpW3CjwcEHRl2 QO6ZAf2xrrpyYldp3EaIC514FpRJB4SRXr/y4nyD87MGCssv2nrZ7o0f9JPZ0x4LS+j3 ikrEkz57UHzv8WGJzytj6bog2fEl+sz66EJwy8x4W/86E3Am8J8PuhhYkh5S311hevMN vHPRTCXrGJc92SSc73hh8Q4XEQhVj9W0tTwjyF13Afv7g2HA3Sxqr6zumsby2o3LBruw hpOXyvaZ16nYNBI0EEEe2xk1O7sSDV4ykzto67G659iU9gvlzlusctIzWh7EnlFd06iN DYrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738333855; x=1738938655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jkJ00bQPlHyacSDxXMVR+WVEfXofLdMgzS8qb7ZbIsw=; b=fAvI51T0RmxA2NcGAm74vJiOitCGk8Izx94PjZF/wHjLPjSaV3LDWdi5LI00MLqoD6 4lGcMSs1QJKexlQmzA+EkR1bng9xtC0CZ6M07nHQhLcSvlljW9+xHSeKNajQHUUW6UC2 TFNUYt6XJFHAIxy3J7INXBGoFC4f2QegniRWu7lx52cBOs3e9x21MI5ti5efv7N/Lkzj PWzyWJHeQlAo2l31BL9nfivIK6XytM+X4Bu3ZxZhOzZe7JIpF0yVFg5wLL9y9x97lHHu 3d9QYFI1bwom1dl6D6iM28+M3T46y2uolgx9IKPX2O0PN1AESJ9+5yOC35yMPr8/bnJG r2vg== X-Gm-Message-State: AOJu0Yzxg4fAZLB23ZxVf6w6e2I2eTgC/upGKAN3Xi0gJ9EBS/WedQWm tURw8rue/ybupkAG6o+BfW3sCBjsCGKzSdD/Zxx27pVe0mv09PG8SSnVBC7Q X-Gm-Gg: ASbGncvuP6b6WWaCTxOmBeW08fiO2A6geO+4JmAic1zz3RkXlv0rFIJqy2gCi6F/74R XykNRdrCVzr5Wafw7j3NB6gCf5KJ80OSeSctcXBnT7Xw2PGHx3dDPt82S6tqcjQA/TESihp6cRk C5hrvwSY3IylamOUNpB1ZxcQ/0PKFC6VEDE+xNEiIz08zZXRH3Ppq7uHQRgd6/J+5DY/lPoZhe6 ooUmofFL6SvYaQwsgxUyP4lQq4oNflFujnvXenkMNXf8hwBZ7onntiouRf+VlLPpONk2nJj7n6k s5hr+dA7HugXbWjGOcVMn3xv+fPe X-Google-Smtp-Source: AGHT+IFDMFNXgbRPNPeH2RFneEFBwrLq6X2f/yQL/UxS/UDPYjErCz728ru47sykedb9LcTXv8EzPA== X-Received: by 2002:a05:6000:188b:b0:385:f2a2:50df with SMTP id ffacd0b85a97d-38c5195f498mr11116175f8f.27.1738333854737; Fri, 31 Jan 2025 06:30:54 -0800 (PST) Received: from able.fritz.box ([2a00:e180:14ea:9e00:b99f:ba95:78e6:9a32]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c5c102e19sm4891382f8f.36.2025.01.31.06.30.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2025 06:30:54 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org Subject: [PATCH 1/2] drm/ttm: test private resv obj on release/destroy Date: Fri, 31 Jan 2025 15:30:51 +0100 Message-Id: <20250131143052.1728-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250131143052.1728-1-christian.koenig@amd.com> References: <20250131143052.1728-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Test the fences in the private dma_resv object instead of the pointer to a potentially shared dma_resv object. This only matters for imported BOs with an SG table since those don't get their dma_resv pointer replaced on release. Signed-off-by: Christian König Reviewed-and-Tested-by: James Zhu Reviewed-by: Felix Kuehling --- drivers/gpu/drm/ttm/ttm_bo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 06d6a452c4f4..4d6b2143db63 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -234,7 +234,7 @@ static void ttm_bo_delayed_delete(struct work_struct *work) bo = container_of(work, typeof(*bo), delayed_delete); - dma_resv_wait_timeout(bo->base.resv, DMA_RESV_USAGE_BOOKKEEP, false, + dma_resv_wait_timeout(&bo->base._resv, DMA_RESV_USAGE_BOOKKEEP, false, MAX_SCHEDULE_TIMEOUT); dma_resv_lock(bo->base.resv, NULL); ttm_bo_cleanup_memtype_use(bo); @@ -269,7 +269,7 @@ static void ttm_bo_release(struct kref *kref) drm_vma_offset_remove(bdev->vma_manager, &bo->base.vma_node); ttm_mem_io_free(bdev, bo->resource); - if (!dma_resv_test_signaled(bo->base.resv, + if (!dma_resv_test_signaled(&bo->base._resv, DMA_RESV_USAGE_BOOKKEEP) || (want_init_on_free() && (bo->ttm != NULL)) || bo->type == ttm_bo_type_sg || From patchwork Fri Jan 31 14:30:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13955439 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 7E60CC0218F for ; Fri, 31 Jan 2025 14:31:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 27EC310E1EC; Fri, 31 Jan 2025 14:31:02 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mrtDrkCp"; dkim-atps=neutral Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by gabe.freedesktop.org (Postfix) with ESMTPS id 20B7E10EACD for ; Fri, 31 Jan 2025 14:30:57 +0000 (UTC) Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4362bae4d7dso15184835e9.1 for ; Fri, 31 Jan 2025 06:30:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738333855; x=1738938655; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=qYEU99YjaIifrQifFG08E+amsttIxcl2+iMYS7g1xuc=; b=mrtDrkCpgz8dqOKoxL2shvHXTygEd6DAjd2yOe0T1DejoiJl1XP5UUmbQpf8BOCpS/ Ki0j82B5hzklK4q+FUSFBpTc6kbTnOpHvbK0+v1ifXSUaBL0xw0OwVEpJlf9ehO1Lvph H/JWrrKfREJRao9aF8WclgdiluL7AthCWvQHvBL0hws6xk8JR2mSmGbH69F6EEYNC6Bs 2PTfeusNl/bG0iEKOwEGqcRhB5wfPkefqoIeV9FmeJMvxPLXh+DWgxtwx0h1t/p2eiFr pXDUFWBpih9c0cJwAy6KaRSoqOrpNuagG917mLOdke5zsw0eMMy5ng6v62udBm2l9n3r QI5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738333855; x=1738938655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qYEU99YjaIifrQifFG08E+amsttIxcl2+iMYS7g1xuc=; b=Z5zto/+Lt0U7H9HlywKuPQoOacGZMb3/J5GORzwHOXypes3L+1q3GUDqjLNYZTRD2+ 2FEeGOSIP9R+1B3otHHMH5tmZbCwngvTFXOO2320FEwxbTkdedNGVHowSRyCMMTYd/IX VVNUUn5eCdYKyNtnxsdBNzVaDiy0EcHWWOs+Vdkpg2R50Q1Z3h27mmRK3sggVBNJJflQ r1QaKxqSgrVMTzb6H4NTUnPpsXW/1Y43OaSq1hjAHFLaQ37ay2YKc90iymjoAn0n1Wjh sfw0aFKd5zdujW+6LPjox6IEL2Z21+97rbNsHZ7zGKz6aq78GgTJscY6X3wb4SDtYUht WEwQ== X-Gm-Message-State: AOJu0YxokliIn131mPYaBLve8g/rJjPQEb+6VesB1Y+X3UXXJguiZDvn ClTMst9ZahHz+0jJuYfJkpnXv/PXrFh9etORfYc8sbAkOHVI4ZnBn/Mia1VqoNk= X-Gm-Gg: ASbGncuhlr44q24UECSHxB8VJvK6vc+gpz4fAv1adDdwlmGbCFhpLLGa9y8NDRs95rR 9Obr2l38oK1s7Mt9f8nx6458IgA/xzYdIRQzTACO3GIXcZQvKJNOzH8690GSEmNaYE5PfVFFKW1 YBPgi3cMxTCoQT6oqSnyPATaatgkoQXIXb13dBOenCEb3aZGTXJ0aY0QRi1et8FD3UjSquGm6fc sggFDVDySZnDosU0nx+64fCX7CHL9g/7WvKb2slUDHYjwCx3RQMTtnd/Na7Co0USHw6abNEN2pd waQLQ5VuUSEzsZCBhyOdqC7xVb66 X-Google-Smtp-Source: AGHT+IEb50p+YxQIdYWDDGsIS+xOJ4pr3HNU8af3p5QhvQ4ncRvf6OKUrz4jk45IRkUfM5ODD3tBJQ== X-Received: by 2002:a5d:6987:0:b0:385:f7d2:7e9b with SMTP id ffacd0b85a97d-38c51b5dc56mr6937141f8f.30.1738333855387; Fri, 31 Jan 2025 06:30:55 -0800 (PST) Received: from able.fritz.box ([2a00:e180:14ea:9e00:b99f:ba95:78e6:9a32]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c5c102e19sm4891382f8f.36.2025.01.31.06.30.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2025 06:30:55 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org Subject: [PATCH 2/2] drm/amdgpu: remove all KFD fences from the BO on release Date: Fri, 31 Jan 2025 15:30:52 +0100 Message-Id: <20250131143052.1728-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250131143052.1728-1-christian.koenig@amd.com> References: <20250131143052.1728-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Remove all KFD BOs from the private dma_resv object. This prevents the KFD from being evitec unecessarily when an exported BO is released. Signed-off-by: Christian König Reviewed-and-Tested-by: James Zhu Reviewed-by: Felix Kuehling --- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 5 +- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 52 ++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 38 ++++++++------ 3 files changed, 47 insertions(+), 48 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h index 4b80ad860639..62917f76da33 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h @@ -192,7 +192,7 @@ int kfd_debugfs_kfd_mem_limits(struct seq_file *m, void *data); #if IS_ENABLED(CONFIG_HSA_AMD) bool amdkfd_fence_check_mm(struct dma_fence *f, struct mm_struct *mm); struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f); -int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo); +void amdgpu_amdkfd_remove_all_eviction_fences(struct amdgpu_bo *bo); int amdgpu_amdkfd_evict_userptr(struct mmu_interval_notifier *mni, unsigned long cur_seq, struct kgd_mem *mem); int amdgpu_amdkfd_bo_validate_and_fence(struct amdgpu_bo *bo, @@ -212,9 +212,8 @@ struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f) } static inline -int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo) +void amdgpu_amdkfd_remove_all_eviction_fences(struct amdgpu_bo *bo) { - return 0; } static inline diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index f30548f4c3b3..609b27fe1cda 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -370,40 +370,32 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, return 0; } -int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo) +/** + * amdgpu_amdkfd_remove_all_eviction_fences - Remove all eviction fences + * @bo: the BO where to remove the evictions fences from. + * + * This functions should only be used on release when all references to the BO + * are already dropped. We remove the eviction fence from the private copy of + * the dma_resv object here since that is what is used during release to + * determine of the BO is idle or not. + */ +void amdgpu_amdkfd_remove_all_eviction_fences(struct amdgpu_bo *bo) { - struct amdgpu_bo *root = bo; - struct amdgpu_vm_bo_base *vm_bo; - struct amdgpu_vm *vm; - struct amdkfd_process_info *info; - struct amdgpu_amdkfd_fence *ef; - int ret; - - /* we can always get vm_bo from root PD bo.*/ - while (root->parent) - root = root->parent; + struct dma_resv *resv = &bo->tbo.base._resv; + struct dma_fence *fence, *stub; + struct dma_resv_iter cursor; - vm_bo = root->vm_bo; - if (!vm_bo) - return 0; + dma_resv_assert_held(resv); - vm = vm_bo->vm; - if (!vm) - return 0; - - info = vm->process_info; - if (!info || !info->eviction_fence) - return 0; - - ef = container_of(dma_fence_get(&info->eviction_fence->base), - struct amdgpu_amdkfd_fence, base); - - BUG_ON(!dma_resv_trylock(bo->tbo.base.resv)); - ret = amdgpu_amdkfd_remove_eviction_fence(bo, ef); - dma_resv_unlock(bo->tbo.base.resv); + stub = dma_fence_get_stub(); + dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_BOOKKEEP, fence) { + if (!to_amdgpu_amdkfd_fence(fence)) + continue; - dma_fence_put(&ef->base); - return ret; + dma_resv_replace_fences(resv, fence->context, stub, + DMA_RESV_USAGE_BOOKKEEP); + } + dma_fence_put(stub); } static int amdgpu_amdkfd_bo_validate(struct amdgpu_bo *bo, uint32_t domain, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index fc94b8b9b86d..d12be7a1eb6e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -1194,28 +1194,36 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) if (abo->kfd_bo) amdgpu_amdkfd_release_notify(abo); - /* We only remove the fence if the resv has individualized. */ - WARN_ON_ONCE(bo->type == ttm_bo_type_kernel - && bo->base.resv != &bo->base._resv); - if (bo->base.resv == &bo->base._resv) - amdgpu_amdkfd_remove_fence_on_pt_pd_bos(abo); + /* + * We lock the private dma_resv object here and since the BO is about to + * be released nobody else should have a pointer to it. + * So when this locking here fails something is wrong with the reference + * counting. + */ + if (WARN_ON_ONCE(!dma_resv_trylock(&bo->base._resv))) + return; + + amdgpu_amdkfd_remove_all_eviction_fences(abo); if (!bo->resource || bo->resource->mem_type != TTM_PL_VRAM || !(abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE) || adev->in_suspend || drm_dev_is_unplugged(adev_to_drm(adev))) - return; + goto out; - if (WARN_ON_ONCE(!dma_resv_trylock(bo->base.resv))) - return; + r = dma_resv_reserve_fences(&bo->base._resv, 1); + if (r) + goto out; - r = amdgpu_fill_buffer(abo, 0, bo->base.resv, &fence, true); - if (!WARN_ON(r)) { - amdgpu_vram_mgr_set_cleared(bo->resource); - amdgpu_bo_fence(abo, fence, false); - dma_fence_put(fence); - } + r = amdgpu_fill_buffer(abo, 0, &bo->base._resv, &fence, true); + if (WARN_ON(r)) + goto out; + + amdgpu_vram_mgr_set_cleared(bo->resource); + dma_resv_add_fence(&bo->base._resv, fence, DMA_RESV_USAGE_KERNEL); + dma_fence_put(fence); - dma_resv_unlock(bo->base.resv); +out: + dma_resv_unlock(&bo->base._resv); } /**