• Bibo Mao's avatar
    LoongArch: KVM: Fix timer emulation with oneshot mode · 5b3d5249
    Bibo Mao authored
    When timer is fired in oneshot mode, CSR TVAL will be -1 rather than 0.
    There needs special handing for this situation. There are two scenarios
    when oneshot timer is fired. One scenario is that time is fired after
    exiting to host, CSR TVAL is set with 0 in order to inject hw interrupt,
    and -1 will assigned to CSR TVAL soon.
    
    The other situation is that timer is fired in VM and guest kernel is
    hanlding timer IRQ, IRQ is acked and is ready to set next expired timer
    value, then vm exits to host. Timer interrupt should not be inject at
    this point, else there will be spurious timer interrupt.
    
    Here hw timer irq status in CSR ESTAT is used to judge these two
    scenarios. If CSR TVAL is -1, the oneshot timer is fired; and if timer
    hw irq is on in CSR ESTAT register, it happens after exiting to host;
    else if timer hw irq is off, we think that it happens in vm and timer
    IRQ handler has already acked IRQ.
    
    With this patch, runltp with version ltp20230516 passes to run in vm.
    Signed-off-by: default avatarBibo Mao <maobibo@loongson.cn>
    Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
    5b3d5249
timer.c 5.96 KB