All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Svensson <bluecmd@google.com>
To: openbmc@lists.ozlabs.org
Cc: blue@cmd.nu, joel@jms.id.au, andrew@aj.id.au, clg@kaod.org,
	 Christian Svensson <bluecmd@google.com>
Subject: [PATCH] qemu: aspeed_timer: Use signed muldiv for timer resets
Date: Mon, 12 Nov 2018 15:21:38 +0100	[thread overview]
Message-ID: <20181112142137.160970-1-bluecmd@google.com> (raw)

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@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);
             aspeed_timer_mod(t);
         }
         break;
-- 
2.19.1.930.g4563a0d9d0-goog

             reply	other threads:[~2018-11-12 14:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-12 14:21 Christian Svensson [this message]
2018-11-12 18:37 ` [PATCH] qemu: aspeed_timer: Use signed muldiv for timer resets Cédric Le Goater
2018-11-12 18:45   ` Christian Svensson
2018-11-13  0:27     ` Andrew Jeffery
2018-11-13  8:58       ` Christian Svensson
2019-01-11 12:30         ` Christian Svensson
2019-01-14  2:14           ` Andrew Jeffery
2019-01-14  7:18             ` Christian Svensson
2019-02-11 22:52               ` Andrew Jeffery

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=20181112142137.160970-1-bluecmd@google.com \
    --to=bluecmd@google.com \
    --cc=andrew@aj.id.au \
    --cc=blue@cmd.nu \
    --cc=clg@kaod.org \
    --cc=joel@jms.id.au \
    --cc=openbmc@lists.ozlabs.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.