[Patch] Fix the possibility of insane return value of hpet_calibrate() against SMI. (take 2)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Yasunori Goto
Date: Tuesday, March 17, 2009 - 7:47 pm

> 

Here is updated version.

--------

hpet_calibrate() has a possibility of miss-calibration due to SMI.
If SMI interrupts in the while loop of calibration, then return value
will be big. This change calibrates until stabilizing by the return
value with a small value.


Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>


---
 drivers/char/hpet.c |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

Index: hpet_test/drivers/char/hpet.c
===================================================================
--- hpet_test.orig/drivers/char/hpet.c	2009-03-12 15:47:45.000000000 +0900
+++ hpet_test/drivers/char/hpet.c	2009-03-18 11:12:42.000000000 +0900
@@ -713,7 +713,7 @@
  */
 #define	TICK_CALIBRATE	(1000UL)
 
-static unsigned long hpet_calibrate(struct hpets *hpetp)
+static unsigned long __hpet_calibrate(struct hpets *hpetp)
 {
 	struct hpet_timer __iomem *timer = NULL;
 	unsigned long t, m, count, i, flags, start;
@@ -750,6 +750,25 @@
 	return (m - start) / i;
 }
 
+static unsigned long hpet_calibrate(struct hpets *hpetp)
+{
+	unsigned long ret = ~0UL, tmp;
+
+	/*
+	 * Try to calibrate until return value becomes stable small value.
+	 * If SMI interruption occurs in calibration loop, the return value
+	 * will be big. This avoids its impact.
+	 */
+	do {
+		tmp = __hpet_calibrate(hpetp);
+		if (ret <= tmp)
+			break;
+		ret = tmp;
+	} while (1);
+
+	return ret;
+}
+
 int hpet_alloc(struct hpet_data *hdp)
 {
 	u64 cap, mcfg;

-- 
Yasunori Goto 


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[Patch] Fix the possibility of insane return value of hpet ..., Yasunori Goto, (Tue Mar 17, 7:47 pm)
Re: [Patch] Fix the possibility of insane return value of ..., Clemens Ladisch, (Wed Mar 18, 12:44 am)