Message ID | 04d1de23a2ff14e2709edd8b75e27b81d703bc57.1724309198.git.christophe.leroy@csgroup.eu (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Wire up getrandom() vDSO implementation on powerpc | expand |
On Thu, Aug 22, 2024 at 09:13:22AM +0200, Christophe Leroy wrote: > Don't hard-code x86 specific names, use vdso_config definitions > to find the correct function matching the architecture. > > Add random VDSO function names in names[][]. Remove the #ifdef > CONFIG_VDSO32, having the name there all the time is harmless > and guaranties a steady index for following strings. This is indeed the right way of doing it. Thanks. I'll take this now, though with one small fixup: > + const char *version = versions[VDSO_VERSION]; > + const char **name = (const char **)&names[VDSO_NAMES]; I'll just do: const char *name = names[VDSO_NAMES][6]; Instead of referring to name[6] everywhere after. Seems more straight forward. Jason
Le 26/08/2024 à 09:28, Jason A. Donenfeld a écrit : > On Thu, Aug 22, 2024 at 09:13:22AM +0200, Christophe Leroy wrote: >> Don't hard-code x86 specific names, use vdso_config definitions >> to find the correct function matching the architecture. >> >> Add random VDSO function names in names[][]. Remove the #ifdef >> CONFIG_VDSO32, having the name there all the time is harmless >> and guaranties a steady index for following strings. > > This is indeed the right way of doing it. Thanks. I'll take this now, > though with one small fixup: > >> + const char *version = versions[VDSO_VERSION]; >> + const char **name = (const char **)&names[VDSO_NAMES]; > > I'll just do: > > const char *name = names[VDSO_NAMES][6]; > > Instead of referring to name[6] everywhere after. Seems more straight > forward. Yes you are right that's more straight forward when using only one of the names. I copy-pasted it from the gettimeofday test which uses several names from the table. Christophe
diff --git a/tools/testing/selftests/vDSO/vdso_config.h b/tools/testing/selftests/vDSO/vdso_config.h index 00bfed6e4922..740ce8c98d2e 100644 --- a/tools/testing/selftests/vDSO/vdso_config.h +++ b/tools/testing/selftests/vDSO/vdso_config.h @@ -68,16 +68,15 @@ static const char *versions[7] = { "LINUX_5.10" }; -static const char *names[2][6] = { +static const char *names[2][7] = { { "__kernel_gettimeofday", "__kernel_clock_gettime", "__kernel_time", "__kernel_clock_getres", "__kernel_getcpu", -#if defined(VDSO_32BIT) "__kernel_clock_gettime64", -#endif + "__kernel_getrandom", }, { "__vdso_gettimeofday", @@ -85,9 +84,8 @@ static const char *names[2][6] = { "__vdso_time", "__vdso_clock_getres", "__vdso_getcpu", -#if defined(VDSO_32BIT) "__vdso_clock_gettime64", -#endif + "__vdso_getrandom", }, }; diff --git a/tools/testing/selftests/vDSO/vdso_test_getrandom.c b/tools/testing/selftests/vDSO/vdso_test_getrandom.c index 05122425a873..02bcffc23e0c 100644 --- a/tools/testing/selftests/vDSO/vdso_test_getrandom.c +++ b/tools/testing/selftests/vDSO/vdso_test_getrandom.c @@ -21,6 +21,7 @@ #include "../kselftest.h" #include "parse_vdso.h" +#include "vdso_config.h" #ifndef timespecsub #define timespecsub(tsp, usp, vsp) \ @@ -107,6 +108,9 @@ static void vgetrandom_put_state(void *state) static void vgetrandom_init(void) { + const char *version = versions[VDSO_VERSION]; + const char **name = (const char **)&names[VDSO_NAMES]; + if (pthread_key_create(&grnd_ctx.key, vgetrandom_put_state) != 0) return; unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR); @@ -115,9 +119,9 @@ static void vgetrandom_init(void) exit(KSFT_SKIP); } vdso_init_from_sysinfo_ehdr(sysinfo_ehdr); - grnd_ctx.fn = (__typeof__(grnd_ctx.fn))vdso_sym("LINUX_2.6", "__vdso_getrandom"); + grnd_ctx.fn = (__typeof__(grnd_ctx.fn))vdso_sym(version, name[6]); if (!grnd_ctx.fn) { - printf("__vdso_getrandom is missing!\n"); + printf("%s is missing!\n", name[6]); exit(KSFT_FAIL); } if (grnd_ctx.fn(NULL, 0, 0, &grnd_ctx.params, ~0UL) != 0) {
Don't hard-code x86 specific names, use vdso_config definitions to find the correct function matching the architecture. Add random VDSO function names in names[][]. Remove the #ifdef CONFIG_VDSO32, having the name there all the time is harmless and guaranties a steady index for following strings. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> --- tools/testing/selftests/vDSO/vdso_config.h | 8 +++----- tools/testing/selftests/vDSO/vdso_test_getrandom.c | 8 ++++++-- 2 files changed, 9 insertions(+), 7 deletions(-)