Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aaron Lewis" <aaronlewis@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/4] vfio: selftests: Add memfd test to vfio_dma_mapping_perf_test
Date: Wed, 01 Jul 2026 20:43:36 +0000	[thread overview]
Message-ID: <20260701204337.0EB561F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260701203311.326798-3-aaronlewis@google.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Missing SKIP fallback for hugepage allocation failures.
- [Low] MAP_SHARED (an mmap flag) is incorrectly passed to memfd_create() via memfd_flags.
- [Low] memfd_create() return value is incorrectly validated against <= 0, which rejects fd 0 and leaks it.
--

commit ffa43469ab562932001b32361e9549a362e44c3c
Author: Aaron Lewis <aaronlewis@google.com>

vfio: selftests: Add memfd test to vfio_dma_mapping_perf_test

Add a second test to "vfio_dma_mapping_perf_test" to evaluate memfd
latencies. A key motivator for adding this test is to demonstrate that
the IOMMU_IOAS_MAP_FILE ioctl is significantly faster than other methods
of mapping DMA regions.

> diff --git a/tools/testing/selftests/vfio/vfio_dma_mapping_perf_test.c b/tools/testing/selftests/vfio/vfio_dma_mapping_perf_test.c
> index 87d84450fc47e..4639bda7ebaa3 100644
> --- a/tools/testing/selftests/vfio/vfio_dma_mapping_perf_test.c
> +++ b/tools/testing/selftests/vfio/vfio_dma_mapping_perf_test.c
[ ... ]
> +#define FIXTURE_VARIANT_ADD_IOMMU_MODE(_iommu_mode, _name, _mmap_flags, _memfd_flags) \
> +FIXTURE_VARIANT_ADD(vfio_dma_mapping_perf_memfd_test, _iommu_mode ## _ ## _name) {    \
> +	.iommu_mode = #_iommu_mode,						      \
> +	.mmap_flags = MAP_SHARED | (_mmap_flags),				      \
> +	.memfd_flags = MAP_SHARED | (_memfd_flags),				      \

[Severity: Low]
Does this incorrectly pass the mmap flag MAP_SHARED to memfd_create() via
memfd_flags?

MAP_SHARED (0x01) aliases with MFD_CLOEXEC (0x0001U) in the memfd flag
namespace, which silently sets close-on-exec rather than failing at runtime.
Could conflating the namespaces here cause confusion?

> +}
> +
[ ... ]
> +static void *setup_memfd(int *fd, u64 size, int mmap_flags, int mfd_flags)
> +{
> +	void *buf = MAP_FAILED;
> +	struct timespec start;
> +
> +	timer_start(&start);
> +	*fd = memfd_create("vfio_dma_mapping_perf_memfd_test", mfd_flags);
> +	printf("Completed memfd_create() in %.2lfms\n", timer_elapsed_ms(start));
> +	if (*fd <= 0)
> +		return MAP_FAILED;

[Severity: Low]
Could this leak fd 0 if memfd_create() successfully returns it?

File descriptors can validly be 0 if the test is run with stdin closed.
Would it be better to check if (*fd < 0) instead so it doesn't reject fd 0?

> +
> +	if (ftruncate(*fd, size))
> +		goto out;
[ ... ]
> +TEST_F(vfio_dma_mapping_perf_memfd_test, dma_map_unmap_from_file)
> +{
> +	const u64 size = SZ_1G;
> +	struct dma_region region;
> +	struct timespec start;
> +	u64 unmapped;
> +	int rc, fd;
> +
> +	region.vaddr = setup_memfd(&fd, size, variant->mmap_flags, variant->memfd_flags);
> +	ASSERT_NE(region.vaddr, MAP_FAILED);

[Severity: Medium]
Will this unconditional ASSERT_NE cause the test suite to fail on systems
that do not have sufficient hugepages configured (e.g., for MFD_HUGE_1GB or
MFD_HUGE_2MB) instead of gracefully skipping the unsupported variants?

> +
> +	region.iova = iova_allocator_alloc(self->iova_allocator, size);
> +	region.size = size;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260701203311.326798-1-aaronlewis@google.com?part=2

  reply	other threads:[~2026-07-01 20:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 20:33 [PATCH 0/4] Introduce vfio_dma_mapping_perf_test Aaron Lewis
2026-07-01 20:33 ` [PATCH 1/4] vfio: selftests: " Aaron Lewis
2026-07-01 20:44   ` sashiko-bot
2026-07-01 20:33 ` [PATCH 2/4] vfio: selftests: Add memfd test to vfio_dma_mapping_perf_test Aaron Lewis
2026-07-01 20:43   ` sashiko-bot [this message]
2026-07-01 20:33 ` [PATCH 3/4] vfio: selftests: Allow a size for vfio_dma_mapping_perf_test Aaron Lewis
2026-07-01 20:44   ` sashiko-bot
2026-07-01 20:33 ` [PATCH 4/4] vfio: selftests: Allow the flag MAP_POPULATE to be set on the cmdline Aaron Lewis

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=20260701204337.0EB561F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aaronlewis@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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