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 320D1606A322 for ; Fri, 4 Dec 2026 16:32:02 +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=PXXKCM+b Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EB2CD11307C; Fri, 4 Dec 2026 16:31:56 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id CF39C10E89B for ; Fri, 4 Dec 2026 16:31:50 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id B190E41989; Fri, 4 Dec 2026 16:31:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 814451F000CE; Fri, 4 Dec 2026 16:31:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796401910; bh=tHK1J8FY777SYxShGG+DVHaiXu0KyhjohZsskGONN10=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=PXXKCM+bcp3Xzm4K5eh+3W0IDrEcjRJGrSZxCfl+k5PAm3Qr5OI6i2gnKrPylDPv9 kl4BUS1mSbCCu/3wGb/Z0ZcrhyWAmc9QfbJHUBgczJxPC7MFpaOWz6oa1zQljDMmsD LpZ2c4QVN3FDSiBuK0fGh7EZYd1q7zeSIAKEeyHo4wiDkN5Vm3raJtxu7murH97lR5 9HQWKh8oLxEC1D8LJZyMo9QENxLVOBtScBT00C82EYKBKDiPYma2rF5dzt5Io42yVw k5ZcPz6H0wvRkawRtHafztgnPEn40sOw3MnEMIEv4T5qcS+naUIEbkhIU0jaUp4dQX FLt0ax1xryi7Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC 06/11] drm/xe/vf: Query and allocate VF GuC log and debug capture buffers To: "Satyanarayana K V P" , intel-xe@lists.freedesktop.org In-Reply-To: <20261204144712.3520695-19-satyanarayana.k.v.p@intel.com> References: <20261204144712.3520695-13-satyanarayana.k.v.p@intel.com> <20261204144712.3520695-19-satyanarayana.k.v.p@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 16:31:50 +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=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, 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 6 potential issues to consider: - [High] drm/xe: unguarded gt->sriov.vf union read in VF debug/log helpers - [High] drm/xe: unaligned VF GuC log size triggers BUG_ON in xe_guc_log_init() - [Medium] drm/xe: VF capture BO over-allocated and unzeroed in xe_guc_ads_init() - [Medium] drm/xe: uninitialized VF ads->bo mapped to GGTT in xe_guc_ads_init() - [Medium] drm/xe: 32-bit overflow in PAGE_ALIGN() in guc_ads_capture_size() - [Medium] drm/xe: signed int overflow in xe_guc_log_snapshot_capture() -- commit ed04b7320e3205eaeb1e90354391eab392dd317d Author: Satyanarayana K V P drm/xe/vf: Query and allocate VF GuC log and debug capture buffers This commit adds VF helpers to query the GuC log and debug state capture buffer sizes from the PF and uses them to allocate the corresponding buffers in xe_guc_log_init() and xe_guc_ads_init(). > diff --git a/drivers/gpu/drm/xe/xe_guc_ads.c b/drivers/gpu/drm/xe/xe_guc_= ads.c > index 4b7d423e715ca..1cce54cc711d4 100644 > --- a/drivers/gpu/drm/xe/xe_guc_ads.c > +++ b/drivers/gpu/drm/xe/xe_guc_ads.c > @@ -446,6 +446,49 @@ static int calculate_waklv_size(struct xe_guc_ads *a= ds) > return SZ_4K; > } > =20 > +/** > + * xe_guc_debug_capture_support() - Check if VF GuC debug state capture = is > + * supported > + * @ads: the &ads > + * > + * Returns: true if VF GuC debug state capture is enabled, false otherwi= se. > + */ > +bool xe_guc_debug_capture_support(struct xe_guc_ads *ads) > +{ > + struct xe_gt *gt =3D ads_to_gt(ads); > + > + return gt->sriov.vf.debug_log.debug_state_capture_enabled; > +} [Severity: High] Can xe_guc_debug_capture_support() and xe_guc_log_vf_supported() read aliased PF state when called on a non-VF device? gt->sriov is a union of pf and vf, so reading gt->sriov.vf.debug_log without checking IS_SRIOV_VF(gt_to_xe(gt)) performs an unlocked read of live PF fields on a PF and can return true. Later in this series, devcoredump_snapshot() calls xe_guc_log_vf_supported() unconditionally on PF devices, which can then run xe_guc_log_vf_request_snapshot() on a PF and lock the uninitialized vf_log_capture_lock mutex. Returning false when !IS_SRIOV_VF(gt_to_xe(gt)) in both helpers (and reflecting VF-only scope in xe_guc_debug_capture_support()'s name) would avoid the union aliasing. > + > +static u32 guc_capture_size(struct xe_guc_ads *ads) > +{ > + u32 size =3D xe_guc_capture_ads_input_worst_size(ads_to_guc(ads)); > + struct xe_gt *gt =3D ads_to_gt(ads); > + int err; > + > + if (!IS_SRIOV_VF(gt_to_xe(gt))) > + return size; > + > + gt->sriov.vf.debug_log.debug_state_capture_enabled =3D false; > + err =3D xe_gt_sriov_vf_guc_debug_state_capture_buff_size(gt, &size); > + if (err) { > + xe_gt_err(gt, "Failed to query debug state capture size!\n"); > + size =3D 0; > + goto out; > + } > + > + if (!size) { > + xe_gt_notice(gt, "VF debug state capture is not enabled by PF\n"); > + goto out; > + } > + > + gt->sriov.vf.debug_log.debug_state_capture_enabled =3D true; > + xe_gt_notice(gt, "VF GuC debug state capture buffer size: %u bytes\n", = size); > + > +out: > + return size; > +} [Severity: Medium] Can an unchecked capture buffer size from GuC overflow PAGE_ALIGN() in guc_ads_capture_size()? drivers/gpu/drm/xe/xe_guc_ads.c:guc_ads_capture_size() { return PAGE_ALIGN(ads->capture_size); } Because ads->capture_size is a u32, PAGE_ALIGN() evaluates in 32-bit arithmetic and wraps values above U32_MAX - (PAGE_SIZE - 1) to 0. xe_guc_ads_init() then allocates ads->bo with 0 bytes for capture while leaving ads->capture_size near 4 GiB and debug_state_capture_enabled set. Validating an upper bound on size in guc_capture_size() would prevent this wrap. [ ... ] > @@ -456,10 +499,13 @@ int xe_guc_ads_init(struct xe_guc_ads *ads) > struct xe_bo *bo; > =20 > ads->golden_lrc_size =3D calculate_golden_lrc_size(ads); > - ads->capture_size =3D xe_guc_capture_ads_input_worst_size(ads_to_guc(ad= s)); > + ads->capture_size =3D guc_capture_size(ads); > ads->regset_size =3D calculate_regset_size(gt); > ads->ads_waklv_size =3D calculate_waklv_size(ads); > =20 > + if (!ads->capture_size) > + return 0; > + > bo =3D xe_managed_bo_create_pin_map(xe, tile, guc_ads_size(ads) + MAX_G= OLDEN_LRC_SIZE, > XE_BO_FLAG_SYSTEM | > XE_BO_FLAG_GGTT | [Severity: Medium] Does reusing xe_guc_ads_init() over-allocate VF GGTT and pinned RAM for the VF debug state capture buffer? On a VF, guc_ads_size(ads) + MAX_GOLDEN_LRC_SIZE adds at least 256 KiB plus unused PF ADS headers, golden LRC, regset, and WA KLV space per GT, which can exhaust tight PF-provisioned VF GGTT budgets and makes xe_bo_size(ads->bo) disagree with ads->capture_size. Also, gating BO allocation on !ads->capture_size unconditionally skips ads->bo on native and PF devices where xe_guc_ads_populate_minimal() expects it to be non-NULL. Restricting the zero-size skip to IS_SRIOV_VF(xe) and allocating only the validated capture size for VFs would avoid both issues. [ ... ] > @@ -471,6 +517,9 @@ int xe_guc_ads_init(struct xe_guc_ads *ads) > =20 > ads->bo =3D bo; > =20 > + if (IS_SRIOV_VF(xe)) > + return 0; > + [Severity: Medium] Is ads->bo left uninitialized when mapped into the GGTT on a VF? ttm_tt_create() does not zero-allocate ttm_bo_type_kernel BOs, and VFs never call xe_guc_ads_populate*(). Without an xe_map_memset() here like xe_guc_log_init() does, stale guest memory is exposed to the GPU/GuC/PF and remains in unwritten parts of the capture buffer and its header. [ ... ] > diff --git a/drivers/gpu/drm/xe/xe_guc_log.c b/drivers/gpu/drm/xe/xe_guc_= log.c > index 80d80393b05db..7625e07026a7d 100644 > --- a/drivers/gpu/drm/xe/xe_guc_log.c > +++ b/drivers/gpu/drm/xe/xe_guc_log.c [ ... ] > +static size_t guc_log_size(struct xe_gt *gt) > +{ > + u32 size =3D GUC_LOG_SIZE; > + int err; > + > + if (!IS_SRIOV_VF(gt_to_xe(gt))) > + return size; > + > + gt->sriov.vf.debug_log.guc_log_enabled =3D false; > + err =3D xe_gt_sriov_vf_guc_log_buff_size(gt, &size); > + if (err) { > + xe_gt_err(gt, "Failed to query Guc log size!\n"); > + size =3D 0; > + goto out; > + } > + > + if (!size) { > + xe_gt_notice(gt, "VF GuC log not enabled by PF\n"); > + goto out; > + } > + > + gt->sriov.vf.debug_log.guc_log_enabled =3D true; > + xe_gt_notice(gt, "VF Guc log size is %u\n", size); > +out: > + return size; > +} [Severity: Medium] Can an unbounded VF GuC log size trigger a signed int overflow in xe_guc_log_snapshot_capture()? drivers/gpu/drm/xe/xe_guc_log.c:xe_guc_log_snapshot_capture() { ... for (i =3D 0; i < snapshot->num_chunks; i++) { size_t size =3D min(GUC_LOG_CHUNK_SIZE, remain); xe_map_memcpy_from(xe, snapshot->copy[i], &log->bo->vmap, i * GUC_LOG_CHUNK_SIZE, size); ... } Both i and GUC_LOG_CHUNK_SIZE (SZ_2M) are signed 32-bit ints. If GuC reports a log size above 2 GiB, i * GUC_LOG_CHUNK_SIZE overflows at i =3D=3D 1024 and sign-extends to a huge size_t offset in xe_map_memcpy_from(), causing an out-of-bounds read. Enforcing an upper bound in guc_log_size() and using size_t for the offset calculation would prevent this. > + > int xe_guc_log_init(struct xe_guc_log *log) > { > struct xe_device *xe =3D log_to_xe(log); > struct xe_gt *gt =3D log_to_gt(log); > struct xe_tile *tile =3D gt_to_tile(gt); > + size_t size =3D guc_log_size(gt); > struct xe_bo *bo; > =20 > - bo =3D xe_managed_bo_create_pin_map(xe, tile, GUC_LOG_SIZE, > + if (!size) > + return 0; > + > + bo =3D xe_managed_bo_create_pin_map(xe, tile, size, > XE_BO_FLAG_SYSTEM | [Severity: High] Can an unaligned VF GuC log size panic the kernel in drm_gem_private_object_init()? xe_guc_log_init() passes the raw KLV byte count directly to xe_managed_bo_create_pin_map(). For ttm_bo_type_kernel system BOs, xe_bo_init_locked() passes size unchanged to drm_gem_private_object_init(), which runs: drivers/gpu/drm/drm_gem.c:drm_gem_private_object_init() { ... BUG_ON((size & (PAGE_SIZE - 1)) !=3D 0); ... } On 16 KiB or 64 KiB page kernels (or if GuC reports any size not aligned to PAGE_SIZE), this panics during VF probe. Checking alignment or safely aligning size in size_t before allocation would avoid the crash. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204144712.3520= 695-13-satyanarayana.k.v.p@intel.com?part=3D6