linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] userfaultfd/selftests: use swap() to make code cleaner
@ 2021-10-28 11:23 cgel.zte
  2021-10-28 13:13 ` Shuah Khan
  2022-01-31 23:00 ` Mike Kravetz
  0 siblings, 2 replies; 4+ messages in thread
From: cgel.zte @ 2021-10-28 11:23 UTC (permalink / raw)
  To: akpm
  Cc: shuah, linux-mm, linux-kselftest, linux-kernel, Changcheng Deng,
	Zeal Robot

From: Changcheng Deng <deng.changcheng@zte.com.cn>

Use swap() in order to make code cleaner. Issue found by coccinelle.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Changcheng Deng <deng.changcheng@zte.com.cn>
---
 tools/testing/selftests/vm/userfaultfd.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index 8a09057d2f22..41dfe6f4ebfb 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -1413,7 +1413,6 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize)
 static int userfaultfd_stress(void)
 {
 	void *area;
-	char *tmp_area;
 	unsigned long nr;
 	struct uffdio_register uffdio_register;
 	struct uffd_stats uffd_stats[nr_cpus];
@@ -1524,13 +1523,8 @@ static int userfaultfd_stress(void)
 					    count_verify[nr], nr);
 
 		/* prepare next bounce */
-		tmp_area = area_src;
-		area_src = area_dst;
-		area_dst = tmp_area;
-
-		tmp_area = area_src_alias;
-		area_src_alias = area_dst_alias;
-		area_dst_alias = tmp_area;
+		swap(area_src, area_dst);
+		swap(area_src_alias, area_dst_alias);
 
 		uffd_stats_report(uffd_stats, nr_cpus);
 	}
-- 
2.25.1


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

* Re: [PATCH] userfaultfd/selftests: use swap() to make code cleaner
  2021-10-28 11:23 [PATCH] userfaultfd/selftests: use swap() to make code cleaner cgel.zte
@ 2021-10-28 13:13 ` Shuah Khan
  2022-01-31 23:00 ` Mike Kravetz
  1 sibling, 0 replies; 4+ messages in thread
From: Shuah Khan @ 2021-10-28 13:13 UTC (permalink / raw)
  To: cgel.zte, akpm
  Cc: shuah, linux-mm, linux-kselftest, linux-kernel, Changcheng Deng,
	Zeal Robot, Shuah Khan

On 10/28/21 5:23 AM, cgel.zte@gmail.com wrote:
> From: Changcheng Deng <deng.changcheng@zte.com.cn>
> 
> Use swap() in order to make code cleaner. Issue found by coccinelle.

Please include the coccinelle log.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Changcheng Deng <deng.changcheng@zte.com.cn>
> ---
>   tools/testing/selftests/vm/userfaultfd.c | 10 ++--------
>   1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
> index 8a09057d2f22..41dfe6f4ebfb 100644
> --- a/tools/testing/selftests/vm/userfaultfd.c
> +++ b/tools/testing/selftests/vm/userfaultfd.c
> @@ -1413,7 +1413,6 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize)
>   static int userfaultfd_stress(void)
>   {
>   	void *area;
> -	char *tmp_area;
>   	unsigned long nr;
>   	struct uffdio_register uffdio_register;
>   	struct uffd_stats uffd_stats[nr_cpus];
> @@ -1524,13 +1523,8 @@ static int userfaultfd_stress(void)
>   					    count_verify[nr], nr);
>   
>   		/* prepare next bounce */
> -		tmp_area = area_src;
> -		area_src = area_dst;
> -		area_dst = tmp_area;
> -
> -		tmp_area = area_src_alias;
> -		area_src_alias = area_dst_alias;
> -		area_dst_alias = tmp_area;
> +		swap(area_src, area_dst);
> +		swap(area_src_alias, area_dst_alias);
>   
>   		uffd_stats_report(uffd_stats, nr_cpus);
>   	}
> 

thanks,
-- Shuah

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

* Re: [PATCH] userfaultfd/selftests: use swap() to make code cleaner
  2021-10-28 11:23 [PATCH] userfaultfd/selftests: use swap() to make code cleaner cgel.zte
  2021-10-28 13:13 ` Shuah Khan
@ 2022-01-31 23:00 ` Mike Kravetz
  2022-02-01  1:06   ` Mike Kravetz
  1 sibling, 1 reply; 4+ messages in thread
From: Mike Kravetz @ 2022-01-31 23:00 UTC (permalink / raw)
  To: cgel.zte, akpm
  Cc: shuah, linux-mm, linux-kselftest, linux-kernel, Changcheng Deng,
	Zeal Robot

On 10/28/21 04:23, cgel.zte@gmail.com wrote:
> From: Changcheng Deng <deng.changcheng@zte.com.cn>
> 
> Use swap() in order to make code cleaner. Issue found by coccinelle.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Changcheng Deng <deng.changcheng@zte.com.cn>
> ---
>  tools/testing/selftests/vm/userfaultfd.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
> index 8a09057d2f22..41dfe6f4ebfb 100644
> --- a/tools/testing/selftests/vm/userfaultfd.c
> +++ b/tools/testing/selftests/vm/userfaultfd.c
> @@ -1413,7 +1413,6 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize)
>  static int userfaultfd_stress(void)
>  {
>  	void *area;
> -	char *tmp_area;
>  	unsigned long nr;
>  	struct uffdio_register uffdio_register;
>  	struct uffd_stats uffd_stats[nr_cpus];
> @@ -1524,13 +1523,8 @@ static int userfaultfd_stress(void)
>  					    count_verify[nr], nr);
>  
>  		/* prepare next bounce */
> -		tmp_area = area_src;
> -		area_src = area_dst;
> -		area_dst = tmp_area;
> -
> -		tmp_area = area_src_alias;
> -		area_src_alias = area_dst_alias;
> -		area_dst_alias = tmp_area;
> +		swap(area_src, area_dst);
> +		swap(area_src_alias, area_dst_alias);
>  
>  		uffd_stats_report(uffd_stats, nr_cpus);
>  	}

Sorry for the late comment/question.

Where is the test supposed to get the definition of swap()?  When trying to
build, I get:

gcc -Wall -I ../../../../usr/include  -no-pie    userfaultfd.c -lrt -lpthread -o /home/mkravetz/tmp/linux-stable/tools/testing/selftests/vm/userfaultfd
userfaultfd.c: In function ‘userfaultfd_stress’:
userfaultfd.c:1530:3: warning: implicit declaration of function ‘swap’; did you mean ‘swab’? [-Wimplicit-function-declaration]
 1530 |   swap(area_src, area_dst);
      |   ^~~~
      |   swab
/usr/bin/ld: /tmp/ccPiwPM0.o: in function `userfaultfd_stress':
userfaultfd.c:(.text+0x4b6d): undefined reference to `swap'
/usr/bin/ld: userfaultfd.c:(.text+0x4b8b): undefined reference to `swap'
collect2: error: ld returned 1 exit status
make[1]: *** [../lib.mk:146: /home/mkravetz/tmp/linux-stable/tools/testing/selftests/vm/userfaultfd] Error 1

As far as I can see, swap is only defined in 'include/linux/minmax.h'.
However, that is not part of the user API and not available to the tests.
What am I missing?
--
Mike Kravetz

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

* Re: [PATCH] userfaultfd/selftests: use swap() to make code cleaner
  2022-01-31 23:00 ` Mike Kravetz
@ 2022-02-01  1:06   ` Mike Kravetz
  0 siblings, 0 replies; 4+ messages in thread
From: Mike Kravetz @ 2022-02-01  1:06 UTC (permalink / raw)
  To: cgel.zte, akpm
  Cc: shuah, linux-mm, linux-kselftest, linux-kernel, Changcheng Deng,
	Zeal Robot

On 1/31/22 15:00, Mike Kravetz wrote:
> On 10/28/21 04:23, cgel.zte@gmail.com wrote:
>> From: Changcheng Deng <deng.changcheng@zte.com.cn>
>>
>> Use swap() in order to make code cleaner. Issue found by coccinelle.
>>
>> Reported-by: Zeal Robot <zealci@zte.com.cn>
>> Signed-off-by: Changcheng Deng <deng.changcheng@zte.com.cn>
>> ---
>>  tools/testing/selftests/vm/userfaultfd.c | 10 ++--------
>>  1 file changed, 2 insertions(+), 8 deletions(-)
>>
>> diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
>> index 8a09057d2f22..41dfe6f4ebfb 100644
>> --- a/tools/testing/selftests/vm/userfaultfd.c
>> +++ b/tools/testing/selftests/vm/userfaultfd.c
>> @@ -1413,7 +1413,6 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize)
>>  static int userfaultfd_stress(void)
>>  {
>>  	void *area;
>> -	char *tmp_area;
>>  	unsigned long nr;
>>  	struct uffdio_register uffdio_register;
>>  	struct uffd_stats uffd_stats[nr_cpus];
>> @@ -1524,13 +1523,8 @@ static int userfaultfd_stress(void)
>>  					    count_verify[nr], nr);
>>  
>>  		/* prepare next bounce */
>> -		tmp_area = area_src;
>> -		area_src = area_dst;
>> -		area_dst = tmp_area;
>> -
>> -		tmp_area = area_src_alias;
>> -		area_src_alias = area_dst_alias;
>> -		area_dst_alias = tmp_area;
>> +		swap(area_src, area_dst);
>> +		swap(area_src_alias, area_dst_alias);
>>  
>>  		uffd_stats_report(uffd_stats, nr_cpus);
>>  	}
> 
> Sorry for the late comment/question.
> 
> Where is the test supposed to get the definition of swap()?  When trying to
> build, I get:
> 
> gcc -Wall -I ../../../../usr/include  -no-pie    userfaultfd.c -lrt -lpthread -o /home/mkravetz/tmp/linux-stable/tools/testing/selftests/vm/userfaultfd
> userfaultfd.c: In function ‘userfaultfd_stress’:
> userfaultfd.c:1530:3: warning: implicit declaration of function ‘swap’; did you mean ‘swab’? [-Wimplicit-function-declaration]
>  1530 |   swap(area_src, area_dst);
>       |   ^~~~
>       |   swab
> /usr/bin/ld: /tmp/ccPiwPM0.o: in function `userfaultfd_stress':
> userfaultfd.c:(.text+0x4b6d): undefined reference to `swap'
> /usr/bin/ld: userfaultfd.c:(.text+0x4b8b): undefined reference to `swap'
> collect2: error: ld returned 1 exit status
> make[1]: *** [../lib.mk:146: /home/mkravetz/tmp/linux-stable/tools/testing/selftests/vm/userfaultfd] Error 1
> 
> As far as I can see, swap is only defined in 'include/linux/minmax.h'.
> However, that is not part of the user API and not available to the tests.
> What am I missing?

Please disregard.

It was failing for me on v5.17-rc2, but I see it was fixed in linux-next
with commit "selftests: vm: remove dependecy from internal kernel macros".

Sorry for the noise,
-- 
Mike Kravetz

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

end of thread, other threads:[~2022-02-01  1:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-28 11:23 [PATCH] userfaultfd/selftests: use swap() to make code cleaner cgel.zte
2021-10-28 13:13 ` Shuah Khan
2022-01-31 23:00 ` Mike Kravetz
2022-02-01  1:06   ` Mike Kravetz

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).