public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Wang, Jian J" <jian.j.wang@intel.com>
To: "Ni, Ruiyu" <ruiyu.ni@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Kinney, Michael D" <michael.d.kinney@intel.com>,
	"Gao, Liming" <liming.gao@intel.com>
Subject: Re: [PATCH 1/3] IntelFrameworkPkg/LegacyBios.h: Add a macro to guarantee page 0 access
Date: Wed, 6 Dec 2017 12:36:26 +0000	[thread overview]
Message-ID: <D827630B58408649ACB04F44C510003624CBB918@SHSMSX103.ccr.corp.intel.com> (raw)
In-Reply-To: <30755dcb-1e79-f8f1-70b3-3c5bad9d2a4b@Intel.com>

Good catch. I think it's a typo not on purpose. Many thanks!

> -----Original Message-----
> From: Ni, Ruiyu
> Sent: Wednesday, December 06, 2017 5:31 PM
> To: Wang, Jian J <jian.j.wang@intel.com>; edk2-devel@lists.01.org
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming
> <liming.gao@intel.com>
> Subject: Re: [edk2] [PATCH 1/3] IntelFrameworkPkg/LegacyBios.h: Add a macro
> to guarantee page 0 access
> 
> On 12/6/2017 3:31 PM, Jian J Wang wrote:
> > Due to the introduction of NULL pointer detection feature, page 0 will be
> > disabled if the feature is enabled, which will cause legacy code failed to
> > update legacy data in page 0. This macro is introduced to make sure the
> > page 0 is enabled before those code and restore the original status of it
> > afterwards.
> >
> > Another reason to introduce this macro is to eliminate the dependency on
> > the PcdNullPointerDetectionPropertyMask. Because this is a new PCD, it
> > could cause some backward compatibility issue for some old packages.
> >
> > This macro will simply check if the page 0 is disabled or not. If it's
> > disabled, it will enable it before code updating page 0 and disable it
> > afterwards. Otherwise, this macro will do nothing to page 0.
> >
> > The usage of the macro will be look like (similar to DEBUG_CODE macro):
> >
> >      ACCESS_PAGE0_CODE(
> >        {
> >            <code accessing page 0>
> >        }
> >      );
> >
> > Cc: Liming Gao <liming.gao@intel.com>
> > Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
> > ---
> >   IntelFrameworkPkg/Include/Protocol/LegacyBios.h | 34
> +++++++++++++++++++++++++
> >   1 file changed, 34 insertions(+)
> >
> > diff --git a/IntelFrameworkPkg/Include/Protocol/LegacyBios.h
> b/IntelFrameworkPkg/Include/Protocol/LegacyBios.h
> > index 641f101bce..f77c92ba21 100644
> > --- a/IntelFrameworkPkg/Include/Protocol/LegacyBios.h
> > +++ b/IntelFrameworkPkg/Include/Protocol/LegacyBios.h
> > @@ -1518,6 +1518,40 @@ struct _EFI_LEGACY_BIOS_PROTOCOL {
> >     EFI_LEGACY_BIOS_BOOT_UNCONVENTIONAL_DEVICE
> BootUnconventionalDevice;
> >   };
> >
> > +//
> > +// Legacy BIOS needs to access memory in page 0 (0-4095), which is disabled
> if
> > +// NULL pointer detection feature is enabled. Following macro can be used to
> > +// enable/disable page 0 before/after accessing it.
> > +//
> > +#define ACCESS_PAGE0_CODE(statements)                           \
> > +  do {                                                          \
> > +    EFI_STATUS                            Status_;              \
> > +    EFI_GCD_MEMORY_SPACE_DESCRIPTOR       Desc_;                \
> > +                                                                \
> > +    Status_ = gDS->GetMemorySpaceDescriptor (0, &Desc_);        \
> > +    if (!EFI_ERROR (Status_)) {                                 \
> > +      if ((Desc_.Attributes & EFI_MEMORY_RP) != 0) {            \
> > +        Status_ = gDS->SetMemorySpaceAttributes (               \
> > +                        0,                                      \
> > +                        EFI_PAGES_TO_SIZE(1),                   \
> > +                        Desc_.Attributes &= ~EFI_MEMORY_RP      \
> 
> &= is used here so Desc_.Attributes is updated to have RP cleared.
> Then the below if will be always FALSE.
> 
> > +                        );                                      \
> > +        ASSERT_EFI_ERROR (Status_);                             \
> > +      }                                                         \
> > +                                                                \
> > +      statements;                                               \
> > +                                                                \
> > +      if ((Desc_.Attributes & EFI_MEMORY_RP) != 0) {            \
> > +        Status_ = gDS->SetMemorySpaceAttributes (               \
> > +                        0,                                      \
> > +                        EFI_PAGES_TO_SIZE(1),                   \
> > +                        Desc_.Attributes                        \
> > +                        );                                      \
> > +        ASSERT_EFI_ERROR (Status_);                             \
> > +      }                                                         \
> > +    }                                                           \
> > +  } while (FALSE)
> > +
> >   extern EFI_GUID gEfiLegacyBiosProtocolGuid;
> >
> >   #endif
> >
> 
> 
> --
> Thanks,
> Ray

  reply	other threads:[~2017-12-06 12:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-06  7:31 [PATCH 0/3] Remove dependency on PcdNullPointerDetectionPropertyMask Jian J Wang
2017-12-06  7:31 ` [PATCH 1/3] IntelFrameworkPkg/LegacyBios.h: Add a macro to guarantee page 0 access Jian J Wang
2017-12-06  9:31   ` Ni, Ruiyu
2017-12-06 12:36     ` Wang, Jian J [this message]
2017-12-06  7:31 ` [PATCH 2/3] IntelFrameworkModulePkg/LegacyBiosDxe: Use macro to enable/disable page 0 Jian J Wang
2017-12-06  9:32   ` Ni, Ruiyu
2017-12-06 12:38     ` Wang, Jian J
2017-12-06  7:31 ` [PATCH 3/3] IntelFrameworkModulePkg/KeyboardDxe: " Jian J Wang

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=D827630B58408649ACB04F44C510003624CBB918@SHSMSX103.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