mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bibo Mao <maobibo@loongson.cn>
To: Tao Cui <cui.tao@linux.dev>, zhaotianrui@loongson.cn
Cc: chenhuacai@kernel.org, kernel@xen0n.name, kvm@vger.kernel.org,
	loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
	lixianglai@loongson.cn, cuitao@kylinos.cn
Subject: Re: [PATCH v3 2/2] LoongArch: KVM: Prevent division by zero in periodic timer restore
Date: Thu, 16 Jul 2026 14:14:26 +0800	[thread overview]
Message-ID: <82dba701-e64a-e20d-fea0-203192995805@loongson.cn> (raw)
In-Reply-To: <20260715100640.1454413-3-cui.tao@linux.dev>



On 2026/7/15 下午6:06, Tao Cui wrote:
> From: Tao Cui <cuitao@kylinos.cn>
> 
> A guest can write CSR_TCFG with the periodic bit set but a period value
> of zero.  When kvm_restore_timer() later enters the periodic branch,
> period = cfg & CSR_TCFG_VAL evaluates to 0, causing delta % period to
> trigger a division by zero and crash the host kernel.
> 
> Clamp the period to 1 to avoid the panic.
> 
> Fixes: a5857b9ff6e0 ("LoongArch: KVM: Implement vcpu timer operations")
> Signed-off-by: Tao Cui <cuitao@kylinos.cn>
> ---
>   arch/loongarch/kvm/timer.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/arch/loongarch/kvm/timer.c b/arch/loongarch/kvm/timer.c
> index 96f33e34855a..524d4096bac0 100644
> --- a/arch/loongarch/kvm/timer.c
> +++ b/arch/loongarch/kvm/timer.c
> @@ -135,6 +135,8 @@ void kvm_restore_timer(struct kvm_vcpu *vcpu)
>   		delta = ktime_to_tick(vcpu, ktime_sub(expire, now));
>   	else if (cfg & CSR_TCFG_PERIOD) {
>   		period = cfg & CSR_TCFG_VAL;
> +		if (!period)
> +			period = 1;
>   		delta = ktime_to_tick(vcpu, ktime_sub(now, expire));
>   		delta = period - (delta % period);
>   
> 
Reviewed-by: Bibo Mao <maobibo@loongson.cn>


      reply	other threads:[~2026-07-16  6:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15 10:06 [PATCH v3 0/2] LoongArch: KVM: Fix timer restore issues Tao Cui
2026-07-15 10:06 ` [PATCH v3 1/2] LoongArch: KVM: Reload one-shot TVAL on migration destination Tao Cui
2026-07-16  6:14   ` Bibo Mao
2026-07-15 10:06 ` [PATCH v3 2/2] LoongArch: KVM: Prevent division by zero in periodic timer restore Tao Cui
2026-07-16  6:14   ` Bibo Mao [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=82dba701-e64a-e20d-fea0-203192995805@loongson.cn \
    --to=maobibo@loongson.cn \
    --cc=chenhuacai@kernel.org \
    --cc=cui.tao@linux.dev \
    --cc=cuitao@kylinos.cn \
    --cc=kernel@xen0n.name \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lixianglai@loongson.cn \
    --cc=loongarch@lists.linux.dev \
    --cc=zhaotianrui@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome