@@ -1651,6 +1651,61 @@ static void vmx_update_hfi_table(struct kvm *kvm)
vmx_inject_therm_interrupt(kvm_get_vcpu(kvm, 0));
}
+static void vmx_hfi_notifier_register(struct kvm *kvm)
+{
+ struct kvm_vmx *kvm_vmx = to_kvm_vmx(kvm);
+ struct hfi_desc *kvm_vmx_hfi = &kvm_vmx->pkg_therm.hfi_desc;
+
+ if (!intel_hfi_enabled())
+ return;
+
+ if (!vmx_hfi_initialized(kvm_vmx))
+ return;
+
+ if (kvm_vmx_hfi->has_hfi_instance)
+ return;
+
+ /*
+ * HFI/ITD virtualization is supported on the platforms with only
+ * 1 HFI instance. Just register notifier for vCPU 0.
+ */
+ kvm_vmx_hfi->has_hfi_instance =
+ !intel_hfi_notifier_register(&kvm_vmx_hfi->hfi_nb,
+ kvm_get_vcpu(kvm, 0)->cpu);
+}
+
+static void vmx_hfi_notifier_unregister(struct kvm *kvm)
+{
+ struct kvm_vmx *kvm_vmx = to_kvm_vmx(kvm);
+ struct hfi_desc *kvm_vmx_hfi = &kvm_vmx->pkg_therm.hfi_desc;
+
+ if (!kvm_vmx_hfi->has_hfi_instance)
+ return;
+
+ intel_hfi_notifier_unregister(&kvm_vmx_hfi->hfi_nb,
+ kvm_get_vcpu(kvm, 0)->cpu);
+ kvm_vmx_hfi->has_hfi_instance = false;
+}
+
+static int vmx_hfi_update_notify(struct notifier_block *nb,
+ unsigned long code, void *data)
+{
+ struct hfi_desc *kvm_vmx_hfi;
+ struct kvm *kvm;
+
+ kvm_vmx_hfi = container_of(nb, struct hfi_desc, hfi_nb);
+ kvm = &kvm_vmx_hfi->vmx->kvm;
+
+ /*
+ * Don't need to check if vcpu 0 belongs to
+ * kvm_vmx_hfi->host_hfi_instance since currently ITD/HFI
+ * virtualization is only supported for client platforms
+ * (with only one HFI instance).
+ */
+ kvm_make_request(KVM_REQ_HFI_UPDATE, kvm_get_vcpu(kvm, 0));
+ return NOTIFY_OK;
+}
+
static void vmx_dynamic_update_hfi_table(struct kvm_vcpu *vcpu)
{
struct kvm_vmx *kvm_vmx = to_kvm_vmx(vcpu->kvm);
@@ -7871,8 +7926,11 @@ static int vmx_vcpu_create(struct kvm_vcpu *vcpu)
static int vmx_vm_init_pkg_therm(struct kvm *kvm)
{
struct pkg_therm_desc *pkg_therm = &to_kvm_vmx(kvm)->pkg_therm;
+ struct hfi_desc *kvm_vmx_hfi = &pkg_therm->hfi_desc;
mutex_init(&pkg_therm->pkg_therm_lock);
+ kvm_vmx_hfi->hfi_nb.notifier_call = vmx_hfi_update_notify;
+ kvm_vmx_hfi->vmx = to_kvm_vmx(kvm);
return 0;
}
@@ -8542,6 +8600,7 @@ static void vmx_vm_destroy(struct kvm *kvm)
struct kvm_vmx *kvm_vmx = to_kvm_vmx(kvm);
struct hfi_desc *kvm_vmx_hfi = &kvm_vmx->pkg_therm.hfi_desc;
+ vmx_hfi_notifier_unregister(kvm);
kfree(kvm_vmx_hfi->hfi_table.base_addr);
free_pages((unsigned long)kvm_vmx->pid_table, vmx_get_pid_table_order(kvm));
}
@@ -395,6 +395,11 @@ struct vcpu_vmx {
* the vCPU is running on.
* When KVM updates the Guest's HFI table, it writes the local
* virtual HFI table to the Guest HFI table memory in @table_base.
+ * @has_hfi_instance: Flag indicates if VM registers @hfi_nb on Host's HFI instance.
+ * @hfi_nb: Notifier block to be registered in Host HFI instance.
+ * @vmx: Points to the kvm_vmx where the current nb is located.
+ * Used to get the corresponding kvm_vmx of the nb when it
+ * is executed.
*
* A set of status flags and feature information, used to maintain local virtual HFI table
* and sync updates to Guest HFI table.
@@ -409,6 +414,9 @@ struct hfi_desc {
gpa_t table_base;
struct hfi_features hfi_features;
struct hfi_table hfi_table;
+ bool has_hfi_instance;
+ struct notifier_block hfi_nb;
+ struct kvm_vmx *vmx;
};
struct pkg_therm_desc {