If we should ever compile timing.c for 32 bit inmates, then unsigned long is
the wrong type. A 32 bit type (aka unsigned long on 32 bit) is too small to
hold the result.

This ensures that we won't hit a bug when enabling on 32 bit. Once we will
enable timing.c on 32 bit, we will have to implement 64 bit division
intrinsics.

Signed-off-by: Ralf Ramsauer <[email protected]>
---
 inmates/lib/x86/include/inmate.h | 2 +-
 inmates/lib/x86/timing.c         | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/inmates/lib/x86/include/inmate.h b/inmates/lib/x86/include/inmate.h
index 7664570d..e4f75206 100644
--- a/inmates/lib/x86/include/inmate.h
+++ b/inmates/lib/x86/include/inmate.h
@@ -241,7 +241,7 @@ void ioapic_pin_set_vector(unsigned int pin,
                           enum ioapic_trigger_mode trigger_mode,
                           unsigned int vector);
 
-unsigned long pm_timer_read(void);
+unsigned long long pm_timer_read(void);
 
 unsigned long tsc_read_ns(void);
 unsigned long tsc_init(void);
diff --git a/inmates/lib/x86/timing.c b/inmates/lib/x86/timing.c
index de41fc35..d179da0f 100644
--- a/inmates/lib/x86/timing.c
+++ b/inmates/lib/x86/timing.c
@@ -92,13 +92,13 @@ unsigned long tsc_init(void)
        return tsc_freq;
 }
 
-unsigned long pm_timer_read(void)
+unsigned long long pm_timer_read(void)
 {
        unsigned int cpu = cpu_id();
-       unsigned long tmr;
+       unsigned long long tmr;
 
-       tmr = ((inl(comm_region->pm_timer_address) & 0x00ffffff) * NS_PER_SEC)
-               / PM_TIMER_HZ;
+       tmr = ((unsigned long long)(inl(comm_region->pm_timer_address)
+               & 0x00ffffff) * NS_PER_SEC) / PM_TIMER_HZ;
        if (tmr < pm_timer_last[cpu])
                pm_timer_overflows[cpu] += PM_TIMER_OVERFLOW;
        pm_timer_last[cpu] = tmr;
-- 
2.21.0

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20190610230330.21419-2-ralf.ramsauer%40oth-regensburg.de.
For more options, visit https://groups.google.com/d/optout.

Reply via email to