Skip to content

Commit f3ad802

Browse files
krzkgregkh
authored andcommitted
firmware: qcom: scm: Fix missing read barrier in qcom_scm_is_available()
commit 0a744cc upstream. Commit 2e49551 ("firmware: qcom: scm: Fix __scm and waitq completion variable initialization") introduced a write barrier in probe function to store global '__scm' variable. It also claimed that it added a read barrier, because as we all known barriers are paired (see memory-barriers.txt: "Note that write barriers should normally be paired with read or address-dependency barriers"), however it did not really add it. The offending commit used READ_ONCE() to access '__scm' global which is not a barrier. The barrier is needed so the store to '__scm' will be properly visible. This is most likely not fatal in current driver design, because missing read barrier would mean qcom_scm_is_available() callers will access old value, NULL. Driver does not support unbinding and does not correctly handle probe failures, thus there is no risk of stale or old pointer in '__scm' variable. However for code correctness, readability and to be sure that we did not mess up something in this tricky topic of SMP barriers, add a read barrier for accessing '__scm'. Change also comment from useless/obvious what does barrier do, to what is expected: which other parts of the code are involved here. Fixes: 2e49551 ("firmware: qcom: scm: Fix __scm and waitq completion variable initialization") Cc: stable@vger.kernel.org Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-1-9061013c8d92@linaro.org Signed-off-by: Bjorn Andersson <andersson@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 36b08a9 commit f3ad802

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/firmware/qcom/qcom_scm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,8 @@ static int qcom_scm_qseecom_init(struct qcom_scm *scm)
18671867
*/
18681868
bool qcom_scm_is_available(void)
18691869
{
1870-
return !!READ_ONCE(__scm);
1870+
/* Paired with smp_store_release() in qcom_scm_probe */
1871+
return !!smp_load_acquire(&__scm);
18711872
}
18721873
EXPORT_SYMBOL_GPL(qcom_scm_is_available);
18731874

@@ -2024,7 +2025,7 @@ static int qcom_scm_probe(struct platform_device *pdev)
20242025
if (ret)
20252026
return ret;
20262027

2027-
/* Let all above stores be available after this */
2028+
/* Paired with smp_load_acquire() in qcom_scm_is_available(). */
20282029
smp_store_release(&__scm, scm);
20292030

20302031
irq = platform_get_irq_optional(pdev, 0);

0 commit comments

Comments
 (0)