aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/include/uapi/asm
diff options
context:
space:
mode:
authorJames Hogan <james.hogan@imgtec.com>2014-05-29 05:16:37 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2014-05-30 07:02:45 -0400
commitf82393426afb7c82f7618b3b4e440d8dd2b40c08 (patch)
treefdbaec36165ae0545c8561acf7d56cd09454faef /arch/mips/include/uapi/asm
parenteda3d33c685ff62524500681249e4c8e2e8dbb8c (diff)
MIPS: KVM: Add master disable count interface
Expose two new virtual registers to userland via the KVM_{GET,SET}_ONE_REG ioctls. KVM_REG_MIPS_COUNT_CTL is for timer configuration fields and just contains a master disable count bit. This can be used by userland to freeze the timer in order to read a consistent state from the timer count value and timer interrupt pending bit. This cannot be done with the CP0_Cause.DC bit because the timer interrupt pending bit (TI) is also in CP0_Cause so it would be impossible to stop the timer without also risking a race with an hrtimer interrupt and having to explicitly check whether an interrupt should have occurred. When the timer is re-enabled it resumes without losing time, i.e. the CP0_Count value jumps to what it would have been had the timer not been disabled, which would also be impossible to do from userland with CP0_Cause.DC. The timer interrupt also cannot be lost, i.e. if a timer interrupt would have occurred had the timer not been disabled it is queued when the timer is re-enabled. This works by storing the nanosecond monotonic time when the master disable is set, and using it for various operations instead of the current monotonic time (e.g. when recalculating the bias when the CP0_Count is set), until the master disable is cleared again, i.e. the timer state is read/written as it would have been at that time. This state is exposed to userland via the read-only KVM_REG_MIPS_COUNT_RESUME virtual register so that userland can determine the exact time the master disable took effect. This should allow userland to atomically save the state of the timer, and later restore it. Signed-off-by: James Hogan <james.hogan@imgtec.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Gleb Natapov <gleb@kernel.org> Cc: kvm@vger.kernel.org Cc: Ralf Baechle <ralf@linux-mips.org> Cc: linux-mips@linux-mips.org Cc: David Daney <david.daney@cavium.com> Cc: Sanjay Lal <sanjayl@kymasys.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/mips/include/uapi/asm')
-rw-r--r--arch/mips/include/uapi/asm/kvm.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/arch/mips/include/uapi/asm/kvm.h b/arch/mips/include/uapi/asm/kvm.h
index f09ff5ae2059..f859fbada1f7 100644
--- a/arch/mips/include/uapi/asm/kvm.h
+++ b/arch/mips/include/uapi/asm/kvm.h
@@ -106,6 +106,34 @@ struct kvm_fpu {
106#define KVM_REG_MIPS_LO (KVM_REG_MIPS | KVM_REG_SIZE_U64 | 33) 106#define KVM_REG_MIPS_LO (KVM_REG_MIPS | KVM_REG_SIZE_U64 | 33)
107#define KVM_REG_MIPS_PC (KVM_REG_MIPS | KVM_REG_SIZE_U64 | 34) 107#define KVM_REG_MIPS_PC (KVM_REG_MIPS | KVM_REG_SIZE_U64 | 34)
108 108
109/* KVM specific control registers */
110
111/*
112 * CP0_Count control
113 * DC: Set 0: Master disable CP0_Count and set COUNT_RESUME to now
114 * Set 1: Master re-enable CP0_Count with unchanged bias, handling timer
115 * interrupts since COUNT_RESUME
116 * This can be used to freeze the timer to get a consistent snapshot of
117 * the CP0_Count and timer interrupt pending state, while also resuming
118 * safely without losing time or guest timer interrupts.
119 * Other: Reserved, do not change.
120 */
121#define KVM_REG_MIPS_COUNT_CTL (KVM_REG_MIPS | KVM_REG_SIZE_U64 | \
122 0x20000 | 0)
123#define KVM_REG_MIPS_COUNT_CTL_DC 0x00000001
124
125/*
126 * CP0_Count resume monotonic nanoseconds
127 * The monotonic nanosecond time of the last set of COUNT_CTL.DC (master
128 * disable). Any reads and writes of Count related registers while
129 * COUNT_CTL.DC=1 will appear to occur at this time. When COUNT_CTL.DC is
130 * cleared again (master enable) any timer interrupts since this time will be
131 * emulated.
132 * Modifications to times in the future are rejected.
133 */
134#define KVM_REG_MIPS_COUNT_RESUME (KVM_REG_MIPS | KVM_REG_SIZE_U64 | \
135 0x20000 | 1)
136
109/* 137/*
110 * KVM MIPS specific structures and definitions 138 * KVM MIPS specific structures and definitions
111 * 139 *