[-next] KVM: selftests: Fix build error

Message ID 20230130124445.3476-1-yuehaibing@huawei.com
State New
Headers
Series [-next] KVM: selftests: Fix build error |

Commit Message

Yue Haibing Jan. 30, 2023, 12:44 p.m. UTC
  kvm selftests build fails with below info:

rseq_test.c:48:13: error: conflicting types for ‘sys_getcpu’; have ‘void(unsigned int *)’
   48 | static void sys_getcpu(unsigned *cpu)
      |             ^~~~~~~~~~
In file included from rseq_test.c:23:
../rseq/rseq.c:82:12: note: previous definition of ‘sys_getcpu’ with type ‘int(unsigned int *, unsigned int *)’
   82 | static int sys_getcpu(unsigned *cpu, unsigned *node)
      |            ^~~~~~~~~~

commit 66d42ac73fc6 ("KVM: selftests: Make rseq compatible with glibc-2.35")
has include "../rseq/rseq.c", and commit 99babd04b250 ("selftests/rseq: Implement rseq numa node id field selftest")
add sys_getcpu() implement, so use sys_getcpu in rseq/rseq.c to fix this.

Fixes: 99babd04b250 ("selftests/rseq: Implement rseq numa node id field selftest")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 tools/testing/selftests/kvm/rseq_test.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)
  

Comments

Mathieu Desnoyers Jan. 30, 2023, 3:50 p.m. UTC | #1
On 2023-01-30 07:44, YueHaibing wrote:
> kvm selftests build fails with below info:
> 
> rseq_test.c:48:13: error: conflicting types for ‘sys_getcpu’; have ‘void(unsigned int *)’
>     48 | static void sys_getcpu(unsigned *cpu)
>        |             ^~~~~~~~~~
> In file included from rseq_test.c:23:
> ../rseq/rseq.c:82:12: note: previous definition of ‘sys_getcpu’ with type ‘int(unsigned int *, unsigned int *)’
>     82 | static int sys_getcpu(unsigned *cpu, unsigned *node)
>        |            ^~~~~~~~~~
> 
> commit 66d42ac73fc6 ("KVM: selftests: Make rseq compatible with glibc-2.35")
> has include "../rseq/rseq.c", and commit 99babd04b250 ("selftests/rseq: Implement rseq numa node id field selftest")
> add sys_getcpu() implement, so use sys_getcpu in rseq/rseq.c to fix this.
> 
> Fixes: 99babd04b250 ("selftests/rseq: Implement rseq numa node id field selftest")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

Hi,

This patch replicates an already existing patch:

https://lore.kernel.org/all/20230106-fix-kvm-rseq-build-v1-1-b704d9831d02@kernel.org/

The original patch should be routed through the tip tree by Peter Zijlstra shortly.

Thanks,

Mathieu

> ---
>   tools/testing/selftests/kvm/rseq_test.c | 19 ++++++-------------
>   1 file changed, 6 insertions(+), 13 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/rseq_test.c b/tools/testing/selftests/kvm/rseq_test.c
> index 3045fdf9bdf5..69ff39aa2991 100644
> --- a/tools/testing/selftests/kvm/rseq_test.c
> +++ b/tools/testing/selftests/kvm/rseq_test.c
> @@ -41,18 +41,6 @@ static void guest_code(void)
>   		GUEST_SYNC(0);
>   }
>   
> -/*
> - * We have to perform direct system call for getcpu() because it's
> - * not available until glic 2.29.
> - */
> -static void sys_getcpu(unsigned *cpu)
> -{
> -	int r;
> -
> -	r = syscall(__NR_getcpu, cpu, NULL, NULL);
> -	TEST_ASSERT(!r, "getcpu failed, errno = %d (%s)", errno, strerror(errno));
> -}
> -
>   static int next_cpu(int cpu)
>   {
>   	/*
> @@ -249,7 +237,12 @@ int main(int argc, char *argv[])
>   			 * across the seq_cnt reads.
>   			 */
>   			smp_rmb();
> -			sys_getcpu(&cpu);
> +			/*
> +			 * We have to perform direct system call for getcpu() because it's
> +			 * not available until glic 2.29.
> +			 */
> +			r = sys_getcpu(&cpu, NULL);
> +			TEST_ASSERT(!r, "getcpu failed, errno = %d (%s)", errno, strerror(errno));
>   			rseq_cpu = rseq_current_cpu_raw();
>   			smp_rmb();
>   		} while (snapshot != atomic_read(&seq_cnt));
  

Patch

diff --git a/tools/testing/selftests/kvm/rseq_test.c b/tools/testing/selftests/kvm/rseq_test.c
index 3045fdf9bdf5..69ff39aa2991 100644
--- a/tools/testing/selftests/kvm/rseq_test.c
+++ b/tools/testing/selftests/kvm/rseq_test.c
@@ -41,18 +41,6 @@  static void guest_code(void)
 		GUEST_SYNC(0);
 }
 
-/*
- * We have to perform direct system call for getcpu() because it's
- * not available until glic 2.29.
- */
-static void sys_getcpu(unsigned *cpu)
-{
-	int r;
-
-	r = syscall(__NR_getcpu, cpu, NULL, NULL);
-	TEST_ASSERT(!r, "getcpu failed, errno = %d (%s)", errno, strerror(errno));
-}
-
 static int next_cpu(int cpu)
 {
 	/*
@@ -249,7 +237,12 @@  int main(int argc, char *argv[])
 			 * across the seq_cnt reads.
 			 */
 			smp_rmb();
-			sys_getcpu(&cpu);
+			/*
+			 * We have to perform direct system call for getcpu() because it's
+			 * not available until glic 2.29.
+			 */
+			r = sys_getcpu(&cpu, NULL);
+			TEST_ASSERT(!r, "getcpu failed, errno = %d (%s)", errno, strerror(errno));
 			rseq_cpu = rseq_current_cpu_raw();
 			smp_rmb();
 		} while (snapshot != atomic_read(&seq_cnt));