Page MenuHomeFreeBSD

Add more mmap tests related to character devices.
ClosedPublic

Authored by jhb on Aug 6 2015, 5:19 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 8, 1:57 PM
Unknown Object (File)
Mon, Mar 25, 10:31 PM
Unknown Object (File)
Jan 8 2024, 6:51 AM
Unknown Object (File)
Dec 22 2023, 8:57 PM
Unknown Object (File)
Dec 20 2023, 5:54 PM
Unknown Object (File)
Dec 4 2023, 9:14 AM
Unknown Object (File)
Nov 25 2023, 4:44 PM
Unknown Object (File)
Nov 13 2023, 2:12 AM
Subscribers

Details

Summary
  • Add cdev-related tests for bad args.
  • Add a simple test case for mapping /dev/zero.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb retitled this revision from to Add more mmap tests related to character devices..
jhb updated this object.
jhb edited the test plan for this revision. (Show Details)
jhb added reviewers: kib, alc.
tests/sys/vm/mmap_test.c
168 ↗(On Diff #7729)

I left this nullfd test here for you to see, but as my comment above suggests, I'm inclined to remove it. It is not a reliable test. I would need some some sort of /dev/foo for which non-root mmap works.

I suppose I could add a test that used /dev/mem and was skipped if the open failed due to not being root? This would at least test when run as root. Not sure if the automated tests under jenkins run as root or a mere mortal though.

171 ↗(On Diff #7729)

I used this test to verify that my recent fix for /dev/zero preserved existing behavior for the MAP_SHARED case. This failed in a pre-fo_mmap kernel and now still fails after the recent change.

183 ↗(On Diff #7729)

FWIW, MAP_SHARED mappings of a read/write /dev/zero fd have the same behavior. Not sure if that is a feature we should test for or just due to the implementation being simple.

  • Use a dedicated test for MAP_PRIVATE + cdevs with /dev/mem.
tests/sys/vm/mmap_test.c
127 ↗(On Diff #7730)

Somewhat complicated suggestion is to check whether you really get a private mapping, i.e. zero pages even if other mapping wrote something.

Oh, I found the test below.

167 ↗(On Diff #7730)

Might be, consider /dev/devstat ? I did not checked it actually.

182 ↗(On Diff #7730)

I see. This is the feature, and since you test for the behaviour of the private mapping, the shared mapping could be easily handled.

tests/sys/vm/mmap_test.c
182 ↗(On Diff #7730)

FWIW, MAP_SHARED mappings of a read/write /dev/zero fd have the same behavior.

I'm confused by this statement. It's the same behavior as what?

Does the mapping of /dev/zero ever behave differently from MAP_ANON?

tests/sys/vm/mmap_test.c
182 ↗(On Diff #7730)

Well, the behaviour is weird for something with mmap(fd) where fd != -1. Every new mapping gets zero content, and flags only define future sharing mode. This is in contrast of other anonymous memory, like posix shm fd.

Yes, mmap("/dev/zero") is defned to behave as mmap(MAP_ANON), but sometimes caller of mmap cannot tell since it is defined by fd.

alc edited edge metadata.

Yes, the semantics of mmap()ing /dev/zero have always been irregular. I just wanted to be sure that there wasn't another issue.

Anyway, I think that the proposed tests are correct.

This revision is now accepted and ready to land.Aug 7 2015, 10:24 PM
jhb edited edge metadata.
  • Use /dev/devstat instead of /dev/mem.
  • Now that the cdev_private test doesn't require root, merge it into bad_arguments.
  • Duplicate the MAP_PRIVATE /dev/zero test for MAP_SHARED.
This revision now requires review to proceed.Sep 3 2015, 3:28 AM
kib edited edge metadata.
kib added inline comments.
tests/sys/vm/mmap_test.c
116 ↗(On Diff #8445)

>= 0 could be usefully replaced by >= devstatfd in the assertion, etc.

This revision is now accepted and ready to land.Sep 3 2015, 8:52 AM
jhb edited edge metadata.

Try to force an update.

This revision now requires review to proceed.Sep 4 2015, 1:00 AM
This revision was automatically updated to reflect the committed changes.