* [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault [not found] <20200907153701.2981205-1-arnd@arndb.de> @ 2020-09-07 15:36 ` Arnd Bergmann 2020-09-08 6:11 ` Christoph Hellwig 2020-09-27 9:25 ` Linus Walleij 0 siblings, 2 replies; 5+ messages in thread From: Arnd Bergmann @ 2020-09-07 15:36 UTC (permalink / raw) To: Christoph Hellwig, Russell King Cc: Alexander Viro, kernel, linux-arch, linux-arm-kernel, linus.walleij, Arnd Bergmann, Andrew Morton, Daniel Borkmann, Alexei Starovoitov, linux-mm, linux-kernel On machines such as ARMv5 that trap unaligned accesses, these two functions can be slow when each access needs to be emulated, or they might not work at all. Change them so that each loop is only used when both the src and dst pointers are naturally aligned. Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- mm/maccess.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/mm/maccess.c b/mm/maccess.c index 3bd70405f2d8..d3f1a1f0b1c1 100644 --- a/mm/maccess.c +++ b/mm/maccess.c @@ -24,13 +24,21 @@ bool __weak copy_from_kernel_nofault_allowed(const void *unsafe_src, long copy_from_kernel_nofault(void *dst, const void *src, size_t size) { + unsigned long align = 0; + + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) + align = (unsigned long)dst | (unsigned long)src; + if (!copy_from_kernel_nofault_allowed(src, size)) return -ERANGE; pagefault_disable(); - copy_from_kernel_nofault_loop(dst, src, size, u64, Efault); - copy_from_kernel_nofault_loop(dst, src, size, u32, Efault); - copy_from_kernel_nofault_loop(dst, src, size, u16, Efault); + if (!(align & 7)) + copy_from_kernel_nofault_loop(dst, src, size, u64, Efault); + if (!(align & 3)) + copy_from_kernel_nofault_loop(dst, src, size, u32, Efault); + if (!(align & 1)) + copy_from_kernel_nofault_loop(dst, src, size, u16, Efault); copy_from_kernel_nofault_loop(dst, src, size, u8, Efault); pagefault_enable(); return 0; @@ -50,10 +58,18 @@ EXPORT_SYMBOL_GPL(copy_from_kernel_nofault); long copy_to_kernel_nofault(void *dst, const void *src, size_t size) { + unsigned long align = 0; + + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) + align = (unsigned long)dst | (unsigned long)src; + pagefault_disable(); - copy_to_kernel_nofault_loop(dst, src, size, u64, Efault); - copy_to_kernel_nofault_loop(dst, src, size, u32, Efault); - copy_to_kernel_nofault_loop(dst, src, size, u16, Efault); + if (!(align & 7)) + copy_to_kernel_nofault_loop(dst, src, size, u64, Efault); + if (!(align & 3)) + copy_to_kernel_nofault_loop(dst, src, size, u32, Efault); + if (!(align & 1)) + copy_to_kernel_nofault_loop(dst, src, size, u16, Efault); copy_to_kernel_nofault_loop(dst, src, size, u8, Efault); pagefault_enable(); return 0; -- 2.27.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault 2020-09-07 15:36 ` [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault Arnd Bergmann @ 2020-09-08 6:11 ` Christoph Hellwig 2020-09-27 9:25 ` Linus Walleij 1 sibling, 0 replies; 5+ messages in thread From: Christoph Hellwig @ 2020-09-08 6:11 UTC (permalink / raw) To: Arnd Bergmann Cc: Christoph Hellwig, Russell King, Alexander Viro, kernel, linux-arch, linux-arm-kernel, linus.walleij, Andrew Morton, Daniel Borkmann, Alexei Starovoitov, linux-mm, linux-kernel Looks good: Reviewed-by: Christoph Hellwig <hch@lst.de> This should probably go into Al's base.set_fs branch. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault 2020-09-07 15:36 ` [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault Arnd Bergmann 2020-09-08 6:11 ` Christoph Hellwig @ 2020-09-27 9:25 ` Linus Walleij 1 sibling, 0 replies; 5+ messages in thread From: Linus Walleij @ 2020-09-27 9:25 UTC (permalink / raw) To: Arnd Bergmann Cc: Christoph Hellwig, Russell King, Alexander Viro, linux-kernel@vger.kernel.org, linux-arch, Linux ARM, Andrew Morton, Daniel Borkmann, Alexei Starovoitov, linux-mm, linux-kernel On Mon, Sep 7, 2020 at 5:37 PM Arnd Bergmann <arnd@arndb.de> wrote: > On machines such as ARMv5 that trap unaligned accesses, these > two functions can be slow when each access needs to be emulated, > or they might not work at all. > > Change them so that each loop is only used when both the src > and dst pointers are naturally aligned. > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> That's a clever optimization idea, nice! Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Yours, Linus Walleij ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 0/9] ARM: remove set_fs callers and implementation
@ 2020-10-30 15:45 Arnd Bergmann
2020-10-30 15:49 ` [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault Arnd Bergmann
0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2020-10-30 15:45 UTC (permalink / raw)
To: Russell King, Christoph Hellwig
Cc: Arnd Bergmann, linux-kernel, linux-arm-kernel, linux-arch,
linux-mm, Alexander Viro, Linus Walleij
From: Arnd Bergmann <arnd@arndb.de>
Hi Christoph, Russell,
This is the rebased version of my ARM set_fs patches on top of
v5.10-rc1, dropping the TASK_SIZE_MAX patch but leaving everything
else unchanged.
I have tested the oabi-compat changes using the LTP tests for the three
modified syscalls using an Armv7 kernel and a Debian 5 OABI user space.
I also tested the syscall_get_nr() in all combinations of OABI/EABI
kernel user space and fixed the bugs I found after Russell pointed
out one of those issues.
Russell, you can pull these from
https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git arm-setfs_v4
or I can add them to the ARM patch tracker if you prefer.
Arnd
Arnd Bergmann (9):
mm/maccess: fix unaligned copy_{from,to}_kernel_nofault
ARM: traps: use get_kernel_nofault instead of set_fs()
ARM: oabi-compat: add epoll_pwait handler
ARM: syscall: always store thread_info->syscall
ARM: oabi-compat: rework epoll_wait/epoll_pwait emulation
ARM: oabi-compat: rework sys_semtimedop emulation
ARM: oabi-compat: rework fcntl64() emulation
ARM: uaccess: add __{get,put}_kernel_nofault
ARM: uaccess: remove set_fs() implementation
arch/arm/Kconfig | 1 -
arch/arm/include/asm/ptrace.h | 1 -
arch/arm/include/asm/syscall.h | 16 ++-
arch/arm/include/asm/thread_info.h | 4 -
arch/arm/include/asm/uaccess-asm.h | 6 -
arch/arm/include/asm/uaccess.h | 169 ++++++++++++++-------------
arch/arm/kernel/asm-offsets.c | 3 +-
arch/arm/kernel/entry-common.S | 17 +--
arch/arm/kernel/process.c | 7 +-
arch/arm/kernel/ptrace.c | 9 +-
arch/arm/kernel/signal.c | 8 --
arch/arm/kernel/sys_oabi-compat.c | 181 ++++++++++++++++-------------
arch/arm/kernel/traps.c | 47 +++-----
arch/arm/lib/copy_from_user.S | 3 +-
arch/arm/lib/copy_to_user.S | 3 +-
arch/arm/tools/syscall.tbl | 2 +-
fs/eventpoll.c | 5 +-
include/linux/eventpoll.h | 18 +++
include/linux/syscalls.h | 3 +
ipc/sem.c | 84 ++++++++-----
mm/maccess.c | 28 ++++-
21 files changed, 332 insertions(+), 283 deletions(-)
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-arch@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Arnd Bergmann <arnd@arndb.de>
--
2.27.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault 2020-10-30 15:45 [PATCH v4 0/9] ARM: remove set_fs callers and implementation Arnd Bergmann @ 2020-10-30 15:49 ` Arnd Bergmann 2020-11-06 8:57 ` Linus Walleij 0 siblings, 1 reply; 5+ messages in thread From: Arnd Bergmann @ 2020-10-30 15:49 UTC (permalink / raw) To: Russell King, Christoph Hellwig Cc: linux-kernel, linux-arm-kernel, linux-arch, linux-mm, viro, linus.walleij, arnd From: Arnd Bergmann <arnd@arndb.de> On machines such as ARMv5 that trap unaligned accesses, these two functions can be slow when each access needs to be emulated, or they might not work at all. Change them so that each loop is only used when both the src and dst pointers are naturally aligned. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- mm/maccess.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/mm/maccess.c b/mm/maccess.c index 3bd70405f2d8..d3f1a1f0b1c1 100644 --- a/mm/maccess.c +++ b/mm/maccess.c @@ -24,13 +24,21 @@ bool __weak copy_from_kernel_nofault_allowed(const void *unsafe_src, long copy_from_kernel_nofault(void *dst, const void *src, size_t size) { + unsigned long align = 0; + + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) + align = (unsigned long)dst | (unsigned long)src; + if (!copy_from_kernel_nofault_allowed(src, size)) return -ERANGE; pagefault_disable(); - copy_from_kernel_nofault_loop(dst, src, size, u64, Efault); - copy_from_kernel_nofault_loop(dst, src, size, u32, Efault); - copy_from_kernel_nofault_loop(dst, src, size, u16, Efault); + if (!(align & 7)) + copy_from_kernel_nofault_loop(dst, src, size, u64, Efault); + if (!(align & 3)) + copy_from_kernel_nofault_loop(dst, src, size, u32, Efault); + if (!(align & 1)) + copy_from_kernel_nofault_loop(dst, src, size, u16, Efault); copy_from_kernel_nofault_loop(dst, src, size, u8, Efault); pagefault_enable(); return 0; @@ -50,10 +58,18 @@ EXPORT_SYMBOL_GPL(copy_from_kernel_nofault); long copy_to_kernel_nofault(void *dst, const void *src, size_t size) { + unsigned long align = 0; + + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) + align = (unsigned long)dst | (unsigned long)src; + pagefault_disable(); - copy_to_kernel_nofault_loop(dst, src, size, u64, Efault); - copy_to_kernel_nofault_loop(dst, src, size, u32, Efault); - copy_to_kernel_nofault_loop(dst, src, size, u16, Efault); + if (!(align & 7)) + copy_to_kernel_nofault_loop(dst, src, size, u64, Efault); + if (!(align & 3)) + copy_to_kernel_nofault_loop(dst, src, size, u32, Efault); + if (!(align & 1)) + copy_to_kernel_nofault_loop(dst, src, size, u16, Efault); copy_to_kernel_nofault_loop(dst, src, size, u8, Efault); pagefault_enable(); return 0; -- 2.27.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault 2020-10-30 15:49 ` [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault Arnd Bergmann @ 2020-11-06 8:57 ` Linus Walleij 0 siblings, 0 replies; 5+ messages in thread From: Linus Walleij @ 2020-11-06 8:57 UTC (permalink / raw) To: Arnd Bergmann Cc: Russell King, Christoph Hellwig, linux-kernel, Linux ARM, Linux-Arch, Linux Memory Management List, Al Viro, Arnd Bergmann On Fri, Oct 30, 2020 at 4:49 PM Arnd Bergmann <arnd@kernel.org> wrote: > From: Arnd Bergmann <arnd@arndb.de> > > On machines such as ARMv5 that trap unaligned accesses, these > two functions can be slow when each access needs to be emulated, > or they might not work at all. > > Change them so that each loop is only used when both the src > and dst pointers are naturally aligned. > > Reviewed-by: Christoph Hellwig <hch@lst.de> > Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Yours, Linus Walleij ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-11-06 8:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20200907153701.2981205-1-arnd@arndb.de>
2020-09-07 15:36 ` [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault Arnd Bergmann
2020-09-08 6:11 ` Christoph Hellwig
2020-09-27 9:25 ` Linus Walleij
2020-10-30 15:45 [PATCH v4 0/9] ARM: remove set_fs callers and implementation Arnd Bergmann
2020-10-30 15:49 ` [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault Arnd Bergmann
2020-11-06 8:57 ` Linus Walleij
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox