0
votes

ARMv7 architectures with hardware virtualization support also include virtualization support for timers and the interrupt controller.

I would like to know how guest access virtual timer in this Virtualized environment?

Is it like when guest trying to access virtual timer it(Guest KVM) would Inject virtual interrupt(kvm_vgic_inject_irq) to vgic code?

Could any one please provide the details on Guest access Virtual timer in ARM?

EDIT

I am trying to understand source flow from the point Guest access the Virtual timer. As per my understanding

When KVM Guest trying to access(read VTimer tick/count) , it would inject virtual interrupt to vgic code via ach_timer.c

                    kvm_timer_inject_irq()
                             |
                             |
                     kvm_vgic_inject_irq()
                             |                                 
                             |
                       kvm_vcpu_kick()  
                             | 
                             | 
                       timer_handler()
                             |
                             |
                      arch_timer_reg_read()
                             |
                             |
                    arch_timer_reg_read_cp15()    

Also,reading Vtimer count from guest would not generate any trap as can't find any vmexit or vmentry in code flow, right?

1
As per the code, it just reads its virtual count out of CNTVCT, same way the host kernel does. Unless you mean some other interpretation of "access"?Notlikethat
Ok, But if Guest kernel is also reading the virtual count out of CNTVCT then how guest sync its time with host using cntvoff register which is programmed only in Hypervisor KVM?Amit Singh Tomar
I don't understand what you mean by "sync its time with the host" - the whole point of the virtualised counter is to hide host time from the guests, so that they don't see large jumps in their counter value when their vCPU gets rescheduled after something else was running.Notlikethat
Ok, By sync I meant, whatever time is seen at host, same time would be their on host.let's say host start at time 10pm and after 20 mins we do lunch a guest , would guest should show time as 10:20 pm same as host?Amit Singh Tomar

1 Answers

1
votes

I will divide the answer into two parts:

1. Accessing Virtual Timer registers: The guest OS will be accessing a Virtual timer. KVM will keep a copy of the Virtual Timer registers in VM context for each VM in the system. This (timer) context will be switching IN/OUT during VM switching. In addition to this, Virtual timer's counter can be adjusted by Host Kernel using the Timer Offset register. (The adjustment is done to account for lost ticks when other Guest VMs were executing). These two mechanisms allows KVM to switch between VM's and virtualize the timer registers.

2. Routing of Virtual timer interrupts All interrupts in the system are routed through KVM. KVM decides based on the interrupt number (and other paramater) as to which Guest should be getting the interrupt. Once a decision is made to deliver the interrupt, KVM will ask the VCPU interface of VGIC to fire an interrupt for the particual VM. Essentially the Virtual timer interrupt is routed to Guest VM just like any other Interrupt in the system

The call trace you have pasted in your question, shows how an interrupt is generally handled. The 'timer_handler' was called, because in this particular instance the timer interrupt fired, the top half of the trace would remain pretty much same for any interrupt.