]> Git Repo - linux.git/commitdiff
random: vDSO: minimize and simplify header includes
authorChristophe Leroy <[email protected]>
Tue, 27 Aug 2024 07:31:47 +0000 (09:31 +0200)
committerJason A. Donenfeld <[email protected]>
Fri, 13 Sep 2024 15:28:35 +0000 (17:28 +0200)
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
8165b57bca21 ("linux/const.h: Extract common header for vDSO") and
commit 8c59ab839f52 ("lib/vdso: Enable common headers").

On some architectures this results in missing PAGE_SIZE, as was
described by commit 8b3843ae3634 ("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 cffaefd15a8f ("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]>
arch/x86/include/asm/pvclock.h
include/asm-generic/unaligned.h
include/vdso/helpers.h
include/vdso/unaligned.h [new file with mode: 0644]
lib/vdso/getrandom.c

index 0c92db84469dbd5160c0676a0b482d98a3004d68..6e4f8fae3ce9e98c5c336e3d653f811b3f31326c 100644 (file)
@@ -5,6 +5,7 @@
 #include <asm/clocksource.h>
 #include <asm/pvclock-abi.h>
 
+struct timespec64;
 /* some helper functions for xen and kvm pv clock sources */
 u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src);
 u64 pvclock_clocksource_read_nowd(struct pvclock_vcpu_time_info *src);
index a84c64e5f11ece50583ec55f90bf4047b91b62f0..95acdd70b3b21a9f1d4863b17f2e09dad1145b91 100644 (file)
@@ -8,16 +8,7 @@
  */
 #include <linux/unaligned/packed_struct.h>
 #include <asm/byteorder.h>
-
-#define __get_unaligned_t(type, ptr) ({                                                \
-       const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);      \
-       __pptr->x;                                                              \
-})
-
-#define __put_unaligned_t(type, val, ptr) do {                                 \
-       struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);            \
-       __pptr->x = (val);                                                      \
-} while (0)
+#include <vdso/unaligned.h>
 
 #define get_unaligned(ptr)     __get_unaligned_t(typeof(*(ptr)), (ptr))
 #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
index 73501149439ddcf9735d5b1cccb90abefbf3e321..3ddb03bb05cbeefc110adf0e672c2cd68848a0ae 100644 (file)
@@ -4,6 +4,7 @@
 
 #ifndef __ASSEMBLY__
 
+#include <asm/barrier.h>
 #include <vdso/datapage.h>
 
 static __always_inline u32 vdso_read_begin(const struct vdso_data *vd)
diff --git a/include/vdso/unaligned.h b/include/vdso/unaligned.h
new file mode 100644 (file)
index 0000000..eee3d2a
--- /dev/null
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __VDSO_UNALIGNED_H
+#define __VDSO_UNALIGNED_H
+
+#define __get_unaligned_t(type, ptr) ({                                                \
+       const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);      \
+       __pptr->x;                                                              \
+})
+
+#define __put_unaligned_t(type, val, ptr) do {                                 \
+       struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);            \
+       __pptr->x = (val);                                                      \
+} while (0)
+
+#endif /* __VDSO_UNALIGNED_H */
index 1281fa3546c20fd16982da78fa6a4921f6c514ac..938ca539aaa64bc46280ef6dd17aa661126699eb 100644 (file)
@@ -4,15 +4,18 @@
  */
 
 #include <linux/array_size.h>
-#include <linux/cache.h>
-#include <linux/kernel.h>
-#include <linux/time64.h>
+#include <linux/minmax.h>
 #include <vdso/datapage.h>
 #include <vdso/getrandom.h>
+#include <vdso/unaligned.h>
 #include <asm/vdso/getrandom.h>
-#include <asm/vdso/vsyscall.h>
-#include <asm/unaligned.h>
 #include <uapi/linux/mman.h>
+#include <uapi/linux/random.h>
+
+#undef PAGE_SIZE
+#undef PAGE_MASK
+#define PAGE_SIZE (1UL << CONFIG_PAGE_SHIFT)
+#define PAGE_MASK (~(PAGE_SIZE - 1))
 
 #define MEMCPY_AND_ZERO_SRC(type, dst, src, len) do {                          \
        while (len >= sizeof(type)) {                                           \
This page took 0.082595 seconds and 4 git commands to generate.