<div dir="ltr">Petri and Kamil,<div><br></div><div>I just sent in a new patch under the name "Replaced instances of mmap64() with drm_mmap()".<br></div><div>This patch follows Rob Clark's advice and uses drm_mmap() instead of mmap() so 32-bit</div><div>machines are (partially) accounted for.</div><div><br></div><div>Thank you,</div><div>Jake Freeland</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 3, 2022 at 8:17 AM Petri Latvala <<a href="mailto:petri.latvala@intel.com" target="_blank">petri.latvala@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Sep 28, 2022 at 05:36:36PM +0200, Kamil Konieczny wrote:<br>
> On 2022-09-28 at 15:44:54 +0300, Petri Latvala wrote:<br>
> > On Wed, Sep 28, 2022 at 02:33:14PM +0200, Kamil Konieczny wrote:<br>
> > > Hi Jake,<br>
> > > <br>
> > > this patch is missing commit message. Please put here short<br>
> > > description of change and why you do it. Change looks resonable<br>
> > > as on 64-bit systems both functions are the same.<br>
> > > <br>
> > > On 2022-09-18 at 17:15:35 -0500, Jake Freeland wrote:<br>
> > > > Signed-off-by: Jake Freeland <<a href="mailto:jfree@freebsd.org" target="_blank">jfree@freebsd.org</a>><br>
> > > <br>
> > > Adding Petri on cc as I do not know if anyone compiles this on<br>
> > > 32-bit platforms.<br>
> > <br>
> > Aren't you supposed to use mmap() with _LARGEFILE_something even on<br>
> > 32-bit builds, instead of mmap64?<br>
> > <br>
> > <br>
> > -- <br>
> > Petri Latvala<br>
> > <br>
> <br>
> imho _LARGEFILE_... is indeed needed on 32-bit builds, no need<br>
> for this on our current builds as Linux runs now on 64-bit<br>
> machines.<br>
> <br>
> I was asking if you know of anyone compiling and using igt i915<br>
> code for 32-bit platform.<br>
> <br>
> I see that this patch touches also igt_vgem lib so maybe we<br>
> should also ask arm igt users ?<br>
<br>
Rob Clark suggested just using drm_mmap() and letting it figure out<br>
whether to call mmap or mmap64. Although it just seems to call mmap()<br>
anyway and assumes largefile always, except on android, except when<br>
__LP64__ is set.<br>
<br>
For IGT we could either use drm_mmap or just make the same documented<br>
assumption.<br>
<br>
-- <br>
Petri Latvala<br>
<br>
<br>
> <br>
> --<br>
> Kamil<br>
> <br>
> > <br>
> > <br>
> > > <br>
> > > Regards,<br>
> > > Kamil<br>
> > > <br>
> > > > ---<br>
> > > > lib/i915/gem_mman.c | 4 ++--<br>
> > > > lib/igt_vgem.c | 2 +-<br>
> > > > tests/i915/gem_mmap_gtt.c | 22 +++++++++++-----------<br>
> > > > tests/i915/gem_mmap_offset.c | 14 +++++++-------<br>
> > > > 4 files changed, 21 insertions(+), 21 deletions(-)<br>
> > > > <br>
> > > > diff --git a/lib/i915/gem_mman.c b/lib/i915/gem_mman.c<br>
> > > > index aa9ac6f3..0b41ba70 100644<br>
> > > > --- a/lib/i915/gem_mman.c<br>
> > > > +++ b/lib/i915/gem_mman.c<br>
> > > > @@ -118,7 +118,7 @@ void *__gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot)<br>
> > > > if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg))<br>
> > > > return NULL;<br>
> > > > <br>
> > > > - ptr = mmap64(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);<br>
> > > > + ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);<br>
> > > > if (ptr == MAP_FAILED)<br>
> > > > ptr = NULL;<br>
> > > > else<br>
> > > > @@ -331,7 +331,7 @@ void *__gem_mmap_offset(int fd, uint32_t handle, uint64_t offset, uint64_t size,<br>
> > > > if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_OFFSET, &arg))<br>
> > > > return NULL;<br>
> > > > <br>
> > > > - ptr = mmap64(0, size, prot, MAP_SHARED, fd, arg.offset + offset);<br>
> > > > + ptr = mmap(0, size, prot, MAP_SHARED, fd, arg.offset + offset);<br>
> > > > <br>
> > > > if (ptr == MAP_FAILED)<br>
> > > > ptr = NULL;<br>
> > > > diff --git a/lib/igt_vgem.c b/lib/igt_vgem.c<br>
> > > > index 7f933b23..468383c7 100644<br>
> > > > --- a/lib/igt_vgem.c<br>
> > > > +++ b/lib/igt_vgem.c<br>
> > > > @@ -76,7 +76,7 @@ void *__vgem_mmap(int fd, struct vgem_bo *bo, unsigned prot)<br>
> > > > if (drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg))<br>
> > > > return NULL;<br>
> > > > <br>
> > > > - ptr = mmap64(0, bo->size, prot, MAP_SHARED, fd, arg.offset);<br>
> > > > + ptr = mmap(0, bo->size, prot, MAP_SHARED, fd, arg.offset);<br>
> > > > if (ptr == MAP_FAILED)<br>
> > > > return NULL;<br>
> > > > <br>
> > > > diff --git a/tests/i915/gem_mmap_gtt.c b/tests/i915/gem_mmap_gtt.c<br>
> > > > index 4f05eb18..683eaf16 100644<br>
> > > > --- a/tests/i915/gem_mmap_gtt.c<br>
> > > > +++ b/tests/i915/gem_mmap_gtt.c<br>
> > > > @@ -113,11 +113,11 @@ test_access(int fd)<br>
> > > > mmap_arg.handle = handle;<br>
> > > > do_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg);<br>
> > > > <br>
> > > > - igt_assert(mmap64(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,<br>
> > > > + igt_assert(mmap(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,<br>
> > > > MAP_SHARED, fd, mmap_arg.offset));<br>
> > > > <br>
> > > > /* Check that the same offset on the other fd doesn't work. */<br>
> > > > - igt_assert(mmap64(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,<br>
> > > > + igt_assert(mmap(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,<br>
> > > > MAP_SHARED, fd2, mmap_arg.offset) == MAP_FAILED);<br>
> > > > igt_assert(errno == EACCES);<br>
> > > > <br>
> > > > @@ -128,7 +128,7 @@ test_access(int fd)<br>
> > > > <br>
> > > > /* Recheck that it works after flink. */<br>
> > > > /* Check that the same offset on the other fd doesn't work. */<br>
> > > > - igt_assert(mmap64(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,<br>
> > > > + igt_assert(mmap(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,<br>
> > > > MAP_SHARED, fd2, mmap_arg.offset));<br>
> > > > }<br>
> > > > <br>
> > > > @@ -159,11 +159,11 @@ test_short(int fd)<br>
> > > > for (pages = 1; pages <= OBJECT_SIZE / PAGE_SIZE; pages <<= 1) {<br>
> > > > uint8_t *r, *w;<br>
> > > > <br>
> > > > - w = mmap64(0, pages * PAGE_SIZE, PROT_READ | PROT_WRITE,<br>
> > > > + w = mmap(0, pages * PAGE_SIZE, PROT_READ | PROT_WRITE,<br>
> > > > MAP_SHARED, fd, mmap_arg.offset);<br>
> > > > igt_assert(w != MAP_FAILED);<br>
> > > > <br>
> > > > - r = mmap64(0, pages * PAGE_SIZE, PROT_READ,<br>
> > > > + r = mmap(0, pages * PAGE_SIZE, PROT_READ,<br>
> > > > MAP_SHARED, fd, mmap_arg.offset);<br>
> > > > igt_assert(r != MAP_FAILED);<br>
> > > > <br>
> > > > @@ -384,13 +384,13 @@ test_isolation(int i915)<br>
> > > > <br>
> > > > close(B);<br>
> > > > <br>
> > > > - ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);<br>
> > > > + ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);<br>
> > > > igt_assert(ptr != MAP_FAILED);<br>
> > > > munmap(ptr, 4096);<br>
> > > > <br>
> > > > close(A);<br>
> > > > <br>
> > > > - ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);<br>
> > > > + ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);<br>
> > > > igt_assert(ptr == MAP_FAILED);<br>
> > > > }<br>
> > > > <br>
> > > > @@ -400,7 +400,7 @@ test_close_race(int i915)<br>
> > > > const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);<br>
> > > > _Atomic uint32_t *handles;<br>
> > > > <br>
> > > > - handles = mmap64(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);<br>
> > > > + handles = mmap(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);<br>
> > > > igt_assert(handles != MAP_FAILED);<br>
> > > > <br>
> > > > igt_fork(child, ncpus + 1) {<br>
> > > > @@ -418,7 +418,7 @@ test_close_race(int i915)<br>
> > > > &mmap_arg) != -1) {<br>
> > > > void *ptr;<br>
> > > > <br>
> > > > - ptr = mmap64(0, 4096,<br>
> > > > + ptr = mmap(0, 4096,<br>
> > > > PROT_WRITE, MAP_SHARED, i915,<br>
> > > > mmap_arg.offset);<br>
> > > > if (ptr != MAP_FAILED) {<br>
> > > > @@ -444,7 +444,7 @@ test_flink_race(int i915)<br>
> > > > const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);<br>
> > > > _Atomic uint32_t *handles;<br>
> > > > <br>
> > > > - handles = mmap64(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);<br>
> > > > + handles = mmap(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);<br>
> > > > igt_assert(handles != MAP_FAILED);<br>
> > > > <br>
> > > > igt_fork(child, ncpus + 1) {<br>
> > > > @@ -469,7 +469,7 @@ test_flink_race(int i915)<br>
> > > > &mmap_arg) != -1) {<br>
> > > > void *ptr;<br>
> > > > <br>
> > > > - ptr = mmap64(0, 4096,<br>
> > > > + ptr = mmap(0, 4096,<br>
> > > > PROT_WRITE, MAP_SHARED, fd,<br>
> > > > mmap_arg.offset);<br>
> > > > if (ptr != MAP_FAILED) {<br>
> > > > diff --git a/tests/i915/gem_mmap_offset.c b/tests/i915/gem_mmap_offset.c<br>
> > > > index 5781b2fb..0933ed94 100644<br>
> > > > --- a/tests/i915/gem_mmap_offset.c<br>
> > > > +++ b/tests/i915/gem_mmap_offset.c<br>
> > > > @@ -66,7 +66,7 @@ __mmap_offset(int i915, uint32_t handle, uint64_t offset, uint64_t size,<br>
> > > > if (mmap_offset_ioctl(i915, &arg))<br>
> > > > return NULL;<br>
> > > > <br>
> > > > - ptr = mmap64(0, size, prot, MAP_SHARED, i915, arg.offset + offset);<br>
> > > > + ptr = mmap(0, size, prot, MAP_SHARED, i915, arg.offset + offset);<br>
> > > > if (ptr == MAP_FAILED)<br>
> > > > ptr = NULL;<br>
> > > > else<br>
> > > > @@ -214,12 +214,12 @@ static void isolation(int i915)<br>
> > > > t->name, B, b, offset_b);<br>
> > > > <br>
> > > > errno = 0;<br>
> > > > - ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, i915, offset_a);<br>
> > > > + ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, i915, offset_a);<br>
> > > > igt_assert(ptr == MAP_FAILED);<br>
> > > > igt_assert_eq(errno, EACCES);<br>
> > > > <br>
> > > > errno = 0;<br>
> > > > - ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, i915, offset_b);<br>
> > > > + ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, i915, offset_b);<br>
> > > > igt_assert(ptr == MAP_FAILED);<br>
> > > > igt_assert_eq(errno, EACCES);<br>
> > > > <br>
> > > > @@ -237,13 +237,13 @@ static void isolation(int i915)<br>
> > > > <br>
> > > > close(B);<br>
> > > > <br>
> > > > - ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);<br>
> > > > + ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);<br>
> > > > igt_assert(ptr != MAP_FAILED);<br>
> > > > munmap(ptr, 4096);<br>
> > > > <br>
> > > > close(A);<br>
> > > > <br>
> > > > - ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);<br>
> > > > + ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);<br>
> > > > igt_assert(ptr == MAP_FAILED);<br>
> > > > }<br>
> > > > }<br>
> > > > @@ -401,7 +401,7 @@ static void close_race(int i915, int timeout)<br>
> > > > _Atomic uint32_t *handles;<br>
> > > > size_t len = ALIGN((ncpus + 1) * sizeof(uint32_t), 4096);<br>
> > > > <br>
> > > > - handles = mmap64(0, len, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);<br>
> > > > + handles = mmap(0, len, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);<br>
> > > > igt_assert(handles != MAP_FAILED);<br>
> > > > <br>
> > > > igt_fork(child, ncpus + 1) {<br>
> > > > @@ -420,7 +420,7 @@ static void close_race(int i915, int timeout)<br>
> > > > &mmap_arg) != -1) {<br>
> > > > void *ptr;<br>
> > > > <br>
> > > > - ptr = mmap64(0, 4096,<br>
> > > > + ptr = mmap(0, 4096,<br>
> > > > PROT_WRITE, MAP_SHARED, i915,<br>
> > > > mmap_arg.offset);<br>
> > > > if (ptr != MAP_FAILED) {<br>
> > > > -- <br>
> > > > 2.37.3<br>
> > > > <br>
</blockquote></div>