]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/x86/include/asm/string_64.h
KVM: x86: Use gpa_t for cr2/gpa to fix TDP support on 32-bit KVM
[mirror_ubuntu-bionic-kernel.git] / arch / x86 / include / asm / string_64.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_STRING_64_H
3 #define _ASM_X86_STRING_64_H
4
5 #ifdef __KERNEL__
6 #include <linux/jump_label.h>
7
8 /* Written 2002 by Andi Kleen */
9
10 /* Only used for special circumstances. Stolen from i386/string.h */
11 static __always_inline void *__inline_memcpy(void *to, const void *from, size_t n)
12 {
13 unsigned long d0, d1, d2;
14 asm volatile("rep ; movsl\n\t"
15 "testb $2,%b4\n\t"
16 "je 1f\n\t"
17 "movsw\n"
18 "1:\ttestb $1,%b4\n\t"
19 "je 2f\n\t"
20 "movsb\n"
21 "2:"
22 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
23 : "0" (n / 4), "q" (n), "1" ((long)to), "2" ((long)from)
24 : "memory");
25 return to;
26 }
27
28 /* Even with __builtin_ the compiler may decide to use the out of line
29 function. */
30
31 #define __HAVE_ARCH_MEMCPY 1
32 extern void *memcpy(void *to, const void *from, size_t len);
33 extern void *__memcpy(void *to, const void *from, size_t len);
34
35 #define __HAVE_ARCH_MEMSET
36 void *memset(void *s, int c, size_t n);
37 void *__memset(void *s, int c, size_t n);
38
39 #define __HAVE_ARCH_MEMSET16
40 static inline void *memset16(uint16_t *s, uint16_t v, size_t n)
41 {
42 long d0, d1;
43 asm volatile("rep\n\t"
44 "stosw"
45 : "=&c" (d0), "=&D" (d1)
46 : "a" (v), "1" (s), "0" (n)
47 : "memory");
48 return s;
49 }
50
51 #define __HAVE_ARCH_MEMSET32
52 static inline void *memset32(uint32_t *s, uint32_t v, size_t n)
53 {
54 long d0, d1;
55 asm volatile("rep\n\t"
56 "stosl"
57 : "=&c" (d0), "=&D" (d1)
58 : "a" (v), "1" (s), "0" (n)
59 : "memory");
60 return s;
61 }
62
63 #define __HAVE_ARCH_MEMSET64
64 static inline void *memset64(uint64_t *s, uint64_t v, size_t n)
65 {
66 long d0, d1;
67 asm volatile("rep\n\t"
68 "stosq"
69 : "=&c" (d0), "=&D" (d1)
70 : "a" (v), "1" (s), "0" (n)
71 : "memory");
72 return s;
73 }
74
75 #define __HAVE_ARCH_MEMMOVE
76 void *memmove(void *dest, const void *src, size_t count);
77 void *__memmove(void *dest, const void *src, size_t count);
78
79 int memcmp(const void *cs, const void *ct, size_t count);
80 size_t strlen(const char *s);
81 char *strcpy(char *dest, const char *src);
82 char *strcat(char *dest, const char *src);
83 int strcmp(const char *cs, const char *ct);
84
85 #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
86
87 /*
88 * For files that not instrumented (e.g. mm/slub.c) we
89 * should use not instrumented version of mem* functions.
90 */
91
92 #undef memcpy
93 #define memcpy(dst, src, len) __memcpy(dst, src, len)
94 #define memmove(dst, src, len) __memmove(dst, src, len)
95 #define memset(s, c, n) __memset(s, c, n)
96
97 #ifndef __NO_FORTIFY
98 #define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */
99 #endif
100
101 #endif
102
103 #define __HAVE_ARCH_MEMCPY_MCSAFE 1
104 __must_check int memcpy_mcsafe_unrolled(void *dst, const void *src, size_t cnt);
105 DECLARE_STATIC_KEY_FALSE(mcsafe_key);
106
107 /**
108 * memcpy_mcsafe - copy memory with indication if a machine check happened
109 *
110 * @dst: destination address
111 * @src: source address
112 * @cnt: number of bytes to copy
113 *
114 * Low level memory copy function that catches machine checks
115 * We only call into the "safe" function on systems that can
116 * actually do machine check recovery. Everyone else can just
117 * use memcpy().
118 *
119 * Return 0 for success, -EFAULT for fail
120 */
121 static __always_inline __must_check int
122 memcpy_mcsafe(void *dst, const void *src, size_t cnt)
123 {
124 #ifdef CONFIG_X86_MCE
125 if (static_branch_unlikely(&mcsafe_key))
126 return memcpy_mcsafe_unrolled(dst, src, cnt);
127 else
128 #endif
129 memcpy(dst, src, cnt);
130 return 0;
131 }
132
133 #ifdef CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE
134 #define __HAVE_ARCH_MEMCPY_FLUSHCACHE 1
135 void memcpy_flushcache(void *dst, const void *src, size_t cnt);
136 #endif
137
138 #endif /* __KERNEL__ */
139
140 #endif /* _ASM_X86_STRING_64_H */