* [PATCH] selftests/vm: Fix map_hugetlb length used for testing read and write
@ 2020-02-06 8:42 Christophe Leroy
2020-02-15 6:49 ` Leonardo Bras
2020-02-27 17:03 ` Christophe Leroy
0 siblings, 2 replies; 4+ messages in thread
From: Christophe Leroy @ 2020-02-06 8:42 UTC (permalink / raw)
To: Michael Ellerman, Shuah Khan
Cc: linux-kernel, linuxppc-dev, linux-mm, linux-kselftest
Commit fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and
page size in map_hugetlb") added the possibility to change the size
of memory mapped for the test, but left the read and write test using
the default value. This is unnoticed when mapping a length greater
than the default one, but segfaults otherwise.
Fix read_bytes() and write_bytes() by giving them the real length.
Also fix the call to munmap().
Fixes: fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and page size in map_hugetlb")
Cc: stable@vger.kernel.org
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
tools/testing/selftests/vm/map_hugetlb.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/vm/map_hugetlb.c b/tools/testing/selftests/vm/map_hugetlb.c
index 5a2d7b8efc40..6af951900aa3 100644
--- a/tools/testing/selftests/vm/map_hugetlb.c
+++ b/tools/testing/selftests/vm/map_hugetlb.c
@@ -45,20 +45,20 @@ static void check_bytes(char *addr)
printf("First hex is %x\n", *((unsigned int *)addr));
}
-static void write_bytes(char *addr)
+static void write_bytes(char *addr, size_t length)
{
unsigned long i;
- for (i = 0; i < LENGTH; i++)
+ for (i = 0; i < length; i++)
*(addr + i) = (char)i;
}
-static int read_bytes(char *addr)
+static int read_bytes(char *addr, size_t length)
{
unsigned long i;
check_bytes(addr);
- for (i = 0; i < LENGTH; i++)
+ for (i = 0; i < length; i++)
if (*(addr + i) != (char)i) {
printf("Mismatch at %lu\n", i);
return 1;
@@ -96,11 +96,11 @@ int main(int argc, char **argv)
printf("Returned address is %p\n", addr);
check_bytes(addr);
- write_bytes(addr);
- ret = read_bytes(addr);
+ write_bytes(addr, length);
+ ret = read_bytes(addr, length);
/* munmap() length of MAP_HUGETLB memory must be hugepage aligned */
- if (munmap(addr, LENGTH)) {
+ if (munmap(addr, length)) {
perror("munmap");
exit(1);
}
--
2.25.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] selftests/vm: Fix map_hugetlb length used for testing read and write
2020-02-06 8:42 [PATCH] selftests/vm: Fix map_hugetlb length used for testing read and write Christophe Leroy
@ 2020-02-15 6:49 ` Leonardo Bras
2020-02-17 14:10 ` Leonardo Bras
2020-02-27 17:03 ` Christophe Leroy
1 sibling, 1 reply; 4+ messages in thread
From: Leonardo Bras @ 2020-02-15 6:49 UTC (permalink / raw)
To: Christophe Leroy, Michael Ellerman, Shuah Khan
Cc: linux-mm, linuxppc-dev, linux-kernel, linux-kselftest
[-- Attachment #1: Type: text/plain, Size: 2337 bytes --]
Hello Christophe, thank you for the patch.
On Thu, 2020-02-06 at 08:42 +0000, Christophe Leroy wrote:
> Commit fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and
> page size in map_hugetlb") added the possibility to change the size
> of memory mapped for the test, but left the read and write test using
> the default value. This is unnoticed when mapping a length greater
> than the default one, but segfaults otherwise.
>
> Fix read_bytes() and write_bytes() by giving them the real length.
>
> Also fix the call to munmap().
>
> Fixes: fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and page size in map_hugetlb")
> Cc: stable@vger.kernel.org
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> ---
> tools/testing/selftests/vm/map_hugetlb.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/vm/map_hugetlb.c b/tools/testing/selftests/vm/map_hugetlb.c
> index 5a2d7b8efc40..6af951900aa3 100644
> --- a/tools/testing/selftests/vm/map_hugetlb.c
> +++ b/tools/testing/selftests/vm/map_hugetlb.c
> @@ -45,20 +45,20 @@ static void check_bytes(char *addr)
> printf("First hex is %x\n", *((unsigned int *)addr));
> }
>
> -static void write_bytes(char *addr)
> +static void write_bytes(char *addr, size_t length)
> {
> unsigned long i;
>
> - for (i = 0; i < LENGTH; i++)
> + for (i = 0; i < length; i++)
> *(addr + i) = (char)i;
> }
>
> -static int read_bytes(char *addr)
> +static int read_bytes(char *addr, size_t length)
> {
> unsigned long i;
>
> check_bytes(addr);
> - for (i = 0; i < LENGTH; i++)
> + for (i = 0; i < length; i++)
> if (*(addr + i) != (char)i) {
> printf("Mismatch at %lu\n", i);
> return 1;
> @@ -96,11 +96,11 @@ int main(int argc, char **argv)
>
> printf("Returned address is %p\n", addr);
> check_bytes(addr);
> - write_bytes(addr);
> - ret = read_bytes(addr);
> + write_bytes(addr, length);
> + ret = read_bytes(addr, length);
>
> /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */
> - if (munmap(addr, LENGTH)) {
> + if (munmap(addr, length)) {
> perror("munmap");
> exit(1);
> }
I agree with you, it's a needed fix.
FWIW:
Reviwed-by: Leonardo Bras <leonardo@linux.ibm.com>
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] selftests/vm: Fix map_hugetlb length used for testing read and write
2020-02-15 6:49 ` Leonardo Bras
@ 2020-02-17 14:10 ` Leonardo Bras
0 siblings, 0 replies; 4+ messages in thread
From: Leonardo Bras @ 2020-02-17 14:10 UTC (permalink / raw)
To: Christophe Leroy, Michael Ellerman, Shuah Khan
Cc: linux-mm, linuxppc-dev, linux-kernel, linux-kselftest
[-- Attachment #1: Type: text/plain, Size: 2599 bytes --]
On Sat, 2020-02-15 at 03:49 -0300, Leonardo Bras wrote:
> Hello Christophe, thank you for the patch.
>
> On Thu, 2020-02-06 at 08:42 +0000, Christophe Leroy wrote:
> > Commit fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and
> > page size in map_hugetlb") added the possibility to change the size
> > of memory mapped for the test, but left the read and write test using
> > the default value. This is unnoticed when mapping a length greater
> > than the default one, but segfaults otherwise.
> >
> > Fix read_bytes() and write_bytes() by giving them the real length.
> >
> > Also fix the call to munmap().
> >
> > Fixes: fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and page size in map_hugetlb")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> > ---
> > tools/testing/selftests/vm/map_hugetlb.c | 14 +++++++-------
> > 1 file changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/tools/testing/selftests/vm/map_hugetlb.c b/tools/testing/selftests/vm/map_hugetlb.c
> > index 5a2d7b8efc40..6af951900aa3 100644
> > --- a/tools/testing/selftests/vm/map_hugetlb.c
> > +++ b/tools/testing/selftests/vm/map_hugetlb.c
> > @@ -45,20 +45,20 @@ static void check_bytes(char *addr)
> > printf("First hex is %x\n", *((unsigned int *)addr));
> > }
> >
> > -static void write_bytes(char *addr)
> > +static void write_bytes(char *addr, size_t length)
> > {
> > unsigned long i;
> >
> > - for (i = 0; i < LENGTH; i++)
> > + for (i = 0; i < length; i++)
> > *(addr + i) = (char)i;
> > }
> >
> > -static int read_bytes(char *addr)
> > +static int read_bytes(char *addr, size_t length)
> > {
> > unsigned long i;
> >
> > check_bytes(addr);
> > - for (i = 0; i < LENGTH; i++)
> > + for (i = 0; i < length; i++)
> > if (*(addr + i) != (char)i) {
> > printf("Mismatch at %lu\n", i);
> > return 1;
> > @@ -96,11 +96,11 @@ int main(int argc, char **argv)
> >
> > printf("Returned address is %p\n", addr);
> > check_bytes(addr);
> > - write_bytes(addr);
> > - ret = read_bytes(addr);
> > + write_bytes(addr, length);
> > + ret = read_bytes(addr, length);
> >
> > /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */
> > - if (munmap(addr, LENGTH)) {
> > + if (munmap(addr, length)) {
> > perror("munmap");
> > exit(1);
> > }
>
> I agree with you, it's a needed fix.
>
> FWIW:
> Reviwed-by: Leonardo Bras <leonardo@linux.ibm.com>
Sorry, typo.
Reviewed-by: Leonardo Bras <leonardo@linux.ibm.com>
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] selftests/vm: Fix map_hugetlb length used for testing read and write
2020-02-06 8:42 [PATCH] selftests/vm: Fix map_hugetlb length used for testing read and write Christophe Leroy
2020-02-15 6:49 ` Leonardo Bras
@ 2020-02-27 17:03 ` Christophe Leroy
1 sibling, 0 replies; 4+ messages in thread
From: Christophe Leroy @ 2020-02-27 17:03 UTC (permalink / raw)
To: Shuah Khan
Cc: Michael Ellerman, linux-mm, linuxppc-dev, linux-kernel, linux-kselftest
Shuah,
Le 06/02/2020 à 09:42, Christophe Leroy a écrit :
> Commit fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and
> page size in map_hugetlb") added the possibility to change the size
> of memory mapped for the test, but left the read and write test using
> the default value. This is unnoticed when mapping a length greater
> than the default one, but segfaults otherwise.
>
> Fix read_bytes() and write_bytes() by giving them the real length.
>
> Also fix the call to munmap().
>
> Fixes: fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and page size in map_hugetlb")
> Cc: stable@vger.kernel.org
Can you also consider this one for next rc ?
Thanks
Christophe
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> ---
> tools/testing/selftests/vm/map_hugetlb.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/vm/map_hugetlb.c b/tools/testing/selftests/vm/map_hugetlb.c
> index 5a2d7b8efc40..6af951900aa3 100644
> --- a/tools/testing/selftests/vm/map_hugetlb.c
> +++ b/tools/testing/selftests/vm/map_hugetlb.c
> @@ -45,20 +45,20 @@ static void check_bytes(char *addr)
> printf("First hex is %x\n", *((unsigned int *)addr));
> }
>
> -static void write_bytes(char *addr)
> +static void write_bytes(char *addr, size_t length)
> {
> unsigned long i;
>
> - for (i = 0; i < LENGTH; i++)
> + for (i = 0; i < length; i++)
> *(addr + i) = (char)i;
> }
>
> -static int read_bytes(char *addr)
> +static int read_bytes(char *addr, size_t length)
> {
> unsigned long i;
>
> check_bytes(addr);
> - for (i = 0; i < LENGTH; i++)
> + for (i = 0; i < length; i++)
> if (*(addr + i) != (char)i) {
> printf("Mismatch at %lu\n", i);
> return 1;
> @@ -96,11 +96,11 @@ int main(int argc, char **argv)
>
> printf("Returned address is %p\n", addr);
> check_bytes(addr);
> - write_bytes(addr);
> - ret = read_bytes(addr);
> + write_bytes(addr, length);
> + ret = read_bytes(addr, length);
>
> /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */
> - if (munmap(addr, LENGTH)) {
> + if (munmap(addr, length)) {
> perror("munmap");
> exit(1);
> }
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-02-27 17:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-06 8:42 [PATCH] selftests/vm: Fix map_hugetlb length used for testing read and write Christophe Leroy
2020-02-15 6:49 ` Leonardo Bras
2020-02-17 14:10 ` Leonardo Bras
2020-02-27 17:03 ` Christophe Leroy
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).