diff mbox series

[v3,13/22] KVM: x86: Annotate -EFAULTs from kvm_hv_get_assist_page()

Message ID 20230412213510.1220557-14-amoorthy@google.com (mailing list archive)
State New, archived
Headers show
Series Improve scalability of KVM + userfaultfd live migration via annotated memory faults. | expand

Commit Message

Anish Moorthy April 12, 2023, 9:35 p.m. UTC
Implement KVM_CAP_MEMORY_FAULT_INFO for efaults generated by
kvm_hv_get_assist_page().

Signed-off-by: Anish Moorthy <amoorthy@google.com>
---
 arch/x86/kvm/hyperv.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index b28fd020066f6..467fff271bc88 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -921,13 +921,21 @@  EXPORT_SYMBOL_GPL(kvm_hv_assist_page_enabled);
 
 int kvm_hv_get_assist_page(struct kvm_vcpu *vcpu)
 {
+	int ret = -EFAULT;
 	struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
 
 	if (!hv_vcpu || !kvm_hv_assist_page_enabled(vcpu))
-		return -EFAULT;
+		goto out;
+
+	ret = kvm_read_guest_cached(vcpu->kvm, &vcpu->arch.pv_eoi.data,
+								&hv_vcpu->vp_assist_page,
+								sizeof(struct hv_vp_assist_page));
 
-	return kvm_read_guest_cached(vcpu->kvm, &vcpu->arch.pv_eoi.data,
-				     &hv_vcpu->vp_assist_page, sizeof(struct hv_vp_assist_page));
+out:
+	if (ret == -EFAULT)
+		kvm_populate_efault_info(vcpu, vcpu->arch.pv_eoi.data.gpa,
+								 vcpu->arch.pv_eoi.data.len);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(kvm_hv_get_assist_page);