drm/xe/rtp: Check hwe before calling match_func
Subsystems (2)
PATCH 1/1 drm/xe/rtp: Check hwe before calling match_func
XE_RTP_MATCH_FUNC may attempt to dereference the target xe_hw_engine. Ensure the hwe is not NULL before calling the function, matching XE_RTP_MATCH_ENGINE_CLASS, for example.
This covers a static analysis issue.
--- drivers/gpu/drm/xe/xe_rtp.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/xe/xe_rtp.c +3 -0
@@ -129,6 +129,9 @@ static bool rule_match_item(struct rule_match_ctx *match_ctx)return hwe->class != r->engine_class;case XE_RTP_MATCH_FUNC : +if (drm_WARN_ON (&xe->drm, !hwe)) +return false; +return r->match_func (xe, gt, hwe);default : drm_warn(&xe->drm, "Invalid RTP match %u\n",
Signature · 1 line
2.53.0
-----Original Message-----
From: Cavitt, Jonathan <[email protected]>
Sent: Thursday, May 28, 2026 2:34 PM
To: [email protected]
Cc: Gupta, Saurabhg <[email protected]>; Zuo, Alex <[email protected]>; Cavitt, Jonathan <[email protected]>; Sousa, Gustavo <[email protected]>
Subject: [PATCH] drm/xe/rtp: Check hwe before calling match_func
Quoted 18 lines
XE_RTP_MATCH_FUNCmay attempt to dereference the targetxe_hw_engine. Ensure the hwe is not NULL before calling the function, matchingXE_RTP_MATCH_ENGINE_CLASS, for example.This covers a static analysis issue.
Signed-off-by Jonathan Cavitt <[email protected]>Cc Gustavo Sousa <[email protected]>--- drivers/gpu/drm/xe/xe_rtp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/gpu/drm/xe/xe_rtp.c +0
-0
drivers/gpu/drm/xe/xe_rtp.c static bool rule_match_item(struct rule_match_ctx *match_ctx) · line 135
Quoted 7 lines
drivers/gpu/drm/xe/xe_rtp.c +3
-0@@ -129,6 +129,9 @@ static bool rule_match_item(struct rule_match_ctx *match_ctx)return hwe->class != r->engine_class;case XE_RTP_MATCH_FUNC : +if (drm_WARN_ON (&xe->drm, !hwe)) +return false; +return r->match_func (xe, gt, hwe);
I only just now noticed that this is also a possible issue with gt.
I'll wait for a response from Gustavo Sousa before creating a new revision with the added gt check, as it's possible these checks aren't necessary. If they aren't necessary, I'll just mark these as false positives on my end.
-Jonathan Cavitt
Quoted 6 lines
drivers/gpu/drm/xe/xe_rtp.c +0
-0default : drm_warn(&xe->drm, "Invalid RTP match %u\n",Signature · 1 line
2.53.0
Quoted 17 lines · Jonathan Cavitt
XE_RTP_MATCH_FUNCmay attempt to dereference the targetxe_hw_engine. Ensure the hwe is not NULL before calling the function, matchingXE_RTP_MATCH_ENGINE_CLASS, for example.This covers a static analysis issue.
Signed-off-by Jonathan Cavitt <[email protected]>Cc Gustavo Sousa <[email protected]>--- drivers/gpu/drm/xe/xe_rtp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/gpu/drm/xe/xe_rtp.c +0
-0
drivers/gpu/drm/xe/xe_rtp.c static bool rule_match_item(struct rule_match_ctx *match_ctx) · line 133
Quoted 5 lines
drivers/gpu/drm/xe/xe_rtp.c +2
-0@@ -129,6 +129,9 @@ static bool rule_match_item(struct rule_match_ctx *match_ctx)return hwe->class != r->engine_class;case XE_RTP_MATCH_FUNC : +if (drm_WARN_ON (&xe->drm, !hwe)) +return false;
There are several functions passed via XE_RTP_MATCH_FUNC() (i.e. MATCH() in definitions of RTP rules) that are meant to be used to do checks that do not depend on hwe. Returning false here is wrong as it will cause those checks to be skipped.
The developer is responsible for not passing a function that uses hwe in a context where it is NULL.
--
Gustavo Sousa
Quoted 6 lines
drivers/gpu/drm/xe/xe_rtp.c +1
-0+return r->match_func (xe, gt, hwe);default : drm_warn(&xe->drm, "Invalid RTP match %u\n",Signature · 1 line
2.53.0
-----Original Message-----
From: Sousa, Gustavo <[email protected]>
Sent: Thursday, May 28, 2026 3:30 PM
To: Cavitt, Jonathan <[email protected]>; [email protected]
Cc: Gupta, Saurabhg <[email protected]>; Zuo, Alex <[email protected]>; Cavitt, Jonathan <[email protected]>
Subject: Re: [PATCH] drm/xe/rtp: Check hwe before calling match_func
Quoted 31 lines
Quoted 17 lines · Jonathan Cavitt
XE_RTP_MATCH_FUNCmay attempt to dereference the targetxe_hw_engine. Ensure the hwe is not NULL before calling the function, matchingXE_RTP_MATCH_ENGINE_CLASS, for example.This covers a static analysis issue.
Signed-off-by Jonathan Cavitt <[email protected]>Cc Gustavo Sousa <[email protected]>--- drivers/gpu/drm/xe/xe_rtp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/gpu/drm/xe/xe_rtp.c +0
-0drivers/gpu/drm/xe/xe_rtp.c static bool rule_match_item(struct rule_match_ctx *match_ctx) · line 133
Quoted 5 lines
drivers/gpu/drm/xe/xe_rtp.c +2
-0@@ -129,6 +129,9 @@ static bool rule_match_item(struct rule_match_ctx *match_ctx)return hwe->class != r->engine_class;case XE_RTP_MATCH_FUNC : +if (drm_WARN_ON (&xe->drm, !hwe)) +return false;There are several functions passed via
XE_RTP_MATCH_FUNC()(i.e.MATCH()in definitions of RTP rules) that are meant to be used to do checks that do not depend on hwe. Returning false here is wrong as it will cause those checks to be skipped.
Quoted 2 lines
The developer is responsible for not passing a function that uses hwe in a context where it is NULL.
Understood, though quick question: is this also the case for GT? -Jonathan Cavitt
Quoted 11 lines
--
Gustavo SousaQuoted 6 lines
drivers/gpu/drm/xe/xe_rtp.c +1
-0+return r->match_func (xe, gt, hwe);default : drm_warn(&xe->drm, "Invalid RTP match %u\n",Signature · 1 line
2.53.0
Quoted 37 lines · Jonathan
-----Original Message-----
From: Sousa, Gustavo <[email protected]>
Sent: Thursday, May 28, 2026 3:30 PM
To: Cavitt, Jonathan <[email protected]>; [email protected]
Cc: Gupta, Saurabhg <[email protected]>; Zuo, Alex <[email protected]>; Cavitt, Jonathan <[email protected]>
Subject: Re: [PATCH] drm/xe/rtp: Check hwe before callingmatch_funcQuoted 31 lines
Quoted 17 lines · Jonathan Cavitt
XE_RTP_MATCH_FUNCmay attempt to dereference the targetxe_hw_engine. Ensure the hwe is not NULL before calling the function, matchingXE_RTP_MATCH_ENGINE_CLASS, for example.This covers a static analysis issue.
Signed-off-by Jonathan Cavitt <[email protected]>Cc Gustavo Sousa <[email protected]>--- drivers/gpu/drm/xe/xe_rtp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/gpu/drm/xe/xe_rtp.c +0
-0drivers/gpu/drm/xe/xe_rtp.c static bool rule_match_item(struct rule_match_ctx *match_ctx) · line 133
Quoted 5 lines
drivers/gpu/drm/xe/xe_rtp.c +2
-0@@ -129,6 +129,9 @@ static bool rule_match_item(struct rule_match_ctx *match_ctx)return hwe->class != r->engine_class;case XE_RTP_MATCH_FUNC : +if (drm_WARN_ON (&xe->drm, !hwe)) +return false;There are several functions passed via
XE_RTP_MATCH_FUNC()(i.e.MATCH()in definitions of RTP rules) that are meant to be used to do checks that do not depend on hwe. Returning false here is wrong as it will cause those checks to be skipped.
Quoted 4 lines
Quoted 2 lines
The developer is responsible for not passing a function that uses hwe in a context where it is NULL.
Understood, though quick question: is this also the case for GT?
Yep. Some examples:
* match_has_mert
* xe_rtp_match_not_sriov_vf
* xe_rtp_match_has_flat_ccs
--
Gustavo Sousa
Quoted 13 lines
-Jonathan Cavitt
Quoted 11 lines
--
Gustavo SousaQuoted 6 lines
drivers/gpu/drm/xe/xe_rtp.c +1
-0+return r->match_func (xe, gt, hwe);default : drm_warn(&xe->drm, "Invalid RTP match %u\n",Signature · 1 line
2.53.0