This is an archive of the discontinued LLVM Phabricator instance.

Memorysanitizer fix mmap test for oses not supporting MAP_NORESERVE flag
ClosedPublic

Authored by devnexen on May 21 2018, 9:17 AM.

Details

Summary
  • fix the unit test mmap detecting the MAP_NORESERVE flag support (but NetBSD does not implement it).

Diff Detail

Event Timeline

devnexen created this revision.May 21 2018, 9:17 AM
devnexen retitled this revision from Memorysanitizer fix mmap test to Memorysanitizer fix mmap test for non Linux oses.May 21 2018, 9:18 AM
devnexen added reviewers: krytarowski, slthakur.
krytarowski added inline comments.May 21 2018, 9:55 AM
test/msan/mmap.cc
67

ifdef MAP_NORESERVE

$ grep -r MAP_NORESERVE /usr/include/sys          
/usr/include/sys/mman.h:#define	MAP_NORESERVE	 0x0040	/* Sun: don't reserve needed swap area */
$ uname -a
NetBSD rugged 8.99.14 NetBSD 8.99.14 (GENERIC) #1: Thu Apr 26 15:16:44 CEST 2018  root@chieftec:/public/netbsd-root/sys/arch/amd64/compile/GENERIC amd64
devnexen updated this revision to Diff 147816.May 21 2018, 10:46 AM
devnexen retitled this revision from Memorysanitizer fix mmap test for non Linux oses to Memorysanitizer fix mmap test for oses not supporting MAP_NORESERVE flag.
devnexen edited the summary of this revision. (Show Details)

The code looks fine.. but I don't like the description.

NetBSD has the flag available, but it does not support/implement it. It's dummy.

Sorry I was not aware of the NetBSD specifics. Changing.

devnexen edited the summary of this revision. (Show Details)May 24 2018, 10:01 PM

Does it look better to you now ? It s ok I won t bother you more than that I have commit access now :-)

I defer it to maintainers!

Two questions,

  1. How does MSan work at all if MAP_NORESERVE is not implemented? Is it actually the default setting, and it's the opposite behavior that is not implemented?
  2. If the flag is defined in the headers but ignored by the kernel, then what is the purpose of this patch?

This patch is more for systems not implementing it (as NetBSD) or even not having this flag (as FreeBSD).
However the flag is defined for FreeBSD into lib sanitizer (sanitizer_posix_libcdep.cc line 45) for MmapFixedNoReserve.

eugenis accepted this revision.May 25 2018, 12:54 PM

OK, fine.
Just keep in mind that this test tries to exhaust the address space, but, without NORESERVE semantics, it would exhaust physical RAM instead and may DOS the entire system.

This revision is now accepted and ready to land.May 25 2018, 12:54 PM

i.e. unless you've tested it on one of those systems, it might be safer to disable the test instead

I tested in my relatively casual FreeBSD box 4GB.

devnexen closed this revision.May 25 2018, 1:38 PM

On NetBSD NORESERVE is enforced by default, so this flag is dummy.

This design is most likely the same on all current BSDs. OpenBSD borrowed UVM from NetBSD. FreeBSD has its distinct memory subsystem.

Submitted with r333306.