Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pranjal Shrivastava" <praan@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [RFC PATCH 7/7] vfio/selftests: Add observability test for IO page table usage
Date: Fri, 02 Oct 2026 09:14:06 +0000	[thread overview]
Message-ID: <20261002091406.993B61F00899@smtp.kernel.org> (raw)
In-Reply-To: <20261001224531.765278-8-praan@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] selftests: vfio_nr_pages_test skips IOMMUFD due to zero-initialized fd assumption
- [Medium] selftests: vfio_nr_pages_test crashes when mapping PROT_NONE memory
--

commit d7003d8f6957a90f40b858dea08cd7ccf897ea8b
Author: Pranjal Shrivastava <praan@google.com>

vfio/selftests: Add observability test for IO page table usage

This commit adds a new selftest, vfio_nr_pages_test, to validate the
iommu-nr-pages fdinfo metric across IOMMU backends. The test performs
sparse mappings to force deep page table allocation and checks that the
metric increases and remains allocated upon unmapping.

> diff --git a/tools/testing/selftests/vfio/vfio_nr_pages_test.c b/tools/testing/selftests/vfio/vfio_nr_pages_test.c
> new file mode 100644
> index 0000000000000..aef6b1dd8e19d
> --- /dev/null
> +++ b/tools/testing/selftests/vfio/vfio_nr_pages_test.c
> @@ -0,0 +1,119 @@

[ ... ]

> +static long read_nr_pages(struct iommu *iommu)
> +{
> +	char path[256];
> +	char line[128];
> +	FILE *f;
> +	long val = -1;
> +	int fd = iommu->container_fd != -1 ? iommu->container_fd : iommu->iommufd;

[Severity: Medium]
Will this ternary operation erroneously yield 0 instead of the actual
iommufd file descriptor?

In IOMMUFD mode, iommu->container_fd is implicitly initialized to 0 via
calloc_assert() in iommu_init(), while iommu->iommufd is initialized to the
actual file descriptor.

This causes the ternary operator iommu->container_fd != -1 to evaluate to
true, assigning fd = 0.

The test then reads from /proc/self/fdinfo/0, fails to find the metric, and
silently skips execution for the IOMMUFD backend.

[ ... ]

> +TEST_F(vfio_nr_pages_test, sparse_mapping_sticky_reclamation)
> +{
> +	long nr_pages_initial, nr_pages_mapped, nr_pages_final;
> +	struct dma_region region1 = {0};
> +	struct dma_region region2 = {0};
> +
> +	if (!self->iommu || !self->device)
> +		SKIP(return, "Fixture setup failed");
> +
> +	nr_pages_initial = read_nr_pages(self->iommu);
> +	if (nr_pages_initial < 0)
> +		SKIP(return, "iommu-nr-pages not reported by this IOMMU");
> +
> +	/* Map a page at start */
> +	region1.size = SZ_4K;
> +	region1.vaddr = mmap_reserve(region1.size, region1.size, 0);
> +	ASSERT_NE(MAP_FAILED, region1.vaddr);
> +	region1.iova = 0x100000;
> +	iommu_map(self->iommu, &region1);

[Severity: Medium]
Does mapping this PROT_NONE region cause the test to crash?

mmap_reserve() provisions memory using mmap() with strictly PROT_NONE
protections. The test immediately passes this region to iommu_map()
without calling mprotect() or over-mapping with PROT_READ | PROT_WRITE.

The kernel will attempt to pin these pages using get_user_pages(), which
will fail with -EFAULT due to lack of read/write permissions.

The iommu_map() wrapper asserts success, causing the test to unconditionally
crash.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261001224531.765278-1-praan@google.com?part=7

      reply	other threads:[~2026-10-02  9:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 22:45 [RFC PATCH 0/7] iommu: Introduce Page Table Observability Framework Pranjal Shrivastava
2026-10-01 22:45 ` [RFC PATCH 1/7] iommu: Add infrastructure for per-domain IOPT accounting Pranjal Shrivastava
2026-10-01 22:45 ` [RFC PATCH 2/7] iommu: Implement domain-attributed page allocation Pranjal Shrivastava
2026-10-01 22:45 ` [RFC PATCH 3/7] iommupt: Enable per-domain IOPT attribution Pranjal Shrivastava
2026-10-01 22:45 ` [RFC PATCH 4/7] vfio/type1: Expose IO page table usage via fdinfo Pranjal Shrivastava
2026-10-01 22:45 ` [RFC PATCH 5/7] iommufd: " Pranjal Shrivastava
2026-10-01 22:45 ` [RFC PATCH 6/7] iommufd/selftest: Add observability test for iommu-nr-pages Pranjal Shrivastava
2026-10-01 22:45 ` [RFC PATCH 7/7] vfio/selftests: Add observability test for IO page table usage Pranjal Shrivastava
2026-10-02  9:14   ` sashiko-bot [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=20261002091406.993B61F00899@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=praan@google.com \
    --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