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 04224192D97; Mon, 24 Feb 2025 14:38:30 +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=1740407910; cv=none; b=EI4eEDZzQBYxVuj2ySV005s2CBApLbdMweRlBwaKOQve0F/tF1j4QfhbFxtF1mmiNnfYPZ/sKnhw6hJmaQ5gKNgOKCqWbY87CHkh6o5NkZN9RUOiTBNsh47jgplFImkOSUj0W+f3Hj9FXdzkq7mpACo5Dhw79KMDJze2Ke+nXRM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740407910; c=relaxed/simple; bh=vORD/xnjTjwsBybsF4lqWHIe29xYZIV/XDvBJVBwG4w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S1LSQavbMiTaE4zCWgacjmv5stfXE1dWW+Ieo3yJVws/82dgTy8h3f1ahFAlTTeg7EVaMdy/FoIucnwGKk+C7BeoL9QvwLG8xF2Uw3ZyWcxrqaz3IFXARNf1nREPbTYJSW9QdbMgWMd86pnKI/msCQqDnKgij8n1ec6mj3FkXzU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FZOaXNpm; 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="FZOaXNpm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 650B3C4CED6; Mon, 24 Feb 2025 14:38:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1740407909; bh=vORD/xnjTjwsBybsF4lqWHIe29xYZIV/XDvBJVBwG4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FZOaXNpmh9Wksk1YhNWo1CxbTd6j3tNatF1SwCzCQlHFDCw4jDXZ9LszgvZcrTY/M Nbdvm75CJhQ+B+OtQZAGdYQV/gAghPxQ/oKW8lYUibbCuzyfgB0RyTFfP7hMQ/AAqY DyyEufL/mewdu79B/2jntvVSkBBq9yo+Mm92mXMk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bartosz Golaszewski , Krzysztof Kozlowski , Bjorn Andersson , Sasha Levin Subject: [PATCH 6.6 045/140] firmware: qcom: scm: Fix missing read barrier in qcom_scm_is_available() Date: Mon, 24 Feb 2025 15:34:04 +0100 Message-ID: <20250224142604.780074626@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224142602.998423469@linuxfoundation.org> References: <20250224142602.998423469@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Krzysztof Kozlowski [ Upstream commit 0a744cceebd0480cb39587b3b1339d66a9d14063 ] 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: Sasha Levin --- drivers/firmware/qcom_scm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c index 7af59985f1c1f..4c5c2b73d42c2 100644 --- a/drivers/firmware/qcom_scm.c +++ b/drivers/firmware/qcom_scm.c @@ -1339,7 +1339,8 @@ static int qcom_scm_find_dload_address(struct device *dev, u64 *addr) */ 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); @@ -1457,7 +1458,7 @@ static int qcom_scm_probe(struct platform_device *pdev) 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); -- 2.39.5