Skip to content
Snippets Groups Projects
  • Stephen Boyd's avatar
    f114a362
    clk: Evict unregistered clks from parent caches · f114a362
    Stephen Boyd authored
    
    commit bdcf1dc2 upstream.
    
    We leave a dangling pointer in each clk_core::parents array that has an
    unregistered clk as a potential parent when that clk_core pointer is
    freed by clk{_hw}_unregister(). It is impossible for the true parent of
    a clk to be set with clk_set_parent() once the dangling pointer is left
    in the cache because we compare parent pointers in
    clk_fetch_parent_index() instead of checking for a matching clk name or
    clk_hw pointer.
    
    Before commit ede77858 ("clk: Remove global clk traversal on fetch
    parent index"), we would check clk_hw pointers, which has a higher
    chance of being the same between registration and unregistration, but it
    can still be allocated and freed by the clk provider. In fact, this has
    been a long standing problem since commit da0f0b2c ("clk: Correct
    lookup logic in clk_fetch_parent_index()") where we stopped trying to
    compare clk names and skipped over entries in the cache that weren't
    NULL.
    
    There are good (performance) reasons to not do the global tree lookup in
    cases where the cache holds dangling pointers to parents that have been
    unregistered. Let's take the performance hit on the uncommon
    registration path instead. Loop through all the clk_core::parents arrays
    when a clk is unregistered and set the entry to NULL when the parent
    cache entry and clk being unregistered are the same pointer. This will
    fix this problem and avoid the overhead for the "normal" case.
    
    Based on a patch by Bjorn Andersson.
    
    Fixes: da0f0b2c ("clk: Correct lookup logic in clk_fetch_parent_index()")
    Reviewed-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
    Tested-by: default avatarSai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
    Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
    Link: https://lkml.kernel.org/r/20190828181959.204401-1-sboyd@kernel.org
    
    
    Tested-by: default avatarNaresh Kamboju <naresh.kamboju@linaro.org>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    f114a362
    History
    clk: Evict unregistered clks from parent caches
    Stephen Boyd authored
    
    commit bdcf1dc2 upstream.
    
    We leave a dangling pointer in each clk_core::parents array that has an
    unregistered clk as a potential parent when that clk_core pointer is
    freed by clk{_hw}_unregister(). It is impossible for the true parent of
    a clk to be set with clk_set_parent() once the dangling pointer is left
    in the cache because we compare parent pointers in
    clk_fetch_parent_index() instead of checking for a matching clk name or
    clk_hw pointer.
    
    Before commit ede77858 ("clk: Remove global clk traversal on fetch
    parent index"), we would check clk_hw pointers, which has a higher
    chance of being the same between registration and unregistration, but it
    can still be allocated and freed by the clk provider. In fact, this has
    been a long standing problem since commit da0f0b2c ("clk: Correct
    lookup logic in clk_fetch_parent_index()") where we stopped trying to
    compare clk names and skipped over entries in the cache that weren't
    NULL.
    
    There are good (performance) reasons to not do the global tree lookup in
    cases where the cache holds dangling pointers to parents that have been
    unregistered. Let's take the performance hit on the uncommon
    registration path instead. Loop through all the clk_core::parents arrays
    when a clk is unregistered and set the entry to NULL when the parent
    cache entry and clk being unregistered are the same pointer. This will
    fix this problem and avoid the overhead for the "normal" case.
    
    Based on a patch by Bjorn Andersson.
    
    Fixes: da0f0b2c ("clk: Correct lookup logic in clk_fetch_parent_index()")
    Reviewed-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
    Tested-by: default avatarSai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
    Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
    Link: https://lkml.kernel.org/r/20190828181959.204401-1-sboyd@kernel.org
    
    
    Tested-by: default avatarNaresh Kamboju <naresh.kamboju@linaro.org>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Code owners
Assign users and groups as approvers for specific file changes. Learn more.