public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] UefiCpuPkg/CommonFeature: Skip locking when the feature is disabled
@ 2018-11-06  9:06 Ruiyu Ni
  2018-11-06 16:15 ` Laszlo Ersek
  2018-11-07  2:19 ` Dong, Eric
  0 siblings, 2 replies; 3+ messages in thread
From: Ruiyu Ni @ 2018-11-06  9:06 UTC (permalink / raw)
  To: edk2-devel; +Cc: Eric Dong, Laszlo Ersek

Today's code unconditionally sets the IA32_FEATURE_CONTROL.Lock to 1
no matter the feature is enabled or not.

The patch fixes this issue by only setting the Lock bit to 1 when
the feature is enabled.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
---
 UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c b/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c
index 8c1eb5eb4f..0b85f25f90 100644
--- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c
+++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c
@@ -1,7 +1,7 @@
 /** @file
   Features in MSR_IA32_FEATURE_CONTROL register.
 
-  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -184,6 +184,14 @@ LockFeatureControlRegisterInitialize (
 {
   MSR_IA32_FEATURE_CONTROL_REGISTER    *MsrRegister;
 
+  //
+  // When Lock Feature Control Register feature is disabled,
+  // just skip the MSR lock bit setting.
+  //
+  if (!State) {
+    return RETURN_SUCCESS;
+  }
+
   //
   // The scope of Lock bit in the MSR_IA32_FEATURE_CONTROL is core for
   // below processor type, only program MSR_IA32_FEATURE_CONTROL for thread 0 in each
-- 
2.16.1.windows.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] UefiCpuPkg/CommonFeature: Skip locking when the feature is disabled
  2018-11-06  9:06 [PATCH] UefiCpuPkg/CommonFeature: Skip locking when the feature is disabled Ruiyu Ni
@ 2018-11-06 16:15 ` Laszlo Ersek
  2018-11-07  2:19 ` Dong, Eric
  1 sibling, 0 replies; 3+ messages in thread
From: Laszlo Ersek @ 2018-11-06 16:15 UTC (permalink / raw)
  To: Ruiyu Ni, edk2-devel; +Cc: Eric Dong

On 11/06/18 10:06, Ruiyu Ni wrote:
> Today's code unconditionally sets the IA32_FEATURE_CONTROL.Lock to 1
> no matter the feature is enabled or not.
> 
> The patch fixes this issue by only setting the Lock bit to 1 when
> the feature is enabled.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> ---
>  UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c b/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c
> index 8c1eb5eb4f..0b85f25f90 100644
> --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c
> +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Features in MSR_IA32_FEATURE_CONTROL register.
>  
> -  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD License
>    which accompanies this distribution.  The full text of the license may be found at
> @@ -184,6 +184,14 @@ LockFeatureControlRegisterInitialize (
>  {
>    MSR_IA32_FEATURE_CONTROL_REGISTER    *MsrRegister;
>  
> +  //
> +  // When Lock Feature Control Register feature is disabled,
> +  // just skip the MSR lock bit setting.
> +  //
> +  if (!State) {
> +    return RETURN_SUCCESS;
> +  }
> +
>    //
>    // The scope of Lock bit in the MSR_IA32_FEATURE_CONTROL is core for
>    // below processor type, only program MSR_IA32_FEATURE_CONTROL for thread 0 in each
> 

I'll defer to Eric on this, as OVMF does not use this lib instance.

(In fact, no platform in the edk2 tree seems to.)

Thanks,
Laszlo


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] UefiCpuPkg/CommonFeature: Skip locking when the feature is disabled
  2018-11-06  9:06 [PATCH] UefiCpuPkg/CommonFeature: Skip locking when the feature is disabled Ruiyu Ni
  2018-11-06 16:15 ` Laszlo Ersek
@ 2018-11-07  2:19 ` Dong, Eric
  1 sibling, 0 replies; 3+ messages in thread
From: Dong, Eric @ 2018-11-07  2:19 UTC (permalink / raw)
  To: Ni, Ruiyu, edk2-devel@lists.01.org; +Cc: Laszlo Ersek

Hi Ray,

I think we should add comments to mention that if the Lock bit is already set, driver can't disable it. So driver can directly return success if state is FALSE.

With that comments, Reviewed-by: Eric Dong <eric.dong@intel.com>

Thanks,
Eric

> -----Original Message-----
> From: Ni, Ruiyu
> Sent: Tuesday, November 6, 2018 5:06 PM
> To: edk2-devel@lists.01.org
> Cc: Dong, Eric <eric.dong@intel.com>; Laszlo Ersek <lersek@redhat.com>
> Subject: [PATCH] UefiCpuPkg/CommonFeature: Skip locking when the
> feature is disabled
> 
> Today's code unconditionally sets the IA32_FEATURE_CONTROL.Lock to 1 no
> matter the feature is enabled or not.
> 
> The patch fixes this issue by only setting the Lock bit to 1 when the feature is
> enabled.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> ---
>  UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c | 10
> +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c
> b/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c
> index 8c1eb5eb4f..0b85f25f90 100644
> --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c
> +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Features in MSR_IA32_FEATURE_CONTROL register.
> 
> -  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2017 - 2018, Intel Corporation. All rights
> + reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at @@ -184,6 +184,14 @@ LockFeatureControlRegisterInitialize (  {
>    MSR_IA32_FEATURE_CONTROL_REGISTER    *MsrRegister;
> 
> +  //
> +  // When Lock Feature Control Register feature is disabled,  // just
> + skip the MSR lock bit setting.
> +  //
> +  if (!State) {
> +    return RETURN_SUCCESS;
> +  }
> +
>    //
>    // The scope of Lock bit in the MSR_IA32_FEATURE_CONTROL is core for
>    // below processor type, only program MSR_IA32_FEATURE_CONTROL for
> thread 0 in each
> --
> 2.16.1.windows.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-07  2:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-06  9:06 [PATCH] UefiCpuPkg/CommonFeature: Skip locking when the feature is disabled Ruiyu Ni
2018-11-06 16:15 ` Laszlo Ersek
2018-11-07  2:19 ` Dong, Eric

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox