public inbox for intel-xe@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Gustavo Sousa <gustavo.sousa@intel.com>
To: "Lin, Shuicheng" <shuicheng.lin@intel.com>,
	"intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>
Subject: RE: [PATCH] drm/xe/hdcp: Add NULL check for media_gt in intel_hdcp_gsc_check_status()
Date: Wed, 11 Mar 2026 19:09:08 -0300	[thread overview]
Message-ID: <87jyvi588r.fsf@intel.com> (raw)
In-Reply-To: <DM4PR11MB5456C9921D64DCF63901C692EA7FA@DM4PR11MB5456.namprd11.prod.outlook.com>

"Lin, Shuicheng" <shuicheng.lin@intel.com> writes:

> On Tue, Mar 3, 2026 5:56 AM Gustavo Sousa wrote:
>> "Lin, Shuicheng" <shuicheng.lin@intel.com> writes:
>> 
>> > On Mon, Mar 2, 2026 10:19 AM Gustavo Sousa wrote:
>> >> When media GT is disabled via configfs, there is no allocation for
>> >> media_gt, which is kept as NULL.  In such scenario,
>> >> intel_hdcp_gsc_check_status() results in a kernel pagefault error due
>> >> to &gt-
>> >> >uc.gsc being evaluated as an invalid memory address.
>> >>
>> >> Fix that by introducing a NULL check on media_gt and bailing out early if so.
>> >>
>> >> Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
>> >> ---
>> >>  drivers/gpu/drm/xe/display/xe_hdcp_gsc.c | 6 ++++++
>> >>  1 file changed, 6 insertions(+)
>> >>
>> >> diff --git a/drivers/gpu/drm/xe/display/xe_hdcp_gsc.c
>> >> b/drivers/gpu/drm/xe/display/xe_hdcp_gsc.c
>> >> index 29c72aa4b0d2..1cac00c17d4c 100644
>> >> --- a/drivers/gpu/drm/xe/display/xe_hdcp_gsc.c
>> >> +++ b/drivers/gpu/drm/xe/display/xe_hdcp_gsc.c
>> >> @@ -39,6 +39,12 @@ static bool intel_hdcp_gsc_check_status(struct
>> >> drm_device *drm)
>> >>  	struct xe_gt *gt = tile->media_gt;
>> >>  	struct xe_gsc *gsc = &gt->uc.gsc;
>> >
>> > If gt is NULL, this "&gt->uc.gsc" is already undefined behavior.
>> 
>> I don't think so. It just turns out that the offset will be invalid. We are not
>> dereferencing the gt pointer here.
>
> I also thought it should be the offset of the structure, like offsetof() do.
> But it turns out not correct when I ask it to chatgpt. And here is an article to explain it:
> https://medium.com/@Code_Analysis/null-pointer-dereferencing-causes-undefined-behavior-32462a200106
>
> So, I still prefer to move the assignment to after the !gt check. 😊

I don't have access to the C standard, but the article and its
linked material sound convincing.  Thanks for sharing that!

I'll incorporate your suggestion.

--
Gustavo Sousa

>
> Shuicheng
>
>> 
>> > I would prefer to move this assignment to after below check.
>> 
>> I think that might be unecessary. Would you agree with keeping it as-is based
>> on my argument above?
>> 
>> >
>> >>
>> >> +	if (!gt) {
>> >> +		drm_dbg_kms(&xe->drm,
>> >> +			    "not checking GSC status for HDCP2.x: media GT not
>> >> present or disabled\n");
>> >> +		return false;
>> >> +	}
>> >> +
>> >>  	if (!gsc || !xe_uc_fw_is_available(&gsc->fw)) {
>> >
>> > BTW, if gt is not NULL, then gsc cannot be NULL. So this "!gsc" check
>> > could be dropped.
>> 
>> Yep. Makes sense.
>> 
>> --
>> Gustavo Sousa
>> 
>> >
>> > Shuicheng
>> >
>> >>  		drm_dbg_kms(&xe->drm,
>> >>  			    "GSC Components not ready for HDCP2.x\n");
>> >>
>> >> ---
>> >> base-commit: 40e52ed6c66cef091579dd7fe49ccd2de135f5c5
>> >> change-id: 20260302-check-for-null-media_gt-in-
>> >> intel_hdcp_gsc_check_status-071898b8a402
>> >>
>> >> Best regards,
>> >> --
>> >> Gustavo Sousa <gustavo.sousa@intel.com>

  reply	other threads:[~2026-03-11 22:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02 18:18 [PATCH] drm/xe/hdcp: Add NULL check for media_gt in intel_hdcp_gsc_check_status() Gustavo Sousa
2026-03-02 23:07 ` Lin, Shuicheng
2026-03-03 13:56   ` Gustavo Sousa
2026-03-03 16:53     ` Lin, Shuicheng
2026-03-11 22:09       ` Gustavo Sousa [this message]
2026-03-24  8:03         ` Bhadane, Dnyaneshwar
2026-03-03  0:37 ` ✓ CI.KUnit: success for " Patchwork
2026-03-03  1:12 ` ✓ Xe.CI.BAT: " Patchwork
2026-03-03  9:32 ` ✓ Xe.CI.FULL: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87jyvi588r.fsf@intel.com \
    --to=gustavo.sousa@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=shuicheng.lin@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox