Re: [PATCH v4 09/14] selftests: harness: Move teardown conditional into test metadata
From: Jason Gunthorpe
Date: Thu Jun 12 2025 - 14:56:27 EST
On Thu, Jun 12, 2025 at 11:53:24AM -0700, Nicolin Chen wrote:
> @@ -2022,7 +2023,19 @@ FIXTURE_SETUP(iommufd_dirty_tracking)
> self->fd = open("/dev/iommu", O_RDWR);
> ASSERT_NE(-1, self->fd);
>
> - rc = posix_memalign(&self->buffer, HUGEPAGE_SIZE, variant->buffer_size);
> + if (variant->hugepages) {
> + /*
> + * Allocation must be aligned to the HUGEPAGE_SIZE, because the
> + * following mmap() will automatically align the length to be a
> + * multiple of the underlying huge page size. Failing to do the
> + * same at this allocation will result in a memory overwrite by
> + * the mmap().
> + */
> + size = __ALIGN_KERNEL(variant->buffer_size, HUGEPAGE_SIZE);
> + } else {
> + size = variant->buffer_size;
> + }
> + rc = posix_memalign(&self->buffer, HUGEPAGE_SIZE, size);
> if (rc || !self->buffer) {
> SKIP(return, "Skipping buffer_size=%lu due to errno=%d",
> variant->buffer_size, rc);
>
> It can just upsize the allocation, i.e. the test case will only
> use the first 64M or 128MB out of the reserved 512MB huge page.
The MAP_HUGETLBFS is required that is the whole point of what it is
doing..
Jason