Skip to content

Commit 3639a53

Browse files
committed
x86: move stac/clac from user copy routines into callers
This is preparatory work for inlining the 'rep movs' case, but also a cleanup. The __copy_user_nocache() function was mis-used by the rdma code to do uncached kernel copies that don't actually want user copies at all, and as a result doesn't want the stac/clac either. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d2c95f9 commit 3639a53

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

arch/x86/include/asm/uaccess_64.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ copy_user_generic(void *to, const void *from, unsigned len)
2727
{
2828
unsigned ret;
2929

30+
stac();
3031
/*
3132
* If CPU has FSRM feature, use 'rep movs'.
3233
* Otherwise, use copy_user_generic_unrolled.
@@ -38,6 +39,7 @@ copy_user_generic(void *to, const void *from, unsigned len)
3839
"=d" (len)),
3940
"1" (to), "2" (from), "3" (len)
4041
: "memory", "rcx", "r8", "r9", "r10", "r11");
42+
clac();
4143
return ret;
4244
}
4345

@@ -64,8 +66,12 @@ static inline int
6466
__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
6567
unsigned size)
6668
{
69+
long ret;
6770
kasan_check_write(dst, size);
68-
return __copy_user_nocache(dst, src, size, 0);
71+
stac();
72+
ret = __copy_user_nocache(dst, src, size, 0);
73+
clac();
74+
return ret;
6975
}
7076

7177
static inline int

arch/x86/lib/copy_user_64.S

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
* eax uncopied bytes or 0 if successful.
5252
*/
5353
SYM_FUNC_START(copy_user_generic_unrolled)
54-
ASM_STAC
5554
cmpl $8,%edx
5655
jb .Lcopy_user_short_string_bytes
5756
ALIGN_DESTINATION
@@ -123,15 +122,12 @@ EXPORT_SYMBOL(copy_user_generic_unrolled)
123122
* eax uncopied bytes or 0 if successful.
124123
*/
125124
SYM_FUNC_START(copy_user_fast_string)
126-
ASM_STAC
127125
movl %edx,%ecx
128126
1: rep movsb
129127
xorl %eax,%eax
130-
ASM_CLAC
131128
RET
132129

133130
12: movl %ecx,%eax /* ecx is zerorest also */
134-
ASM_CLAC
135131
RET
136132

137133
_ASM_EXTABLE_CPY(1b, 12b)
@@ -160,12 +156,10 @@ SYM_CODE_START_LOCAL(.Lcopy_user_handle_tail)
160156
movl %edx,%ecx
161157
1: rep movsb
162158
2: mov %ecx,%eax
163-
ASM_CLAC
164159
RET
165160

166161
3:
167162
movl %edx,%eax
168-
ASM_CLAC
169163
RET
170164

171165
_ASM_EXTABLE_CPY(1b, 2b)
@@ -209,7 +203,6 @@ SYM_CODE_START_LOCAL(copy_user_short_string)
209203
decl %ecx
210204
jnz 21b
211205
23: xor %eax,%eax
212-
ASM_CLAC
213206
RET
214207

215208
40: leal (%rdx,%rcx,8),%edx
@@ -233,8 +226,6 @@ SYM_CODE_END(copy_user_short_string)
233226
* - Require 4-byte alignment when size is 4 bytes.
234227
*/
235228
SYM_FUNC_START(__copy_user_nocache)
236-
ASM_STAC
237-
238229
/* If size is less than 8 bytes, go to 4-byte copy */
239230
cmpl $8,%edx
240231
jb .L_4b_nocache_copy_entry
@@ -327,7 +318,6 @@ SYM_FUNC_START(__copy_user_nocache)
327318
/* Finished copying; fence the prior stores */
328319
.L_finish_copy:
329320
xorl %eax,%eax
330-
ASM_CLAC
331321
sfence
332322
RET
333323

arch/x86/lib/usercopy_64.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ EXPORT_SYMBOL_GPL(arch_wb_cache_pmem);
4545
long __copy_user_flushcache(void *dst, const void __user *src, unsigned size)
4646
{
4747
unsigned long flushed, dest = (unsigned long) dst;
48-
long rc = __copy_user_nocache(dst, src, size, 0);
48+
long rc;
49+
50+
stac();
51+
rc = __copy_user_nocache(dst, src, size, 0);
52+
clac();
4953

5054
/*
5155
* __copy_user_nocache() uses non-temporal stores for the bulk

tools/objtool/check.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,9 @@ static const char *uaccess_safe_builtin[] = {
12851285
"copy_mc_enhanced_fast_string",
12861286
"ftrace_likely_update", /* CONFIG_TRACE_BRANCH_PROFILING */
12871287
"clear_user_original",
1288+
"copy_user_generic_unrolled",
1289+
"copy_user_fast_string",
1290+
"__copy_user_nocache",
12881291
NULL
12891292
};
12901293

0 commit comments

Comments
 (0)