]>
Commit | Line | Data |
---|---|---|
50efe82c AS |
1 | /* |
2 | * QEMU KVM Hyper-V support | |
3 | * | |
4 | * Copyright (C) 2015 Andrey Smetanin <asmetanin@virtuozzo.com> | |
5 | * | |
6 | * Authors: | |
7 | * Andrey Smetanin <asmetanin@virtuozzo.com> | |
8 | * | |
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. | |
11 | * | |
12 | */ | |
13 | ||
b6a0aa05 | 14 | #include "qemu/osdep.h" |
267e071b | 15 | #include "qemu/main-loop.h" |
50efe82c | 16 | #include "hyperv.h" |
701189e3 | 17 | #include "hw/hyperv/hyperv.h" |
5e953812 | 18 | #include "hyperv-proto.h" |
50efe82c | 19 | |
606c34bf RK |
20 | int hyperv_x86_synic_add(X86CPU *cpu) |
21 | { | |
22 | hyperv_synic_add(CPU(cpu)); | |
23 | return 0; | |
24 | } | |
25 | ||
26 | void hyperv_x86_synic_reset(X86CPU *cpu) | |
27 | { | |
28 | hyperv_synic_reset(CPU(cpu)); | |
29 | } | |
30 | ||
31 | void hyperv_x86_synic_update(X86CPU *cpu) | |
32 | { | |
33 | CPUX86State *env = &cpu->env; | |
34 | bool enable = env->msr_hv_synic_control & HV_SYNIC_ENABLE; | |
35 | hwaddr msg_page_addr = (env->msr_hv_synic_msg_page & HV_SIMP_ENABLE) ? | |
36 | (env->msr_hv_synic_msg_page & TARGET_PAGE_MASK) : 0; | |
37 | hwaddr event_page_addr = (env->msr_hv_synic_evt_page & HV_SIEFP_ENABLE) ? | |
38 | (env->msr_hv_synic_evt_page & TARGET_PAGE_MASK) : 0; | |
39 | hyperv_synic_update(CPU(cpu), enable, msg_page_addr, event_page_addr); | |
40 | } | |
41 | ||
267e071b RK |
42 | static void async_synic_update(CPUState *cs, run_on_cpu_data data) |
43 | { | |
44 | qemu_mutex_lock_iothread(); | |
45 | hyperv_x86_synic_update(X86_CPU(cs)); | |
46 | qemu_mutex_unlock_iothread(); | |
47 | } | |
48 | ||
50efe82c AS |
49 | int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) |
50 | { | |
51 | CPUX86State *env = &cpu->env; | |
52 | ||
53 | switch (exit->type) { | |
54 | case KVM_EXIT_HYPERV_SYNIC: | |
2d384d7c | 55 | if (!hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC)) { |
50efe82c AS |
56 | return -1; |
57 | } | |
58 | ||
50efe82c AS |
59 | switch (exit->u.synic.msr) { |
60 | case HV_X64_MSR_SCONTROL: | |
61 | env->msr_hv_synic_control = exit->u.synic.control; | |
62 | break; | |
63 | case HV_X64_MSR_SIMP: | |
64 | env->msr_hv_synic_msg_page = exit->u.synic.msg_page; | |
65 | break; | |
66 | case HV_X64_MSR_SIEFP: | |
67 | env->msr_hv_synic_evt_page = exit->u.synic.evt_page; | |
68 | break; | |
69 | default: | |
70 | return -1; | |
71 | } | |
606c34bf | 72 | |
267e071b RK |
73 | /* |
74 | * this will run in this cpu thread before it returns to KVM, but in a | |
75 | * safe environment (i.e. when all cpus are quiescent) -- this is | |
76 | * necessary because memory hierarchy is being changed | |
77 | */ | |
78 | async_safe_run_on_cpu(CPU(cpu), async_synic_update, RUN_ON_CPU_NULL); | |
606c34bf | 79 | |
50efe82c | 80 | return 0; |
1b0d9b05 | 81 | case KVM_EXIT_HYPERV_HCALL: { |
e6ea9f45 RK |
82 | uint16_t code = exit->u.hcall.input & 0xffff; |
83 | bool fast = exit->u.hcall.input & HV_HYPERCALL_FAST; | |
84 | uint64_t param = exit->u.hcall.params[0]; | |
1b0d9b05 | 85 | |
1b0d9b05 | 86 | switch (code) { |
76036a5f RK |
87 | case HV_POST_MESSAGE: |
88 | exit->u.hcall.result = hyperv_hcall_post_message(param, fast); | |
89 | break; | |
5e953812 | 90 | case HV_SIGNAL_EVENT: |
e6ea9f45 RK |
91 | exit->u.hcall.result = hyperv_hcall_signal_event(param, fast); |
92 | break; | |
1b0d9b05 AS |
93 | default: |
94 | exit->u.hcall.result = HV_STATUS_INVALID_HYPERCALL_CODE; | |
1b0d9b05 | 95 | } |
e6ea9f45 | 96 | return 0; |
1b0d9b05 | 97 | } |
50efe82c AS |
98 | default: |
99 | return -1; | |
100 | } | |
101 | } |