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 19E10606A332 for ; Fri, 4 Dec 2026 18:41:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LNsU+0bW Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CC90410E830; Fri, 4 Dec 2026 18:41:37 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id D05C310E830 for ; Fri, 4 Dec 2026 18:41:30 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 82290445F6; Fri, 4 Dec 2026 18:41:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22B941F00A1F; Fri, 4 Dec 2026 18:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796409690; bh=GEQ1jGOsmh4hnmhIY6cuihtbYHNAHaDzaiPgMZb668w=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=LNsU+0bW6cAGDtUIhCQ7HU8ZAipBh39k4FenTbkjFnZHwQMKerAm/0E8ro7Il8azY oTOUpwJdU50W20nLHg+6ygFHVgGJDR5TzvjBSqA2MlXB3swBY0bK9f0xGaL9nYZweH KHiohalhzu/BLGbhgvu74fsmFBqu8Raa6S92DyEPhmgcdiCNz29LNc2vrvw+HqHxrV aWUV4xRpm8sSVgDxYij8AC8MOiMVGJKrRvys4cwwgYn1yS0wTUdpBffCHMUrYWc9zZ AVWhNf8b4DvuF4t5Ph4kPG6uji4yhk9tWgke5lssW2n8SaQWG0oX+SHGOpZiL5LV7w WL4WOxsUZVG6Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC 11/11] drm/xe/guc: Process VF GuC error state captures To: "Satyanarayana K V P" , intel-xe@lists.freedesktop.org In-Reply-To: <20261204144712.3520695-24-satyanarayana.k.v.p@intel.com> References: <20261204144712.3520695-13-satyanarayana.k.v.p@intel.com> <20261204144712.3520695-24-satyanarayana.k.v.p@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 18:41:29 +0000 X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Intel-xe" X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 X-Archived-By: Thank you for your contribution! Sashiko AI review found 14 potential issues to consider: - [High] drm/xe: union type confusion in devcoredump_snapshot() on SR-IOV PF - [High] drm/xe: xe_hw_engine_snapshot_capture() drops VF captures and leaks nodes - [Medium] drm/xe: devcoredump_snapshot() stalls TDR on hung or stopped VF GuC - [Medium] drm/xe/guc: NULL guc->ads.bo deref in guc_capture_process_output_vf() - [Medium] drm/xe/guc: unvalidated VF header bounds in guc_capture_process_output_vf() - [Medium] drm/xe/guc: guc_capture_process_output_vf() ignores wrap_offset and FULL flag - [Medium] drm/xe/guc: unconditional VF node prealloc in xe_guc_capture_init() - [Medium] drm/xe: unserialized xe_guc_mmio_send() from devcoredump_snapshot() - [Low] drm/xe: vf_log_capture_lock dropped before log BO copy in devcoredump - [Low] drm/xe: non-portable bitfields and struct version tag in guc_log_abi.h - [Low] drm/xe/guc: swapped overflow and full args in guc_capture_process_output_vf() - [Low] drm/xe/guc: non-portable bitfields and wrong DOC size in guc_log_abi.h - [Low] drm/xe: unused uc variable and unreachable VF check in xe_guc_capture.c - [Low] drm/xe: commit message omits VF GuC log request in devcoredump_snapshot() -- commit 4aa56cd4efff155a6869d4a8e1711b02a0d8fd3a Author: Satyanarayana K V P > drm/xe/guc: Process VF GuC error state captures > > Process the debug error state capture snapshot received from GuC for a VF. > Initialize the capture preallocated nodes for VFs and allow coredump > matching and engine snapshot collection to consume captures reported > for VF queues. > > Signed-off-by: Satyanarayana K V P [Severity: Low] Should the commit message mention the VF GuC event log snapshot request added to devcoredump_snapshot()? Calling xe_guc_log_vf_request_snapshot() populates guc->log.bo before xe_guc_log_snapshot_capture() copies it, which is separate from error state capture processing and may belong in its own commit or be described here. > diff --git a/drivers/gpu/drm/xe/abi/guc_log_abi.h b/drivers/gpu/drm/xe/ab= i/guc_log_abi.h > index fbf212d59a40e..58706b0e80c4c 100644 > --- a/drivers/gpu/drm/xe/abi/guc_log_abi.h > +++ b/drivers/gpu/drm/xe/abi/guc_log_abi.h [ ... ] > + * +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D+ 0000h > + * | Crash dump state header | ^ > + * +-------------------------------+ 32B | > + * | | | > + * | Reserved | 4KB [Severity: Low] Are the header label and size in this diagram accurate? This buffer holds error state capture rather than a crash dump, and struct guc_debug_snapshot_buffer_state_vf has nine u32 fields (36 bytes), not 32B. [ ... ] > +struct guc_debug_snapshot_buffer_state_vf { > + /** @marker: buffer state start marker */ > + u32 marker[2]; > + /** @version: The version of the this structure */ > + struct version { > + /** @version.minor: Minor version number */ > + u32 minor:8; > + /** @version.major: Major version number */ > + u32 major:8; > + /** @version.reserved: Reserved for future use */ > + u32 reserved:16; > + } __packed version; [Severity: Low] Should version be a plain u32 with GENMASK() definitions instead of a named bitfield struct? C bitfield ordering is endianness- and compiler-dependent (unlike the rest of drivers/gpu/drm/xe/abi/), and declaring a tagged struct version here exports that tag at file scope to every includer of this header. > diff --git a/drivers/gpu/drm/xe/xe_devcoredump.c b/drivers/gpu/drm/xe/xe_= devcoredump.c > index 7634246d77258..c9768842c6435 100644 > --- a/drivers/gpu/drm/xe/xe_devcoredump.c > +++ b/drivers/gpu/drm/xe/xe_devcoredump.c > @@ -678,6 +678,10 @@ static void devcoredump_snapshot(struct xe_devcoredu= mp *coredump, > =20 > CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL); > =20 > + /* We need request GuC log and keep it ready in the buffer */ > + if (xe_guc_log_vf_supported(&guc->log)) > + xe_guc_log_vf_request_snapshot(&guc->log); > + > cookie =3D dma_fence_begin_signalling(); [Severity: High] Can this trigger union type confusion and a NULL pointer dereference on an SR-IOV PF? devcoredump_snapshot() runs on native, PF, and VF devices, but xe_guc_log_vf_supported() reads gt->sriov.vf.debug_log.guc_log_enabled without checking IS_SRIOV_VF(). Because gt->sriov is a union of pf and vf, on a PF this reads an aliased byte from live gt->sriov.pf data. If that byte is non-zero, xe_guc_log_vf_request_snapshot() runs on the PF, where xe_guc_log_init() never initialized log->vf_log_capture_lock or log->vf_log_ready, hitting xe_gt_assert(gt, IS_SRIOV_VF(xe)) and crashing in wait_for_completion_timeout(). Checking IS_SRIOV_VF(gt_to_xe(gt)) inside xe_guc_log_vf_supported() would prevent this. [Severity: Medium] Can calling xe_guc_log_vf_request_snapshot() here stall TDR and GT reset recovery when the VF GuC is hung or stopped? guc_exec_queue_timedout_job() calls xe_devcoredump() right before xe_gt_reset_async(), including after a schedule-disable timeout or when xe_guc_read_stopped(guc) is already set. Without checking xe_guc_read_stopped(guc), this blocks under coredump->lock for up to GUC_LOG_VF_READY_TIMEOUT (5 seconds) waiting on CTB (or falls back to blocking MMIO HXG requests when CT is stopped), while also ignoring the return value. [Severity: Medium] Can the MMIO fallback in xe_guc_log_vf_request_snapshot() race with xe_uc_suspend() on the shared per-GT MMIO mailbox? CPU0 (PM suspend) CPU1 (gt->ordered_wq) xe_uc_suspend() uc_reset_wait() /* stopped=3D1 */ xe_uc_stop() xe_guc_ct_stop() guc_exec_queue_timedout_job() xe_devcoredump() devcoredump_snapshot() xe_guc_log_vf_request_snapshot() /* !ct_enabled -> MMIO path */ xe_guc_suspend() xe_guc_softreset() xe_guc_mmio_send() xe_guc_mmio_send() <-- concurrent VF_SW_FLAG use drm_sched_wqueue_stop() does not cancel sched->work_tdr, and xe_guc_mmio_send_recv() writes and polls VF_SW_FLAG / MED_VF_SW_FLAG without mutual exclusion. Overlapping requests can corrupt the mailbox exchange and fail xe_guc_softreset(), aborting suspend. [Severity: Low] Can log->bo be overwritten by GuC while devcoredump_snapshot() is copying it? xe_guc_log_vf_request_snapshot() drops log->vf_log_capture_lock before returning, while xe_guc_log_snapshot_capture() copies log->bo->vmap in chunks later in devcoredump_snapshot(). A concurrent debugfs guc_log read via xe_guc_log_vf_print() can request a new snapshot mid-copy, producing a torn log dump. > diff --git a/drivers/gpu/drm/xe/xe_guc_capture.c b/drivers/gpu/drm/xe/xe_= guc_capture.c > index 7e3b1bb234331..45bbc7cd48936 100644 > --- a/drivers/gpu/drm/xe/xe_guc_capture.c > +++ b/drivers/gpu/drm/xe/xe_guc_capture.c [ ... ] > @@ -1581,6 +1583,60 @@ static void __guc_capture_process_output(struct xe= _guc *guc) > __guc_capture_flushlog_complete(guc); > } > =20 > +static void guc_capture_process_output_vf(struct xe_guc *guc) > +{ > + struct guc_debug_snapshot_buffer_state_vf log_buf_state_local; > + struct xe_uc *uc =3D container_of(guc, typeof(*uc), guc); [Severity: Low] Is uc unused here? Also, now that xe_guc_capture_process() routes all VFs to guc_capture_process_output_vf(), the IS_SRIOV_VF() early return inside __guc_capture_process_output() is unreachable dead code and can be removed. [ ... ] > + xe_map_memcpy_from(guc_to_xe(guc), &log_buf_state_local, &guc->ads.bo->= vmap, > + log_buf_state_offset, sizeof(struct guc_debug_snapshot_buffer_stat= e_vf)); [Severity: Medium] Can guc->ads.bo be NULL here? guc_init_vf() always allocates guc->capture before calling xe_guc_ads_init(), which returns 0 early leaving ads->bo =3D=3D NULL when ads->capture_size is 0 (VF debug state capture disabled by the PF). If an unexpected capture G2H notification arrives, xe_guc_capture_process() only checks !guc->capture and reaches &guc->ads.bo->vmap, causing a NULL pointer dereference. [ ... ] > + /* Overflow and full count are for the dump parser. */ > + xe_gt_dbg(guc_to_gt(guc), "vf log-state: overflow =3D %lu full =3D %lu\= n", > + FIELD_GET(GUC_LOG_BUFFER_STATE_FULL, log_buf_state_local.flags), > + FIELD_GET(GUC_LOG_BUFFER_STATE_OVERFLOW, log_buf_state_local.flags)); [Severity: Low] Are the FIELD_GET() arguments swapped relative to the format string? The format prints overflow first and full second, while the arguments pass GUC_LOG_BUFFER_STATE_FULL then GUC_LOG_BUFFER_STATE_OVERFLOW. > + > + buf.size =3D log_buf_state_local.size; > + buf.rd =3D log_buf_state_local.start_ptr; > + buf.wr =3D log_buf_state_local.end_ptr; > + buf.data_offset =3D src_data_offset; [Severity: Medium] Can malformed or uninitialized header fields in guc->ads.bo cause an out-of-bounds read or buffer overflow in guc_capture_log_remove_bytes()? Unlike __guc_capture_process_output(), this assigns size, start_ptr, and end_ptr from firmware-writable memory without checking them against xe_bo_size(guc->ads.bo) - src_data_offset (or INT_MAX), or verifying rd <=3D size and wr <=3D size. If start_ptr > size and start_ptr > end_ptr, guc_capture_buf_cnt_to_end() returns a negative int that guc_capture_log_remove_bytes() passes as copy_size to xe_map_memcpy_from(), sign-extending it to size_t and overflowing the destination buffer. > + > + if (!xe_guc_read_stopped(guc)) { > + do { > + ret =3D guc_capture_extract_reglists(guc, &buf); > + if (ret && ret !=3D -ENODATA) > + xe_gt_dbg(guc_to_gt(guc), "Capture extraction failed:%d\n", ret); > + } while (ret >=3D 0); > + } > + > + /* Make start_ptr same as end_ptr */ > + xe_map_wr(guc_to_xe(guc), &guc->ads.bo->vmap, > + log_buf_state_offset + offsetof(struct guc_debug_snapshot_buffer_sta= te_vf, > + start_ptr), u32, log_buf_state_local.end_ptr); > +} [Severity: Medium] Does this drop full capture buffers and corrupt wrapped streams? Per struct guc_debug_snapshot_buffer_state_vf, when start_ptr >=3D end_ptr valid data is [start_ptr, wrap_offset) followed by [0, end_ptr), and GUC_LOG_BUFFER_STATE_FULL distinguishes a full buffer from an empty one when start_ptr =3D=3D end_ptr. Because wrap_offset is ignored, guc_capture_buf_cnt_to_end() reads stale bytes in [wrap_offset, size) when wrap_offset < size, breaking header parsing. When GUC_LOG_BUFFER_STATE_FULL is set with start_ptr =3D=3D end_p= tr, guc_capture_buf_cnt() returns 0 and silently discards the entire buffer, and updating start_ptr without clearing GUC_LOG_BUFFER_STATE_FULL leaves the header still marked full. [ ... ] > @@ -2024,9 +2087,6 @@ xe_guc_capture_get_matching_and_lock(struct xe_exec= _queue *q) > if (!xe_device_uc_enabled(xe)) > return NULL; > =20 > - if (IS_SRIOV_VF(xe)) > - return NULL; > - > ss =3D &xe->devcoredump.snapshot; > if (ss->matched_node && ss->matched_node->source =3D=3D XE_ENGINE_CAPTU= RE_SOURCE_GUC) > return ss->matched_node; > @@ -2079,9 +2139,6 @@ xe_engine_snapshot_capture_for_queue(struct xe_exec= _queue *q) > enum xe_hw_engine_id id; > u32 adj_logical_mask =3D q->logical_mask; > =20 > - if (IS_SRIOV_VF(xe)) > - return; > - > for_each_hw_engine(hwe, q->gt, id) { > if (hwe->class !=3D q->hwe->class || > !(BIT(hwe->logical_instance) & adj_logical_mask)) { [Severity: High] Does removing these IS_SRIOV_VF() guards without updating xe_hw_engine_snapshot_capture() drop VF captures and leak preallocated nodes? xe_hw_engine_snapshot_capture() still returns early on VFs before attaching the matched GuC capture node: drivers/gpu/drm/xe/xe_hw_engine.c:xe_hw_engine_snapshot_capture() { ... /* no more VF accessible data below this point */ if (IS_SRIOV_VF(gt_to_xe(hwe->gt))) return snapshot; if (q) { /* If got guc capture, set source to GuC */ node =3D xe_guc_capture_get_matching_and_lock(q); ... } When GuC delivers a VF capture before TDR runs, guc_exec_queue_timedout_job() calls xe_guc_capture_get_matching_and_lock(), setting n->locked =3D 1 and skipping the early xe_engine_snapshot_capture_for_queue() call. Later, devcoredump_snapshot() calls xe_hw_engine_snapshot_capture(), which returns early leaving coredump->snapshot.matched_node NULL. As a result, xe_engine_snapshot_print() omits the captured registers from the devcoredump, and xe_guc_capture_put_matched_nodes() never unlocks or returns n to cachelist, permanently leaking one node per hang until the pool is exhausted. Moving the VF check after the if (q) block (or relying on the existing VF guard in xe_engine_manual_capture()) would fix both. > @@ -2175,6 +2232,9 @@ int xe_guc_capture_init(struct xe_guc *guc) > INIT_LIST_HEAD(&guc->capture->outlist); > INIT_LIST_HEAD(&guc->capture->cachelist); > =20 > + if (IS_SRIOV_VF(guc_to_xe(guc))) > + guc_capture_create_prealloc_nodes(guc); > + > return 0; > } [Severity: Medium] Should VF node preallocation be gated on VF debug state capture support? guc_init_vf() calls xe_guc_capture_init() before xe_guc_ads_init() checks whether the PF enabled VF debug state capture, so this unconditionally allocates PREALLOC_NODES_MAX_COUNT (1,536) nodes via 6,144 drmm_kzalloc() calls per GT (~5 MiB per GT) on every VF even when capture is disabled. Deferring this until after xe_guc_ads_init() and checking xe_guc_debug_capture_support(&guc->ads) would avoid that overhead. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204144712.3520= 695-13-satyanarayana.k.v.p@intel.com?part=3D11