From: Don Slutz Subject: [PATCH v2 09/10] hvm/hpet: Correctly limit period to a maximum. Date: Tue, 8 Apr 2014 10:24:53 -0400 Message-ID: <1396967094-29484-10-git-send-email-dslutz@verizon.com> References: <1396967094-29484-1-git-send-email-dslutz@verizon.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1396967094-29484-1-git-send-email-dslutz@verizon.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Keir Fraser , Don Slutz , Jan Beulich List-Id: xen-devel@lists.xenproject.org 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 --- xen/arch/x86/hvm/hpet.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c index 28f5224..3226a61 100644 --- a/xen/arch/x86/hvm/hpet.c +++ b/xen/arch/x86/hvm/hpet.c @@ -419,6 +419,9 @@ static int hpet_write( } else { + 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 @@ -427,7 +430,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; } } -- 1.8.4