Linux IOMMU Development
 help / color / mirror / Atom feed
From: Pranjal Shrivastava <praan@google.com>
To: Daniel Mentz <danielmentz@google.com>
Cc: iommu@lists.linux.dev, Will Deacon <will@kernel.org>,
	Joerg Roedel <joro@8bytes.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Mostafa Saleh <smostafa@google.com>,
	Nicolin Chen <nicolinc@nvidia.com>
Subject: Re: [PATCH v4 2/8] iommu/arm-smmu-v3: Add a helper to drain cmd queues
Date: Thu, 20 Nov 2025 20:45:46 +0000	[thread overview]
Message-ID: <aR99-oihNS8kLaDX@google.com> (raw)
In-Reply-To: <CAE2F3rD_HnZZz9XZTtpoWFfAsP-Rkiq2sAtmUR7xaH5_igYP0Q@mail.gmail.com>

On Mon, Nov 17, 2025 at 07:48:12PM -0800, Daniel Mentz wrote:
> On Mon, Nov 17, 2025 at 11:15 AM Pranjal Shrivastava <praan@google.com> wrote:
> > +int arm_smmu_queue_poll_until_empty(struct arm_smmu_device *smmu,
> > +                                   struct arm_smmu_queue *q)
> 
> Since this function is only ever used with the Command Queue (cmdq),
> could you simplify the signature by obtaining the queue pointer
> directly from &smmu->cmdq.q within the function?
> 

Ack. I'll pick up the cmdq from the smmu ptr.

> > +{
> > +       struct arm_smmu_queue_poll qp;
> > +       struct arm_smmu_ll_queue *llq = &q->llq;
> > +       int ret = 0;
> 
> I believe you don't need to initialize this to 0. It won't be used
> uninitialized.
> 

Ack.

> > +
> > +       queue_poll_init(smmu, &qp);
> > +       do {
> > +               if (queue_empty(llq))
> > +                       break;
> > +
> > +               ret = queue_poll(&qp);
> > +               WRITE_ONCE(llq->cons, readl_relaxed(q->cons_reg));
> > +
> > +       } while (!ret);
> > +
> > +       return ret;
> > +}
> > +
> > +static int arm_smmu_drain_queues(struct arm_smmu_device *smmu)
> > +{
> > +       struct arm_smmu_cmdq *cmdq = &smmu->cmdq;
> > +       unsigned long flags;
> > +       int ret;
> > +
> > +       /*
> > +        * Since this is only called from the suspend callback, we
> > +        * should be able to acquire the exclusive lock without failing.
> > +        */
> > +       arm_smmu_cmdq_exclusive_trylock_irqsave(cmdq, flags);
> 
> If you assume that we're the exclusive user and then ignore the return
> value of arm_smmu_cmdq_exclusive_trylock_irqsave, I'm wondering if you
> can just skip the locking entirely.
> 

Correct, with this approach we can be sure that we are the only owner as
we'll be executing this much after setting the nr_users = 0;

> > +       ret = arm_smmu_queue_poll_until_empty(smmu, &smmu->cmdq.q);
> > +       arm_smmu_cmdq_exclusive_unlock_irqrestore(cmdq, flags);
> > +
> > +       if (ret)
> > +               return ret;
> > +
> > +       return 0;
> 
> Can you just always "return ret;". Wouldn't that be the same?
> 

We can, since we're suspending anyway even if this times out.

> > +}
> > +

Thanks,
Praan

  reply	other threads:[~2025-11-20 20:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-17 19:14 [RFC PATCH v4 0/8] iommu/arm-smmu-v3: Implement Runtime/System Sleep ops Pranjal Shrivastava
2025-11-17 19:14 ` [PATCH v4 1/8] iommu/arm-smmu-v3: Refactor arm_smmu_setup_irqs Pranjal Shrivastava
2025-11-17 19:14 ` [PATCH v4 2/8] iommu/arm-smmu-v3: Add a helper to drain cmd queues Pranjal Shrivastava
2025-11-17 19:31   ` Nicolin Chen
2025-11-18  3:48   ` Daniel Mentz
2025-11-20 20:45     ` Pranjal Shrivastava [this message]
2025-11-17 19:14 ` [PATCH v4 3/8] iommu/tegra241-cmdqv: Add a helper to drain VCMDQs Pranjal Shrivastava
2025-11-17 19:14 ` [PATCH v4 4/8] iommu/arm-smmu-v3: Cache and restore MSI config Pranjal Shrivastava
2025-11-17 19:14 ` [PATCH v4 5/8] iommu/arm-smmu-v3: Add a usage counter for cmdq Pranjal Shrivastava
2025-11-18  6:05   ` Sairaj Kodilkar
2025-11-20 20:48     ` Pranjal Shrivastava
2025-11-17 19:14 ` [PATCH v4 6/8] iommu/arm-smmu-v3: Implement pm_runtime & system sleep ops Pranjal Shrivastava
2025-12-24  7:39   ` Ashish Mhetre
2026-01-12  8:50     ` Pranjal Shrivastava
2026-01-13  5:06       ` Ashish Mhetre
2025-11-17 19:14 ` [PATCH v4 7/8] iommu/arm-smmu-v3: Enable pm_runtime and setup devlinks Pranjal Shrivastava
2025-11-17 19:14 ` [PATCH v4 8/8] iommu/arm-smmu-v3: Invoke pm_runtime before hw access Pranjal Shrivastava
2025-11-18  0:14   ` Jason Gunthorpe
2025-11-20 20:26     ` Pranjal Shrivastava

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=aR99-oihNS8kLaDX@google.com \
    --to=praan@google.com \
    --cc=danielmentz@google.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=joro@8bytes.org \
    --cc=nicolinc@nvidia.com \
    --cc=robin.murphy@arm.com \
    --cc=smostafa@google.com \
    --cc=will@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