The issue is related to how qemu TCG threads wake up due to an interrupt
pending at any privilege level.

target/riscv/cpu.c
bool riscv_cpu_has_work(CPUState *cs)
{
    RISCVCPU *cpu = RISCV_CPU(cs);
    CPURISCVState *env = &cpu->env;
    /*
     * Definition of the WFI instruction requires it to ignore the privilege
     * mode and delegation registers, but respect individual enables
     */
    return riscv_cpu_all_pending(env) != 0 ||
        riscv_cpu_sirq_pending(env) != RISCV_EXCP_NONE ||
        riscv_cpu_vsirq_pending(env) != RISCV_EXCP_NONE;
}

However, KVM doesn't reset the VSTIMECMP during vmexit. So the qemu tcg
thread keeps waking up due to previously programmed timer via vstimecmp.
There is no VM running hence the interrupt is not served.

--- a/arch/riscv/kvm/vcpu_timer.c
+++ b/arch/riscv/kvm/vcpu_timer.c
@@ -346,6 +346,12 @@ void kvm_riscv_vcpu_timer_save(struct kvm_vcpu *vcpu)
         * The vstimecmp CSRs are saved by kvm_riscv_vcpu_timer_sync()
         * upon every VM exit so no need to save here.
         */
+#if defined(CONFIG_32BIT)
+       t->next_cycles = ncsr_swap(CSR_VSTIMECMP, -1UL);
+       t->next_cycles |= (u64)ncsr_swap(CSR_VSTIMECMPH, -1UL) << 32;
+#else
+       t->next_cycles = ncsr_swap(CSR_VSTIMECMP, -1UL);
+#endif
 
        /* timer should be enabled for the remaining operations */
        if (unlikely(!t->init_done))

This fixes the host cpu usage issue in cases where AIA is not in use.
However, we are seeing rcu stalls with AIA enabled with this fix. We
(Anup & I) are debugging the the root cause behind it.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2112578

Title:
  riscv64: KVM does not release harts

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2112578/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to