From: "Yao, Jiewen" <jiewen.yao@intel.com>
To: "Wang, Jian J" <jian.j.wang@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Dong, Eric" <eric.dong@intel.com>,
Laszlo Ersek <lersek@redhat.com>,
"Ni, Ruiyu" <ruiyu.ni@intel.com>
Subject: Re: [PATCH v2] UefiCpuPkg/PiSmmCpuDxeSmm: fix infinite loop issue in SMM profile
Date: Wed, 7 Feb 2018 07:01:21 +0000 [thread overview]
Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503AAB7C27@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <20180206084016.18408-1-jian.j.wang@intel.com>
Reviewed-by: Jiewen.yao@intel.com
> -----Original Message-----
> From: Wang, Jian J
> Sent: Tuesday, February 6, 2018 4:40 PM
> To: edk2-devel@lists.01.org
> Cc: Dong, Eric <eric.dong@intel.com>; Laszlo Ersek <lersek@redhat.com>; Ni,
> Ruiyu <ruiyu.ni@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>
> Subject: [PATCH v2] UefiCpuPkg/PiSmmCpuDxeSmm: fix infinite loop issue in
> SMM profile
>
> > v2:
> > Reduce the number of page to update/restore from 3 to 2 because DF
> > has no effect in this issue.
>
> The infinite loop is caused by the memory instruction, such as
> "rep mov", operating on memory block crossing boundary of NON-PRESENT
> pages. Because the address triggering page fault set in CR2 will be in
> the first page, SmmProfilePFHandler() will only change the first page
> into PRESENT. The page following will be still in NON-PRESENT status.
>
> Since SmmProfilePFHandler() will setup single-step trap for the
> instruction causing #PF, when the handler returns back to the
> instruction and re-execute it, both #DB and #PF will be triggered
> because the instruction wants to access both first and second page
> but only first page is PRESENT.
>
> Normally #DB exception will be handled first and its handler will
> change first page back to NON-PRESENT status. Then #PF is handled
> and its handler will change first page to PRESENT status again and
> setup another single-step for the instruction triggering #PF. Then
> the whole system falls into an infinite loop and the memory operation
> will never move on.
>
> This patch fix above situation by always changing 2 pages to PRESENT
> status instead of just 1 page. Those 2 pages include the page causing
> #PF and the page after it.
>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
> ---
> UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 21 +++++++++++++++++----
> 1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> index 9588eaf029..c90167f160 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> @@ -1302,6 +1302,8 @@ SmmProfilePFHandler (
> {
> UINT64 *PageTable;
> UINT64 PFAddress;
> + UINT64 RestoreAddress;
> + UINTN RestorePageNumber;
> UINTN CpuIndex;
> UINTN Index;
> UINT64 InstructionAddress;
> @@ -1331,10 +1333,21 @@ SmmProfilePFHandler (
> PFAddress = AsmReadCr2 ();
> CpuIndex = GetCpuIndex ();
>
> - if (PFAddress <= 0xFFFFFFFF) {
> - RestorePageTableBelow4G (PageTable, PFAddress, CpuIndex, ErrorCode);
> - } else {
> - RestorePageTableAbove4G (PageTable, PFAddress, CpuIndex, ErrorCode,
> &IsValidPFAddress);
> + //
> + // Memory operation cross pages, like "rep mov" instruction, will cause
> + // infinite loop between this and Debug Trap handler. We have to make sure
> + // that current page and the page followed are both in PRESENT state.
> + //
> + RestorePageNumber = 2;
> + RestoreAddress = PFAddress;
> + while (RestorePageNumber > 0) {
> + if (RestoreAddress <= 0xFFFFFFFF) {
> + RestorePageTableBelow4G (PageTable, RestoreAddress, CpuIndex,
> ErrorCode);
> + } else {
> + RestorePageTableAbove4G (PageTable, RestoreAddress, CpuIndex,
> ErrorCode, &IsValidPFAddress);
> + }
> + RestoreAddress += EFI_PAGE_SIZE;
> + RestorePageNumber--;
> }
>
> if (!IsValidPFAddress) {
> --
> 2.14.1.windows.1
prev parent reply other threads:[~2018-02-07 6:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-06 8:40 [PATCH v2] UefiCpuPkg/PiSmmCpuDxeSmm: fix infinite loop issue in SMM profile Jian J Wang
2018-02-07 7:01 ` Yao, Jiewen [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=74D8A39837DF1E4DA445A8C0B3885C503AAB7C27@shsmsx102.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