From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796250990; b=pZKTCEHWUrlQ1xoIMIHPEaqTWa82HW0SoIAffypiuo3dStYb70LoSfhXRptAXuQ/NFiP 5nW3mTNaqxuq7S+o9Me6P4AkD1Q2zRKFjvqKr18mwxDxRCXjLWJZC2UZF/KsGzfPPv/MW LYTtUOQrDviD63/nUFAVdy9PWWmYV8+OMG/koeYL8d0KPNgCwwKUbFVHmdIZmsd2VfBaa ofBXojx58ecen3MrKACk4q8l0+cCb5o7FssVKPJfSF9NKK6f7RX0Fbcnrf9kVIxGDjQ2L Rc889v5Szcf3ASbkVm4puYl+YHLTo+A3YuTS8u3Hq9FOoiflTg5ZuLdZOZ+wchf9AXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796250990; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=JX19tL22q7VxqphBCfz6eSIG6iqegO/grquRYzMYKvI=; b=4BPX5lE7WohS3yWqFZFEIkMAR8/calWPOWziv05RNOZBgttWeeseXYN7CWMSIoHQIoGa K7+zMAlOlFBF6C8Cm44TNfLYC+ZJYO4dGGTbsu16TSZMBnrhozzm/r0T0rtVuCCfdhM6F RhRhxvK6/BguI0PNqPmKm+n1DavGJgsfBoVQdKgGZbGp9rnvb4RGtoAwJP6NY073mZdDf PxcsOG1YfdXfe4zW1kcOs8lmTcsGe0hPCgGRm6K0z7kdIWxbvoqWVIQ/cBZnhtcsnpsrV Dw9YQN4gv85zOz+x5SpYDjrHA+tV49noWz33Nv++/4PTk+8IwqMNi8YiMKuUQ4oQqiA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=p9cWV97K; arc=none smtp.remote-ip=209.85.128.178 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B50E606A69D for ; Wed, 2 Dec 2026 22:36:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7B50E606A69D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=p9cWV97K Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-8b4d07494b0so4149147b3.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=vger.kernel.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=p9cWV97KOeVWBWSUWpqgDO2akpjVwRGv8lnywI2OjCaaqfV1Q/i0u3Kg7DGBvQJTYi h96mz1iWgBBYPhg4SDl4IAV3fYfHKrqMtDDN+mVMMqsVCsgOLyF9Qny0VCOO1wTn5t5R mN0M1woTRi72jQH/aShqLtMKxa/7Cnu7l1enyYvA6us5reysTgsfaig4Mp6ItT4HhOft JxOacxNTAROKaoCITcqZfyc1cQXdZ38X6nP0XAcPPtqh6TdlQrCX9+deiNRpcMEgR+xq UkHqSLfdmhEZqLdgnwjtc4x8wAeeJAkmQ2ZFKNqh51RYzwRE0OLe994mMG/W2hTGkmjq a52w== 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=XrswbVaqLB7J+Oym1oC52NtRfUgE8ZJ1J8Uii2yZrWVy7G9y5oj2IxSRIqVns/7LCv WKCBtHiLi8U2Y3v6xHCGqjx1qT5PiHoQHcjpVB5s+mJlX8VPADaJL36Yxt+aAWuvOKF2 BsJWriFpgdXp+ya6toqDmKc4Hqp1vAmn9AMmcrfSumhEfnbgzGG1pYzkx3Mu3kdXmNBu ZsevAN1tLjBiAyowbTWdQD3ZxH6M5wvBZHsPEFwRUPzPNpE9SeOqy0NP3iJeGTyaPCa6 4wm5XEopu9uL56eCEUorykhbCmVN2pQnw62N4coZfe7+/K2IZj4xrUsFbvjr9MLu4oOe obCQ== X-Forwarded-Encrypted: i=1; AL+hErFpI6Sh30i8XN+RStHAHA5g8+n66XScVl5O1HKtj+McShQH5HMTGUlG3QEC5JPFRRCjyRbRfLPo/u9bEBM=@vger.kernel.org X-Gm-Message-State: APuU4Z/gLzBrEOcTYOPGhClOyjtnF2LW+g9zcpcX9Vu0saPcJh16wBrD PzFd2NzG15raYz336MvPj9hG9jv3kwJITHsptWBWJaDXpy99YIDfze19 X-Gm-Gg: AZFdTZfWS+BBATYaDiDyfKyoRxydeUekpF5OZwIg6QXe1nS/LgupxgYQp395phQd8F5 ufoJEfgTIaxKlV498E7HjAGvpJneCtkOb2bhvJBmx3Ldta08RVLsLXT2VK3IXN8phCgaY9U21eT tv65TM33p5cx7B+ebCLPmWDJy8wpU/erfr47b1+U5xbFdwBinqiboCQKdtlcqhMH+OfVPSlcIK2 y23U64YpwdV36WKjC7ozCzOO52DWxeep2JHAWfahdNnvXfGsJdOnAAUv0JmGTegYaw3Qmk/8N1Z +LeonnP+Xp1p4Fa/PK340M2IOKSjr/28XMpF/hPbcOTQgBaqm7pnpz6cHWym8sltax80I1zdOC4 G1/vPbZplUlmKqZH6wfH3wzE/3GIGmv1wYPcMu0Ss1pzxv0ge0nid/Pargl9vIkmhebfs4E3AQd jp4nW8gSS3fo9wuiiTYIZh2KaUHFZkE//7U48mCWU97VkE9uAFU7tQnsyW8E7tCbPtv++2Pu1UG eIJ+TxIJfO4kCuZR9ZEfaUExfUSU9VUJWZ3pS6k/lQUoLmfUVXlGjUGukeVnF38BvMnU7pIqrm2 YNlkfEBnJtXXvjbWVQjVMCZpq/BM6M+kBxjx4/vPck/FMUG1saMOH2ZgHuhizsTi2uq8xkqiEhw f0Qkgn3UWiK0sTGMYAxHoKFP+exbJm9KXsOdSWXf642ixsgU8ZsJ0OK+LozoekEp6WA05nZSVUK wC83r1uVJU+5yGY4srhQ== 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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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