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; Mon, 29 Jul 2019 04:49:04 -0700 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC7903082E6E; Mon, 29 Jul 2019 11:49:03 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-117-240.ams2.redhat.com [10.36.117.240]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7088519C58; Mon, 29 Jul 2019 11:49:02 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH 3/3] UefiCpuPkg/PiSmmCpu: Allow SMM access-out when static paging is OFF To: devel@edk2.groups.io, ray.ni@intel.com Cc: Eric Dong , Jiewen Yao , Jian J Wang References: <20190727032850.337840-1-ray.ni@intel.com> <20190727032850.337840-4-ray.ni@intel.com> From: "Laszlo Ersek" Message-ID: Date: Mon, 29 Jul 2019 13:49:01 +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: <20190727032850.337840-4-ray.ni@intel.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 29 Jul 2019 11:49:03 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 07/27/19 05:28, Ni, Ray wrote: > Commit c60d36b4d1ee1f69b7cca897d3621dfa951895c2 > * UefiCpuPkg/SmmCpu: Block access-out only when static paging is used > > updated page fault handler to treat SMM access-out as allowed > address when static paging is not used. > > But that commit is not complete because the page table is still > updated in SetUefiMemMapAttributes() for non-SMRAM memory. When SMM > code accesses non-SMRAM memory, page fault is still generated. > > This patch skips to update page table for non-SMRAM memory and > page table itself. > > Signed-off-by: Ray Ni > Cc: Eric Dong > Cc: Jiewen Yao > Cc: Jian J Wang > --- > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 21 +++++++++++++++------ > 1 file changed, 15 insertions(+), 6 deletions(-) > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c > index 69a04dfb23..d7d94c8b6d 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c > @@ -1121,6 +1121,9 @@ FindSmramInfo ( > *SmrrBase = (UINT32)CurrentSmramRange->CpuStart; > *SmrrSize = (UINT32)CurrentSmramRange->PhysicalSize; > > + // > + // Extend *SmrrBase/*SmrrSize to include adjacent SMRAM ranges > + // > do { > Found = FALSE; > for (Index = 0; Index < mSmmCpuSmramRangeCount; Index++) { > @@ -1432,14 +1435,20 @@ PerformRemainingTasks ( > SetMemMapAttributes (); > > // > - // For outside SMRAM, we only map SMM communication buffer or MMIO. > + // Protect memory outside SMRAM when SMM Static Page Table is enabled. > // > - SetUefiMemMapAttributes (); > + if (IsStaticPageTableEnabled ()) { > > - // > - // Set page table itself to be read-only > - // > - SetPageTableAttributes (); > + // > + // For outside SMRAM, we only map SMM communication buffer or MMIO. > + // > + SetUefiMemMapAttributes (); > + > + // > + // Set page table itself to be read-only > + // > + SetPageTableAttributes (); > + } > > // > // Configure SMM Code Access Check feature if available. > With the IA32 bug in patch#1 fixed, this patch will also do the right thing (as part of OVMF anyway): - on IA32, there will be no change in behavior (IsStaticPageTableEnabled() will evaluate to constant TRUE) - on X64, OVMF keeps the DEC-default TRUE value for the underlying PCD (PcdCpuSmmStaticPageTable), hence IsStaticPageTableEnabled() will return TRUE, and the behavior won't change. Because I cannot validate the PcdCpuSmmStaticPageTable==FALSE case, I won't give R-b. But I can certainly give: Acked-by: Laszlo Ersek Thanks! Laszlo