From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDF28271267; Thu, 13 Feb 2025 14:44:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739457880; cv=none; b=LGsyfAUJ7KRPb7N41EZsJ8BmKNVDNOBZRh2Q54pPHKH3ysubir9w4wWaooCadlJAl6sHwmP5cbRGm3T4t+plc2hY2F71BrRbztij055zXnUQEVZp5mPbDMQaeX5AgG97MeuzO+l3avNUvkewwuj0z4qlegCvc/lG4EUlKu4d80I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739457880; c=relaxed/simple; bh=IRE59FoIjQRzJz/isdbdwwSoEKPrYHIkm5hT6MqMB1k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LEYkaF5bnmsiNJV1jVqFIK9s1euxJ2/fFpTMEwO7SP0ag65dnLxCx4ARlaOCGbesEms6yY6FuBG6YIBlnYXNblnw8V1nO7c5FVT+Pp2WZCGi+yOTXbhAJUah44JVSKwjs08GqbwPeIQTTrZGmJR9UwQ5aaNDF3vuUG97VEIuz5E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0U3uraY7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="0U3uraY7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43869C4CEE4; Thu, 13 Feb 2025 14:44:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739457879; bh=IRE59FoIjQRzJz/isdbdwwSoEKPrYHIkm5hT6MqMB1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0U3uraY7Q51q6mDraclhhXrJ7C38ORMV9aj5yFrZy3ZLUzokPYXFQRwTMiP8npJr9 CK9KsGJGdX9dkppeBnYP/BUNfGaSd9xYFsmQVpDv+vOWoIH7iVpsrbn8JkMupWGVm2 yV7SzQpc8nq48G+Rj8Ic/nzqLl0IjqapVVRgfBZU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bartosz Golaszewski , Krzysztof Kozlowski , Bjorn Andersson Subject: [PATCH 6.12 240/422] firmware: qcom: scm: Fix missing read barrier in qcom_scm_is_available() Date: Thu, 13 Feb 2025 15:26:29 +0100 Message-ID: <20250213142445.798116696@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250213142436.408121546@linuxfoundation.org> References: <20250213142436.408121546@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Krzysztof Kozlowski commit 0a744cceebd0480cb39587b3b1339d66a9d14063 upstream. Commit 2e4955167ec5 ("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: 2e4955167ec5 ("firmware: qcom: scm: Fix __scm and waitq completion variable initialization") Cc: stable@vger.kernel.org Reviewed-by: Bartosz Golaszewski Signed-off-by: Krzysztof Kozlowski 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 Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/qcom/qcom_scm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1839,7 +1839,8 @@ static int qcom_scm_qseecom_init(struct */ bool qcom_scm_is_available(void) { - return !!READ_ONCE(__scm); + /* Paired with smp_store_release() in qcom_scm_probe */ + return !!smp_load_acquire(&__scm); } EXPORT_SYMBOL_GPL(qcom_scm_is_available); @@ -1996,7 +1997,7 @@ static int qcom_scm_probe(struct platfor if (ret) return ret; - /* Let all above stores be available after this */ + /* Paired with smp_load_acquire() in qcom_scm_is_available(). */ smp_store_release(&__scm, scm); irq = platform_get_irq_optional(pdev, 0);