public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ruiyu" <ruiyu.ni@intel.com>
To: "Kinney, Michael D" <michael.d.kinney@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [Patch] PcAtChipsetPkg/HpetTimerDxe: Fix race condition in SetTimerPeriod()
Date: Thu, 27 Oct 2016 01:42:30 +0000	[thread overview]
Message-ID: <734D49CCEBEEF84792F5B80ED585239D58E42C61@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <1477521081-14264-1-git-send-email-michael.d.kinney@intel.com>



Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
>-----Original Message-----
>From: Kinney, Michael D
>Sent: Thursday, October 27, 2016 6:31 AM
>To: edk2-devel@lists.01.org
>Cc: Ni, Ruiyu <ruiyu.ni@intel.com>
>Subject: [Patch] PcAtChipsetPkg/HpetTimerDxe: Fix race condition in SetTimerPeriod()
>
>https://bugzilla.tianocore.org/show_bug.cgi?id=182
>
>The function TimerDriverSetTimerPeriod() disables the HPET timer
>while the HPET timer HW is reprogrammed with a new timer period.
>However, the MMIO write to disable the HPET timer HW can be
>delayed and an HPET timer interrupt may be processed in the middle
>of reprogramming the HPET timer HW and this may produced unexpected
>results.
>
>The fix is to raise TPL to TPL_HIGH_LEVEL in
>TimerDriverSetTimerPeriod() during the time the HPET timer HW is
>reprogrammed.  This guarantees that no timer interrupts are
>processed during reprogramming.
>
>The TimerDriverGenerateSoftInterrupt() function in this same
>driver also raises TPL to TPL_HIGH_LEVEL, so this fix matches
>the logic that is already used in another function for the same
>reason.
>
>Cc: Ruiyu Ni <ruiyu.ni@intel.com>
>Contributed-under: TianoCore Contribution Agreement 1.0
>Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
>---
> PcAtChipsetPkg/HpetTimerDxe/HpetTimer.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
>diff --git a/PcAtChipsetPkg/HpetTimerDxe/HpetTimer.c b/PcAtChipsetPkg/HpetTimerDxe/HpetTimer.c
>index 0ed8743..c62c3a9 100644
>--- a/PcAtChipsetPkg/HpetTimerDxe/HpetTimer.c
>+++ b/PcAtChipsetPkg/HpetTimerDxe/HpetTimer.c
>@@ -492,11 +492,17 @@ TimerDriverSetTimerPeriod (
>   IN UINT64                   TimerPeriod
>   )
> {
>+  EFI_TPL                        Tpl;
>   UINT64                         MainCounter;
>   UINT64                         Delta;
>   UINT64                         CurrentComparator;
>   HPET_TIMER_MSI_ROUTE_REGISTER  HpetTimerMsiRoute;
>-
>+
>+  //
>+  // Disable interrupts
>+  //
>+  Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
>+
>   //
>   // Disable HPET timer when adjusting the timer period
>   //
>@@ -616,7 +622,12 @@ TimerDriverSetTimerPeriod (
>   // is disabled.
>   //
>   HpetEnable (TRUE);
>-
>+
>+  //
>+  // Restore interrupts
>+  //
>+  gBS->RestoreTPL (Tpl);
>+
>   return EFI_SUCCESS;
> }
>
>--
>2.6.3.windows.1



      reply	other threads:[~2016-10-27  1:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-26 22:31 [Patch] PcAtChipsetPkg/HpetTimerDxe: Fix race condition in SetTimerPeriod() Michael Kinney
2016-10-27  1:42 ` Ni, Ruiyu [this message]

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-list 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=734D49CCEBEEF84792F5B80ED585239D58E42C61@SHSMSX104.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /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