forked from mirrors/linux
Depending on the architecture, building a 32-bit vDSO on a 64-bit kernel
is problematic when some system headers are included.
Minimise the amount of headers by moving needed items, such as
__{get,put}_unaligned_t, into dedicated common headers and in general
use more specific headers, similar to what was done in commit
8165b57bca ("linux/const.h: Extract common header for vDSO") and
commit 8c59ab839f ("lib/vdso: Enable common headers").
On some architectures this results in missing PAGE_SIZE, as was
described by commit 8b3843ae36 ("vdso/datapage: Quick fix - use
asm/page-def.h for ARM64"), so define this if necessary, in the same way
as done prior by commit cffaefd15a ("vdso: Use CONFIG_PAGE_SHIFT in
vdso/datapage.h").
Removing linux/time64.h leads to missing 'struct timespec64' in
x86's asm/pvclock.h. Add a forward declaration of that struct in
that file.
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
57 lines
1.3 KiB
C
57 lines
1.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __VDSO_HELPERS_H
|
|
#define __VDSO_HELPERS_H
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
#include <asm/barrier.h>
|
|
#include <vdso/datapage.h>
|
|
|
|
static __always_inline u32 vdso_read_begin(const struct vdso_data *vd)
|
|
{
|
|
u32 seq;
|
|
|
|
while (unlikely((seq = READ_ONCE(vd->seq)) & 1))
|
|
cpu_relax();
|
|
|
|
smp_rmb();
|
|
return seq;
|
|
}
|
|
|
|
static __always_inline u32 vdso_read_retry(const struct vdso_data *vd,
|
|
u32 start)
|
|
{
|
|
u32 seq;
|
|
|
|
smp_rmb();
|
|
seq = READ_ONCE(vd->seq);
|
|
return seq != start;
|
|
}
|
|
|
|
static __always_inline void vdso_write_begin(struct vdso_data *vd)
|
|
{
|
|
/*
|
|
* WRITE_ONCE() is required otherwise the compiler can validly tear
|
|
* updates to vd[x].seq and it is possible that the value seen by the
|
|
* reader is inconsistent.
|
|
*/
|
|
WRITE_ONCE(vd[CS_HRES_COARSE].seq, vd[CS_HRES_COARSE].seq + 1);
|
|
WRITE_ONCE(vd[CS_RAW].seq, vd[CS_RAW].seq + 1);
|
|
smp_wmb();
|
|
}
|
|
|
|
static __always_inline void vdso_write_end(struct vdso_data *vd)
|
|
{
|
|
smp_wmb();
|
|
/*
|
|
* WRITE_ONCE() is required otherwise the compiler can validly tear
|
|
* updates to vd[x].seq and it is possible that the value seen by the
|
|
* reader is inconsistent.
|
|
*/
|
|
WRITE_ONCE(vd[CS_HRES_COARSE].seq, vd[CS_HRES_COARSE].seq + 1);
|
|
WRITE_ONCE(vd[CS_RAW].seq, vd[CS_RAW].seq + 1);
|
|
}
|
|
|
|
#endif /* !__ASSEMBLY__ */
|
|
|
|
#endif /* __VDSO_HELPERS_H */
|