Commit 22a8a353 authored by hanliyang's avatar hanliyang
Browse files

KVM: x86: Introduce control_{pre,post}_system_reset ioctl interfaces

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


CVE: NA

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

In the upcoming patches, we will support for rebooting CSV2 guests. In
order to support rebooting CSV2 guest, we will set
vcpu->arch.guest_state_protected to false, before VMRUN, so that VMM
can initialize vCPU states and VMSA, and then set
vcpu->arch.guest_state_protected back to true to bypass unexpected
behaviour in KVM. Besides, cache flush is necessary during rebooting a
memory encrypted guest.

Introduce control_{pre,post}_system_reset ioctl interfaces to support
rebooting memory encrypted guests correctly.

Signed-off-by: default avatarhanliyang <hanliyang@hygon.cn>
parent 8cb8b512
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -137,6 +137,8 @@ KVM_X86_OP(vcpu_deliver_sipi_vector)
KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons);
KVM_X86_OP_OPTIONAL(get_untagged_addr)
KVM_X86_OP_OPTIONAL(vm_attestation)
KVM_X86_OP_OPTIONAL(control_pre_system_reset)
KVM_X86_OP_OPTIONAL(control_post_system_reset)

#undef KVM_X86_OP
#undef KVM_X86_OP_OPTIONAL
+3 −1
Original line number Diff line number Diff line
@@ -1773,9 +1773,11 @@ struct kvm_x86_ops {
	gva_t (*get_untagged_addr)(struct kvm_vcpu *vcpu, gva_t gva, unsigned int flags);

	/*
	 * Attestation interface for HYGON CSV guest
	 * Interfaces for HYGON CSV guest
	 */
	int (*vm_attestation)(struct kvm *kvm, unsigned long gpa, unsigned long len);
	int (*control_pre_system_reset)(struct kvm *kvm);
	int (*control_post_system_reset)(struct kvm *kvm);
};

struct kvm_x86_nested_ops {
+12 −0
Original line number Diff line number Diff line
@@ -973,6 +973,16 @@ bool csv_has_emulated_ghcb_msr(struct kvm *kvm)
	return true;
}

static int csv_control_pre_system_reset(struct kvm *kvm)
{
	return 0;
}

static int csv_control_post_system_reset(struct kvm *kvm)
{
	return 0;
}

void csv_exit(void)
{
}
@@ -990,4 +1000,6 @@ void __init csv_init(struct kvm_x86_ops *ops)

	ops->mem_enc_ioctl = csv_mem_enc_ioctl;
	ops->vm_attestation = csv_vm_attestation;
	ops->control_pre_system_reset = csv_control_pre_system_reset;
	ops->control_post_system_reset = csv_control_post_system_reset;
}
+12 −0
Original line number Diff line number Diff line
@@ -7194,6 +7194,18 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
		r = kvm_vm_ioctl_set_msr_filter(kvm, &filter);
		break;
	}
	case KVM_CONTROL_PRE_SYSTEM_RESET:
		if (kvm_x86_ops.control_pre_system_reset)
			r = static_call(kvm_x86_control_pre_system_reset)(kvm);
		else
			r = -ENOTTY;
		break;
	case KVM_CONTROL_POST_SYSTEM_RESET:
		if (kvm_x86_ops.control_post_system_reset)
			r = static_call(kvm_x86_control_post_system_reset)(kvm);
		else
			r = -ENOTTY;
		break;
	default:
		r = -ENOTTY;
	}
+4 −0
Original line number Diff line number Diff line
@@ -2334,4 +2334,8 @@ struct kvm_csv_receive_update_vmsa {
	__u32 trans_len;
};

/* ioctls for control vm during system reset, currently only for CSV */
#define KVM_CONTROL_PRE_SYSTEM_RESET	 _IO(KVMIO, 0xe8)
#define KVM_CONTROL_POST_SYSTEM_RESET	 _IO(KVMIO, 0xe9)

#endif /* __LINUX_KVM_H */