Message ID | 20230210135136.1115213-1-rkanwal@rivosinc.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [1/1] riscv/kvm: Fix VM hang in case of timer delta being zero. | expand |
Context | Check | Description |
---|---|---|
conchuod/cover_letter | success | Single patches do not need cover letters |
conchuod/tree_selection | success | Guessed tree name to be for-next |
conchuod/fixes_present | success | Fixes tag not required for -next series |
conchuod/maintainers_pattern | success | MAINTAINERS pattern errors before the patch: 13 and now 13 |
conchuod/verify_signedoff | success | Signed-off-by tag matches author and committer |
conchuod/kdoc | success | Errors and warnings before: 0 this patch: 0 |
conchuod/build_rv64_clang_allmodconfig | success | Errors and warnings before: 0 this patch: 0 |
conchuod/module_param | success | Was 0 now: 0 |
conchuod/build_rv64_gcc_allmodconfig | success | Errors and warnings before: 0 this patch: 0 |
conchuod/alphanumeric_selects | success | Out of order selects before the patch: 59 and now 59 |
conchuod/build_rv32_defconfig | success | Build OK |
conchuod/dtb_warn_rv64 | success | Errors and warnings before: 2 this patch: 2 |
conchuod/header_inline | success | No static functions without inline keyword in header files |
conchuod/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 12 lines checked |
conchuod/source_inline | success | Was 0 now: 0 |
conchuod/build_rv64_nommu_k210_defconfig | success | Build OK |
conchuod/verify_fixes | success | No Fixes tag |
conchuod/build_rv64_nommu_virt_defconfig | success | Build OK |
On Fri, Feb 10, 2023 at 7:21 PM Rajnesh Kanwal <rkanwal@rivosinc.com> wrote: > > In case when VCPU is blocked due to WFI, we schedule the timer > from `kvm_riscv_vcpu_timer_blocking()` to keep timer interrupt > ticking. > > But in case when delta_ns comes to be zero, we never schedule > the timer and VCPU keeps sleeping indefinitely until any activity > is done with VM console. > > This is easily reproduce-able using kvmtool. > ./lkvm-static run -c1 --console virtio -p "earlycon root=/dev/vda" \ > -k ./Image -d rootfs.ext4 > > Also, just add a print in kvm_riscv_vcpu_vstimer_expired() to > check the interrupt delivery and run `top` or similar auto-upating > cmd from guest. Within sometime one can notice that print from > timer expiry routine stops and the `top` cmd output will stop > updating. > > This change fixes this by making sure we schedule the timer even > with delta_ns being zero to bring the VCPU out of sleep immediately. > Please add the Fixes tag here. > Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com> > --- > arch/riscv/kvm/vcpu_timer.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/arch/riscv/kvm/vcpu_timer.c b/arch/riscv/kvm/vcpu_timer.c > index ad34519c8a13..3ac2ff6a65da 100644 > --- a/arch/riscv/kvm/vcpu_timer.c > +++ b/arch/riscv/kvm/vcpu_timer.c > @@ -147,10 +147,8 @@ static void kvm_riscv_vcpu_timer_blocking(struct kvm_vcpu *vcpu) > return; > > delta_ns = kvm_riscv_delta_cycles2ns(t->next_cycles, gt, t); > - if (delta_ns) { > - hrtimer_start(&t->hrt, ktime_set(0, delta_ns), HRTIMER_MODE_REL); > - t->next_set = true; > - } > + hrtimer_start(&t->hrt, ktime_set(0, delta_ns), HRTIMER_MODE_REL); > + t->next_set = true; > } > > static void kvm_riscv_vcpu_timer_unblocking(struct kvm_vcpu *vcpu) > -- > 2.25.1 >
On Fri, Feb 10, 2023 at 2:07 PM Anup Patel <apatel@ventanamicro.com> wrote: > > On Fri, Feb 10, 2023 at 7:21 PM Rajnesh Kanwal <rkanwal@rivosinc.com> wrote: > > > > In case when VCPU is blocked due to WFI, we schedule the timer > > from `kvm_riscv_vcpu_timer_blocking()` to keep timer interrupt > > ticking. > > > > But in case when delta_ns comes to be zero, we never schedule > > the timer and VCPU keeps sleeping indefinitely until any activity > > is done with VM console. > > > > This is easily reproduce-able using kvmtool. > > ./lkvm-static run -c1 --console virtio -p "earlycon root=/dev/vda" \ > > -k ./Image -d rootfs.ext4 > > > > Also, just add a print in kvm_riscv_vcpu_vstimer_expired() to > > check the interrupt delivery and run `top` or similar auto-upating > > cmd from guest. Within sometime one can notice that print from > > timer expiry routine stops and the `top` cmd output will stop > > updating. > > > > This change fixes this by making sure we schedule the timer even > > with delta_ns being zero to bring the VCPU out of sleep immediately. > > > > Please add the Fixes tag here. Fixed in v2. https://lore.kernel.org/all/20230210142711.1177212-1-rkanwal@rivosinc.com/T/#t Thanks Rajnesh > > > Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com> > > --- > > arch/riscv/kvm/vcpu_timer.c | 6 ++---- > > 1 file changed, 2 insertions(+), 4 deletions(-) > > > > diff --git a/arch/riscv/kvm/vcpu_timer.c b/arch/riscv/kvm/vcpu_timer.c > > index ad34519c8a13..3ac2ff6a65da 100644 > > --- a/arch/riscv/kvm/vcpu_timer.c > > +++ b/arch/riscv/kvm/vcpu_timer.c > > @@ -147,10 +147,8 @@ static void kvm_riscv_vcpu_timer_blocking(struct kvm_vcpu *vcpu) > > return; > > > > delta_ns = kvm_riscv_delta_cycles2ns(t->next_cycles, gt, t); > > - if (delta_ns) { > > - hrtimer_start(&t->hrt, ktime_set(0, delta_ns), HRTIMER_MODE_REL); > > - t->next_set = true; > > - } > > + hrtimer_start(&t->hrt, ktime_set(0, delta_ns), HRTIMER_MODE_REL); > > + t->next_set = true; > > } > > > > static void kvm_riscv_vcpu_timer_unblocking(struct kvm_vcpu *vcpu) > > -- > > 2.25.1 > >
diff --git a/arch/riscv/kvm/vcpu_timer.c b/arch/riscv/kvm/vcpu_timer.c index ad34519c8a13..3ac2ff6a65da 100644 --- a/arch/riscv/kvm/vcpu_timer.c +++ b/arch/riscv/kvm/vcpu_timer.c @@ -147,10 +147,8 @@ static void kvm_riscv_vcpu_timer_blocking(struct kvm_vcpu *vcpu) return; delta_ns = kvm_riscv_delta_cycles2ns(t->next_cycles, gt, t); - if (delta_ns) { - hrtimer_start(&t->hrt, ktime_set(0, delta_ns), HRTIMER_MODE_REL); - t->next_set = true; - } + hrtimer_start(&t->hrt, ktime_set(0, delta_ns), HRTIMER_MODE_REL); + t->next_set = true; } static void kvm_riscv_vcpu_timer_unblocking(struct kvm_vcpu *vcpu)
In case when VCPU is blocked due to WFI, we schedule the timer from `kvm_riscv_vcpu_timer_blocking()` to keep timer interrupt ticking. But in case when delta_ns comes to be zero, we never schedule the timer and VCPU keeps sleeping indefinitely until any activity is done with VM console. This is easily reproduce-able using kvmtool. ./lkvm-static run -c1 --console virtio -p "earlycon root=/dev/vda" \ -k ./Image -d rootfs.ext4 Also, just add a print in kvm_riscv_vcpu_vstimer_expired() to check the interrupt delivery and run `top` or similar auto-upating cmd from guest. Within sometime one can notice that print from timer expiry routine stops and the `top` cmd output will stop updating. This change fixes this by making sure we schedule the timer even with delta_ns being zero to bring the VCPU out of sleep immediately. Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com> --- arch/riscv/kvm/vcpu_timer.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)