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 AFDC260A2600 for ; Wed, 2 Dec 2026 00:20:21 +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=oDtM/gjM Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 131F110EA7D; Wed, 2 Dec 2026 00:20:16 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 12E0810EA7D; Wed, 2 Dec 2026 00:20:10 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 267CB60EE9; Wed, 2 Dec 2026 00:20:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EB841F00937; Wed, 2 Dec 2026 00:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796170808; bh=PchKdW6rU/KGynGsA59yny7g36SP+BEO5P+x8kTCI9g=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=oDtM/gjMmayeJoWf9wIOuvUJ3awzGt5yj+zvEdiTkRTFw6xlVVvW4s6qdLtYIzhI1 zqjqogpBuBraMhiFyZilR672qDCLbi3dnA0RZZu1UemI3QlYEA1TKf2BB33xEXWgFP R+u2nUnAlYNWW/2oJJKK28nLEde8ssUCXeQDTfJVEyBxhX93dzh2ekpyTVw7zp23Qb Hrll8z8z+DcycLjkF9mlV/NyqdYGejCkLL5W+5eaPwU0NaqQipFDlgFIeZh6WF3cYk 6CwJqqoxDOHL2oaLDUwnrpGpLtcXT4SWIz07yHKhfgvjkif8+C3Y2tpgb7vH7H8rQ5 kfhjfg0DAXojA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 33/33] drm/xe: Make BO defrag tunables configurable via sysfs To: "Matthew Brost" , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: <20261201234915.3305331-34-matthew.brost@intel.com> References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-34-matthew.brost@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 00:20:08 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-10.8 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=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 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/xe: xe_device_sysfs_init() checks defrag support before VF CCS init - [Low] drm/xe: unlocked read of interval_ms in xe_bo_defrag_schedule() -- commit 3ba32e8d8538d69064e633102b60c492b213486e Author: Matthew Brost drm/xe: Make BO defrag tunables configurable via sysfs This commit exposes the BO defragmentation per-run size limit, default worker interval, and maximum worker interval as device sysfs attributes and reports the runtime values in the bo_defrag debugfs entry. > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > index 9c218b03210ae..165453328931e 100644 > --- a/drivers/gpu/drm/xe/xe_bo.c > +++ b/drivers/gpu/drm/xe/xe_bo.c [ ... ] > @@ -2308,23 +2316,105 @@ void xe_bo_defrag_resume(struct xe_device *xe) [ ... ] > +int xe_bo_defrag_set_interval_max_ms(struct xe_device *xe, > + unsigned int interval_max_ms) > +{ > + if (interval_max_ms < XE_BO_DEFRAG_INTERVAL_MAX_MS_MIN || > + interval_max_ms > XE_BO_DEFRAG_INTERVAL_MAX_MS_MAX) > + return -EINVAL; > + > + guard(spinlock)(&xe->mem.defrag.lock); > + > + if (interval_max_ms < xe->mem.defrag.interval_default_ms) > + return -EINVAL; > + > + WRITE_ONCE(xe->mem.defrag.interval_max_ms, interval_max_ms); > + xe->mem.defrag.interval_ms =3D min(xe->mem.defrag.interval_ms, > + interval_max_ms); > + > + return 0; > +} [Severity: Low] Can clamping xe->mem.defrag.interval_ms here race with xe_bo_defrag_schedule()? Although @mem.defrag.interval_ms is documented as protected by @mem.defrag.lock, all callers of xe_bo_defrag_schedule() drop xe->mem.defrag.lock before calling it, and xe_bo_defrag_schedule() reads xe->mem.defrag.interval_ms without holding the lock or using READ_ONCE(): drivers/gpu/drm/xe/xe_bo.c:xe_bo_defrag_schedule() { xe_assert(xe, XE_BO_DEFRAG_SIZE_LIMIT >=3D SZ_2M); schedule_delayed_work(&xe->mem.defrag.worker, msecs_to_jiffies(xe->mem.defrag.interval_ms)); } A concurrent write to defrag_interval_max_ms (or a concurrent update in xe_bo_defrag_add()) causes a data race and can leave xe_bo_defrag_schedule() using a stale interval. > diff --git a/drivers/gpu/drm/xe/xe_device_sysfs.c b/drivers/gpu/drm/xe/xe= _device_sysfs.c > index 9b734aeefd332..c94592576408f 100644 > --- a/drivers/gpu/drm/xe/xe_device_sysfs.c > +++ b/drivers/gpu/drm/xe/xe_device_sysfs.c [ ... ] > @@ -441,6 +557,12 @@ int xe_device_sysfs_init(struct xe_device *xe) > if (ret) > return ret; > =20 > + if (xe_bo_defrag_supported(xe)) { > + ret =3D devm_device_add_group(dev, &defrag_attr_group); > + if (ret) > + return ret; > + } [Severity: Medium] Does checking xe_bo_defrag_supported(xe) here expose defrag_attr_group on SR-IOV VFs where defragmentation is disabled due to CCS save/restore? xe_bo_defrag_supported() checks !IS_VF_CCS_READY(xe), which reads xe->sriov.vf.ccs.initialized. However, in xe_device_probe(), xe_device_sysfs_init() runs before xe_sriov_init_late(): drivers/gpu/drm/xe/xe_device.c:xe_device_probe() { ... err =3D xe_device_sysfs_init(xe); if (err) goto err_unregister_display; ... err =3D xe_sriov_init_late(xe); } Because xe->sriov.vf.ccs.initialized is only set inside xe_sriov_init_late() -> xe_sriov_vf_init_late() -> vf_migration_init_late() -> xe_sriov_vf_ccs_init(), IS_VF_CCS_READY(xe) is always false when xe_device_sysfs_init() runs. As a result, the defrag sysfs attributes are always registered on VF devices with CCS save/restore enabled even though xe_bo_defrag_supported() becomes false once probe finishes. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201234915.3305= 331-1-matthew.brost@intel.com?part=3D33