1
2
3
4
5
6
7
8
9
10#include <linux/linkage.h>
11
12#include <asm/processor-flags.h>
13#include <asm/msr.h>
14#include <asm/asm-offsets.h>
15
16 .text
17 .code32
18SYM_FUNC_START(get_sev_encryption_bit)
19 xor %eax, %eax
20
21#ifdef CONFIG_AMD_MEM_ENCRYPT
22 push %ebx
23 push %ecx
24 push %edx
25
26 movl $0x80000000, %eax
27 cpuid
28 cmpl $0x8000001f, %eax
29 jb .Lno_sev
30
31
32
33
34
35
36
37 movl $0x8000001f, %eax
38 cpuid
39 bt $1, %eax
40 jnc .Lno_sev
41
42 movl $MSR_AMD64_SEV, %ecx
43 rdmsr
44 bt $MSR_AMD64_SEV_ENABLED_BIT, %eax
45 jnc .Lno_sev
46
47 movl %ebx, %eax
48 andl $0x3f, %eax
49 jmp .Lsev_exit
50
51.Lno_sev:
52 xor %eax, %eax
53
54.Lsev_exit:
55 pop %edx
56 pop %ecx
57 pop %ebx
58
59#endif
60
61 ret
62SYM_FUNC_END(get_sev_encryption_bit)
63
64
65
66
67
68
69
70
71
72
73
74SYM_CODE_START_LOCAL(sev_es_req_cpuid)
75 shll $30, %eax
76 orl $0x00000004, %eax
77 movl $MSR_AMD64_SEV_ES_GHCB, %ecx
78 wrmsr
79 rep; vmmcall
80 rdmsr
81
82
83 movl %eax, %ecx
84 andl $0x3ffff000, %ecx
85 jnz 2f
86
87
88 andl $0xfff, %eax
89 cmpl $5, %eax
90 jne 2f
91
92
93 xorl %eax, %eax
941:
95 ret
962:
97 movl $-1, %eax
98 jmp 1b
99SYM_CODE_END(sev_es_req_cpuid)
100
101SYM_CODE_START(startup32_vc_handler)
102 pushl %eax
103 pushl %ebx
104 pushl %ecx
105 pushl %edx
106
107
108 movl %eax, %ebx
109
110
111 cmpl $0x72, 16(%esp)
112 jne .Lfail
113
114 movl $0, %eax
115 movl %ebx, %edx
116 call sev_es_req_cpuid
117 testl %eax, %eax
118 jnz .Lfail
119 movl %edx, 12(%esp)
120
121 movl $1, %eax
122 movl %ebx, %edx
123 call sev_es_req_cpuid
124 testl %eax, %eax
125 jnz .Lfail
126 movl %edx, 8(%esp)
127
128 movl $2, %eax
129 movl %ebx, %edx
130 call sev_es_req_cpuid
131 testl %eax, %eax
132 jnz .Lfail
133 movl %edx, 4(%esp)
134
135 movl $3, %eax
136 movl %ebx, %edx
137 call sev_es_req_cpuid
138 testl %eax, %eax
139 jnz .Lfail
140 movl %edx, 0(%esp)
141
142
143
144
145
146
147
148 cmpl $0x80000000, %ebx
149 jne .Lcheck_sev
150 cmpl $0x8000001f, 12(%esp)
151 jb .Lfail
152 jmp .Ldone
153
154.Lcheck_sev:
155
156 cmpl $0x8000001f, %ebx
157 jne .Ldone
158 btl $1, 12(%esp)
159 jnc .Lfail
160
161.Ldone:
162 popl %edx
163 popl %ecx
164 popl %ebx
165 popl %eax
166
167
168 addl $4, %esp
169
170
171 addl $2, (%esp)
172
173 iret
174.Lfail:
175
176 movl $0x100, %eax
177 xorl %edx, %edx
178 movl $MSR_AMD64_SEV_ES_GHCB, %ecx
179 wrmsr
180 rep; vmmcall
181
182
183 hlt
184 jmp .Lfail
185SYM_CODE_END(startup32_vc_handler)
186
187 .code64
188
189#include "../../kernel/sev_verify_cbit.S"
190SYM_FUNC_START(set_sev_encryption_mask)
191#ifdef CONFIG_AMD_MEM_ENCRYPT
192 push %rbp
193 push %rdx
194
195 movq %rsp, %rbp
196
197 call get_sev_encryption_bit
198 testl %eax, %eax
199 jz .Lno_sev_mask
200
201 bts %rax, sme_me_mask(%rip)
202
203
204
205
206
207
208 movl $MSR_AMD64_SEV, %ecx
209 rdmsr
210
211
212 shlq $32, %rdx
213 orq %rdx, %rax
214 movq %rax, sev_status(%rip)
215
216.Lno_sev_mask:
217 movq %rbp, %rsp
218
219 pop %rdx
220 pop %rbp
221#endif
222
223 xor %rax, %rax
224 ret
225SYM_FUNC_END(set_sev_encryption_mask)
226
227 .data
228
229#ifdef CONFIG_AMD_MEM_ENCRYPT
230 .balign 8
231SYM_DATA(sme_me_mask, .quad 0)
232SYM_DATA(sev_status, .quad 0)
233SYM_DATA(sev_check_data, .quad 0)
234#endif
235