Commit 91d78497 authored by hanliyang's avatar hanliyang
Browse files

KVM: x86: Restore control registers in __set_sregs() to support CSV2 guest live migration

hygon inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I98WBH


CVE: NA

---------------------------

When migrate CSV2 guest to the recipient, the KVM which on
recipient's side needs to update the guest context so that the guest
can continues to run. The control register state is necessary for
updating the guest context.

Allows the control registers to be updated in __set_sregs() so that
the CSV2 guest could continue running correctly after migrated to
the recipient.

Signed-off-by: default avatarhanliyang <hanliyang@hygon.cn>
parent d4c3f02a
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -11623,8 +11623,16 @@ static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs,
	if (kvm_set_apic_base(vcpu, &apic_base_msr))
		return -EINVAL;

	if (vcpu->arch.guest_state_protected)
	if (vcpu->arch.guest_state_protected) {
		/*
		 * For HYGON CSV2 guest, we need update some regs to support
		 * live migration.
		 */
		if (is_x86_vendor_hygon())
			goto skip_dt_cr2_cr3;

		return 0;
	}

	dt.size = sregs->idt.limit;
	dt.address = sregs->idt.base;
@@ -11639,6 +11647,7 @@ static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs,
	kvm_register_mark_dirty(vcpu, VCPU_EXREG_CR3);
	static_call_cond(kvm_x86_post_set_cr3)(vcpu, sregs->cr3);

skip_dt_cr2_cr3:
	kvm_set_cr8(vcpu, sregs->cr8);

	*mmu_reset_needed |= vcpu->arch.efer != sregs->efer;
@@ -11651,6 +11660,9 @@ static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs,
	*mmu_reset_needed |= kvm_read_cr4(vcpu) != sregs->cr4;
	static_call(kvm_x86_set_cr4)(vcpu, sregs->cr4);

	if (vcpu->arch.guest_state_protected)
		return 0;

	if (update_pdptrs) {
		idx = srcu_read_lock(&vcpu->kvm->srcu);
		if (is_pae_paging(vcpu)) {