mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 01:33:56 -06:00
i386: move kvm accel files into kvm/
Signed-off-by: Claudio Fontana <cfontana@suse.de> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20201212155530.23098-2-cfontana@suse.de> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
parent
af3f37319c
commit
a9dc68d9b2
25 changed files with 26 additions and 22 deletions
164
target/i386/kvm/hyperv-proto.h
Normal file
164
target/i386/kvm/hyperv-proto.h
Normal file
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
* Definitions for Hyper-V guest/hypervisor interaction - x86-specific part
|
||||
*
|
||||
* Copyright (c) 2017-2018 Virtuozzo International GmbH.
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#ifndef TARGET_I386_HYPERV_PROTO_H
|
||||
#define TARGET_I386_HYPERV_PROTO_H
|
||||
|
||||
#include "hw/hyperv/hyperv-proto.h"
|
||||
|
||||
#define HV_CPUID_VENDOR_AND_MAX_FUNCTIONS 0x40000000
|
||||
#define HV_CPUID_INTERFACE 0x40000001
|
||||
#define HV_CPUID_VERSION 0x40000002
|
||||
#define HV_CPUID_FEATURES 0x40000003
|
||||
#define HV_CPUID_ENLIGHTMENT_INFO 0x40000004
|
||||
#define HV_CPUID_IMPLEMENT_LIMITS 0x40000005
|
||||
#define HV_CPUID_NESTED_FEATURES 0x4000000A
|
||||
#define HV_CPUID_MIN 0x40000005
|
||||
#define HV_CPUID_MAX 0x4000ffff
|
||||
#define HV_HYPERVISOR_PRESENT_BIT 0x80000000
|
||||
|
||||
/*
|
||||
* HV_CPUID_FEATURES.EAX bits
|
||||
*/
|
||||
#define HV_VP_RUNTIME_AVAILABLE (1u << 0)
|
||||
#define HV_TIME_REF_COUNT_AVAILABLE (1u << 1)
|
||||
#define HV_SYNIC_AVAILABLE (1u << 2)
|
||||
#define HV_SYNTIMERS_AVAILABLE (1u << 3)
|
||||
#define HV_APIC_ACCESS_AVAILABLE (1u << 4)
|
||||
#define HV_HYPERCALL_AVAILABLE (1u << 5)
|
||||
#define HV_VP_INDEX_AVAILABLE (1u << 6)
|
||||
#define HV_RESET_AVAILABLE (1u << 7)
|
||||
#define HV_REFERENCE_TSC_AVAILABLE (1u << 9)
|
||||
#define HV_ACCESS_FREQUENCY_MSRS (1u << 11)
|
||||
#define HV_ACCESS_REENLIGHTENMENTS_CONTROL (1u << 13)
|
||||
|
||||
/*
|
||||
* HV_CPUID_FEATURES.EDX bits
|
||||
*/
|
||||
#define HV_MWAIT_AVAILABLE (1u << 0)
|
||||
#define HV_GUEST_DEBUGGING_AVAILABLE (1u << 1)
|
||||
#define HV_PERF_MONITOR_AVAILABLE (1u << 2)
|
||||
#define HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE (1u << 3)
|
||||
#define HV_HYPERCALL_PARAMS_XMM_AVAILABLE (1u << 4)
|
||||
#define HV_GUEST_IDLE_STATE_AVAILABLE (1u << 5)
|
||||
#define HV_FREQUENCY_MSRS_AVAILABLE (1u << 8)
|
||||
#define HV_GUEST_CRASH_MSR_AVAILABLE (1u << 10)
|
||||
#define HV_STIMER_DIRECT_MODE_AVAILABLE (1u << 19)
|
||||
|
||||
/*
|
||||
* HV_CPUID_ENLIGHTMENT_INFO.EAX bits
|
||||
*/
|
||||
#define HV_AS_SWITCH_RECOMMENDED (1u << 0)
|
||||
#define HV_LOCAL_TLB_FLUSH_RECOMMENDED (1u << 1)
|
||||
#define HV_REMOTE_TLB_FLUSH_RECOMMENDED (1u << 2)
|
||||
#define HV_APIC_ACCESS_RECOMMENDED (1u << 3)
|
||||
#define HV_SYSTEM_RESET_RECOMMENDED (1u << 4)
|
||||
#define HV_RELAXED_TIMING_RECOMMENDED (1u << 5)
|
||||
#define HV_CLUSTER_IPI_RECOMMENDED (1u << 10)
|
||||
#define HV_EX_PROCESSOR_MASKS_RECOMMENDED (1u << 11)
|
||||
#define HV_ENLIGHTENED_VMCS_RECOMMENDED (1u << 14)
|
||||
#define HV_NO_NONARCH_CORESHARING (1u << 18)
|
||||
|
||||
/*
|
||||
* Basic virtualized MSRs
|
||||
*/
|
||||
#define HV_X64_MSR_GUEST_OS_ID 0x40000000
|
||||
#define HV_X64_MSR_HYPERCALL 0x40000001
|
||||
#define HV_X64_MSR_VP_INDEX 0x40000002
|
||||
#define HV_X64_MSR_RESET 0x40000003
|
||||
#define HV_X64_MSR_VP_RUNTIME 0x40000010
|
||||
#define HV_X64_MSR_TIME_REF_COUNT 0x40000020
|
||||
#define HV_X64_MSR_REFERENCE_TSC 0x40000021
|
||||
#define HV_X64_MSR_TSC_FREQUENCY 0x40000022
|
||||
#define HV_X64_MSR_APIC_FREQUENCY 0x40000023
|
||||
|
||||
/*
|
||||
* Virtual APIC MSRs
|
||||
*/
|
||||
#define HV_X64_MSR_EOI 0x40000070
|
||||
#define HV_X64_MSR_ICR 0x40000071
|
||||
#define HV_X64_MSR_TPR 0x40000072
|
||||
#define HV_X64_MSR_APIC_ASSIST_PAGE 0x40000073
|
||||
|
||||
/*
|
||||
* Synthetic interrupt controller MSRs
|
||||
*/
|
||||
#define HV_X64_MSR_SCONTROL 0x40000080
|
||||
#define HV_X64_MSR_SVERSION 0x40000081
|
||||
#define HV_X64_MSR_SIEFP 0x40000082
|
||||
#define HV_X64_MSR_SIMP 0x40000083
|
||||
#define HV_X64_MSR_EOM 0x40000084
|
||||
#define HV_X64_MSR_SINT0 0x40000090
|
||||
#define HV_X64_MSR_SINT1 0x40000091
|
||||
#define HV_X64_MSR_SINT2 0x40000092
|
||||
#define HV_X64_MSR_SINT3 0x40000093
|
||||
#define HV_X64_MSR_SINT4 0x40000094
|
||||
#define HV_X64_MSR_SINT5 0x40000095
|
||||
#define HV_X64_MSR_SINT6 0x40000096
|
||||
#define HV_X64_MSR_SINT7 0x40000097
|
||||
#define HV_X64_MSR_SINT8 0x40000098
|
||||
#define HV_X64_MSR_SINT9 0x40000099
|
||||
#define HV_X64_MSR_SINT10 0x4000009A
|
||||
#define HV_X64_MSR_SINT11 0x4000009B
|
||||
#define HV_X64_MSR_SINT12 0x4000009C
|
||||
#define HV_X64_MSR_SINT13 0x4000009D
|
||||
#define HV_X64_MSR_SINT14 0x4000009E
|
||||
#define HV_X64_MSR_SINT15 0x4000009F
|
||||
|
||||
/*
|
||||
* Synthetic timer MSRs
|
||||
*/
|
||||
#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0
|
||||
#define HV_X64_MSR_STIMER0_COUNT 0x400000B1
|
||||
#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2
|
||||
#define HV_X64_MSR_STIMER1_COUNT 0x400000B3
|
||||
#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4
|
||||
#define HV_X64_MSR_STIMER2_COUNT 0x400000B5
|
||||
#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6
|
||||
#define HV_X64_MSR_STIMER3_COUNT 0x400000B7
|
||||
|
||||
/*
|
||||
* Guest crash notification MSRs
|
||||
*/
|
||||
#define HV_X64_MSR_CRASH_P0 0x40000100
|
||||
#define HV_X64_MSR_CRASH_P1 0x40000101
|
||||
#define HV_X64_MSR_CRASH_P2 0x40000102
|
||||
#define HV_X64_MSR_CRASH_P3 0x40000103
|
||||
#define HV_X64_MSR_CRASH_P4 0x40000104
|
||||
#define HV_CRASH_PARAMS (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0 + 1)
|
||||
#define HV_X64_MSR_CRASH_CTL 0x40000105
|
||||
#define HV_CRASH_CTL_NOTIFY (1ull << 63)
|
||||
|
||||
/*
|
||||
* Reenlightenment notification MSRs
|
||||
*/
|
||||
#define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106
|
||||
#define HV_X64_MSR_TSC_EMULATION_CONTROL 0x40000107
|
||||
#define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108
|
||||
|
||||
/*
|
||||
* Hypercall MSR bits
|
||||
*/
|
||||
#define HV_HYPERCALL_ENABLE (1u << 0)
|
||||
|
||||
/*
|
||||
* Synthetic interrupt controller definitions
|
||||
*/
|
||||
#define HV_SYNIC_VERSION 1
|
||||
#define HV_SYNIC_ENABLE (1u << 0)
|
||||
#define HV_SIMP_ENABLE (1u << 0)
|
||||
#define HV_SIEFP_ENABLE (1u << 0)
|
||||
#define HV_SINT_MASKED (1u << 16)
|
||||
#define HV_SINT_AUTO_EOI (1u << 17)
|
||||
#define HV_SINT_VECTOR_MASK 0xff
|
||||
|
||||
#define HV_STIMER_COUNT 4
|
||||
|
||||
|
||||
#endif
|
48
target/i386/kvm/hyperv-stub.c
Normal file
48
target/i386/kvm/hyperv-stub.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Stubs for CONFIG_HYPERV=n
|
||||
*
|
||||
* Copyright (c) 2015-2018 Virtuozzo International GmbH.
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "hyperv.h"
|
||||
|
||||
#ifdef CONFIG_KVM
|
||||
int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit)
|
||||
{
|
||||
switch (exit->type) {
|
||||
case KVM_EXIT_HYPERV_SYNIC:
|
||||
if (!hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tracking the changes in the MSRs is unnecessary as there are no
|
||||
* users for them beside save/load, which is handled nicely by the
|
||||
* generic MSR save/load code
|
||||
*/
|
||||
return 0;
|
||||
case KVM_EXIT_HYPERV_HCALL:
|
||||
exit->u.hcall.result = HV_STATUS_INVALID_HYPERCALL_CODE;
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int hyperv_x86_synic_add(X86CPU *cpu)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
void hyperv_x86_synic_reset(X86CPU *cpu)
|
||||
{
|
||||
}
|
||||
|
||||
void hyperv_x86_synic_update(X86CPU *cpu)
|
||||
{
|
||||
}
|
101
target/i386/kvm/hyperv.c
Normal file
101
target/i386/kvm/hyperv.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* QEMU KVM Hyper-V support
|
||||
*
|
||||
* Copyright (C) 2015 Andrey Smetanin <asmetanin@virtuozzo.com>
|
||||
*
|
||||
* Authors:
|
||||
* Andrey Smetanin <asmetanin@virtuozzo.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "hyperv.h"
|
||||
#include "hw/hyperv/hyperv.h"
|
||||
#include "hyperv-proto.h"
|
||||
|
||||
int hyperv_x86_synic_add(X86CPU *cpu)
|
||||
{
|
||||
hyperv_synic_add(CPU(cpu));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hyperv_x86_synic_reset(X86CPU *cpu)
|
||||
{
|
||||
hyperv_synic_reset(CPU(cpu));
|
||||
}
|
||||
|
||||
void hyperv_x86_synic_update(X86CPU *cpu)
|
||||
{
|
||||
CPUX86State *env = &cpu->env;
|
||||
bool enable = env->msr_hv_synic_control & HV_SYNIC_ENABLE;
|
||||
hwaddr msg_page_addr = (env->msr_hv_synic_msg_page & HV_SIMP_ENABLE) ?
|
||||
(env->msr_hv_synic_msg_page & TARGET_PAGE_MASK) : 0;
|
||||
hwaddr event_page_addr = (env->msr_hv_synic_evt_page & HV_SIEFP_ENABLE) ?
|
||||
(env->msr_hv_synic_evt_page & TARGET_PAGE_MASK) : 0;
|
||||
hyperv_synic_update(CPU(cpu), enable, msg_page_addr, event_page_addr);
|
||||
}
|
||||
|
||||
static void async_synic_update(CPUState *cs, run_on_cpu_data data)
|
||||
{
|
||||
qemu_mutex_lock_iothread();
|
||||
hyperv_x86_synic_update(X86_CPU(cs));
|
||||
qemu_mutex_unlock_iothread();
|
||||
}
|
||||
|
||||
int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit)
|
||||
{
|
||||
CPUX86State *env = &cpu->env;
|
||||
|
||||
switch (exit->type) {
|
||||
case KVM_EXIT_HYPERV_SYNIC:
|
||||
if (!hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (exit->u.synic.msr) {
|
||||
case HV_X64_MSR_SCONTROL:
|
||||
env->msr_hv_synic_control = exit->u.synic.control;
|
||||
break;
|
||||
case HV_X64_MSR_SIMP:
|
||||
env->msr_hv_synic_msg_page = exit->u.synic.msg_page;
|
||||
break;
|
||||
case HV_X64_MSR_SIEFP:
|
||||
env->msr_hv_synic_evt_page = exit->u.synic.evt_page;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* this will run in this cpu thread before it returns to KVM, but in a
|
||||
* safe environment (i.e. when all cpus are quiescent) -- this is
|
||||
* necessary because memory hierarchy is being changed
|
||||
*/
|
||||
async_safe_run_on_cpu(CPU(cpu), async_synic_update, RUN_ON_CPU_NULL);
|
||||
|
||||
return 0;
|
||||
case KVM_EXIT_HYPERV_HCALL: {
|
||||
uint16_t code = exit->u.hcall.input & 0xffff;
|
||||
bool fast = exit->u.hcall.input & HV_HYPERCALL_FAST;
|
||||
uint64_t param = exit->u.hcall.params[0];
|
||||
|
||||
switch (code) {
|
||||
case HV_POST_MESSAGE:
|
||||
exit->u.hcall.result = hyperv_hcall_post_message(param, fast);
|
||||
break;
|
||||
case HV_SIGNAL_EVENT:
|
||||
exit->u.hcall.result = hyperv_hcall_signal_event(param, fast);
|
||||
break;
|
||||
default:
|
||||
exit->u.hcall.result = HV_STATUS_INVALID_HYPERCALL_CODE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
29
target/i386/kvm/hyperv.h
Normal file
29
target/i386/kvm/hyperv.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* QEMU KVM Hyper-V support
|
||||
*
|
||||
* Copyright (C) 2015 Andrey Smetanin <asmetanin@virtuozzo.com>
|
||||
*
|
||||
* Authors:
|
||||
* Andrey Smetanin <asmetanin@virtuozzo.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TARGET_I386_HYPERV_H
|
||||
#define TARGET_I386_HYPERV_H
|
||||
|
||||
#include "cpu.h"
|
||||
#include "sysemu/kvm.h"
|
||||
#include "hw/hyperv/hyperv.h"
|
||||
|
||||
#ifdef CONFIG_KVM
|
||||
int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit);
|
||||
#endif
|
||||
|
||||
int hyperv_x86_synic_add(X86CPU *cpu);
|
||||
void hyperv_x86_synic_reset(X86CPU *cpu);
|
||||
void hyperv_x86_synic_update(X86CPU *cpu);
|
||||
|
||||
#endif
|
41
target/i386/kvm/kvm-stub.c
Normal file
41
target/i386/kvm/kvm-stub.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* QEMU KVM x86 specific function stubs
|
||||
*
|
||||
* Copyright Linaro Limited 2012
|
||||
*
|
||||
* Author: Peter Maydell <peter.maydell@linaro.org>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
#include "qemu/osdep.h"
|
||||
#include "cpu.h"
|
||||
#include "kvm_i386.h"
|
||||
|
||||
#ifndef __OPTIMIZE__
|
||||
bool kvm_has_smm(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool kvm_enable_x2apic(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* This function is only called inside conditionals which we
|
||||
* rely on the compiler to optimize out when CONFIG_KVM is not
|
||||
* defined.
|
||||
*/
|
||||
uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
|
||||
uint32_t index, int reg)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
bool kvm_hv_vpindex_settable(void)
|
||||
{
|
||||
return false;
|
||||
}
|
4766
target/i386/kvm/kvm.c
Normal file
4766
target/i386/kvm/kvm.c
Normal file
File diff suppressed because it is too large
Load diff
53
target/i386/kvm/kvm_i386.h
Normal file
53
target/i386/kvm/kvm_i386.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* QEMU KVM support -- x86 specific functions.
|
||||
*
|
||||
* Copyright (c) 2012 Linaro Limited
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QEMU_KVM_I386_H
|
||||
#define QEMU_KVM_I386_H
|
||||
|
||||
#include "sysemu/kvm.h"
|
||||
|
||||
#define kvm_apic_in_kernel() (kvm_irqchip_in_kernel())
|
||||
|
||||
#ifdef CONFIG_KVM
|
||||
|
||||
#define kvm_pit_in_kernel() \
|
||||
(kvm_irqchip_in_kernel() && !kvm_irqchip_is_split())
|
||||
#define kvm_pic_in_kernel() \
|
||||
(kvm_irqchip_in_kernel() && !kvm_irqchip_is_split())
|
||||
#define kvm_ioapic_in_kernel() \
|
||||
(kvm_irqchip_in_kernel() && !kvm_irqchip_is_split())
|
||||
|
||||
#else
|
||||
|
||||
#define kvm_pit_in_kernel() 0
|
||||
#define kvm_pic_in_kernel() 0
|
||||
#define kvm_ioapic_in_kernel() 0
|
||||
|
||||
#endif /* CONFIG_KVM */
|
||||
|
||||
bool kvm_has_smm(void);
|
||||
bool kvm_has_adjust_clock(void);
|
||||
bool kvm_has_adjust_clock_stable(void);
|
||||
bool kvm_has_exception_payload(void);
|
||||
void kvm_synchronize_all_tsc(void);
|
||||
void kvm_arch_reset_vcpu(X86CPU *cs);
|
||||
void kvm_arch_do_init_vcpu(X86CPU *cs);
|
||||
|
||||
void kvm_put_apicbase(X86CPU *cpu, uint64_t value);
|
||||
|
||||
bool kvm_enable_x2apic(void);
|
||||
bool kvm_has_x2apic_api(void);
|
||||
bool kvm_has_waitpkg(void);
|
||||
|
||||
bool kvm_hv_vpindex_settable(void);
|
||||
|
||||
uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address);
|
||||
|
||||
#endif
|
3
target/i386/kvm/meson.build
Normal file
3
target/i386/kvm/meson.build
Normal file
|
@ -0,0 +1,3 @@
|
|||
i386_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
|
||||
i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'))
|
||||
i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c'))
|
7
target/i386/kvm/trace-events
Normal file
7
target/i386/kvm/trace-events
Normal file
|
@ -0,0 +1,7 @@
|
|||
# See docs/devel/tracing.txt for syntax documentation.
|
||||
|
||||
# kvm.c
|
||||
kvm_x86_fixup_msi_error(uint32_t gsi) "VT-d failed to remap interrupt for GSI %" PRIu32
|
||||
kvm_x86_add_msi_route(int virq) "Adding route entry for virq %d"
|
||||
kvm_x86_remove_msi_route(int virq) "Removing route entry for virq %d"
|
||||
kvm_x86_update_msi_routes(int num) "Updated %d MSI routes"
|
1
target/i386/kvm/trace.h
Normal file
1
target/i386/kvm/trace.h
Normal file
|
@ -0,0 +1 @@
|
|||
#include "trace/trace-target_i386_kvm.h"
|
Loading…
Add table
Add a link
Reference in a new issue