1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/linkage.h>
14
15#include <asm/processor-flags.h>
16#include <asm/msr.h>
17#include <asm/asm-offsets.h>
18
19 .text
20 .code32
21ENTRY(get_sev_encryption_bit)
22 xor %eax, %eax
23
24#ifdef CONFIG_AMD_MEM_ENCRYPT
25 push %ebx
26 push %ecx
27 push %edx
28 push %edi
29
30
31
32
33
34
35 call 1f
361: popl %edi
37 subl $1b, %edi
38
39 movl enc_bit(%edi), %eax
40 cmpl $0, %eax
41 jge .Lsev_exit
42
43
44 movl $1, %eax
45 cpuid
46 bt $31, %ecx
47 jnc .Lno_sev
48
49 movl $0x80000000, %eax
50 cpuid
51 cmpl $0x8000001f, %eax
52 jb .Lno_sev
53
54
55
56
57
58
59
60 movl $0x8000001f, %eax
61 cpuid
62 bt $1, %eax
63 jnc .Lno_sev
64
65 movl $MSR_AMD64_SEV, %ecx
66 rdmsr
67 bt $MSR_AMD64_SEV_ENABLED_BIT, %eax
68 jnc .Lno_sev
69
70 movl %ebx, %eax
71 andl $0x3f, %eax
72 movl %eax, enc_bit(%edi)
73 jmp .Lsev_exit
74
75.Lno_sev:
76 xor %eax, %eax
77 movl %eax, enc_bit(%edi)
78
79.Lsev_exit:
80 pop %edi
81 pop %edx
82 pop %ecx
83 pop %ebx
84
85#endif
86
87 ret
88ENDPROC(get_sev_encryption_bit)
89
90 .code64
91ENTRY(set_sev_encryption_mask)
92#ifdef CONFIG_AMD_MEM_ENCRYPT
93 push %rbp
94 push %rdx
95
96 movq %rsp, %rbp
97
98 call get_sev_encryption_bit
99 testl %eax, %eax
100 jz .Lno_sev_mask
101
102 bts %rax, sme_me_mask(%rip)
103
104.Lno_sev_mask:
105 movq %rbp, %rsp
106
107 pop %rdx
108 pop %rbp
109#endif
110
111 xor %rax, %rax
112 ret
113ENDPROC(set_sev_encryption_mask)
114
115 .data
116enc_bit:
117 .int 0xffffffff
118
119#ifdef CONFIG_AMD_MEM_ENCRYPT
120 .balign 8
121GLOBAL(sme_me_mask)
122 .quad 0
123#endif
124