Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@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>,
	Nicolin Chen <nicolinc@nvidia.com>,
	 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 v6 1/2] iommu/arm-smmu-v3: Add a cmdq_max_n_shift module parameter
Date: Wed, 23 Sep 2026 14:03:36 -0300	[thread overview]
Message-ID: <179018301689.3334538.1783583175230817305.b4-review@b4> (raw)
In-Reply-To: <20260909095228.2174031-2-kas@kernel.org>

> [ ... 34 lines skipped ... ]
> @@ -40,6 +40,11 @@ module_param(disable_msipolling, bool, 0444);
>  MODULE_PARM_DESC(disable_msipolling,
>  	"Disable MSI-based polling for CMD_SYNC completion.");
>  
> +static unsigned int cmdq_max_n_shift;
> +module_param(cmdq_max_n_shift, uint, 0444);
> +MODULE_PARM_DESC(cmdq_max_n_shift,
> +	"Cap on the command queue depth, as log2 of the number of entries. Zero means the hardware maximum; the queue never shrinks below one page.");

The patch looks ok

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

But I'd rather use lg2 as name, especially user visible, instead of
n_shift. "shift" is a word for bitwise stuff, this is a 2**N log2
encoded value.

> [ ... 9 lines skipped ... ]
> +/**
> + * arm_smmu_queue_max_n_shift() - pick the log2 depth of a queue
> + * @ceiling: default log2 depth ceiling of the queue
> + * @ent_sz_shift: log2 of the queue entry size in bytes
> + * @shift: log2 depth asked for, or zero for the default
> + *
> + * @shift is floored at 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 ceiling, u32 ent_sz_shift, u32 shift)

These names took me a while to figure out. Something like this seems
much clearer:

 hw_max_lg2
 ent_size_lg2
 user_limit_lg2

And the flow can be simplified alot:

static u32 arm_smmu_queue_max_lg2(u32 hw_max_lg2, u32 ent_sz_lg2,
				  u32 user_limit_lg2)
{
	u32 floor_lg2 = PAGE_SHIFT - ent_sz_lg2;

	if (is_kdump_kernel())
		return min(hw_max_lg2, floor_lg2);
	user_limit_lg2 = max(user_limit_lg2, floor_lg2);
	return min(hw_max_lg2, user_limit_lg2);

Just pass the MAX's as the user limit:

static inline u32 arm_smmu_evtq_max_n_shift(u32 ceiling)
{
	return arm_smmu_queue_max_lg2(ceiling, EVTQ_ENT_SZ_SHIFT,
				      EVTQ_MAX_SZ_SHIFT);
With only one min:

	return arm_smmu_queue_max_lg2(ceiling, CMDQ_ENT_SZ_SHIFT,
				      min(CMDQ_MAX_SZ_SHIFT, cmdq_max_n_shift));

Jason

-- 
Jason


  parent reply	other threads:[~2026-09-23 17:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  9:52 [PATCH v6 0/2] iommu/arm-smmu-v3: Make the queue depths tunable, and shrink them in a kdump kernel Kiryl Shutsemau (Meta)
2026-09-09  9:52 ` [PATCH v6 1/2] iommu/arm-smmu-v3: Add a cmdq_max_n_shift module parameter Kiryl Shutsemau (Meta)
2026-09-15 12:16   ` Breno Leitao
2026-09-23 17:03   ` Jason Gunthorpe [this message]
2026-09-25 10:01     ` Kiryl Shutsemau
2026-09-25 12:46       ` Jason Gunthorpe
2026-10-02 15:33       ` Will Deacon
2026-09-09  9:52 ` [PATCH v6 2/2] iommu/arm-smmu-v3: Default queue depths to one page in a kdump kernel Kiryl Shutsemau (Meta)
2026-09-15 11:20   ` Yuanhe Shu
2026-09-23 17:03   ` Jason Gunthorpe

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=179018301689.3334538.1783583175230817305.b4-review@b4 \
    --to=jgg@nvidia.com \
    --cc=iommu@lists.linux.dev \
    --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=nicolinc@nvidia.com \
    --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