drm/amd/display: Route connector DDC over AUX for native DP sinks
Subsystems (3)
PATCH v2 1/1 drm/amd/display: Route connector DDC over AUX for native DP sinks
On DisplayPort and eDP connectors DDC is tunneled over the AUX channel, but the connector's "ddc" adapter ("AMDGPU DM i2c hw bus N") always drives the physical i2c pins, which don't reach a native DP sink. The AUX backed adapter ("AMDGPU DM aux hw bus N") does, so userspace such as fwupd, which uses the "ddc" sysfs link for DDC/CI, has to work around this.
Keep a single i2c bus per connector and pick the transport per transfer based on the detected sink: if the sink is a native DP/eDP/MST sink, forward the transfer to the AUX adapter, otherwise (DVI/HDMI, including DP++ with a passive adapter) use the hw i2c engine as before.
---
Changes in v2:
- Check which i2c bus to use on the fly instead of changing static symlink to avoid regressing passive adapters.
- Link to v1: https://patch.msgid.link/[email protected]
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +16 -0
@@ -3373,6 +3373,22 @@ STATIC_IFN_KUNIT int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,int i;int result = -EIO ; +if (!i2c->oem) { +struct dc_link *link = ddc_service->link; +struct amdgpu_dm_connector *aconnector = link->priv; + +/* +* DDC to a native DisplayPort sink is tunneled over the AUX +* channel; the physical i2c pins only reach DVI/HDMI sinks +* (e.g. DP++ with a passive adapter). Route accordingly so +* the connector's single "ddc" bus works for either sink. +*/ +if (aconnector && link->local_sink && +dc_is_dp_signal (link->local_sink->sink_signal) && + aconnector->dm_dp_aux.aux.ddc.algo) +return i2c_transfer (&aconnector->dm_dp_aux.aux.ddc, msgs, num); + } +if (!ddc_service->ddc_pin)return result;
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261102-superm1-amdgpu-ddc-63f0eb10c022
Best regards,
Signature · 1 line
Mario Limonciello <[email protected]>
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Critical] drm/amd/display: UAF race on link->local_sink in amdgpu_dm_i2c_xfer() - [High]…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] drm/amd/display: UAF race on link->local_sink in amdgpu_dm_i2c_xfer()
- [High] drm/amd/display: NULL link dereference in amdgpu_dm_i2c_xfer()
- [Medium] drm/amd/display: amdgpu_dm_i2c_xfer() misses MST and force_to_use_aux links --
commit 7a7dcab86c8948b21ebe53eebc9df866754fd915
Author: Mario Limonciello <[email protected]>
drm/amd/display: Route connector DDC over AUX for native DP sinks
This commit updates amdgpu_dm_i2c_xfer() to route I2C transfers over the DisplayPort AUX DDC adapter when a native DisplayPort, eDP, or MST sink is detected on the link, while keeping the hardware I2C engine for DVI/HDMI sinks.
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c STATIC_IFN_KUNIT int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap, · line 3378
Quoted 11 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +3
-0@@ -3373,6 +3373,22 @@ STATIC_IFN_KUNIT int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,int i;int result = -EIO ; +if (!i2c->oem) { +struct dc_link *link = ddc_service->link; +struct amdgpu_dm_connector *aconnector = link->priv;
[Severity: High]
Can ddc_service->link be NULL here?
Previously, amdgpu_dm_i2c_xfer() checked ddc_service->ddc_pin before dereferencing ddc_service->link. Moving this block ahead of the ddc_service->ddc_pin check without verifying that link is non-NULL causes a NULL pointer dereference in the existing KUnit test dm_test_i2c_xfer_no_ddc_pin():
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c:dm_test_i2c_xfer_no_ddc_pin() {
...
i2c->ddc_service = ddc;
i2c_set_adapdata(&i2c->base, i2c);
/* ddc->ddc_pin is NULL -> transfer is rejected with -EIO. */
KUNIT_EXPECT_EQ(test, amdgpu_dm_i2c_xfer(&i2c->base, NULL, 0), -EIO);
}In that test, i2c->oem is false and ddc->link is NULL, so evaluating link->priv crashes immediately.
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c STATIC_IFN_KUNIT int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap, · line 3387
Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +9
-0+ +/* +* DDC to a native DisplayPort sink is tunneled over the AUX +* channel; the physical i2c pins only reach DVI/HDMI sinks +* (e.g. DP++ with a passive adapter). Route accordingly so +* the connector's single "ddc" bus works for either sink. +*/ + if (aconnector && link->local_sink && + dc_is_dp_signal(link->local_sink->sink_signal) &&
[Severity: Critical]
What protects link->local_sink against concurrent hotplug or link detection while amdgpu_dm_i2c_xfer() reads and dereferences it?
Userspace I2C transfers on /dev/i2c-N invoke amdgpu_dm_i2c_xfer() holding only i2c_adap->bus_lock, without acquiring aconnector->hpd_lock or adev->dm.dc_lock and without taking a sink reference via dc_sink_retain().
Concurrently, link detection and disconnect paths release and free link->local_sink before clearing or updating the pointer:
drivers/gpu/drm/amd/display/dc/link/link_detection.c:link_disconnect_sink() {
if (link->local_sink) {
dc_sink_release(link->local_sink);
link->local_sink = NULL;
}
...
}drivers/gpu/drm/amd/display/dc/link/link_detection.c:link_disconnect_remap() {
dc_sink_release(link->local_sink);
link->local_sink = prev_sink;
}Similar unserialized releases happen in amdgpu_dm_connector_poll(), amdgpu_dm_emulated_link_detect(), and detect_link_and_local_sink() (for example when a temporary local_sink with refcount 1 is released on EDID read failure, same_edid remap, or MST topology discovery). Could a concurrent I2C transfer observe a non-NULL link->local_sink and suffer a use-after-free or NULL pointer dereference when reading link->local_sink->sink_signal?
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c STATIC_IFN_KUNIT int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap, · line 3390
Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +3
-0+ aconnector->dm_dp_aux.aux.ddc.algo) +return i2c_transfer (&aconnector->dm_dp_aux.aux.ddc, msgs, num); + }
[Severity: Medium]
Will checking link->local_sink and dc_is_dp_signal() work for DP MST links or links with force_to_use_aux set?
When an MST topology is started in discover_dp_mst_topology(), link_disconnect_sink() is called immediately:
drivers/gpu/drm/amd/display/dc/link/link_detection.c:discover_dp_mst_topology() {
...
if (dm_helpers_dp_mst_start_top_mgr(link->ctx,
link, (reason == DETECT_REASON_BOOT || reason == DETECT_REASON_RESUMEFROMS3S4))) {
link_disconnect_sink(link);
} else {
...
}This sets link->local_sink to NULL while downstream sinks are stored in link->remote_sinks[], so link->local_sink is NULL on active MST links and transfers will not be routed to the AUX adapter as described in the commit message.
Additionally, on connectors with link->force_to_use_aux set (such as ASICs with no_ddc_pin where ddc_service->ddc_pin is NULL), detect_dp() sets the transaction type to DDC_TRANSACTION_TYPE_I2C_OVER_AUX (setting link->aux_mode = true) while dp_passive_dongle_detection() sets sink_caps->signal to HDMI or DVI:
drivers/gpu/drm/amd/display/dc/link/link_detection.c:detect_dp() {
...
if (!detect_dp_sink_caps(link)) {
if (link->force_to_use_aux) {
sink_caps->signal = dp_passive_dongle_detection(link->ddc, sink_caps, audio_support);
...
}In that case dc_is_dp_signal(link->local_sink->sink_signal) is false and the transfer falls through to the hardware I2C path (or fails with -EIO when ddc_pin is NULL). Would checking link->aux_mode (similar to other DDC selection paths in amdgpu_dm) handle native DP, MST, and force_to_use_aux links without dereferencing link->local_sink?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 61 lines · Mario Limonciello
On DisplayPort and eDP connectors DDC is tunneled over the AUX channel, but the connector's "ddc" adapter ("AMDGPU DM i2c hw bus N") always drives the physical i2c pins, which don't reach a native DP sink. The AUX backed adapter ("AMDGPU DM aux hw bus N") does, so userspace such as fwupd, which uses the "ddc" sysfs link for DDC/CI, has to work around this.
Keep a single i2c bus per connector and pick the transport per transfer based on the detected sink: if the sink is a native DP/eDP/MST sink, forward the transfer to the AUX adapter, otherwise (DVI/HDMI, including DP++ with a passive adapter) use the hw i2c engine as before.
Reported-by [email protected]Signed-off-by Mario Limonciello <[email protected]>---
Changes in v2:
- Check which i2c bus to use on the fly instead of changing static symlink to avoid regressing passive adapters.
- Link to v1: https://patch.msgid.link/[email protected]--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +16
-1@@ -3373,6 +3373,22 @@ STATIC_IFN_KUNIT int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,int i;int result = -EIO ; +if (!i2c->oem) { +struct dc_link *link = ddc_service->link; +struct amdgpu_dm_connector *aconnector = link->priv; + +/* +* DDC to a native DisplayPort sink is tunneled over the AUX +* channel; the physical i2c pins only reach DVI/HDMI sinks +* (e.g. DP++ with a passive adapter). Route accordingly so +* the connector's single "ddc" bus works for either sink. +*/ +if (aconnector && link->local_sink && +dc_is_dp_signal (link->local_sink->sink_signal) && + aconnector->dm_dp_aux.aux.ddc.algo) +return i2c_transfer (&aconnector->dm_dp_aux.aux.ddc, msgs, num); + } +if (!ddc_service->ddc_pin)return result; ---base-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261102-superm1-amdgpu-ddc-63f0eb10c022Best regards,
Signature · 1 line
Mario Limonciello <[email protected]>
Quoted 1 line · Wayne Lin
Reviewed-by Wayne Lin <[email protected]>
Thanks Wayne.
Simon, Richard,
Can you please check that this resolves the issue raised?
Thanks,
Quoted 63 lines · Mario Limonciello
Quoted 61 lines
On DisplayPort and eDP connectors DDC is tunneled over the AUX channel, but the connector's "ddc" adapter ("AMDGPU DM i2c hw bus N") always drives the physical i2c pins, which don't reach a native DP sink. The AUX backed adapter ("AMDGPU DM aux hw bus N") does, so userspace such as fwupd, which uses the "ddc" sysfs link for DDC/CI, has to work around this.
Keep a single i2c bus per connector and pick the transport per transfer based on the detected sink: if the sink is a native DP/eDP/MST sink, forward the transfer to the AUX adapter, otherwise (DVI/HDMI, including DP++ with a passive adapter) use the hw i2c engine as before.
Reported-by [email protected]Signed-off-by Mario Limonciello <[email protected]>---
Changes in v2:
- Check which i2c bus to use on the fly instead of changing static symlink to avoid regressing passive adapters.
- Link to v1: https://patch.msgid.link/[email protected]--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +16
-1@@ -3373,6 +3373,22 @@ STATIC_IFN_KUNIT int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,int i;int result = -EIO ; +if (!i2c->oem) { +struct dc_link *link = ddc_service->link; +struct amdgpu_dm_connector *aconnector = link->priv; + +/* +* DDC to a native DisplayPort sink is tunneled over the AUX +* channel; the physical i2c pins only reach DVI/HDMI sinks +* (e.g. DP++ with a passive adapter). Route accordingly so +* the connector's single "ddc" bus works for either sink. +*/ +if (aconnector && link->local_sink && +dc_is_dp_signal (link->local_sink->sink_signal) && + aconnector->dm_dp_aux.aux.ddc.algo) +return i2c_transfer (&aconnector->dm_dp_aux.aux.ddc, msgs, num); + } +if (!ddc_service->ddc_pin)return result; ---base-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261102-superm1-amdgpu-ddc-63f0eb10c022Best regards,
--
Mario Limonciello <[email protected]>
Hi Wayne, Mario,
48b8c06b05ad ("drm/amd/display: Route connector DDC over AUX for native DP sinks") in amd-staging-drm-next is v2 of this patch, not v3 [1].
v3 added a NULL check on ddc_service->link. Without it, the existing KUnit test dm_test_i2c_xfer_no_ddc_pin(), whose ddc_service has no link, dereferences a NULL link and panics the UML kernel. sashiko-bot pointed this out on v2 [2]. It reproduces on amd-staging-drm-next 8dd68a79583a:
RIP: 0033:amdgpu_dm_i2c_xfer+0x52/0x210 Kernel panic - not syncing: Segfault with no mm ... dm_test_i2c_xfer_no_ddc_pin+0xaf/0x1e0
Only 670 of the 1931 amdgpu_dm tests get to run.
I don't think picking up v3 instead is the answer, though. From reading the code, sashiko-bot's DP++ concern on v3 [3] looks right:link->aux_mode is only written in detect_link_and_local_sink() after detect_dp(), and nothing clears it on unplug. After a native DP monitor is swapped for a passive DP++ HDMI adapter, the adapter ID read in dp_passive_dongle_detection() would go over AUX. v2 doesn't have that problem, because link_disconnect_sink() clears local_sink before detect_dp().
In the driver, a non-OEM adapter always has ddc_service->link set (amdgpu_dm_create_i2c() already dereferences it), so I think only the test needs fixing. I can send a test-only patch that gives the test a zeroed dc_link. With it, all three i2c_xfer tests pass and the suite runs to the end again. Mario, if you'd rather fold it into a driver follow-up, I'm happy to test that instead.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
Thanks,
Eren
Quoted 33 lines · Eren Özen
Hi Wayne, Mario,
48b8c06b05ad("drm/amd/display: Route connector DDC over AUX for native DP sinks") in amd-staging-drm-next is v2 of this patch, not v3 [1].v3 added a NULL check on
ddc_service->link. Without it, the existing KUnit testdm_test_i2c_xfer_no_ddc_pin(), whoseddc_servicehas no link, dereferences a NULL link and panics the UML kernel. sashiko-bot pointed this out on v2 [2]. It reproduces on amd-staging-drm-next8dd68a79583a:RIP: 0033:amdgpu_dm_i2c_xfer+0x52/0x210 Kernel panic - not syncing: Segfault with no mm ... dm_test_i2c_xfer_no_ddc_pin+0xaf/0x1e0Only 670 of the 1931
amdgpu_dmtests get to run.I don't think picking up v3 instead is the answer, though. From reading the code, sashiko-bot's DP++ concern on v3 [3] looks right:
link->aux_modeis only written indetect_link_and_local_sink()afterdetect_dp(), and nothing clears it on unplug. After a native DP monitor is swapped for a passive DP++ HDMI adapter, the adapter ID read indp_passive_dongle_detection()would go over AUX. v2 doesn't have that problem, becauselink_disconnect_sink()clearslocal_sinkbeforedetect_dp().In the driver, a non-OEM adapter always has
ddc_service->linkset (amdgpu_dm_create_i2c()already dereferences it), so I think only the test needs fixing. I can send a test-only patch that gives the test a zeroeddc_link. With it, all threei2c_xfertests pass and the suite runs to the end again. Mario, if you'd rather fold it into a driver follow-up, I'm happy to test that instead.
Quoted 6 lines
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/Thanks,
Eren
Eren,
Really appreciate the feedback. If you want to share your test patch I'll fold it into what's currently v3 and give you a C-d-b tag for v4.
Simon,
But I still need testing this actually works for the issue originally raised on real hardware.
These unit test issues are just noise "for that purpose".
Hi Mario,
Thanks, the patch is below.
With v3's ddc_service->link check the test passes even without this change, so in v4 it only makes the test set up the adapter the way the driver does. I tested it on amd-staging-drm-next 8dd68a79583a, which has
v2: the three i2c_xfer tests pass and the suite runs to the end again. The one remaining failure, dm_test_fs_caps_dp_vsdb_version, is the dropped FreeSync hunk I reported on Cooper's thread.
One thing for v4: if it keeps routing on link->aux_mode, the DP++ case from my last mail still applies. Simon's testing probably won't hit it unless he swaps a native DP monitor for a passive DP++ HDMI adapter on the same port.
Thanks,
Eren
-- >8 --
Subject: drm/amd/display: Give the no-DDC-pin i2c_xfer test a dc_link
Since commit 48b8c06b05ad ("drm/amd/display: Route connector DDC over AUX for native DP sinks"), amdgpu_dm_i2c_xfer() reads ddc_service->link for every non-OEM adapter before it checks for a DDC pin. dm_test_i2c_xfer_no_ddc_pin() builds a ddc_service without a link, so the test now dereferences a NULL pointer and panics the UML kernel. Only 670 of the 1931 amdgpu_dm tests run.
The driver itself never creates a non-OEM adapter without a link:amdgpu_dm_create_i2c() already dereferences it. So fix the test rather than the driver and give the ddc_service a zeroed dc_link.
With this change the three i2c_xfer tests pass again and the suite runs to the end.
--- .../amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c +5 -1
@@ -6455,7 +6455,9 @@ static void dm_test_i2c_func_returns_flags(struct kunit *test)* @test: The KUnit test context * * When the backing ddc_service has no ddc_pin the transfer bails out early -* with -EIO before touching the message buffers or the dc handle. +* with -EIO before touching the message buffers or the dc handle. Non-OEM +* adapters always have a link, so the test gives the ddc_service a zeroed +* one. */ static void dm_test_i2c_xfer_no_ddc_pin (struct kunit *test) {
@@ -6466,6 +6468,8 @@ static void dm_test_i2c_xfer_no_ddc_pin(struct kunit *test)KUNIT_ASSERT_NOT_NULL (test, i2c); ddc =kunit_kzalloc (test,sizeof (*ddc),GFP_KERNEL );KUNIT_ASSERT_NOT_NULL (test, ddc); + ddc->link =kunit_kzalloc (test,sizeof (*ddc->link),GFP_KERNEL ); +KUNIT_ASSERT_NOT_NULL (test, ddc->link); i2c->ddc_service = ddc;i2c_set_adapdata (&i2c->base, i2c);
Hey guys,
Thanks guys for working on the fix!
How do I test the fix easily? I've never compiled or installed a kernel manually. Can you give me some hints? I don't want to corrupt my installation
Greetings
Simon
Am 18.11.26 um 17:07 schrieb Eren Özen:
Quoted 69 lines
Hi Mario,
Thanks, the patch is below.
With v3's
ddc_service->linkcheck the test passes even without this change, so in v4 it only makes the test set up the adapter the way the driver does. I tested it on amd-staging-drm-next8dd68a79583a, which has
v2: the threei2c_xfertests pass and the suite runs to the end again. The one remaining failure,dm_test_fs_caps_dp_vsdb_version, is the dropped FreeSync hunk I reported on Cooper's thread.One thing for v4: if it keeps routing on
link->aux_mode, the DP++ case from my last mail still applies. Simon's testing probably won't hit it unless he swaps a native DP monitor for a passive DP++ HDMI adapter on the same port.Thanks,
Eren-- >8 --
Subject: drm/amd/display: Give the no-DDC-pini2c_xfertest adc_linkSince commit
48b8c06b05ad("drm/amd/display: Route connector DDC over AUX for native DP sinks"),amdgpu_dm_i2c_xfer()readsddc_service->linkfor every non-OEM adapter before it checks for a DDC pin.dm_test_i2c_xfer_no_ddc_pin()builds addc_servicewithout a link, so the test now dereferences a NULL pointer and panics the UML kernel. Only 670 of the 1931amdgpu_dmtests run.The driver itself never creates a non-OEM adapter without a link:
amdgpu_dm_create_i2c()already dereferences it. So fix the test rather than the driver and give theddc_servicea zeroeddc_link.With this change the three
i2c_xfertests pass again and the suite runs to the end.Fixes 48b8c06b05ad ("drm/amd/display: Route connector DDC over AUX for native DP sinks")Assisted-by Claude:claude-opus-5-5Signed-off-by Eren Özen <[email protected]>--- .../amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c +5
-1@@ -6455,7 +6455,9 @@ static void dm_test_i2c_func_returns_flags(struct kunit *test)* @test: The KUnit test context * * When the backing ddc_service has no ddc_pin the transfer bails out early -* with -EIO before touching the message buffers or the dc handle. +* with -EIO before touching the message buffers or the dc handle. Non-OEM +* adapters always have a link, so the test gives the ddc_service a zeroed +* one. */ static void dm_test_i2c_xfer_no_ddc_pin (struct kunit *test) {@@ -6466,6 +6468,8 @@ static void dm_test_i2c_xfer_no_ddc_pin(struct kunit *test)KUNIT_ASSERT_NOT_NULL (test, i2c); ddc =kunit_kzalloc (test,sizeof (*ddc),GFP_KERNEL );KUNIT_ASSERT_NOT_NULL (test, ddc); + ddc->link =kunit_kzalloc (test,sizeof (*ddc->link),GFP_KERNEL ); +KUNIT_ASSERT_NOT_NULL (test, ddc->link); i2c->ddc_service = ddc;i2c_set_adapdata (&i2c->base, i2c);
Hi Simon,
To avoid a mix-up: the patch in my mail only fixes a unit test that runs in a simulated kernel during development. It doesn't change how the driver talks to your monitor,so there's nothing in it for you to test.
The fix for your problem is Mario's patch. He's about to fold my test change into a v4, so it's best to wait for him to say which version to test.
About breaking your installation, a kernel you build yourself is normally installed next to your distribution's kernel, not over it. If it doesn't work, you pick the old kernel in the boot menu and nothing is lost.
Thanks,
Eren