diff mbox series

[v2,16/17] selftests: vdso: Make VDSO function call more generic

Message ID bd05c8faee64972a9e01f9497d1870dc267a55f4.1724309198.git.christophe.leroy@csgroup.eu (mailing list archive)
State Superseded
Headers show
Series Wire up getrandom() vDSO implementation on powerpc | expand

Commit Message

Christophe Leroy Aug. 22, 2024, 7:13 a.m. UTC
On powerpc, a call to a VDSO function is not a standard C function
call. Unlike x86 that returns a negated error code in case of an
error, powerpc sets CR[SO] and returns the error code as a
positive value.

So use a macro called VDSO_CALL() which takes a pointer to the
function to call, the number of arguments and the arguments.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 tools/testing/selftests/vDSO/vdso_call.h           | 12 ++++++++++++
 tools/testing/selftests/vDSO/vdso_test_getrandom.c |  3 ++-
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/vDSO/vdso_call.h

Comments

Jason A. Donenfeld Aug. 26, 2024, 7:37 a.m. UTC | #1
On Thu, Aug 22, 2024 at 09:13:24AM +0200, Christophe Leroy wrote:
> On powerpc, a call to a VDSO function is not a standard C function
> call. Unlike x86 that returns a negated error code in case of an
> error, powerpc sets CR[SO] and returns the error code as a
> positive value.
> 
> So use a macro called VDSO_CALL() which takes a pointer to the
> function to call, the number of arguments and the arguments.
 
You'll probably want to move to VDSO_CALL() for the whole test suite,
not just the getrandom one, right?
LEROY Christophe Aug. 26, 2024, 7:48 a.m. UTC | #2
Le 26/08/2024 à 09:37, Jason A. Donenfeld a écrit :
> On Thu, Aug 22, 2024 at 09:13:24AM +0200, Christophe Leroy wrote:
>> On powerpc, a call to a VDSO function is not a standard C function
>> call. Unlike x86 that returns a negated error code in case of an
>> error, powerpc sets CR[SO] and returns the error code as a
>> positive value.
>>
>> So use a macro called VDSO_CALL() which takes a pointer to the
>> function to call, the number of arguments and the arguments.
>   
> You'll probably want to move to VDSO_CALL() for the whole test suite,
> not just the getrandom one, right?

Yes indeed, the following needs it as well:

vdso_test_abi.c
vdso_test_getcpu.c
vdso_test_gettimeofday.c
vdso_test_correctness.c

Christophe
diff mbox series

Patch

diff --git a/tools/testing/selftests/vDSO/vdso_call.h b/tools/testing/selftests/vDSO/vdso_call.h
new file mode 100644
index 000000000000..ca5db2220925
--- /dev/null
+++ b/tools/testing/selftests/vDSO/vdso_call.h
@@ -0,0 +1,12 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Macro to call vDSO functions
+ *
+ * Copyright (C) 2024 Christophe Leroy <christophe.leroy@csgroup.eu>, CS GROUP France
+ */
+#ifndef __VDSO_CALL_H__
+#define __VDSO_CALL_H__
+
+#define VDSO_CALL(fn, nr, args...)	fn(args)
+
+#endif
diff --git a/tools/testing/selftests/vDSO/vdso_test_getrandom.c b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
index 02bcffc23e0c..16ad400721c3 100644
--- a/tools/testing/selftests/vDSO/vdso_test_getrandom.c
+++ b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
@@ -22,6 +22,7 @@ 
 #include "../kselftest.h"
 #include "parse_vdso.h"
 #include "vdso_config.h"
+#include "vdso_call.h"
 
 #ifndef timespecsub
 #define	timespecsub(tsp, usp, vsp)					\
@@ -147,7 +148,7 @@  static ssize_t vgetrandom(void *buf, size_t len, unsigned long flags)
 			exit(KSFT_FAIL);
 		}
 	}
-	return grnd_ctx.fn(buf, len, flags, state, grnd_ctx.params.size_of_opaque_state);
+	return VDSO_CALL(grnd_ctx.fn, 5, buf, len, flags, state, grnd_ctx.params.size_of_opaque_state);
 }
 
 enum { TRIALS = 25000000, THREADS = 256 };