* Question about mmap syscall and POSIX standard on mips arch
@ 2018-10-18 3:26 Hongzhi, Song
2018-10-18 4:32 ` Al Viro
0 siblings, 1 reply; 3+ messages in thread
From: Hongzhi, Song @ 2018-10-18 3:26 UTC (permalink / raw)
To: linux-kernel, mm-commits
Hi all,
Ltp has a POSIX teatcase about mmap, 24-2.c.
https://github.com/linux-test-project/ltp/blob/e816127e5d8efbff5ae53e9c2292fae22f36838b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c#L94
-----part of code-----
pa = mmap(addr, len, PROT_READ | PROT_WRITE, MAP_FIXED |
MAP_SHARED, fd,
0);
if (pa == MAP_FAILED && errno == ENOMEM) {
printf("Got ENOMEM: %s\nTest PASSED\n", strerror(errno));
exit(PTS_PASS);
}
-----end----------------
Under POSIX standard, the expected errno should be ENOMEM
when the specific [addr+len] exceeds the bound of memory.
But mips returns EINVAL.
https://github.com/torvalds/linux/blob/bab5c80b211035739997ebd361a679fa85b39465/arch/mips/mm/mmap.c#L69
-------part of code-------
if (flags & MAP_FIXED) {
/* Even MAP_FIXED mappings must reside within TASK_SIZE */
if (TASK_SIZE - len < addr)
return -EINVAL;
-------end------------------
So, can we change EINVAL to ENOMEM to follow POSIX standard?
--Hongzhi
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Question about mmap syscall and POSIX standard on mips arch 2018-10-18 3:26 Question about mmap syscall and POSIX standard on mips arch Hongzhi, Song @ 2018-10-18 4:32 ` Al Viro 2018-10-18 23:09 ` Paul Burton 0 siblings, 1 reply; 3+ messages in thread From: Al Viro @ 2018-10-18 4:32 UTC (permalink / raw) To: Hongzhi, Song; +Cc: linux-kernel, mm-commits, linux-mips, Ralf Baechle [mips folks Cc'd] On Thu, Oct 18, 2018 at 11:26:02AM +0800, Hongzhi, Song wrote: > Hi all, > > Ltp has a POSIX teatcase about mmap, 24-2.c. > > https://github.com/linux-test-project/ltp/blob/e816127e5d8efbff5ae53e9c2292fae22f36838b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c#L94 [basically, MAP_FIXED mmap with addr + len > TASK_SIZE fails with -EINVAL on mips and -ENOMEM elsewhere] > Under POSIX standard, the expected errno should be ENOMEM > > when the specific [addr+len] exceeds the bound of memory. The mmap() function may fail if: [EINVAL] The addr argument (if MAP_FIXED was specified) or off is not a multiple of the page size as returned by sysconf(), or is considered invalid by ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the implementation. ^^^^^^^^^^^^^^^^^^^ So that behaviour gets past POSIX. That part is mostly about the things like cache aliasing constraints, etc., but it leaves enough space to weasel out. Said that, this [ENOMEM] MAP_FIXED was specified, and the range [addr,addr+len) exceeds that allowed for the address space of a process; or, if MAP_FIXED was not specified and there is insufficient room in the address space to effect the mapping. is a lot more specific, so switching to -ENOMEM there might be a good idea, especially since on other architectures we do get -ENOMEM in that case, AFAICS. ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Question about mmap syscall and POSIX standard on mips arch 2018-10-18 4:32 ` Al Viro @ 2018-10-18 23:09 ` Paul Burton 0 siblings, 0 replies; 3+ messages in thread From: Paul Burton @ 2018-10-18 23:09 UTC (permalink / raw) To: Al Viro Cc: Hongzhi, Song, linux-kernel@vger.kernel.org, mm-commits@vger.kernel.org, linux-mips@linux-mips.org, Ralf Baechle Hi Al, On Thu, Oct 18, 2018 at 05:32:00AM +0100, Al Viro wrote: > [mips folks Cc'd] > > On Thu, Oct 18, 2018 at 11:26:02AM +0800, Hongzhi, Song wrote: > > Hi all, > > > > Ltp has a POSIX teatcase about mmap, 24-2.c. > > > > https://github.com/linux-test-project/ltp/blob/e816127e5d8efbff5ae53e9c2292fae22f36838b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c#L94 > > [basically, MAP_FIXED mmap with addr + len > TASK_SIZE fails with > -EINVAL on mips and -ENOMEM elsewhere] > > > Under POSIX standard, the expected errno should be ENOMEM > > > > when the specific [addr+len] exceeds the bound of memory. > > The mmap() function may fail if: > > [EINVAL] > The addr argument (if MAP_FIXED was specified) or off is not a multiple > of the page size as returned by sysconf(), or is considered invalid by > ^^^^^^^^^^^^^^^^^^^^^^^^^^^ > the implementation. > ^^^^^^^^^^^^^^^^^^^ > > So that behaviour gets past POSIX. That part is mostly about the > things like cache aliasing constraints, etc., but it leaves enough > space to weasel out. Said that, this > > [ENOMEM] > MAP_FIXED was specified, and the range [addr,addr+len) exceeds that allowed > for the address space of a process; or, if MAP_FIXED was not specified and > there is insufficient room in the address space to effect the mapping. > > is a lot more specific, so switching to -ENOMEM there might be a good idea, > especially since on other architectures we do get -ENOMEM in that case, > AFAICS. Thanks for the heads up - that does sound like reasonably clear non-compliance. I'll make a note to put together a patch & test it out, likely next week, if nobody submits one first. Thanks, Paul ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-10-18 23:09 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-10-18 3:26 Question about mmap syscall and POSIX standard on mips arch Hongzhi, Song 2018-10-18 4:32 ` Al Viro 2018-10-18 23:09 ` Paul Burton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).