proc: fix proc-self-map-files selftest for arm
Subsystems (3)
PATCH 1/1 proc: fix proc-self-map-files selftest for arm
MAP_FIXED is important for this test but, unfortunately, lowest virtual address for user space mapping on arm is (PAGE_SIZE * 2) and NULL hint does not seem to guarantee that when MAP_FIXED is given. This patch sets the virtual address that will hold the mapping for the test, fixing the issue.
--- tools/testing/selftests/proc/proc-self-map-files-002.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/proc/proc-self-map-files-002.c +3 -1
@@ -55,7 +55,9 @@ int main(void)if (fd ==-1 )return 1 ; - p =mmap (NULL ,PAGE_SIZE ,PROT_NONE ,MAP_PRIVATE |MAP_FILE |MAP_FIXED , fd,0 ); + p =mmap ((void *) (2 *PAGE_SIZE ),PAGE_SIZE ,PROT_NONE , +MAP_PRIVATE |MAP_FILE |MAP_FIXED , fd,0 ); +if (p ==MAP_FAILED ) {if (errno ==EPERM )return 2 ;
Signature · 1 line
2.19.1
Quoted 17 lines · Rafael David Tinoco
MAP_FIXEDis important for this test but, unfortunately, lowest virtual address for user space mapping on arm is (PAGE_SIZE* 2) and NULL hint does not seem to guarantee that whenMAP_FIXEDis given. This patch sets the virtual address that will hold the mapping for the test, fixing the issue.Signed-off-by Rafael David Tinoco <rafael.tinoco at linaro.org>--- tools/testing/selftests/proc/proc-self-map-files-002.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/testing/selftests/proc/proc-self-map-files-002.c +0
-0
tools/testing/selftests/proc/proc-self-map-files-002.c int main(void) · line 63
Quoted 10 lines
tools/testing/selftests/proc/proc-self-map-files-002.c +3
-1@@ -55,7 +55,9 @@ int main(void)if (fd ==-1 )return 1 ; - p =mmap (NULL ,PAGE_SIZE ,PROT_NONE ,MAP_PRIVATE |MAP_FILE |MAP_FIXED , fd,0 ); + p =mmap ((void *) (2 *PAGE_SIZE ),PAGE_SIZE ,PROT_NONE , +MAP_PRIVATE |MAP_FILE |MAP_FIXED , fd,0 ); +if (p ==MAP_FAILED ) {if (errno ==EPERM )return 2 ;
As far as I remember nil virtual address has been there only to be sure the vma allocated won't be merged with another vmas. Fore sure most of x86 standart application won't be using 8K address as well, so should do the trick I think.
(Strictlly speaking the test should be rather parsing own maps first and
find unused address instead but whatever :)
Quoted 17 lines · Rafael David Tinoco
MAP_FIXEDis important for this test but, unfortunately, lowest virtual address for user space mapping on arm is (PAGE_SIZE* 2) and NULL hint does not seem to guarantee that whenMAP_FIXEDis given. This patch sets the virtual address that will hold the mapping for the test, fixing the issue.Signed-off-by Rafael David Tinoco <rafael.tinoco at linaro.org>--- tools/testing/selftests/proc/proc-self-map-files-002.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/testing/selftests/proc/proc-self-map-files-002.c +0
-0
tools/testing/selftests/proc/proc-self-map-files-002.c int main(void) · line 59
Quoted 6 lines
tools/testing/selftests/proc/proc-self-map-files-002.c +2
-1@@ -55,7 +55,9 @@ int main(void)if (fd ==-1 )return 1 ; - p =mmap (NULL ,PAGE_SIZE ,PROT_NONE ,MAP_PRIVATE |MAP_FILE |MAP_FIXED , fd,0 ); + p =mmap ((void *) (2 *PAGE_SIZE ),PAGE_SIZE ,PROT_NONE , +MAP_PRIVATE |MAP_FILE |MAP_FIXED , fd,0 );
As the comment in the beginning says this test is specifically for addresss 0. Maybe it should be ifdeffed with __arm__ then.
Quoted 3 lines · Alexey Dobriyan
As the comment in the beginning says this test is specifically for addresss 0. Maybe it should be ifdeffed with
__arm__then.
Is there some other reason than allocating non-mergable VMA?
Quoted 6 lines · Cyrill Gorcunov
Quoted 3 lines · Alexey Dobriyan
As the comment in the beginning says this test is specifically for addresss 0. Maybe it should be ifdeffed with
__arm__then.Is there some other reason than allocating non-mergable VMA?
IIRC the reason is to test address 0 as it is effectively banned for userspace so if it will be broken, it will be broken silently for a long time.
As for "unmergeable" libc here doesn't map /dev/zero. I know how to avoid even theoretical breakage by creating binaries by hand but it will be probably too much.
Quoted 11 lines · Alexey Dobriyan
Quoted 6 lines · Cyrill Gorcunov
Quoted 3 lines · Alexey Dobriyan
As the comment in the beginning says this test is specifically for addresss 0. Maybe it should be ifdeffed with
__arm__then.Is there some other reason than allocating non-mergable VMA?
IIRC the reason is to test address 0 as it is effectively banned for userspace so if it will be broken, it will be broken silently for a long time.
This is rather a side effect of the test because the primary reason was to check procfs numbers conversion, right? Don't get me wrong, I don't mind about __arm__ define or similar, this is fine for one architecture, but if there comes more we will get a number of #ifdefs which is unrelated to procfs numeric routines at all.
Quoted 3 lines
As for "unmergeable" libc here doesn't map
/dev/zero. I know how to avoid even theoretical breakage by creating binaries by hand but it will be probably too much.
Sure.
Quoted 13 lines · Cyrill Gorcunov
Quoted 11 lines · Alexey Dobriyan
Quoted 6 lines · Cyrill Gorcunov
Quoted 3 lines · Alexey Dobriyan
As the comment in the beginning says this test is specifically for addresss 0. Maybe it should be ifdeffed with
__arm__then.Is there some other reason than allocating non-mergable VMA?
IIRC the reason is to test address 0 as it is effectively banned for userspace so if it will be broken, it will be broken silently for a long time.
Quoted 5 lines
This is rather a side effect of the test because the primary reason was to check procfs numbers conversion, right? Don't get me wrong, I don't mind about
__arm__define or similar, this is fine for one architecture, but if there comes more we will get a number of #ifdefs which is unrelated to procfs numeric routines at all.
That is what I also had in mind, thus the patch. I just realized we had another issue on LKFT (our functional tests tool) for proc-self-map-files-001.c. Test 001 does pretty much the same as 002, but without the MAP_FIXED mmap flag.
Is it okay to consolidate both tests into just 1, and focus in checking procfs numbers conversion only, rather than if mapping 0 is allowed or not ? Can I send a v2 with that in mind ?
Quoted 7 lines
Quoted 4 lines
As for "unmergeable" libc here doesn't map
/dev/zero. I know how to avoid even theoretical breakage by creating binaries by hand but it will be probably too much.Sure.
Quoted 8 lines · Rafael David Tinoco
That is what I also had in mind, thus the patch. I just realized we had another issue on LKFT (our functional tests tool) for
proc-self-map-files-001.c. Test 001 does pretty much the same as 002, but without theMAP_FIXEDmmap flag.Is it okay to consolidate both tests into just 1, and focus in checking procfs numbers conversion only, rather than if mapping 0 is allowed or not ? Can I send a v2 with that in mind ?
As to me -- yes, I would move zero page testing to a separate memory testcase. But since Alexey is the former author of the tests better wait for his opinion.
Quoted 6 lines · Cyrill Gorcunov
Quoted 5 lines · Rafael David Tinoco
That is what I also had in mind, thus the patch. I just realized we had another issue on LKFT (our functional tests tool) for
proc-self-map-files-001.c. Test 001 does pretty much the same as 002, but without theMAP_FIXEDmmap flag.
Quoted 6 lines
Quoted 3 lines
Is it okay to consolidate both tests into just 1, and focus in checking procfs numbers conversion only, rather than if mapping 0 is allowed or not ? Can I send a v2 with that in mind ?
As to me -- yes, I would move zero page testing to a separate memory testcase. But since Alexey is the former author of the tests better wait for his opinion.
Alexey,
would you care if we turn those 2 tests into 1, taking care of the zero page testing elsewhere ? Would you mind if I send out a patch for that ?
Quoted 9 lines · Rafael David Tinoco
Quoted 3 lines
As to me -- yes, I would move zero page testing to a separate memory testcase. But since Alexey is the former author of the tests better wait for his opinion.
Alexey,
would you care if we turn those 2 tests into 1, taking care of the zero page testing elsewhere ? Would you mind if I send out a patch for that ?
Rafael, just make it so. While we preserve old functionality I think it is fine.
Cyrill
PATCH 1/1 proc: fix and merge proc-self-map-file tests
Merge proc-self-map-files tests into one since this test should focus in testing readlink in /proc/self/map_files/* only, and not trying to test mapping virtual address 0.
Lowest virtual address for user space mapping in other architectures, like arm, is *at least* *(PAGE_SIZE * 2) and NULL hint does not guarantee that when MAP_FIXED flag, important to this test, is given. This patch also fixes this issue in remaining test.
--- tools/testing/selftests/proc/.gitignore | 1 - tools/testing/selftests/proc/Makefile | 1 - .../selftests/proc/proc-self-map-files-001.c | 5 +- .../selftests/proc/proc-self-map-files-002.c | 85 ------------------- 4 files changed, 3 insertions(+), 89 deletions(-) delete mode 100644 tools/testing/selftests/proc/proc-self-map-files-002.c
tools/testing/selftests/proc/.gitignore +0 -1
@@ -3,7 +3,6 @@ /fd-003-kthread /proc-loadavg-001 /proc-self-map-files-001 -/proc-self-map-files-002 /proc-self-syscall /proc-self-wchan /proc-uptime-001
tools/testing/selftests/proc/Makefile +0 -1
@@ -7,7 +7,6 @@ TEST_GEN_PROGS += fd-002-posix-eq TEST_GEN_PROGS += fd-003-kthread TEST_GEN_PROGS += proc-loadavg-001 TEST_GEN_PROGS += proc-self-map-files-001 -TEST_GEN_PROGS += proc-self-map-files-002 TEST_GEN_PROGS += proc-self-syscall TEST_GEN_PROGS += proc-self-wchan TEST_GEN_PROGS += proc-uptime-001
tools/testing/selftests/proc/proc-self-map-files-001.c +3 -2
@@ -46,16 +46,17 @@ static void fail(const char *fmt, unsigned long a, unsigned long b)int main (void ) { -const unsigned int PAGE_SIZE =sysconf (_SC_PAGESIZE);void *p;int fd;unsigned long a, b; +const long PAGE_SIZE =sysconf (_SC_PAGESIZE); fd =open ("/dev/zero" ,O_RDONLY );if (fd ==-1 )return 1 ; - p =mmap (NULL ,PAGE_SIZE ,PROT_NONE ,MAP_PRIVATE |MAP_FILE , fd,0 ); + p =mmap ((void *) (2 *PAGE_SIZE ),PAGE_SIZE ,PROT_NONE , +MAP_PRIVATE |MAP_FILE , fd,0 );if (p ==MAP_FAILED )return 1 ;
tools/testing/selftests/proc/proc-self-map-files-002.c deleted +0 -85
85 lines not on this page · raw message
Signature · 1 line
2.19.1
Re: [PATCH] proc: fix and merge proc-self-map-file tests
Quoted 11 lines · Rafael David Tinoco
Merge proc-self-map-files tests into one since this test should focus in testing readlink in
/proc/self/map_files/*only, and not trying to test mapping virtual address 0.Lowest virtual address for user space mapping in other architectures, like arm, is *at least* *(PAGE_SIZE * 2) and NULL hint does not guarantee that when
MAP_FIXEDflag, important to this test, is given. This patch also fixes this issue in remaining test.
Wait, Rafael. But we will loose the test of mapping virtual address 0 then. I though you would move testing of virtual address 0 into a separate testcase. I mean testing of first page was a positive side effect of the former Alexey's patch, so we definitely should keep it on x86 at least. Gimme some time I'll try to address it today evening or tomorrow. I think this way everybody will be
happy: procfs get passed on arm32 and x86 will still have first page testing.
Re: [PATCH] proc: fix and merge proc-self-map-file tests
Quoted 13 lines · Cyrill Gorcunov
Quoted 11 lines · Rafael David Tinoco
Merge proc-self-map-files tests into one since this test should focus in testing readlink in
/proc/self/map_files/*only, and not trying to test mapping virtual address 0.Lowest virtual address for user space mapping in other architectures, like arm, is *at least* *(PAGE_SIZE * 2) and NULL hint does not guarantee that when
MAP_FIXEDflag, important to this test, is given. This patch also fixes this issue in remaining test.Signed-off-by Rafael David Tinoco <rafael.tinoco at linaro.org>
Quoted 8 lines
Wait, Rafael. But we will loose the test of mapping virtual address 0 then. I though you would move testing of virtual address 0 into a separate testcase. I mean testing of first page was a positive side effect of the former Alexey's patch, so we definitely should keep it on x86 at least. Gimme some time I'll try to address it today evening or tomorrow. I think this way everybody will be
happy: procfs get passed on arm32 and x86 will still have first page testing.
Ohh, my understanding was that this was going to be addressed in some other test, like what you said.. I did not understand you wanted me to create a test for it altogether, my bad. I can do it if you want, let me know, pls.
Thanks!
Re: [PATCH] proc: fix and merge proc-self-map-file tests
On Fri, Nov 09, 2018@09:45:36AM -0200, Rafael David Tinoco wrote:
...
Quoted 7 lines
Quoted 3 lines
today evening or tomorrow. I think this way everybody will be
happy: procfs get passed on arm32 and x86 will still have first page testing.Ohh, my understanding was that this was going to be addressed in some other test, like what you said.. I did not understand you wanted me to create a test for it altogether, my bad. I can do it if you want, let me know, pls.
:-) I'll be able to create patch and test in about 10 hours, so feel free to beat me if you have time meanwhile.
Re: [PATCH] proc: fix and merge proc-self-map-file tests
Quoted 6 lines · Cyrill Gorcunov
On Fri, Nov 09, 2018 at 09:45:36AM -0200, Rafael David Tinoco wrote:
...Quoted 4 lines
Quoted 3 lines
today evening or tomorrow. I think this way everybody will be
happy: procfs get passed on arm32 and x86 will still have first page testing.
Quoted 6 lines
Quoted 3 lines
Ohh, my understanding was that this was going to be addressed in some other test, like what you said.. I did not understand you wanted me to create a test for it altogether, my bad. I can do it if you want, let me know, pls.
:-) I'll be able to create patch and test in about 10 hours, so feel free to beat me if you have time meanwhile.
Alright, I'm fixing membarrier_test before, so.. I guess we have a competition.. =o)
Re: [PATCH] proc: fix and merge proc-self-map-file tests
Quoted 2 lines · Rafael David Tinoco
Alright, I'm fixing
membarrier_testbefore, so.. I guess we have a competition.. =o)
Rafael, Alexey, what about simply wrap the test code with x86 and extend later with all archs which support zero address mapping?
--- tools/testing/selftests/proc/proc-self-map-files-002.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/testing/selftests/proc/proc-self-map-files-002.c +14 -0
@@ -23,6 +23,11 @@#include <sys/mman.h> #include <stdlib.h> +/* +* Should run on archs which support zero address mapping. +*/ +#if defined(__i386) || defined(__x86_64) +static void pass (const char *fmt,unsigned long a,unsigned long b) {char name[64 ];
@@ -83,3 +88,12 @@ int main(void) return 0; } + +#else + +int main (void ) +{ +return 0 ; +} + +#endif
Re: [PATCH] proc: fix and merge proc-self-map-file tests
Quoted 29 lines · Cyrill Gorcunov
Quoted 2 lines · Rafael David Tinoco
Alright, I'm fixing
membarrier_testbefore, so.. I guess we have a competition.. =o)Rafael, Alexey, what about simply wrap the test code with x86 and extend later with all archs which support zero address mapping?
--- tools/testing/selftests/proc/proc-self-map-files-002.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)Index:
linux-ml.git/tools/testing/selftests/proc/proc-self-map-files-002.c
===================================================================tools/testing/selftests/proc/proc-self-map-files-002.c +5
-0@@ -23,6 +23,11 @@#include <sys/mman.h> #include <stdlib.h> +/* +* Should run on archs which support zero address mapping. +*/ +#if defined(__i386) || defined(__x86_64) +static void pass (const char *fmt,unsigned long a,unsigned long b) {char name[64 ];@@ -83,3 +88,12 @@ int main(void)return 0 ;
tools/testing/selftests/proc/proc-self-map-files-002.c int main(void) · line 99
Quoted 10 lines
tools/testing/selftests/proc/proc-self-map-files-002.c +9
-0} + +#else + +int main (void ) +{ +return 0 ; +} + +#endif
let me see if I got this right.. the premise for this test is to have *at least* 2 vmas, so we can check if the symlink for the mem range, describing the mapped area, is correct in procfs files, correct ? if yes, then why to have a totally duplicated test... just to check if mmap(0, ... MAP_FIXED ...) would work ?
Wouldn't exist a better place to have such test ? like in tools/testing/selftests/vm/mmap-null.c or something like it ? genuine curiosity.. thinking i'm missing something about this test...
Re: [PATCH] proc: fix and merge proc-self-map-file tests
Quoted 9 lines · Rafael David Tinoco
let me see if I got this right.. the premise for this test is to have *at least* 2 vmas, so we can check if the symlink for the mem range, describing the mapped area, is correct in procfs files, correct ? if yes, then why to have a totally duplicated test... just to check if mmap(0, ...
MAP_FIXED...) would work ?Wouldn't exist a better place to have such test ? like in
tools/testing/selftests/vm/mmap-null.cor something like it ? genuine curiosity.. thinking i'm missing something about this test...
Ah, I happen to miss that they are identical except nil address. Then true, vm/ looks like more suitable place for that. Do you happen to know which exactly archs reserve first page (together with x86)?
Re: [PATCH] proc: fix and merge proc-self-map-file tests
In reply to Rafael David Tinocotools/testing/selftests/proc/proc-self-map-files-001.c static void fail(const char *fmt, unsigned long a, unsigned long b) · line 58
Quoted 11 lines · Rafael David Tinoco
Merge proc-self-map-files tests into one since this test should focus in testing readlink in
/proc/self/map_files/*only, and not trying to test mapping virtual address 0.Lowest virtual address for user space mapping in other architectures, like arm, is *at least* *(PAGE_SIZE * 2) and NULL hint does not guarantee that when
MAP_FIXEDflag, important to this test, is given. This patch also fixes this issue in remaining test.tools/testing/selftests/proc/proc-self-map-files-001.c +1
-1- p =mmap (NULL ,PAGE_SIZE ,PROT_NONE ,MAP_PRIVATE |MAP_FILE , fd,0 ); + p = mmap((void *) (2 * PAGE_SIZE), PAGE_SIZE, PROT_NONE,
I don't know ARM. Is this 2 page limitation a limitation of hardware or kernel's?
Re: [PATCH] proc: fix and merge proc-self-map-file tests
Quoted 10 lines · Alexey Dobriyan
Quoted 8 lines · Rafael David Tinoco
Merge proc-self-map-files tests into one since this test should focus in testing readlink in
/proc/self/map_files/*only, and not trying to test mapping virtual address 0.Lowest virtual address for user space mapping in other architectures, like arm, is *at least* *(PAGE_SIZE * 2) and NULL hint does not guarantee that when
MAP_FIXEDflag, important to this test, is given. This patch also fixes this issue in remaining test.
Quoted 5 lines
tools/testing/selftests/proc/proc-self-map-files-001.c static void fail(const char *fmt, unsigned long a, unsigned long b) · line 58
Quoted 2 lines
tools/testing/selftests/proc/proc-self-map-files-001.c +1
-1- p =mmap (NULL ,PAGE_SIZE ,PROT_NONE ,MAP_PRIVATE |MAP_FILE , fd,0 ); + p = mmap((void *) (2 * PAGE_SIZE), PAGE_SIZE, PROT_NONE,I don't know ARM. Is this 2 page limitation a limitation of hardware or kernel's?
Re: [PATCH] proc: fix and merge proc-self-map-file tests
Quoted 11 lines · Rafael David Tinoco
Quoted 10 lines · Alexey Dobriyan
Quoted 8 lines · Rafael David Tinoco
Merge proc-self-map-files tests into one since this test should focus in testing readlink in
/proc/self/map_files/*only, and not trying to test mapping virtual address 0.Lowest virtual address for user space mapping in other architectures, like arm, is *at least* *(PAGE_SIZE * 2) and NULL hint does not guarantee that when
MAP_FIXEDflag, important to this test, is given. This patch also fixes this issue in remaining test.
Quoted 8 lines
Quoted 5 lines
tools/testing/selftests/proc/proc-self-map-files-001.c static void fail(const char *fmt, unsigned long a, unsigned long b) · line 58
Quoted 2 lines
tools/testing/selftests/proc/proc-self-map-files-001.c +1
-1- p =mmap (NULL ,PAGE_SIZE ,PROT_NONE ,MAP_PRIVATE |MAP_FILE , fd,0 ); + p = mmap((void *) (2 * PAGE_SIZE), PAGE_SIZE, PROT_NONE,I don't know ARM. Is this 2 page limitation a limitation of hardware or kernel's?
Ahh. please test the path I've sent, I don't have arm install readily available.
Re: [PATCH] proc: fix and merge proc-self-map-file tests
Quoted 18 lines · Alexey Dobriyan
Quoted 17 lines · Rafael David Tinoco
Quoted 15 lines · Alexey Dobriyan
tools/testing/selftests/proc/proc-self-map-files-001.c static void fail(const char *fmt, unsigned long a, unsigned long b) · line 58
Quoted 11 lines · Rafael David Tinoco
Merge proc-self-map-files tests into one since this test should focus in testing readlink in
/proc/self/map_files/*only, and not trying to test mapping virtual address 0.Lowest virtual address for user space mapping in other architectures, like arm, is *at least* *(PAGE_SIZE * 2) and NULL hint does not guarantee that when
MAP_FIXEDflag, important to this test, is given. This patch also fixes this issue in remaining test.tools/testing/selftests/proc/proc-self-map-files-001.c +1
-1- p =mmap (NULL ,PAGE_SIZE ,PROT_NONE ,MAP_PRIVATE |MAP_FILE , fd,0 ); + p = mmap((void *) (2 * PAGE_SIZE), PAGE_SIZE, PROT_NONE,I don't know ARM. Is this 2 page limitation a limitation of hardware or kernel's?
Quoted 5 lines
Quoted 2 lines
Ahh. please test the path I've sent, I don't have arm install readily available.
I replied to your patch based on some of the discussion we had in this thread.
Thanks
Rafael
-
Rafael D. Tinoco
Linaro Kernel Validation Team