All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips
@ 2018-10-24  2:36 Hongzhi.Song
  2018-10-29  7:42 ` Hongzhi, Song
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Hongzhi.Song @ 2018-10-24  2:36 UTC (permalink / raw)
  To: ltp

Mips will return EINVAL instead of ENOMEM as expected
if MAP_FIXED is set and the range of [addr + len) exceeds
TASK_SIZE.

Linux kernel code: arch/mips/mm/mmap.c
if (flags & MAP_FIXED) {
    /* Even MAP_FIXED mappings must reside within TASK_SIZE */
    if (TASK_SIZE - len < addr)
        return -EINVAL;

The POSIX specification says:
"If MAP_FIXED is set, mmap() may return MAP_FAILED and set errno to
[EINVAL]."
[http://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html]

So I think the mips kernel remains POSIX compliant.

Relax the condition and accept both ENOMEM and EINVAL
as expected outcome.

Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
---
 .../open_posix_testsuite/conformance/interfaces/mmap/24-2.c    | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
index de51d43..810e5c8 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
@@ -7,7 +7,7 @@
  * source tree.
  *
  * The mmap() function shall fail if:
- * [ENOMEM] MAP_FIXED was specified,
+ * [ENOMEM or EINVAL] 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.
@@ -15,7 +15,7 @@
  * Test Step:
  * 1. Map a shared memory object, with size exceeding the value get from
  *    rlim_cur of resource RLIMIT_AS, setting MAP_FIXED;
- * 3. Should get ENOMEM.
+ * 3. Should get ENOMEM or EINVAL.
  */
 
 #define _XOPEN_SOURCE 600
@@ -93,8 +93,8 @@ int main(void)
 	       (unsigned long)len);
 	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));
+	if (pa == MAP_FAILED && (errno == ENOMEM || errno == EINVAL)) {
+		printf("Got ENOMEM or EINVAL: %s\nTest PASSED\n", strerror(errno));
 		exit(PTS_PASS);
 	}
 
@@ -103,6 +103,6 @@ int main(void)
 	else
 		munmap(pa, len);
 	close(fd);
-	printf("Test Fail: Did not get ENOMEM as expected\n");
+	printf("Test Failed: Did not get ENOMEM or EINVAL as expected\n");
 	return PTS_FAIL;
 }
-- 
2.8.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips
  2018-10-24  2:36 [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips Hongzhi.Song
@ 2018-10-29  7:42 ` Hongzhi, Song
  2018-11-01  1:49 ` Hongzhi, Song
  2018-11-27 13:51 ` Cyril Hrubis
  2 siblings, 0 replies; 8+ messages in thread
From: Hongzhi, Song @ 2018-10-29  7:42 UTC (permalink / raw)
  To: ltp

Sorry, this is V2.

Kindly ping

--Hongzhi


On 10/24/2018 10:36 AM, Hongzhi.Song wrote:
> Mips will return EINVAL instead of ENOMEM as expected
> if MAP_FIXED is set and the range of [addr + len) exceeds
> TASK_SIZE.
>
> Linux kernel code: arch/mips/mm/mmap.c
> if (flags & MAP_FIXED) {
>      /* Even MAP_FIXED mappings must reside within TASK_SIZE */
>      if (TASK_SIZE - len < addr)
>          return -EINVAL;
>
> The POSIX specification says:
> "If MAP_FIXED is set, mmap() may return MAP_FAILED and set errno to
> [EINVAL]."
> [http://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html]
>
> So I think the mips kernel remains POSIX compliant.
>
> Relax the condition and accept both ENOMEM and EINVAL
> as expected outcome.
>
> Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
> ---
>   .../open_posix_testsuite/conformance/interfaces/mmap/24-2.c    | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
> index de51d43..810e5c8 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
> @@ -7,7 +7,7 @@
>    * source tree.
>    *
>    * The mmap() function shall fail if:
> - * [ENOMEM] MAP_FIXED was specified,
> + * [ENOMEM or EINVAL] 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.
> @@ -15,7 +15,7 @@
>    * Test Step:
>    * 1. Map a shared memory object, with size exceeding the value get from
>    *    rlim_cur of resource RLIMIT_AS, setting MAP_FIXED;
> - * 3. Should get ENOMEM.
> + * 3. Should get ENOMEM or EINVAL.
>    */
>   
>   #define _XOPEN_SOURCE 600
> @@ -93,8 +93,8 @@ int main(void)
>   	       (unsigned long)len);
>   	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));
> +	if (pa == MAP_FAILED && (errno == ENOMEM || errno == EINVAL)) {
> +		printf("Got ENOMEM or EINVAL: %s\nTest PASSED\n", strerror(errno));
>   		exit(PTS_PASS);
>   	}
>   
> @@ -103,6 +103,6 @@ int main(void)
>   	else
>   		munmap(pa, len);
>   	close(fd);
> -	printf("Test Fail: Did not get ENOMEM as expected\n");
> +	printf("Test Failed: Did not get ENOMEM or EINVAL as expected\n");
>   	return PTS_FAIL;
>   }


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips
  2018-10-24  2:36 [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips Hongzhi.Song
  2018-10-29  7:42 ` Hongzhi, Song
@ 2018-11-01  1:49 ` Hongzhi, Song
  2018-11-05  1:15   ` Hongzhi, Song
  2018-11-27 13:51 ` Cyril Hrubis
  2 siblings, 1 reply; 8+ messages in thread
From: Hongzhi, Song @ 2018-11-01  1:49 UTC (permalink / raw)
  To: ltp

Hi guys,

Referring to POSIX spec, the return values, EINVAL and ENOMEM,

are all right if MAP_FIXED is set. So I think Mips also keep to POSIX.


Please review this patch.


--Hongzhi


On 10/24/2018 10:36 AM, Hongzhi.Song wrote:
> Mips will return EINVAL instead of ENOMEM as expected
> if MAP_FIXED is set and the range of [addr + len) exceeds
> TASK_SIZE.
>
> Linux kernel code: arch/mips/mm/mmap.c
> if (flags & MAP_FIXED) {
>      /* Even MAP_FIXED mappings must reside within TASK_SIZE */
>      if (TASK_SIZE - len < addr)
>          return -EINVAL;
>
> The POSIX specification says:
> "If MAP_FIXED is set, mmap() may return MAP_FAILED and set errno to
> [EINVAL]."
> [http://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html]
>
> So I think the mips kernel remains POSIX compliant.
>
> Relax the condition and accept both ENOMEM and EINVAL
> as expected outcome.
>
> Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
> ---
>   .../open_posix_testsuite/conformance/interfaces/mmap/24-2.c    | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
> index de51d43..810e5c8 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
> @@ -7,7 +7,7 @@
>    * source tree.
>    *
>    * The mmap() function shall fail if:
> - * [ENOMEM] MAP_FIXED was specified,
> + * [ENOMEM or EINVAL] 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.
> @@ -15,7 +15,7 @@
>    * Test Step:
>    * 1. Map a shared memory object, with size exceeding the value get from
>    *    rlim_cur of resource RLIMIT_AS, setting MAP_FIXED;
> - * 3. Should get ENOMEM.
> + * 3. Should get ENOMEM or EINVAL.
>    */
>   
>   #define _XOPEN_SOURCE 600
> @@ -93,8 +93,8 @@ int main(void)
>   	       (unsigned long)len);
>   	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));
> +	if (pa == MAP_FAILED && (errno == ENOMEM || errno == EINVAL)) {
> +		printf("Got ENOMEM or EINVAL: %s\nTest PASSED\n", strerror(errno));
>   		exit(PTS_PASS);
>   	}
>   
> @@ -103,6 +103,6 @@ int main(void)
>   	else
>   		munmap(pa, len);
>   	close(fd);
> -	printf("Test Fail: Did not get ENOMEM as expected\n");
> +	printf("Test Failed: Did not get ENOMEM or EINVAL as expected\n");
>   	return PTS_FAIL;
>   }


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips
  2018-11-01  1:49 ` Hongzhi, Song
@ 2018-11-05  1:15   ` Hongzhi, Song
  2019-07-19  1:38     ` Hongzhi, Song
  0 siblings, 1 reply; 8+ messages in thread
From: Hongzhi, Song @ 2018-11-05  1:15 UTC (permalink / raw)
  To: ltp

Kindly ping

--Hongzhi


On 11/01/2018 09:49 AM, Hongzhi, Song wrote:
> Hi guys,
>
> Referring to POSIX spec, the return values, EINVAL and ENOMEM,
>
> are all right if MAP_FIXED is set. So I think Mips also keep to POSIX.
>
>
> Please review this patch.
>
>
> --Hongzhi
>
>
> On 10/24/2018 10:36 AM, Hongzhi.Song wrote:
>> Mips will return EINVAL instead of ENOMEM as expected
>> if MAP_FIXED is set and the range of [addr + len) exceeds
>> TASK_SIZE.
>>
>> Linux kernel code: arch/mips/mm/mmap.c
>> if (flags & MAP_FIXED) {
>>      /* Even MAP_FIXED mappings must reside within TASK_SIZE */
>>      if (TASK_SIZE - len < addr)
>>          return -EINVAL;
>>
>> The POSIX specification says:
>> "If MAP_FIXED is set, mmap() may return MAP_FAILED and set errno to
>> [EINVAL]."
>> [http://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html]
>>
>> So I think the mips kernel remains POSIX compliant.
>>
>> Relax the condition and accept both ENOMEM and EINVAL
>> as expected outcome.
>>
>> Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
>> ---
>>   .../open_posix_testsuite/conformance/interfaces/mmap/24-2.c | 10 
>> +++++-----
>>   1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git 
>> a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c 
>> b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
>> index de51d43..810e5c8 100644
>> --- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
>> +++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
>> @@ -7,7 +7,7 @@
>>    * source tree.
>>    *
>>    * The mmap() function shall fail if:
>> - * [ENOMEM] MAP_FIXED was specified,
>> + * [ENOMEM or EINVAL] 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.
>> @@ -15,7 +15,7 @@
>>    * Test Step:
>>    * 1. Map a shared memory object, with size exceeding the value get 
>> from
>>    *    rlim_cur of resource RLIMIT_AS, setting MAP_FIXED;
>> - * 3. Should get ENOMEM.
>> + * 3. Should get ENOMEM or EINVAL.
>>    */
>>     #define _XOPEN_SOURCE 600
>> @@ -93,8 +93,8 @@ int main(void)
>>              (unsigned long)len);
>>       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));
>> +    if (pa == MAP_FAILED && (errno == ENOMEM || errno == EINVAL)) {
>> +        printf("Got ENOMEM or EINVAL: %s\nTest PASSED\n", 
>> strerror(errno));
>>           exit(PTS_PASS);
>>       }
>>   @@ -103,6 +103,6 @@ int main(void)
>>       else
>>           munmap(pa, len);
>>       close(fd);
>> -    printf("Test Fail: Did not get ENOMEM as expected\n");
>> +    printf("Test Failed: Did not get ENOMEM or EINVAL as expected\n");
>>       return PTS_FAIL;
>>   }
>
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips
  2018-10-24  2:36 [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips Hongzhi.Song
  2018-10-29  7:42 ` Hongzhi, Song
  2018-11-01  1:49 ` Hongzhi, Song
@ 2018-11-27 13:51 ` Cyril Hrubis
  2019-07-24  8:11   ` Hongzhi, Song
  2 siblings, 1 reply; 8+ messages in thread
From: Cyril Hrubis @ 2018-11-27 13:51 UTC (permalink / raw)
  To: ltp

Hi!
First of all sorry for the late reply.

> Mips will return EINVAL instead of ENOMEM as expected
> if MAP_FIXED is set and the range of [addr + len) exceeds
> TASK_SIZE.
> 
> Linux kernel code: arch/mips/mm/mmap.c
> if (flags & MAP_FIXED) {
>     /* Even MAP_FIXED mappings must reside within TASK_SIZE */
>     if (TASK_SIZE - len < addr)
>         return -EINVAL;
> 
> The POSIX specification says:
> "If MAP_FIXED is set, mmap() may return MAP_FAILED and set errno to
> [EINVAL]."
> [http://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html]
> 
> So I think the mips kernel remains POSIX compliant.

There is a subtle difference between the ENOMEM and EINVAL error for
MAP_FIXED though.

If you look at POSIX specification terminology it says that 'shall'
defines mandatory features while 'may' describes optional features.

Which means that the MAP_FIXED returning ENOMEM for addresses above
TASK_SIZE is mandatory since it's defined in the shall fail list. And
that EINVAL is recomended to be used for other unsuitable address that
fit into the process address space but are not suitable for a different
reasons which could be mostly translated to hardware limits.

To sum it up, as far as I can tell mips is not POSIX confirmant here and
even if this is a very minor issue we shouldn't change the test here.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips
  2018-11-05  1:15   ` Hongzhi, Song
@ 2019-07-19  1:38     ` Hongzhi, Song
  2019-07-24  1:21       ` Hongzhi, Song
  0 siblings, 1 reply; 8+ messages in thread
From: Hongzhi, Song @ 2019-07-19  1:38 UTC (permalink / raw)
  To: ltp

ping.

There are some discussion for patch-v1 : 
https://lists.linux.it/pipermail/ltp/2018-October/009624.html

Thanks

--Hongzhi


On 11/5/18 9:15 AM, Hongzhi, Song wrote:
> Kindly ping
>
> --Hongzhi
>
>
> On 11/01/2018 09:49 AM, Hongzhi, Song wrote:
>> Hi guys,
>>
>> Referring to POSIX spec, the return values, EINVAL and ENOMEM,
>>
>> are all right if MAP_FIXED is set. So I think Mips also keep to POSIX.
>>
>>
>> Please review this patch.
>>
>>
>> --Hongzhi
>>
>>
>> On 10/24/2018 10:36 AM, Hongzhi.Song wrote:
>>> Mips will return EINVAL instead of ENOMEM as expected
>>> if MAP_FIXED is set and the range of [addr + len) exceeds
>>> TASK_SIZE.
>>>
>>> Linux kernel code: arch/mips/mm/mmap.c
>>> if (flags & MAP_FIXED) {
>>> ???? /* Even MAP_FIXED mappings must reside within TASK_SIZE */
>>> ???? if (TASK_SIZE - len < addr)
>>> ???????? return -EINVAL;
>>>
>>> The POSIX specification says:
>>> "If MAP_FIXED is set, mmap() may return MAP_FAILED and set errno to
>>> [EINVAL]."
>>> [http://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html]
>>>
>>> So I think the mips kernel remains POSIX compliant.
>>>
>>> Relax the condition and accept both ENOMEM and EINVAL
>>> as expected outcome.
>>>
>>> Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
>>> ---
>>> ? .../open_posix_testsuite/conformance/interfaces/mmap/24-2.c | 10 
>>> +++++-----
>>> ? 1 file changed, 5 insertions(+), 5 deletions(-)
>>>
>>> diff --git 
>>> a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c 
>>> b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
>>> index de51d43..810e5c8 100644
>>> --- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
>>> +++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
>>> @@ -7,7 +7,7 @@
>>> ?? * source tree.
>>> ?? *
>>> ?? * The mmap() function shall fail if:
>>> - * [ENOMEM] MAP_FIXED was specified,
>>> + * [ENOMEM or EINVAL] 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.
>>> @@ -15,7 +15,7 @@
>>> ?? * Test Step:
>>> ?? * 1. Map a shared memory object, with size exceeding the value 
>>> get from
>>> ?? *??? rlim_cur of resource RLIMIT_AS, setting MAP_FIXED;
>>> - * 3. Should get ENOMEM.
>>> + * 3. Should get ENOMEM or EINVAL.
>>> ?? */
>>> ? ? #define _XOPEN_SOURCE 600
>>> @@ -93,8 +93,8 @@ int main(void)
>>> ???????????? (unsigned long)len);
>>> ????? 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));
>>> +??? if (pa == MAP_FAILED && (errno == ENOMEM || errno == EINVAL)) {
>>> +??????? printf("Got ENOMEM or EINVAL: %s\nTest PASSED\n", 
>>> strerror(errno));
>>> ????????? exit(PTS_PASS);
>>> ????? }
>>> ? @@ -103,6 +103,6 @@ int main(void)
>>> ????? else
>>> ????????? munmap(pa, len);
>>> ????? close(fd);
>>> -??? printf("Test Fail: Did not get ENOMEM as expected\n");
>>> +??? printf("Test Failed: Did not get ENOMEM or EINVAL as expected\n");
>>> ????? return PTS_FAIL;
>>> ? }
>>
>>
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips
  2019-07-19  1:38     ` Hongzhi, Song
@ 2019-07-24  1:21       ` Hongzhi, Song
  0 siblings, 0 replies; 8+ messages in thread
From: Hongzhi, Song @ 2019-07-24  1:21 UTC (permalink / raw)
  To: ltp

ping

--Hongzhi


On 7/19/19 9:38 AM, Hongzhi, Song wrote:
> ping.
>
> There are some discussion for patch-v1 : 
> https://lists.linux.it/pipermail/ltp/2018-October/009624.html
>
> Thanks
>
> --Hongzhi
>
>
> On 11/5/18 9:15 AM, Hongzhi, Song wrote:
>> Kindly ping
>>
>> --Hongzhi
>>
>>
>> On 11/01/2018 09:49 AM, Hongzhi, Song wrote:
>>> Hi guys,
>>>
>>> Referring to POSIX spec, the return values, EINVAL and ENOMEM,
>>>
>>> are all right if MAP_FIXED is set. So I think Mips also keep to POSIX.
>>>
>>>
>>> Please review this patch.
>>>
>>>
>>> --Hongzhi
>>>
>>>
>>> On 10/24/2018 10:36 AM, Hongzhi.Song wrote:
>>>> Mips will return EINVAL instead of ENOMEM as expected
>>>> if MAP_FIXED is set and the range of [addr + len) exceeds
>>>> TASK_SIZE.
>>>>
>>>> Linux kernel code: arch/mips/mm/mmap.c
>>>> if (flags & MAP_FIXED) {
>>>> ???? /* Even MAP_FIXED mappings must reside within TASK_SIZE */
>>>> ???? if (TASK_SIZE - len < addr)
>>>> ???????? return -EINVAL;
>>>>
>>>> The POSIX specification says:
>>>> "If MAP_FIXED is set, mmap() may return MAP_FAILED and set errno to
>>>> [EINVAL]."
>>>> [http://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html]
>>>>
>>>> So I think the mips kernel remains POSIX compliant.
>>>>
>>>> Relax the condition and accept both ENOMEM and EINVAL
>>>> as expected outcome.
>>>>
>>>> Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
>>>> ---
>>>> .../open_posix_testsuite/conformance/interfaces/mmap/24-2.c | 10 
>>>> +++++-----
>>>> ? 1 file changed, 5 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git 
>>>> a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c 
>>>> b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
>>>> index de51d43..810e5c8 100644
>>>> --- 
>>>> a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
>>>> +++ 
>>>> b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c
>>>> @@ -7,7 +7,7 @@
>>>> ?? * source tree.
>>>> ?? *
>>>> ?? * The mmap() function shall fail if:
>>>> - * [ENOMEM] MAP_FIXED was specified,
>>>> + * [ENOMEM or EINVAL] 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.
>>>> @@ -15,7 +15,7 @@
>>>> ?? * Test Step:
>>>> ?? * 1. Map a shared memory object, with size exceeding the value 
>>>> get from
>>>> ?? *??? rlim_cur of resource RLIMIT_AS, setting MAP_FIXED;
>>>> - * 3. Should get ENOMEM.
>>>> + * 3. Should get ENOMEM or EINVAL.
>>>> ?? */
>>>> ? ? #define _XOPEN_SOURCE 600
>>>> @@ -93,8 +93,8 @@ int main(void)
>>>> ???????????? (unsigned long)len);
>>>> ????? 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));
>>>> +??? if (pa == MAP_FAILED && (errno == ENOMEM || errno == EINVAL)) {
>>>> +??????? printf("Got ENOMEM or EINVAL: %s\nTest PASSED\n", 
>>>> strerror(errno));
>>>> ????????? exit(PTS_PASS);
>>>> ????? }
>>>> ? @@ -103,6 +103,6 @@ int main(void)
>>>> ????? else
>>>> ????????? munmap(pa, len);
>>>> ????? close(fd);
>>>> -??? printf("Test Fail: Did not get ENOMEM as expected\n");
>>>> +??? printf("Test Failed: Did not get ENOMEM or EINVAL as 
>>>> expected\n");
>>>> ????? return PTS_FAIL;
>>>> ? }
>>>
>>>
>>
>>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips
  2018-11-27 13:51 ` Cyril Hrubis
@ 2019-07-24  8:11   ` Hongzhi, Song
  0 siblings, 0 replies; 8+ messages in thread
From: Hongzhi, Song @ 2019-07-24  8:11 UTC (permalink / raw)
  To: ltp


On 11/27/18 9:51 PM, Cyril Hrubis wrote:
> Hi!
> First of all sorry for the late reply.
>
>> Mips will return EINVAL instead of ENOMEM as expected
>> if MAP_FIXED is set and the range of [addr + len) exceeds
>> TASK_SIZE.
>>
>> Linux kernel code: arch/mips/mm/mmap.c
>> if (flags & MAP_FIXED) {
>>      /* Even MAP_FIXED mappings must reside within TASK_SIZE */
>>      if (TASK_SIZE - len < addr)
>>          return -EINVAL;
>>
>> The POSIX specification says:
>> "If MAP_FIXED is set, mmap() may return MAP_FAILED and set errno to
>> [EINVAL]."
>> [http://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html]
>>
>> So I think the mips kernel remains POSIX compliant.
> There is a subtle difference between the ENOMEM and EINVAL error for
> MAP_FIXED though.
>
> If you look at POSIX specification terminology it says that 'shall'
> defines mandatory features while 'may' describes optional features.
>
> Which means that the MAP_FIXED returning ENOMEM for addresses above
> TASK_SIZE is mandatory since it's defined in the shall fail list. And
> that EINVAL is recomended to be used for other unsuitable address that
> fit into the process address space but are not suitable for a different
> reasons which could be mostly translated to hardware limits.
>
> To sum it up, as far as I can tell mips is not POSIX confirmant here and
> even if this is a very minor issue we shouldn't change the test here.
>

Sorry for my recent ping-emails, because I missed your reply.

I follow your final above conclusion.


--Hongzhi



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-07-24  8:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-24  2:36 [LTP] [PATCH] open_posix_testsuite/mmap24-2: Support mips Hongzhi.Song
2018-10-29  7:42 ` Hongzhi, Song
2018-11-01  1:49 ` Hongzhi, Song
2018-11-05  1:15   ` Hongzhi, Song
2019-07-19  1:38     ` Hongzhi, Song
2019-07-24  1:21       ` Hongzhi, Song
2018-11-27 13:51 ` Cyril Hrubis
2019-07-24  8:11   ` Hongzhi, Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.