qemu-riscv
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-riscv] [Qemu-devel] [PATCH] hw/riscv/sifive_clint.c: avoid int


From: Palmer Dabbelt
Subject: Re: [Qemu-riscv] [Qemu-devel] [PATCH] hw/riscv/sifive_clint.c: avoid integer overflow in timecmp write
Date: Wed, 13 Feb 2019 10:12:10 -0800 (PST)

On Fri, 08 Feb 2019 10:41:17 PST (-0800), address@hidden wrote:
On Thu, Feb 7, 2019 at 2:08 AM Fabien Chouteau <address@hidden> wrote:

Hello Alistair,

On 07/02/2019 01:42, Alistair Francis wrote:>
> Can you describe what this fixes?
>

I encountered this problem when I tried to write 0xffffffffffffffff in timecmp.

With the integer overflow in QEMU, writing this value means that the QEMU timer
will be set in the past.

> Won't an overflow be ok as we then just wrap around anyway? I guess
> there is a problem if we want a value so large that we wrap around
> past our current time though.
>

The overflow was in the computation of the value `next_ns`. It is used to set
the QEMU timer:

timer_mod(cpu->env.timer, next_ns);

A negative `next_ns` -because of the overflow- means that the timer
triggers immediately instead of far in the future.

Ah you are right here. The expired time of the timer will be set to
zero (it looks like QEMU ensures it can't be negative) but then it
detects that as being in the past and will trigger the timer event as
timer_expired_ns() will return true.

Reviewed-by: Alistair Francis <address@hidden>

Thanks.  I'll target this for the next PR.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]