Misc drive-by fixes for MST helpers
Subsystems (3)
cover Misc drive-by fixes for MST helpers
I'm now (finally!) finishing up my work with getting rid of the legacy MST code and makng everything atomic only, and while doing that I ended up coming up with a few unrelated patches along the way. These are those patches.
Lyude Paul (3):
drm/display/dp_mst: Don't validate port refs in
drm_dp_check_and_send_link_address()
drm/display/dp_mst: Fix drm_atomic_get_mst_topology_state() drm/dp_mst: Get rid of old comment in
drm_atomic_get_mst_topology_state docs
drivers/gpu/drm/display/drm_dp_mst_topology.c | 27 ++++++------------- include/drm/display/drm_dp_mst_helper.h | 2 ++ 2 files changed, 10 insertions(+), 19 deletions(-)
Signature · 1 line
2.35.3
PATCH 1/3 drm/display/dp_mst: Don't validate port refs in drm_dp_check_and_send_link_address()
Drive-by cleanup, we don't need to validate the port references here as we already previously went through the effort of refactoring things such that we're guaranteed to be able to access ->mstb and ->port safely from drm_dp_check_and_send_link_address(), since the only two places in the codebase that drop an MST reference in such a way that it would remove it from the topology are both protected under probe_lock.
Thanks for that, past Lyude!
--- drivers/gpu/drm/display/drm_dp_mst_topology.c | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-)
drivers/gpu/drm/display/drm_dp_mst_topology.c +6 -16
@@ -2666,24 +2666,14 @@ static int drm_dp_check_and_send_link_address(struct drm_dp_mst_topology_mgr *mg }list_for_each_entry (port, &mstb->ports, next) { -struct drm_dp_mst_branch *mstb_child =NULL ; - -if (port->input || !port->ddps) +if (port->input || !port->ddps || !port->mstb)continue ; -if (port->mstb) - mstb_child =drm_dp_mst_topology_get_mstb_validated ( - mgr, port->mstb); - -if (mstb_child) { - ret =drm_dp_check_and_send_link_address (mgr, - mstb_child); -drm_dp_mst_topology_put_mstb (mstb_child); -if (ret ==1 ) - changed = true; -else if (ret <0 ) -return ret; - } + ret =drm_dp_check_and_send_link_address (mgr, port->mstb); +if (ret ==1 ) + changed = true; +else if (ret <0 ) +return ret; }return changed;
Signature · 1 line
2.35.3
RE: [PATCH 1/3] drm/display/dp_mst: Don't validate port refs in drm_dp_check_and_send_link_address()
[Public]
Thanks, Lyude.
Feel free to add
Quoted 67 lines
-----Original Message-----
From: Lyude Paul <[email protected]>
Sent: Friday, June 3, 2022 4:18 AM
To: [email protected]
Cc: David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Thomas Zimmermann <[email protected]>; Lin, Wayne <[email protected]>; Jani Nikula <[email protected]>; Lakha, Bhawanpreet <[email protected]>; Rajkumar Subbiah <[email protected]>; open list <[email protected]>
Subject: [PATCH 1/3] drm/display/dp_mst: Don't validate port refs indrm_dp_check_and_send_link_address()Drive-by cleanup, we don't need to validate the port references here as we already previously went through the effort of refactoring things such that we're guaranteed to be able to access ->mstb and ->port safely from
drm_dp_check_and_send_link_address(), since the only two places in the codebase that drop an MST reference in such a way that it would remove it from the topology are both protected underprobe_lock.Thanks for that, past Lyude!
Signed-off-by Lyude Paul <[email protected]>--- drivers/gpu/drm/display/drm_dp_mst_topology.c | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-)drivers/gpu/drm/display/drm_dp_mst_topology.c +0
-0@@ -2666,24 +2666,14 @@ static intdrm_dp_check_and_send_link_address(struct
drm_dp_mst_topology_mgr*mgdrivers/gpu/drm/display/drm_dp_mst_topology.c +1
-5}list_for_each_entry (port, &mstb->ports, next) { -struct drm_dp_mst_branch *mstb_child =NULL ; - -if (port->input || !port->ddps) +if (port->input || !port->ddps || !port->mstb)continue ; -if (port->mstb) - mstb_child =drm_dp_mst_topology_get_mstb_validated(
drivers/gpu/drm/display/drm_dp_mst_topology.c +1
-11- mgr, port->mstb); - -if (mstb_child) { - ret =drm_dp_check_and_send_link_address (mgr, - mstb_child); -drm_dp_mst_topology_put_mstb (mstb_child); -if (ret ==1 ) - changed = true; -else if (ret <0 ) -return ret; - } + ret = drm_dp_check_and_send_link_address(mgr, port-Quoted 1 line
mstb);
drivers/gpu/drm/display/drm_dp_mst_topology.c +4
-1+if (ret ==1 ) + changed = true; +else if (ret <0 ) +return ret; }return changed; --
Quoted 1 line
2.35.3
--
Regards,
Wayne
PATCH 2/3 drm/display/dp_mst: Fix drm_atomic_get_mst_topology_state()
In reply to Lyude PaulI noticed a rather surprising issue here while working on removing all of the non-atomic MST code: drm_atomic_get_mst_topology_state() doesn't check the return value of drm_atomic_get_private_obj_state() and instead just passes it directly to to_dp_mst_topology_state(). This means that if we hit a deadlock or something else which would return an error code pointer, we'll likely segfault the kernel.
This is definitely another one of those fixes where I'm astonished we somehow managed never to discover this issue until now…
--- drivers/gpu/drm/display/drm_dp_mst_topology.c | 2 +- include/drm/display/drm_dp_mst_helper.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/display/drm_dp_mst_topology.c +1 -1
@@ -5468,7 +5468,7 @@ EXPORT_SYMBOL(drm_dp_mst_topology_state_funcs);struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state (struct drm_atomic_state *state,struct drm_dp_mst_topology_mgr *mgr) { -return to_dp_mst_topology_state (drm_atomic_get_private_obj_state (state, &mgr->base)); +return to_dp_mst_topology_state_safe (drm_atomic_get_private_obj_state (state, &mgr->base)); }EXPORT_SYMBOL (drm_atomic_get_mst_topology_state);
include/drm/display/drm_dp_mst_helper.h +2 -0
@@ -541,6 +541,8 @@ struct drm_dp_payload { };#define to_dp_mst_topology_state (x) container_of(x, struct drm_dp_mst_topology_state, base) +#define to_dp_mst_topology_state_safe (x) \ + container_of_safe(x, struct drm_dp_mst_topology_state, base)struct drm_dp_vcpi_allocation {struct drm_dp_mst_port *port;
Signature · 1 line
2.35.3
Re: [PATCH 2/3] drm/display/dp_mst: Fix drm_atomic_get_mst_topology_state()
Quoted 9 lines · Lyude Paul
I noticed a rather surprising issue here while working on removing all of the non-atomic MST code:
drm_atomic_get_mst_topology_state()doesn't check the return value ofdrm_atomic_get_private_obj_state()and instead just passes it directly toto_dp_mst_topology_state(). This means that if we hit a deadlock or something else which would return an error code pointer, we'll likely segfault the kernel.This is definitely another one of those fixes where I'm astonished we somehow managed never to discover this issue until now…
It has been discussed before.
struct drm_dp_mst_topology_state {
struct drm_private_state base;
...
}so offsetof(base)==0.
Quoted 28 lines
Signed-off-by Lyude Paul <[email protected]>Fixes a4370c777406 ("drm/atomic: Make private objs proper objects")Cc Ville Syrjälä <[email protected]>Cc <[email protected]> # v4.14+--- drivers/gpu/drm/display/drm_dp_mst_topology.c | 2 +- include/drm/display/drm_dp_mst_helper.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/display/drm_dp_mst_topology.c +1
-1@@ -5468,7 +5468,7 @@ EXPORT_SYMBOL(drm_dp_mst_topology_state_funcs);struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state (struct drm_atomic_state *state,struct drm_dp_mst_topology_mgr *mgr) { -return to_dp_mst_topology_state (drm_atomic_get_private_obj_state (state, &mgr->base)); +return to_dp_mst_topology_state_safe (drm_atomic_get_private_obj_state (state, &mgr->base)); }EXPORT_SYMBOL (drm_atomic_get_mst_topology_state);include/drm/display/drm_dp_mst_helper.h +0
-0
include/drm/display/drm_dp_mst_helper.h struct drm_dp_payload { · line 545
Quoted 5 lines
include/drm/display/drm_dp_mst_helper.h +2
-0@@ -541,6 +541,8 @@ struct drm_dp_payload { };#define to_dp_mst_topology_state (x) container_of(x, struct drm_dp_mst_topology_state, base) +#define to_dp_mst_topology_state_safe (x) \ + container_of_safe(x, struct drm_dp_mst_topology_state, base)
Wasn't aware of container_of_safe(). I suppose no real harm in using it. Not sure why we'd even keep the non-safe version around?
Though the use of container_of_safe() everywhere won't help when "casting" the other way (&foo->base, when foo==NULL/errptr). In order to make that work for non-zero offsets we'd have to introduce a casting macro for that direction as well.
Quoted 5 lines
include/drm/display/drm_dp_mst_helper.h +0
-0struct drm_dp_vcpi_allocation {struct drm_dp_mst_port *port;Signature · 1 line
2.35.3
Signature · 2 lines
Ville Syrjälä Intel
Re: [PATCH 2/3] drm/display/dp_mst: Fix drm_atomic_get_mst_topology_state()
Quoted 11 lines · Ville Syrjälä
Quoted 9 lines · Lyude Paul
I noticed a rather surprising issue here while working on removing all of the non-atomic MST code:
drm_atomic_get_mst_topology_state()doesn't check the return value ofdrm_atomic_get_private_obj_state()and instead just passes it directly toto_dp_mst_topology_state(). This means that if we hit a deadlock or something else which would return an error code pointer, we'll likely segfault the kernel.This is definitely another one of those fixes where I'm astonished we somehow managed never to discover this issue until now…
Quoted 8 lines
It has been discussed before.
struct
drm_dp_mst_topology_state{
structdrm_private_statebase;
...
}so offsetof(base)==0.
fhjdffds yes you're right, I guess we can just drop this patch then
Quoted 59 lines
Quoted 38 lines
Signed-off-by Lyude Paul <[email protected]>Fixes a4370c777406 ("drm/atomic: Make private objs proper objects")Cc Ville Syrjälä <[email protected]>Cc <[email protected]> # v4.14+---
drivers/gpu/drm/display/drm_dp_mst_topology.c | 2 +- include/drm/display/drm_dp_mst_helper.h | 2 ++2 files changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/display/drm_dp_mst_topology.c +0
-0@@ -5468,7 +5468,7 @@ EXPORT_SYMBOL(drm_dp_mst_topology_state_funcs);struct
drm_dp_mst_topology_state*drm_atomic_get_mst_topology_state(structdrm_atomic_state*state, structdrm_dp_mst_topology_mgr*mgr)
{
- return to_dp_mst_topology_state(drm_atomic_get_private_obj_state(state, &mgr-Quoted 1 line
base));
+ return
to_dp_mst_topology_state_safe(drm_atomic_get_private_obj_state(state, &mgr->base));
}
EXPORT_SYMBOL(drm_atomic_get_mst_topology_state);include/drm/display/drm_dp_mst_helper.h +0
-0@@ -541,6 +541,8 @@ struct drm_dp_payload { };Quoted 5 lines
#defineto_dp_mst_topology_state(x)container_of(x, struct drm_dp_mst_topology_state, base)
+#defineto_dp_mst_topology_state_safe(x)\
+ container_of_safe(x, structdrm_dp_mst_topology_state, base)Wasn't aware of
container_of_safe(). I suppose no real harm in using it. Not sure why we'd even keep the non-safe version around?Though the use of
container_of_safe()everywhere won't help when "casting" the other way (&foo->base, when foo==NULL/errptr). In order to make that work for non-zero offsets we'd have to introduce a casting macro for that direction as well.Quoted 5 lines
structdrm_dp_vcpi_allocation{
structdrm_dp_mst_port*port;Signature · 1 line
2.35.3
Signature · 3 lines
Cheers, Lyude Paul (she/her) Software Engineer at Red Hat
PATCH 3/3 drm/dp_mst: Get rid of old comment in drm_atomic_get_mst_topology_state docs
In reply to Lyude PaulWe don't actually care about connection_mutex here anymore, so let's get rid of the comment mentioning it in this function's kdocs.
--- drivers/gpu/drm/display/drm_dp_mst_topology.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/display/drm_dp_mst_topology.c +1 -2
@@ -5458,8 +5458,7 @@ EXPORT_SYMBOL(drm_dp_mst_topology_state_funcs);* * This function wraps drm_atomic_get_priv_obj_state() passing in the MST atomic * state vtable so that the private object state returned is that of a MST -* topology object. Also, drm_atomic_get_private_obj_state() expects the caller -* to care of the locking, so warn if don't hold the connection_mutex. +* topology object. * * RETURNS: *
Signature · 1 line
2.35.3
RE: [PATCH 3/3] drm/dp_mst: Get rid of old comment in drm_atomic_get_mst_topology_state docs
[Public]
Hi Lyude,
Feel free to add
Quoted 32 lines
-----Original Message-----
From: Lyude Paul <[email protected]>
Sent: Friday, June 3, 2022 4:18 AM
To: [email protected]
Cc: David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Thomas Zimmermann <[email protected]>; Lin, Wayne <[email protected]>; Jani Nikula <[email protected]>; Lakha, Bhawanpreet <[email protected]>; Rajkumar Subbiah <[email protected]>; open list <[email protected]>
Subject: [PATCH 3/3] drm/dp_mst: Get rid of old comment indrm_atomic_get_mst_topology_statedocsWe don't actually care about
connection_mutexhere anymore, so let's get rid of the comment mentioning it in this function's kdocs.Signed-off-by Lyude Paul <[email protected]>--- drivers/gpu/drm/display/drm_dp_mst_topology.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/display/drm_dp_mst_topology.c +0
-0@@ -5458,8 +5458,7 @@EXPORT_SYMBOL (drm_dp_mst_topology_state_funcs); * * This function wraps drm_atomic_get_priv_obj_state() passing in the MSTatomic
* state vtable so that the private object state returned is that of a MST
- * topology object. Also,drm_atomic_get_private_obj_state()expects the
Quoted 8 lines
caller
- * to care of the locking, so warn if don't hold theconnection_mutex.
+ * topology object.
*
* RETURNS:
*
--
2.35.3
--
Regards,
Wayne Lin
Re: [PATCH 3/3] drm/dp_mst: Get rid of old comment in drm_atomic_get_mst_topology_state docs
Thanks! Will push these two patches upstream
Quoted 54 lines · Wayne
[Public]
Hi Lyude,
Feel free to add
Reviewed-by Wayne Lin <[email protected]>Quoted 34 lines
-----Original Message-----
From: Lyude Paul <[email protected]>
Sent: Friday, June 3, 2022 4:18 AM
To: [email protected]
Cc: David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Thomas
Zimmermann <[email protected]>; Lin, Wayne <[email protected]>; Jani Nikula <[email protected]>; Lakha, Bhawanpreet <[email protected]>; Rajkumar Subbiah <[email protected]>; open list <[email protected]>
Subject: [PATCH 3/3] drm/dp_mst: Get rid of old comment indrm_atomic_get_mst_topology_statedocsWe don't actually care about
connection_mutexhere anymore, so let's get rid of the comment mentioning it in this function's kdocs.Signed-off-by Lyude Paul <[email protected]>---
drivers/gpu/drm/display/drm_dp_mst_topology.c | 3 +--1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/display/drm_dp_mst_topology.c +0
-0@@ -5458,8 +5458,7 @@EXPORT_SYMBOL (drm_dp_mst_topology_state_funcs); * * This function wraps drm_atomic_get_priv_obj_state() passing in the MSTatomic
* state vtable so that the private object state returned is that of a MST
- * topology object. Also,drm_atomic_get_private_obj_state()expects theQuoted 8 lines
caller
- * to care of the locking, so warn if don't hold theconnection_mutex.
+ * topology object.
*
* RETURNS:
*
--
2.35.3--
Regards,
Wayne Lin
Signature · 3 lines
Cheers, Lyude Paul (she/her) Software Engineer at Red Hat