2 * QEMU KVM Hyper-V support
4 * Copyright (C) 2015 Andrey Smetanin <asmetanin@virtuozzo.com>
7 * Andrey Smetanin <asmetanin@virtuozzo.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
16 #include "standard-headers/asm-x86/hyperv.h"
18 int kvm_hv_handle_exit(X86CPU
*cpu
, struct kvm_hyperv_exit
*exit
)
20 CPUX86State
*env
= &cpu
->env
;
23 case KVM_EXIT_HYPERV_SYNIC
:
24 if (!cpu
->hyperv_synic
) {
29 * For now just track changes in SynIC control and msg/evt pages msr's.
30 * When SynIC messaging/events processing will be added in future
31 * here we will do messages queues flushing and pages remapping.
33 switch (exit
->u
.synic
.msr
) {
34 case HV_X64_MSR_SCONTROL
:
35 env
->msr_hv_synic_control
= exit
->u
.synic
.control
;
38 env
->msr_hv_synic_msg_page
= exit
->u
.synic
.msg_page
;
40 case HV_X64_MSR_SIEFP
:
41 env
->msr_hv_synic_evt_page
= exit
->u
.synic
.evt_page
;
52 static void kvm_hv_sint_ack_handler(EventNotifier
*notifier
)
54 HvSintRoute
*sint_route
= container_of(notifier
, HvSintRoute
,
56 event_notifier_test_and_clear(notifier
);
57 if (sint_route
->sint_ack_clb
) {
58 sint_route
->sint_ack_clb(sint_route
);
62 HvSintRoute
*kvm_hv_sint_route_create(uint32_t vcpu_id
, uint32_t sint
,
63 HvSintAckClb sint_ack_clb
)
65 HvSintRoute
*sint_route
;
68 sint_route
= g_malloc0(sizeof(*sint_route
));
69 r
= event_notifier_init(&sint_route
->sint_set_notifier
, false);
74 r
= event_notifier_init(&sint_route
->sint_ack_notifier
, false);
76 goto err_sint_set_notifier
;
79 event_notifier_set_handler(&sint_route
->sint_ack_notifier
,
80 kvm_hv_sint_ack_handler
);
82 gsi
= kvm_irqchip_add_hv_sint_route(kvm_state
, vcpu_id
, sint
);
87 r
= kvm_irqchip_add_irqfd_notifier_gsi(kvm_state
,
88 &sint_route
->sint_set_notifier
,
89 &sint_route
->sint_ack_notifier
, gsi
);
93 sint_route
->gsi
= gsi
;
94 sint_route
->sint_ack_clb
= sint_ack_clb
;
95 sint_route
->vcpu_id
= vcpu_id
;
96 sint_route
->sint
= sint
;
101 kvm_irqchip_release_virq(kvm_state
, gsi
);
103 event_notifier_set_handler(&sint_route
->sint_ack_notifier
, NULL
);
104 event_notifier_cleanup(&sint_route
->sint_ack_notifier
);
105 err_sint_set_notifier
:
106 event_notifier_cleanup(&sint_route
->sint_set_notifier
);
113 void kvm_hv_sint_route_destroy(HvSintRoute
*sint_route
)
115 kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state
,
116 &sint_route
->sint_set_notifier
,
118 kvm_irqchip_release_virq(kvm_state
, sint_route
->gsi
);
119 event_notifier_set_handler(&sint_route
->sint_ack_notifier
, NULL
);
120 event_notifier_cleanup(&sint_route
->sint_ack_notifier
);
121 event_notifier_cleanup(&sint_route
->sint_set_notifier
);
125 int kvm_hv_sint_route_set_sint(HvSintRoute
*sint_route
)
127 return event_notifier_set(&sint_route
->sint_set_notifier
);