Skip to content

Commit 7f05381

Browse files
chleroyzx2c4
authored andcommitted
random: vDSO: minimize and simplify header includes
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 8165b57 ("linux/const.h: Extract common header for vDSO") and commit 8c59ab8 ("lib/vdso: Enable common headers"). On some architectures this results in missing PAGE_SIZE, as was described by commit 8b3843a ("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 cffaefd ("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 <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent b7bad08 commit 7f05381

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

arch/x86/include/asm/pvclock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <asm/clocksource.h>
66
#include <asm/pvclock-abi.h>
77

8+
struct timespec64;
89
/* some helper functions for xen and kvm pv clock sources */
910
u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src);
1011
u64 pvclock_clocksource_read_nowd(struct pvclock_vcpu_time_info *src);

include/asm-generic/unaligned.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,7 @@
88
*/
99
#include <linux/unaligned/packed_struct.h>
1010
#include <asm/byteorder.h>
11-
12-
#define __get_unaligned_t(type, ptr) ({ \
13-
const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
14-
__pptr->x; \
15-
})
16-
17-
#define __put_unaligned_t(type, val, ptr) do { \
18-
struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
19-
__pptr->x = (val); \
20-
} while (0)
11+
#include <vdso/unaligned.h>
2112

2213
#define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
2314
#define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))

include/vdso/helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#ifndef __ASSEMBLY__
66

7+
#include <asm/barrier.h>
78
#include <vdso/datapage.h>
89

910
static __always_inline u32 vdso_read_begin(const struct vdso_data *vd)

include/vdso/unaligned.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __VDSO_UNALIGNED_H
3+
#define __VDSO_UNALIGNED_H
4+
5+
#define __get_unaligned_t(type, ptr) ({ \
6+
const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
7+
__pptr->x; \
8+
})
9+
10+
#define __put_unaligned_t(type, val, ptr) do { \
11+
struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
12+
__pptr->x = (val); \
13+
} while (0)
14+
15+
#endif /* __VDSO_UNALIGNED_H */

lib/vdso/getrandom.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
*/
55

66
#include <linux/array_size.h>
7-
#include <linux/cache.h>
8-
#include <linux/kernel.h>
9-
#include <linux/time64.h>
7+
#include <linux/minmax.h>
108
#include <vdso/datapage.h>
119
#include <vdso/getrandom.h>
10+
#include <vdso/unaligned.h>
1211
#include <asm/vdso/getrandom.h>
13-
#include <asm/vdso/vsyscall.h>
14-
#include <asm/unaligned.h>
1512
#include <uapi/linux/mman.h>
13+
#include <uapi/linux/random.h>
14+
15+
#undef PAGE_SIZE
16+
#undef PAGE_MASK
17+
#define PAGE_SIZE (1UL << CONFIG_PAGE_SHIFT)
18+
#define PAGE_MASK (~(PAGE_SIZE - 1))
1619

1720
#define MEMCPY_AND_ZERO_SRC(type, dst, src, len) do { \
1821
while (len >= sizeof(type)) { \

0 commit comments

Comments
 (0)