Add AMD SEV guest live migration support
Subsystems (6)
v2 cover Add AMD SEV guest live migration support
The series add support for AMD SEV guest live migration commands. To protect the confidentiality of an SEV protected guest memory while in transit we need to use the SEV commands defined in SEV API spec [1].
SEV guest VMs have the concept of private and shared memory. Private memory is encrypted with the guest-specific key, while shared memory may be encrypted with hypervisor key. The commands provided by the SEV FW are meant to be used for the private memory only. The patch series introduces a new hypercall. The guest OS can use this hypercall to notify the page encryption status. If the page is encrypted with guest specific-key then we use SEV command during the migration. If page is not encrypted then fallback to default.
The patch adds new ioctls KVM_{SET,GET}_PAGE_ENC_BITMAP. The ioctl can be used by the qemu to get the page encrypted bitmap. Qemu can consult this bitmap during the migration to know whether the page is encrypted.
[1] https://developer.amd.com/wp-content/resources/55766.PDF
While implementing the migration I stumbled on the follow question:
- Since there is a guest OS changes required to support the migration, so how do we know whether guest OS is updated? Should we extend KVM capabilities/feature bits to check this?
TODO:
- reset the bitmap on guest reboot.
The complete tree with patch is available at:
https://github.com/codomania/kvm/tree/sev-migration-rfc-v2
Changes since v1:
- Add support to share the page encryption between the source and target machine.
- Fix review feedbacks from Tom Lendacky.
- Add check to limit the session blob length.
- Update KVM_GET_PAGE_ENC_BITMAP icotl to use the base_gfn instead of the memory slot when querying the bitmap.
Brijesh Singh (11):
KVM: SVM: Add KVM_SEV SEND_START command
KVM: SVM: Add KVM_SEND_UPDATE_DATA command
KVM: SVM: Add KVM_SEV_SEND_FINISH command
KVM: SVM: Add support for KVM_SEV_RECEIVE_START command
KVM: SVM: Add KVM_SEV_RECEIVE_UPDATE_DATA command
KVM: SVM: Add KVM_SEV_RECEIVE_FINISH command
KVM: x86: Add AMD SEV specific Hypercall3
KVM: X86: Introduce KVM_HC_PAGE_ENC_STATUS hypercall
KVM: x86: Introduce KVM_GET_PAGE_ENC_BITMAP ioctl
mm: x86: Invoke hypercall when page encryption status is changed
KVM: x86: Introduce KVM_SET_PAGE_ENC_BITMAP ioctl
.../virtual/kvm/amd-memory-encryption.rst | 120 ++++ Documentation/virtual/kvm/hypercalls.txt | 14 + arch/x86/include/asm/kvm_host.h | 4 + arch/x86/include/asm/kvm_para.h | 12 + arch/x86/include/asm/mem_encrypt.h | 3 + arch/x86/kvm/svm.c | 573 +++++++++++++++++- arch/x86/kvm/vmx/vmx.c | 1 + arch/x86/kvm/x86.c | 29 + arch/x86/mm/mem_encrypt.c | 45 +- arch/x86/mm/pageattr.c | 15 + include/uapi/linux/kvm.h | 52 ++ include/uapi/linux/kvm_para.h | 1 + 12 files changed, 864 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
RFC PATCH v2 1/11 KVM: SVM: Add KVM_SEV SEND_START command
The command is used to create an outgoing SEV guest encryption context.
--- .../virtual/kvm/amd-memory-encryption.rst | 27 +++++ arch/x86/kvm/svm.c | 105 ++++++++++++++++++ include/uapi/linux/kvm.h | 12 ++ 3 files changed, 144 insertions(+)
Documentation/virtual/kvm/amd-memory-encryption.rst +27 -0
@@ -238,6 +238,33 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +10. KVM_SEV_SEND_START +---------------------- + +The KVM_SEV_SEND_START command can be used by the hypervisor to create an +outgoing guest encryption context. + +Parameters (in): struct kvm_sev_send_start + +Returns: 0 on success, -negative on error + +:: + struct kvm_sev_send_start { + __u32 policy; /* guest policy */ + + __u64 pdh_cert_uaddr; /* platform Diffie-Hellman certificate */ + __u32 pdh_cert_len; + + __u64 plat_cert_uaddr; /* platform certificate chain */ + __u32 plat_cert_len; + + __u64 amd_cert_uaddr; /* AMD certificate */ + __u32 amd_cert_len; + + __u64 session_uaddr; /* Guest session information */ + __u32 session_len; + }; + References ==========
arch/x86/kvm/svm.c +105 -0
117 lines not on this page · raw message
include/uapi/linux/kvm.h +12 -0
@@ -1531,6 +1531,18 @@ struct kvm_sev_dbg {__u32 len; }; +struct kvm_sev_send_start { +__u32 policy; +__u64 pdh_cert_uaddr; +__u32 pdh_cert_len; +__u64 plat_cert_uaddr; +__u32 plat_cert_len; +__u64 amd_cert_uaddr; +__u32 amd_cert_len; +__u64 session_uaddr; +__u32 session_len; +}; +#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)#define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
Signature · 1 line
2.17.1
RFC PATCH v2 2/11 KVM: SVM: Add KVM_SEND_UPDATE_DATA command
In reply to Singh, BrijeshThe command is used for encrypting the guest memory region using the encryption context created with KVM_SEV_SEND_START.
--- .../virtual/kvm/amd-memory-encryption.rst | 24 ++++ arch/x86/kvm/svm.c | 120 +++++++++++++++++- include/uapi/linux/kvm.h | 9 ++ 3 files changed, 149 insertions(+), 4 deletions(-)
Documentation/virtual/kvm/amd-memory-encryption.rst +24 -0
@@ -265,6 +265,30 @@ Returns: 0 on success, -negative on error __u32 session_len; }; +11. KVM_SEV_SEND_UPDATE_DATA +---------------------------- + +The KVM_SEV_SEND_UPDATE_DATA command can be used by the hypervisor to encrypt the +outgoing guest memory region with the encryption context creating using +KVM_SEV_SEND_START. + +Parameters (in): struct kvm_sev_send_update_data + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_launch_send_update_data { + __u64 hdr_uaddr; /* userspace address containing the packet header */ + __u32 hdr_len; + + __u64 guest_uaddr; /* the source memory region to be encrypted */ + __u32 guest_len; + + __u64 trans_uaddr; /* the destition memory region */ + __u32 trans_len; + }; + References ==========
arch/x86/kvm/svm.c +116 -4
150 lines not on this page · raw message
include/uapi/linux/kvm.h +9 -0
@@ -1543,6 +1543,15 @@ struct kvm_sev_send_start {__u32 session_len; }; +struct kvm_sev_send_update_data { +__u64 hdr_uaddr; +__u32 hdr_len; +__u64 guest_uaddr; +__u32 guest_len; +__u64 trans_uaddr; +__u32 trans_len; +}; +#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)#define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
Signature · 1 line
2.17.1
RFC PATCH v2 3/11 KVM: SVM: Add KVM_SEV_SEND_FINISH command
In reply to Singh, BrijeshThe command is used to finailize the encryption context created with KVM_SEV_SEND_START command.
--- .../virtual/kvm/amd-memory-encryption.rst | 8 +++++++ arch/x86/kvm/svm.c | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+)
Documentation/virtual/kvm/amd-memory-encryption.rst +8 -0
@@ -289,6 +289,14 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +12. KVM_SEV_SEND_FINISH +------------------------ + +After completion of the migration flow, the KVM_SEV_SEND_FINISH command can be +issued by the hypervisor to delete the encryption context. + +Returns: 0 on success, -negative on error + References ==========
arch/x86/kvm/svm.c +23 -0
@@ -7171,6 +7171,26 @@ static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp)return ret; } +static int sev_send_finish (struct kvm *kvm,struct kvm_sev_cmd *argp) +{ +struct kvm_sev_info *sev = &to_kvm_svm (kvm)->sev_info; +struct sev_data_send_finish *data; +int ret; + +if (!sev_guest (kvm)) +return -ENOTTY ; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->handle = sev->handle; + ret =sev_issue_cmd (kvm,SEV_CMD_SEND_FINISH , data, &argp->error); + +kfree (data); +return ret; +} +static int svm_mem_enc_op (struct kvm *kvm,void __user *argp) {struct kvm_sev_cmd sev_cmd;
@@ -7218,6 +7238,9 @@ static int svm_mem_enc_op(struct kvm *kvm, void __user *argp)case KVM_SEV_SEND_UPDATE_DATA : r =sev_send_update_data (kvm, &sev_cmd);break ; +case KVM_SEV_SEND_FINISH : + r =sev_send_finish (kvm, &sev_cmd); +break ;default : r = -EINVAL ; goto out;
Signature · 1 line
2.17.1
RFC PATCH v2 4/11 KVM: SVM: Add support for KVM_SEV_RECEIVE_START command
In reply to Singh, BrijeshThe command is used to create the encryption context for an incoming SEV guest. The encryption context can be later used by the hypervisor to import the incoming data into the SEV guest memory space.
--- .../virtual/kvm/amd-memory-encryption.rst | 29 +++++++ arch/x86/kvm/svm.c | 80 +++++++++++++++++++ include/uapi/linux/kvm.h | 9 +++ 3 files changed, 118 insertions(+)
Documentation/virtual/kvm/amd-memory-encryption.rst +29 -0
@@ -297,6 +297,35 @@ issued by the hypervisor to delete the encryption context. Returns: 0 on success, -negative on error +13. KVM_SEV_RECEIVE_START +------------------------ + +The KVM_SEV_RECEIVE_START command is used for creating the memory encryption +context for an incoming SEV guest. To create the encryption context, the user must +provide a guest policy, the platform public Diffie-Hellman (PDH) key and session +information. + +Parameters: struct kvm_sev_receive_start (in/out) + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_receive_start { + __u32 handle; /* if zero then firmware creates a new handle */ + __u32 policy; /* guest's policy */ + + __u64 pdh_uaddr; /* userspace address pointing to the PDH key */ + __u32 dh_len; + + __u64 session_addr; /* userspace address which points to the guest session information */ + __u32 session_len; + }; + +On success, the 'handle' field contains a new handle and on error, a negative value. + +For more details, see SEV spec Section 6.12. + References ==========
arch/x86/kvm/svm.c +80 -0
92 lines not on this page · raw message
include/uapi/linux/kvm.h +9 -0
@@ -1552,6 +1552,15 @@ struct kvm_sev_send_update_data {__u32 trans_len; }; +struct kvm_sev_receive_start { +__u32 handle; +__u32 policy; +__u64 pdh_uaddr; +__u32 pdh_len; +__u64 session_uaddr; +__u32 session_len; +}; +#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)#define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
Signature · 1 line
2.17.1
RFC PATCH v2 5/11 KVM: SVM: Add KVM_SEV_RECEIVE_UPDATE_DATA command
In reply to Singh, BrijeshThe command is used for copying the incoming buffer into the SEV guest memory space.
--- .../virtual/kvm/amd-memory-encryption.rst | 24 ++++++ arch/x86/kvm/svm.c | 75 +++++++++++++++++++ include/uapi/linux/kvm.h | 9 +++ 3 files changed, 108 insertions(+)
Documentation/virtual/kvm/amd-memory-encryption.rst +24 -0
@@ -326,6 +326,30 @@ On success, the 'handle' field contains a new handle and on error, a negative va For more details, see SEV spec Section 6.12. +14. KVM_SEV_RECEIVE_UPDATE_DATA +---------------------------- + +The KVM_SEV_RECEIVE_UPDATE_DATA command can be used by the hypervisor to copy +the incoming buffers into the guest memory region with encryption context +created during the KVM_SEV_RECEIVE_START. + +Parameters (in): struct kvm_sev_receive_update_data + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_launch_receive_update_data { + __u64 hdr_uaddr; /* userspace address containing the packet header */ + __u32 hdr_len; + + __u64 guest_uaddr; /* the destination guest memory region */ + __u32 guest_len; + + __u64 trans_uaddr; /* the incoming buffer memory region */ + __u32 trans_len; + }; + References ==========
arch/x86/kvm/svm.c +75 -0
87 lines not on this page · raw message
include/uapi/linux/kvm.h +9 -0
@@ -1561,6 +1561,15 @@ struct kvm_sev_receive_start {__u32 session_len; }; +struct kvm_sev_receive_update_data { +__u64 hdr_uaddr; +__u32 hdr_len; +__u64 guest_uaddr; +__u32 guest_len; +__u64 trans_uaddr; +__u32 trans_len; +}; +#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)#define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
Signature · 1 line
2.17.1
RFC PATCH v2 6/11 KVM: SVM: Add KVM_SEV_RECEIVE_FINISH command
In reply to Singh, BrijeshThe command finalize the guest receiving process and make the SEV guest ready for the execution.
--- .../virtual/kvm/amd-memory-encryption.rst | 8 +++++++ arch/x86/kvm/svm.c | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+)
Documentation/virtual/kvm/amd-memory-encryption.rst +8 -0
@@ -350,6 +350,14 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +15. KVM_SEV_RECEIVE_FINISH +------------------------ + +After completion of the migration flow, the KVM_SEV_RECEIVE_FINISH command can be +issued by the hypervisor to make the guest ready for execution. + +Returns: 0 on success, -negative on error + References ==========
arch/x86/kvm/svm.c +23 -0
@@ -7340,6 +7340,26 @@ static int sev_receive_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp)return ret; } +static int sev_receive_finish (struct kvm *kvm,struct kvm_sev_cmd *argp) +{ +struct kvm_sev_info *sev = &to_kvm_svm (kvm)->sev_info; +struct sev_data_receive_finish *data; +int ret; + +if (!sev_guest (kvm)) +return -ENOTTY ; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->handle = sev->handle; + ret =sev_issue_cmd (kvm,SEV_CMD_RECEIVE_FINISH , data, &argp->error); + +kfree (data); +return ret; +} +static int svm_mem_enc_op (struct kvm *kvm,void __user *argp) {struct kvm_sev_cmd sev_cmd;
@@ -7396,6 +7416,9 @@ static int svm_mem_enc_op(struct kvm *kvm, void __user *argp)case KVM_SEV_RECEIVE_UPDATE_DATA : r =sev_receive_update_data (kvm, &sev_cmd);break ; +case KVM_SEV_RECEIVE_FINISH : + r =sev_receive_finish (kvm, &sev_cmd); +break ;default : r = -EINVAL ; goto out;
Signature · 1 line
2.17.1
RFC PATCH v2 7/11 KVM: x86: Add AMD SEV specific Hypercall3
In reply to Singh, BrijeshKVM hypercall framework relies on alternative framework to patch the VMCALL -> VMMCALL on AMD platform. If a hypercall is made before apply_alternative() is called then it defaults to VMCALL. The approach works fine on non SEV guest. A VMCALL would causes #UD, and hypervisor will be able to decode the instruction and do the right things. But when SEV is active, guest memory is encrypted with guest key and hypervisor will not be able to decode the instruction bytes.
Add SEV specific hypercall3, it unconditionally uses VMMCALL. The hypercall will be used by the SEV guest to notify encrypted pages to the hypervisor.
--- arch/x86/include/asm/kvm_para.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/x86/include/asm/kvm_para.h +12 -0
@@ -84,6 +84,18 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,return ret; } +static inline long kvm_sev_hypercall3 (unsigned int nr,unsigned long p1, +unsigned long p2,unsigned long p3) +{ +long ret; + + asmvolatile ("vmmcall" + :"=a" (ret) + :"a" (nr),"b" (p1),"c" (p2),"d" (p3) + :"memory" ); +return ret; +} +#ifdef CONFIG_KVM_GUEST bool kvm_para_available (void );unsigned int kvm_arch_para_features (void );
Signature · 1 line
2.17.1
RFC PATCH v2 8/11 KVM: X86: Introduce KVM_HC_PAGE_ENC_STATUS hypercall
In reply to Singh, BrijeshThis hypercall is used by the SEV guest to notify a change in the page encryption status to the hypervisor. The hypercall should be invoked only when the encryption attribute is changed from encrypted -> decrypted and vice versa. By default all guest pages are considered encrypted.
--- Documentation/virtual/kvm/hypercalls.txt | 14 ++++++ arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/svm.c | 63 ++++++++++++++++++++++++ arch/x86/kvm/vmx/vmx.c | 1 + arch/x86/kvm/x86.c | 5 ++ include/uapi/linux/kvm_para.h | 1 + 6 files changed, 86 insertions(+)
Documentation/virtual/kvm/hypercalls.txt +14 -0
@@ -141,3 +141,17 @@ a0 corresponds to the APIC ID in the third argument (a2), bit 1 corresponds to the APIC ID a2+1, and so on. Returns the number of CPUs to which the IPIs were delivered successfully. + +7. KVM_HC_PAGE_ENC_STATUS +------------------------- +Architecture: x86 +Status: active +Purpose: Notify the encryption status changes in guest page table (SEV guest) + +a0: the guest physical address of the start page +a1: the number of pages +a2: encryption attribute + + Where: + * 1: Encryption attribute is set + * 0: Encryption attribute is cleared
arch/x86/include/asm/kvm_host.h +2 -0
@@ -1202,6 +1202,8 @@ struct kvm_x86_ops {uint16_t (*nested_get_evmcs_version)(struct kvm_vcpu *vcpu);bool (*need_emulation_on_page_fault)(struct kvm_vcpu *vcpu); +int (*page_enc_status_hc)(struct kvm *kvm,unsigned long gpa, +unsigned long sz,unsigned long mode); };struct kvm_arch_async_pf {
arch/x86/kvm/svm.c +63 -0
87 lines not on this page · raw message
arch/x86/kvm/vmx/vmx.c +1 -0
@@ -7727,6 +7727,7 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = { .get_vmcs12_pages = NULL, .nested_enable_evmcs = NULL, .need_emulation_on_page_fault = vmx_need_emulation_on_page_fault, + .page_enc_status_hc = NULL, };static void vmx_cleanup_l1d_flush (void )
arch/x86/kvm/x86.c +5 -0
@@ -7221,6 +7221,11 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)case KVM_HC_SEND_IPI : ret =kvm_pv_send_ipi (vcpu->kvm, a0, a1, a2, a3, op_64_bit);break ; +case KVM_HC_PAGE_ENC_STATUS : + ret = -KVM_ENOSYS ; +if (kvm_x86_ops->page_enc_status_hc) + ret = kvm_x86_ops->page_enc_status_hc (vcpu->kvm, a0, a1, a2); +break ;default : ret = -KVM_ENOSYS ;break ;
include/uapi/linux/kvm_para.h +1 -0
@@ -28,6 +28,7 @@#define KVM_HC_MIPS_CONSOLE_OUTPUT 8#define KVM_HC_CLOCK_PAIRING 9#define KVM_HC_SEND_IPI 10 +#define KVM_HC_PAGE_ENC_STATUS 11/* * hypercalls use architecture specific
Signature · 1 line
2.17.1
RFC PATCH v2 9/11 KVM: x86: Introduce KVM_GET_PAGE_ENC_BITMAP ioctl
In reply to Singh, BrijeshThe ioctl can be used to retrieve page encryption bitmap for a given gfn range.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 44 ++++++++++++++++++++++++++++++++- arch/x86/kvm/x86.c | 12 +++++++++ include/uapi/linux/kvm.h | 12 +++++++++ 4 files changed, 68 insertions(+), 1 deletion(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1204,6 +1204,7 @@ struct kvm_x86_ops {bool (*need_emulation_on_page_fault)(struct kvm_vcpu *vcpu);int (*page_enc_status_hc)(struct kvm *kvm,unsigned long gpa,unsigned long sz,unsigned long mode); +int (*get_page_enc_bitmap)(struct kvm *kvm,struct kvm_page_enc_bitmap *bmap); };struct kvm_arch_async_pf {
arch/x86/kvm/svm.c +43 -1
56 lines not on this page · raw message
arch/x86/kvm/x86.c +12 -0
@@ -4929,6 +4929,18 @@ long kvm_arch_vm_ioctl(struct file *filp, r =kvm_vm_ioctl_hv_eventfd (kvm, &hvevfd);break ; } +case KVM_GET_PAGE_ENC_BITMAP : { +struct kvm_page_enc_bitmap bitmap; + + r = -EFAULT ; +if (copy_from_user (&bitmap, argp,sizeof (bitmap))) + goto out; + + r = -ENOTTY ; +if (kvm_x86_ops->get_page_enc_bitmap) + r = kvm_x86_ops->get_page_enc_bitmap (kvm, &bitmap); +break ; + }default : r = -ENOTTY ; }
include/uapi/linux/kvm.h +12 -0
@@ -492,6 +492,16 @@ struct kvm_dirty_log { }; }; +/* for KVM_GET_PAGE_ENC_BITMAP */ +struct kvm_page_enc_bitmap { +__u64 start; +__u64 num_pages; +union { +void __user *enc_bitmap;/* one bit per page */ +__u64 padding2; + }; +}; +/* for KVM_CLEAR_DIRTY_LOG */ struct kvm_clear_dirty_log {__u32 slot;
@@ -1451,6 +1461,8 @@ struct kvm_enc_region {/* Available with KVM_CAP_ARM_SVE */ #define KVM_ARM_VCPU_FINALIZE _IOW(KVMIO, 0xc2, int) +#define KVM_GET_PAGE_ENC_BITMAP _IOW(KVMIO, 0xc2, struct kvm_page_enc_bitmap) +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */
Signature · 1 line
2.17.1
RFC PATCH v2 10/11 mm: x86: Invoke hypercall when page encryption status is changed
In reply to Singh, BrijeshInvoke a hypercall when a memory region is changed from encrypted -> decrypted and vice versa. Hypervisor need to know the page encryption status during the guest migration.
--- arch/x86/include/asm/mem_encrypt.h | 3 ++ arch/x86/mm/mem_encrypt.c | 45 +++++++++++++++++++++++++++++- arch/x86/mm/pageattr.c | 15 ++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-)
arch/x86/include/asm/mem_encrypt.h +3 -0
@@ -97,4 +97,7 @@ extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_decrypte#endif /* __ASSEMBLY__ */ +extern void set_memory_enc_dec_hypercall (unsigned long vaddr, +unsigned long size,bool enc); +#endif /* __X86_MEM_ENCRYPT_H__ */
arch/x86/mm/mem_encrypt.c +44 -1
80 lines not on this page · raw message
arch/x86/mm/pageattr.c +15 -0
@@ -26,6 +26,7 @@#include <asm/proto.h> #include <asm/pat.h> #include <asm/set_memory.h> +#include <asm/mem_encrypt.h> #include "mm_internal.h"
@@ -2020,6 +2021,12 @@ int set_memory_global(unsigned long addr, int numpages) __pgprot(_PAGE_GLOBAL), 0); } +void __attribute__((weak))set_memory_enc_dec_hypercall (unsigned long addr, +unsigned long size, +bool enc) +{ +} +static int __set_memory_enc_dec (unsigned long addr,int numpages,bool enc) {struct cpa_data cpa;
@@ -2060,6 +2067,14 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)*/ cpa_flush (&cpa,0 ); +/* +* When SEV is active, notify hypervisor that a given memory range is mapped +* encrypted or decrypted. Hypervisor will use this information during +* the VM migration. +*/ +if (sev_active ()) +set_memory_enc_dec_hypercall (addr, numpages <<PAGE_SHIFT , enc); +return ret; }
Signature · 1 line
2.17.1
RFC PATCH v2 11/11 KVM: x86: Introduce KVM_SET_PAGE_ENC_BITMAP ioctl
In reply to Singh, BrijeshThe ioctl can be used to set page encryption bitmap for an incoming guest.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 44 ++++++++++++++++++++++++++++++++- arch/x86/kvm/x86.c | 12 +++++++++ include/uapi/linux/kvm.h | 1 + 4 files changed, 57 insertions(+), 1 deletion(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1205,6 +1205,7 @@ struct kvm_x86_ops {int (*page_enc_status_hc)(struct kvm *kvm,unsigned long gpa,unsigned long sz,unsigned long mode);int (*get_page_enc_bitmap)(struct kvm *kvm,struct kvm_page_enc_bitmap *bmap); +int (*set_page_enc_bitmap)(struct kvm *kvm,struct kvm_page_enc_bitmap *bmap); };struct kvm_arch_async_pf {
arch/x86/kvm/svm.c +43 -1
56 lines not on this page · raw message
arch/x86/kvm/x86.c +12 -0
@@ -4941,6 +4941,18 @@ long kvm_arch_vm_ioctl(struct file *filp, r = kvm_x86_ops->get_page_enc_bitmap (kvm, &bitmap);break ; } +case KVM_SET_PAGE_ENC_BITMAP : { +struct kvm_page_enc_bitmap bitmap; + + r = -EFAULT ; +if (copy_from_user (&bitmap, argp,sizeof (bitmap))) + goto out; + + r = -ENOTTY ; +if (kvm_x86_ops->set_page_enc_bitmap) + r = kvm_x86_ops->set_page_enc_bitmap (kvm, &bitmap); +break ; + }default : r = -ENOTTY ; }
include/uapi/linux/kvm.h +1 -0
@@ -1462,6 +1462,7 @@ struct kvm_enc_region {#define KVM_ARM_VCPU_FINALIZE _IOW(KVMIO, 0xc2, int)#define KVM_GET_PAGE_ENC_BITMAP _IOW(KVMIO, 0xc2, struct kvm_page_enc_bitmap) +#define KVM_SET_PAGE_ENC_BITMAP _IOW(KVMIO, 0xc3, struct kvm_page_enc_bitmap)/* Secure Encrypted Virtualization command */ enum sev_cmd_id {
Signature · 1 line
2.17.1