hvm/hpet: Correctly limit period to a maximum.
authorDon Slutz <dslutz@verizon.com>
Fri, 2 May 2014 20:18:02 +0000 (16:18 -0400)
committerTim Deegan <tim@xen.org>
Thu, 8 May 2014 11:03:53 +0000 (12:03 +0100)
In the code section after the comment:

    /*
     * Clamp period to reasonable min/max values:
     *  - minimum is 100us, same as timers controlled by vpt.c
     *  - maximum is to prevent overflow in time_after() calculations
     */

The current maximum limit actually allows "bad" values like 0 and 1.
This is because it uses a mask not a maximum.

Signed-off-by: Don Slutz <dslutz@verizon.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Tim Deegan <tim@xen.org>
xen/arch/x86/hvm/hpet.c

index 910d87d73270015a377e03621f82cb35d2197cab..c64c5471acb92d3f547ff7b81a5647fb7df69da3 100644 (file)
@@ -404,6 +404,8 @@ static int hpet_write(
         if ( timer_is_periodic(h, tn) &&
              !(h->hpet.timers[tn].config & HPET_TN_SETVAL) )
         {
+            uint64_t max_period = (timer_is_32bit(h, tn) ? ~0u : ~0ull) >> 1;
+
             /*
              * Clamp period to reasonable min/max values:
              *  - minimum is 100us, same as timers controlled by vpt.c
@@ -411,7 +413,8 @@ static int hpet_write(
              */
             if ( hpet_tick_to_ns(h, new_val) < MICROSECS(100) )
                 new_val = (MICROSECS(100) << 10) / h->hpet_to_ns_scale;
-            new_val &= (timer_is_32bit(h, tn) ? ~0u : ~0ull) >> 1;
+            if ( new_val > max_period )
+                new_val = max_period;
             h->hpet.period[tn] = new_val;
         }
         else