From: Nicolin Chen <nicolinc@nvidia.com>
To: Pranjal Shrivastava <praan@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>,
Daniel Mentz <danielmentz@google.com>,
Ashish Mhetre <amhetre@nvidia.com>,
<linux-arm-kernel@lists.infradead.org>,
Thomas Gleixner <tglx@kernel.org>, Radu Rendec <radu@rendec.net>,
Bjorn Helgaas <bhelgaas@google.com>, <linux-pci@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
<rafael@kernel.org>, "Danilo Krummrich" <dakr@kernel.org>,
<driver-core@lists.linux.dev>
Subject: Re: [PATCH v11 16/16] iommu/arm-smmu-v3: Add KUnit unit tests for Runtime PM
Date: Thu, 1 Oct 2026 12:12:32 -0700 [thread overview]
Message-ID: <ar6woMRpqt4k6uBs@nvidia.com> (raw)
In-Reply-To: <20260929034510.2023173-17-praan@google.com>
On Tue, Sep 29, 2026 at 03:45:10AM +0000, Pranjal Shrivastava wrote:
> #include <kunit/test.h>
> +#include <linux/delay.h>
> +#include <linux/kthread.h>
> +#include <linux/sched.h>
kthread is used here, so sched is not necessary?
> +struct arm_smmu_mock_cmdq {
> + /*
> + * Mock register in RAM. Typed as __le32 to match writel_relaxed()
> + * endianness without calling readl_* accessors directly on RAM.
> + */
> + __le32 mock_prod_reg;
> +};
> +
> +/* Helper to allocate a self-consuming mock cmdq */
> +static void arm_smmu_v3_test_init_mock_cmdq(struct kunit *test,
> + struct arm_smmu_device *smmu,
> + struct arm_smmu_mock_cmdq *mock)
> +{
> + struct arm_smmu_cmdq *cmdq = &smmu->cmdq;
> + unsigned long *mock_valid_map;
> + u64 *mock_base;
> +
> + mock_base = kunit_kzalloc(test, 1024 * sizeof(struct arm_smmu_cmd), GFP_KERNEL);
> + mock_valid_map = kunit_kzalloc(test, BITS_TO_LONGS(1024) * sizeof(long), GFP_KERNEL);
> +
> + KUNIT_ASSERT_NOT_NULL(test, mock_base);
> + KUNIT_ASSERT_NOT_NULL(test, mock_valid_map);
> +
> + smmu->features = 0;
> + /* 1024 entries */
> + cmdq->q.llq.max_n_shift = 10;
> + cmdq->q.ent_dwords = CMDQ_ENT_DWORDS;
> + cmdq->q.base = (__le64 *)mock_base;
> + cmdq->valid_map = (atomic_long_t *)mock_valid_map;
> +
> + /* Self-Consuming, prod == cons always ensures queue empty */
> + cmdq->q.prod_reg = (__force void __iomem *)&mock->mock_prod_reg;
> + cmdq->q.cons_reg = (__force void __iomem *)&mock->mock_prod_reg;
Is it really necessary to return mock->mock_prod_reg?
mock_base and mock_valid_map are working well here.
Couldn't mock_prod_reg be allocated here, then the caller just uses
cmdq->q.prod_reg?
E.g.
static inline u32 arm_smmu_v3_test_read_prod(struct arm_smmu_cmdq *cmdq)
{
return le32_to_cpu(READ_ONCE(*(__le32 __force *)cmdq->q.prod_reg));
}
> +struct arm_smmu_test_timer_context {
> + struct arm_smmu_device *smmu;
> + struct timer_list timer;
> + bool suspended;
> +};
> +
> +static void arm_smmu_v3_test_rpm_timer_callback(struct timer_list *t)
> +{
> + struct arm_smmu_test_timer_context *ctx =
> + timer_container_of(ctx, t, timer);
> + struct arm_smmu_cmdq *cmdq = &ctx->smmu->cmdq;
> +
> + /* Simulate a concurrent suspend event interrupting the invalidations */
> + atomic_or(CMDQ_PROD_STOP_FLAG, &cmdq->q.llq.atomic.prod);
> + WRITE_ONCE(ctx->suspended, true);
Both STOP and suspended flags are set at the same time, seemingly
a bit redundant to me..
> +struct arm_smmu_test_kthread_context {
> + struct arm_smmu_device *smmu;
> + int error;
> +};
> +
> +static int arm_smmu_v3_test_kthread_worker(void *data)
> +{
> + struct arm_smmu_cmd cmd = arm_smmu_make_cmd_cfgi_all();
> + struct arm_smmu_test_kthread_context *ctx = data;
> + struct arm_smmu_cmdq *cmdq = &ctx->smmu->cmdq;
> +
> + while (!kthread_should_stop()) {
> + if (arm_smmu_cmdq_issue_cmdlist(ctx->smmu, cmdq, &cmd, 1, false))
> + WRITE_ONCE(ctx->error, 1);
With "sync=false", arm_smmu_cmdq_issue_cmdlist cannot fail. I don't
see any "sync=true" call site in this patch. But even there was one,
would the mock cmdq ever time out?
So, error (and arm_smmu_test_kthread_context) seems useless?
> +static void arm_smmu_v3_rpm_test_kthread_race(struct kunit *test)
> +{
> + struct arm_smmu_test_kthread_context *ctx;
> + struct arm_smmu_device *mock_smmu;
> + struct arm_smmu_mock_cmdq *mock;
> + struct task_struct *thread1, *thread2;
> + u32 stopped_prod;
> + int i;
> +
> + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
> + mock_smmu = kunit_kzalloc(test, sizeof(*mock_smmu), GFP_KERNEL);
The other function simply does:
struct arm_smmu_device mock_smmu = smmu;
> + /* Wait for worker threads to start and issue initial commands */
> + for (i = 0; i < 20; i++) {
I am a bit confused by the number in the for loop: it's 20 here...
> + KUNIT_EXPECT_GT(test, le32_to_cpu(READ_ONCE(mock->mock_prod_reg)), 0);
> +
> + /* Gate the CMDQ */
> + atomic_or(CMDQ_PROD_STOP_FLAG, &mock_smmu->cmdq.q.llq.atomic.prod);
> +
> + /* Wait for in-flight submissions to settle */
> + for (i = 0; i < 50; i++) {
... but it's 50 here. Mind elaborating?
Nicolin
prev parent reply other threads:[~2026-10-01 19:13 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 3:44 [PATCH v11 00/16] iommu/arm-smmu-v3: Implement Runtime/System Sleep ops Pranjal Shrivastava
2026-09-29 3:44 ` [PATCH v11 01/16] iommu/arm-smmu-v3: Refactor arm_smmu_setup_irqs Pranjal Shrivastava
2026-09-29 3:44 ` [PATCH v11 02/16] iommu/arm-smmu-v3: Add Q_POS() macro Pranjal Shrivastava
2026-09-29 3:44 ` [PATCH v11 03/16] iommu/arm-smmu-v3: Add arm_smmu_drain_queue() helper Pranjal Shrivastava
2026-09-30 18:24 ` Nicolin Chen
2026-09-30 20:17 ` Pranjal Shrivastava
2026-09-29 3:44 ` [PATCH v11 04/16] iommu/tegra241-cmdqv: Add a helper to drain VCMDQs Pranjal Shrivastava
2026-09-29 3:44 ` [PATCH v11 05/16] iommu/arm-smmu-v3: Add a helper to drain cmd queues Pranjal Shrivastava
2026-09-29 3:45 ` [PATCH v11 06/16] iommu/tegra241-cmdqv: Restore PROD and CONS after resume Pranjal Shrivastava
2026-09-29 3:45 ` [PATCH v11 07/16] genirq/msi: Cache MSI message in irq_chip_write_msi_msg() Pranjal Shrivastava
2026-09-29 3:45 ` [PATCH v11 08/16] genirq/msi: Provide msi_device_domain_restore_msi_msgs() Pranjal Shrivastava
2026-09-29 3:45 ` [PATCH v11 09/16] iommu/arm-smmu-v3: Restore MSI config on resume Pranjal Shrivastava
2026-09-29 3:45 ` [PATCH v11 10/16] iommu/arm-smmu-v3: Factor out arm_smmu_handle_gerror() Pranjal Shrivastava
2026-09-30 18:34 ` Nicolin Chen
2026-09-30 20:00 ` Pranjal Shrivastava
2026-09-30 20:12 ` Nicolin Chen
2026-09-30 20:03 ` Pranjal Shrivastava
2026-09-29 3:45 ` [PATCH v11 11/16] iommu/arm-smmu-v3: Add CMDQ_PROD_STOP_FLAG to gate CMDQ submissions Pranjal Shrivastava
2026-09-30 20:33 ` Nicolin Chen
2026-10-01 5:40 ` Pranjal Shrivastava
2026-10-01 18:03 ` Nicolin Chen
2026-10-02 16:47 ` Jason Gunthorpe
2026-10-02 21:11 ` Pranjal Shrivastava
2026-09-29 3:45 ` [PATCH v11 12/16] iommu/tegra241-cmdqv: Add a helper to quiesce VCMDQs Pranjal Shrivastava
2026-09-30 19:02 ` Nicolin Chen
2026-09-30 19:57 ` Pranjal Shrivastava
2026-09-30 20:03 ` Nicolin Chen
2026-09-29 3:45 ` [PATCH v11 13/16] iommu/arm-smmu-v3: Implement pm_runtime & system sleep ops Pranjal Shrivastava
2026-10-01 20:22 ` Nicolin Chen
2026-09-29 3:45 ` [PATCH v11 14/16] iommu/arm-smmu-v3: Enable pm_runtime and setup devlinks Pranjal Shrivastava
2026-09-29 3:45 ` [PATCH v11 15/16] iommu/arm-smmu-v3: Invoke pm_runtime before hw access Pranjal Shrivastava
2026-09-29 3:45 ` [PATCH v11 16/16] iommu/arm-smmu-v3: Add KUnit unit tests for Runtime PM Pranjal Shrivastava
2026-10-01 19:12 ` Nicolin Chen [this message]
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=ar6woMRpqt4k6uBs@nvidia.com \
--to=nicolinc@nvidia.com \
--cc=amhetre@nvidia.com \
--cc=bhelgaas@google.com \
--cc=dakr@kernel.org \
--cc=danielmentz@google.com \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=praan@google.com \
--cc=radu@rendec.net \
--cc=rafael@kernel.org \
--cc=robin.murphy@arm.com \
--cc=smostafa@google.com \
--cc=tglx@kernel.org \
--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®