RISC-V Fixes for 5.15-rc5

* A pair of fixes (along with the necessary cleanup) to our VDSO, to
   avoid
 * 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.
 -----BEGIN PGP SIGNATURE-----
 
 iQJHBAABCgAxFiEEKzw3R0RoQ7JKlDp6LhMZ81+7GIkFAmFgdiUTHHBhbG1lckBk
 YWJiZWx0LmNvbQAKCRAuExnzX7sYiUnPD/9xeQ/c8zL3/tAjfdHhKmoFMT7xU2sA
 mshFrYAUSPywaXU8AGH8zCOJnU1qc3IPxCfojhzgNm6mgVDRZB0z0yhvaInQ/pfT
 NoyzYVmhP72sxM2OdAwMyv5al6sR6g+Z3XGnBIa3e33XwMXGED/o70plKrR80f8H
 6ssKVVXsI3pDhUHwVAS7l7FptLNdreWI1RWJMYI+Idv6gKWqY/6l9B+njB7DeLuH
 0kptFXYDAJHeN5wGcStsMk8nLJ8MaUWFqyqYoxetR2Jr6gegPSPlsirz81XdTjtz
 YRdOXsgTF7gsZc/0impTYPXrfSPeYgjGpJYFyZbCducotQLcFgn9VoKSyOVzeoF6
 sd0kE9seo0wT7rbx/S8Hz0koRqi3ZyA7ieRmpNNxLcr5Se4QghI6DIP0MQkuvwlC
 1yJKAIiNormJ48svLyisJQO0FBiiS68fEBlBnnQAqU8dSJYVj7rq+bd+ufJ7HgqP
 k93Dx8bjPvXNUSSAYWwg4ILqvBJIXAhuXg1TNzfMm4ZXLwQYieHOTZmOXek9rovb
 4EyrbqXr1+q/Z4LudFhJBN8kpzNZYWeqO1Nm32IZg9OKTAGnV5zAjxbK8kFkfD4i
 UDvLlcKDbefAx16zOuIN+k85vZt8QIwKx9uD8lBSskbUCgU1ot15kxNH0H/3wkii
 RqFeFATLa5gjjQ==
 =+mKs
 -----END PGP SIGNATURE-----

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
This commit is contained in:
Linus Torvalds 2021-10-09 09:07:58 -07:00
commit 717478d89f
8 changed files with 58 additions and 33 deletions

View File

@ -82,4 +82,5 @@ static inline int syscall_get_arch(struct task_struct *task)
#endif #endif
} }
asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, uintptr_t);
#endif /* _ASM_RISCV_SYSCALL_H */ #endif /* _ASM_RISCV_SYSCALL_H */

View File

@ -16,18 +16,24 @@
#ifdef CONFIG_MMU #ifdef CONFIG_MMU
#include <linux/types.h> #include <linux/types.h>
#include <generated/vdso-offsets.h> /*
* All systems with an MMU have a VDSO, but systems without an MMU don't
* support shared libraries and therefor don't have one.
*/
#ifdef CONFIG_MMU
#ifndef CONFIG_GENERIC_TIME_VSYSCALL #define __VVAR_PAGES 1
struct vdso_data {
}; #ifndef __ASSEMBLY__
#endif #include <generated/vdso-offsets.h>
#define VDSO_SYMBOL(base, name) \ #define VDSO_SYMBOL(base, name) \
(void __user *)((unsigned long)(base) + __vdso_##name##_offset) (void __user *)((unsigned long)(base) + __vdso_##name##_offset)
#endif /* CONFIG_MMU */ #endif /* CONFIG_MMU */
asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, uintptr_t); #endif /* !__ASSEMBLY__ */
#endif /* CONFIG_MMU */
#endif /* _ASM_RISCV_VDSO_H */ #endif /* _ASM_RISCV_VDSO_H */

View File

@ -18,9 +18,10 @@
#ifdef __LP64__ #ifdef __LP64__
#define __ARCH_WANT_NEW_STAT #define __ARCH_WANT_NEW_STAT
#define __ARCH_WANT_SET_GET_RLIMIT #define __ARCH_WANT_SET_GET_RLIMIT
#define __ARCH_WANT_SYS_CLONE3
#endif /* __LP64__ */ #endif /* __LP64__ */
#define __ARCH_WANT_SYS_CLONE3
#include <asm-generic/unistd.h> #include <asm-generic/unistd.h>
/* /*

View File

@ -7,7 +7,6 @@
#include <linux/linkage.h> #include <linux/linkage.h>
#include <linux/syscalls.h> #include <linux/syscalls.h>
#include <asm-generic/syscalls.h> #include <asm-generic/syscalls.h>
#include <asm/vdso.h>
#include <asm/syscall.h> #include <asm/syscall.h>
#undef __SYSCALL #undef __SYSCALL

View File

@ -12,14 +12,24 @@
#include <linux/binfmts.h> #include <linux/binfmts.h>
#include <linux/err.h> #include <linux/err.h>
#include <asm/page.h> #include <asm/page.h>
#include <asm/vdso.h>
#ifdef CONFIG_GENERIC_TIME_VSYSCALL #ifdef CONFIG_GENERIC_TIME_VSYSCALL
#include <vdso/datapage.h> #include <vdso/datapage.h>
#else #else
#include <asm/vdso.h> struct vdso_data {
};
#endif #endif
extern char vdso_start[], vdso_end[]; extern char vdso_start[], vdso_end[];
enum vvar_pages {
VVAR_DATA_PAGE_OFFSET,
VVAR_NR_PAGES,
};
#define VVAR_SIZE (VVAR_NR_PAGES << PAGE_SHIFT)
static unsigned int vdso_pages __ro_after_init; static unsigned int vdso_pages __ro_after_init;
static struct page **vdso_pagelist __ro_after_init; static struct page **vdso_pagelist __ro_after_init;
@ -38,7 +48,7 @@ static int __init vdso_init(void)
vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT; vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
vdso_pagelist = vdso_pagelist =
kcalloc(vdso_pages + 1, sizeof(struct page *), GFP_KERNEL); kcalloc(vdso_pages + VVAR_NR_PAGES, sizeof(struct page *), GFP_KERNEL);
if (unlikely(vdso_pagelist == NULL)) { if (unlikely(vdso_pagelist == NULL)) {
pr_err("vdso: pagelist allocation failed\n"); pr_err("vdso: pagelist allocation failed\n");
return -ENOMEM; return -ENOMEM;
@ -63,38 +73,41 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,
unsigned long vdso_base, vdso_len; unsigned long vdso_base, vdso_len;
int ret; int ret;
vdso_len = (vdso_pages + 1) << PAGE_SHIFT; BUILD_BUG_ON(VVAR_NR_PAGES != __VVAR_PAGES);
vdso_len = (vdso_pages + VVAR_NR_PAGES) << PAGE_SHIFT;
if (mmap_write_lock_killable(mm))
return -EINTR;
mmap_write_lock(mm);
vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0); vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0);
if (IS_ERR_VALUE(vdso_base)) { if (IS_ERR_VALUE(vdso_base)) {
ret = vdso_base; ret = vdso_base;
goto end; goto end;
} }
mm->context.vdso = NULL;
ret = install_special_mapping(mm, vdso_base, VVAR_SIZE,
(VM_READ | VM_MAYREAD), &vdso_pagelist[vdso_pages]);
if (unlikely(ret))
goto end;
ret =
install_special_mapping(mm, vdso_base + VVAR_SIZE,
vdso_pages << PAGE_SHIFT,
(VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
vdso_pagelist);
if (unlikely(ret))
goto end;
/* /*
* Put vDSO base into mm struct. We need to do this before calling * Put vDSO base into mm struct. We need to do this before calling
* install_special_mapping or the perf counter mmap tracking code * install_special_mapping or the perf counter mmap tracking code
* will fail to recognise it as a vDSO (since arch_vma_name fails). * will fail to recognise it as a vDSO (since arch_vma_name fails).
*/ */
mm->context.vdso = (void *)vdso_base; mm->context.vdso = (void *)vdso_base + VVAR_SIZE;
ret =
install_special_mapping(mm, vdso_base, vdso_pages << PAGE_SHIFT,
(VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
vdso_pagelist);
if (unlikely(ret)) {
mm->context.vdso = NULL;
goto end;
}
vdso_base += (vdso_pages << PAGE_SHIFT);
ret = install_special_mapping(mm, vdso_base, PAGE_SIZE,
(VM_READ | VM_MAYREAD), &vdso_pagelist[vdso_pages]);
if (unlikely(ret))
mm->context.vdso = NULL;
end: end:
mmap_write_unlock(mm); mmap_write_unlock(mm);
return ret; return ret;
@ -105,7 +118,7 @@ const char *arch_vma_name(struct vm_area_struct *vma)
if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso)) if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso))
return "[vdso]"; return "[vdso]";
if (vma->vm_mm && (vma->vm_start == if (vma->vm_mm && (vma->vm_start ==
(long)vma->vm_mm->context.vdso + PAGE_SIZE)) (long)vma->vm_mm->context.vdso - VVAR_SIZE))
return "[vdso_data]"; return "[vdso_data]";
return NULL; return NULL;
} }

View File

@ -3,12 +3,13 @@
* Copyright (C) 2012 Regents of the University of California * Copyright (C) 2012 Regents of the University of California
*/ */
#include <asm/page.h> #include <asm/page.h>
#include <asm/vdso.h>
OUTPUT_ARCH(riscv) OUTPUT_ARCH(riscv)
SECTIONS SECTIONS
{ {
PROVIDE(_vdso_data = . + PAGE_SIZE); PROVIDE(_vdso_data = . - __VVAR_PAGES * PAGE_SIZE);
. = SIZEOF_HEADERS; . = SIZEOF_HEADERS;
.hash : { *(.hash) } :text .hash : { *(.hash) } :text

View File

@ -16,6 +16,8 @@ static void ipi_remote_fence_i(void *info)
void flush_icache_all(void) void flush_icache_all(void)
{ {
local_flush_icache_all();
if (IS_ENABLED(CONFIG_RISCV_SBI)) if (IS_ENABLED(CONFIG_RISCV_SBI))
sbi_remote_fence_i(NULL); sbi_remote_fence_i(NULL);
else else

View File

@ -82,10 +82,8 @@ cat << EOF
#define __IGNORE_truncate64 #define __IGNORE_truncate64
#define __IGNORE_stat64 #define __IGNORE_stat64
#define __IGNORE_lstat64 #define __IGNORE_lstat64
#define __IGNORE_fstat64
#define __IGNORE_fcntl64 #define __IGNORE_fcntl64
#define __IGNORE_fadvise64_64 #define __IGNORE_fadvise64_64
#define __IGNORE_fstatat64
#define __IGNORE_fstatfs64 #define __IGNORE_fstatfs64
#define __IGNORE_statfs64 #define __IGNORE_statfs64
#define __IGNORE_llseek #define __IGNORE_llseek
@ -253,6 +251,10 @@ cat << EOF
#define __IGNORE_getpmsg #define __IGNORE_getpmsg
#define __IGNORE_putpmsg #define __IGNORE_putpmsg
#define __IGNORE_vserver #define __IGNORE_vserver
/* 64-bit ports never needed these, and new 32-bit ports can use statx */
#define __IGNORE_fstat64
#define __IGNORE_fstatat64
EOF EOF
} }