[PATCH] qemu: aspeed_timer: Use signed muldiv for timer resets
Cédric Le Goater
clg at kaod.org
Tue Nov 13 05:37:06 AEDT 2018
On 11/12/18 3:21 PM, Christian Svensson wrote:
> If the host decrements the counter register that results in a negative
> delta. This is then passed to muldiv64 which only handles unsigned
> numbers resulting in bogus results.
>
> This fix ensures the data being operated on is signed before it is
> ultimately casted to the final unsigned value.
>
> Test case: kexec a kernel using aspeed_timer and it will freeze on the
> second bootup when the kernel initializes the timer. With this patch
> that no longer happens and the timer appears to run OK.
>
> Signed-off-by: Christian Svensson <bluecmd at google.com>
> ---
> hw/timer/aspeed_timer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
> index 9acd1de485..1a54d85e9d 100644
> --- a/hw/timer/aspeed_timer.c
> +++ b/hw/timer/aspeed_timer.c
> @@ -253,7 +253,7 @@ static void aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
> int64_t delta = (int64_t) value - (int64_t) calculate_ticks(t, now);
> uint32_t rate = calculate_rate(t);
>
> - t->start += muldiv64(delta, NANOSECONDS_PER_SECOND, rate);
> + t->start = (int64_t)t->start + ((__int128_t)delta * NANOSECONDS_PER_SECOND / rate);
isn't QEMU using the helpers from :
include/qemu/host-utils.h
which do about the same ?
Thanks,
C.
> aspeed_timer_mod(t);
> }
> break;
>
More information about the openbmc
mailing list