GIMAllHv.cpp revision 46fa8016c74a7f3a46a16278103fda26c749e6f1
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync/* $Id$ */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync/** @file
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * GIM - Guest Interface Manager, Microsoft Hyper-V, All Contexts.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync/*
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * Copyright (C) 2014 Oracle Corporation
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * available from http://www.virtualbox.org. This file is free software;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * you can redistribute it and/or modify it under the terms of the GNU
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * General Public License (GPL) as published by the Free Software
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync/*******************************************************************************
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync* Header Files *
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync*******************************************************************************/
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#define LOG_GROUP LOG_GROUP_GIM
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#include "GIMHvInternal.h"
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#include "GIMInternal.h"
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#include <VBox/err.h>
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#include <VBox/vmm/hm.h>
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#include <VBox/vmm/tm.h>
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#include <VBox/vmm/vm.h>
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#include <VBox/vmm/pgm.h>
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#include <VBox/vmm/pdmdev.h>
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#include <VBox/vmm/pdmapi.h>
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#include <iprt/asm-amd64-x86.h>
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#include <iprt/spinlock.h>
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync/**
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * Handles the Hyper-V hypercall.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @returns VBox status code.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param pVCpu Pointer to the VMCPU.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param pCtx Pointer to the guest-CPU context.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsyncVMM_INT_DECL(int) GIMHvHypercall(PVMCPU pVCpu, PCPUMCTX pCtx)
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync{
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync PVM pVM = pVCpu->CTX_SUFF(pVM);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync if (!MSR_GIM_HV_HYPERCALL_IS_ENABLED(pVM->gim.s.u.Hv.u64HypercallMsr))
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VERR_GIM_HYPERCALLS_NOT_ENABLED;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync /** @todo Handle hypercalls. Fail for now */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VERR_GIM_IPE_3;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync}
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync/**
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * Returns whether the guest has configured and enabled the use of Hyper-V's
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * hypercall interface.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @returns true if hypercalls are enabled, false otherwise.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param pVCpu Pointer to the VMCPU.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsyncVMM_INT_DECL(bool) GIMHvAreHypercallsEnabled(PVMCPU pVCpu)
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync{
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return MSR_GIM_HV_HYPERCALL_IS_ENABLED(pVCpu->CTX_SUFF(pVM)->gim.s.u.Hv.u64HypercallMsr);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync}
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync/**
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * Returns whether the guest has configured and enabled the use of Hyper-V's
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * paravirtualized TSC.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @returns true if paravirt. TSC is enabled, false otherwise.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param pVM Pointer to the VM.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsyncVMM_INT_DECL(bool) GIMHvIsParavirtTscEnabled(PVM pVM)
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync{
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return MSR_GIM_HV_REF_TSC_IS_ENABLED(pVM->gim.s.u.Hv.u64TscPageMsr);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync}
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync/**
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * MSR read handler for Hyper-V.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @returns Strict VBox status code like CPUMQueryGuestMsr.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @retval VINF_CPUM_R3_MSR_READ
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @retval VERR_CPUM_RAISE_GP_0
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param pVCpu Pointer to the VMCPU.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param idMsr The MSR being read.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param pRange The range this MSR belongs to.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param puValue Where to store the MSR value read.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsyncVMM_INT_DECL(VBOXSTRICTRC) GIMHvReadMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t *puValue)
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync{
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync NOREF(pRange);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync PVM pVM = pVCpu->CTX_SUFF(pVM);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync PGIMHV pHv = &pVM->gim.s.u.Hv;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync switch (idMsr)
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync {
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_TIME_REF_COUNT:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync {
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync /* Hyper-V reports the time in 100 ns units (10 MHz). */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync uint64_t u64Tsc = TMCpuTickGet(pVCpu);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync uint64_t u64TscHz = TMCpuTicksPerSecond(pVM);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync uint64_t u64Tsc100Ns = u64TscHz / UINT64_C(10000000); /* 100 ns */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *puValue = (u64Tsc / u64Tsc100Ns);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync }
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_VP_INDEX:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *puValue = pVCpu->idCpu;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_TPR:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync PDMApicReadMSR(pVM, pVCpu->idCpu, 0x80, puValue);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_EOI:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync PDMApicReadMSR(pVM, pVCpu->idCpu, 0x0B, puValue);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_ICR:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync PDMApicReadMSR(pVM, pVCpu->idCpu, 0x30, puValue);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_GUEST_OS_ID:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *puValue = pHv->u64GuestOsIdMsr;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_HYPERCALL:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *puValue = pHv->u64HypercallMsr;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_REF_TSC:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *puValue = pHv->u64TscPageMsr;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_TSC_FREQ:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *puValue = TMCpuTicksPerSecond(pVM);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_APIC_FREQ:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync {
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync int rc = PDMApicGetTimerFreq(pVM, puValue);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync if (RT_FAILURE(rc))
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VERR_CPUM_RAISE_GP_0;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync }
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_RESET:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *puValue = 0;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync default:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#ifdef IN_RING3
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync static uint32_t s_cTimes = 0;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync if (s_cTimes++ < 20)
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync LogRel(("GIM: HyperV: Unknown/invalid RdMsr (%#x) -> #GP(0)\n", idMsr));
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#endif
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync LogFunc(("Unknown/invalid RdMsr (%#RX32) -> #GP(0)\n", idMsr));
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync break;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync }
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VERR_CPUM_RAISE_GP_0;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync}
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync/**
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * MSR write handler for Hyper-V.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @returns Strict VBox status code like CPUMSetGuestMsr.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @retval VINF_CPUM_R3_MSR_WRITE
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @retval VERR_CPUM_RAISE_GP_0
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync *
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param pVCpu Pointer to the VMCPU.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param idMsr The MSR being written.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param pRange The range this MSR belongs to.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync * @param uRawValue The raw value with the ignored bits not masked.
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsyncVMM_INT_DECL(VBOXSTRICTRC) GIMHvWriteMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t uRawValue)
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync{
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync NOREF(pRange);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync PVM pVM = pVCpu->CTX_SUFF(pVM);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync PGIMHV pHv = &pVM->gim.s.u.Hv;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync switch (idMsr)
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync {
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_TPR:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync PDMApicWriteMSR(pVM, pVCpu->idCpu, 0x80, uRawValue);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_EOI:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync PDMApicWriteMSR(pVM, pVCpu->idCpu, 0x0B, uRawValue);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_ICR:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync PDMApicWriteMSR(pVM, pVCpu->idCpu, 0x30, uRawValue);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_GUEST_OS_ID:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync {
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#ifndef IN_RING3
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_CPUM_R3_MSR_WRITE;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#else
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync /* Disable the hypercall-page if 0 is written to this MSR. */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync if (!uRawValue)
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync {
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync GIMR3HvDisableHypercallPage(pVM);
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync pHv->u64HypercallMsr &= ~MSR_GIM_HV_HYPERCALL_ENABLE_BIT;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync }
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync pHv->u64GuestOsIdMsr = uRawValue;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync return VINF_SUCCESS;
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#endif /* IN_RING3 */
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync }
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync case MSR_GIM_HV_HYPERCALL:
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync {
e6725710856db1d20c16eb103a0d3ea8f46a982avboxsync#ifndef IN_RING3
return VINF_CPUM_R3_MSR_WRITE;
#else /* IN_RING3 */
/*
* For now ignore writes to the hypercall MSR (i.e. keeps it disabled).
* This is required to boot FreeBSD 10.1 (with Hyper-V enabled ofc),
* see @bugref{7270} comment #116.
*/
return VINF_SUCCESS;
# if 0
/* First, update all but the hypercall enable bit. */
pHv->u64HypercallMsr = (uRawValue & ~MSR_GIM_HV_HYPERCALL_ENABLE_BIT);
/* Hypercalls can only be enabled when the guest has set the Guest-OS Id Msr. */
bool fEnable = RT_BOOL(uRawValue & MSR_GIM_HV_HYPERCALL_ENABLE_BIT);
if ( fEnable
&& !pHv->u64GuestOsIdMsr)
{
return VINF_SUCCESS;
}
/* Is the guest disabling the hypercall-page? Allow it regardless of the Guest-OS Id Msr. */
if (!fEnable)
{
GIMR3HvDisableHypercallPage(pVM);
pHv->u64HypercallMsr = uRawValue;
return VINF_SUCCESS;
}
/* Enable the hypercall-page. */
RTGCPHYS GCPhysHypercallPage = MSR_GIM_HV_HYPERCALL_GUEST_PFN(uRawValue) << PAGE_SHIFT;
int rc = GIMR3HvEnableHypercallPage(pVM, GCPhysHypercallPage);
if (RT_SUCCESS(rc))
{
pHv->u64HypercallMsr = uRawValue;
return VINF_SUCCESS;
}
return VERR_CPUM_RAISE_GP_0;
# endif
#endif /* IN_RING3 */
}
case MSR_GIM_HV_REF_TSC:
{
#ifndef IN_RING3
return VINF_CPUM_R3_MSR_WRITE;
#else /* IN_RING3 */
/* First, update all but the TSC-page enable bit. */
pHv->u64TscPageMsr = (uRawValue & ~MSR_GIM_HV_REF_TSC_ENABLE_BIT);
/* Is the guest disabling the TSC-page? */
bool fEnable = RT_BOOL(uRawValue & MSR_GIM_HV_REF_TSC_ENABLE_BIT);
if (!fEnable)
{
GIMR3HvDisableTscPage(pVM);
pHv->u64TscPageMsr = uRawValue;
return VINF_SUCCESS;
}
/* Enable the TSC-page. */
RTGCPHYS GCPhysTscPage = MSR_GIM_HV_REF_TSC_GUEST_PFN(uRawValue) << PAGE_SHIFT;
int rc = GIMR3HvEnableTscPage(pVM, GCPhysTscPage, false /* fUseThisTscSequence */, 0 /* uTscSequence */);
if (RT_SUCCESS(rc))
{
pHv->u64TscPageMsr = uRawValue;
return VINF_SUCCESS;
}
return VERR_CPUM_RAISE_GP_0;
#endif /* IN_RING3 */
}
case MSR_GIM_HV_RESET:
{
#ifndef IN_RING3
return VINF_CPUM_R3_MSR_WRITE;
#else
if (MSR_GIM_HV_RESET_IS_SET(uRawValue))
{
LogRel(("GIM: HyperV: Reset initiated through MSR.\n"));
int rc = PDMDevHlpVMReset(pVM->gim.s.pDevInsR3);
AssertRC(rc);
}
/* else: Ignore writes to other bits. */
return VINF_SUCCESS;
#endif /* IN_RING3 */
}
case MSR_GIM_HV_TIME_REF_COUNT: /* Read-only MSRs. */
case MSR_GIM_HV_VP_INDEX:
case MSR_GIM_HV_TSC_FREQ:
case MSR_GIM_HV_APIC_FREQ:
LogFunc(("WrMsr on read-only MSR %#RX32 -> #GP(0)\n", idMsr));
return VERR_CPUM_RAISE_GP_0;
default:
#ifdef IN_RING3
static uint32_t s_cTimes = 0;
if (s_cTimes++ < 20)
LogRel(("GIM: HyperV: Unknown/invalid WrMsr (%#x,%#x`%08x) -> #GP(0)\n", idMsr, uRawValue & UINT64_C(0xffffffff00000000),
uRawValue & UINT64_C(0xffffffff)));
#endif
LogFunc(("Unknown/invalid WrMsr (%#RX32,%#RX64) -> #GP(0)\n", idMsr, uRawValue));
break;
}
return VERR_CPUM_RAISE_GP_0;
}