Skip to contentSkip to conversation

x86/copy_user: Remove 64-bit asm _copy_*_user variants

PATCH In review Borislav Petkov 3 participants 3 messages Oct 31, 2016 – Nov 1, 2016 x86

lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

PATCH 1/1 x86/copy_user: Remove 64-bit asm _copy_*_user variants

From: Borislav Petkov <[email protected]>

We already have the same functionality in usercopy_32.c. Share it with 64-bit and get rid of some more asm glue which is not needed anymore.

---

Guys, please double-check me on this but I think the asm and the access_ok() macros are equivalent so we can get rid of the asm gunk and redirect to the __copy_*_user variants after checking...

 arch/x86/lib/copy_user_64.S | 47 -------------------------------------------
 arch/x86/lib/usercopy.c     | 49 +++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/lib/usercopy_32.c  | 49 ---------------------------------------------
 3 files changed, 49 insertions(+), 96 deletions(-)
arch/x86/lib/copy_user_64.S +0 -47
index d376e4b48f88..c5959576c315 100644
@@ -16,53 +16,6 @@
 #include <asm/smap.h>
 #include <asm/export.h>
 
-/* Standard copy_to_user with segment limit checking */
-ENTRY(_copy_to_user)
-	mov PER_CPU_VAR(current_task), %rax
-	movq %rdi,%rcx
-	addq %rdx,%rcx
-	jc bad_to_user
-	cmpq TASK_addr_limit(%rax),%rcx
-	ja bad_to_user
-	ALTERNATIVE_2 "jmp copy_user_generic_unrolled",		\
-		      "jmp copy_user_generic_string",		\
-		      X86_FEATURE_REP_GOOD,			\
-		      "jmp copy_user_enhanced_fast_string",	\
-		      X86_FEATURE_ERMS
-ENDPROC(_copy_to_user)
-EXPORT_SYMBOL(_copy_to_user)
-
-/* Standard copy_from_user with segment limit checking */
-ENTRY(_copy_from_user)
-	mov PER_CPU_VAR(current_task), %rax
-	movq %rsi,%rcx
-	addq %rdx,%rcx
-	jc bad_from_user
-	cmpq TASK_addr_limit(%rax),%rcx
-	ja bad_from_user
-	ALTERNATIVE_2 "jmp copy_user_generic_unrolled",		\
-		      "jmp copy_user_generic_string",		\
-		      X86_FEATURE_REP_GOOD,			\
-		      "jmp copy_user_enhanced_fast_string",	\
-		      X86_FEATURE_ERMS
-ENDPROC(_copy_from_user)
-EXPORT_SYMBOL(_copy_from_user)
-
-
-	.section .fixup,"ax"
-	/* must zero dest */
-ENTRY(bad_from_user)
-bad_from_user:
-	movl %edx,%ecx
-	xorl %eax,%eax
-	rep
-	stosb
-bad_to_user:
-	movl %edx,%eax
-	ret
-ENDPROC(bad_from_user)
-	.previous
-
 /*
  * copy_user_generic_unrolled - memory copy with exception handling.
  * This version is for CPUs like P4 that don't have efficient micro
arch/x86/lib/usercopy.c +49 -0

52 lines not on this page · raw message

arch/x86/lib/usercopy_32.c +0 -49

52 lines not on this page · raw message

Signature · 1 line
2.10.0
#1 lore raw

[tip:x86/asm] x86/copy_user: Unify the code by removing the 64-bit asm _copy_*_user() variants

x86/copy_user: Unify the code by removing the 64-bit asm _copy_*_user() variants
Commit-ID:  adb402cd1461eef6e1a21db4532a3b9e6a6be853
Gitweb:     http://git.kernel.org/tip/adb402cd1461eef6e1a21db4532a3b9e6a6be853
Author:     Borislav Petkov <[email protected]>
AuthorDate: Mon, 31 Oct 2016 16:10:15 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 1 Nov 2016 07:41:27 +0100

x86/copy_user: Unify the code by removing the 64-bit asm _copy_*_user() variants

We already have the same functionality in usercopy_32.c. Share it with 64-bit and get rid of some more asm glue which is not needed anymore.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/lib/copy_user_64.S | 47 -------------------------------------------
 arch/x86/lib/usercopy.c     | 49 +++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/lib/usercopy_32.c  | 49 ---------------------------------------------
 3 files changed, 49 insertions(+), 96 deletions(-)
arch/x86/lib/copy_user_64.S +0 -47
index d376e4b..c595957 100644
@@ -16,53 +16,6 @@
 #include <asm/smap.h>
 #include <asm/export.h>
 
-/* Standard copy_to_user with segment limit checking */
-ENTRY(_copy_to_user)
-	mov PER_CPU_VAR(current_task), %rax
-	movq %rdi,%rcx
-	addq %rdx,%rcx
-	jc bad_to_user
-	cmpq TASK_addr_limit(%rax),%rcx
-	ja bad_to_user
-	ALTERNATIVE_2 "jmp copy_user_generic_unrolled",		\
-		      "jmp copy_user_generic_string",		\
-		      X86_FEATURE_REP_GOOD,			\
-		      "jmp copy_user_enhanced_fast_string",	\
-		      X86_FEATURE_ERMS
-ENDPROC(_copy_to_user)
-EXPORT_SYMBOL(_copy_to_user)
-
-/* Standard copy_from_user with segment limit checking */
-ENTRY(_copy_from_user)
-	mov PER_CPU_VAR(current_task), %rax
-	movq %rsi,%rcx
-	addq %rdx,%rcx
-	jc bad_from_user
-	cmpq TASK_addr_limit(%rax),%rcx
-	ja bad_from_user
-	ALTERNATIVE_2 "jmp copy_user_generic_unrolled",		\
-		      "jmp copy_user_generic_string",		\
-		      X86_FEATURE_REP_GOOD,			\
-		      "jmp copy_user_enhanced_fast_string",	\
-		      X86_FEATURE_ERMS
-ENDPROC(_copy_from_user)
-EXPORT_SYMBOL(_copy_from_user)
-
-
-	.section .fixup,"ax"
-	/* must zero dest */
-ENTRY(bad_from_user)
-bad_from_user:
-	movl %edx,%ecx
-	xorl %eax,%eax
-	rep
-	stosb
-bad_to_user:
-	movl %edx,%eax
-	ret
-ENDPROC(bad_from_user)
-	.previous
-
 /*
  * copy_user_generic_unrolled - memory copy with exception handling.
  * This version is for CPUs like P4 that don't have efficient micro
arch/x86/lib/usercopy.c +49 -0

52 lines not on this page · raw message

arch/x86/lib/usercopy_32.c +0 -49

52 lines not on this page · raw message

#2 lore raw
In reply to Borislav Petkov
Quoted 4 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

We already have the same functionality in usercopy_32.c. Share it with 64-bit and get rid of some more asm glue which is not needed anymore.

I see this already made it into -tip, but it looks good to me. I think Al may have some of this in generic code already in his uaccess cleanup stuff, but I doubt this makes for any huge merge conflict issues.

Linus