mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge remote-tracking branch 'remotes/bonzini-gitlab/tags/for-upstream' into staging
* HVF fixes * Extra qos-test debugging output (Christian) * SEV secret address autodetection (James) * SEV-ES support (Thomas) * Relocatable paths bugfix (Stefan) * RR fix (Pavel) * EventNotifier fix (Greg) # gpg: Signature made Tue 16 Feb 2021 16:15:59 GMT # gpg: using RSA key F13338574B662389866C7682BFFBD25F78C7AE83 # gpg: issuer "pbonzini@redhat.com" # gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" [full] # gpg: aka "Paolo Bonzini <pbonzini@redhat.com>" [full] # Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4 E2F7 7E15 100C CD36 69B1 # Subkey fingerprint: F133 3857 4B66 2389 866C 7682 BFFB D25F 78C7 AE83 * remotes/bonzini-gitlab/tags/for-upstream: (21 commits) replay: fix icount request when replaying clock access event_notifier: Set ->initialized earlier in event_notifier_init() hvf: Fetch cr4 before evaluating CPUID(1) target/i386/hvf: add rdmsr 35H MSR_CORE_THREAD_COUNT hvf: x86: Remove unused definitions target/i386/hvf: add vmware-cpuid-freq cpu feature hvf: Guard xgetbv call util/cutils: Skip "." when looking for next directory component tests/qtest/qos-test: dump QEMU command if verbose tests/qtest/qos-test: dump environment variables if verbose tests/qtest/qos-test: dump qos graph if verbose libqos/qgraph_internal: add qos_printf() and qos_printf_literal() libqos/qgraph: add qos_node_create_driver_named() sev/i386: Enable an SEV-ES guest based on SEV policy kvm/i386: Use a per-VM check for SMM capability sev/i386: Don't allow a system reset under an SEV-ES guest sev/i386: Allow AP booting under SEV-ES sev/i386: Require in-kernel irqchip support for SEV-ES guests sev/i386: Add initial support for SEV-ES sev: update sev-inject-launch-secret to make gpa optional ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
+5
-1
@@ -39,7 +39,6 @@
|
||||
#include "qemu/main-loop.h"
|
||||
#include "trace.h"
|
||||
#include "hw/irq.h"
|
||||
#include "sysemu/sev.h"
|
||||
#include "qapi/visitor.h"
|
||||
#include "qapi/qapi-types-common.h"
|
||||
#include "qapi/qapi-visit-common.h"
|
||||
@@ -2313,6 +2312,11 @@ void kvm_flush_coalesced_mmio_buffer(void)
|
||||
s->coalesced_flush_in_progress = false;
|
||||
}
|
||||
|
||||
bool kvm_cpu_check_are_resettable(void)
|
||||
{
|
||||
return kvm_arch_cpu_check_are_resettable();
|
||||
}
|
||||
|
||||
static void do_kvm_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
|
||||
{
|
||||
if (!cpu->vcpu_dirty) {
|
||||
|
||||
+126
-4
@@ -125,6 +125,113 @@ void pc_system_flash_cleanup_unused(PCMachineState *pcms)
|
||||
}
|
||||
}
|
||||
|
||||
#define OVMF_TABLE_FOOTER_GUID "96b582de-1fb2-45f7-baea-a366c55a082d"
|
||||
|
||||
static uint8_t *ovmf_table;
|
||||
static int ovmf_table_len;
|
||||
|
||||
static void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
QemuUUID guid;
|
||||
int tot_len;
|
||||
|
||||
/* should only be called once */
|
||||
if (ovmf_table) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (flash_size < TARGET_PAGE_SIZE) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* if this is OVMF there will be a table footer
|
||||
* guid 48 bytes before the end of the flash file. If it's
|
||||
* not found, silently abort the flash parsing.
|
||||
*/
|
||||
qemu_uuid_parse(OVMF_TABLE_FOOTER_GUID, &guid);
|
||||
guid = qemu_uuid_bswap(guid); /* guids are LE */
|
||||
ptr = flash_ptr + flash_size - 48;
|
||||
if (!qemu_uuid_is_equal((QemuUUID *)ptr, &guid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* if found, just before is two byte table length */
|
||||
ptr -= sizeof(uint16_t);
|
||||
tot_len = le16_to_cpu(*(uint16_t *)ptr) - sizeof(guid) - sizeof(uint16_t);
|
||||
|
||||
if (tot_len <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ovmf_table = g_malloc(tot_len);
|
||||
ovmf_table_len = tot_len;
|
||||
|
||||
/*
|
||||
* ptr is the foot of the table, so copy it all to the newly
|
||||
* allocated ovmf_table and then set the ovmf_table pointer
|
||||
* to the table foot
|
||||
*/
|
||||
memcpy(ovmf_table, ptr - tot_len, tot_len);
|
||||
ovmf_table += tot_len;
|
||||
}
|
||||
|
||||
bool pc_system_ovmf_table_find(const char *entry, uint8_t **data,
|
||||
int *data_len)
|
||||
{
|
||||
uint8_t *ptr = ovmf_table;
|
||||
int tot_len = ovmf_table_len;
|
||||
QemuUUID entry_guid;
|
||||
|
||||
if (qemu_uuid_parse(entry, &entry_guid) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
entry_guid = qemu_uuid_bswap(entry_guid); /* guids are LE */
|
||||
while (tot_len >= sizeof(QemuUUID) + sizeof(uint16_t)) {
|
||||
int len;
|
||||
QemuUUID *guid;
|
||||
|
||||
/*
|
||||
* The data structure is
|
||||
* arbitrary length data
|
||||
* 2 byte length of entire entry
|
||||
* 16 byte guid
|
||||
*/
|
||||
guid = (QemuUUID *)(ptr - sizeof(QemuUUID));
|
||||
len = le16_to_cpu(*(uint16_t *)(ptr - sizeof(QemuUUID) -
|
||||
sizeof(uint16_t)));
|
||||
|
||||
/*
|
||||
* just in case the table is corrupt, wouldn't want to spin in
|
||||
* the zero case
|
||||
*/
|
||||
if (len < sizeof(QemuUUID) + sizeof(uint16_t)) {
|
||||
return false;
|
||||
} else if (len > tot_len) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ptr -= len;
|
||||
tot_len -= len;
|
||||
if (qemu_uuid_is_equal(guid, &entry_guid)) {
|
||||
if (data) {
|
||||
*data = ptr;
|
||||
}
|
||||
if (data_len) {
|
||||
*data_len = len - sizeof(QemuUUID) - sizeof(uint16_t);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Map the pcms->flash[] from 4GiB downward, and realize.
|
||||
* Map them in descending order, i.e. pcms->flash[0] at the top,
|
||||
@@ -149,6 +256,7 @@ static void pc_system_flash_map(PCMachineState *pcms,
|
||||
MemoryRegion *flash_mem;
|
||||
void *flash_ptr;
|
||||
int flash_size;
|
||||
int ret;
|
||||
|
||||
assert(PC_MACHINE_GET_CLASS(pcms)->pci_enabled);
|
||||
|
||||
@@ -192,10 +300,24 @@ static void pc_system_flash_map(PCMachineState *pcms,
|
||||
flash_mem = pflash_cfi01_get_memory(system_flash);
|
||||
pc_isa_bios_init(rom_memory, flash_mem, size);
|
||||
|
||||
/* Encrypt the pflash boot ROM, if necessary */
|
||||
flash_ptr = memory_region_get_ram_ptr(flash_mem);
|
||||
flash_size = memory_region_size(flash_mem);
|
||||
sev_encrypt_flash(flash_ptr, flash_size, &error_fatal);
|
||||
/* Encrypt the pflash boot ROM */
|
||||
if (sev_enabled()) {
|
||||
flash_ptr = memory_region_get_ram_ptr(flash_mem);
|
||||
flash_size = memory_region_size(flash_mem);
|
||||
/*
|
||||
* OVMF places a GUIDed structures in the flash, so
|
||||
* search for them
|
||||
*/
|
||||
pc_system_parse_ovmf_flash(flash_ptr, flash_size);
|
||||
|
||||
ret = sev_es_save_reset_vector(flash_ptr, flash_size);
|
||||
if (ret) {
|
||||
error_report("failed to locate and/or save reset vector");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sev_encrypt_flash(flash_ptr, flash_size, &error_fatal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "qemu/notify.h"
|
||||
#include "qapi/qapi-types-common.h"
|
||||
#include "qemu/uuid.h"
|
||||
#include "hw/boards.h"
|
||||
#include "hw/block/fdc.h"
|
||||
#include "hw/block/flash.h"
|
||||
@@ -191,6 +192,9 @@ ISADevice *pc_find_fdc0(void);
|
||||
void pc_system_flash_create(PCMachineState *pcms);
|
||||
void pc_system_flash_cleanup_unused(PCMachineState *pcms);
|
||||
void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
|
||||
bool pc_system_ovmf_table_find(const char *entry, uint8_t **data,
|
||||
int *data_len);
|
||||
|
||||
|
||||
/* acpi-build.c */
|
||||
void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid,
|
||||
|
||||
@@ -41,6 +41,8 @@ extern int icount_align_option;
|
||||
/* Unblock cpu */
|
||||
void qemu_cpu_kick_self(void);
|
||||
|
||||
bool cpus_are_resettable(void);
|
||||
|
||||
void cpu_synchronize_all_states(void);
|
||||
void cpu_synchronize_all_post_reset(void);
|
||||
void cpu_synchronize_all_post_init(void);
|
||||
|
||||
@@ -22,4 +22,9 @@ void cpu_synchronize_post_reset(CPUState *cpu);
|
||||
void cpu_synchronize_post_init(CPUState *cpu);
|
||||
void cpu_synchronize_pre_loadvm(CPUState *cpu);
|
||||
|
||||
static inline bool cpu_check_are_resettable(void)
|
||||
{
|
||||
return kvm_enabled() ? kvm_cpu_check_are_resettable() : true;
|
||||
}
|
||||
|
||||
#endif /* QEMU_HW_ACCEL_H */
|
||||
|
||||
@@ -541,4 +541,14 @@ int kvm_get_max_memslots(void);
|
||||
/* Notify resamplefd for EOI of specific interrupts. */
|
||||
void kvm_resample_fd_notify(int gsi);
|
||||
|
||||
/**
|
||||
* kvm_cpu_check_are_resettable - return whether CPUs can be reset
|
||||
*
|
||||
* Returns: true: CPUs are resettable
|
||||
* false: CPUs are not resettable
|
||||
*/
|
||||
bool kvm_cpu_check_are_resettable(void);
|
||||
|
||||
bool kvm_arch_cpu_check_are_resettable(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -128,18 +128,20 @@ bool replay_has_interrupt(void);
|
||||
int64_t replay_save_clock(ReplayClockKind kind, int64_t clock,
|
||||
int64_t raw_icount);
|
||||
/*! Read the specified clock from the log or return cached data */
|
||||
int64_t replay_read_clock(ReplayClockKind kind);
|
||||
int64_t replay_read_clock(ReplayClockKind kind, int64_t raw_icount);
|
||||
/*! Saves or reads the clock depending on the current replay mode. */
|
||||
#define REPLAY_CLOCK(clock, value) \
|
||||
(replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock)) \
|
||||
(replay_mode == REPLAY_MODE_PLAY \
|
||||
? replay_read_clock((clock), icount_get_raw()) \
|
||||
: replay_mode == REPLAY_MODE_RECORD \
|
||||
? replay_save_clock((clock), (value), icount_get_raw()) \
|
||||
: (value))
|
||||
? replay_save_clock((clock), (value), icount_get_raw()) \
|
||||
: (value))
|
||||
#define REPLAY_CLOCK_LOCKED(clock, value) \
|
||||
(replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock)) \
|
||||
(replay_mode == REPLAY_MODE_PLAY \
|
||||
? replay_read_clock((clock), icount_get_raw_locked()) \
|
||||
: replay_mode == REPLAY_MODE_RECORD \
|
||||
? replay_save_clock((clock), (value), icount_get_raw_locked()) \
|
||||
: (value))
|
||||
: (value))
|
||||
|
||||
/* Processing data from random generators */
|
||||
|
||||
|
||||
@@ -16,8 +16,13 @@
|
||||
|
||||
#include "sysemu/kvm.h"
|
||||
|
||||
bool sev_enabled(void);
|
||||
int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
|
||||
int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
|
||||
int sev_inject_launch_secret(const char *hdr, const char *secret,
|
||||
uint64_t gpa, Error **errp);
|
||||
|
||||
int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size);
|
||||
void sev_es_set_reset_vector(CPUState *cpu);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -216,7 +216,7 @@
|
||||
#
|
||||
##
|
||||
{ 'command': 'sev-inject-launch-secret',
|
||||
'data': { 'packet-header': 'str', 'secret': 'str', 'gpa': 'uint64' },
|
||||
'data': { 'packet-header': 'str', 'secret': 'str', '*gpa': 'uint64' },
|
||||
'if': 'defined(TARGET_I386)' }
|
||||
|
||||
##
|
||||
|
||||
@@ -247,10 +247,31 @@ void replay_advance_current_icount(uint64_t current_icount)
|
||||
/* Time can only go forward */
|
||||
assert(diff >= 0);
|
||||
|
||||
if (diff > 0) {
|
||||
replay_put_event(EVENT_INSTRUCTION);
|
||||
replay_put_dword(diff);
|
||||
replay_state.current_icount += diff;
|
||||
if (replay_mode == REPLAY_MODE_RECORD) {
|
||||
if (diff > 0) {
|
||||
replay_put_event(EVENT_INSTRUCTION);
|
||||
replay_put_dword(diff);
|
||||
replay_state.current_icount += diff;
|
||||
}
|
||||
} else if (replay_mode == REPLAY_MODE_PLAY) {
|
||||
if (diff > 0) {
|
||||
replay_state.instruction_count -= diff;
|
||||
replay_state.current_icount += diff;
|
||||
if (replay_state.instruction_count == 0) {
|
||||
assert(replay_state.data_kind == EVENT_INSTRUCTION);
|
||||
replay_finish_event();
|
||||
/* Wake up iothread. This is required because
|
||||
timers will not expire until clock counters
|
||||
will be read from the log. */
|
||||
qemu_notify_event();
|
||||
}
|
||||
}
|
||||
/* Execution reached the break step */
|
||||
if (replay_break_icount == replay_state.current_icount) {
|
||||
/* Cannot make callback directly from the vCPU thread */
|
||||
timer_mod_ns(replay_break_timer,
|
||||
qemu_clock_get_ns(QEMU_CLOCK_REALTIME));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,12 +46,12 @@ void replay_read_next_clock(ReplayClockKind kind)
|
||||
}
|
||||
|
||||
/*! Reads next clock event from the input. */
|
||||
int64_t replay_read_clock(ReplayClockKind kind)
|
||||
int64_t replay_read_clock(ReplayClockKind kind, int64_t raw_icount)
|
||||
{
|
||||
int64_t ret;
|
||||
g_assert(replay_file && replay_mutex_locked());
|
||||
|
||||
replay_account_executed_instructions();
|
||||
replay_advance_current_icount(raw_icount);
|
||||
|
||||
if (replay_next_event_is(EVENT_CLOCK + kind)) {
|
||||
replay_read_next_clock(kind);
|
||||
|
||||
+1
-22
@@ -94,28 +94,7 @@ void replay_account_executed_instructions(void)
|
||||
if (replay_mode == REPLAY_MODE_PLAY) {
|
||||
g_assert(replay_mutex_locked());
|
||||
if (replay_state.instruction_count > 0) {
|
||||
int count = (int)(replay_get_current_icount()
|
||||
- replay_state.current_icount);
|
||||
|
||||
/* Time can only go forward */
|
||||
assert(count >= 0);
|
||||
|
||||
replay_state.instruction_count -= count;
|
||||
replay_state.current_icount += count;
|
||||
if (replay_state.instruction_count == 0) {
|
||||
assert(replay_state.data_kind == EVENT_INSTRUCTION);
|
||||
replay_finish_event();
|
||||
/* Wake up iothread. This is required because
|
||||
timers will not expire until clock counters
|
||||
will be read from the log. */
|
||||
qemu_notify_event();
|
||||
}
|
||||
/* Execution reached the break step */
|
||||
if (replay_break_icount == replay_state.current_icount) {
|
||||
/* Cannot make callback directly from the vCPU thread */
|
||||
timer_mod_ns(replay_break_timer,
|
||||
qemu_clock_get_ns(QEMU_CLOCK_REALTIME));
|
||||
}
|
||||
replay_advance_current_icount(replay_get_current_icount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +194,11 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu)
|
||||
}
|
||||
}
|
||||
|
||||
bool cpus_are_resettable(void)
|
||||
{
|
||||
return cpu_check_are_resettable();
|
||||
}
|
||||
|
||||
int64_t cpus_get_virtual_clock(void)
|
||||
{
|
||||
/*
|
||||
|
||||
@@ -528,6 +528,9 @@ void qemu_system_reset_request(ShutdownCause reason)
|
||||
if (reboot_action == REBOOT_ACTION_SHUTDOWN &&
|
||||
reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) {
|
||||
shutdown_requested = reason;
|
||||
} else if (!cpus_are_resettable()) {
|
||||
error_report("cpus are not resettable, terminating");
|
||||
shutdown_requested = reason;
|
||||
} else {
|
||||
reset_requested = reason;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ int64_t replay_save_clock(unsigned int kind, int64_t clock, int64_t raw_icount)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t replay_read_clock(unsigned int kind)
|
||||
int64_t replay_read_clock(unsigned int kind, int64_t raw_icount)
|
||||
{
|
||||
abort();
|
||||
return 0;
|
||||
|
||||
@@ -1045,3 +1045,8 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)
|
||||
{
|
||||
return (data - 32) & 0xffff;
|
||||
}
|
||||
|
||||
bool kvm_arch_cpu_check_are_resettable(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5984,6 +5984,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
|
||||
break;
|
||||
case 0x8000001F:
|
||||
*eax = sev_enabled() ? 0x2 : 0;
|
||||
*eax |= sev_es_enabled() ? 0x8 : 0;
|
||||
*ebx = sev_get_cbit_position();
|
||||
*ebx |= sev_get_reduced_phys_bits() << 6;
|
||||
*ecx = 0;
|
||||
|
||||
@@ -368,6 +368,7 @@ typedef enum X86Seg {
|
||||
|
||||
#define MSR_IA32_SMBASE 0x9e
|
||||
#define MSR_SMI_COUNT 0x34
|
||||
#define MSR_CORE_THREAD_COUNT 0x35
|
||||
#define MSR_MTRRcap 0xfe
|
||||
#define MSR_MTRRcap_VCNT 8
|
||||
#define MSR_MTRRcap_FIXRANGE_SUPPORT (1 << 8)
|
||||
|
||||
@@ -21,21 +21,6 @@
|
||||
#include "cpu.h"
|
||||
#include "x86.h"
|
||||
|
||||
#define HVF_MAX_VCPU 0x10
|
||||
|
||||
extern struct hvf_state hvf_global;
|
||||
|
||||
struct hvf_vm {
|
||||
int id;
|
||||
struct hvf_vcpu_state *vcpus[HVF_MAX_VCPU];
|
||||
};
|
||||
|
||||
struct hvf_state {
|
||||
uint32_t version;
|
||||
struct hvf_vm *vm;
|
||||
uint64_t mem_quota;
|
||||
};
|
||||
|
||||
/* hvf_slot flags */
|
||||
#define HVF_SLOT_LOG (1 << 0)
|
||||
|
||||
@@ -75,7 +60,6 @@ hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
|
||||
|
||||
/* Host specific functions */
|
||||
int hvf_inject_interrupt(CPUArchState *env, int vector);
|
||||
int hvf_vcpu_run(struct hvf_vcpu_state *vcpu);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+99
-1
@@ -65,6 +65,7 @@
|
||||
|
||||
#include <Hypervisor/hv.h>
|
||||
#include <Hypervisor/hv_vmx.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include "exec/address-spaces.h"
|
||||
#include "hw/i386/apic_internal.h"
|
||||
@@ -456,6 +457,48 @@ static void dummy_signal(int sig)
|
||||
{
|
||||
}
|
||||
|
||||
static void init_tsc_freq(CPUX86State *env)
|
||||
{
|
||||
size_t length;
|
||||
uint64_t tsc_freq;
|
||||
|
||||
if (env->tsc_khz != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
length = sizeof(uint64_t);
|
||||
if (sysctlbyname("machdep.tsc.frequency", &tsc_freq, &length, NULL, 0)) {
|
||||
return;
|
||||
}
|
||||
env->tsc_khz = tsc_freq / 1000; /* Hz to KHz */
|
||||
}
|
||||
|
||||
static void init_apic_bus_freq(CPUX86State *env)
|
||||
{
|
||||
size_t length;
|
||||
uint64_t bus_freq;
|
||||
|
||||
if (env->apic_bus_freq != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
length = sizeof(uint64_t);
|
||||
if (sysctlbyname("hw.busfrequency", &bus_freq, &length, NULL, 0)) {
|
||||
return;
|
||||
}
|
||||
env->apic_bus_freq = bus_freq;
|
||||
}
|
||||
|
||||
static inline bool tsc_is_known(CPUX86State *env)
|
||||
{
|
||||
return env->tsc_khz != 0;
|
||||
}
|
||||
|
||||
static inline bool apic_bus_freq_is_known(CPUX86State *env)
|
||||
{
|
||||
return env->apic_bus_freq != 0;
|
||||
}
|
||||
|
||||
int hvf_init_vcpu(CPUState *cpu)
|
||||
{
|
||||
|
||||
@@ -480,6 +523,15 @@ int hvf_init_vcpu(CPUState *cpu)
|
||||
hvf_state->hvf_caps = g_new0(struct hvf_vcpu_caps, 1);
|
||||
env->hvf_mmio_buf = g_new(char, 4096);
|
||||
|
||||
if (x86cpu->vmware_cpuid_freq) {
|
||||
init_tsc_freq(env);
|
||||
init_apic_bus_freq(env);
|
||||
|
||||
if (!tsc_is_known(env) || !apic_bus_freq_is_known(env)) {
|
||||
error_report("vmware-cpuid-freq: feature couldn't be enabled");
|
||||
}
|
||||
}
|
||||
|
||||
r = hv_vcpu_create((hv_vcpuid_t *)&cpu->hvf_fd, HV_VCPU_DEFAULT);
|
||||
cpu->vcpu_dirty = 1;
|
||||
assert_hvf_ok(r);
|
||||
@@ -597,6 +649,48 @@ static void hvf_store_events(CPUState *cpu, uint32_t ins_len, uint64_t idtvec_in
|
||||
}
|
||||
}
|
||||
|
||||
static void hvf_cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
|
||||
uint32_t *eax, uint32_t *ebx,
|
||||
uint32_t *ecx, uint32_t *edx)
|
||||
{
|
||||
/*
|
||||
* A wrapper extends cpu_x86_cpuid with 0x40000000 and 0x40000010 leafs,
|
||||
* leafs 0x40000001-0x4000000F are filled with zeros
|
||||
* Provides vmware-cpuid-freq support to hvf
|
||||
*
|
||||
* Note: leaf 0x40000000 not exposes HVF,
|
||||
* leaving hypervisor signature empty
|
||||
*/
|
||||
|
||||
if (index < 0x40000000 || index > 0x40000010 ||
|
||||
!tsc_is_known(env) || !apic_bus_freq_is_known(env)) {
|
||||
|
||||
cpu_x86_cpuid(env, index, count, eax, ebx, ecx, edx);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (index) {
|
||||
case 0x40000000:
|
||||
*eax = 0x40000010; /* Max available cpuid leaf */
|
||||
*ebx = 0; /* Leave signature empty */
|
||||
*ecx = 0;
|
||||
*edx = 0;
|
||||
break;
|
||||
case 0x40000010:
|
||||
*eax = env->tsc_khz;
|
||||
*ebx = env->apic_bus_freq / 1000; /* Hz to KHz */
|
||||
*ecx = 0;
|
||||
*edx = 0;
|
||||
break;
|
||||
default:
|
||||
*eax = 0;
|
||||
*ebx = 0;
|
||||
*ecx = 0;
|
||||
*edx = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int hvf_vcpu_exec(CPUState *cpu)
|
||||
{
|
||||
X86CPU *x86_cpu = X86_CPU(cpu);
|
||||
@@ -734,7 +828,11 @@ int hvf_vcpu_exec(CPUState *cpu)
|
||||
uint32_t rcx = (uint32_t)rreg(cpu->hvf_fd, HV_X86_RCX);
|
||||
uint32_t rdx = (uint32_t)rreg(cpu->hvf_fd, HV_X86_RDX);
|
||||
|
||||
cpu_x86_cpuid(env, rax, rcx, &rax, &rbx, &rcx, &rdx);
|
||||
if (rax == 1) {
|
||||
/* CPUID1.ecx.OSXSAVE needs to know CR4 */
|
||||
env->cr[4] = rvmcs(cpu->hvf_fd, VMCS_GUEST_CR4);
|
||||
}
|
||||
hvf_cpu_x86_cpuid(env, rax, rcx, &rax, &rbx, &rcx, &rdx);
|
||||
|
||||
wreg(cpu->hvf_fd, HV_X86_RAX, rax);
|
||||
wreg(cpu->hvf_fd, HV_X86_RBX, rbx);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user