mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Yasunori Goto <y-goto@jp.fujitsu.com>
Cc: paul.gortmaker@windriver.com, clemens@ladisch.de,
	linux-kernel@vger.kernel.org, robert.picco@hp.com,
	venkatesh.pallipadi@intel.com, vojtech@suse.cz, mingo@redhat.com
Subject: Re: [Patch] Fix the possibility of insane return value of hpet_calibrate() against SMI. (take 2)
Date: Mon, 30 Mar 2009 14:06:59 -0700	[thread overview]
Message-ID: <20090330140659.66ccbfe9.akpm@linux-foundation.org> (raw)
In-Reply-To: <20090318113948.7BAD.E1E9C6FF@jp.fujitsu.com>

On Wed, 18 Mar 2009 11:47:04 +0900
Yasunori Goto <y-goto@jp.fujitsu.com> wrote:

> 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;
> +}

Call me paranoid, but I'd like to see a maximum retry count here and an
error message-and-continue if it is exceeded.  To prevent mysterious
boot-time lockups from misbehaving hpets, perhaps?

Also, style nit - I find

	for ( ; ; ) {
		...
	}

to be more readable than

	do {
		...
	} while (1);

and I believe the former is more common.


And

	unsigned long ret = -1;

has the same effect as

	unsigned long ret = ~0UL;

but is more maintainable - it doesn't subtly break if someone changes
the type of `ret'.  (This is a bit of an ugly C trick).




  parent reply	other threads:[~2009-03-30 21:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-13  5:00 [Patch] Fix the possibility of insane return value of hpet_calibrate() against SMI Yasunori Goto
2009-03-14  8:23 ` Rik van Riel
2009-03-15 19:56 ` Paul Gortmaker
2009-03-16  2:34   ` Yasunori Goto
2009-03-16  8:59     ` Vojtech Pavlik
2009-03-16  9:52     ` Clemens Ladisch
2009-03-17 10:12       ` Yasunori Goto
2009-03-17 13:12         ` Paul Gortmaker
2009-03-18  0:45           ` Yasunori Goto
2009-03-18  2:47             ` [Patch] Fix the possibility of insane return value of hpet_calibrate() against SMI. (take 2) Yasunori Goto
2009-03-18  7:44               ` Clemens Ladisch
2009-03-18  8:25                 ` Vojtech Pavlik
2009-03-18 13:55               ` Paul Gortmaker
2009-03-18 15:11                 ` Clemens Ladisch
2009-03-18 15:32                   ` Paul Gortmaker
2009-03-30 21:06               ` Andrew Morton [this message]
2009-03-30 21:23                 ` Paul Gortmaker

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=20090330140659.66ccbfe9.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=clemens@ladisch.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paul.gortmaker@windriver.com \
    --cc=robert.picco@hp.com \
    --cc=venkatesh.pallipadi@intel.com \
    --cc=vojtech@suse.cz \
    --cc=y-goto@jp.fujitsu.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome