Skip to content

Commit bee038a

Browse files
christofferdall-armMarc Zyngier
authored andcommitted
KVM: arm/arm64: Rework the timer code to use a timer_map
We are currently emulating two timers in two different ways. When we add support for nested virtualization in the future, we are going to be emulating either two timers in two diffferent ways, or four timers in a single way. We need a unified data structure to keep track of how we map virtual state to physical state and we need to cleanup some of the timer code to operate more independently on a struct arch_timer_context instead of trying to consider the global state of the VCPU and recomputing all state. Co-written with Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <christoffer.dall@arm.com>
1 parent 9e01dc7 commit bee038a

3 files changed

Lines changed: 278 additions & 145 deletions

File tree

‎include/kvm/arm_arch_timer.h‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,24 @@ struct arch_timer_context {
5151
/* Emulated Timer (may be unused) */
5252
struct hrtimer hrtimer;
5353

54+
/*
55+
* We have multiple paths which can save/restore the timer state onto
56+
* the hardware, so we need some way of keeping track of where the
57+
* latest state is.
58+
*/
59+
bool loaded;
60+
5461
/* Duplicated state from arch_timer.c for convenience */
5562
u32 host_timer_irq;
5663
u32 host_timer_irq_flags;
5764
};
5865

66+
struct timer_map {
67+
struct arch_timer_context *direct_vtimer;
68+
struct arch_timer_context *direct_ptimer;
69+
struct arch_timer_context *emul_ptimer;
70+
};
71+
5972
struct arch_timer_cpu {
6073
struct arch_timer_context timers[NR_KVM_TIMERS];
6174

@@ -64,16 +77,6 @@ struct arch_timer_cpu {
6477

6578
/* Is the timer enabled */
6679
bool enabled;
67-
68-
/*
69-
* We have multiple paths which can save/restore the timer state
70-
* onto the hardware, so we need some way of keeping track of
71-
* where the latest state is.
72-
*
73-
* loaded == true: State is loaded on the hardware registers.
74-
* loaded == false: State is stored in memory.
75-
*/
76-
bool loaded;
7780
};
7881

7982
int kvm_timer_hyp_init(bool);

0 commit comments

Comments
 (0)