From: Eric Auger <eric.auger@redhat.com>
To: "Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
"Tao Tang" <tangtao1634@phytium.com.cn>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Fabiano Rosas" <farosas@suse.de>,
"Laurent Vivier" <lvivier@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org,
"Chen Baozi" <chenbaozi@phytium.com.cn>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Jean-Philippe Brucker" <jean-philippe@linaro.org>,
"Mostafa Saleh" <smostafa@google.com>,
"CLEMENT MATHIEU--DRIF" <clement.mathieu--drif@eviden.com>
Subject: Re: [RFC RESEND v5 3/4] tests/qtest/libqos: Add SMMUv3 helper library
Date: Wed, 10 Dec 2025 19:43:20 +0100 [thread overview]
Message-ID: <e95d82af-540f-43b0-9f0c-2e5928192049@redhat.com> (raw)
In-Reply-To: <9b2c0429-a8bb-4df4-ad95-492f463cf29f@linaro.org>
On 12/5/25 12:53 AM, Pierrick Bouvier wrote:
> On 11/26/25 7:45 AM, Tao Tang wrote:
>> Introduce qos-smmuv3, a reusable library for SMMUv3-related qtest
>> operations. This module encapsulates common tasks like:
>>
>> - SMMUv3 initialization (enabling, configuring command/event queues)
>> - Stream Table Entry (STE) and Context Descriptor (CD) setup
>> - Multi-level page table construction (L0-L3 for 4KB granules)
>> - Support for Stage 1, Stage 2, and nested translation modes
>> - Could be easily extended to support multi-space testing infrastructure
>> (Non-Secure, Secure, Root, Realm)
>>
>> The library provides high-level abstractions that allow test code to
>> focus on IOMMU behavior validation rather than low-level register
>> manipulation and page table encoding. Key features include:
>>
>> - Automatic memory allocation for translation structures with proper
>> alignment
>> - Helper functions to build valid STEs/CDs for different translation
>> scenarios
>> - Page table walkers that handle address offset calculations per
>> security space
>> - Command queue management for SMMU configuration commands
>>
>> This infrastructure is designed to be used by iommu-testdev-based tests
>> and future SMMUv3 test suites, reducing code duplication and improving
>> test maintainability.
>>
>> Signed-off-by: Tao Tang <tangtao1634@phytium.com.cn>
>> ---
>> tests/qtest/libqos/meson.build | 3 +
>> tests/qtest/libqos/qos-smmuv3.c | 731 ++++++++++++++++++++++++++++++++
>> tests/qtest/libqos/qos-smmuv3.h | 267 ++++++++++++
>> 3 files changed, 1001 insertions(+)
>> create mode 100644 tests/qtest/libqos/qos-smmuv3.c
>> create mode 100644 tests/qtest/libqos/qos-smmuv3.h
>>
>
> ...
>
>> +
>> +void qsmmu_single_translation(QSMMUTestContext *ctx)
>> +{
>> + uint32_t config_result;
>> + uint32_t dma_result;
>> + bool test_passed;
>> +
>> + /* Configure SMMU translation */
>> + config_result = qsmmu_setup_and_enable_translation(ctx);
>> + if (config_result != 0) {
>> + g_test_message("Configuration failed: mode=%u status=0x%x",
>> + ctx->config.trans_mode, config_result);
>> + return;
>
> Is that expected to silently return if we can't configure translation?
>
>> + }
>> +
>> + /* Trigger DMA operation */
>> + dma_result = qsmmu_trigger_dma(ctx);
>> + if (dma_result != 0) {
>> + g_test_message("DMA failed: mode=%u result=0x%x",
>> + ctx->config.trans_mode, dma_result);
>> + } else {
>> + g_test_message("-> DMA succeeded: mode=%u",
>> ctx->config.trans_mode);
>> + }
>> +
>> + /* Validate test result */
>> + test_passed = qsmmu_validate_test_result(ctx);
>> + g_assert_true(test_passed);
>> +
>> + /* Clean up translation state to prepare for the next test */
>> + qsmmu_cleanup_translation(ctx);
>> +}
>> +
>> +void qsmmu_translation_batch(const QSMMUTestConfig *configs, size_t
>> count,
>> + QTestState *qts, QPCIDevice *dev,
>> + QPCIBar bar, uint64_t smmu_base)
>> +{
>> + for (int i = 0; i < count; i++) {
>> + /* Initialize test memory */
>> + qtest_memset(qts, configs[i].dma_iova, 0x00,
>> configs[i].dma_len);
>> + /* Execute each test configuration */
>> + QSMMUTestContext ctx = {
>> + .qts = qts,
>> + .dev = dev,
>> + .bar = bar,
>> + .smmu_base = smmu_base,
>> + .config = configs[i],
>> + .trans_status = 0,
>> + .dma_result = 0,
>> + .sid = dev->devfn,
>> + .tx_space = qsmmu_sec_sid_to_space(configs[i].sec_sid),
>> + };
>> +
>> + qsmmu_single_translation(&ctx);
>> + g_test_message("--> Test %d completed: mode=%u sec_sid=%u "
>> + "status=0x%x result=0x%x", i,
>> configs[i].trans_mode,
>> + configs[i].sec_sid, ctx.trans_status,
>> ctx.dma_result);
>> + }
>> +}
>
> What is the reason for batching operations?
> We are not in a performance critical scenario for running this test,
> so it's probably better to have distinct calls to single_translation.
>
> ...
>
> For the rest of the patch, which is quite consequent, congrats. It's
> hard to review all the setup phase here, but knowing it works with the
> current smmuv3 implementation, that's a good proof that it's working
> as expected.
That's a huge amount of code indeed. I don't how much we shall review
this test lib but if it needs std review the patch needs to be split to
ease the review. Maybe qtest maintainers can give some guidelines here...
Eric
next prev parent reply other threads:[~2025-12-10 18:44 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 15:45 [RFC RESEND v5 0/4] hw/misc: Introduce a generalized IOMMU test framework Tao Tang
2025-11-26 15:45 ` [RFC RESEND v5 1/4] hw/arm/smmuv3: Extract common definitions to smmuv3-common.h Tao Tang
2025-12-04 18:19 ` Pierrick Bouvier
2025-11-26 15:45 ` [RFC RESEND v5 2/4] hw/misc: Introduce iommu-testdev for bare-metal IOMMU testing Tao Tang
2025-12-04 18:36 ` Pierrick Bouvier
2025-12-10 18:35 ` Eric Auger
2025-12-11 7:27 ` Tao Tang
2025-11-26 15:45 ` [RFC RESEND v5 3/4] tests/qtest/libqos: Add SMMUv3 helper library Tao Tang
2025-12-04 23:53 ` Pierrick Bouvier
2025-12-05 15:03 ` Tao Tang
2025-12-05 17:19 ` Pierrick Bouvier
2025-12-06 5:27 ` Tao Tang
2025-12-10 18:40 ` Eric Auger
2025-12-11 8:53 ` Tao Tang
2025-12-10 18:43 ` Eric Auger [this message]
2025-12-11 9:39 ` Tao Tang
2025-11-26 15:45 ` [RFC RESEND v5 4/4] tests/qtest: Add SMMUv3 bare-metal test using iommu-testdev Tao Tang
2025-12-04 18:42 ` Pierrick Bouvier
2025-12-05 14:19 ` Tao Tang
2025-12-05 17:06 ` Pierrick Bouvier
2025-12-06 4:54 ` Tao Tang
2025-12-10 18:45 ` Eric Auger
2025-12-11 8:06 ` Tao Tang
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=e95d82af-540f-43b0-9f0c-2e5928192049@redhat.com \
--to=eric.auger@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=chenbaozi@phytium.com.cn \
--cc=clement.mathieu--drif@eviden.com \
--cc=farosas@suse.de \
--cc=jean-philippe@linaro.org \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=smostafa@google.com \
--cc=tangtao1634@phytium.com.cn \
/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;
as well as URLs for NNTP newsgroup(s).