mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicolin Chen <nicolinc@nvidia.com>
To: "Kiryl Shutsemau (Meta)" <kas@kernel.org>
Cc: Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	"Joerg Roedel" <joro@8bytes.org>,
	Jason Gunthorpe <jgg@nvidia.com>,
	"Pranjal Shrivastava" <praan@google.com>,
	Mostafa Saleh <smostafa@google.com>,
	"Thierry Reding" <thierry.reding@kernel.org>,
	Krishna Reddy <vdumpa@nvidia.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Breno Leitao <leitao@debian.org>, Kyle McMartin <jkkm@meta.com>,
	Usama Arif <usama.arif@linux.dev>, <kernel-team@meta.com>,
	<linux-arm-kernel@lists.infradead.org>, <iommu@lists.linux.dev>,
	<linux-tegra@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 1/2] iommu/arm-smmu-v3: Add a cmdq_entries module parameter
Date: Sun, 6 Sep 2026 21:07:35 -0700	[thread overview]
Message-ID: <ap44h0CSuwm173NO@nvidia.com> (raw)
In-Reply-To: <20260902121724.3494954-2-kas@kernel.org>

Hi,

I think there can be some small cosmetic changes. I gave it a try, and
it looks overall cleaner to me. Hope you would agree.

On Wed, Sep 02, 2026 at 01:17:23PM +0100, Kiryl Shutsemau (Meta) wrote:
> +/**
> + * arm_smmu_queue_max_n_shift() - pick the log2 depth of a queue
> + * @hw_shift: log2 depth the hardware allows, capped for natural alignment

We can drop "capped for natural alignment" -- evtq/priq don't cap.

> + * @ent_sz_shift: log2 of the queue entry size in bytes
> + * @want: number of entries asked for, or zero to use @hw_shift

Instead, rename to:

@ceiling: default max_n_shift ceiling of the queue
@ent_sz_shift: log2 of the queue entry size in bytes
@new_ceiling: new ceiling to override; use the default if 0

> + * @want is rounded down to a power of two. It never sizes a queue below one
> + * page, because coherent DMA is page granular: a shallower queue occupies the
> + * same memory as one that fills the page, and arm_smmu_init_one_queue() stops
> + * shrinking at a page too.
> + */
> +static u32 arm_smmu_queue_max_n_shift(u32 hw_shift, u32 ent_sz_shift, u32 want)
> +{
> +	u32 page_shift = PAGE_SHIFT - ent_sz_shift;

And let's call it "floor". It fits the comments and commit message.

> +
> +	if (!want)
> +		return hw_shift;
> +
> +	return min(hw_shift, max(ilog2(want), page_shift));
> +}
> +
> +/*
> + * Command queues are also allocated by the Tegra241 CMDQV for its VCMDQs, which
> + * need the same depth decision.
> + */
> +u32 arm_smmu_cmdq_max_n_shift(u32 hw_shift)
> +{
> +	return arm_smmu_queue_max_n_shift(hw_shift, CMDQ_ENT_SZ_SHIFT,
> +					  cmdq_entries);
> +}

Here, move in the natural alignment cap.

u32 arm_smmu_cmdq_max_n_shift(u32 ceiling)
{
	/* Capped to ensure natural alignment */
	ceiling = min_t(u32, CMDQ_MAX_SZ_SHIFT, ceiling);

	return arm_smmu_queue_max_n_shift(
		ceiling, CMDQ_ENT_SZ_SHIFT,
		cmdq_max_entries ? ilog2(cmdq_max_entries) : 0);
}
  
> @@ -662,8 +663,8 @@ static int tegra241_vcmdq_alloc_smmu_cmdq(struct tegra241_vcmdq *vcmdq)
>  
>  	/* Cap queue size to SMMU's IDR1.CMDQS and ensure natural alignment */
>  	regval = readl_relaxed(smmu->base + ARM_SMMU_IDR1);
> -	q->llq.max_n_shift =
> -		min_t(u32, CMDQ_MAX_SZ_SHIFT, FIELD_GET(IDR1_CMDQS, regval));
> +	hw_shift = min_t(u32, CMDQ_MAX_SZ_SHIFT, FIELD_GET(IDR1_CMDQS, regval));
> +	q->llq.max_n_shift = arm_smmu_cmdq_max_n_shift(hw_shift);

Then, we can just use FIELD_GET() at the two call sites:

	smmu->cmdq.q.llq.max_n_shift =
		arm_smmu_cmdq_max_n_shift(FIELD_GET(IDR1_CMDQS, reg));

Thanks
Nicolin

  parent reply	other threads:[~2026-09-07  4:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 12:17 [PATCH v4 0/2] iommu/arm-smmu-v3: Make the queue depths tunable, and shrink them in a kdump kernel Kiryl Shutsemau (Meta)
2026-09-02 12:17 ` [PATCH v4 1/2] iommu/arm-smmu-v3: Add a cmdq_entries module parameter Kiryl Shutsemau (Meta)
2026-09-02 17:22   ` Nicolin Chen
2026-09-03 14:15     ` Kiryl Shutsemau
2026-09-03 15:09       ` Nicolin Chen
2026-09-04 14:28         ` Kiryl Shutsemau
2026-09-07  4:07   ` Nicolin Chen [this message]
2026-09-02 12:17 ` [PATCH v4 2/2] iommu/arm-smmu-v3: Default queue depths to one page in a kdump kernel Kiryl Shutsemau (Meta)
2026-09-07  4:10   ` Nicolin Chen

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=ap44h0CSuwm173NO@nvidia.com \
    --to=nicolinc@nvidia.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=jkkm@meta.com \
    --cc=jonathanh@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kas@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=leitao@debian.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=praan@google.com \
    --cc=robin.murphy@arm.com \
    --cc=smostafa@google.com \
    --cc=thierry.reding@kernel.org \
    --cc=usama.arif@linux.dev \
    --cc=vdumpa@nvidia.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

all inboxes | Powered by JetHome®