Skip to content

Commit dc32cb4

Browse files
t-8chKAGA-KOKO
authored andcommitted
LoongArch: vDSO: Use vdso/datapage.h to access vDSO data
vdso/datapage.h provides symbols and functions to ease the access to shared vDSO data from both the kernel and the vDSO. Make use of it to simplify the current code and also prepare for further changes unifying the vDSO data storage between architectures. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent 2bb7947 commit dc32cb4

File tree

6 files changed

+21
-23
lines changed

6 files changed

+21
-23
lines changed

arch/loongarch/include/asm/vdso/getrandom.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ static __always_inline ssize_t getrandom_syscall(void *_buffer, size_t _len, uns
3030

3131
static __always_inline const struct vdso_rng_data *__arch_get_vdso_rng_data(void)
3232
{
33-
return (const struct vdso_rng_data *)(get_vdso_data() + VVAR_LOONGARCH_PAGES_START *
34-
PAGE_SIZE + offsetof(struct loongarch_vdso_data, rng_data));
33+
return &_loongarch_data.rng_data;
3534
}
3635

3736
#endif /* !__ASSEMBLY__ */

arch/loongarch/include/asm/vdso/gettimeofday.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ static inline bool loongarch_vdso_hres_capable(void)
9191

9292
static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
9393
{
94-
return (const struct vdso_data *)get_vdso_data();
94+
return _vdso_data;
9595
}
9696

9797
#ifdef CONFIG_TIME_NS
9898
static __always_inline
9999
const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd)
100100
{
101-
return (const struct vdso_data *)(get_vdso_data() + VVAR_TIMENS_PAGE_OFFSET * PAGE_SIZE);
101+
return _timens_data;
102102
}
103103
#endif
104104
#endif /* !__ASSEMBLY__ */

arch/loongarch/include/asm/vdso/vdso.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,7 @@ enum vvar_pages {
4848

4949
#define VVAR_SIZE (VVAR_NR_PAGES << PAGE_SHIFT)
5050

51-
static inline unsigned long get_vdso_base(void)
52-
{
53-
unsigned long addr;
54-
55-
__asm__(
56-
" la.pcrel %0, _start\n"
57-
: "=r" (addr)
58-
:
59-
:);
60-
61-
return addr;
62-
}
63-
64-
static inline unsigned long get_vdso_data(void)
65-
{
66-
return get_vdso_base() - VVAR_SIZE;
67-
}
51+
extern struct loongarch_vdso_data _loongarch_data __attribute__((visibility("hidden")));
6852

6953
#endif /* __ASSEMBLY__ */
7054

arch/loongarch/kernel/asm-offsets.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <asm/ptrace.h>
1515
#include <asm/processor.h>
1616
#include <asm/ftrace.h>
17+
#include <vdso/datapage.h>
1718

1819
static void __used output_ptreg_defines(void)
1920
{
@@ -321,3 +322,11 @@ static void __used output_kvm_defines(void)
321322
OFFSET(KVM_GPGD, kvm, arch.pgd);
322323
BLANK();
323324
}
325+
326+
static void __used output_vdso_defines(void)
327+
{
328+
COMMENT("LoongArch vDSO offsets.");
329+
330+
DEFINE(__VVAR_PAGES, VVAR_NR_PAGES);
331+
BLANK();
332+
}

arch/loongarch/vdso/vdso.lds.S

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
* Author: Huacai Chen <[email protected]>
44
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
55
*/
6+
#include <asm/page.h>
7+
#include <generated/asm-offsets.h>
68

79
OUTPUT_FORMAT("elf64-loongarch", "elf64-loongarch", "elf64-loongarch")
810

911
OUTPUT_ARCH(loongarch)
1012

1113
SECTIONS
1214
{
13-
PROVIDE(_start = .);
15+
PROVIDE(_vdso_data = . - __VVAR_PAGES * PAGE_SIZE);
16+
#ifdef CONFIG_TIME_NS
17+
PROVIDE(_timens_data = _vdso_data + PAGE_SIZE);
18+
#endif
19+
PROVIDE(_loongarch_data = _vdso_data + 2 * PAGE_SIZE);
1420
. = SIZEOF_HEADERS;
1521

1622
.hash : { *(.hash) } :text

arch/loongarch/vdso/vgetcpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static __always_inline int read_cpu_id(void)
2121

2222
static __always_inline const struct vdso_pcpu_data *get_pcpu_data(void)
2323
{
24-
return (struct vdso_pcpu_data *)(get_vdso_data() + VVAR_LOONGARCH_PAGES_START * PAGE_SIZE);
24+
return _loongarch_data.pdata;
2525
}
2626

2727
extern

0 commit comments

Comments
 (0)