Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: "David Matlack" <dmatlack@google.com>
To: "Aaron Lewis" <aaronlewis@google.com>, <kvm@vger.kernel.org>
Cc: <alex@shazbot.org>, <dmatlack@google.com>, <jgg@nvidia.com>,
	"Kees Cook" <kees@kernel.org>,
	"Andy Lutomirski" <luto@amacapital.net>,
	"Will Drewry" <wad@chromium.org>, "Shuah Khan" <shuah@kernel.org>,
	<linux-kselftest@vger.kernel.org>,
	"Sean Christopherson" <seanjc@google.com>
Subject: Re: [PATCH v4 5/5] vfio: selftests: Allow a size for vfio_dma_mapping_perf_test
Date: Wed, 25 Nov 2026 11:56:07 -0800	[thread overview]
Message-ID: <DN4K1F1Z8M9L.25VB33PVA6VDO@google.com> (raw)
In-Reply-To: <20261114132200.113697-6-aaronlewis@google.com>

On Sat Nov 14, 2026 at 5:22 AM PST, Aaron Lewis wrote:
> +/*
> + * Parses "[0-9]+[kmgt]?".
> + */
> +static u64 parse_size(const char *size)

+Sean

This is a copy of parse_size() from KVM selftests
(tools/testing/selftests/kvm/lib/test_util.c), which points to a broader
problem: VFIO and KVM selftests keep growing duplicate copies of the
same basic helpers. Besides parse_size(), this series adds
timer_get()/timer_elapsed_ns(), which overlap with KVM's
timespec_elapsed()/timespec_to_ns(), and VFIO selftests have their own
VFIO_ASSERT*() macros that serve the same purpose as KVM's
TEST_ASSERT().

This isn't just about the tests themselves, it's also about the
libraries. libvfio uses VFIO_ASSERT*() internally and gets linked into
KVM selftests, so a KVM test that uses libvfio (e.g. irq_test) ends up
with two different assert implementations depending on which library
the failure came from. And libvfio can't use any of KVM's helpers, since
VFIO selftests don't link against libkvm. We need to figure out a common
place for these helpers that both libvfio and libkvm (and probably other
selftests too) can use.

That doesn't need to block this series though.

[...]

>  TEST_F(vfio_dma_mapping_perf_test, dma_map_unmap)
>  {
> -	const u64 size = SZ_1G;
> +	const u64 page_size = variant->page_size ?: getpagesize();
> +	const u64 size = test_params.size;
>  	const int flags = variant->mmap_flags;
>  	struct dma_region region;
>  
> -	ksft_print_msg("mmap size = %lluG\n", (unsigned long long)(size / SZ_1G));
> +	if (!IS_ALIGNED(size, page_size))
> +		SKIP(return, "Size 0x%llx is not aligned to page size 0x%llx",
> +		     (unsigned long long)size, (unsigned long long)page_size);
> +
> +	ksft_print_msg("mmap size = %s\n", test_params.size_str);

The page size calculation, alignment check, and ksft_print_msg() are
all duplicated in dma_map_unmap_from_file(). How about:

 - Print the size once in main(), since it's the same for every test.

 - Move the alignment check into a helper and call it at the top of
   both FIXTURE_SETUP()s. Roughly:

	static bool skip_if_size_unaligned(struct __test_metadata *_metadata,
					   u64 page_size)
	{
		page_size = page_size ?: getpagesize();
		if (IS_ALIGNED(test_params.size, page_size))
			return false;

		SKIP(return true, "Size 0x%llx is not aligned to page size 0x%llx",
		     (unsigned long long)test_params.size,
		     (unsigned long long)page_size);
	}

	FIXTURE_SETUP(vfio_dma_mapping_perf_test)
	{
		if (skip_if_size_unaligned(_metadata, variant->page_size))
			return;

		...
	}

   The harness won't run the test if setup skips (see
   vfio_dma_mapping_mmio_test.c for an example), and doing the check
   first avoids setting up the IOMMU and device for tests that are going
   to be skipped anyway.

With that,

Reviewed-by: David Matlack <dmatlack@google.com>

      reply	other threads:[~2026-11-25 19:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261114132200.113697-1-aaronlewis@google.com>
2026-11-14 13:21 ` [PATCH v4 4/5] selftests: harness: Support custom command-line options Aaron Lewis
2026-11-25 19:40   ` David Matlack
2026-11-14 13:22 ` [PATCH v4 5/5] vfio: selftests: Allow a size for vfio_dma_mapping_perf_test Aaron Lewis
2026-11-25 19:56   ` David Matlack [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=DN4K1F1Z8M9L.25VB33PVA6VDO@google.com \
    --to=dmatlack@google.com \
    --cc=aaronlewis@google.com \
    --cc=alex@shazbot.org \
    --cc=jgg@nvidia.com \
    --cc=kees@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=wad@chromium.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