public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Tudor Ambarus <tudor.ambarus@linaro.org>
To: Krzysztof Kozlowski <krzk@kernel.org>,
	Alim Akhtar <alim.akhtar@samsung.com>
Cc: linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, peter.griffin@linaro.org,
	andre.draszik@linaro.org, jyescas@google.com,
	kernel-team@android.com, stable@vger.kernel.org
Subject: Re: [PATCH v2 4/6] firmware: samsung: acpm: Fix memory ordering race in RX path
Date: Wed, 29 Apr 2026 14:05:45 +0300	[thread overview]
Message-ID: <6d21cfc8-4686-43f2-a320-1b9505d38338@linaro.org> (raw)
In-Reply-To: <4421c95f-3ee7-40ac-b239-d877709b498a@linaro.org>



On 4/28/26 3:57 PM, Tudor Ambarus wrote:
> Another thing that I thought about was about the reordering of memset
> and set_bit in acpm_prepare_xfer(), but even there, the internal
> execution order doesn't matter. Both are guaranteed to be completed
> before writel (wmb).

I need to correct myself here. While the wmb() inside writel() does
prevent the hardware from seeing incomplete state, my previous
statement was slightly misleading regarding the local CPU pipeline.

The wmb() alone does not prevent the CPU from speculatively trying
to wipe the memory before it actually finds the first zero bit in
the bitmap.

What truly prevents speculative execution here is a strict
Address Dependency (implicit barrier). The CPU mathematically cannot
calculate the destination pointer for the memset() until the bit in
the bitmap is identified. I will add a comment in the code describing
this dependency.

In what concerns that set_bit() in acpm_prepare_xfer(), we only need
to ensure it is visible before the next TX thread tries to allocate
a sequence number. That is completely protected by the tx_lock
boundaries. The RX thread does not care about set_bit() at all — it
only blind-clears bits based on the rx_seqnum it gets back from the
firmware. I'll add a comment documenting the set_bit() safety as well.

Finally, regarding test_bit() and find_next_zero_bit() in
acpm_prepare_xfer(), they are functionally equivalent. Both are
relaxed, barrier-less reads. The non-atomic find_next_zero_bit()
introduces zero concurrency problems because this phase is strictly
a read-only search (if we read the bitmap just before the RX thread
frees a bit, we simply skip to the next available one).

I'll reorder the patches and put this one as last in the set, I want
to have the find_next_zero_bit() before it, to not touch the same
code twice.

Thanks,
ta


  reply	other threads:[~2026-04-29 11:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-27 15:04 [PATCH v2 0/6] firmware: samsung: acpm: Various fixes for sashiko bug reports Tudor Ambarus
2026-04-27 15:04 ` [PATCH v2 1/6] firmware: samsung: acpm: Fix cross-thread RX length corruption Tudor Ambarus
2026-04-27 15:04 ` [PATCH v2 2/6] firmware: samsung: acpm: Fix mailbox channel leak on probe error Tudor Ambarus
2026-04-27 15:04 ` [PATCH v2 3/6] firmware: samsung: acpm: Fix dummy stubs to return ERR_PTR Tudor Ambarus
2026-04-27 15:04 ` [PATCH v2 4/6] firmware: samsung: acpm: Fix memory ordering race in RX path Tudor Ambarus
2026-04-28  9:52   ` Krzysztof Kozlowski
2026-04-28 12:57     ` Tudor Ambarus
2026-04-29 11:05       ` Tudor Ambarus [this message]
2026-04-27 15:04 ` [PATCH v2 5/6] firmware: samsung: acpm: Fix out-of-bounds read and infinite loop " Tudor Ambarus
2026-04-28 13:04   ` Tudor Ambarus
2026-04-27 15:04 ` [PATCH v2 6/6] firmware: samsung: acpm: Fix infinite loop on sequence number exhaustion Tudor Ambarus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6d21cfc8-4686-43f2-a320-1b9505d38338@linaro.org \
    --to=tudor.ambarus@linaro.org \
    --cc=alim.akhtar@samsung.com \
    --cc=andre.draszik@linaro.org \
    --cc=jyescas@google.com \
    --cc=kernel-team@android.com \
    --cc=krzk@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=peter.griffin@linaro.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox