All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] openposix: mmap/21-1: adjust the test to work with MAP_SHARED_VALIDATE
@ 2018-02-08 15:55 Stanislav Kholmanskikh
  2018-02-08 16:34 ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Stanislav Kholmanskikh @ 2018-02-08 15:55 UTC (permalink / raw)
  To: ltp

Linux commit 50a8e840d050 ("mm: introduce MAP_SHARED_VALIDATE, a mechanism to safely define new mmap flags")
introduced the MAP_SHARED_VALIDATE flag, which is similar to MAP_SHARED but
provides additional semantics. So on we need to make sure that the invalid
value of 'flags' in the test is generated taking into account this new flag.

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 .../conformance/interfaces/mmap/21-1.c             |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/21-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/21-1.c
index dc0cc13..81114b7 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/21-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/21-1.c
@@ -27,6 +27,24 @@
 #include <errno.h>
 #include "posixtest.h"
 
+int is_valid(int flag)
+{
+	if (flag == MAP_SHARED || flag == MAP_PRIVATE || flag == MAP_FIXED)
+		return 1;
+
+#ifdef __linux__
+
+#ifndef MAP_SHARED_VALIDATE
+#define MAP_SHARED_VALIDATE 0x03
+#endif
+
+	if (flag == MAP_SHARED_VALIDATE)
+		return 1;
+#endif
+
+	return 0;
+}
+
 int main(void)
 {
 	char tmpfname[256];
@@ -51,7 +69,7 @@ int main(void)
 	}
 
 	flag = MAP_SHARED;
-	while (flag == MAP_SHARED || flag == MAP_PRIVATE || flag == MAP_FIXED)
+	while (is_valid(flag))
 		flag++;
 
 	pa = mmap(NULL, size, PROT_READ | PROT_WRITE, flag, fd, 0);
-- 
1.7.1


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

* [LTP] [PATCH] openposix: mmap/21-1: adjust the test to work with MAP_SHARED_VALIDATE
  2018-02-08 15:55 [LTP] [PATCH] openposix: mmap/21-1: adjust the test to work with MAP_SHARED_VALIDATE Stanislav Kholmanskikh
@ 2018-02-08 16:34 ` Cyril Hrubis
  2018-02-12 12:29   ` Stanislav Kholmanskikh
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2018-02-08 16:34 UTC (permalink / raw)
  To: ltp

Hi!
> +int is_valid(int flag)
> +{
> +	if (flag == MAP_SHARED || flag == MAP_PRIVATE || flag == MAP_FIXED)
> +		return 1;
> +
> +#ifdef __linux__
> +
> +#ifndef MAP_SHARED_VALIDATE
> +#define MAP_SHARED_VALIDATE 0x03
> +#endif
> +
> +	if (flag == MAP_SHARED_VALIDATE)
> +		return 1;
> +#endif
> +
> +	return 0;
> +}

Hmm, this probably does not scale up, what about setting the flag to
have all its bits set (i.e. passing ~0 to the mmap()) from the start
instead?

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH] openposix: mmap/21-1: adjust the test to work with MAP_SHARED_VALIDATE
  2018-02-08 16:34 ` Cyril Hrubis
@ 2018-02-12 12:29   ` Stanislav Kholmanskikh
  2018-02-12 15:17     ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Stanislav Kholmanskikh @ 2018-02-12 12:29 UTC (permalink / raw)
  To: ltp

Hi.

On 02/08/2018 07:34 PM, Cyril Hrubis wrote:
> Hi!
>> +int is_valid(int flag)
>> +{
>> +	if (flag == MAP_SHARED || flag == MAP_PRIVATE || flag == MAP_FIXED)
>> +		return 1;
>> +
>> +#ifdef __linux__
>> +
>> +#ifndef MAP_SHARED_VALIDATE
>> +#define MAP_SHARED_VALIDATE 0x03
>> +#endif
>> +
>> +	if (flag == MAP_SHARED_VALIDATE)
>> +		return 1;
>> +#endif
>> +
>> +	return 0;
>> +}
> 
> Hmm, this probably does not scale up, what about setting the flag to
> have all its bits set (i.e. passing ~0 to the mmap()) from the start
> instead?
> 

In main() we search for the first value of 'flag' for which the
following statement is not true:

flag == MAP_SHARED || flag == MAP_PRIVATE || flag == MAP_FIXED || flag
== MAP_SHARED_VALIDATE

where the last part is Linux-specific and likely needs an #ifdef.

We are not interested if flag has MAP_SHARED or other bits set, but we
are interested when flag _equals_ MAP_SHARED or other values.

In order to make the code more readable (IMHO) I decided to move this
check into a separate function.

I don't fully understand your proposal. Could you, please, elaborate a
bit more?

Thanks.

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

* [LTP] [PATCH] openposix: mmap/21-1: adjust the test to work with MAP_SHARED_VALIDATE
  2018-02-12 12:29   ` Stanislav Kholmanskikh
@ 2018-02-12 15:17     ` Cyril Hrubis
  2018-03-01  9:22       ` [LTP] [PATCH] openposix: mmap/21-1: use all bits set as the invalid flag Stanislav Kholmanskikh
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2018-02-12 15:17 UTC (permalink / raw)
  To: ltp

Hi!
> >> +int is_valid(int flag)
> >> +{
> >> +	if (flag == MAP_SHARED || flag == MAP_PRIVATE || flag == MAP_FIXED)
> >> +		return 1;
> >> +
> >> +#ifdef __linux__
> >> +
> >> +#ifndef MAP_SHARED_VALIDATE
> >> +#define MAP_SHARED_VALIDATE 0x03
> >> +#endif
> >> +
> >> +	if (flag == MAP_SHARED_VALIDATE)
> >> +		return 1;
> >> +#endif
> >> +
> >> +	return 0;
> >> +}
> > 
> > Hmm, this probably does not scale up, what about setting the flag to
> > have all its bits set (i.e. passing ~0 to the mmap()) from the start
> > instead?
> > 
> 
> In main() we search for the first value of 'flag' for which the
> following statement is not true:
> 
> flag == MAP_SHARED || flag == MAP_PRIVATE || flag == MAP_FIXED || flag
> == MAP_SHARED_VALIDATE
> 
> where the last part is Linux-specific and likely needs an #ifdef.
> 
> We are not interested if flag has MAP_SHARED or other bits set, but we
> are interested when flag _equals_ MAP_SHARED or other values.
> 
> In order to make the code more readable (IMHO) I decided to move this
> check into a separate function.
> 
> I don't fully understand your proposal. Could you, please, elaborate a
> bit more?

We are trying to trigger EINVAL by passing an invalid flags value to
mmap. And given that the flags are likely to be allocated in increasing
manner starting with known flag and increasing it while it's equal to
other known flags will break again sooner or later and we will end up
adding more and more special cases for different systems.

Hence I suggest to use a value that is unlikely to be valid flag (all
bits set) and use that for the testing.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH] openposix: mmap/21-1: use all bits set as the invalid flag
  2018-02-12 15:17     ` Cyril Hrubis
@ 2018-03-01  9:22       ` Stanislav Kholmanskikh
  2018-03-01  9:50         ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Stanislav Kholmanskikh @ 2018-03-01  9:22 UTC (permalink / raw)
  To: ltp

The test is trying to trigger EINVAL by passing an invalid flags
value to mmap(). Linux commit 50a8e840d050 ("mm: introduce MAP_SHARED_VALIDATE, a mechanism to safely define new mmap flags")
introduced a new flag (MAP_SHARED_VALIDATE) and that flag may not be the last one.

So instead of adding an 'if' for each new flag we use a value with all bits
set (which is unlikely to be a valid flag).

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 .../conformance/interfaces/mmap/21-1.c             |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/21-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/21-1.c
index dc0cc13..ce636cf 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/21-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/21-1.c
@@ -33,7 +33,7 @@ int main(void)
 
 	void *pa;
 	size_t size = 1024;
-	int flag;
+	int flag = ~0;
 	int fd;
 
 	snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_21_1_%d", getpid());
@@ -50,10 +50,6 @@ int main(void)
 		return PTS_UNRESOLVED;
 	}
 
-	flag = MAP_SHARED;
-	while (flag == MAP_SHARED || flag == MAP_PRIVATE || flag == MAP_FIXED)
-		flag++;
-
 	pa = mmap(NULL, size, PROT_READ | PROT_WRITE, flag, fd, 0);
 	if (pa == MAP_FAILED && errno == EINVAL) {
 		printf("Test PASSED\n");
-- 
1.7.1


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

* [LTP] [PATCH] openposix: mmap/21-1: use all bits set as the invalid flag
  2018-03-01  9:22       ` [LTP] [PATCH] openposix: mmap/21-1: use all bits set as the invalid flag Stanislav Kholmanskikh
@ 2018-03-01  9:50         ` Cyril Hrubis
  2018-03-01 10:59           ` Stanislav Kholmanskikh
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2018-03-01  9:50 UTC (permalink / raw)
  To: ltp

Hi!
> The test is trying to trigger EINVAL by passing an invalid flags
> value to mmap(). Linux commit 50a8e840d050 ("mm: introduce MAP_SHARED_VALIDATE, a mechanism to safely define new mmap flags")
> introduced a new flag (MAP_SHARED_VALIDATE) and that flag may not be the last one.
> 
> So instead of adding an 'if' for each new flag we use a value with all bits
> set (which is unlikely to be a valid flag).

Acked, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH] openposix: mmap/21-1: use all bits set as the invalid flag
  2018-03-01  9:50         ` Cyril Hrubis
@ 2018-03-01 10:59           ` Stanislav Kholmanskikh
  0 siblings, 0 replies; 7+ messages in thread
From: Stanislav Kholmanskikh @ 2018-03-01 10:59 UTC (permalink / raw)
  To: ltp



On 03/01/2018 12:50 PM, Cyril Hrubis wrote:
> Hi!
>> The test is trying to trigger EINVAL by passing an invalid flags
>> value to mmap(). Linux commit 50a8e840d050 ("mm: introduce MAP_SHARED_VALIDATE, a mechanism to safely define new mmap flags")
>> introduced a new flag (MAP_SHARED_VALIDATE) and that flag may not be the last one.
>>
>> So instead of adding an 'if' for each new flag we use a value with all bits
>> set (which is unlikely to be a valid flag).
> 
> Acked, thanks.
> 
Thank you. Committed.

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

end of thread, other threads:[~2018-03-01 10:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-08 15:55 [LTP] [PATCH] openposix: mmap/21-1: adjust the test to work with MAP_SHARED_VALIDATE Stanislav Kholmanskikh
2018-02-08 16:34 ` Cyril Hrubis
2018-02-12 12:29   ` Stanislav Kholmanskikh
2018-02-12 15:17     ` Cyril Hrubis
2018-03-01  9:22       ` [LTP] [PATCH] openposix: mmap/21-1: use all bits set as the invalid flag Stanislav Kholmanskikh
2018-03-01  9:50         ` Cyril Hrubis
2018-03-01 10:59           ` Stanislav Kholmanskikh

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.