Skip to contentSkip to conversation

drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

PATCH In review Perry Yuan 3 participants 9 messages Nov 1, 2021 – Nov 12, 2021

Subsystems (2)
lore
Share & tools
lore

Perry Yuan

author
#0 lore raw

PATCH v2 1/1 drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

Fix below crash by adding a check in the drm_dp_dpcd_access which ensures that aux->transfer was actually initialized earlier.

BUG: kernel NULL pointer dereference, address: 0000000000000000
PGD 0 P4D 0
Oops: 0010 [#1] SMP NOPTI
RIP: 0010:0x0
Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6.
RSP: 0018:ffffa8d64225bab8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000020 RCX: ffffa8d64225bb5e
RDX: ffff93151d921880 RSI: ffffa8d64225bac8 RDI: ffff931511a1a9d8
RBP: ffffa8d64225bb10 R08: 0000000000000001 R09: ffffa8d64225ba60
R10: 0000000000000002 R11: 000000000000000d R12: 0000000000000001
R13: 0000000000000000 R14: ffffa8d64225bb5e R15: ffff931511a1a9d8
FS: 00007ff8ea7fa9c0(0000) GS:ffff9317fe6c0000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffffffffd6 CR3: 000000010d5a4000 CR4: 0000000000750ee0
PKRU: 55555554
Call Trace:
drm_dp_dpcd_access+0x72/0x110 [drm_kms_helper]
drm_dp_dpcd_read+0xb7/0xf0 [drm_kms_helper]
drm_dp_start_crc+0x38/0xb0 [drm_kms_helper]
amdgpu_dm_crtc_set_crc_source+0x1ae/0x3e0 [amdgpu]
crtc_crc_open+0x174/0x220 [drm]
full_proxy_open+0x168/0x1f0
? open_proxy_open+0x100/0x100
do_dentry_open+0x156/0x370
vfs_open+0x2d/0x30

v2: fix some typo

---
 drivers/gpu/drm/drm_dp_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_dp_helper.c +4 -0
index 6d0f2c447f3b..76b28396001a 100644
@@ -260,6 +260,10 @@ static int drm_dp_dpcd_access(struct drm_dp_aux *aux, u8 request,
 	msg.buffer = buffer;
 	msg.size = size;
 
+	/* No transfer function is set, so not an available DP connector */
+	if (!aux->transfer)
+		return -EINVAL;
+
 	mutex_lock(&aux->hw_mutex);
 
 	/*
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · Perry Yuan

Fix below crash by adding a check in the drm_dp_dpcd_access which ensures that aux->transfer was actually initialized earlier.

Gut feeling says this is papering over a real usage issue somewhere else. Why is the aux being used for transfers before ->transfer has been set? Why should the dp helper be defensive against all kinds of misprogramming?

BR,
Jani.

Quoted 49 lines
BUG: kernel NULL pointer dereference, address: 0000000000000000
PGD 0 P4D 0
Oops: 0010 [#1] SMP NOPTI
RIP: 0010:0x0
Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6.
RSP: 0018:ffffa8d64225bab8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000020 RCX: ffffa8d64225bb5e
RDX: ffff93151d921880 RSI: ffffa8d64225bac8 RDI: ffff931511a1a9d8
RBP: ffffa8d64225bb10 R08: 0000000000000001 R09: ffffa8d64225ba60
R10: 0000000000000002 R11: 000000000000000d R12: 0000000000000001
R13: 0000000000000000 R14: ffffa8d64225bb5e R15: ffff931511a1a9d8
FS: 00007ff8ea7fa9c0(0000) GS:ffff9317fe6c0000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffffffffd6 CR3: 000000010d5a4000 CR4: 0000000000750ee0
PKRU: 55555554
Call Trace:
drm_dp_dpcd_access+0x72/0x110 [drm_kms_helper]
drm_dp_dpcd_read+0xb7/0xf0 [drm_kms_helper]
drm_dp_start_crc+0x38/0xb0 [drm_kms_helper]
amdgpu_dm_crtc_set_crc_source+0x1ae/0x3e0 [amdgpu]
crtc_crc_open+0x174/0x220 [drm]
full_proxy_open+0x168/0x1f0
? open_proxy_open+0x100/0x100
do_dentry_open+0x156/0x370
vfs_open+0x2d/0x30

v2: fix some typo

---
 drivers/gpu/drm/drm_dp_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_dp_helper.c +4 -0
index 6d0f2c447f3b..76b28396001a 100644
@@ -260,6 +260,10 @@ static int drm_dp_dpcd_access(struct drm_dp_aux *aux, u8 request,
 	msg.buffer = buffer;
 	msg.size = size;
 
+	/* No transfer function is set, so not an available DP connector */
+	if (!aux->transfer)
+		return -EINVAL;
+
 	mutex_lock(&aux->hw_mutex);
 
 	/*
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
#2 lore raw

[AMD Official Use Only]

Hi Jani:
Thanks for your comments.

Quoted 19 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, November 1, 2021 9:07 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: Yuan, Perry <[email protected]>; [email protected]; linux- [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray <[email protected]>
Subject: Re: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 2 lines · Perry Yuan

Fix below crash by adding a check in the drm_dp_dpcd_access which ensures that aux->transfer was actually initialized earlier.

Quoted 8 lines

Gut feeling says this is papering over a real usage issue somewhere else. Why is the aux being used for transfers before ->transfer has been set? Why should the dp helper be defensive against all kinds of misprogramming?

BR,
Jani.

The issue was found by Intel IGT test suite, graphic by pass test case.
https://gitlab.freedesktop.org/drm/igt-gpu-tools
normally use case will not see the issue.
To avoid this issue happy again when we run the test case , it will be nice to add a check before the transfer is called. And we can see that it really needs to have a check here to make ITG &kernel happy.

Perry.

Quoted 56 lines

drivers/gpu/drm/drm_dp_helper.c static int drm_dp_dpcd_access(struct drm_dp_aux

Quoted 42 lines

BUG: kernel NULL pointer dereference, address: 0000000000000000 PGD 0
P4D 0
Oops: 0010 [#1] SMP NOPTI
RIP: 0010:0x0
Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6.
RSP: 0018:ffffa8d64225bab8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000020 RCX: ffffa8d64225bb5e
RDX: ffff93151d921880 RSI: ffffa8d64225bac8 RDI: ffff931511a1a9d8
RBP: ffffa8d64225bb10 R08: 0000000000000001 R09: ffffa8d64225ba60
R10: 0000000000000002 R11: 000000000000000d R12: 0000000000000001
R13: 0000000000000000 R14: ffffa8d64225bb5e R15: ffff931511a1a9d8
FS: 00007ff8ea7fa9c0(0000) GS:ffff9317fe6c0000(0000)

knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffffffffd6 CR3: 000000010d5a4000 CR4: 0000000000750ee0
PKRU: 55555554

Call Trace:
drm_dp_dpcd_access+0x72/0x110 [drm_kms_helper]
drm_dp_dpcd_read+0xb7/0xf0 [drm_kms_helper]
drm_dp_start_crc+0x38/0xb0 [drm_kms_helper]
amdgpu_dm_crtc_set_crc_source+0x1ae/0x3e0 [amdgpu]
crtc_crc_open+0x174/0x220 [drm]
full_proxy_open+0x168/0x1f0
? open_proxy_open+0x100/0x100
do_dentry_open+0x156/0x370
vfs_open+0x2d/0x30

v2: fix some typo

---
 drivers/gpu/drm/drm_dp_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_dp_helper.c index 6d0f2c447f3b..76b28396001a 100644

drivers/gpu/drm/drm_dp_helper.c +0 -0
@@ -260,6 +260,10 @@ static int drm_dp_dpcd_access(struct drm_dp_aux

*aux, u8 request,

drivers/gpu/drm/drm_dp_helper.c static int drm_dp_dpcd_access(struct drm_dp_aux *aux, u8 request, · line 269

Quoted 10 lines
drivers/gpu/drm/drm_dp_helper.c +4 -0
      msg.buffer = buffer;
      msg.size = size;
 
+     /* No transfer function is set, so not an available DP connector */
+     if (!aux->transfer)
+             return -EINVAL;
+
      mutex_lock(&aux->hw_mutex);
 
      /*

--
Jani Nikula, Intel Open Source Graphics Center

#3 lore raw
Quoted 33 lines · Perry

[AMD Official Use Only]

Hi Jani:
Thanks for your comments.

Quoted 19 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, November 1, 2021 9:07 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: Yuan, Perry <[email protected]>; [email protected]; linux- [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray <[email protected]>
Subject: Re: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 2 lines · Perry Yuan

Fix below crash by adding a check in the drm_dp_dpcd_access which ensures that aux->transfer was actually initialized earlier.

Quoted 8 lines

Gut feeling says this is papering over a real usage issue somewhere else. Why is the aux being used for transfers before ->transfer has been set? Why should the dp helper be defensive against all kinds of misprogramming?

BR,
Jani.

Quoted 5 lines

The issue was found by Intel IGT test suite, graphic by pass test case.
https://gitlab.freedesktop.org/drm/igt-gpu-tools
normally use case will not see the issue.
To avoid this issue happy again when we run the test case , it will be nice to add a check before the transfer is called. And we can see that it really needs to have a check here to make ITG &kernel happy.

You're missing my point. What is the root cause? Why do you have the aux device or connector registered before ->transfer function is initialized. I don't think you should do that.

BR,
Jani.

Quoted 59 lines

Perry.

Quoted 56 lines

drivers/gpu/drm/drm_dp_helper.c static int drm_dp_dpcd_access(struct drm_dp_aux

Quoted 42 lines

BUG: kernel NULL pointer dereference, address: 0000000000000000 PGD 0
P4D 0
Oops: 0010 [#1] SMP NOPTI
RIP: 0010:0x0
Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6.
RSP: 0018:ffffa8d64225bab8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000020 RCX: ffffa8d64225bb5e
RDX: ffff93151d921880 RSI: ffffa8d64225bac8 RDI: ffff931511a1a9d8
RBP: ffffa8d64225bb10 R08: 0000000000000001 R09: ffffa8d64225ba60
R10: 0000000000000002 R11: 000000000000000d R12: 0000000000000001
R13: 0000000000000000 R14: ffffa8d64225bb5e R15: ffff931511a1a9d8
FS: 00007ff8ea7fa9c0(0000) GS:ffff9317fe6c0000(0000)

knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffffffffd6 CR3: 000000010d5a4000 CR4: 0000000000750ee0
PKRU: 55555554

Call Trace:
drm_dp_dpcd_access+0x72/0x110 [drm_kms_helper]
drm_dp_dpcd_read+0xb7/0xf0 [drm_kms_helper]
drm_dp_start_crc+0x38/0xb0 [drm_kms_helper]
amdgpu_dm_crtc_set_crc_source+0x1ae/0x3e0 [amdgpu]
crtc_crc_open+0x174/0x220 [drm]
full_proxy_open+0x168/0x1f0
? open_proxy_open+0x100/0x100
do_dentry_open+0x156/0x370
vfs_open+0x2d/0x30

v2: fix some typo

---
 drivers/gpu/drm/drm_dp_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_dp_helper.c index 6d0f2c447f3b..76b28396001a 100644

drivers/gpu/drm/drm_dp_helper.c +0 -0
@@ -260,6 +260,10 @@ static int drm_dp_dpcd_access(struct drm_dp_aux

*aux, u8 request,

drivers/gpu/drm/drm_dp_helper.c static int drm_dp_dpcd_access(struct drm_dp_aux *aux, u8 request, · line 269

Quoted 10 lines
drivers/gpu/drm/drm_dp_helper.c +4 -0
      msg.buffer = buffer;
      msg.size = size;
 
+     /* No transfer function is set, so not an available DP connector */
+     if (!aux->transfer)
+             return -EINVAL;
+
      mutex_lock(&aux->hw_mutex);
 
      /*

--
Jani Nikula, Intel Open Source Graphics Center

Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
#4 lore raw

[AMD Official Use Only]

Hi Jani:

Quoted 70 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Tuesday, November 2, 2021 4:40 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: [email protected]; [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray <[email protected]>
Subject: RE: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 11 lines · Perry

[AMD Official Use Only]

Hi Jani:
Thanks for your comments.

Quoted 6 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, November 1, 2021 9:07 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>;

David

Quoted 4 lines
Quoted 4 lines

Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: Yuan, Perry <[email protected]>; [email protected]; linux- [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray

<[email protected]>

Quoted 5 lines
Quoted 5 lines

Subject: Re: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 7 lines
Quoted 7 lines · Perry Yuan
Quoted 2 lines

Fix below crash by adding a check in the drm_dp_dpcd_access which ensures that aux->transfer was actually initialized earlier.

Gut feeling says this is papering over a real usage issue somewhere else. Why is the aux being used for transfers before ->transfer has been set? Why should the dp helper be defensive against all kinds of

misprogramming?

Quoted 9 lines
Quoted 5 lines

BR,
Jani.

The issue was found by Intel IGT test suite, graphic by pass test case.
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitl
ab.freedesktop.org%2Fdrm%2Figt-gpu-

tools&amp;data=04%7C01%7CPerry.Yuan

Quoted 1 line

%40amd.com%7C83d011acfe65437c0fa808d99ddc65b0%7C3dd8961fe4884e6

08e11a8

Quoted 1 line

2d994e183d%7C0%7C0%7C637714392203200313%7CUnknown%7CTWFpbGZsb 3d8eyJWIj

Quoted 1 line

oiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C100 0&am

Quoted 1 line

p;sdata=snPpRYLGeJtTpNGle1YHZAvevcABbgLkgOsffiNzQPw%3D&amp;reserved =0

Quoted 2 lines

normally use case will not see the issue.
To avoid this issue happy again when we run the test case , it will be nice to

add a check before the transfer is called.

Quoted 1 line

And we can see that it really needs to have a check here to make ITG &kernel

Quoted 9 lines

happy.

You're missing my point. What is the root cause? Why do you have the aux device or connector registered before ->transfer function is initialized. I don't think you should do that.

BR,
Jani.

One potential IGT fix patch to resolve the test case failure is:

tests/amdgpu/amd_bypass.c
data->pipe_crc = igt_pipe_crc_new(data->drm_fd, data->pipe_id,
- AMDGPU_PIPE_CRC_SOURCE_DPRX);
+ INTEL_PIPE_CRC_SOURCE_AUTO);
The kernel panic error gone after change "dprx" to "auto" in the IGT test.

In my view ,the IGT amdgpu bypass test will do some common setup work including crc piple, source. When the IGT sets up a new CRC pipe capture source for amdgpu bypass test, the SOURCE was set as "dprx" instead of "auto" It makes "amdgpu_dm_crtc_set_crc_source()" failed to set correct AUX and it's transfer function invalid . The system I tested use HDMI port connected to monitor .

amdgpu_dm_crtc_set_crc_source-> (aux = (aconn->port) ? &aconn->port->aux : &aconn->dm_dp_aux.aux;)

	 drm_dp_start_crc ->   
		drm_dp_dpcd_readb->   aux->transfer is NULL, issue here. 

The fix will use the "auto" keyword, which will let the driver select a default source of frame CRCs for this CRTC.

Correct me if have some wrong points.

Thank you!
Perry.

Quoted 64 lines
Quoted 61 lines

Perry.

Quoted 57 lines
Quoted 42 lines

BUG: kernel NULL pointer dereference, address: 0000000000000000 PGD
0 P4D 0
Oops: 0010 [#1] SMP NOPTI
RIP: 0010:0x0
Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6.
RSP: 0018:ffffa8d64225bab8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000020 RCX: ffffa8d64225bb5e
RDX: ffff93151d921880 RSI: ffffa8d64225bac8 RDI: ffff931511a1a9d8
RBP: ffffa8d64225bb10 R08: 0000000000000001 R09: ffffa8d64225ba60
R10: 0000000000000002 R11: 000000000000000d R12: 0000000000000001
R13: 0000000000000000 R14: ffffa8d64225bb5e R15: ffff931511a1a9d8
FS: 00007ff8ea7fa9c0(0000) GS:ffff9317fe6c0000(0000)

knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffffffffd6 CR3: 000000010d5a4000 CR4: 0000000000750ee0
PKRU: 55555554

Call Trace:
drm_dp_dpcd_access+0x72/0x110 [drm_kms_helper]
drm_dp_dpcd_read+0xb7/0xf0 [drm_kms_helper]
drm_dp_start_crc+0x38/0xb0 [drm_kms_helper]
amdgpu_dm_crtc_set_crc_source+0x1ae/0x3e0 [amdgpu]
crtc_crc_open+0x174/0x220 [drm]
full_proxy_open+0x168/0x1f0
? open_proxy_open+0x100/0x100
do_dentry_open+0x156/0x370
vfs_open+0x2d/0x30

v2: fix some typo

---
 drivers/gpu/drm/drm_dp_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_dp_helper.c index 6d0f2c447f3b..76b28396001a 100644

drivers/gpu/drm/drm_dp_helper.c +0 -0
@@ -260,6 +260,10 @@ static int drm_dp_dpcd_access(struct
Quoted 1 line

drm_dp_aux

*aux, u8 request,

drivers/gpu/drm/drm_dp_helper.c static int drm_dp_dpcd_access(struct drm_dp_aux *aux, u8 request, · line 269

Quoted 10 lines
      msg.buffer = buffer;
      msg.size = size;
drivers/gpu/drm/drm_dp_helper.c +4 -0
+     /* No transfer function is set, so not an available DP connector */
+     if (!aux->transfer)
+             return -EINVAL;
+
      mutex_lock(&aux->hw_mutex);
 
      /*

--
Jani Nikula, Intel Open Source Graphics Center

--
Jani Nikula, Intel Open Source Graphics Center

#5 lore raw
Quoted 97 lines · Perry

[AMD Official Use Only]

Hi Jani:

Quoted 70 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Tuesday, November 2, 2021 4:40 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: [email protected]; [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray <[email protected]>
Subject: RE: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 11 lines · Perry

[AMD Official Use Only]

Hi Jani:
Thanks for your comments.

Quoted 6 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, November 1, 2021 9:07 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>;

David

Quoted 4 lines
Quoted 4 lines

Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: Yuan, Perry <[email protected]>; [email protected]; linux- [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray

<[email protected]>

Quoted 5 lines
Quoted 5 lines

Subject: Re: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 7 lines
Quoted 7 lines · Perry Yuan
Quoted 2 lines

Fix below crash by adding a check in the drm_dp_dpcd_access which ensures that aux->transfer was actually initialized earlier.

Gut feeling says this is papering over a real usage issue somewhere else. Why is the aux being used for transfers before ->transfer has been set? Why should the dp helper be defensive against all kinds of

misprogramming?

Quoted 9 lines
Quoted 5 lines

BR,
Jani.

The issue was found by Intel IGT test suite, graphic by pass test case.
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitl
ab.freedesktop.org%2Fdrm%2Figt-gpu-

tools&amp;data=04%7C01%7CPerry.Yuan

Quoted 1 line

%40amd.com%7C83d011acfe65437c0fa808d99ddc65b0%7C3dd8961fe4884e6

08e11a8

Quoted 1 line

2d994e183d%7C0%7C0%7C637714392203200313%7CUnknown%7CTWFpbGZsb 3d8eyJWIj

Quoted 1 line

oiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C100 0&am

Quoted 1 line

p;sdata=snPpRYLGeJtTpNGle1YHZAvevcABbgLkgOsffiNzQPw%3D&amp;reserved =0

Quoted 2 lines

normally use case will not see the issue.
To avoid this issue happy again when we run the test case , it will be nice to

add a check before the transfer is called.

Quoted 1 line

And we can see that it really needs to have a check here to make ITG &kernel

Quoted 9 lines

happy.

You're missing my point. What is the root cause? Why do you have the aux device or connector registered before ->transfer function is initialized. I don't think you should do that.

BR,
Jani.

One potential IGT fix patch to resolve the test case failure is:

tests/amdgpu/amd_bypass.c
data->pipe_crc = igt_pipe_crc_new(data->drm_fd, data->pipe_id,
- AMDGPU_PIPE_CRC_SOURCE_DPRX);
+ INTEL_PIPE_CRC_SOURCE_AUTO);
The kernel panic error gone after change "dprx" to "auto" in the IGT test.

In my view ,the IGT amdgpu bypass test will do some common setup work including crc piple, source. When the IGT sets up a new CRC pipe capture source for amdgpu bypass test, the SOURCE was set as "dprx" instead of "auto" It makes "amdgpu_dm_crtc_set_crc_source()" failed to set correct AUX and it's transfer function invalid . The system I tested use HDMI port connected to monitor .

Quoted 6 lines

amdgpu_dm_crtc_set_crc_source-> (aux = (aconn->port) ? &aconn->port->aux : &aconn->dm_dp_aux.aux;)

	 drm_dp_start_crc ->   
		drm_dp_dpcd_readb->   aux->transfer is NULL, issue here. 

The fix will use the "auto" keyword, which will let the driver select a default source of frame CRCs for this CRTC.

Correct me if have some wrong points.

Apparently I'm completely failing to communicate my POV to you.

If you have a kernel oops, the fix needs to be in the kernel, not IGT.

The question is, why is it possible for IGT (or any userspace) to trigger AUX communication when the ->transfer function is not set? In my opinion, the kernel driver should not have exposed the interface at all if the ->transfer function is not set. The interface is useless without the ->transfer function. IMO, that's the bug.

BR,
Jani.

Quoted 68 lines

Thank you!
Perry.

Quoted 64 lines
Quoted 61 lines

Perry.

Quoted 57 lines
Quoted 42 lines

BUG: kernel NULL pointer dereference, address: 0000000000000000 PGD
0 P4D 0
Oops: 0010 [#1] SMP NOPTI
RIP: 0010:0x0
Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6.
RSP: 0018:ffffa8d64225bab8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000020 RCX: ffffa8d64225bb5e
RDX: ffff93151d921880 RSI: ffffa8d64225bac8 RDI: ffff931511a1a9d8
RBP: ffffa8d64225bb10 R08: 0000000000000001 R09: ffffa8d64225ba60
R10: 0000000000000002 R11: 000000000000000d R12: 0000000000000001
R13: 0000000000000000 R14: ffffa8d64225bb5e R15: ffff931511a1a9d8
FS: 00007ff8ea7fa9c0(0000) GS:ffff9317fe6c0000(0000)

knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffffffffd6 CR3: 000000010d5a4000 CR4: 0000000000750ee0
PKRU: 55555554

Call Trace:
drm_dp_dpcd_access+0x72/0x110 [drm_kms_helper]
drm_dp_dpcd_read+0xb7/0xf0 [drm_kms_helper]
drm_dp_start_crc+0x38/0xb0 [drm_kms_helper]
amdgpu_dm_crtc_set_crc_source+0x1ae/0x3e0 [amdgpu]
crtc_crc_open+0x174/0x220 [drm]
full_proxy_open+0x168/0x1f0
? open_proxy_open+0x100/0x100
do_dentry_open+0x156/0x370
vfs_open+0x2d/0x30

v2: fix some typo

---
 drivers/gpu/drm/drm_dp_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_dp_helper.c index 6d0f2c447f3b..76b28396001a 100644

drivers/gpu/drm/drm_dp_helper.c +0 -0
@@ -260,6 +260,10 @@ static int drm_dp_dpcd_access(struct
Quoted 1 line

drm_dp_aux

*aux, u8 request,

drivers/gpu/drm/drm_dp_helper.c static int drm_dp_dpcd_access(struct drm_dp_aux *aux, u8 request, · line 269

Quoted 10 lines
      msg.buffer = buffer;
      msg.size = size;
drivers/gpu/drm/drm_dp_helper.c +4 -0
+     /* No transfer function is set, so not an available DP connector */
+     if (!aux->transfer)
+             return -EINVAL;
+
      mutex_lock(&aux->hw_mutex);
 
      /*

--
Jani Nikula, Intel Open Source Graphics Center

--
Jani Nikula, Intel Open Source Graphics Center

Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
#6 lore raw

[AMD Official Use Only]

Hi Jani:

Quoted 141 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Wednesday, November 3, 2021 7:31 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: [email protected]; [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray <[email protected]>
Subject: RE: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 10 lines · Perry

[AMD Official Use Only]

Hi Jani:

Quoted 6 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Tuesday, November 2, 2021 4:40 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>;

David

Quoted 3 lines
Quoted 3 lines

Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: [email protected]; [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray

<[email protected]>

Quoted 11 lines
Quoted 11 lines

Subject: RE: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 5 lines · Perry

[AMD Official Use Only]

Hi Jani:
Thanks for your comments.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, November 1, 2021 9:07 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann

<[email protected]>;

Quoted 22 lines
Quoted 22 lines

David

Quoted 4 lines
Quoted 4 lines

Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: Yuan, Perry <[email protected]>; [email protected]; linux- [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray

<[email protected]>

Quoted 5 lines
Quoted 5 lines

Subject: Re: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 8 lines
Quoted 8 lines · Perry Yuan
Quoted 2 lines

Fix below crash by adding a check in the drm_dp_dpcd_access which ensures that aux->transfer was actually initialized earlier.

Gut feeling says this is papering over a real usage issue somewhere else. Why is the aux being used for transfers before ->transfer has been set? Why should the dp helper be defensive against all kinds of

misprogramming?

Quoted 2 lines
Quoted 2 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

BR,
Jani.

The issue was found by Intel IGT test suite, graphic by pass test case.

https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fg

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

itl
ab.freedesktop.org%2Fdrm%2Figt-gpu-

tools&amp;data=04%7C01%7CPerry.Yuan

Quoted 1 line

%40amd.com%7C83d011acfe65437c0fa808d99ddc65b0%7C3dd8961fe4

884e6

Quoted 3 lines
Quoted 3 lines

08e11a8

Quoted 1 line

2d994e183d%7C0%7C0%7C637714392203200313%7CUnknown%7CTWFpbG Zsb

Quoted 3 lines
Quoted 3 lines

3d8eyJWIj

Quoted 1 line

oiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1 00

Quoted 3 lines
Quoted 3 lines

0&am

Quoted 1 line

p;sdata=snPpRYLGeJtTpNGle1YHZAvevcABbgLkgOsffiNzQPw%3D&amp;reser ved

Quoted 19 lines
Quoted 7 lines

=0

Quoted 3 lines

normally use case will not see the issue.
To avoid this issue happy again when we run the test case , it will be nice to

add a check before the transfer is called.

Quoted 2 lines

And we can see that it really needs to have a check here to make ITG &kernel

Quoted 9 lines

happy.

You're missing my point. What is the root cause? Why do you have the aux device or connector registered before ->transfer function is initialized. I don't think you should do that.

BR,
Jani.

One potential IGT fix patch to resolve the test case failure is:

Quoted 7 lines

tests/amdgpu/amd_bypass.c
data->pipe_crc = igt_pipe_crc_new(data->drm_fd, data->pipe_id,
- AMDGPU_PIPE_CRC_SOURCE_DPRX);
+ INTEL_PIPE_CRC_SOURCE_AUTO);
The kernel panic error gone after change "dprx" to "auto" in the IGT test.

In my view ,the IGT amdgpu bypass test will do some common setup work

including crc piple, source.

Quoted 1 line

When the IGT sets up a new CRC pipe capture source for amdgpu bypass

test, the SOURCE was set as "dprx" instead of "auto"

Quoted 1 line

It makes "amdgpu_dm_crtc_set_crc_source()" failed to set correct AUX

and it's transfer function invalid .

Quoted 7 lines

The system I tested use HDMI port connected to monitor .

amdgpu_dm_crtc_set_crc_source-> (aux = (aconn->port) ? &aconn-
port->aux : &aconn->dm_dp_aux.aux;)

       drm_dp_start_crc ->
              drm_dp_dpcd_readb->   aux->transfer is NULL, issue here.

The fix will use the "auto" keyword, which will let the driver select a

default source of frame CRCs for this CRTC.

Quoted 2 lines

Correct me if have some wrong points.

Apparently I'm completely failing to communicate my POV to you.

Quoted 8 lines

If you have a kernel oops, the fix needs to be in the kernel, not IGT.

The question is, why is it possible for IGT (or any userspace) to trigger AUX communication when the ->transfer function is not set? In my opinion, the kernel driver should not have exposed the interface at all if the ->transfer function is not set. The interface is useless without the ->transfer function. IMO, that's the bug.

Yes , you are correct , the transfer shouldn't be called before it is ready !

Let me explain more details in my view .
Maybe the root cause is not why the aux->transfer is not called before it is registered in this case. I suppose the issue was triggered by wrong CRC pipe source .

Actually the aux->transfer has been registered when amdgpu DM registered at kernel boot. IGT test was run when system login to Gnome desktop.

amdgpu_dm_initialize_dp_connector-> aconnector->dm_dp_aux.aux.transfer = dm_dp_aux_transfer;

The test case failed when the IGT set an "DPRX" CRC pipe source while the HDMI connected to monitor only. At this time, the aux->transfer is NULL, and dp helper did not check the transfer pointer NULL or not. It calls the transfers to DPCD read, then you see the kernel panic log.

amdgpu_dm_crtc_funcs-> amdgpu_dm_crtc_set_crc_source-> drm_dp_start_crc

* And if the DP cable connected only, the issue will not happen. Test will pass.
* If I change the CRC source to "auto", kernel will not see the panic as well. Maybe the failed test case need to run on the DP instead of HDMI, I am not sure at now.

Hopping this info can help.

Perry.

Quoted 83 lines

BR,
Jani.

Quoted 76 lines

Thank you!
Perry.

Quoted 72 lines
Quoted 69 lines

Perry.

Quoted 65 lines
Quoted 50 lines

BUG: kernel NULL pointer dereference, address: 0000000000000000
PGD
0 P4D 0
Oops: 0010 [#1] SMP NOPTI
RIP: 0010:0x0
Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6.
RSP: 0018:ffffa8d64225bab8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000020 RCX:

ffffa8d64225bb5e
RDX: ffff93151d921880 RSI: ffffa8d64225bac8 RDI:
ffff931511a1a9d8
RBP: ffffa8d64225bb10 R08: 0000000000000001 R09:
ffffa8d64225ba60
R10: 0000000000000002 R11: 000000000000000d R12:
0000000000000001
R13: 0000000000000000 R14: ffffa8d64225bb5e R15:
ffff931511a1a9d8
FS: 00007ff8ea7fa9c0(0000) GS:ffff9317fe6c0000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffffffffd6 CR3: 000000010d5a4000 CR4:
0000000000750ee0
PKRU: 55555554

Call Trace:
drm_dp_dpcd_access+0x72/0x110 [drm_kms_helper]
drm_dp_dpcd_read+0xb7/0xf0 [drm_kms_helper]
drm_dp_start_crc+0x38/0xb0 [drm_kms_helper]
amdgpu_dm_crtc_set_crc_source+0x1ae/0x3e0 [amdgpu]
crtc_crc_open+0x174/0x220 [drm]
full_proxy_open+0x168/0x1f0
? open_proxy_open+0x100/0x100
do_dentry_open+0x156/0x370
vfs_open+0x2d/0x30

v2: fix some typo

---
 drivers/gpu/drm/drm_dp_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_dp_helper.c index
6d0f2c447f3b..76b28396001a
100644

drivers/gpu/drm/drm_dp_helper.c +0 -0
@@ -260,6 +260,10 @@ static int drm_dp_dpcd_access(struct
Quoted 1 line

drm_dp_aux

*aux, u8 request,

drivers/gpu/drm/drm_dp_helper.c static int drm_dp_dpcd_access(struct drm_dp_aux *aux, u8 request, · line 269

Quoted 10 lines
      msg.buffer = buffer;
      msg.size = size;
drivers/gpu/drm/drm_dp_helper.c +4 -0
+     /* No transfer function is set, so not an available DP connector */
+     if (!aux->transfer)
+             return -EINVAL;
+
      mutex_lock(&aux->hw_mutex);
 
      /*

--
Jani Nikula, Intel Open Source Graphics Center

--
Jani Nikula, Intel Open Source Graphics Center

--
Jani Nikula, Intel Open Source Graphics Center

#7 lore raw
Quoted 82 lines · Perry

[AMD Official Use Only]

Hi Jani:

Quoted 77 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Wednesday, November 3, 2021 7:31 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: [email protected]; [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray <[email protected]>
Subject: RE: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 10 lines · Perry

[AMD Official Use Only]

Hi Jani:

Quoted 6 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Tuesday, November 2, 2021 4:40 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>;

David

Quoted 3 lines
Quoted 3 lines

Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: [email protected]; [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray

<[email protected]>

Quoted 11 lines
Quoted 11 lines

Subject: RE: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 5 lines · Perry

[AMD Official Use Only]

Hi Jani:
Thanks for your comments.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, November 1, 2021 9:07 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann

<[email protected]>;

Quoted 22 lines
Quoted 22 lines

David

Quoted 4 lines
Quoted 4 lines

Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: Yuan, Perry <[email protected]>; [email protected]; linux- [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray

<[email protected]>

Quoted 5 lines
Quoted 5 lines

Subject: Re: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 8 lines
Quoted 8 lines · Perry Yuan
Quoted 2 lines

Fix below crash by adding a check in the drm_dp_dpcd_access which ensures that aux->transfer was actually initialized earlier.

Gut feeling says this is papering over a real usage issue somewhere else. Why is the aux being used for transfers before ->transfer has been set? Why should the dp helper be defensive against all kinds of

misprogramming?

Quoted 2 lines
Quoted 2 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

BR,
Jani.

The issue was found by Intel IGT test suite, graphic by pass test case.

https://g

itl

Quoted 88 lines
Quoted 63 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

ab.freedesktop.org%2Fdrm%2Figt-gpu-

tools&amp;data=04%7C01%7CPerry.Yuan

Quoted 1 line

%40amd.com%7C83d011acfe65437c0fa808d99ddc65b0%7C3dd8961fe4

884e6

Quoted 3 lines
Quoted 3 lines

08e11a8

Quoted 1 line

2d994e183d%7C0%7C0%7C637714392203200313%7CUnknown%7CTWFpbG Zsb

Quoted 3 lines
Quoted 3 lines

3d8eyJWIj

Quoted 1 line

oiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1 00

Quoted 3 lines
Quoted 3 lines

0&am

Quoted 1 line

p;sdata=snPpRYLGeJtTpNGle1YHZAvevcABbgLkgOsffiNzQPw%3D&amp;reser ved

Quoted 19 lines
Quoted 7 lines

=0

Quoted 3 lines

normally use case will not see the issue.
To avoid this issue happy again when we run the test case , it will be nice to

add a check before the transfer is called.

Quoted 2 lines

And we can see that it really needs to have a check here to make ITG &kernel

Quoted 9 lines

happy.

You're missing my point. What is the root cause? Why do you have the aux device or connector registered before ->transfer function is initialized. I don't think you should do that.

BR,
Jani.

One potential IGT fix patch to resolve the test case failure is:

Quoted 7 lines

tests/amdgpu/amd_bypass.c
data->pipe_crc = igt_pipe_crc_new(data->drm_fd, data->pipe_id,
- AMDGPU_PIPE_CRC_SOURCE_DPRX);
+ INTEL_PIPE_CRC_SOURCE_AUTO);
The kernel panic error gone after change "dprx" to "auto" in the IGT test.

In my view ,the IGT amdgpu bypass test will do some common setup work

including crc piple, source.

Quoted 1 line

When the IGT sets up a new CRC pipe capture source for amdgpu bypass

test, the SOURCE was set as "dprx" instead of "auto"

Quoted 1 line

It makes "amdgpu_dm_crtc_set_crc_source()" failed to set correct AUX

and it's transfer function invalid .

Quoted 7 lines

The system I tested use HDMI port connected to monitor .

amdgpu_dm_crtc_set_crc_source-> (aux = (aconn->port) ? &aconn-
port->aux : &aconn->dm_dp_aux.aux;)

       drm_dp_start_crc ->
              drm_dp_dpcd_readb->   aux->transfer is NULL, issue here.

The fix will use the "auto" keyword, which will let the driver select a

default source of frame CRCs for this CRTC.

Quoted 2 lines

Correct me if have some wrong points.

Apparently I'm completely failing to communicate my POV to you.

Quoted 8 lines

If you have a kernel oops, the fix needs to be in the kernel, not IGT.

The question is, why is it possible for IGT (or any userspace) to trigger AUX communication when the ->transfer function is not set? In my opinion, the kernel driver should not have exposed the interface at all if the ->transfer function is not set. The interface is useless without the ->transfer function. IMO, that's the bug.

Yes , you are correct , the transfer shouldn't be called before it is ready !

Let me explain more details in my view .
Maybe the root cause is not why the aux->transfer is not called before it is registered in this case. I suppose the issue was triggered by wrong CRC pipe source .

Actually the aux->transfer has been registered when amdgpu DM registered at kernel boot. IGT test was run when system login to Gnome desktop.

amdgpu_dm_initialize_dp_connector-> aconnector->dm_dp_aux.aux.transfer = dm_dp_aux_transfer;

The test case failed when the IGT set an "DPRX" CRC pipe source while the HDMI connected to monitor only. At this time, the aux->transfer is NULL, and dp helper did not check the transfer pointer NULL or not. It calls the transfers to DPCD read, then you see the kernel panic log.

Quoted 6 lines

amdgpu_dm_crtc_funcs-> amdgpu_dm_crtc_set_crc_source-> drm_dp_start_crc

* And if the DP cable connected only, the issue will not happen. Test will pass.
* If I change the CRC source to "auto", kernel will not see the panic as well. Maybe the failed test case need to run on the DP instead of HDMI, I am not sure at now.

Two things need to happen:
1) IGT should skip tests requiring DPRX CRC source if not on a DP connector.
2) Driver should return EINVAL (or another appropriate error) if DPRX CRC source is requested when the CRTC is not connected to a DP display. Alternatively we could make sure that DPRX is not advertised as a CRC source in this case but I'm not sure how difficult that would be.

Like Jani said, I don't think the current patch is the correct one as it doesn't get to the root cause. The root cause fix should be in the CRC debugfs handling code.

Harry

Quoted 89 lines

Hopping this info can help.

Perry.

Quoted 83 lines

BR,
Jani.

Quoted 76 lines

Thank you!
Perry.

Quoted 72 lines
Quoted 69 lines

Perry.

Quoted 65 lines
Quoted 50 lines

BUG: kernel NULL pointer dereference, address: 0000000000000000
PGD
0 P4D 0
Oops: 0010 [#1] SMP NOPTI
RIP: 0010:0x0
Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6.
RSP: 0018:ffffa8d64225bab8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000020 RCX:

ffffa8d64225bb5e
RDX: ffff93151d921880 RSI: ffffa8d64225bac8 RDI:
ffff931511a1a9d8
RBP: ffffa8d64225bb10 R08: 0000000000000001 R09:
ffffa8d64225ba60
R10: 0000000000000002 R11: 000000000000000d R12:
0000000000000001
R13: 0000000000000000 R14: ffffa8d64225bb5e R15:
ffff931511a1a9d8
FS: 00007ff8ea7fa9c0(0000) GS:ffff9317fe6c0000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffffffffd6 CR3: 000000010d5a4000 CR4:
0000000000750ee0
PKRU: 55555554

Call Trace:
drm_dp_dpcd_access+0x72/0x110 [drm_kms_helper]
drm_dp_dpcd_read+0xb7/0xf0 [drm_kms_helper]
drm_dp_start_crc+0x38/0xb0 [drm_kms_helper]
amdgpu_dm_crtc_set_crc_source+0x1ae/0x3e0 [amdgpu]
crtc_crc_open+0x174/0x220 [drm]
full_proxy_open+0x168/0x1f0
? open_proxy_open+0x100/0x100
do_dentry_open+0x156/0x370
vfs_open+0x2d/0x30

v2: fix some typo

---
 drivers/gpu/drm/drm_dp_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_dp_helper.c index
6d0f2c447f3b..76b28396001a
100644

drivers/gpu/drm/drm_dp_helper.c +0 -0
@@ -260,6 +260,10 @@ static int drm_dp_dpcd_access(struct
Quoted 1 line

drm_dp_aux

*aux, u8 request,

drivers/gpu/drm/drm_dp_helper.c

Quoted 10 lines
      msg.buffer = buffer;
      msg.size = size;
drivers/gpu/drm/drm_dp_helper.c +4 -0
+     /* No transfer function is set, so not an available DP connector */
+     if (!aux->transfer)
+             return -EINVAL;
+
      mutex_lock(&aux->hw_mutex);
 
      /*

--
Jani Nikula, Intel Open Source Graphics Center

--
Jani Nikula, Intel Open Source Graphics Center

--
Jani Nikula, Intel Open Source Graphics Center

#8 lore raw

[AMD Official Use Only]

Hi Harry.

Quoted 215 lines

-----Original Message-----
From: Wentland, Harry <[email protected]>
Sent: Wednesday, November 10, 2021 11:32 PM
To: Yuan, Perry <[email protected]>; Jani Nikula <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: Huang, Shimmer <[email protected]>; Huang, Ray <[email protected]>; [email protected]; dri- [email protected]; Limonciello, Mario <[email protected]>
Subject: Re: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

Quoted 11 lines · Perry

[AMD Official Use Only]

Hi Jani:

Quoted 6 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Wednesday, November 3, 2021 7:31 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>;

David

Quoted 3 lines
Quoted 3 lines

Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: [email protected]; [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray

<[email protected]>

Quoted 61 lines
Quoted 61 lines

Subject: RE: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 10 lines · Perry

[AMD Official Use Only]

Hi Jani:

Quoted 6 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Tuesday, November 2, 2021 4:40 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann <[email protected]>;

David

Quoted 3 lines
Quoted 3 lines

Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: [email protected]; [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray

<[email protected]>

Quoted 11 lines
Quoted 11 lines

Subject: RE: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 5 lines · Perry

[AMD Official Use Only]

Hi Jani:
Thanks for your comments.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Monday, November 1, 2021 9:07 PM
To: Yuan, Perry <[email protected]>; Maarten Lankhorst <[email protected]>; Maxime Ripard <[email protected]>; Thomas Zimmermann

<[email protected]>;

Quoted 22 lines
Quoted 22 lines

David

Quoted 4 lines
Quoted 4 lines

Airlie <[email protected]>; Daniel Vetter <[email protected]>
Cc: Yuan, Perry <[email protected]>; [email protected]; linux- [email protected]; Huang, Shimmer <[email protected]>; Huang, Ray

<[email protected]>

Quoted 5 lines
Quoted 5 lines

Subject: Re: [PATCH v2] drm/dp: Fix aux->transfer NULL pointer dereference on drm_dp_dpcd_access

[CAUTION: External Email]

Quoted 8 lines
Quoted 8 lines · Perry Yuan
Quoted 2 lines

Fix below crash by adding a check in the drm_dp_dpcd_access which ensures that aux->transfer was actually initialized earlier.

Gut feeling says this is papering over a real usage issue somewhere else. Why is the aux being used for transfers before ->transfer has been set? Why should the dp helper be defensive against all kinds of

misprogramming?

Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

BR,
Jani.

The issue was found by Intel IGT test suite, graphic by pass test case.

https://g

itl

Quoted 36 lines
Quoted 36 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

ab.freedesktop.org%2Fdrm%2Figt-gpu-

tools&amp;data=04%7C01%7CPerry.Yuan

Quoted 1 line

%40amd.com%7C83d011acfe65437c0fa808d99ddc65b0%7C3dd8961fe4

884e6

Quoted 3 lines
Quoted 3 lines

08e11a8

Quoted 1 line

2d994e183d%7C0%7C0%7C637714392203200313%7CUnknown%7CTWFpbG Zsb

Quoted 3 lines
Quoted 3 lines

3d8eyJWIj

Quoted 1 line

oiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1 00

Quoted 3 lines
Quoted 3 lines

0&am

Quoted 1 line

p;sdata=snPpRYLGeJtTpNGle1YHZAvevcABbgLkgOsffiNzQPw%3D&amp;reser ved

Quoted 17 lines
Quoted 16 lines

=0

Quoted 3 lines

normally use case will not see the issue.
To avoid this issue happy again when we run the test case , it will be nice to

add a check before the transfer is called.

Quoted 2 lines

And we can see that it really needs to have a check here to make ITG &kernel

happy.

You're missing my point. What is the root cause? Why do you have the aux device or connector registered before ->transfer function is initialized. I don't think you should do that.

BR,
Jani.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

One potential IGT fix patch to resolve the test case failure is:

tests/amdgpu/amd_bypass.c

      data->pipe_crc = igt_pipe_crc_new(data->drm_fd, data->pipe_id,
                                       - AMDGPU_PIPE_CRC_SOURCE_DPRX);
                                       +

INTEL_PIPE_CRC_SOURCE_AUTO); The kernel panic error gone after change

"dprx" to "auto" in the IGT test.

Quoted 29 lines
Quoted 21 lines
Quoted 3 lines

In my view ,the IGT amdgpu bypass test will do some common setup work

including crc piple, source.

Quoted 1 line

When the IGT sets up a new CRC pipe capture source for amdgpu bypass

test, the SOURCE was set as "dprx" instead of "auto"

Quoted 2 lines

It makes "amdgpu_dm_crtc_set_crc_source()" failed to set correct AUX

and it's transfer function invalid .

Quoted 8 lines

The system I tested use HDMI port connected to monitor .

amdgpu_dm_crtc_set_crc_source-> (aux = (aconn->port) ? &aconn-
port->aux : &aconn->dm_dp_aux.aux;)

       drm_dp_start_crc ->
              drm_dp_dpcd_readb->   aux->transfer is NULL, issue here.

The fix will use the "auto" keyword, which will let the driver select a

default source of frame CRCs for this CRTC.

Quoted 2 lines

Correct me if have some wrong points.

Quoted 8 lines

Apparently I'm completely failing to communicate my POV to you.

If you have a kernel oops, the fix needs to be in the kernel, not IGT.

The question is, why is it possible for IGT (or any userspace) to trigger AUX communication when the ->transfer function is not set? In my opinion, the kernel driver should not have exposed the interface
at all if the ->transfer function is not set. The interface is useless without the -

Quoted 8 lines

transfer function.

Quoted 2 lines

IMO, that's the bug.

Yes , you are correct , the transfer shouldn't be called before it is ready !

Let me explain more details in my view .
Maybe the root cause is not why the aux->transfer is not called before it is

registered in this case.

Quoted 3 lines

I suppose the issue was triggered by wrong CRC pipe source .

Actually the aux->transfer has been registered when amdgpu DM registered at

kernel boot.

Quoted 6 lines

IGT test was run when system login to Gnome desktop.

amdgpu_dm_initialize_dp_connector-> aconnector->dm_dp_aux.aux.transfer = dm_dp_aux_transfer;

The test case failed when the IGT set an "DPRX" CRC pipe source while the

HDMI connected to monitor only.

Quoted 1 line

At this time, the aux->transfer is NULL, and dp helper did not check the

transfer pointer NULL or not.

Quoted 8 lines

It calls the transfers to DPCD read, then you see the kernel panic log.

amdgpu_dm_crtc_funcs-> amdgpu_dm_crtc_set_crc_source-> drm_dp_start_crc

* And if the DP cable connected only, the issue will not happen. Test will pass.
* If I change the CRC source to "auto", kernel will not see the panic as well. Maybe the failed test case need to run on the DP instead of HDMI, I am not

sure at now.

Quoted 1 line

Two things need to happen:
1) IGT should skip tests requiring DPRX CRC source if not on a DP connector.
2) Driver should return EINVAL (or another appropriate error) if DPRX CRC source is requested when the CRTC is not connected to a DP display. Alternatively we could make sure that DPRX is not advertised as a CRC source in this case but I'm not sure how difficult that would be.

Quoted 4 lines

Like Jani said, I don't think the current patch is the correct one as it doesn't get to the root cause. The root cause fix should be in the CRC debugfs handling code.

Harry

Got your point.
I will make another two patches as you suggested.
Thanks for your feedback.

Perry.

Quoted 90 lines
Quoted 90 lines

Hopping this info can help.

Perry.

Quoted 83 lines

BR,
Jani.

Quoted 76 lines

Thank you!
Perry.

Quoted 72 lines
Quoted 69 lines

Perry.

Quoted 65 lines
Quoted 50 lines

BUG: kernel NULL pointer dereference, address: 0000000000000000
PGD
0 P4D 0
Oops: 0010 [#1] SMP NOPTI
RIP: 0010:0x0
Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6.
RSP: 0018:ffffa8d64225bab8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000020 RCX:

ffffa8d64225bb5e
RDX: ffff93151d921880 RSI: ffffa8d64225bac8 RDI:
ffff931511a1a9d8
RBP: ffffa8d64225bb10 R08: 0000000000000001 R09:
ffffa8d64225ba60
R10: 0000000000000002 R11: 000000000000000d R12:
0000000000000001
R13: 0000000000000000 R14: ffffa8d64225bb5e R15:
ffff931511a1a9d8
FS: 00007ff8ea7fa9c0(0000) GS:ffff9317fe6c0000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffffffffd6 CR3: 000000010d5a4000 CR4:
0000000000750ee0
PKRU: 55555554

Call Trace:
drm_dp_dpcd_access+0x72/0x110 [drm_kms_helper]
drm_dp_dpcd_read+0xb7/0xf0 [drm_kms_helper]
drm_dp_start_crc+0x38/0xb0 [drm_kms_helper]
amdgpu_dm_crtc_set_crc_source+0x1ae/0x3e0 [amdgpu]
crtc_crc_open+0x174/0x220 [drm]
full_proxy_open+0x168/0x1f0
? open_proxy_open+0x100/0x100
do_dentry_open+0x156/0x370
vfs_open+0x2d/0x30

v2: fix some typo

---
 drivers/gpu/drm/drm_dp_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_dp_helper.c index
6d0f2c447f3b..76b28396001a
100644

drivers/gpu/drm/drm_dp_helper.c +0 -0
@@ -260,6 +260,10 @@ static int drm_dp_dpcd_access(struct
Quoted 1 line

drm_dp_aux

*aux, u8 request,

drivers/gpu/drm/drm_dp_helper.c

Quoted 10 lines
      msg.buffer = buffer;
      msg.size = size;
drivers/gpu/drm/drm_dp_helper.c +4 -0
+     /* No transfer function is set, so not an available DP connector */
+     if (!aux->transfer)
+             return -EINVAL;
+
      mutex_lock(&aux->hw_mutex);
 
      /*

--
Jani Nikula, Intel Open Source Graphics Center

--
Jani Nikula, Intel Open Source Graphics Center

--
Jani Nikula, Intel Open Source Graphics Center