From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Tue, 13 Aug 2019 03:28:14 -0700 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B8005859E; Tue, 13 Aug 2019 10:28:14 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-117-193.ams2.redhat.com [10.36.117.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 669EF6E6F5; Tue, 13 Aug 2019 10:28:13 +0000 (UTC) Subject: Re: [edk2-devel] [Patch v2 5/6] UefiCpuPkg/RegisterCpuFeaturesLib: Supports test then write new value logic. To: devel@edk2.groups.io, eric.dong@intel.com Cc: Ray Ni References: <20190812103152.35164-1-eric.dong@intel.com> <20190812103152.35164-6-eric.dong@intel.com> From: "Laszlo Ersek" Message-ID: <0b98160e-2902-959d-5aa9-f9318797b189@redhat.com> Date: Tue, 13 Aug 2019 12:28:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190812103152.35164-6-eric.dong@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 13 Aug 2019 10:28:14 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 08/12/19 12:31, Dong, Eric wrote: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2040 > > Supports new logic which test current value before write new value. > Only write new value when current value not same as new value. > > Signed-off-by: Eric Dong > Cc: Ray Ni > Cc: Laszlo Ersek > --- > .../CpuFeaturesInitialize.c | 31 ++++++++++++++++++- > 1 file changed, 30 insertions(+), 1 deletion(-) > > diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c > index ef7452e2b8..6988a75bfe 100644 > --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c > +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c > @@ -826,6 +826,7 @@ ProgramProcessorRegister ( > UINTN ValidThreadCount; > UINT32 *ValidCoreCountPerPackage; > EFI_STATUS Status; > + UINT64 CurrentValue; > > // > // Traverse Register Table of this logical processor > @@ -848,7 +849,16 @@ ProgramProcessorRegister ( > if (EFI_ERROR (Status)) { > continue; > } > - > + if (RegisterTableEntry->TestThenWrite) { > + CurrentValue = BitFieldRead64 ( > + Value, > + RegisterTableEntry->ValidBitStart, > + RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1 > + ); > + if (CurrentValue == RegisterTableEntry->Value) { > + continue; > + } > + } > Value = (UINTN) BitFieldWrite64 ( > Value, > RegisterTableEntry->ValidBitStart, > @@ -857,10 +867,29 @@ ProgramProcessorRegister ( > ); > ReadWriteCr (RegisterTableEntry->Index, FALSE, &Value); > break; > + > // > // The specified register is Model Specific Register > // > case Msr: > + if (RegisterTableEntry->TestThenWrite) { > + Value = (UINTN)AsmReadMsr64 (RegisterTableEntry->Index); > + if (RegisterTableEntry->ValidBitLength >= 64) { > + if (Value == RegisterTableEntry->Value) { > + continue; > + } > + } else { > + CurrentValue = BitFieldRead64 ( > + Value, > + RegisterTableEntry->ValidBitStart, > + RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1 > + ); > + if (CurrentValue == RegisterTableEntry->Value) { > + continue; > + } > + } > + } > + > if (RegisterTableEntry->ValidBitLength >= 64) { > // > // If length is not less than 64 bits, then directly write without reading > Acked-by: Laszlo Ersek