On Thu, Jun 12, 2025 at 12:42:42PM -0300, Jason Gunthorpe wrote: > On Thu, Jun 12, 2025 at 05:23:01PM +0200, Thomas Weißschuh wrote: > > On Thu, Jun 12, 2025 at 11:58:01AM -0300, Jason Gunthorpe wrote: > > > On Thu, Jun 12, 2025 at 04:27:41PM +0200, Thomas Weißschuh wrote: > > > > > > > If the assumption is that this is most likely a kernel bug, > > > > shouldn't it be fixed properly rather than worked around? > > > > After all the job of a selftest is to detect bugs to be fixed. > > > > > > I investigated the history for a bit and it seems likely we cannot > > > change the kernel here. Call it an undocumented "feature". > > > > I looked a bit and it seems to be mentioned in mmap(2): > > > > For mmap(), offset must be a multiple of the underlying huge page size. > > The system automatically aligns length to be a multiple of the > > underlying huge page size. > > Oh there you go then :) Horrible design. No way for userspace to know > what the rounded up length actually was and thus no way for > userspace to unmap it.
OK. I think we would have to skip those cases then. > > > MAP_HUGETLBFS rounds up the length to some value, userspace has to > > > figure that out and not pass incorrect lengths. The selftest is doing > > > that wrong. > > > > The selftest would be more robust if MAP_FIXED is replaced by > > MAP_FIXED_NOREPLACE. Even with the new explicit skip logic it should > > make debugging easier if something goes wrong. > > The point is to replace something that is already mapped there, though > I no longer remember why it is working like this. By replacing MAP_FIXED with MAP_FIXED_NOREPLACE, at the existing two places, the selftest crashed at early setup_sizes...: iommufd: iommufd.c:53: setup_sizes: Assertion `vrc == buffer' failed. /nicolinc/iommufd_selftest.sh: line 19: 21487 Aborted (core dumped) tools/testing/selftests/iommu/iommufd strace: mmap(0xffff80000000, 1048576, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS|MAP_FIXED_NOREPLACE, -1, 0) = -1 EEXIST (File exists) This one doesn't MAP_HUGETLBFS btw... Thanks Nicolin