FAILED: patch "[PATCH] amdkfd: Fix memory availability double accounting of kfd pinned objects" failed to apply to 6.6-stable tree
Subsystems (4)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 16df12d7158fb55f20d6e985abd1996cbabab9f8
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 16df12d7158fb55f20d6e985abd1996cbabab9f8 Mon Sep 17 00:00:00 2001
From: Daniel Phillips <[email protected]>
Date: Sun, 5 Mar 2023 22:54:35 -0800
Subject: [PATCH] amdkfd: Fix memory availability double accounting of kfd
pinned objects
Pinned objects that are not kfd objects reduce the total vram available to kfd, so we subtract the total size of pinned objects from kdf vram availability. However this double counts objects pinned by kfd itself, because they are counted both as used and pinned. So track the total size of objects pinned by kfd and add it back to kfd availability to remove the double accounting.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 11 +++++++++++ 2 files changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
@@ -106,6 +106,7 @@ struct amdgpu_kfd_dev {struct kfd_dev *dev;int64_t vram_used[MAX_XCP ];uint64_t vram_used_aligned[MAX_XCP ]; +atomic64_t vram_pinned;bool init_complete;struct work_struct reset_work;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +11 -0
@@ -1536,6 +1536,11 @@ static int amdgpu_amdkfd_gpuvm_pin_bo(struct amdgpu_bo *bo, u32 domain)pr_err ("Error in Pinning BO to domain: %d\n" , domain);amdgpu_bo_sync_wait (bo,AMDGPU_FENCE_OWNER_KFD , false); + +if (!ret && bo->tbo.resource->mem_type ==TTM_PL_VRAM ) +atomic64_add (amdgpu_bo_size (bo), + &amdgpu_ttm_adev (bo->tbo.bdev)->kfd.vram_pinned); + out:amdgpu_bo_unreserve (bo);return ret;
@@ -1558,6 +1563,11 @@ static void amdgpu_amdkfd_gpuvm_unpin_bo(struct amdgpu_bo *bo)return ;amdgpu_bo_unpin (bo); + +if (bo->tbo.resource->mem_type ==TTM_PL_VRAM ) +atomic64_sub (amdgpu_bo_size (bo), + &amdgpu_ttm_adev (bo->tbo.bdev)->kfd.vram_pinned); +amdgpu_bo_unreserve (bo); }
@@ -1679,6 +1689,7 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev, vram_available =KFD_XCP_MEMORY_SIZE (adev, xcp_id) - adev->kfd.vram_used_aligned[xcp_id] -atomic64_read (&adev->vram_pin_size) + +atomic64_read (&adev->kfd.vram_pinned) - reserved_for_pt - reserved_for_ras;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 amdkfd: Fix memory availability double accounting of kfd pinned objects
From: Daniel Phillips <[email protected]>
[ Upstream commit 16df12d7158fb55f20d6e985abd1996cbabab9f8 ]
Pinned objects that are not kfd objects reduce the total vram available to kfd, so we subtract the total size of pinned objects from kdf vram availability. However this double counts objects pinned by kfd itself, because they are counted both as used and pinned. So track the total size of objects pinned by kfd and add it back to kfd availability to remove the double accounting.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 11 +++++++++++ 2 files changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
@@ -100,6 +100,7 @@ struct amdgpu_kfd_dev {struct kfd_dev *dev;int64_t vram_used[MAX_XCP ];uint64_t vram_used_aligned[MAX_XCP ]; +atomic64_t vram_pinned;bool init_complete;struct work_struct reset_work;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +11 -0
@@ -1432,6 +1432,11 @@ static int amdgpu_amdkfd_gpuvm_pin_bo(struct amdgpu_bo *bo, u32 domain)pr_err ("Error in Pinning BO to domain: %d\n" , domain);amdgpu_bo_sync_wait (bo,AMDGPU_FENCE_OWNER_KFD , false); + +if (!ret && bo->tbo.resource->mem_type ==TTM_PL_VRAM ) +atomic64_add (amdgpu_bo_size (bo), + &amdgpu_ttm_adev (bo->tbo.bdev)->kfd.vram_pinned); +amdgpu_bo_unreserve (bo);return ret;
@@ -1454,6 +1459,11 @@ static void amdgpu_amdkfd_gpuvm_unpin_bo(struct amdgpu_bo *bo)return ;amdgpu_bo_unpin (bo); + +if (bo->tbo.resource->mem_type ==TTM_PL_VRAM ) +atomic64_sub (amdgpu_bo_size (bo), + &amdgpu_ttm_adev (bo->tbo.bdev)->kfd.vram_pinned); +amdgpu_bo_unreserve (bo); }
@@ -1610,6 +1620,7 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev, vram_available =KFD_XCP_MEMORY_SIZE (adev, xcp_id) - adev->kfd.vram_used_aligned[xcp_id] -atomic64_read (&adev->vram_pin_size) + +atomic64_read (&adev->kfd.vram_pinned) - reserved_for_pt;if (adev->gmc.is_app_apu) {
Signature · 1 line
2.53.0