Skip to content

Commit b757959

Browse files
chleroyzx2c4
authored andcommitted
random: vDSO: add __arch_get_k_vdso_rng_data() helper for data page access
_vdso_data is specific to x86 and __arch_get_k_vdso_data() is provided so that all architectures can provide the requested pointer. Do the same with _vdso_rng_data, provide __arch_get_k_vdso_rng_data() and don't use x86 _vdso_rng_data directly. Until now vdso/vsyscall.h was only included by time/vsyscall.c but now it will also be included in char/random.c, leading to a duplicate declaration of _vdso_data and _vdso_rng_data. To fix this issue, move the declaration in a C file. vma.c looks like the most appropriate candidate. We don't need to replace the definitions in vsyscall.h by declarations as declarations are already in asm/vvar.h. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent 81c6896 commit b757959

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

arch/x86/entry/vdso/vma.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ struct vdso_data *arch_get_vdso_data(void *vvar_page)
3838
}
3939
#undef EMIT_VVAR
4040

41+
DEFINE_VVAR(struct vdso_data, _vdso_data);
42+
DEFINE_VVAR_SINGLE(struct vdso_rng_data, _vdso_rng_data);
43+
4144
unsigned int vclocks_used __read_mostly;
4245

4346
#if defined(CONFIG_X86_64)

arch/x86/include/asm/vdso/vsyscall.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#include <asm/vgtod.h>
1010
#include <asm/vvar.h>
1111

12-
DEFINE_VVAR(struct vdso_data, _vdso_data);
13-
DEFINE_VVAR_SINGLE(struct vdso_rng_data, _vdso_rng_data);
14-
1512
/*
1613
* Update the vDSO data page to keep in sync with kernel timekeeping.
1714
*/
@@ -22,6 +19,13 @@ struct vdso_data *__x86_get_k_vdso_data(void)
2219
}
2320
#define __arch_get_k_vdso_data __x86_get_k_vdso_data
2421

22+
static __always_inline
23+
struct vdso_rng_data *__x86_get_k_vdso_rng_data(void)
24+
{
25+
return &_vdso_rng_data;
26+
}
27+
#define __arch_get_k_vdso_rng_data __x86_get_k_vdso_rng_data
28+
2529
/* The asm-generic header needs to be included after the definitions above */
2630
#include <asm-generic/vdso/vsyscall.h>
2731

drivers/char/random.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#ifdef CONFIG_VDSO_GETRANDOM
6060
#include <vdso/getrandom.h>
6161
#include <vdso/datapage.h>
62+
#include <vdso/vsyscall.h>
6263
#endif
6364
#include <asm/archrandom.h>
6465
#include <asm/processor.h>
@@ -289,7 +290,7 @@ static void crng_reseed(struct work_struct *work)
289290
* because the vDSO side only checks whether the value changed, without
290291
* actually using or interpreting the value.
291292
*/
292-
smp_store_release((unsigned long *)&_vdso_rng_data.generation, next_gen + 1);
293+
smp_store_release((unsigned long *)&__arch_get_k_vdso_rng_data()->generation, next_gen + 1);
293294
#endif
294295
if (!static_branch_likely(&crng_is_ready))
295296
crng_init = CRNG_READY;
@@ -742,7 +743,7 @@ static void __cold _credit_init_bits(size_t bits)
742743
queue_work(system_unbound_wq, &set_ready);
743744
atomic_notifier_call_chain(&random_ready_notifier, 0, NULL);
744745
#ifdef CONFIG_VDSO_GETRANDOM
745-
WRITE_ONCE(_vdso_rng_data.is_ready, true);
746+
WRITE_ONCE(__arch_get_k_vdso_rng_data()->is_ready, true);
746747
#endif
747748
wake_up_interruptible(&crng_init_wait);
748749
kill_fasync(&fasync, SIGIO, POLL_IN);

0 commit comments

Comments
 (0)