[PATCH v11 11/16] iommu/arm-smmu-v3: Add CMDQ_PROD_STOP_FLAG to gate CMDQ submissions
John Garry
john.garry at arm.com
Wed Nov 25 01:37:02 PST 2026
On 11/23/26 13:46, Pranjal Shrivastava wrote:
>>> u64 old;
>>> + /*
>>> + * If the SMMU is suspended/suspending, any new CMDs are elided.
>>> + * This loop is the Point of Commitment. If we haven't cmpxchg'd
>>> + * our new indices yet, we can safely bail. Once the indices are
>>> + * committed, we MUST write valid commands to those slots to
>>> + * avoid indefinite polling in the drain function.
>>> + */
>>> + if (Q_STOP(llq.prod)) {
>> I know that there has already been other comments on this "stop" flag and
>> whether to use it in this way... but, if CONFIG_PM is unset, could Q_STOP()
>> ever return true?
>>
> No, the flag is only ever set from the suspend path. Since I'm moving
> the PM bits under CONFIG_PM in v12 anyway (per Will's comment), I'll
> make Q_STOP() evaluate to false at compile time when CONFIG_PM is unset,
> i.e. IS_ENABLED(CONFIG_PM) && (p & CMDQ_PROD_STOP_FLAG), so all of these
> checks (including the one in queue_inc_prod_n()) just compile away. Does
> that sound good?
That should be fine.
>
>> And it would be nice to not add extra logic in this loop. It is very timing
>> sensitive, and adding extra checks can increase the chance that the cmpxchg
>> fails (bad for performance).
>>
> That's a fair concern. A couple of things here:
>
> - The check is on our local llq copy, which we've already loaded, so
> it's a bit test + a (not-taken) branch, with no extra memory access
> before the cmpxchg.
>
> - Per Will's suggestion, I'm making arm_smmu_cmdq_poll_until_not_full()
> bail out on the STOP flag, which lets me drop the check at the top of
> the loop and the extra READ_ONCE(), leaving a single unlikely() check
> right before the cmpxchg.
>
> It does need to stay in the loop though, since the cmpxchg is the only
> point where checking the flag and reserving the slots is atomic.. a
> check any earlier (e.g. in arm_smmu_get_cmdq()) could race with the
> suspend path setting it.
I just find it odd that we try to elide commands here (at the point of
command submission). I would assume that any commands would not get this
far - or even be submitted to the queue - if at the point of entering sleep.
Thanks,
John
More information about the linux-arm-kernel
mailing list