diff options
Diffstat (limited to 'arch/x86/lib')
-rw-r--r-- | arch/x86/lib/Makefile | 2 | ||||
-rw-r--r-- | arch/x86/lib/copy_user_64.S | 12 | ||||
-rw-r--r-- | arch/x86/lib/delay.c | 1 | ||||
-rw-r--r-- | arch/x86/lib/hash.c | 92 | ||||
-rw-r--r-- | arch/x86/lib/memcpy_32.c | 6 | ||||
-rw-r--r-- | arch/x86/lib/msr.c | 89 | ||||
-rw-r--r-- | arch/x86/lib/x86-opcode-map.txt | 4 |
7 files changed, 190 insertions, 16 deletions
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index 992d63bb154f..eabcb6e6a900 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile | |||
@@ -24,7 +24,7 @@ lib-$(CONFIG_SMP) += rwlock.o | |||
24 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o | 24 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o |
25 | lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o | 25 | lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o |
26 | 26 | ||
27 | obj-y += msr.o msr-reg.o msr-reg-export.o | 27 | obj-y += msr.o msr-reg.o msr-reg-export.o hash.o |
28 | 28 | ||
29 | ifeq ($(CONFIG_X86_32),y) | 29 | ifeq ($(CONFIG_X86_32),y) |
30 | obj-y += atomic64_32.o | 30 | obj-y += atomic64_32.o |
diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S index a30ca15be21c..dee945d55594 100644 --- a/arch/x86/lib/copy_user_64.S +++ b/arch/x86/lib/copy_user_64.S | |||
@@ -186,7 +186,7 @@ ENTRY(copy_user_generic_unrolled) | |||
186 | 30: shll $6,%ecx | 186 | 30: shll $6,%ecx |
187 | addl %ecx,%edx | 187 | addl %ecx,%edx |
188 | jmp 60f | 188 | jmp 60f |
189 | 40: lea (%rdx,%rcx,8),%rdx | 189 | 40: leal (%rdx,%rcx,8),%edx |
190 | jmp 60f | 190 | jmp 60f |
191 | 50: movl %ecx,%edx | 191 | 50: movl %ecx,%edx |
192 | 60: jmp copy_user_handle_tail /* ecx is zerorest also */ | 192 | 60: jmp copy_user_handle_tail /* ecx is zerorest also */ |
@@ -236,8 +236,6 @@ ENDPROC(copy_user_generic_unrolled) | |||
236 | ENTRY(copy_user_generic_string) | 236 | ENTRY(copy_user_generic_string) |
237 | CFI_STARTPROC | 237 | CFI_STARTPROC |
238 | ASM_STAC | 238 | ASM_STAC |
239 | andl %edx,%edx | ||
240 | jz 4f | ||
241 | cmpl $8,%edx | 239 | cmpl $8,%edx |
242 | jb 2f /* less than 8 bytes, go to byte copy loop */ | 240 | jb 2f /* less than 8 bytes, go to byte copy loop */ |
243 | ALIGN_DESTINATION | 241 | ALIGN_DESTINATION |
@@ -249,12 +247,12 @@ ENTRY(copy_user_generic_string) | |||
249 | 2: movl %edx,%ecx | 247 | 2: movl %edx,%ecx |
250 | 3: rep | 248 | 3: rep |
251 | movsb | 249 | movsb |
252 | 4: xorl %eax,%eax | 250 | xorl %eax,%eax |
253 | ASM_CLAC | 251 | ASM_CLAC |
254 | ret | 252 | ret |
255 | 253 | ||
256 | .section .fixup,"ax" | 254 | .section .fixup,"ax" |
257 | 11: lea (%rdx,%rcx,8),%rcx | 255 | 11: leal (%rdx,%rcx,8),%ecx |
258 | 12: movl %ecx,%edx /* ecx is zerorest also */ | 256 | 12: movl %ecx,%edx /* ecx is zerorest also */ |
259 | jmp copy_user_handle_tail | 257 | jmp copy_user_handle_tail |
260 | .previous | 258 | .previous |
@@ -279,12 +277,10 @@ ENDPROC(copy_user_generic_string) | |||
279 | ENTRY(copy_user_enhanced_fast_string) | 277 | ENTRY(copy_user_enhanced_fast_string) |
280 | CFI_STARTPROC | 278 | CFI_STARTPROC |
281 | ASM_STAC | 279 | ASM_STAC |
282 | andl %edx,%edx | ||
283 | jz 2f | ||
284 | movl %edx,%ecx | 280 | movl %edx,%ecx |
285 | 1: rep | 281 | 1: rep |
286 | movsb | 282 | movsb |
287 | 2: xorl %eax,%eax | 283 | xorl %eax,%eax |
288 | ASM_CLAC | 284 | ASM_CLAC |
289 | ret | 285 | ret |
290 | 286 | ||
diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c index 7c3bee636e2f..39d6a3db0b96 100644 --- a/arch/x86/lib/delay.c +++ b/arch/x86/lib/delay.c | |||
@@ -16,7 +16,6 @@ | |||
16 | #include <linux/timex.h> | 16 | #include <linux/timex.h> |
17 | #include <linux/preempt.h> | 17 | #include <linux/preempt.h> |
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/init.h> | ||
20 | 19 | ||
21 | #include <asm/processor.h> | 20 | #include <asm/processor.h> |
22 | #include <asm/delay.h> | 21 | #include <asm/delay.h> |
diff --git a/arch/x86/lib/hash.c b/arch/x86/lib/hash.c new file mode 100644 index 000000000000..ff4fa51a5b1f --- /dev/null +++ b/arch/x86/lib/hash.c | |||
@@ -0,0 +1,92 @@ | |||
1 | /* | ||
2 | * Some portions derived from code covered by the following notice: | ||
3 | * | ||
4 | * Copyright (c) 2010-2013 Intel Corporation. All rights reserved. | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * * Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * * Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * * Neither the name of Intel Corporation nor the names of its | ||
18 | * contributors may be used to endorse or promote products derived | ||
19 | * from this software without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
32 | */ | ||
33 | |||
34 | #include <linux/hash.h> | ||
35 | #include <linux/init.h> | ||
36 | |||
37 | #include <asm/processor.h> | ||
38 | #include <asm/cpufeature.h> | ||
39 | #include <asm/hash.h> | ||
40 | |||
41 | static inline u32 crc32_u32(u32 crc, u32 val) | ||
42 | { | ||
43 | #ifdef CONFIG_AS_CRC32 | ||
44 | asm ("crc32l %1,%0\n" : "+r" (crc) : "rm" (val)); | ||
45 | #else | ||
46 | asm (".byte 0xf2, 0x0f, 0x38, 0xf1, 0xc1" : "+a" (crc) : "c" (val)); | ||
47 | #endif | ||
48 | return crc; | ||
49 | } | ||
50 | |||
51 | static u32 intel_crc4_2_hash(const void *data, u32 len, u32 seed) | ||
52 | { | ||
53 | const u32 *p32 = (const u32 *) data; | ||
54 | u32 i, tmp = 0; | ||
55 | |||
56 | for (i = 0; i < len / 4; i++) | ||
57 | seed = crc32_u32(seed, *p32++); | ||
58 | |||
59 | switch (len & 3) { | ||
60 | case 3: | ||
61 | tmp |= *((const u8 *) p32 + 2) << 16; | ||
62 | /* fallthrough */ | ||
63 | case 2: | ||
64 | tmp |= *((const u8 *) p32 + 1) << 8; | ||
65 | /* fallthrough */ | ||
66 | case 1: | ||
67 | tmp |= *((const u8 *) p32); | ||
68 | seed = crc32_u32(seed, tmp); | ||
69 | break; | ||
70 | } | ||
71 | |||
72 | return seed; | ||
73 | } | ||
74 | |||
75 | static u32 intel_crc4_2_hash2(const u32 *data, u32 len, u32 seed) | ||
76 | { | ||
77 | const u32 *p32 = (const u32 *) data; | ||
78 | u32 i; | ||
79 | |||
80 | for (i = 0; i < len; i++) | ||
81 | seed = crc32_u32(seed, *p32++); | ||
82 | |||
83 | return seed; | ||
84 | } | ||
85 | |||
86 | void __init setup_arch_fast_hash(struct fast_hash_ops *ops) | ||
87 | { | ||
88 | if (cpu_has_xmm4_2) { | ||
89 | ops->hash = intel_crc4_2_hash; | ||
90 | ops->hash2 = intel_crc4_2_hash2; | ||
91 | } | ||
92 | } | ||
diff --git a/arch/x86/lib/memcpy_32.c b/arch/x86/lib/memcpy_32.c index e78761d6b7f8..a404b4b75533 100644 --- a/arch/x86/lib/memcpy_32.c +++ b/arch/x86/lib/memcpy_32.c | |||
@@ -4,7 +4,7 @@ | |||
4 | #undef memcpy | 4 | #undef memcpy |
5 | #undef memset | 5 | #undef memset |
6 | 6 | ||
7 | void *memcpy(void *to, const void *from, size_t n) | 7 | __visible void *memcpy(void *to, const void *from, size_t n) |
8 | { | 8 | { |
9 | #ifdef CONFIG_X86_USE_3DNOW | 9 | #ifdef CONFIG_X86_USE_3DNOW |
10 | return __memcpy3d(to, from, n); | 10 | return __memcpy3d(to, from, n); |
@@ -14,13 +14,13 @@ void *memcpy(void *to, const void *from, size_t n) | |||
14 | } | 14 | } |
15 | EXPORT_SYMBOL(memcpy); | 15 | EXPORT_SYMBOL(memcpy); |
16 | 16 | ||
17 | void *memset(void *s, int c, size_t count) | 17 | __visible void *memset(void *s, int c, size_t count) |
18 | { | 18 | { |
19 | return __memset(s, c, count); | 19 | return __memset(s, c, count); |
20 | } | 20 | } |
21 | EXPORT_SYMBOL(memset); | 21 | EXPORT_SYMBOL(memset); |
22 | 22 | ||
23 | void *memmove(void *dest, const void *src, size_t n) | 23 | __visible void *memmove(void *dest, const void *src, size_t n) |
24 | { | 24 | { |
25 | int d0,d1,d2,d3,d4,d5; | 25 | int d0,d1,d2,d3,d4,d5; |
26 | char *ret = dest; | 26 | char *ret = dest; |
diff --git a/arch/x86/lib/msr.c b/arch/x86/lib/msr.c index 8f8eebdca7d4..db9db446b71a 100644 --- a/arch/x86/lib/msr.c +++ b/arch/x86/lib/msr.c | |||
@@ -8,7 +8,7 @@ struct msr *msrs_alloc(void) | |||
8 | 8 | ||
9 | msrs = alloc_percpu(struct msr); | 9 | msrs = alloc_percpu(struct msr); |
10 | if (!msrs) { | 10 | if (!msrs) { |
11 | pr_warning("%s: error allocating msrs\n", __func__); | 11 | pr_warn("%s: error allocating msrs\n", __func__); |
12 | return NULL; | 12 | return NULL; |
13 | } | 13 | } |
14 | 14 | ||
@@ -21,3 +21,90 @@ void msrs_free(struct msr *msrs) | |||
21 | free_percpu(msrs); | 21 | free_percpu(msrs); |
22 | } | 22 | } |
23 | EXPORT_SYMBOL(msrs_free); | 23 | EXPORT_SYMBOL(msrs_free); |
24 | |||
25 | /** | ||
26 | * Read an MSR with error handling | ||
27 | * | ||
28 | * @msr: MSR to read | ||
29 | * @m: value to read into | ||
30 | * | ||
31 | * It returns read data only on success, otherwise it doesn't change the output | ||
32 | * argument @m. | ||
33 | * | ||
34 | */ | ||
35 | int msr_read(u32 msr, struct msr *m) | ||
36 | { | ||
37 | int err; | ||
38 | u64 val; | ||
39 | |||
40 | err = rdmsrl_safe(msr, &val); | ||
41 | if (!err) | ||
42 | m->q = val; | ||
43 | |||
44 | return err; | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * Write an MSR with error handling | ||
49 | * | ||
50 | * @msr: MSR to write | ||
51 | * @m: value to write | ||
52 | */ | ||
53 | int msr_write(u32 msr, struct msr *m) | ||
54 | { | ||
55 | return wrmsrl_safe(msr, m->q); | ||
56 | } | ||
57 | |||
58 | static inline int __flip_bit(u32 msr, u8 bit, bool set) | ||
59 | { | ||
60 | struct msr m, m1; | ||
61 | int err = -EINVAL; | ||
62 | |||
63 | if (bit > 63) | ||
64 | return err; | ||
65 | |||
66 | err = msr_read(msr, &m); | ||
67 | if (err) | ||
68 | return err; | ||
69 | |||
70 | m1 = m; | ||
71 | if (set) | ||
72 | m1.q |= BIT_64(bit); | ||
73 | else | ||
74 | m1.q &= ~BIT_64(bit); | ||
75 | |||
76 | if (m1.q == m.q) | ||
77 | return 0; | ||
78 | |||
79 | err = msr_write(msr, &m); | ||
80 | if (err) | ||
81 | return err; | ||
82 | |||
83 | return 1; | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * Set @bit in a MSR @msr. | ||
88 | * | ||
89 | * Retval: | ||
90 | * < 0: An error was encountered. | ||
91 | * = 0: Bit was already set. | ||
92 | * > 0: Hardware accepted the MSR write. | ||
93 | */ | ||
94 | int msr_set_bit(u32 msr, u8 bit) | ||
95 | { | ||
96 | return __flip_bit(msr, bit, true); | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * Clear @bit in a MSR @msr. | ||
101 | * | ||
102 | * Retval: | ||
103 | * < 0: An error was encountered. | ||
104 | * = 0: Bit was already cleared. | ||
105 | * > 0: Hardware accepted the MSR write. | ||
106 | */ | ||
107 | int msr_clear_bit(u32 msr, u8 bit) | ||
108 | { | ||
109 | return __flip_bit(msr, bit, false); | ||
110 | } | ||
diff --git a/arch/x86/lib/x86-opcode-map.txt b/arch/x86/lib/x86-opcode-map.txt index 533a85e3a07e..1a2be7c6895d 100644 --- a/arch/x86/lib/x86-opcode-map.txt +++ b/arch/x86/lib/x86-opcode-map.txt | |||
@@ -346,8 +346,8 @@ AVXcode: 1 | |||
346 | 17: vmovhps Mq,Vq (v1) | vmovhpd Mq,Vq (66),(v1) | 346 | 17: vmovhps Mq,Vq (v1) | vmovhpd Mq,Vq (66),(v1) |
347 | 18: Grp16 (1A) | 347 | 18: Grp16 (1A) |
348 | 19: | 348 | 19: |
349 | 1a: | 349 | 1a: BNDCL Ev,Gv | BNDCU Ev,Gv | BNDMOV Gv,Ev | BNDLDX Gv,Ev,Gv |
350 | 1b: | 350 | 1b: BNDCN Ev,Gv | BNDMOV Ev,Gv | BNDMK Gv,Ev | BNDSTX Ev,GV,Gv |
351 | 1c: | 351 | 1c: |
352 | 1d: | 352 | 1d: |
353 | 1e: | 353 | 1e: |