• Lyude Paul's avatar
    drm/dp_mst: Add probe_lock · 14692a36
    Lyude Paul authored
    Currently, MST lacks locking in a lot of places that really should have
    some sort of locking. Hotplugging and link address code paths are some
    of the offenders here, as there is actually nothing preventing us from
    running a link address probe while at the same time handling a
    connection status update request - something that's likely always been
    possible but never seen in the wild because hotplugging has been broken
    for ages now (with the exception of amdgpu, for reasons I don't think
    are worth digging into very far).
    
    Note: I'm going to start using the term "in-memory topology layout" here
    to refer to drm_dp_mst_port->mstb and drm_dp_mst_branch->ports.
    
    Locking in these places is a little tougher then it looks though.
    Generally we protect anything having to do with the in-memory topology
    layout under &mgr->lock. But this becomes nearly impossible to do from
    the context of link address probes due to the fact that &mgr->lock is
    usually grabbed under random various modesetting locks, meaning that
    there's no way we can just invert the &mgr->lock order and keep it
    locked throughout the whole process of updating the topology.
    
    Luckily there are only two workers which can modify the in-memory
    topology layout: drm_dp_mst_up_req_work() and
    drm_dp_mst_link_probe_work(), meaning as long as we prevent these two
    workers from traveling the topology layout in parallel with the intent
    of updating it we don't need to worry about grabbing &mgr->lock in these
    workers for reads. We only need to grab &mgr->lock in these workers for
    writes, so that readers outside these two workers are still protected
    from the topology layout changing beneath them.
    
    So, add the new &mgr->probe_lock and use it in both
    drm_dp_mst_link_probe_work() and drm_dp_mst_up_req_work(). Additionally,
    add some more detailed explanations for how this locking is intended to
    work to drm_dp_mst_port->mstb and drm_dp_mst_branch->ports.
    Signed-off-by: default avatarLyude Paul <lyude@redhat.com>
    Reviewed-by: default avatarSean Paul <sean@poorly.run>
    Cc: Juston Li <juston.li@intel.com>
    Cc: Imre Deak <imre.deak@intel.com>
    Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
    Cc: Harry Wentland <hwentlan@amd.com>
    Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
    Link: https://patchwork.freedesktop.org/patch/msgid/20191022023641.8026-6-lyude@redhat.com
    14692a36
drm_dp_mst_helper.h 23.5 KB