]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - Documentation/x86/amd-memory-encryption.txt
powerpc/cacheinfo: Remove double free
[mirror_ubuntu-hirsute-kernel.git] / Documentation / x86 / amd-memory-encryption.txt
CommitLineData
33e63acc
BS
1Secure Memory Encryption (SME) and Secure Encrypted Virtualization (SEV) are
2features found on AMD processors.
c262f3b9
TL
3
4SME provides the ability to mark individual pages of memory as encrypted using
5the standard x86 page tables. A page that is marked encrypted will be
6automatically decrypted when read from DRAM and encrypted when written to
7DRAM. SME can therefore be used to protect the contents of DRAM from physical
8attacks on the system.
9
33e63acc
BS
10SEV enables running encrypted virtual machines (VMs) in which the code and data
11of the guest VM are secured so that a decrypted version is available only
12within the VM itself. SEV guest VMs have the concept of private and shared
13memory. Private memory is encrypted with the guest-specific key, while shared
14memory may be encrypted with hypervisor key. When SME is enabled, the hypervisor
15key is the same key which is used in SME.
16
c262f3b9
TL
17A page is encrypted when a page table entry has the encryption bit set (see
18below on how to determine its position). The encryption bit can also be
19specified in the cr3 register, allowing the PGD table to be encrypted. Each
20successive level of page tables can also be encrypted by setting the encryption
21bit in the page table entry that points to the next table. This allows the full
22page table hierarchy to be encrypted. Note, this means that just because the
33e63acc 23encryption bit is set in cr3, doesn't imply the full hierarchy is encrypted.
c262f3b9
TL
24Each page table entry in the hierarchy needs to have the encryption bit set to
25achieve that. So, theoretically, you could have the encryption bit set in cr3
26so that the PGD is encrypted, but not set the encryption bit in the PGD entry
27for a PUD which results in the PUD pointed to by that entry to not be
28encrypted.
29
33e63acc
BS
30When SEV is enabled, instruction pages and guest page tables are always treated
31as private. All the DMA operations inside the guest must be performed on shared
32memory. Since the memory encryption bit is controlled by the guest OS when it
33is operating in 64-bit or 32-bit PAE mode, in all other modes the SEV hardware
34forces the memory encryption bit to 1.
35
36Support for SME and SEV can be determined through the CPUID instruction. The
37CPUID function 0x8000001f reports information related to SME:
c262f3b9
TL
38
39 0x8000001f[eax]:
40 Bit[0] indicates support for SME
33e63acc 41 Bit[1] indicates support for SEV
c262f3b9
TL
42 0x8000001f[ebx]:
43 Bits[5:0] pagetable bit number used to activate memory
44 encryption
45 Bits[11:6] reduction in physical address space, in bits, when
46 memory encryption is enabled (this only affects
47 system physical addresses, not guest physical
48 addresses)
49
50If support for SME is present, MSR 0xc00100010 (MSR_K8_SYSCFG) can be used to
51determine if SME is enabled and/or to enable memory encryption:
52
53 0xc0010010:
54 Bit[23] 0 = memory encryption features are disabled
55 1 = memory encryption features are enabled
56
33e63acc
BS
57If SEV is supported, MSR 0xc0010131 (MSR_AMD64_SEV) can be used to determine if
58SEV is active:
59
60 0xc0010131:
61 Bit[0] 0 = memory encryption is not active
62 1 = memory encryption is active
63
c262f3b9
TL
64Linux relies on BIOS to set this bit if BIOS has determined that the reduction
65in the physical address space as a result of enabling memory encryption (see
66CPUID information above) will not conflict with the address space resource
67requirements for the system. If this bit is not set upon Linux startup then
68Linux itself will not set it and memory encryption will not be possible.
69
70The state of SME in the Linux kernel can be documented as follows:
71 - Supported:
72 The CPU supports SME (determined through CPUID instruction).
73
74 - Enabled:
75 Supported and bit 23 of MSR_K8_SYSCFG is set.
76
77 - Active:
78 Supported, Enabled and the Linux kernel is actively applying
79 the encryption bit to page table entries (the SME mask in the
80 kernel is non-zero).
81
82SME can also be enabled and activated in the BIOS. If SME is enabled and
83activated in the BIOS, then all memory accesses will be encrypted and it will
84not be necessary to activate the Linux memory encryption support. If the BIOS
85merely enables SME (sets bit 23 of the MSR_K8_SYSCFG), then Linux can activate
86memory encryption by default (CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT=y) or
87by supplying mem_encrypt=on on the kernel command line. However, if BIOS does
88not enable SME, then Linux will not be able to activate memory encryption, even
89if configured to do so by default or the mem_encrypt=on command line parameter
90is specified.