iris: check memory with INTEL_DEBUG=mem

After this commit, INTEL_DEBUG=mem will make iris over-allocate a page
for every GEM buffer requested, write a pattern to the unused end area
- which we refer to as the red zone - and check for integrity of the
pattern when the buffer is not used anymore. Once a problem is found,
we dump the buffer and assert(false). Notice that the red zone is not
only the extra page we over-allocate, but it also includes the padding
caused by iris' allocation buckets and page rounding: even if our tool
didn't over-allocate anything (i.e., if we define
RED_ZONE_BUFFER_EXTENSION to zero), the tool would still be doing
helpful work.

While I was able to find an issue in the Kernel with this patch
series, it turns our the Mesa problems I suspected to have found were
issues with this patch. So as of v5 the memory checker still has yet
to find a Mesa memory problem.

I also plan to extend the subsystem to also check for use-after-free
issues in later patches, but first I want to work on the bugs that red
zoning was already able to catch.

 - Rebase
 - Missing commas in error message (Marcin Ślusarz).
 - Rely on memcmp() in check_red_zone() instead of implementing our
   own uint64_t check (Marcin Ślusarz).
 - Rebase.
 - Tweak the dump_mem_range() output after having used it for a while.
 - Make the code a little easier to read.
 - Use RAW_MODE so we don't get false positives in RBC and HIZ
   auxiliary buffers.

Signed-off-by: Paulo Zanoni <>
31 jobs for !4713 with mem-debug
latest detached
Status Job ID Name Coverage
manual arm_build #4060905
aarch64 manual
manual arm_test-base #4060908
manual x86_build-base #4060900
manual x86_build_old #4060904
manual x86_test-base #4060902
  Container 2
created arm64_test #4060922
created i386_build #4060917
created kernel+rootfs_amd64 #4060910
created kernel+rootfs_arm64 #4060912
created kernel+rootfs_armhf #4060914
created ppc64el_build #4060918
created s390x_build #4060919
created x86_build #4060916
created x86_test-gl #4060920
created x86_test-vk #4060921
  Meson X86 64
created meson-android #4060926
created meson-clang #4060927
created meson-classic #4060925
created meson-clover #4060928
created meson-clover-old-llvm #4060929
created meson-gallium #4060924
created meson-testing #4060923
created meson-vulkan #4060930
created scons-win64 #4060931
allowed to fail
  Meson Misc
created meson-arm64 #4060933
created meson-arm64-build-test #4060934
created meson-armhf #4060932
created meson-i386 #4060935
created meson-mingw32-x86_64 #4060938
created meson-ppc64el #4060937
created meson-s390x #4060936