* [PATCH 1/2] drm/amdgpu: add ptl_format module parameter
@ 2026-11-23 7:22 Perry Yuan
2026-11-23 7:22 ` [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock Perry Yuan
2026-11-24 2:59 ` [PATCH 1/2] drm/amdgpu: add ptl_format module parameter Zhang, Yifan
0 siblings, 2 replies; 5+ messages in thread
From: Perry Yuan @ 2026-11-23 7:22 UTC (permalink / raw)
To: amd-gfx; +Cc: Alexander.Deucher, Christian.Koenig, Yifan1.Zhang, perry.yuan
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.
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
---
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(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index a7a2b6b5a497..53eb4824f922 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -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;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 6478506d8089..5b366fc910ae 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -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
*/
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index c19600f8b7f8..09648b68d066 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -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;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
index b789f528f3b0..0cf13e78b821 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
@@ -2454,14 +2454,26 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool ena
return -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) {
diff --git a/drivers/gpu/drm/amd/include/amdgpu_ptl.h b/drivers/gpu/drm/amd/include/amdgpu_ptl.h
index eead62b4b327..c445525833a2 100644
--- a/drivers/gpu/drm/amd/include/amdgpu_ptl.h
+++ b/drivers/gpu/drm/amd/include/amdgpu_ptl.h
@@ -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
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock
2026-11-23 7:22 [PATCH 1/2] drm/amdgpu: add ptl_format module parameter Perry Yuan
@ 2026-11-23 7:22 ` Perry Yuan
2026-11-23 7:38 ` sashiko-bot
2026-11-24 2:58 ` Zhang, Yifan
2026-11-24 2:59 ` [PATCH 1/2] drm/amdgpu: add ptl_format module parameter Zhang, Yifan
1 sibling, 2 replies; 5+ messages in thread
From: Perry Yuan @ 2026-11-23 7:22 UTC (permalink / raw)
To: amd-gfx; +Cc: Alexander.Deucher, Christian.Koenig, Yifan1.Zhang, perry.yuan
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.
Fixes: a789761de305 ("amd/amdkfd: Add kfd_ioctl_profiler to contain profiler kernel driver changes")
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index b6981185c7ff..cb1ceae7606b 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -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
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock
2026-11-23 7:22 ` [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock Perry Yuan
@ 2026-11-23 7:38 ` sashiko-bot
2026-11-24 2:58 ` Zhang, Yifan
1 sibling, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-23 7:38 UTC (permalink / raw)
To: Perry Yuan, amd-gfx
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 <perry.yuan@amd.com>
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.
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> index 6663718fb83ce..b63535eda02b3 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> @@ -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);
> 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)
[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 CPU1
kfd_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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123072247.3612981-1-perry.yuan@amd.com?part=2
^ permalink raw reply [flat|nested] 5+ messages in thread* RE: [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock
2026-11-23 7:22 ` [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock Perry Yuan
2026-11-23 7:38 ` sashiko-bot
@ 2026-11-24 2:58 ` Zhang, Yifan
1 sibling, 0 replies; 5+ messages in thread
From: Zhang, Yifan @ 2026-11-24 2:58 UTC (permalink / raw)
To: Yuan, Perry, amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander, Koenig, Christian
AMD General
This patch is: Reviewed-by: Yifan Zhang <yifan1.zhang@amd.com>
Best Regards,
Yifan
-----Original Message-----
From: Yuan, Perry <Perry.Yuan@amd.com>
Sent: Monday, November 23, 2026 3:23 PM
To: amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; Zhang, Yifan <Yifan1.Zhang@amd.com>; Yuan, Perry <Perry.Yuan@amd.com>
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.
Fixes: a789761de305 ("amd/amdkfd: Add kfd_ioctl_profiler to contain profiler kernel driver changes")
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index b6981185c7ff..cb1ceae7606b 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [PATCH 1/2] drm/amdgpu: add ptl_format module parameter
2026-11-23 7:22 [PATCH 1/2] drm/amdgpu: add ptl_format module parameter Perry Yuan
2026-11-23 7:22 ` [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock Perry Yuan
@ 2026-11-24 2:59 ` Zhang, Yifan
1 sibling, 0 replies; 5+ messages in thread
From: Zhang, Yifan @ 2026-11-24 2:59 UTC (permalink / raw)
To: Yuan, Perry, amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander, Koenig, Christian
AMD General
Reviewed-by: Yifan Zhang <yifan1.zhang@amd.com>
Best Regards,
Yifan
-----Original Message-----
From: Yuan, Perry <Perry.Yuan@amd.com>
Sent: Monday, November 23, 2026 3:23 PM
To: amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; Zhang, Yifan <Yifan1.Zhang@amd.com>; Yuan, Perry <Perry.Yuan@amd.com>
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.
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
---
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(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index a7a2b6b5a497..53eb4824f922 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -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;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 6478506d8089..5b366fc910ae 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -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
*/
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index c19600f8b7f8..09648b68d066 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -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;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
index b789f528f3b0..0cf13e78b821 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
@@ -2454,14 +2454,26 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool ena
return -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) {
diff --git a/drivers/gpu/drm/amd/include/amdgpu_ptl.h b/drivers/gpu/drm/amd/include/amdgpu_ptl.h
index eead62b4b327..c445525833a2 100644
--- a/drivers/gpu/drm/amd/include/amdgpu_ptl.h
+++ b/drivers/gpu/drm/amd/include/amdgpu_ptl.h
@@ -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
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-24 2:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 7:22 [PATCH 1/2] drm/amdgpu: add ptl_format module parameter Perry Yuan
2026-11-23 7:22 ` [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock Perry Yuan
2026-11-23 7:38 ` sashiko-bot
2026-11-24 2:58 ` Zhang, Yifan
2026-11-24 2:59 ` [PATCH 1/2] drm/amdgpu: add ptl_format module parameter Zhang, Yifan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.