From: Roman Kagan <rkagan@virtuozzo.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>,
Evgeny Yakovlev <eyakovlev@virtuozzo.com>,
"Denis V . Lunev" <den@openvz.org>
Subject: [Qemu-devel] [PATCH 13/23] hyperv: qdev-ify SynIC
Date: Tue, 6 Jun 2017 21:19:38 +0300 [thread overview]
Message-ID: <20170606181948.16238-14-rkagan@virtuozzo.com> (raw)
In-Reply-To: <20170606181948.16238-1-rkagan@virtuozzo.com>
Make Hyper-V SynIC a device which is attached as a child to X86CPU. For
now it only makes SynIC visibile in the qom hierarchy and exposes a few
properties which are maintained in sync with the respecitve msrs of the
parent cpu.
Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
target/i386/hyperv.h | 4 ++
target/i386/hyperv.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++-
target/i386/kvm.c | 5 ++
target/i386/machine.c | 9 ++++
4 files changed, 147 insertions(+), 2 deletions(-)
diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h
index ca5a32d..9dd5ca0 100644
--- a/target/i386/hyperv.h
+++ b/target/i386/hyperv.h
@@ -34,4 +34,8 @@ int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route);
uint32_t hyperv_vp_index(X86CPU *cpu);
X86CPU *hyperv_find_vcpu(uint32_t vcpu_id);
+void hyperv_synic_add(X86CPU *cpu);
+void hyperv_synic_reset(X86CPU *cpu);
+void hyperv_synic_update(X86CPU *cpu);
+
#endif
diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c
index ae67f82..2d9e9fe 100644
--- a/target/i386/hyperv.c
+++ b/target/i386/hyperv.c
@@ -13,12 +13,27 @@
#include "qemu/osdep.h"
#include "qemu/main-loop.h"
+#include "qapi/error.h"
+#include "hw/qdev-properties.h"
#include "hyperv.h"
#include "hyperv_proto.h"
+typedef struct SynICState {
+ DeviceState parent_obj;
+
+ X86CPU *cpu;
+
+ bool enabled;
+ hwaddr msg_page_addr;
+ hwaddr evt_page_addr;
+} SynICState;
+
+#define TYPE_SYNIC "hyperv-synic"
+#define SYNIC(obj) OBJECT_CHECK(SynICState, (obj), TYPE_SYNIC)
+
struct HvSintRoute {
uint32_t sint;
- X86CPU *cpu;
+ SynICState *synic;
int gsi;
EventNotifier sint_set_notifier;
EventNotifier sint_ack_notifier;
@@ -37,6 +52,37 @@ X86CPU *hyperv_find_vcpu(uint32_t vp_index)
return X86_CPU(qemu_get_cpu(vp_index));
}
+static SynICState *get_synic(X86CPU *cpu)
+{
+ SynICState *synic =
+ SYNIC(object_resolve_path_component(OBJECT(cpu), "synic"));
+ assert(synic);
+ return synic;
+}
+
+static void synic_update_msg_page_addr(SynICState *synic)
+{
+ uint64_t msr = synic->cpu->env.msr_hv_synic_msg_page;
+ hwaddr new_addr = (msr & HV_SIMP_ENABLE) ? (msr & TARGET_PAGE_MASK) : 0;
+
+ synic->msg_page_addr = new_addr;
+}
+
+static void synic_update_evt_page_addr(SynICState *synic)
+{
+ uint64_t msr = synic->cpu->env.msr_hv_synic_evt_page;
+ hwaddr new_addr = (msr & HV_SIEFP_ENABLE) ? (msr & TARGET_PAGE_MASK) : 0;
+
+ synic->evt_page_addr = new_addr;
+}
+
+static void synic_update(SynICState *synic)
+{
+ synic->enabled = synic->cpu->env.msr_hv_synic_control & HV_SYNIC_ENABLE;
+ synic_update_msg_page_addr(synic);
+ synic_update_evt_page_addr(synic);
+}
+
int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit)
{
CPUX86State *env = &cpu->env;
@@ -65,6 +111,7 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit)
default:
return -1;
}
+ synic_update(get_synic(cpu));
return 0;
case KVM_EXIT_HYPERV_HCALL: {
uint16_t code;
@@ -95,10 +142,13 @@ HvSintRoute *hyperv_sint_route_new(X86CPU *cpu, uint32_t sint,
HvSintAckClb sint_ack_clb,
void *sint_ack_clb_data)
{
+ SynICState *synic;
HvSintRoute *sint_route;
EventNotifier *ack_notifier;
int r, gsi;
+ synic = get_synic(cpu);
+
sint_route = g_new0(HvSintRoute, 1);
r = event_notifier_init(&sint_route->sint_set_notifier, false);
if (r) {
@@ -129,7 +179,7 @@ HvSintRoute *hyperv_sint_route_new(X86CPU *cpu, uint32_t sint,
sint_route->gsi = gsi;
sint_route->sint_ack_clb = sint_ack_clb;
sint_route->sint_ack_clb_data = sint_ack_clb_data;
- sint_route->cpu = cpu;
+ sint_route->synic = synic;
sint_route->sint = sint;
sint_route->refcount = 1;
@@ -183,3 +233,80 @@ int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route)
{
return event_notifier_set(&sint_route->sint_set_notifier);
}
+
+static Property synic_props[] = {
+ DEFINE_PROP_BOOL("enabled", SynICState, enabled, false),
+ DEFINE_PROP_UINT64("msg-page-addr", SynICState, msg_page_addr, 0),
+ DEFINE_PROP_UINT64("evt-page-addr", SynICState, evt_page_addr, 0),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void synic_realize(DeviceState *dev, Error **errp)
+{
+ Object *obj = OBJECT(dev);
+ SynICState *synic = SYNIC(dev);
+
+ synic->cpu = X86_CPU(obj->parent);
+}
+
+static void synic_reset(DeviceState *dev)
+{
+ SynICState *synic = SYNIC(dev);
+ synic_update(synic);
+}
+
+static void synic_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ dc->props = synic_props;
+ dc->realize = synic_realize;
+ dc->reset = synic_reset;
+ dc->user_creatable = false;
+}
+
+void hyperv_synic_add(X86CPU *cpu)
+{
+ Object *obj;
+
+ if (!cpu->hyperv_synic) {
+ return;
+ }
+
+ obj = object_new(TYPE_SYNIC);
+ object_property_add_child(OBJECT(cpu), "synic", obj, &error_abort);
+ object_unref(obj);
+ object_property_set_bool(obj, true, "realized", &error_abort);
+}
+
+void hyperv_synic_reset(X86CPU *cpu)
+{
+ if (!cpu->hyperv_synic) {
+ return;
+ }
+
+ device_reset(DEVICE(get_synic(cpu)));
+}
+
+void hyperv_synic_update(X86CPU *cpu)
+{
+ if (!cpu->hyperv_synic) {
+ return;
+ }
+
+ synic_update(get_synic(cpu));
+}
+
+static const TypeInfo synic_type_info = {
+ .name = TYPE_SYNIC,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(SynICState),
+ .class_init = synic_class_init,
+};
+
+static void synic_register_types(void)
+{
+ type_register_static(&synic_type_info);
+}
+
+type_init(synic_register_types)
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index eb9cde4..433c912 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -688,6 +688,9 @@ static int hyperv_handle_properties(CPUState *cs)
}
env->features[FEAT_HYPERV_EAX] |= HV_SYNTIMERS_AVAILABLE;
}
+
+ hyperv_synic_add(cpu);
+
return 0;
}
@@ -1065,6 +1068,8 @@ void kvm_arch_reset_vcpu(X86CPU *cpu)
for (i = 0; i < ARRAY_SIZE(env->msr_hv_synic_sint); i++) {
env->msr_hv_synic_sint[i] = HV_SINT_MASKED;
}
+
+ hyperv_synic_reset(cpu);
}
}
diff --git a/target/i386/machine.c b/target/i386/machine.c
index eb00b19..8022c24 100644
--- a/target/i386/machine.c
+++ b/target/i386/machine.c
@@ -7,6 +7,7 @@
#include "hw/i386/pc.h"
#include "hw/isa/isa.h"
#include "migration/cpu.h"
+#include "hyperv.h"
#include "sysemu/kvm.h"
@@ -633,11 +634,19 @@ static bool hyperv_synic_enable_needed(void *opaque)
return false;
}
+static int hyperv_synic_post_load(void *opaque, int version_id)
+{
+ X86CPU *cpu = opaque;
+ hyperv_synic_update(cpu);
+ return 0;
+}
+
static const VMStateDescription vmstate_msr_hyperv_synic = {
.name = "cpu/msr_hyperv_synic",
.version_id = 1,
.minimum_version_id = 1,
.needed = hyperv_synic_enable_needed,
+ .post_load = hyperv_synic_post_load,
.fields = (VMStateField[]) {
VMSTATE_UINT64(env.msr_hv_synic_control, X86CPU),
VMSTATE_UINT64(env.msr_hv_synic_evt_page, X86CPU),
--
2.9.4
next prev parent reply other threads:[~2017-06-06 18:20 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-06 18:19 [Qemu-devel] [PATCH 00/23] hyperv fixes and enhancements Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 01/23] hyperv: add header with protocol definitions Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 02/23] update-linux-headers: prepare for hyperv.h removal Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 03/23] hyperv: set partition-wide MSRs only on first vcpu Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 04/23] hyperv: ensure msrs are inited properly Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 05/23] hyperv: ensure VP index equal to QEMU cpu_index Roman Kagan
2017-06-13 18:57 ` Eduardo Habkost
2017-06-14 11:25 ` Roman Kagan
2017-06-14 11:26 ` Paolo Bonzini
2017-06-14 13:00 ` Igor Mammedov
2017-06-15 12:41 ` Roman Kagan
2017-06-15 13:22 ` Paolo Bonzini
2017-06-15 13:27 ` Igor Mammedov
2017-06-15 16:05 ` Roman Kagan
2017-06-18 15:29 ` Eduardo Habkost
2017-06-14 13:01 ` Eduardo Habkost
2017-06-14 13:11 ` Igor Mammedov
2017-06-14 13:17 ` Paolo Bonzini
2017-06-14 13:22 ` Eduardo Habkost
2017-06-14 13:37 ` Paolo Bonzini
2017-06-14 13:38 ` Igor Mammedov
2017-06-14 13:45 ` Eduardo Habkost
2017-06-14 18:40 ` Roman Kagan
2017-06-14 18:59 ` Eduardo Habkost
2017-06-15 8:26 ` Paolo Bonzini
2017-06-15 11:40 ` Roman Kagan
2017-06-15 11:42 ` Paolo Bonzini
2017-06-15 12:03 ` Roman Kagan
2017-06-14 13:19 ` Eduardo Habkost
2017-06-14 13:00 ` Eduardo Habkost
2017-06-14 13:24 ` Igor Mammedov
2017-06-14 13:35 ` Eduardo Habkost
2017-06-14 15:31 ` Igor Mammedov
2017-06-06 18:19 ` [Qemu-devel] [PATCH 06/23] hyperv: helper to find vcpu by VP index Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 07/23] hyperv_testdev: refactor for readability Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 08/23] hyperv: cosmetic: g_malloc -> g_new Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 09/23] hyperv: synic: only setup ack notifier if there's a callback Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 10/23] hyperv: allow passing arbitrary data to sint ack callback Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 12/23] hyperv: make HvSintRoute reference-counted Roman Kagan
2017-06-14 13:53 ` Eduardo Habkost
2017-06-14 16:23 ` Roman Kagan
2017-06-23 12:44 ` Eduardo Habkost
2017-06-06 18:19 ` Roman Kagan [this message]
2017-06-13 18:34 ` [Qemu-devel] [PATCH 13/23] hyperv: qdev-ify SynIC Eduardo Habkost
2017-06-14 9:58 ` Roman Kagan
2017-06-14 12:46 ` Eduardo Habkost
2017-06-14 15:11 ` Roman Kagan
2017-06-14 15:21 ` Eduardo Habkost
2017-06-06 18:19 ` [Qemu-devel] [PATCH 14/23] kvm-all: make async_safe_run_on_cpu safe on kvm too Roman Kagan
2017-06-08 14:47 ` Paolo Bonzini
2017-06-06 18:19 ` [Qemu-devel] [PATCH 15/23] hyperv: make overlay pages for SynIC Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 16/23] hyperv: map overlay pages after updating msrs Roman Kagan
2017-06-14 11:12 ` Paolo Bonzini
2017-06-14 11:54 ` Roman Kagan
2017-06-14 12:11 ` Paolo Bonzini
2017-06-14 12:41 ` Roman Kagan
2017-06-14 12:46 ` Paolo Bonzini
2017-06-06 18:19 ` [Qemu-devel] [PATCH 17/23] hyperv: add synic message delivery Roman Kagan
2017-06-14 15:08 ` Paolo Bonzini
2017-06-14 15:28 ` Roman Kagan
2017-06-14 15:32 ` Paolo Bonzini
2017-06-14 15:39 ` Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 18/23] hyperv: add synic event flag signaling Roman Kagan
2017-06-14 15:07 ` Paolo Bonzini
2017-06-06 18:19 ` [Qemu-devel] [PATCH 19/23] hyperv: process SIGNAL_EVENT hypercall Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 20/23] hyperv: process POST_MESSAGE hypercall Roman Kagan
2017-06-14 11:19 ` Paolo Bonzini
2017-06-14 14:20 ` Roman Kagan
2017-06-14 14:30 ` Paolo Bonzini
2017-06-06 18:19 ` [Qemu-devel] [PATCH 21/23] hyperv_testdev: add SynIC message and event testmodes Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 22/23] MAINTAINERS: add myself and eyakovlev@ for hyperv* Roman Kagan
2017-06-06 18:19 ` [Qemu-devel] [PATCH 23/23] hyperv: update copyright notices Roman Kagan
[not found] ` <20170606181948.16238-12-rkagan@virtuozzo.com>
2017-06-13 19:02 ` [Qemu-devel] [PATCH 11/23] hyperv: address HvSintRoute by X86CPU pointer Eduardo Habkost
2017-06-14 11:08 ` Paolo Bonzini
2017-06-14 12:14 ` Roman Kagan
2017-06-14 12:17 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170606181948.16238-14-rkagan@virtuozzo.com \
--to=rkagan@virtuozzo.com \
--cc=den@openvz.org \
--cc=ehabkost@redhat.com \
--cc=eyakovlev@virtuozzo.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).