* Re: Patch "drm/amdkfd: Move dma unmapping after TLB flush" has been added to the 6.6-stable tree
[not found] <20240820120055.2972871-1-sashal@kernel.org>
@ 2024-08-20 15:58 ` Felix Kuehling
2024-08-27 12:39 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Felix Kuehling @ 2024-08-20 15:58 UTC (permalink / raw)
To: stable, stable-commits, Philip.Yang
Cc: Alex Deucher, Christian König, Xinhui Pan, David Airlie,
Daniel Vetter
This patch introduced a regression. If you want to backport it, I'd recommend including this fix as well:
commit 9c29282ecbeeb1b43fced3055c6a5bb244b9390b
Author: Lang Yu <Lang.Yu@amd.com>
Date: Thu Jan 11 12:27:07 2024 +0800
drm/amdkfd: reserve the BO before validating it
Fix a warning.
v2: Avoid unmapping attachment repeatedly when ERESTARTSYS.
v3: Lock the BO before accessing ttm->sg to avoid race conditions.(Felix)
[ 41.708711] WARNING: CPU: 0 PID: 1463 at drivers/gpu/drm/ttm/ttm_bo.c:846 ttm_bo_validate+0x146/0x1b0 [ttm]
[ 41.708989] Call Trace:
[ 41.708992] <TASK>
[ 41.708996] ? show_regs+0x6c/0x80
[ 41.709000] ? ttm_bo_validate+0x146/0x1b0 [ttm]
[ 41.709008] ? __warn+0x93/0x190
[ 41.709014] ? ttm_bo_validate+0x146/0x1b0 [ttm]
[ 41.709024] ? report_bug+0x1f9/0x210
[ 41.709035] ? handle_bug+0x46/0x80
[ 41.709041] ? exc_invalid_op+0x1d/0x80
[ 41.709048] ? asm_exc_invalid_op+0x1f/0x30
[ 41.709057] ? amdgpu_amdkfd_gpuvm_dmaunmap_mem+0x2c/0x80 [amdgpu]
[ 41.709185] ? ttm_bo_validate+0x146/0x1b0 [ttm]
[ 41.709197] ? amdgpu_amdkfd_gpuvm_dmaunmap_mem+0x2c/0x80 [amdgpu]
[ 41.709337] ? srso_alias_return_thunk+0x5/0x7f
[ 41.709346] kfd_mem_dmaunmap_attachment+0x9e/0x1e0 [amdgpu]
[ 41.709467] amdgpu_amdkfd_gpuvm_dmaunmap_mem+0x56/0x80 [amdgpu]
[ 41.709586] kfd_ioctl_unmap_memory_from_gpu+0x1b7/0x300 [amdgpu]
[ 41.709710] kfd_ioctl+0x1ec/0x650 [amdgpu]
[ 41.709822] ? __pfx_kfd_ioctl_unmap_memory_from_gpu+0x10/0x10 [amdgpu]
[ 41.709945] ? srso_alias_return_thunk+0x5/0x7f
[ 41.709949] ? tomoyo_file_ioctl+0x20/0x30
[ 41.709959] __x64_sys_ioctl+0x9c/0xd0
[ 41.709967] do_syscall_64+0x3f/0x90
[ 41.709973] entry_SYSCALL_64_after_hwframe+0x6e/0xd8
Fixes: 101b8104307e ("drm/amdkfd: Move dma unmapping after TLB flush")
Signed-off-by: Lang Yu <Lang.Yu@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Regards,
Felix
On 2024-08-20 8:00, Sasha Levin wrote:
> This is a note to let you know that I've just added the patch titled
>
> drm/amdkfd: Move dma unmapping after TLB flush
>
> to the 6.6-stable tree which can be found at:
> http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
>
> The filename of the patch is:
> drm-amdkfd-move-dma-unmapping-after-tlb-flush.patch
> and it can be found in the queue-6.6 subdirectory.
>
> If you, or anyone else, feels it should not be added to the stable tree,
> please let <stable@vger.kernel.org> know about it.
>
>
>
> commit 23f8ef0f6e5deee5814fda6ec2e2ee4c2f19a384
> Author: Philip Yang <Philip.Yang@amd.com>
> Date: Mon Sep 11 14:44:22 2023 -0400
>
> drm/amdkfd: Move dma unmapping after TLB flush
>
> [ Upstream commit 101b8104307eac734f2dfa4d3511430b0b631c73 ]
>
> Otherwise GPU may access the stale mapping and generate IOMMU
> IO_PAGE_FAULT.
>
> Move this to inside p->mutex to prevent multiple threads mapping and
> unmapping concurrently race condition.
>
> After kfd_mem_dmaunmap_attachment is removed from unmap_bo_from_gpuvm,
> kfd_mem_dmaunmap_attachment is called if failed to map to GPUs, and
> before free the mem attachment in case failed to unmap from GPUs.
>
> Signed-off-by: Philip Yang <Philip.Yang@amd.com>
> Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> index 2fe9860725bd9..5e4fb33b97351 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> @@ -303,6 +303,7 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(struct amdgpu_device *adev,
> struct kgd_mem *mem, void *drm_priv);
> int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(
> struct amdgpu_device *adev, struct kgd_mem *mem, void *drm_priv);
> +void amdgpu_amdkfd_gpuvm_dmaunmap_mem(struct kgd_mem *mem, void *drm_priv);
> int amdgpu_amdkfd_gpuvm_sync_memory(
> struct amdgpu_device *adev, struct kgd_mem *mem, bool intr);
> int amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel(struct kgd_mem *mem,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index 62c1dc9510a41..c2d1d57a6c668 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -733,7 +733,7 @@ kfd_mem_dmaunmap_sg_bo(struct kgd_mem *mem,
> enum dma_data_direction dir;
>
> if (unlikely(!ttm->sg)) {
> - pr_err("SG Table of BO is UNEXPECTEDLY NULL");
> + pr_debug("SG Table of BO is NULL");
> return;
> }
>
> @@ -1202,8 +1202,6 @@ static void unmap_bo_from_gpuvm(struct kgd_mem *mem,
> amdgpu_vm_clear_freed(adev, vm, &bo_va->last_pt_update);
>
> amdgpu_sync_fence(sync, bo_va->last_pt_update);
> -
> - kfd_mem_dmaunmap_attachment(mem, entry);
> }
>
> static int update_gpuvm_pte(struct kgd_mem *mem,
> @@ -1258,6 +1256,7 @@ static int map_bo_to_gpuvm(struct kgd_mem *mem,
>
> update_gpuvm_pte_failed:
> unmap_bo_from_gpuvm(mem, entry, sync);
> + kfd_mem_dmaunmap_attachment(mem, entry);
> return ret;
> }
>
> @@ -1862,8 +1861,10 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
> mem->va + bo_size * (1 + mem->aql_queue));
>
> /* Remove from VM internal data structures */
> - list_for_each_entry_safe(entry, tmp, &mem->attachments, list)
> + list_for_each_entry_safe(entry, tmp, &mem->attachments, list) {
> + kfd_mem_dmaunmap_attachment(mem, entry);
> kfd_mem_detach(entry);
> + }
>
> ret = unreserve_bo_and_vms(&ctx, false, false);
>
> @@ -2037,6 +2038,23 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
> return ret;
> }
>
> +void amdgpu_amdkfd_gpuvm_dmaunmap_mem(struct kgd_mem *mem, void *drm_priv)
> +{
> + struct kfd_mem_attachment *entry;
> + struct amdgpu_vm *vm;
> +
> + vm = drm_priv_to_vm(drm_priv);
> +
> + mutex_lock(&mem->lock);
> +
> + list_for_each_entry(entry, &mem->attachments, list) {
> + if (entry->bo_va->base.vm == vm)
> + kfd_mem_dmaunmap_attachment(mem, entry);
> + }
> +
> + mutex_unlock(&mem->lock);
> +}
> +
> int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(
> struct amdgpu_device *adev, struct kgd_mem *mem, void *drm_priv)
> {
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index d33ba4fe9ad5b..045280c2b607c 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -1432,17 +1432,21 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file *filep,
> goto sync_memory_failed;
> }
> }
> - mutex_unlock(&p->mutex);
>
> - if (flush_tlb) {
> - /* Flush TLBs after waiting for the page table updates to complete */
> - for (i = 0; i < args->n_devices; i++) {
> - peer_pdd = kfd_process_device_data_by_id(p, devices_arr[i]);
> - if (WARN_ON_ONCE(!peer_pdd))
> - continue;
> + /* Flush TLBs after waiting for the page table updates to complete */
> + for (i = 0; i < args->n_devices; i++) {
> + peer_pdd = kfd_process_device_data_by_id(p, devices_arr[i]);
> + if (WARN_ON_ONCE(!peer_pdd))
> + continue;
> + if (flush_tlb)
> kfd_flush_tlb(peer_pdd, TLB_FLUSH_HEAVYWEIGHT);
> - }
> +
> + /* Remove dma mapping after tlb flush to avoid IO_PAGE_FAULT */
> + amdgpu_amdkfd_gpuvm_dmaunmap_mem(mem, peer_pdd->drm_priv);
> }
> +
> + mutex_unlock(&p->mutex);
> +
> kfree(devices_arr);
>
> return 0;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Patch "drm/amdkfd: Move dma unmapping after TLB flush" has been added to the 6.6-stable tree
2024-08-20 15:58 ` Patch "drm/amdkfd: Move dma unmapping after TLB flush" has been added to the 6.6-stable tree Felix Kuehling
@ 2024-08-27 12:39 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2024-08-27 12:39 UTC (permalink / raw)
To: Felix Kuehling
Cc: stable, stable-commits, Philip.Yang, Alex Deucher,
Christian König, Xinhui Pan, David Airlie, Daniel Vetter
On Tue, Aug 20, 2024 at 11:58:30AM -0400, Felix Kuehling wrote:
> This patch introduced a regression. If you want to backport it, I'd recommend including this fix as well:
>
> commit 9c29282ecbeeb1b43fced3055c6a5bb244b9390b
Wrong git id :(
Or right one, but the amd graphics tree is so messed up it's hard to
tell, there's a different commit with the same content but different id.
{sigh}
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-27 12:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20240820120055.2972871-1-sashal@kernel.org>
2024-08-20 15:58 ` Patch "drm/amdkfd: Move dma unmapping after TLB flush" has been added to the 6.6-stable tree Felix Kuehling
2024-08-27 12:39 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox