FAILED: patch "[PATCH] drm/amd/pm: fix torn gpu metrics reads" failed to apply to 5.10-stable tree
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 048f4541b71fb19645fb79d6e62e6e4da23a4035
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026080525-prowler-kangaroo-7aaa@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 048f4541b71fb19645fb79d6e62e6e4da23a4035 Mon Sep 17 00:00:00 2001
From: Yang Wang <[email protected]>
Date: Thu, 23 Jul 2026 23:18:33 +0800
Subject: [PATCH] drm/amd/pm: fix torn gpu metrics reads
amdgpu_dpm_get_gpu_metrics() returns a pointer to the shared metrics cache after dropping adev->pm.mutex. The sysfs path then copies from that pointer. Another reader can refresh the cache in place during the copy and return a snapshot containing data from two generations.
Pass caller-provided storage through the DPM interface and copy the metrics while the mutex is held. This keeps the cache pointer private and makes each sysfs read observe one complete sample.
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -3
@@ -1434,17 +1434,23 @@ int amdgpu_dpm_set_power_profile_mode(struct amdgpu_device *adev,return ret; } -int amdgpu_dpm_get_gpu_metrics (struct amdgpu_device *adev,void **table) +ssize_t amdgpu_dpm_get_gpu_metrics (struct amdgpu_device *adev,void *buf, +size_t size) {const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs; -int ret =0 ; +void *table; +ssize_t ret;if (!pp_funcs->get_gpu_metrics)return 0 ;mutex_lock (&adev->pm.mutex); ret = pp_funcs->get_gpu_metrics (adev->powerplay.pp_handle, - table); + &table); +if (ret >0 ) { + ret =min_t (ssize_t, ret, size); +memcpy (buf, table, ret); + }mutex_unlock (&adev->pm.mutex);return ret;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -7
@@ -1774,7 +1774,6 @@ static ssize_t amdgpu_get_gpu_metrics(struct device *dev, {struct drm_device *ddev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (ddev); -void *gpu_metrics;ssize_t size =0 ;int ret;
@@ -1782,15 +1781,10 @@ static ssize_t amdgpu_get_gpu_metrics(struct device *dev,if (ret)return ret; - size =amdgpu_dpm_get_gpu_metrics (adev, &gpu_metrics); + size =amdgpu_dpm_get_gpu_metrics (adev, buf,PAGE_SIZE -1 );if (size <=0 ) goto out; -if (size >=PAGE_SIZE ) - size =PAGE_SIZE -1 ; - -memcpy (buf, gpu_metrics, size); - out:amdgpu_pm_put_access (adev);
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -1
@@ -518,7 +518,8 @@ int amdgpu_dpm_get_power_profile_mode(struct amdgpu_device *adev, char *buf);int amdgpu_dpm_set_power_profile_mode (struct amdgpu_device *adev,long *input,uint32_t size); -int amdgpu_dpm_get_gpu_metrics (struct amdgpu_device *adev,void **table); +ssize_t amdgpu_dpm_get_gpu_metrics (struct amdgpu_device *adev,void *buf, +size_t size);ssize_t amdgpu_dpm_get_xcp_metrics (struct amdgpu_device *adev,int xcp_id,void *table); ssize_t amdgpu_dpm_get_temp_metrics(struct amdgpu_device *adev,
Sasha Levin
maintainerPATCH 1/1 drm/amd/pm: fix torn gpu metrics reads
From: Yang Wang <[email protected]>
[ Upstream commit 048f4541b71fb19645fb79d6e62e6e4da23a4035 ]
amdgpu_dpm_get_gpu_metrics() returns a pointer to the shared metrics cache after dropping adev->pm.mutex. The sysfs path then copies from that pointer. Another reader can refresh the cache in place during the copy and return a snapshot containing data from two generations.
Pass caller-provided storage through the DPM interface and copy the metrics while the mutex is held. This keeps the cache pointer private and makes each sysfs read observe one complete sample.
--- drivers/gpu/drm/amd/pm/amdgpu_pm.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -8
@@ -1994,20 +1994,18 @@ static ssize_t amdgpu_get_gpu_metrics(struct device *dev,return ret; } +mutex_lock (&adev->pm.mutex);if (is_support_sw_smu (adev)) size =smu_sys_get_gpu_metrics (&adev->smu, &gpu_metrics);else if (adev->powerplay.pp_funcs->get_gpu_metrics) size =amdgpu_dpm_get_gpu_metrics (adev, &gpu_metrics); -if (size <=0 ) - goto out; - -if (size >=PAGE_SIZE ) - size =PAGE_SIZE -1 ; - -memcpy (buf, gpu_metrics, size); +if (size >0 ) { + size =min_t (ssize_t, size,PAGE_SIZE -1 ); +memcpy (buf, gpu_metrics, size); + } +mutex_unlock (&adev->pm.mutex); -out:pm_runtime_mark_last_busy (ddev->dev);pm_runtime_put_autosuspend (ddev->dev);
Signature · 1 line
2.53.0