From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EFF6606A693 for ; Wed, 2 Dec 2026 22:36:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Q3eMK319 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AC7D61125A6; Wed, 2 Dec 2026 22:36:36 +0000 (UTC) Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8ED9B1125A8 for ; Wed, 2 Dec 2026 22:36:29 +0000 (UTC) Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-8b32daac9d7so2800137b3.0 for ; Wed, 02 Dec 2026 14:36:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796250988; x=1796855788; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JX19tL22q7VxqphBCfz6eSIG6iqegO/grquRYzMYKvI=; b=Q3eMK319hnpVH1/Vg2a6q9qoeLH7qCOSVsAvMErz2ASYVCEgcvT9wzzD0XhGvgJVPO okCy5tgP81vEoew9r39VPj2fzZRwwNp5yTph8bZOLe0Pp0DtE74xn5/FDh3CEQ4E/nLG nLb5jTwpM0Up4sOfSdm75JOinXf8/EzHwRGmfLTzw0FIIVyUv7LaU6+6BP2aPQNmBdky nhpmE6YtsyT9lSUIdrGkduUdzCyryl95fwAFF9akXXZbS4GOLhRdUOcKMJUZR//JhNgE EJUP7a4RO8z4907/C+SMGbacYzaejBKwBhNI5R4FP0awikfo9ADMaAotA33pCIkr3575 /qlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796250988; x=1796855788; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=JX19tL22q7VxqphBCfz6eSIG6iqegO/grquRYzMYKvI=; b=wGO6IFVIsNbfRTl1sDBZI5/8lLwrNxSpDRtQlTt9EIzimnRLhjE1ZmaYZVlLM/Nm6Y dhnqIdq2p+ufVqB7OPKBDG7RcTZWzkSPjIQQH34FgQ6/1l2rxIMKNVyPW5wmvfYxntFY wYCPPH0uhwoCshOr8wt9EOsZCfR2n6LS7d6XusXcW4v+Lw4R+NdLBPQ7V1/cfTvYetCd HPnhRJjMY65vAPN/oLDE9AnlKj+poS1kkRJRKLeIO2L990YcsjimRkXSpm2O6pUzKxuW GSo8WPCbrJmuetcvsv0p5BFm5daRCSo+8StBrlDj7OJHKpO5YKZDexWZRqGArY126Zo3 wXdw== X-Gm-Message-State: APuU4Z/dq9ErJcac/SpfwfLKiljxPuovsF7WpSH4g+mjANqZGtYQ3RkG kxkH4h+voxtFqCeE2hLPAozCCFVpfREINcU8c+68Jg2m2xvuoleLWHwa X-Gm-Gg: AZFdTZfhpaVVpCdxg9utvcXU1snCMKQYal1rUI4YCFJihX80mAjEEAEQOJOs7CTJiaV 5/LdJ0rEfqR+8rsAxS8t8OEMLSMvANWb/W6euW/GOob/N2VHYoXVC5plz1Scwl6B3bfvFKbymLX NtrpzI+huXVe6QUb1qkFiIKBWsR2dE9qpxfonncW+2aEcaOEdXvnn4S2c7iNUimOuRoNOJ2d6Te GV8uDmGnKQAwzSGeC1zGHZ47A1HdCMcHVBu2s8d/GNEIunmxOY7dWzmGqhkDqPer/R9lqD4088U FHx+AZWH1Y2VEPU6VjMdJ10jSVj87UCHJDaHc3dFTHQ54XufvG9LOHHcPeOAB7Qu0s2NTaRp3R3 LdqcyLu7jkxegJX4B9wNDfRYAtyjTJnr8RATndI7aLEA9OPjEjrQ1G3jb05SPk8ewKg+JoT+EI5 3tveys7FdrXeA0Y0Vmh2BoZJgxMs6kAJYd6stg7GJUfHIW9w2hT3Y98ZuOEozdPjcUqK0D91zeU LExuQb54ts30LWQDAomyAMxB7tSm7/5nhg70+3jAWpCsC1XmPanKR/nIKrmaMgc01vVyVEDJrJv hAhxqgcRdttvunkiUIyY+l3eaden4fEy55JBrSHFhlR/U+Fofqgsm6K5j35HFWlYUqzSDxJSCEV F4e4Af6aM5JM7dDowBxD3Zz3mDEo+M+3SnsOyte+HWZoJA2Gj5InhQgBfmKtpHF9K15KDkurAG3 EmDqOz7EQ8JQzJDRPORQ== X-Received: by 2002:a05:690c:f0a:b0:8b5:d324:ee1c with SMTP id 00721157ae682-8b5f59666b2mr1540257b3.6.1796250988464; Wed, 02 Dec 2026 14:36:28 -0800 (PST) Received: from localhost (107-220-129-194.lightspeed.chrlnc.sbcglobal.net. [107.220.129.194]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b520354770sm166887387b3.42.2026.12.02.14.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 14:36:27 -0800 (PST) From: Matt Turner Date: Wed, 02 Dec 2026 17:36:14 -0500 Subject: [PATCH 08/14] drm/amdgpu: copy the IB contents when the hang is detected X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-amdgpu-devcoredump-v1-8-3dfa0e033b97@gmail.com> References: <20261202-amdgpu-devcoredump-v1-0-3dfa0e033b97@gmail.com> In-Reply-To: <20261202-amdgpu-devcoredump-v1-0-3dfa0e033b97@gmail.com> To: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Sunil Khatri , Trigger Huang Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Matt Turner , Gregoire Pean X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=14865; i=mattst88@gmail.com; h=from:subject:message-id; bh=ihIdBUj+tnS/72e8dz/2qHnRurMbuPSAJur3Zlqv0+o=; b=owGbwMvMwCW25rVmCc8sv+mMp9WSGLIF5kbYu2ZrL96nes/qHLd5ukCp+e82Rlue6K2bWGs26 nbKSC7t+MjCIMbFMFNMkSVuvSLLrLYdS31OS/+CmcPKBDJEWqSBAQhYGPhyE/NKjXSM9Ey1DfUM gQwdo3iInB6DRmZxcWlqkW5aQZFDXn5JYklmfl6xXn5Bal5BeoFeWmZaSUZGflFxKtAIvbzUElN XRzcjQwMTS0cLMycLR1MTZ2cnQyc3R0dnVycjS3MTA2dLRxNXS3MGLk4BmGum7GZkOLk87OJRg/ 6sC1dXMPJZCEcLLFecUJh5rKxrM/+OCvXoNIb/vs2aMy9uND/awLKMSfL+Z5a28HM/hIt32hv3X Zx265QUBwA= X-Developer-Key: i=mattst88@gmail.com; a=openpgp; fpr=3BB639E56F861FA2E86505690FDD682D974CA72A X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "amd-gfx" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 amdgpu_coredump() is called from the job timeout handler before soft recovery and queue reset, but the IB contents are only read later from the coredump worker, which runs concurrently with recovery. By then the process may have been killed and its BOs freed or evicted, or a reset may have lost VRAM, so the dump either has no IB contents or contents that no longer match what the GPU was executing. Copy the IBs from amdgpu_coredump() itself, after the ring contents. The timeout and reset paths are dma_fence signaling critical sections, so look up the VM with a new amdgpu_vm_trylock_by_pasid() that trylocks the root PD under the PASID lock, trylock IB BOs that do not share its reservation object, and allocate with GFP_NOWAIT. VRAM is only read through the CPU visible aperture there, since reading CPU invisible VRAM through MM_INDEX/MM_DATA would hold up recovery, and system pages that would need ttm_bo_kmap() are not read either. IBs that cannot be copied for any of these reasons are retried from the worker as before, and are marked in the dump as captured after recovery started. Skip IBs larger than 4 MiB, since a GFP_NOWAIT allocation that large is unlikely to succeed anyway. The copy runs in the timeout handler and delays recovery, and a job can have up to 192 IBs, so copy at most 8 MiB in total there and leave the rest to the worker. Suggested-by: Gregoire Pean Signed-off-by: Matt Turner --- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 168 ++++++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 35 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 + 4 files changed, 186 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c index c3f01acc0e8c..033e1b94fcd7 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c @@ -47,6 +47,15 @@ void amdgpu_coredump_fini(struct amdgpu_device *adev) #define AMDGPU_CORE_DUMP_SIZE_MAX (256 * 1024 * 1024) +/* Larger IBs are not copied into the coredump. */ +#define AMDGPU_COREDUMP_IB_MAX_BYTES SZ_4M + +/* + * Copying at hang time delays recovery, so only this much is copied then. The + * rest is left for the worker. + */ +#define AMDGPU_COREDUMP_NOWAIT_MAX_BYTES SZ_8M + const char *hw_ip_names[MAX_HWIP] = { [GC_HWIP] = "GC", [HDP_HWIP] = "HDP", @@ -242,9 +251,14 @@ static bool amdgpu_devcoredump_tt_linear_ok(struct ttm_tt *ttm) * reservation. VRAM is read 4 KiB at a time, which bounds how long the * MM_INDEX/MM_DATA fallback for CPU invisible VRAM keeps interrupts disabled * whatever the page size. + * + * With @nowait, which the timeout and reset paths use, nothing sleeps, and + * VRAM is only read through the CPU visible aperture: reading CPU invisible + * VRAM a dword at a time would hold up recovery, so it fails with -EBUSY and + * is left for the worker, as do system pages that need ttm_bo_kmap(). */ static int amdgpu_devcoredump_read_bo(struct amdgpu_bo *abo, u64 offset, - void *dst, u64 size) + void *dst, u64 size, bool nowait) { struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev); struct ttm_resource *res = abo->tbo.resource; @@ -267,11 +281,17 @@ static int amdgpu_devcoredump_read_bo(struct amdgpu_bo *abo, u64 offset, while (cursor.remaining) { u64 len = min_t(u64, cursor.size, SZ_4K); - amdgpu_device_vram_access(adev, cursor.start, dst, len, - false); + if (!nowait) + amdgpu_device_vram_access(adev, cursor.start, dst, + len, false); + else if (!adev->mman.aper_base_kaddr || + amdgpu_device_aper_access(adev, cursor.start, dst, + len, false) != len) + return -EBUSY; dst += len; amdgpu_res_next(&cursor, len); - cond_resched(); + if (!nowait) + cond_resched(); } return 0; } @@ -288,6 +308,9 @@ static int amdgpu_devcoredump_read_bo(struct amdgpu_bo *abo, u64 offset, if (!amdgpu_devcoredump_tt_linear_ok(ttm)) { pgoff_t first = offset >> PAGE_SHIFT; + if (nowait) + return -EBUSY; + r = ttm_bo_kmap(&abo->tbo, first, PFN_UP(offset + size) - first, &map); if (r) @@ -314,7 +337,8 @@ static int amdgpu_devcoredump_read_bo(struct amdgpu_bo *abo, u64 offset, dst += len; offset += len; size -= len; - cond_resched(); + if (!nowait) + cond_resched(); } return 0; default: @@ -324,13 +348,16 @@ static int amdgpu_devcoredump_read_bo(struct amdgpu_bo *abo, u64 offset, /* * Copy a range of GPU memory, which must lie within a single mapping, into a - * newly allocated buffer. The VM root PD and the BO behind the mapping must be - * reserved by the caller. + * newly allocated buffer. The VM root PD must be reserved by the caller. With + * @nowait the BO behind the mapping is trylocked here unless it shares the + * root PD's reservation object; otherwise the caller must have reserved it. */ static int amdgpu_devcoredump_copy_blob(struct amdgpu_vm *vm, - struct amdgpu_coredump_blob *blob) + struct amdgpu_coredump_blob *blob, + bool nowait) { struct amdgpu_bo_va_mapping *mapping; + struct dma_resv *resv = NULL; struct amdgpu_bo *abo; u64 offset; void *data; @@ -348,11 +375,24 @@ static int amdgpu_devcoredump_copy_blob(struct amdgpu_vm *vm, mapping->offset; /* amdgpu_device_vram_access() can fail without telling us. */ - data = kvzalloc(blob->size, GFP_KERNEL | __GFP_NOWARN); + data = kvzalloc(blob->size, + (nowait ? GFP_NOWAIT : GFP_KERNEL) | __GFP_NOWARN); if (!data) return -ENOMEM; - r = amdgpu_devcoredump_read_bo(abo, offset, data, blob->size); + if (nowait && abo->tbo.base.resv != vm->root.bo->tbo.base.resv) { + if (!dma_resv_trylock(abo->tbo.base.resv)) { + kvfree(data); + return -EBUSY; + } + resv = abo->tbo.base.resv; + } + + r = amdgpu_devcoredump_read_bo(abo, offset, data, blob->size, nowait); + + if (resv) + dma_resv_unlock(resv); + if (r) { kvfree(data); return r; @@ -363,18 +403,86 @@ static int amdgpu_devcoredump_copy_blob(struct amdgpu_vm *vm, } /* - * Copy the contents of the IBs of the hung job, blocking on the reservation - * locks as needed. This runs from the coredump worker, before formatting, so - * that both formatting passes see the same data. + * Whether a capture that failed with @status, or with -EAGAIN was not tried + * yet, could succeed in the worker. */ -static void amdgpu_devcoredump_capture_vm(struct amdgpu_coredump_info *coredump) +static bool amdgpu_devcoredump_status_retry(int status) +{ + return status == -EAGAIN || status == -EBUSY || status == -ENOMEM; +} + +static bool amdgpu_devcoredump_blob_retry(struct amdgpu_coredump_blob *blob) +{ + return !blob->data && amdgpu_devcoredump_status_retry(blob->status); +} + +/* Copy @blob at hang time if it fits in what is left of @budget. */ +static void amdgpu_devcoredump_copy_blob_nowait(struct amdgpu_vm *vm, + struct amdgpu_coredump_blob *blob, + u64 *budget) +{ + if (blob->status != -EAGAIN || blob->size > *budget) + return; + + *budget -= blob->size; + blob->status = amdgpu_devcoredump_copy_blob(vm, blob, true); +} + +/* + * Capture the state of the hung job's VM at the time the hang is detected, + * before soft recovery, queue reset or a full GPU reset change it. This runs + * in the job timeout or GPU reset path, which is a dma_fence signaling + * critical section, so it must not block on reservation locks or allocate + * memory that may wait on reclaim: everything is trylocked, and what cannot + * be copied here is retried from the worker. + */ +static void +amdgpu_devcoredump_capture_vm_nowait(struct amdgpu_device *adev, + struct amdgpu_coredump_info *coredump) +{ + u64 budget = AMDGPU_COREDUMP_NOWAIT_MAX_BYTES; + struct amdgpu_vm *vm; + + vm = amdgpu_vm_trylock_by_pasid(adev, coredump->pasid); + if (IS_ERR(vm)) { + for (int i = 0; i < coredump->num_ibs; i++) { + struct amdgpu_coredump_blob *blob = &coredump->ibs[i].blob; + + if (blob->status == -EAGAIN) + blob->status = PTR_ERR(vm); + } + return; + } + + for (int i = 0; i < coredump->num_ibs; i++) + amdgpu_devcoredump_copy_blob_nowait(vm, &coredump->ibs[i].blob, + &budget); + + dma_resv_unlock(vm->root.bo->tbo.base.resv); +} + +/* + * Retry what could not be captured at hang time, blocking on the reservation + * locks as needed. This runs from the coredump worker, by which point recovery + * may have modified or freed the memory, so the result is marked as captured + * late. + */ +static void +amdgpu_devcoredump_capture_vm_late(struct amdgpu_coredump_info *coredump) { struct amdgpu_bo_va_mapping *mapping; + struct amdgpu_coredump_blob *blob; struct amdgpu_bo *abo; struct drm_exec exec; struct amdgpu_vm *vm; + bool retry = false; int r = 0; + for (int i = 0; i < coredump->num_ibs; i++) + retry |= amdgpu_devcoredump_blob_retry(&coredump->ibs[i].blob); + if (!retry) + return; + /* * Lock the VM root PD and every IB BO together in a single drm_exec * ticket. Reserving the IB BOs one by one while the root PD is held @@ -394,8 +502,11 @@ static void amdgpu_devcoredump_capture_vm(struct amdgpu_coredump_info *coredump) } for (int i = 0; i < coredump->num_ibs; i++) { - mapping = amdgpu_vm_bo_lookup_mapping(vm, - coredump->ibs[i].blob.va); + blob = &coredump->ibs[i].blob; + if (!amdgpu_devcoredump_blob_retry(blob)) + continue; + + mapping = amdgpu_vm_bo_lookup_mapping(vm, blob->va); abo = amdgpu_devcoredump_mapping_bo(mapping); if (!abo) continue; @@ -408,17 +519,23 @@ static void amdgpu_devcoredump_capture_vm(struct amdgpu_coredump_info *coredump) } for (int i = 0; i < coredump->num_ibs; i++) { - struct amdgpu_coredump_blob *blob = &coredump->ibs[i].blob; + blob = &coredump->ibs[i].blob; + if (!amdgpu_devcoredump_blob_retry(blob)) + continue; - blob->status = amdgpu_devcoredump_copy_blob(vm, blob); + blob->status = amdgpu_devcoredump_copy_blob(vm, blob, false); + blob->late = !blob->status; } unlock: drm_exec_fini(&exec); if (r) { - for (int i = 0; i < coredump->num_ibs; i++) - coredump->ibs[i].blob.status = r; + for (int i = 0; i < coredump->num_ibs; i++) { + blob = &coredump->ibs[i].blob; + if (amdgpu_devcoredump_blob_retry(blob)) + blob->status = r; + } } } @@ -434,6 +551,9 @@ static void amdgpu_devcoredump_print_blob(struct drm_printer *p, return; } + if (blob->late) + drm_printf(p, "contents captured after recovery started\n"); + for (u64 i = 0; i < blob->size / 4; i++) drm_printf(p, "0x%08x\n", dw[i]); } @@ -651,7 +771,7 @@ static void amdgpu_devcoredump_deferred_work(struct work_struct *work) goto end; if (coredump->num_ibs) - amdgpu_devcoredump_capture_vm(coredump); + amdgpu_devcoredump_capture_vm_late(coredump); /* Do a one-time preparation of the coredump output because * repeatingly calling drm_coredump_printer is very slow. @@ -765,6 +885,9 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, ib->ib_size_dw = job->ibs[i].length_dw; ib->blob.va = ib->gpu_addr & AMDGPU_GMC_HOLE_MASK; ib->blob.size = (u64)ib->ib_size_dw * 4; + ib->blob.status = + ib->blob.size > AMDGPU_COREDUMP_IB_MAX_BYTES ? + -EFBIG : -EAGAIN; } } @@ -812,6 +935,9 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, coredump->num_rings = idx; } + if (coredump->num_ibs) + amdgpu_devcoredump_capture_vm_nowait(adev, coredump); + coredump->adev = adev; ktime_get_ts64(&coredump->reset_time); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h index ffcb08428631..d62031369e56 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h @@ -46,6 +46,8 @@ struct amdgpu_coredump_blob { /* contents, or NULL with the reason in status */ void *data; int status; + /* copied by the worker rather than when the hang was detected */ + bool late; }; struct amdgpu_coredump_ib_info { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index a627a3092990..b03f3ee4d78c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -3106,6 +3106,41 @@ struct amdgpu_vm *amdgpu_vm_lock_by_pasid(struct amdgpu_device *adev, return vm; } +/** + * amdgpu_vm_trylock_by_pasid - look up a VM by PASID and trylock its root PD + * @adev: amdgpu device pointer + * @pasid: PASID of the VM + * + * Like amdgpu_vm_lock_by_pasid(), but never sleeps, so it can be used from + * the job timeout and GPU reset paths. The root PD is trylocked under the + * PASID lock, and holding its reservation keeps the VM alive without a + * reference: amdgpu_driver_postclose_kms() clears the PASID's owner before + * amdgpu_vm_fini() reserves the root PD to free it. On success the caller + * must unlock vm->root.bo with dma_resv_unlock(). + * + * Return: the VM on success, ERR_PTR(-ESRCH) if the PASID has no VM, or + * ERR_PTR(-EBUSY) if the root PD is contended. + */ +struct amdgpu_vm *amdgpu_vm_trylock_by_pasid(struct amdgpu_device *adev, + u32 pasid) +{ + struct amdgpu_vm *vm = ERR_PTR(-ESRCH); + struct amdgpu_fpriv *fpriv; + unsigned long irqflags; + + amdgpu_pasid_lock(&irqflags); + fpriv = amdgpu_pasid_get_fpriv_locked(pasid); + if (fpriv && fpriv->vm.root.bo) { + if (dma_resv_trylock(fpriv->vm.root.bo->tbo.base.resv)) + vm = &fpriv->vm; + else + vm = ERR_PTR(-EBUSY); + } + amdgpu_pasid_unlock(irqflags); + + return vm; +} + /** * amdgpu_vm_handle_fault - graceful handling of VM faults. * @adev: amdgpu device pointer diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h index f6285a9d9e98..10fd477f7765 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h @@ -529,6 +529,8 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid, struct amdgpu_vm *amdgpu_vm_lock_by_pasid(struct amdgpu_device *adev, u32 pasid, struct drm_exec *exec); +struct amdgpu_vm *amdgpu_vm_trylock_by_pasid(struct amdgpu_device *adev, + u32 pasid); void amdgpu_vm_set_task_info(struct amdgpu_vm *vm); -- 2.56.1