Skip to content

Commit 717478d

Browse files
committed
Merge tag 'riscv-for-linus-5.15-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - A pair of fixes (along with the necessory cleanup) to our VDSO, to avoid a locking during OOM and to prevent the text from overflowing into the data page - A fix to checksyscalls to teach it about our rv32 UABI - A fix to add clone3() to the rv32 UABI, which was pointed out by checksyscalls - A fix to properly flush the icache on the local CPU in addition to the remote CPUs * tag 'riscv-for-linus-5.15-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: checksyscalls: Unconditionally ignore fstat{,at}64 riscv: Flush current cpu icache before other cpus RISC-V: Include clone3() on rv32 riscv/vdso: make arch_setup_additional_pages wait for mmap_sem for write killable riscv/vdso: Move vdso data page up front riscv/vdso: Refactor asm/vdso.h
2 parents f84fc4e + 3ef6ca4 commit 717478d

File tree

8 files changed

+56
-31
lines changed

8 files changed

+56
-31
lines changed

arch/riscv/include/asm/syscall.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,5 @@ static inline int syscall_get_arch(struct task_struct *task)
8282
#endif
8383
}
8484

85+
asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, uintptr_t);
8586
#endif /* _ASM_RISCV_SYSCALL_H */

arch/riscv/include/asm/vdso.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@
1616
#ifdef CONFIG_MMU
1717

1818
#include <linux/types.h>
19-
#include <generated/vdso-offsets.h>
19+
/*
20+
* All systems with an MMU have a VDSO, but systems without an MMU don't
21+
* support shared libraries and therefor don't have one.
22+
*/
23+
#ifdef CONFIG_MMU
24+
25+
#define __VVAR_PAGES 1
2026

21-
#ifndef CONFIG_GENERIC_TIME_VSYSCALL
22-
struct vdso_data {
23-
};
24-
#endif
27+
#ifndef __ASSEMBLY__
28+
#include <generated/vdso-offsets.h>
2529

2630
#define VDSO_SYMBOL(base, name) \
2731
(void __user *)((unsigned long)(base) + __vdso_##name##_offset)
2832

2933
#endif /* CONFIG_MMU */
3034

31-
asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, uintptr_t);
35+
#endif /* !__ASSEMBLY__ */
36+
37+
#endif /* CONFIG_MMU */
3238

3339
#endif /* _ASM_RISCV_VDSO_H */

arch/riscv/include/uapi/asm/unistd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
#ifdef __LP64__
1919
#define __ARCH_WANT_NEW_STAT
2020
#define __ARCH_WANT_SET_GET_RLIMIT
21-
#define __ARCH_WANT_SYS_CLONE3
2221
#endif /* __LP64__ */
2322

23+
#define __ARCH_WANT_SYS_CLONE3
24+
2425
#include <asm-generic/unistd.h>
2526

2627
/*

arch/riscv/kernel/syscall_table.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <linux/linkage.h>
88
#include <linux/syscalls.h>
99
#include <asm-generic/syscalls.h>
10-
#include <asm/vdso.h>
1110
#include <asm/syscall.h>
1211

1312
#undef __SYSCALL

arch/riscv/kernel/vdso.c

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@
1212
#include <linux/binfmts.h>
1313
#include <linux/err.h>
1414
#include <asm/page.h>
15+
#include <asm/vdso.h>
16+
1517
#ifdef CONFIG_GENERIC_TIME_VSYSCALL
1618
#include <vdso/datapage.h>
1719
#else
18-
#include <asm/vdso.h>
20+
struct vdso_data {
21+
};
1922
#endif
2023

2124
extern char vdso_start[], vdso_end[];
2225

26+
enum vvar_pages {
27+
VVAR_DATA_PAGE_OFFSET,
28+
VVAR_NR_PAGES,
29+
};
30+
31+
#define VVAR_SIZE (VVAR_NR_PAGES << PAGE_SHIFT)
32+
2333
static unsigned int vdso_pages __ro_after_init;
2434
static struct page **vdso_pagelist __ro_after_init;
2535

@@ -38,7 +48,7 @@ static int __init vdso_init(void)
3848

3949
vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
4050
vdso_pagelist =
41-
kcalloc(vdso_pages + 1, sizeof(struct page *), GFP_KERNEL);
51+
kcalloc(vdso_pages + VVAR_NR_PAGES, sizeof(struct page *), GFP_KERNEL);
4252
if (unlikely(vdso_pagelist == NULL)) {
4353
pr_err("vdso: pagelist allocation failed\n");
4454
return -ENOMEM;
@@ -63,38 +73,41 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,
6373
unsigned long vdso_base, vdso_len;
6474
int ret;
6575

66-
vdso_len = (vdso_pages + 1) << PAGE_SHIFT;
76+
BUILD_BUG_ON(VVAR_NR_PAGES != __VVAR_PAGES);
77+
78+
vdso_len = (vdso_pages + VVAR_NR_PAGES) << PAGE_SHIFT;
79+
80+
if (mmap_write_lock_killable(mm))
81+
return -EINTR;
6782

68-
mmap_write_lock(mm);
6983
vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0);
7084
if (IS_ERR_VALUE(vdso_base)) {
7185
ret = vdso_base;
7286
goto end;
7387
}
7488

75-
/*
76-
* Put vDSO base into mm struct. We need to do this before calling
77-
* install_special_mapping or the perf counter mmap tracking code
78-
* will fail to recognise it as a vDSO (since arch_vma_name fails).
79-
*/
80-
mm->context.vdso = (void *)vdso_base;
89+
mm->context.vdso = NULL;
90+
ret = install_special_mapping(mm, vdso_base, VVAR_SIZE,
91+
(VM_READ | VM_MAYREAD), &vdso_pagelist[vdso_pages]);
92+
if (unlikely(ret))
93+
goto end;
8194

8295
ret =
83-
install_special_mapping(mm, vdso_base, vdso_pages << PAGE_SHIFT,
96+
install_special_mapping(mm, vdso_base + VVAR_SIZE,
97+
vdso_pages << PAGE_SHIFT,
8498
(VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
8599
vdso_pagelist);
86100

87-
if (unlikely(ret)) {
88-
mm->context.vdso = NULL;
101+
if (unlikely(ret))
89102
goto end;
90-
}
91103

92-
vdso_base += (vdso_pages << PAGE_SHIFT);
93-
ret = install_special_mapping(mm, vdso_base, PAGE_SIZE,
94-
(VM_READ | VM_MAYREAD), &vdso_pagelist[vdso_pages]);
104+
/*
105+
* Put vDSO base into mm struct. We need to do this before calling
106+
* install_special_mapping or the perf counter mmap tracking code
107+
* will fail to recognise it as a vDSO (since arch_vma_name fails).
108+
*/
109+
mm->context.vdso = (void *)vdso_base + VVAR_SIZE;
95110

96-
if (unlikely(ret))
97-
mm->context.vdso = NULL;
98111
end:
99112
mmap_write_unlock(mm);
100113
return ret;
@@ -105,7 +118,7 @@ const char *arch_vma_name(struct vm_area_struct *vma)
105118
if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso))
106119
return "[vdso]";
107120
if (vma->vm_mm && (vma->vm_start ==
108-
(long)vma->vm_mm->context.vdso + PAGE_SIZE))
121+
(long)vma->vm_mm->context.vdso - VVAR_SIZE))
109122
return "[vdso_data]";
110123
return NULL;
111124
}

arch/riscv/kernel/vdso/vdso.lds.S

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* Copyright (C) 2012 Regents of the University of California
44
*/
55
#include <asm/page.h>
6+
#include <asm/vdso.h>
67

78
OUTPUT_ARCH(riscv)
89

910
SECTIONS
1011
{
11-
PROVIDE(_vdso_data = . + PAGE_SIZE);
12+
PROVIDE(_vdso_data = . - __VVAR_PAGES * PAGE_SIZE);
1213
. = SIZEOF_HEADERS;
1314

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

arch/riscv/mm/cacheflush.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ static void ipi_remote_fence_i(void *info)
1616

1717
void flush_icache_all(void)
1818
{
19+
local_flush_icache_all();
20+
1921
if (IS_ENABLED(CONFIG_RISCV_SBI))
2022
sbi_remote_fence_i(NULL);
2123
else

scripts/checksyscalls.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,8 @@ cat << EOF
8282
#define __IGNORE_truncate64
8383
#define __IGNORE_stat64
8484
#define __IGNORE_lstat64
85-
#define __IGNORE_fstat64
8685
#define __IGNORE_fcntl64
8786
#define __IGNORE_fadvise64_64
88-
#define __IGNORE_fstatat64
8987
#define __IGNORE_fstatfs64
9088
#define __IGNORE_statfs64
9189
#define __IGNORE_llseek
@@ -253,6 +251,10 @@ cat << EOF
253251
#define __IGNORE_getpmsg
254252
#define __IGNORE_putpmsg
255253
#define __IGNORE_vserver
254+
255+
/* 64-bit ports never needed these, and new 32-bit ports can use statx */
256+
#define __IGNORE_fstat64
257+
#define __IGNORE_fstatat64
256258
EOF
257259
}
258260

0 commit comments

Comments
 (0)