• J
    MIPS: KVM: Add master disable count interface · f8239342
    James Hogan 提交于
    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: NJames 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: NPaolo Bonzini <pbonzini@redhat.com>
    f8239342
kvm.h 5.3 KB