GIMAllKvm.cpp revision 0bc35f54322c5f9b2d43b064f839a8cf8c99a234
/* $Id$ */
/** @file
* GIM - Guest Interface Manager, KVM, All Contexts.
*/
/*
* Copyright (C) 2015 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_GIM
#include "GIMKvmInternal.h"
#include "GIMInternal.h"
#include <iprt/asm-amd64-x86.h>
/**
* Handles the KVM hypercall.
*
* @returns VBox status code.
* @param pVCpu Pointer to the VMCPU.
* @param pCtx Pointer to the guest-CPU context.
*/
{
/** @todo Handle hypercalls. Fail for now */
return VERR_GIM_IPE_3;
}
/**
* Returns whether the guest has configured and enabled the use of KVM's
* hypercall interface.
*
* @returns true if hypercalls are enabled, false otherwise.
* @param pVCpu Pointer to the VMCPU.
*/
{
/* KVM paravirt interface doesn't have hypercall control bits like Hyper-V does
that guests can control. It's always enabled. */
return true;
}
/**
* Returns whether the guest has configured and enabled the use of KVM's
* paravirtualized TSC.
*
* @returns true if paravirt. TSC is enabled, false otherwise.
* @param pVM Pointer to the VM.
*/
{
return false; /** @todo implement this! */
}
/**
* MSR read handler for KVM.
*
* @returns Strict VBox status code like CPUMQueryGuestMsr().
* @retval VINF_CPUM_R3_MSR_READ
* @retval VERR_CPUM_RAISE_GP_0
*
* @param pVCpu Pointer to the VMCPU.
* @param idMsr The MSR being read.
* @param pRange The range this MSR belongs to.
* @param puValue Where to store the MSR value read.
*/
VMM_INT_DECL(VBOXSTRICTRC) gimKvmReadMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t *puValue)
{
switch (idMsr)
{
case MSR_GIM_KVM_SYSTEM_TIME:
return VINF_SUCCESS;
case MSR_GIM_KVM_WALL_CLOCK:
return VINF_SUCCESS;
default:
{
#ifdef IN_RING3
if (s_cTimes++ < 20)
#endif
break;
}
}
return VERR_CPUM_RAISE_GP_0;
}
/**
* MSR write handler for KVM.
*
* @returns Strict VBox status code like CPUMSetGuestMsr().
* @retval VINF_CPUM_R3_MSR_WRITE
* @retval VERR_CPUM_RAISE_GP_0
*
* @param pVCpu Pointer to the VMCPU.
* @param idMsr The MSR being written.
* @param pRange The range this MSR belongs to.
* @param uRawValue The raw value with the ignored bits not masked.
*/
VMM_INT_DECL(VBOXSTRICTRC) gimKvmWriteMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t uRawValue)
{
switch (idMsr)
{
case MSR_GIM_KVM_SYSTEM_TIME:
{
#ifndef IN_RING3
return VINF_CPUM_R3_MSR_WRITE;
#else
/* Is the guest disabling the system-time struct.? */
if (!fEnable)
{
return VINF_SUCCESS;
}
/* Is the system-time struct. already enabled? If so, get flags that need preserving. */
{
int rc2 = PGMPhysSimpleReadGCPhys(pVM, &SystemTime, pKvmCpu->GCPhysSystemTime, sizeof(GIMKVMSYSTEMTIME));
if (RT_SUCCESS(rc2))
}
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
return VERR_CPUM_RAISE_GP_0;
#endif /* IN_RING3 */
}
case MSR_GIM_KVM_WALL_CLOCK:
{
#ifndef IN_RING3
return VINF_CPUM_R3_MSR_WRITE;
#else
/* Enable the wall-clock struct. */
{
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
}
return VERR_CPUM_RAISE_GP_0;
#endif /* IN_RING3 */
}
default:
{
#ifdef IN_RING3
if (s_cTimes++ < 20)
#endif
break;
}
}
return VERR_CPUM_RAISE_GP_0;
}