drm/amdgpu: add ptl_format module parameter
Subsystems (3)
PATCH 1/2 drm/amdgpu: add ptl_format module parameter
PTL always starts with VECTOR,F8 at driver load. Users who need other formats have to rewrite the ptl_format sysfs file after every boot, and that file only accepts writes once PTL is enabled.
Add an amdgpu.ptl_format module parameter that takes "FMT1,FMT2", for example ptl_format=F8,BF16. The formats are applied on the first PTL initialization; resume and reset keep using the cached formats as before. An invalid value is reported and the VECTOR,F8 defaults are kept.
Move the format parsing out of ptl_format_store() into amdgpu_ptl_parse_formats() so the sysfs file and the module parameter share the same validation.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 10 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 34 +++++++++++++++--------- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 14 +++++++++- drivers/gpu/drm/amd/include/amdgpu_ptl.h | 3 +++ 5 files changed, 48 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -270,6 +270,7 @@ extern int amdgpu_rebar;extern int amdgpu_wbrf;extern int amdgpu_user_queue;extern int amdgpu_ptl; +extern char *amdgpu_ptl_format;extern uint amdgpu_hdmi_hpd_debounce_delay_ms;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +10 -0
@@ -254,6 +254,7 @@ int amdgpu_rebar = -1; /* auto */int amdgpu_user_queue =-1 ;uint amdgpu_hdmi_hpd_debounce_delay_ms;int amdgpu_ptl =-1 ;/* auto */ +char *amdgpu_ptl_format; DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0, "DRM_UT_CORE",
@@ -1183,6 +1184,15 @@ module_param_named(hdmi_hpd_debounce_delay_ms, amdgpu_hdmi_hpd_debounce_delay_msMODULE_PARM_DESC (ptl,"Enable PTL (-1 = auto, 0 = disable (default), 1 = enable, 2 = permanently disable)" );module_param_named (ptl, amdgpu_ptl, int,0444 ); +/** +* DOC: ptl_format (charp) +* PTL preferred formats applied at driver load, as "FMT1,FMT2" +* (e.g. "F8,BF16"). Supported formats: I8, F16, BF16, F32, F64, F8, +* VECTOR. The two formats must differ. Default is VECTOR,F8. +*/ +MODULE_PARM_DESC (ptl_format,"PTL formats at load, \"FMT1,FMT2\" (default VECTOR,F8)" ); +module_param_named (ptl_format, amdgpu_ptl_format, charp,0444 ); +/* These devices are not supported by amdgpu. * They are supported by the mach64, r128, radeon drivers */
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +21 -13
@@ -1880,6 +1880,26 @@ static enum amdgpu_ptl_fmt str_to_ptl_fmt(const char *str)return AMDGPU_PTL_FMT_INVALID ; } +int amdgpu_ptl_parse_formats (const char *buf,enum amdgpu_ptl_fmt *fmt1, +enum amdgpu_ptl_fmt *fmt2) +{ +char fmt1_str[8 ], fmt2_str[8 ]; +enum amdgpu_ptl_fmt f1, f2; + +if (sscanf (buf,"%7[^,],%7s" , fmt1_str, fmt2_str) !=2 ) +return -EINVAL ; + + f1 =str_to_ptl_fmt (fmt1_str); + f2 =str_to_ptl_fmt (fmt2_str); +if (f1 >=AMDGPU_PTL_FMT_INVALID || f2 >=AMDGPU_PTL_FMT_INVALID || + f1 == f2) +return -EINVAL ; + + *fmt1 = f1; + *fmt2 = f2; +return 0 ; +} +static ssize_t ptl_supported_formats_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -1979,7 +1999,6 @@ static ssize_t ptl_format_store(struct device *dev, {struct drm_device *ddev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (ddev); -char fmt1_str[8 ], fmt2_str[8 ];enum amdgpu_ptl_fmt fmt1_enum, fmt2_enum;struct amdgpu_ptl *ptl = &adev->psp.ptl;uint32_t ptl_state, fmt1, fmt2;
@@ -1990,18 +2009,7 @@ static ssize_t ptl_format_store(struct device *dev,return -EPERM ;mutex_lock (&ptl->mutex); -/* Parse input, expecting "FMT1,FMT2" */ -if (sscanf (buf,"%7[^,],%7s" , fmt1_str, fmt2_str) !=2 ) { -mutex_unlock (&ptl->mutex); -return -EINVAL ; - } - - fmt1_enum =str_to_ptl_fmt (fmt1_str); - fmt2_enum =str_to_ptl_fmt (fmt2_str); - -if (fmt1_enum >=AMDGPU_PTL_FMT_INVALID || - fmt2_enum >=AMDGPU_PTL_FMT_INVALID || - fmt1_enum == fmt2_enum) { +if (amdgpu_ptl_parse_formats (buf, &fmt1_enum, &fmt2_enum)) {mutex_unlock (&ptl->mutex);return -EINVAL ; }
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +13 -1
@@ -2454,14 +2454,26 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool enareturn -EOPNOTSUPP ;if (ptl->hw_supported_state ==AMDGPU_PTL_HW_UNINIT ) { +enum amdgpu_ptl_fmt f1, f2; + fmt1 =GFX_FTYPE_VECTOR ; fmt2 =GFX_FTYPE_F8 ; +if (amdgpu_ptl_format) { +if (!amdgpu_ptl_parse_formats (amdgpu_ptl_format, &f1, &f2)) { + fmt1 = f1; + fmt2 = f2; + }else { +dev_warn (adev->dev, +"Invalid amdgpu.ptl_format=%s, using VECTOR,F8\n" , + amdgpu_ptl_format); + } + } }else { fmt1 = ptl->fmt1; fmt2 = ptl->fmt2; } -/* initialize PTL with default formats: GFX_FTYPE_VECTOR & GFX_FTYPE_F8 */ +/* Defaults or amdgpu.ptl_format on first init, cached formats after */ r =amdgpu_ptl_perf_monitor_ctrl (adev,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2);if (r) {
drivers/gpu/drm/amd/include/amdgpu_ptl.h +3 -0
@@ -64,6 +64,9 @@ int amdgpu_ptl_perf_monitor_ctrl(struct amdgpu_device *adev, u32 req_code,enum amdgpu_ptl_fmt *fmt1, enum amdgpu_ptl_fmt *fmt2); +int amdgpu_ptl_parse_formats (const char *buf,enum amdgpu_ptl_fmt *fmt1, +enum amdgpu_ptl_fmt *fmt2); +int amdgpu_ptl_sysfs_init (struct amdgpu_device *adev);void amdgpu_ptl_sysfs_fini (struct amdgpu_device *adev);
Signature · 1 line
2.34.1
PATCH 2/2 drm/amdkfd: fix deadlock between profiler_lock and dqm->lock
There is an AB-BA lock inversion between dqm->lock and kfd->profiler_lock when a profiler process exits without explicitly unlocking the device while another process concurrently creates a queue on the same GPU:
Keep kfd->profiler_lock as a leaf lock (consistent with kfd_profiler_pmc() and profile_lock_device()): clear kfd->profiler_process under profiler_lock, release profiler_lock, and then call set_perfcount(dqm, 0) outside the lock.
--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +6 -1
@@ -1230,12 +1230,17 @@ static void kfd_process_free_outstanding_kfd_bos(struct kfd_process *p)static void kfd_process_profiler_release (struct kfd_process *p,struct kfd_process_device *pdd) { +bool release = false; +mutex_lock (&pdd->dev->kfd->profiler_lock);if (pdd->dev->kfd->profiler_process == p) { - pdd->qpd.dqm->ops.set_perfcount (pdd->qpd.dqm,0 ); pdd->dev->kfd->profiler_process =NULL ; + release = true; }mutex_unlock (&pdd->dev->kfd->profiler_lock); + +if (release) + pdd->qpd.dqm->ops.set_perfcount (pdd->qpd.dqm,0 ); }static void kfd_process_destroy_pdds (struct kfd_process *p)
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/amdkfd: race in kfd_process_profiler_release() disabling perfcount --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/amdkfd: race in kfd_process_profiler_release() disabling perfcount
--
commit 887c47d311618fed50bfb8220d55513cc2a5a998
Author: Perry Yuan <[email protected]>
drm/amdkfd: fix deadlock between profiler_lock and dqm->lock
This commit moves the set_perfcount() call in kfd_process_profiler_release() outside kfd->profiler_lock to avoid an ABBA lock inversion with dqm->lock.
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2
-1@@ -1178,12 +1178,17 @@ static void kfd_process_free_outstanding_kfd_bos(struct kfd_process *p)static void kfd_process_profiler_release (struct kfd_process *p,struct kfd_process_device *pdd) { +bool release = false; +mutex_lock (&pdd->dev->kfd->profiler_lock);if (pdd->dev->kfd->profiler_process == p) { - pdd->qpd.dqm->ops.set_perfcount (pdd->qpd.dqm,0 );
drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_free_outstanding_kfd_bos(struct kfd_process *p) · line 1194
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +4
-0pdd->dev->kfd->profiler_process =NULL ; + release = true; }mutex_unlock (&pdd->dev->kfd->profiler_lock); + +if (release) + pdd->qpd.dqm->ops.set_perfcount (pdd->qpd.dqm,0 ); }static void kfd_process_destroy_pdds (struct kfd_process *p)
[Severity: Medium]
Can clearing profiler_process and dropping profiler_lock before calling set_perfcount(pdd->qpd.dqm, 0) race with a new profiler session?
CPU0 CPU1kfd_process_profiler_release()
mutex_lock(&kfd->profiler_lock)
kfd->profiler_process = NULL
mutex_unlock(&kfd->profiler_lock)
kfd_profiler_pmc()
profile_lock_device(..., 1)
mutex_lock(&kfd->profiler_lock)
kfd->profiler_process = new_p
mutex_unlock(&kfd->profiler_lock)
dqm->ops.set_perfcount(dqm, 1) dqm->ops.set_perfcount(dqm, 0)
<-- disables perfcount for new_p
Once profiler_process is cleared and profiler_lock is released, another process calling kfd_profiler_pmc() can claim profiler_process and enable perfcount, only for the exiting process to overwrite it back to 0 across the device's queues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
RE: [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock
In reply to Perry YuanAMD General
This patch is: Reviewed-by: Yifan Zhang <[email protected]>
Best Regards,
Yifan
-----Original Message-----
From: Yuan, Perry <[email protected]>
Sent: Monday, November 23, 2026 3:23 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Yifan <[email protected]>; Yuan, Perry <[email protected]>
Subject: [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock
There is an AB-BA lock inversion between dqm->lock and kfd->profiler_lock when a profiler process exits without explicitly unlocking the device while another process concurrently creates a queue on the same GPU:
Keep kfd->profiler_lock as a leaf lock (consistent with kfd_profiler_pmc() and profile_lock_device()): clear kfd->profiler_process under profiler_lock, release profiler_lock, and then call set_perfcount(dqm, 0) outside the lock.
--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +6 -2
@@ -1230,12 +1230,17 @@ static void kfd_process_free_outstanding_kfd_bos(struct kfd_process *p)static void kfd_process_profiler_release (struct kfd_process *p,struct kfd_process_device *pdd) { +bool release = false; +mutex_lock (&pdd->dev->kfd->profiler_lock);if (pdd->dev->kfd->profiler_process == p) { - pdd->qpd.dqm->ops.set_perfcount (pdd->qpd.dqm,0 ); pdd->dev->kfd->profiler_process =NULL ; + release = true; }mutex_unlock (&pdd->dev->kfd->profiler_lock); + +if (release) + pdd->qpd.dqm->ops.set_perfcount (pdd->qpd.dqm,0 ); }static void kfd_process_destroy_pdds (struct kfd_process *p) --
2.34.1
AMD General
Best Regards,
Yifan
-----Original Message-----
From: Yuan, Perry <[email protected]>
Sent: Monday, November 23, 2026 3:23 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Yifan <[email protected]>; Yuan, Perry <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: add ptl_format module parameter
PTL always starts with VECTOR,F8 at driver load. Users who need other formats have to rewrite the ptl_format sysfs file after every boot, and that file only accepts writes once PTL is enabled.
Add an amdgpu.ptl_format module parameter that takes "FMT1,FMT2", for example ptl_format=F8,BF16. The formats are applied on the first PTL initialization; resume and reset keep using the cached formats as before. An invalid value is reported and the VECTOR,F8 defaults are kept.
Move the format parsing out of ptl_format_store() into amdgpu_ptl_parse_formats() so the sysfs file and the module parameter share the same validation.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 10 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 34 +++++++++++++++--------- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 14 +++++++++- drivers/gpu/drm/amd/include/amdgpu_ptl.h | 3 +++ 5 files changed, 48 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -270,6 +270,7 @@ extern int amdgpu_rebar; extern int amdgpu_wbrf; extern int amdgpu_user_queue; extern int amdgpu_ptl; +extern char *amdgpu_ptl_format;extern uint amdgpu_hdmi_hpd_debounce_delay_ms;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +11 -0
@@ -254,6 +254,7 @@ int amdgpu_rebar = -1; /* auto */ int amdgpu_user_queue = -1; uint amdgpu_hdmi_hpd_debounce_delay_ms;int amdgpu_ptl =-1 ;/* auto */ +char *amdgpu_ptl_format; DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0, "DRM_UT_CORE",
@@ -1183,6 +1184,15 @@ module_param_named(hdmi_hpd_debounce_delay_ms, amdgpu_hdmi_hpd_debounce_delay_ms MODULE_PARM_DESC(ptl, "Enable PTL (-1 = auto, 0 = disable (default), 1 = enable, 2 = permanently disable)"); module_param_named(ptl, amdgpu_ptl, int, 0444); +/** +* DOC: ptl_format (charp) +* PTL preferred formats applied at driver load, as "FMT1,FMT2" +* (e.g. "F8,BF16"). Supported formats: I8, F16, BF16, F32, F64, F8, +* VECTOR. The two formats must differ. Default is VECTOR,F8. +*/ +MODULE_PARM_DESC(ptl_format, "PTL formats at load, \"FMT1,FMT2\" +(default VECTOR,F8)"); module_param_named(ptl_format, +amdgpu_ptl_format, charp,0444 ); +/* These devices are not supported by amdgpu. * They are supported by the mach64, r128, radeon drivers */
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +20 -0
@@ -1880,6 +1880,26 @@ static enum amdgpu_ptl_fmt str_to_ptl_fmt(const char *str)return AMDGPU_PTL_FMT_INVALID ; } +int amdgpu_ptl_parse_formats (const char *buf,enum amdgpu_ptl_fmt *fmt1, +enum amdgpu_ptl_fmt *fmt2) +{ +char fmt1_str[8 ], fmt2_str[8 ]; +enum amdgpu_ptl_fmt f1, f2; + +if (sscanf (buf,"%7[^,],%7s" , fmt1_str, fmt2_str) !=2 ) +return -EINVAL ; + + f1 =str_to_ptl_fmt (fmt1_str); + f2 =str_to_ptl_fmt (fmt2_str); +if (f1 >=AMDGPU_PTL_FMT_INVALID || f2 >=AMDGPU_PTL_FMT_INVALID || + f1 == f2) +return -EINVAL ; + + *fmt1 = f1; + *fmt2 = f2; +return 0 ; +} +static ssize_t ptl_supported_formats_show (struct device *dev, struct device_attribute *attr, char *buf) { @@ -1979,7 +1999,6 @@ static ssize_t ptl_format_store(struct device *dev, { struct drm_device *ddev = dev_get_drvdata(dev);
struct amdgpu_device *adev = drm_to_adev(ddev);
- char fmt1_str[8], fmt2_str[8];
enum amdgpu_ptl_fmt fmt1_enum, fmt2_enum;
struct amdgpu_ptl *ptl = &adev->psp.ptl;
uint32_t ptl_state, fmt1, fmt2;
@@ -1990,18 +2009,7 @@ static ssize_t ptl_format_store(struct device *dev,
return -EPERM;
mutex_lock(&ptl->mutex);- /* Parse input, expecting "FMT1,FMT2" */
- if (sscanf(buf, "%7[^,],%7s", fmt1_str, fmt2_str) != 2) {
- mutex_unlock(&ptl->mutex);
- return -EINVAL;
- }
-
- fmt1_enum = str_to_ptl_fmt(fmt1_str);
- fmt2_enum = str_to_ptl_fmt(fmt2_str);
-
- if (fmt1_enum >= AMDGPU_PTL_FMT_INVALID ||
- fmt2_enum >= AMDGPU_PTL_FMT_INVALID ||
- fmt1_enum == fmt2_enum) {
+ if (amdgpu_ptl_parse_formats(buf, &fmt1_enum, &fmt2_enum)) {
mutex_unlock(&ptl->mutex);
return -EINVAL;
}drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +14 -1
@@ -2454,14 +2454,26 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool enareturn -EOPNOTSUPP ;if (ptl->hw_supported_state ==AMDGPU_PTL_HW_UNINIT ) { +enum amdgpu_ptl_fmt f1, f2; + fmt1 =GFX_FTYPE_VECTOR ; fmt2 =GFX_FTYPE_F8 ; +if (amdgpu_ptl_format) { +if (!amdgpu_ptl_parse_formats (amdgpu_ptl_format, &f1, &f2)) { + fmt1 = f1; + fmt2 = f2; + }else { +dev_warn (adev->dev, +"Invalid amdgpu.ptl_format=%s, using VECTOR,F8\n" , + amdgpu_ptl_format); + } + } }else { fmt1 = ptl->fmt1; fmt2 = ptl->fmt2; } -/* initialize PTL with default formats: GFX_FTYPE_VECTOR & GFX_FTYPE_F8 */ +/* Defaults or amdgpu.ptl_format on first init, cached formats after +*/ r =amdgpu_ptl_perf_monitor_ctrl (adev,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2);
if (r) {drivers/gpu/drm/amd/include/amdgpu_ptl.h +3 -1
@@ -64,6 +64,9 @@ int amdgpu_ptl_perf_monitor_ctrl(struct amdgpu_device *adev, u32 req_code,enum amdgpu_ptl_fmt *fmt1, enum amdgpu_ptl_fmt *fmt2); +int amdgpu_ptl_parse_formats (const char *buf,enum amdgpu_ptl_fmt *fmt1, +enum amdgpu_ptl_fmt *fmt2); +int amdgpu_ptl_sysfs_init (struct amdgpu_device *adev);void amdgpu_ptl_sysfs_fini (struct amdgpu_device *adev); --
2.34.1