forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/arch/x86/boot/compressed/mem_encrypt.S
....@@ -1,13 +1,10 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * AMD Memory Encryption Support
34 *
45 * Copyright (C) 2017 Advanced Micro Devices, Inc.
56 *
67 * Author: Tom Lendacky <thomas.lendacky@amd.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
1310 #include <linux/linkage.h>
....@@ -18,19 +15,13 @@
1815
1916 .text
2017 .code32
21
-ENTRY(get_sev_encryption_bit)
18
+SYM_FUNC_START(get_sev_encryption_bit)
2219 xor %eax, %eax
2320
2421 #ifdef CONFIG_AMD_MEM_ENCRYPT
2522 push %ebx
2623 push %ecx
2724 push %edx
28
-
29
- /* Check if running under a hypervisor */
30
- movl $1, %eax
31
- cpuid
32
- bt $31, %ecx /* Check the hypervisor bit */
33
- jnc .Lno_sev
3425
3526 movl $0x80000000, %eax /* CPUID to check the highest leaf */
3627 cpuid
....@@ -67,11 +58,14 @@
6758
6859 #endif /* CONFIG_AMD_MEM_ENCRYPT */
6960
70
- ret
71
-ENDPROC(get_sev_encryption_bit)
61
+ RET
62
+SYM_FUNC_END(get_sev_encryption_bit)
7263
7364 .code64
74
-ENTRY(set_sev_encryption_mask)
65
+
66
+#include "../../kernel/sev_verify_cbit.S"
67
+
68
+SYM_FUNC_START(set_sev_encryption_mask)
7569 #ifdef CONFIG_AMD_MEM_ENCRYPT
7670 push %rbp
7771 push %rdx
....@@ -84,6 +78,19 @@
8478
8579 bts %rax, sme_me_mask(%rip) /* Create the encryption mask */
8680
81
+ /*
82
+ * Read MSR_AMD64_SEV again and store it to sev_status. Can't do this in
83
+ * get_sev_encryption_bit() because this function is 32-bit code and
84
+ * shared between 64-bit and 32-bit boot path.
85
+ */
86
+ movl $MSR_AMD64_SEV, %ecx /* Read the SEV MSR */
87
+ rdmsr
88
+
89
+ /* Store MSR value in sev_status */
90
+ shlq $32, %rdx
91
+ orq %rdx, %rax
92
+ movq %rax, sev_status(%rip)
93
+
8794 .Lno_sev_mask:
8895 movq %rbp, %rsp /* Restore original stack pointer */
8996
....@@ -92,13 +99,14 @@
9299 #endif
93100
94101 xor %rax, %rax
95
- ret
96
-ENDPROC(set_sev_encryption_mask)
102
+ RET
103
+SYM_FUNC_END(set_sev_encryption_mask)
97104
98105 .data
99106
100107 #ifdef CONFIG_AMD_MEM_ENCRYPT
101108 .balign 8
102
-GLOBAL(sme_me_mask)
103
- .quad 0
109
+SYM_DATA(sme_me_mask, .quad 0)
110
+SYM_DATA(sev_status, .quad 0)
111
+SYM_DATA(sev_check_data, .quad 0)
104112 #endif