From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 42E231A1E46 for ; Wed, 26 Oct 2016 18:42:34 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 26 Oct 2016 18:42:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,404,1473145200"; d="scan'208";a="1050828312" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga001.jf.intel.com with ESMTP; 26 Oct 2016 18:42:33 -0700 Received: from fmsmsx102.amr.corp.intel.com (10.18.124.200) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 26 Oct 2016 18:42:33 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX102.amr.corp.intel.com (10.18.124.200) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 26 Oct 2016 18:42:33 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.209]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.104]) with mapi id 14.03.0248.002; Thu, 27 Oct 2016 09:42:31 +0800 From: "Ni, Ruiyu" To: "Kinney, Michael D" , "edk2-devel@lists.01.org" Thread-Topic: [Patch] PcAtChipsetPkg/HpetTimerDxe: Fix race condition in SetTimerPeriod() Thread-Index: AQHSL9i27XHWnwHaWkKFnCegn7JTWaC7hwbw Date: Thu, 27 Oct 2016 01:42:30 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D58E42C61@SHSMSX104.ccr.corp.intel.com> References: <1477521081-14264-1-git-send-email-michael.d.kinney@intel.com> In-Reply-To: <1477521081-14264-1-git-send-email-michael.d.kinney@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYmVhZTQyMjMtMjVlYy00NDJjLWJkNzItYWE2NzdjZjYzODUwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX1BVQkxJQyJ9XX1dfSwiU3ViamVjdExhYmVscyI6W10sIlRNQ1ZlcnNpb24iOiIxNS45LjYuNiIsIlRydXN0ZWRMYWJlbEhhc2giOiJCZVl1UTFTZ2sxWmhBQXVCXC9LXC96eFwvYzZobjcwRmFmcDJBOHN4ZGxBR2FFPSJ9 x-ctpclassification: CTP_PUBLIC x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] PcAtChipsetPkg/HpetTimerDxe: Fix race condition in SetTimerPeriod() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Oct 2016 01:42:34 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ruiyu Ni >-----Original Message----- >From: Kinney, Michael D >Sent: Thursday, October 27, 2016 6:31 AM >To: edk2-devel@lists.01.org >Cc: Ni, Ruiyu >Subject: [Patch] PcAtChipsetPkg/HpetTimerDxe: Fix race condition in SetTim= erPeriod() > >https://bugzilla.tianocore.org/show_bug.cgi?id=3D182 > >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 >Contributed-under: TianoCore Contribution Agreement 1.0 >Signed-off-by: Michael Kinney >--- > PcAtChipsetPkg/HpetTimerDxe/HpetTimer.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > >diff --git a/PcAtChipsetPkg/HpetTimerDxe/HpetTimer.c b/PcAtChipsetPkg/Hpet= TimerDxe/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 =3D 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