aboutsummaryrefslogtreecommitdiff
path: root/target/i386/whpx-all.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2018-03-06 13:24:35 +0000
committerPeter Maydell <peter.maydell@linaro.org>2018-03-06 13:24:35 +0000
commitb5fe11a49ad3df109bfb32dea2f2ef74d1d3ca13 (patch)
treec9007e013761351acda3bbc000e36d192a180827 /target/i386/whpx-all.c
parent58e2e17dba49b43f4ac9de19468aeae1c787dcc2 (diff)
parent3e015d815b3f28bfd874bf8a1697308ef9af2b4c (diff)
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
* new QMP command qom-list-properties (Alexey) * TCG cleanups (David) * use g_path_get_basename/g_path_get_dirname when useful (Julia) * WHPX fixes (Justin) * ASAN fixes (Marc-André) * g364fb memory leak fix, address_space_to_flatview RCU fixes (me) * chardev memory leak fix (Peter) * checkpatch improvements (Julia, Su Hang) * next round of deprecation patches (Thomas) # gpg: Signature made Tue 06 Mar 2018 13:11:58 GMT # gpg: using RSA key BFFBD25F78C7AE83 # gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" # gpg: aka "Paolo Bonzini <pbonzini@redhat.com>" # 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/tags/for-upstream: (34 commits) use g_path_get_basename instead of basename balloon: Fix documentation of the --balloon parameter and deprecate it WHPX improve interrupt notification registration WHXP Removes the use of WHvGetExitContextSize Fix WHPX issue leaking tpr values Fix WHPX typo in 'mmio' Fix WHPX additional lock acquisition Remove unnecessary WHPX __debugbreak(); Resolves WHPX breaking changes in SDK 17095 Fixing WHPX casing to match SDK Revert "build-sys: compile with -Og or -O1 when --enable-debug" checkpatch: add check for `while` and `for` checkpatch: add a warning for basename/dirname address_space_rw: address_space_to_flatview needs RCU lock address_space_map: address_space_to_flatview needs RCU lock address_space_access_valid: address_space_to_flatview needs RCU lock address_space_read: address_space_to_flatview needs RCU lock address_space_write: address_space_to_flatview needs RCU lock memory: inline some performance-sensitive accessors openpic_kvm: drop address_space_to_flatview call ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'target/i386/whpx-all.c')
-rw-r--r--target/i386/whpx-all.c70
1 files changed, 23 insertions, 47 deletions
diff --git a/target/i386/whpx-all.c b/target/i386/whpx-all.c
index 0015b27509..940bbe590d 100644
--- a/target/i386/whpx-all.c
+++ b/target/i386/whpx-all.c
@@ -26,13 +26,12 @@
#include "qapi/error.h"
#include "migration/blocker.h"
-#include <winhvplatform.h>
-#include <winhvemulation.h>
+#include <WinHvPlatform.h>
+#include <WinHvEmulation.h>
struct whpx_state {
uint64_t mem_quota;
WHV_PARTITION_HANDLE partition;
- uint32_t exit_ctx_size;
};
static const WHV_REGISTER_NAME whpx_register_names[] = {
@@ -364,7 +363,6 @@ static void whpx_set_registers(CPUState *cpu)
if (FAILED(hr)) {
error_report("WHPX: Failed to set virtual processor context, hr=%08lx",
hr);
- __debugbreak();
}
return;
@@ -391,7 +389,6 @@ static void whpx_get_registers(CPUState *cpu)
if (FAILED(hr)) {
error_report("WHPX: Failed to get virtual processor context, hr=%08lx",
hr);
- __debugbreak();
}
/* Indexes for first 16 registers match between HV and QEMU definitions */
@@ -529,7 +526,7 @@ static HRESULT CALLBACK whpx_emu_ioport_callback(
return S_OK;
}
-static HRESULT CALLBACK whpx_emu_memio_callback(
+static HRESULT CALLBACK whpx_emu_mmio_callback(
void *ctx,
WHV_EMULATOR_MEMORY_ACCESS_INFO *ma)
{
@@ -554,7 +551,6 @@ static HRESULT CALLBACK whpx_emu_getreg_callback(
if (FAILED(hr)) {
error_report("WHPX: Failed to get virtual processor registers,"
" hr=%08lx", hr);
- __debugbreak();
}
return hr;
@@ -576,7 +572,6 @@ static HRESULT CALLBACK whpx_emu_setreg_callback(
if (FAILED(hr)) {
error_report("WHPX: Failed to set virtual processor registers,"
" hr=%08lx", hr);
- __debugbreak();
}
/*
@@ -604,7 +599,6 @@ static HRESULT CALLBACK whpx_emu_translate_callback(
Gva, TranslateFlags, &res, Gpa);
if (FAILED(hr)) {
error_report("WHPX: Failed to translate GVA, hr=%08lx", hr);
- __debugbreak();
} else {
*TranslationResult = res.ResultCode;
}
@@ -613,8 +607,9 @@ static HRESULT CALLBACK whpx_emu_translate_callback(
}
static const WHV_EMULATOR_CALLBACKS whpx_emu_callbacks = {
+ .Size = sizeof(WHV_EMULATOR_CALLBACKS),
.WHvEmulatorIoPortCallback = whpx_emu_ioport_callback,
- .WHvEmulatorMemoryCallback = whpx_emu_memio_callback,
+ .WHvEmulatorMemoryCallback = whpx_emu_mmio_callback,
.WHvEmulatorGetVirtualProcessorRegisters = whpx_emu_getreg_callback,
.WHvEmulatorSetVirtualProcessorRegisters = whpx_emu_setreg_callback,
.WHvEmulatorTranslateGvaPage = whpx_emu_translate_callback,
@@ -626,15 +621,15 @@ static int whpx_handle_mmio(CPUState *cpu, WHV_MEMORY_ACCESS_CONTEXT *ctx)
struct whpx_vcpu *vcpu = get_whpx_vcpu(cpu);
WHV_EMULATOR_STATUS emu_status;
- hr = WHvEmulatorTryMmioEmulation(vcpu->emulator, cpu, ctx, &emu_status);
+ hr = WHvEmulatorTryMmioEmulation(vcpu->emulator, cpu,
+ &vcpu->exit_ctx.VpContext, ctx,
+ &emu_status);
if (FAILED(hr)) {
- __debugbreak();
error_report("WHPX: Failed to parse MMIO access, hr=%08lx", hr);
return -1;
}
if (!emu_status.EmulationSuccessful) {
- __debugbreak();
error_report("WHPX: Failed to emulate MMIO access");
return -1;
}
@@ -649,15 +644,15 @@ static int whpx_handle_portio(CPUState *cpu,
struct whpx_vcpu *vcpu = get_whpx_vcpu(cpu);
WHV_EMULATOR_STATUS emu_status;
- hr = WHvEmulatorTryIoEmulation(vcpu->emulator, cpu, ctx, &emu_status);
+ hr = WHvEmulatorTryIoEmulation(vcpu->emulator, cpu,
+ &vcpu->exit_ctx.VpContext, ctx,
+ &emu_status);
if (FAILED(hr)) {
- __debugbreak();
error_report("WHPX: Failed to parse PortIO access, hr=%08lx", hr);
return -1;
}
if (!emu_status.EmulationSuccessful) {
- __debugbreak();
error_report("WHPX: Failed to emulate PortMMIO access");
return -1;
}
@@ -691,6 +686,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu)
struct CPUX86State *env = (CPUArchState *)(cpu->env_ptr);
X86CPU *x86_cpu = X86_CPU(cpu);
int irq;
+ uint8_t tpr;
WHV_X64_PENDING_INTERRUPTION_REGISTER new_int = {0};
UINT32 reg_count = 0;
WHV_REGISTER_VALUE reg_values[3] = {0};
@@ -709,10 +705,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu)
new_int.InterruptionVector = 2;
}
if (cpu->interrupt_request & CPU_INTERRUPT_SMI) {
- qemu_mutex_lock_iothread();
cpu->interrupt_request &= ~CPU_INTERRUPT_SMI;
- __debugbreak();
- qemu_mutex_unlock_iothread();
}
}
@@ -753,21 +746,21 @@ static void whpx_vcpu_pre_run(CPUState *cpu)
}
/* Sync the TPR to the CR8 if was modified during the intercept */
- reg_values[reg_count].Reg64 = cpu_get_apic_tpr(x86_cpu->apic_state);
- if (reg_values[reg_count].Reg64 != vcpu->tpr) {
- vcpu->tpr = reg_values[reg_count].Reg64;
+ tpr = cpu_get_apic_tpr(x86_cpu->apic_state);
+ if (tpr != vcpu->tpr) {
+ vcpu->tpr = tpr;
+ reg_values[reg_count].Reg64 = tpr;
cpu->exit_request = 1;
reg_names[reg_count] = WHvX64RegisterCr8;
reg_count += 1;
}
/* Update the state of the interrupt delivery notification */
- if (cpu->interrupt_request & CPU_INTERRUPT_HARD) {
+ if (!vcpu->window_registered &&
+ cpu->interrupt_request & CPU_INTERRUPT_HARD) {
reg_values[reg_count].DeliverabilityNotifications.InterruptNotification
= 1;
- if (vcpu->window_registered != 1) {
- vcpu->window_registered = 1;
- }
+ vcpu->window_registered = 1;
reg_names[reg_count] = WHvX64RegisterDeliverabilityNotifications;
reg_count += 1;
}
@@ -780,7 +773,6 @@ static void whpx_vcpu_pre_run(CPUState *cpu)
if (FAILED(hr)) {
error_report("WHPX: Failed to set interrupt state registers,"
" hr=%08lx", hr);
- __debugbreak();
}
}
@@ -807,7 +799,6 @@ static void whpx_vcpu_post_run(CPUState *cpu)
if (FAILED(hr)) {
error_report("WHPX: Failed to get interrupt state regusters,"
" hr=%08lx", hr);
- __debugbreak();
vcpu->interruptable = false;
return;
}
@@ -905,18 +896,8 @@ static int whpx_vcpu_run(CPUState *cpu)
whpx_vcpu_kick(cpu);
}
- for (;;) {
- hr = WHvRunVirtualProcessor(whpx->partition, cpu->cpu_index,
- &vcpu->exit_ctx, whpx->exit_ctx_size);
-
- if (SUCCEEDED(hr) && (vcpu->exit_ctx.ExitReason ==
- WHvRunVpExitReasonAlerted)) {
- WHvCancelRunVirtualProcessor(whpx->partition, cpu->cpu_index,
- 0);
- } else {
- break;
- }
- }
+ hr = WHvRunVirtualProcessor(whpx->partition, cpu->cpu_index,
+ &vcpu->exit_ctx, sizeof(vcpu->exit_ctx));
if (FAILED(hr)) {
error_report("WHPX: Failed to exec a virtual processor,"
@@ -956,7 +937,6 @@ static int whpx_vcpu_run(CPUState *cpu)
case WHvRunVpExitReasonX64MsrAccess:
case WHvRunVpExitReasonX64Cpuid:
case WHvRunVpExitReasonException:
- case WHvRunVpExitReasonAlerted:
default:
error_report("WHPX: Unexpected VP exit code %d",
vcpu->exit_ctx.ExitReason);
@@ -1060,15 +1040,14 @@ int whpx_init_vcpu(CPUState *cpu)
}
}
- vcpu = g_malloc0(FIELD_OFFSET(struct whpx_vcpu, exit_ctx) +
- whpx->exit_ctx_size);
+ vcpu = g_malloc0(sizeof(struct whpx_vcpu));
if (!vcpu) {
error_report("WHPX: Failed to allocte VCPU context.");
return -ENOMEM;
}
- hr = WHvEmulatorCreateEmulator(whpx_emu_callbacks, &vcpu->emulator);
+ hr = WHvEmulatorCreateEmulator(&whpx_emu_callbacks, &vcpu->emulator);
if (FAILED(hr)) {
error_report("WHPX: Failed to setup instruction completion support,"
" hr=%08lx", hr);
@@ -1318,9 +1297,6 @@ static int whpx_accel_init(MachineState *ms)
goto error;
}
- whpx->exit_ctx_size = WHvGetRunExitContextSize();
- assert(whpx->exit_ctx_size);
-
whpx_memory_init();
cpu_interrupt_handler = whpx_handle_interrupt;