[PATCH] tests/intel/xe_vm: Add BO partial mmap test
Matthew Brost
matthew.brost at intel.com
Wed Aug 14 17:00:26 UTC 2024
On Wed, Aug 14, 2024 at 05:48:19PM +0100, Matthew Auld wrote:
> On 14/08/2024 16:58, Matthew Brost wrote:
> > Ensure BO partial mmap works by setting a BO to 0, partially mmap BO and
> > setting to a canned value, and then mmap entire BO ensure data
> > integrity.
> >
> > Signed-off-by: Matthew Brost <matthew.brost at intel.com>
> > ---
> > tests/intel/xe_vm.c | 53 +++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 53 insertions(+)
> >
> > diff --git a/tests/intel/xe_vm.c b/tests/intel/xe_vm.c
> > index c3960fedee..57534a2a8c 100644
> > --- a/tests/intel/xe_vm.c
> > +++ b/tests/intel/xe_vm.c
> > @@ -106,6 +106,56 @@ test_scratch(int fd)
> > xe_vm_destroy(fd, vm);
> > }
> > +/**
> > + * SUBTEST: bo-mmap-partial
> > + * Description: Test partially mmap of a BO
> > + * Functionality: BO mmap
> > + * Test category: functionality test
> > + */
> > +
> > +static void test_bo_mmap_partial(int fd, size_t bo_size)
> > +{
> > +#define MMAP_VALUE(idx) ((0xdeadull << 32) | idx)
> > + uint32_t bo;
> > + uint64_t offset;
> > + uint64_t *ptr;
> > + size_t partial_size = bo_size / 2;
> > + void *map;
> > + int i, j;
> > +
> > + bo = xe_bo_create(fd, 0, bo_size, vram_if_possible(fd, 0),
> > + DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM);
> > +
> > + /* Set to zero */
> > + map = xe_bo_map(fd, bo, bo_size);
> > + memset(map, 0, bo_size);
> > + munmap(map, bo_size);
> > +
> > + /* Partial map */
> > + offset = xe_bo_mmap_offset(fd, bo);
> > + map = mmap(NULL, partial_size, PROT_WRITE, MAP_SHARED, fd,
> > + offset + partial_size);
>
> So does this also then fail with:
>
Indeed it does fail. I pushed this as reference to the following series [1].
Sima brought it to our attention that Xe doesn't support this, confirmed
via this quick IGT. Discussion is ongoing it this is needed in the i915,
if it is, then it also need in Xe. See all the replies to the cover
letter on the list.
[1] https://patchwork.freedesktop.org/series/137307/
> > + map = mmap(NULL, partial_size, PROT_WRITE, MAP_SHARED, fd,
> > + offset);
>
> Or it that allowed? From looking at the kernel side it looks like it's maybe
> not rejected?
>
The kernel currently rejects. A quick fix is [2] in
drm_gem.c:drm_gem_mmap.
[2] s/drm_vma_offset_exact_lookup_locked/drm_vma_offset_lookup_locked
> Also you can get partial mapping with partial munmap, should we also test
> that to make sure nothing blows up?
>
For sure, the test needs to be robust if we decide to support this.
Matt
> > + igt_assert(map != MAP_FAILED);
> > + ptr = map;
> > + for (i = 0, j = partial_size / sizeof(uint64_t);
> > + j < bo_size / sizeof(uint64_t); ++i, ++j)
> > + ptr[i] = MMAP_VALUE(j);
> > + munmap(map, partial_size);
> > +
> > + /* Map entire BO and check */
> > + map = xe_bo_map(fd, bo, bo_size);
> > + ptr = map;
> > + for (i = 0; i < bo_size / sizeof(uint64_t); ++i) {
> > + if (i < partial_size / sizeof(uint64_t))
> > + igt_assert_eq(ptr[i], 0);
> > + else
> > + igt_assert_eq(ptr[i], MMAP_VALUE(i));
> > + }
> > + munmap(map, bo_size);
> > + gem_close(fd, bo);
> > +#undef MMAP_VALUE
> > +}
> > +
> > static void
> > __test_bind_one_bo(int fd, uint32_t vm, int n_addrs, uint64_t *addrs)
> > {
> > @@ -2354,6 +2404,9 @@ igt_main
> > }
> > }
> > + igt_subtest("bo-mmap-partial")
> > + test_bo_mmap_partial(fd, SZ_2M);
> > +
> > igt_subtest("bind-once")
> > test_bind_once(fd);
More information about the igt-dev
mailing list