qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls
@ 2016-01-21 14:01 Andrey Smetanin
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 1/5] kvm/x86: Rename Hyper-V long spin wait hypercall Andrey Smetanin
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Andrey Smetanin @ 2016-01-21 14:01 UTC (permalink / raw)
  To: kvm
  Cc: Gleb Natapov, Joerg Roedel, qemu-devel, Roman Kagan,
	Denis V. Lunev, Paolo Bonzini, K. Y. Srinivasan, Haiyang Zhang

The patch implements userspace exit 'KVM_EXIT_HYPERV'
for Hyper-V VMBus hypercalls(postmsg, signalevent)
to handle these hypercalls by QEMU.

Changes v2:
* use KVM_EXIT_HYPERV for hypercalls

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
CC: Gleb Natapov <gleb@kernel.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Joerg Roedel <joro@8bytes.org>
CC: "K. Y. Srinivasan" <kys@microsoft.com>
CC: Haiyang Zhang <haiyangz@microsoft.com>
CC: Roman Kagan <rkagan@virtuozzo.com>
CC: Denis V. Lunev <den@openvz.org>
CC: qemu-devel@nongnu.org

Andrey Smetanin (5):
  kvm/x86: Rename Hyper-V long spin wait hypercall
  drivers/hv: Move VMBus hypercall codes into Hyper-V UAPI header
  kvm/x86: Pass return code of kvm_emulate_hypercall
  kvm/x86: Reject Hyper-V hypercall continuation
  kvm/x86: Hyper-V VMBus hypercall userspace exit

 Documentation/virtual/kvm/api.txt  |  6 ++++++
 arch/x86/include/uapi/asm/hyperv.h |  4 +++-
 arch/x86/kvm/hyperv.c              | 40 +++++++++++++++++++++++++++++---------
 arch/x86/kvm/hyperv.h              |  1 +
 arch/x86/kvm/svm.c                 |  3 +--
 arch/x86/kvm/vmx.c                 |  3 +--
 arch/x86/kvm/x86.c                 |  5 +++++
 drivers/hv/hv.c                    |  4 ++--
 drivers/hv/hyperv_vmbus.h          |  6 ------
 include/uapi/linux/kvm.h           |  6 ++++++
 10 files changed, 56 insertions(+), 22 deletions(-)

-- 
2.4.3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v2 1/5] kvm/x86: Rename Hyper-V long spin wait hypercall
  2016-01-21 14:01 [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin
@ 2016-01-21 14:01 ` Andrey Smetanin
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 2/5] drivers/hv: Move VMBus hypercall codes into Hyper-V UAPI header Andrey Smetanin
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Andrey Smetanin @ 2016-01-21 14:01 UTC (permalink / raw)
  To: kvm
  Cc: Gleb Natapov, Joerg Roedel, qemu-devel, Roman Kagan,
	Denis V. Lunev, Paolo Bonzini, K. Y. Srinivasan, Haiyang Zhang

Rename HV_X64_HV_NOTIFY_LONG_SPIN_WAIT
by HV_X64_HCALL_NOTIFY_LONG_SPIN_WAIT. So
the name better reflects hypercall codes accessory.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
CC: Gleb Natapov <gleb@kernel.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Joerg Roedel <joro@8bytes.org>
CC: "K. Y. Srinivasan" <kys@microsoft.com>
CC: Haiyang Zhang <haiyangz@microsoft.com>
CC: Roman Kagan <rkagan@virtuozzo.com>
CC: Denis V. Lunev <den@openvz.org>
CC: qemu-devel@nongnu.org
---
 arch/x86/include/uapi/asm/hyperv.h | 2 +-
 arch/x86/kvm/hyperv.c              | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h
index 7956412..0c50fab 100644
--- a/arch/x86/include/uapi/asm/hyperv.h
+++ b/arch/x86/include/uapi/asm/hyperv.h
@@ -226,7 +226,7 @@
 		(~((1ull << HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT) - 1))
 
 /* Declare the various hypercall operations. */
-#define HV_X64_HV_NOTIFY_LONG_SPIN_WAIT		0x0008
+#define HV_X64_HCALL_NOTIFY_LONG_SPIN_WAIT		0x0008
 
 #define HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE		0x00000001
 #define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT	12
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index c58ba67..f1a42e1 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -1084,7 +1084,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 	trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa);
 
 	switch (code) {
-	case HV_X64_HV_NOTIFY_LONG_SPIN_WAIT:
+	case HV_X64_HCALL_NOTIFY_LONG_SPIN_WAIT:
 		kvm_vcpu_on_spin(vcpu);
 		break;
 	default:
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v2 2/5] drivers/hv: Move VMBus hypercall codes into Hyper-V UAPI header
  2016-01-21 14:01 [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 1/5] kvm/x86: Rename Hyper-V long spin wait hypercall Andrey Smetanin
@ 2016-01-21 14:01 ` Andrey Smetanin
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 3/5] kvm/x86: Pass return code of kvm_emulate_hypercall Andrey Smetanin
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Andrey Smetanin @ 2016-01-21 14:01 UTC (permalink / raw)
  To: kvm
  Cc: Gleb Natapov, Joerg Roedel, qemu-devel, Roman Kagan,
	Denis V. Lunev, Paolo Bonzini, K. Y. Srinivasan, Haiyang Zhang

VMBus hypercall codes inside Hyper-V UAPI header will
be used by QEMU to implement VMBus host devices support.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Acked-by: K. Y. Srinivasan <kys@microsoft.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
CC: Gleb Natapov <gleb@kernel.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Joerg Roedel <joro@8bytes.org>
CC: "K. Y. Srinivasan" <kys@microsoft.com>
CC: Haiyang Zhang <haiyangz@microsoft.com>
CC: Roman Kagan <rkagan@virtuozzo.com>
CC: Denis V. Lunev <den@openvz.org>
CC: qemu-devel@nongnu.org
---
 arch/x86/include/uapi/asm/hyperv.h | 2 ++
 drivers/hv/hv.c                    | 4 ++--
 drivers/hv/hyperv_vmbus.h          | 6 ------
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h
index 0c50fab..bc1c8a9 100644
--- a/arch/x86/include/uapi/asm/hyperv.h
+++ b/arch/x86/include/uapi/asm/hyperv.h
@@ -227,6 +227,8 @@
 
 /* Declare the various hypercall operations. */
 #define HV_X64_HCALL_NOTIFY_LONG_SPIN_WAIT		0x0008
+#define HV_X64_HCALL_POST_MESSAGE			0x005c
+#define HV_X64_HCALL_SIGNAL_EVENT			0x005d
 
 #define HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE		0x00000001
 #define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT	12
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 11bca51..5ce2dec 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -331,7 +331,7 @@ int hv_post_message(union hv_connection_id connection_id,
 	aligned_msg->payload_size = payload_size;
 	memcpy((void *)aligned_msg->payload, payload, payload_size);
 
-	status = hv_do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL);
+	status = hv_do_hypercall(HV_X64_HCALL_POST_MESSAGE, aligned_msg, NULL);
 
 	put_cpu();
 	return status & 0xFFFF;
@@ -348,7 +348,7 @@ int hv_signal_event(void *con_id)
 {
 	u64 status;
 
-	status = hv_do_hypercall(HVCALL_SIGNAL_EVENT, con_id, NULL);
+	status = hv_do_hypercall(HV_X64_HCALL_SIGNAL_EVENT, con_id, NULL);
 
 	return status & 0xFFFF;
 }
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 4ebc796..2f8c0f4 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -256,12 +256,6 @@ struct hv_monitor_page {
 	u8 rsvdz4[1984];
 };
 
-/* Declare the various hypercall operations. */
-enum hv_call_code {
-	HVCALL_POST_MESSAGE	= 0x005c,
-	HVCALL_SIGNAL_EVENT	= 0x005d,
-};
-
 /* Definition of the hv_post_message hypercall input structure. */
 struct hv_input_post_message {
 	union hv_connection_id connectionid;
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v2 3/5] kvm/x86: Pass return code of kvm_emulate_hypercall
  2016-01-21 14:01 [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 1/5] kvm/x86: Rename Hyper-V long spin wait hypercall Andrey Smetanin
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 2/5] drivers/hv: Move VMBus hypercall codes into Hyper-V UAPI header Andrey Smetanin
@ 2016-01-21 14:01 ` Andrey Smetanin
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 4/5] kvm/x86: Reject Hyper-V hypercall continuation Andrey Smetanin
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Andrey Smetanin @ 2016-01-21 14:01 UTC (permalink / raw)
  To: kvm
  Cc: Gleb Natapov, Joerg Roedel, qemu-devel, Roman Kagan,
	Denis V. Lunev, Paolo Bonzini, K. Y. Srinivasan, Haiyang Zhang

Pass the return code from kvm_emulate_hypercall on to the caller,
in order to allow it to indicate to the userspace that
the hypercall has to be handled there.

Also adjust all the existing code paths to return 1 to make sure the
hypercall isn't passed to the userspace without setting kvm_run
appropriately.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
CC: Gleb Natapov <gleb@kernel.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Joerg Roedel <joro@8bytes.org>
CC: "K. Y. Srinivasan" <kys@microsoft.com>
CC: Haiyang Zhang <haiyangz@microsoft.com>
CC: Roman Kagan <rkagan@virtuozzo.com>
CC: Denis V. Lunev <den@openvz.org>
CC: qemu-devel@nongnu.org
---
 arch/x86/kvm/hyperv.c | 2 +-
 arch/x86/kvm/svm.c    | 3 +--
 arch/x86/kvm/vmx.c    | 3 +--
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index f1a42e1..0e7c90f 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -1055,7 +1055,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 	 */
 	if (kvm_x86_ops->get_cpl(vcpu) != 0 || !is_protmode(vcpu)) {
 		kvm_queue_exception(vcpu, UD_VECTOR);
-		return 0;
+		return 1;
 	}
 
 	longmode = is_64_bit_mode(vcpu);
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index c13a64b..9507038 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1858,8 +1858,7 @@ static int halt_interception(struct vcpu_svm *svm)
 static int vmmcall_interception(struct vcpu_svm *svm)
 {
 	svm->next_rip = kvm_rip_read(&svm->vcpu) + 3;
-	kvm_emulate_hypercall(&svm->vcpu);
-	return 1;
+	return kvm_emulate_hypercall(&svm->vcpu);
 }
 
 static unsigned long nested_svm_get_tdp_cr3(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 04d61d4..82879aa 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -5747,8 +5747,7 @@ static int handle_halt(struct kvm_vcpu *vcpu)
 
 static int handle_vmcall(struct kvm_vcpu *vcpu)
 {
-	kvm_emulate_hypercall(vcpu);
-	return 1;
+	return kvm_emulate_hypercall(vcpu);
 }
 
 static int handle_invd(struct kvm_vcpu *vcpu)
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v2 4/5] kvm/x86: Reject Hyper-V hypercall continuation
  2016-01-21 14:01 [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin
                   ` (2 preceding siblings ...)
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 3/5] kvm/x86: Pass return code of kvm_emulate_hypercall Andrey Smetanin
@ 2016-01-21 14:01 ` Andrey Smetanin
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 5/5] kvm/x86: Hyper-V VMBus hypercall userspace exit Andrey Smetanin
  2016-02-02 11:34 ` [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin
  5 siblings, 0 replies; 8+ messages in thread
From: Andrey Smetanin @ 2016-01-21 14:01 UTC (permalink / raw)
  To: kvm
  Cc: Gleb Natapov, Joerg Roedel, qemu-devel, Roman Kagan,
	Denis V. Lunev, Paolo Bonzini, K. Y. Srinivasan, Haiyang Zhang

Currently we do not support Hyper-V hypercall continuation
so reject it.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
CC: Gleb Natapov <gleb@kernel.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Joerg Roedel <joro@8bytes.org>
CC: "K. Y. Srinivasan" <kys@microsoft.com>
CC: Haiyang Zhang <haiyangz@microsoft.com>
CC: Roman Kagan <rkagan@virtuozzo.com>
CC: Denis V. Lunev <den@openvz.org>
CC: qemu-devel@nongnu.org
---
 arch/x86/kvm/hyperv.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 0e7c90f..e1daa8b 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -1083,6 +1083,12 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 
 	trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa);
 
+	/* Hypercall continuation is not supported yet */
+	if (rep_cnt || rep_idx) {
+		res = HV_STATUS_INVALID_HYPERCALL_CODE;
+		goto set_result;
+	}
+
 	switch (code) {
 	case HV_X64_HCALL_NOTIFY_LONG_SPIN_WAIT:
 		kvm_vcpu_on_spin(vcpu);
@@ -1092,6 +1098,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 		break;
 	}
 
+set_result:
 	ret = res | (((u64)rep_done & 0xfff) << 32);
 	if (longmode) {
 		kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v2 5/5] kvm/x86: Hyper-V VMBus hypercall userspace exit
  2016-01-21 14:01 [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin
                   ` (3 preceding siblings ...)
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 4/5] kvm/x86: Reject Hyper-V hypercall continuation Andrey Smetanin
@ 2016-01-21 14:01 ` Andrey Smetanin
  2016-02-10 16:48   ` Paolo Bonzini
  2016-02-02 11:34 ` [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin
  5 siblings, 1 reply; 8+ messages in thread
From: Andrey Smetanin @ 2016-01-21 14:01 UTC (permalink / raw)
  To: kvm
  Cc: Gleb Natapov, Joerg Roedel, qemu-devel, Roman Kagan,
	Denis V. Lunev, Paolo Bonzini, K. Y. Srinivasan, Haiyang Zhang

The patch implements KVM_EXIT_HYPERV userspace exit
functionality for Hyper-V VMBus hypercalls:
HV_X64_HCALL_POST_MESSAGE, HV_X64_HCALL_SIGNAL_EVENT.

Changes v2:
* use KVM_EXIT_HYPERV for hypercalls

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
CC: Gleb Natapov <gleb@kernel.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Joerg Roedel <joro@8bytes.org>
CC: "K. Y. Srinivasan" <kys@microsoft.com>
CC: Haiyang Zhang <haiyangz@microsoft.com>
CC: Roman Kagan <rkagan@virtuozzo.com>
CC: Denis V. Lunev <den@openvz.org>
CC: qemu-devel@nongnu.org
---
 Documentation/virtual/kvm/api.txt |  6 ++++++
 arch/x86/kvm/hyperv.c             | 29 ++++++++++++++++++++++-------
 arch/x86/kvm/hyperv.h             |  1 +
 arch/x86/kvm/x86.c                |  5 +++++
 include/uapi/linux/kvm.h          |  6 ++++++
 5 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 053f613..1bf1a07 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -3339,6 +3339,7 @@ EOI was received.
 
 		struct kvm_hyperv_exit {
 #define KVM_EXIT_HYPERV_SYNIC          1
+#define KVM_EXIT_HYPERV_HCALL          2
 			__u32 type;
 			union {
 				struct {
@@ -3347,6 +3348,11 @@ EOI was received.
 					__u64 evt_page;
 					__u64 msg_page;
 				} synic;
+				struct {
+					__u64 input;
+					__u64 result;
+					__u64 params[2];
+				} hcall;
 			} u;
 		};
 		/* KVM_EXIT_HYPERV */
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index e1daa8b..26ae973 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -1093,6 +1093,14 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 	case HV_X64_HCALL_NOTIFY_LONG_SPIN_WAIT:
 		kvm_vcpu_on_spin(vcpu);
 		break;
+	case HV_X64_HCALL_POST_MESSAGE:
+	case HV_X64_HCALL_SIGNAL_EVENT:
+		vcpu->run->exit_reason = KVM_EXIT_HYPERV;
+		vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL;
+		vcpu->run->hyperv.u.hcall.input = param;
+		vcpu->run->hyperv.u.hcall.params[0] = ingpa;
+		vcpu->run->hyperv.u.hcall.params[1] = outgpa;
+		return 0;
 	default:
 		res = HV_STATUS_INVALID_HYPERCALL_CODE;
 		break;
@@ -1100,12 +1108,19 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 
 set_result:
 	ret = res | (((u64)rep_done & 0xfff) << 32);
-	if (longmode) {
-		kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
-	} else {
-		kvm_register_write(vcpu, VCPU_REGS_RDX, ret >> 32);
-		kvm_register_write(vcpu, VCPU_REGS_RAX, ret & 0xffffffff);
-	}
-
+	kvm_hv_hypercall_set_result(vcpu, ret);
 	return 1;
 }
+
+void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result)
+{
+	bool longmode;
+
+	longmode = is_64_bit_mode(vcpu);
+	if (longmode)
+		kvm_register_write(vcpu, VCPU_REGS_RAX, result);
+	else {
+		kvm_register_write(vcpu, VCPU_REGS_RDX, result >> 32);
+		kvm_register_write(vcpu, VCPU_REGS_RAX, result & 0xffffffff);
+	}
+}
diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
index 60eccd4..64a4a3b 100644
--- a/arch/x86/kvm/hyperv.h
+++ b/arch/x86/kvm/hyperv.h
@@ -52,6 +52,7 @@ int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
 
 bool kvm_hv_hypercall_enabled(struct kvm *kvm);
 int kvm_hv_hypercall(struct kvm_vcpu *vcpu);
+void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result);
 
 void kvm_hv_irq_routing_update(struct kvm *kvm);
 int kvm_hv_synic_set_irq(struct kvm *kvm, u32 vcpu_id, u32 sint);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index f53f5b1..e5c842b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6891,6 +6891,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 	} else
 		WARN_ON(vcpu->arch.pio.count || vcpu->mmio_needed);
 
+	if (unlikely(kvm_run->exit_reason == KVM_EXIT_HYPERV) &&
+	    kvm_run->hyperv.type == KVM_EXIT_HYPERV_HCALL)
+		kvm_hv_hypercall_set_result(vcpu,
+					    kvm_run->hyperv.u.hcall.result);
+
 	r = vcpu_run(vcpu);
 
 out:
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 9da9051..c5519a9 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -157,6 +157,7 @@ struct kvm_s390_skeys {
 
 struct kvm_hyperv_exit {
 #define KVM_EXIT_HYPERV_SYNIC          1
+#define KVM_EXIT_HYPERV_HCALL          2
 	__u32 type;
 	union {
 		struct {
@@ -165,6 +166,11 @@ struct kvm_hyperv_exit {
 			__u64 evt_page;
 			__u64 msg_page;
 		} synic;
+		struct {
+			__u64 input;
+			__u64 result;
+			__u64 params[2];
+		} hcall;
 	} u;
 };
 
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls
  2016-01-21 14:01 [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin
                   ` (4 preceding siblings ...)
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 5/5] kvm/x86: Hyper-V VMBus hypercall userspace exit Andrey Smetanin
@ 2016-02-02 11:34 ` Andrey Smetanin
  5 siblings, 0 replies; 8+ messages in thread
From: Andrey Smetanin @ 2016-02-02 11:34 UTC (permalink / raw)
  To: kvm
  Cc: Gleb Natapov, Joerg Roedel, qemu-devel, Roman Kagan,
	Denis V. Lunev, Paolo Bonzini, K. Y. Srinivasan, Haiyang Zhang

ping

On 01/21/2016 05:01 PM, Andrey Smetanin wrote:
> The patch implements userspace exit 'KVM_EXIT_HYPERV'
> for Hyper-V VMBus hypercalls(postmsg, signalevent)
> to handle these hypercalls by QEMU.
>
> Changes v2:
> * use KVM_EXIT_HYPERV for hypercalls
>
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
> CC: Gleb Natapov <gleb@kernel.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Joerg Roedel <joro@8bytes.org>
> CC: "K. Y. Srinivasan" <kys@microsoft.com>
> CC: Haiyang Zhang <haiyangz@microsoft.com>
> CC: Roman Kagan <rkagan@virtuozzo.com>
> CC: Denis V. Lunev <den@openvz.org>
> CC: qemu-devel@nongnu.org
>
> Andrey Smetanin (5):
>    kvm/x86: Rename Hyper-V long spin wait hypercall
>    drivers/hv: Move VMBus hypercall codes into Hyper-V UAPI header
>    kvm/x86: Pass return code of kvm_emulate_hypercall
>    kvm/x86: Reject Hyper-V hypercall continuation
>    kvm/x86: Hyper-V VMBus hypercall userspace exit
>
>   Documentation/virtual/kvm/api.txt  |  6 ++++++
>   arch/x86/include/uapi/asm/hyperv.h |  4 +++-
>   arch/x86/kvm/hyperv.c              | 40 +++++++++++++++++++++++++++++---------
>   arch/x86/kvm/hyperv.h              |  1 +
>   arch/x86/kvm/svm.c                 |  3 +--
>   arch/x86/kvm/vmx.c                 |  3 +--
>   arch/x86/kvm/x86.c                 |  5 +++++
>   drivers/hv/hv.c                    |  4 ++--
>   drivers/hv/hyperv_vmbus.h          |  6 ------
>   include/uapi/linux/kvm.h           |  6 ++++++
>   10 files changed, 56 insertions(+), 22 deletions(-)
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2 5/5] kvm/x86: Hyper-V VMBus hypercall userspace exit
  2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 5/5] kvm/x86: Hyper-V VMBus hypercall userspace exit Andrey Smetanin
@ 2016-02-10 16:48   ` Paolo Bonzini
  0 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2016-02-10 16:48 UTC (permalink / raw)
  To: Andrey Smetanin, kvm
  Cc: Gleb Natapov, Joerg Roedel, qemu-devel, Roman Kagan,
	Denis V. Lunev, K. Y. Srinivasan, Haiyang Zhang



On 21/01/2016 15:01, Andrey Smetanin wrote:
> The patch implements KVM_EXIT_HYPERV userspace exit
> functionality for Hyper-V VMBus hypercalls:
> HV_X64_HCALL_POST_MESSAGE, HV_X64_HCALL_SIGNAL_EVENT.
> 
> Changes v2:
> * use KVM_EXIT_HYPERV for hypercalls
> 
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
> CC: Gleb Natapov <gleb@kernel.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Joerg Roedel <joro@8bytes.org>
> CC: "K. Y. Srinivasan" <kys@microsoft.com>
> CC: Haiyang Zhang <haiyangz@microsoft.com>
> CC: Roman Kagan <rkagan@virtuozzo.com>
> CC: Denis V. Lunev <den@openvz.org>
> CC: qemu-devel@nongnu.org
> ---
>  Documentation/virtual/kvm/api.txt |  6 ++++++
>  arch/x86/kvm/hyperv.c             | 29 ++++++++++++++++++++++-------
>  arch/x86/kvm/hyperv.h             |  1 +
>  arch/x86/kvm/x86.c                |  5 +++++
>  include/uapi/linux/kvm.h          |  6 ++++++
>  5 files changed, 40 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
> index 053f613..1bf1a07 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -3339,6 +3339,7 @@ EOI was received.
>  
>  		struct kvm_hyperv_exit {
>  #define KVM_EXIT_HYPERV_SYNIC          1
> +#define KVM_EXIT_HYPERV_HCALL          2
>  			__u32 type;
>  			union {
>  				struct {
> @@ -3347,6 +3348,11 @@ EOI was received.
>  					__u64 evt_page;
>  					__u64 msg_page;
>  				} synic;
> +				struct {
> +					__u64 input;
> +					__u64 result;
> +					__u64 params[2];
> +				} hcall;
>  			} u;
>  		};
>  		/* KVM_EXIT_HYPERV */
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index e1daa8b..26ae973 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -1093,6 +1093,14 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
>  	case HV_X64_HCALL_NOTIFY_LONG_SPIN_WAIT:
>  		kvm_vcpu_on_spin(vcpu);
>  		break;
> +	case HV_X64_HCALL_POST_MESSAGE:
> +	case HV_X64_HCALL_SIGNAL_EVENT:
> +		vcpu->run->exit_reason = KVM_EXIT_HYPERV;
> +		vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL;
> +		vcpu->run->hyperv.u.hcall.input = param;
> +		vcpu->run->hyperv.u.hcall.params[0] = ingpa;
> +		vcpu->run->hyperv.u.hcall.params[1] = outgpa;
> +		return 0;
>  	default:
>  		res = HV_STATUS_INVALID_HYPERCALL_CODE;
>  		break;
> @@ -1100,12 +1108,19 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
>  
>  set_result:
>  	ret = res | (((u64)rep_done & 0xfff) << 32);
> -	if (longmode) {
> -		kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
> -	} else {
> -		kvm_register_write(vcpu, VCPU_REGS_RDX, ret >> 32);
> -		kvm_register_write(vcpu, VCPU_REGS_RAX, ret & 0xffffffff);
> -	}
> -
> +	kvm_hv_hypercall_set_result(vcpu, ret);
>  	return 1;
>  }
> +
> +void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result)
> +{
> +	bool longmode;
> +
> +	longmode = is_64_bit_mode(vcpu);
> +	if (longmode)
> +		kvm_register_write(vcpu, VCPU_REGS_RAX, result);
> +	else {
> +		kvm_register_write(vcpu, VCPU_REGS_RDX, result >> 32);
> +		kvm_register_write(vcpu, VCPU_REGS_RAX, result & 0xffffffff);
> +	}
> +}
> diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
> index 60eccd4..64a4a3b 100644
> --- a/arch/x86/kvm/hyperv.h
> +++ b/arch/x86/kvm/hyperv.h
> @@ -52,6 +52,7 @@ int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
>  
>  bool kvm_hv_hypercall_enabled(struct kvm *kvm);
>  int kvm_hv_hypercall(struct kvm_vcpu *vcpu);
> +void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result);
>  
>  void kvm_hv_irq_routing_update(struct kvm *kvm);
>  int kvm_hv_synic_set_irq(struct kvm *kvm, u32 vcpu_id, u32 sint);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index f53f5b1..e5c842b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6891,6 +6891,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
>  	} else
>  		WARN_ON(vcpu->arch.pio.count || vcpu->mmio_needed);
>  
> +	if (unlikely(kvm_run->exit_reason == KVM_EXIT_HYPERV) &&
> +	    kvm_run->hyperv.type == KVM_EXIT_HYPERV_HCALL)
> +		kvm_hv_hypercall_set_result(vcpu,
> +					    kvm_run->hyperv.u.hcall.result);

Can you use vcpu->arch.complete_userspace_io here instead?

Otherwise looks great, thanks.

Paolo

> +
>  	r = vcpu_run(vcpu);
>  
>  out:
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index 9da9051..c5519a9 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -157,6 +157,7 @@ struct kvm_s390_skeys {
>  
>  struct kvm_hyperv_exit {
>  #define KVM_EXIT_HYPERV_SYNIC          1
> +#define KVM_EXIT_HYPERV_HCALL          2
>  	__u32 type;
>  	union {
>  		struct {
> @@ -165,6 +166,11 @@ struct kvm_hyperv_exit {
>  			__u64 evt_page;
>  			__u64 msg_page;
>  		} synic;
> +		struct {
> +			__u64 input;
> +			__u64 result;
> +			__u64 params[2];
> +		} hcall;
>  	} u;
>  };
>  
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-02-10 16:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-21 14:01 [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin
2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 1/5] kvm/x86: Rename Hyper-V long spin wait hypercall Andrey Smetanin
2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 2/5] drivers/hv: Move VMBus hypercall codes into Hyper-V UAPI header Andrey Smetanin
2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 3/5] kvm/x86: Pass return code of kvm_emulate_hypercall Andrey Smetanin
2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 4/5] kvm/x86: Reject Hyper-V hypercall continuation Andrey Smetanin
2016-01-21 14:01 ` [Qemu-devel] [PATCH v2 5/5] kvm/x86: Hyper-V VMBus hypercall userspace exit Andrey Smetanin
2016-02-10 16:48   ` Paolo Bonzini
2016-02-02 11:34 ` [Qemu-devel] [PATCH v2 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).