Skip to content

Commit 73f1b4f

Browse files
ashkalrabonzini
authored andcommitted
x86/kvm: Add kexec support for SEV Live Migration.
Reset the host's shared pages list related to kernel specific page encryption status settings before we load a new kernel by kexec. We cannot reset the complete shared pages list here as we need to retain the UEFI/OVMF firmware specific settings. The host's shared pages list is maintained for the guest to keep track of all unencrypted guest memory regions, therefore we need to explicitly mark all shared pages as encrypted again before rebooting into the new guest kernel. Signed-off-by: Ashish Kalra <[email protected]> Reviewed-by: Steve Rutherford <[email protected]> Message-Id: <3e051424ab839ea470f88333273d7a185006754f.1629726117.git.ashish.kalra@amd.com> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent f449561 commit 73f1b4f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

arch/x86/kernel/kvm.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,10 +869,35 @@ static void __init kvm_init_platform(void)
869869
if (sev_active() &&
870870
kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL)) {
871871
unsigned long nr_pages;
872+
int i;
872873

873874
pv_ops.mmu.notify_page_enc_status_changed =
874875
kvm_sev_hc_page_enc_status;
875876

877+
/*
878+
* Reset the host's shared pages list related to kernel
879+
* specific page encryption status settings before we load a
880+
* new kernel by kexec. Reset the page encryption status
881+
* during early boot intead of just before kexec to avoid SMP
882+
* races during kvm_pv_guest_cpu_reboot().
883+
* NOTE: We cannot reset the complete shared pages list
884+
* here as we need to retain the UEFI/OVMF firmware
885+
* specific settings.
886+
*/
887+
888+
for (i = 0; i < e820_table->nr_entries; i++) {
889+
struct e820_entry *entry = &e820_table->entries[i];
890+
891+
if (entry->type != E820_TYPE_RAM)
892+
continue;
893+
894+
nr_pages = DIV_ROUND_UP(entry->size, PAGE_SIZE);
895+
896+
kvm_sev_hypercall3(KVM_HC_MAP_GPA_RANGE, entry->addr,
897+
nr_pages,
898+
KVM_MAP_GPA_RANGE_ENCRYPTED | KVM_MAP_GPA_RANGE_PAGE_SZ_4K);
899+
}
900+
876901
/*
877902
* Ensure that _bss_decrypted section is marked as decrypted in the
878903
* shared pages list.

0 commit comments

Comments
 (0)