From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, taylor.d.beebe@gmail.com
Cc: Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
Rahul Kumar <rahul1.kumar@intel.com>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [edk2-devel] [PATCH v4 11/14] UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero
Date: Wed, 8 Nov 2023 22:57:48 +0100 [thread overview]
Message-ID: <7afb99f9-67c1-0a4a-6d0b-5818ca017185@redhat.com> (raw)
In-Reply-To: <20231103171706.148-12-taylor.d.beebe@gmail.com>
On 11/3/23 18:17, Taylor Beebe wrote:
> The function EnforceMemoryMapAttribute() in the SMM MAT logic will
> ensure that the CODE and DATA memory types have the desired attributes.
EnforceMemoryMapAttribute() leaves those descriptors alone where
Attribute is already nonzero ("PE image") [1].
For all other descriptors (i.e., where Attribute is zero), it:
- either sets Attribute to EFI_MEMORY_RO [2],
- or sets the EFI_MEMORY_XP *bit* in the Attribute [3] -- which is
identical to setting Attribute to EFI_MEMORY_XP altogether, given that
Attribute is zero to begin with. (So this |= operator looks like a
thinko in the function! But that's a separate topic.)
> The consumer of the SMM MAT
So this seems to imply that the SMM MAT is produced based on
EnforceMemoryMapAttribute(), and then SetMemMapAttributes(), modified in
this patch, is what consumes the SMM MAT. Is that right?
In other words, SetMemMapAttributes() relies on
EnforceMemoryMapAttribute(); is that your point?
> should only override the Attributes field
> in the MAT if it is nonzero.
I don't understand -- do you mean "override the Attributes field if it
is *zero*"? (Because, if it is nonzero, then it has been pre-populated
by EnforceMemoryMapAttribute(), and then we should *use* it, as the
subject line of the patch says.)
Further question: given that EnforceMemoryMapAttribute() exits with
*all* descriptors having a nonzero Attribute field, how is it possible
for SetMemMapAttributes() to see any descriptor with zero Attribute field?
I see two possibilities:
- something introduces a new descriptor between
EnforceMemoryMapAttribute() and SetMemMapAttributes()
- and/or, SetMemMapAttributes() doesn't actually check the entire
Attribute field for nullity, but only the EFI_MEMORY_ACCESS_MASK
bitfield of it. Cases [2] and [3] above ensure the
EFI_MEMORY_ACCESS_MASK bitmask is nonzero, but case [1] ("PE image")
allows for an Attribute field in the descriptor that is nonzero, but
whose EFI_MEMORY_ACCESS_MASK bitfield is zero.
> This also allows the UEFI and SMM MAT
> logic to use ImagePropertiesRecordLib instead of carrying two copies
> of the image properties record manipulation logic.
>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Signed-off-by: Taylor Beebe <taylor.d.beebe@gmail.com>
> ---
> UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c
> index 6f498666157e..d302a9b0cbcf 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c
> @@ -1062,14 +1062,17 @@ SetMemMapAttributes (
> MemoryMap = MemoryMapStart;
> for (Index = 0; Index < MemoryMapEntryCount; Index++) {
> DEBUG ((DEBUG_VERBOSE, "SetAttribute: Memory Entry - 0x%lx, 0x%x\n", MemoryMap->PhysicalStart, MemoryMap->NumberOfPages));
> - if (MemoryMap->Type == EfiRuntimeServicesCode) {
> - MemoryAttribute = EFI_MEMORY_RO;
> - } else {
> - ASSERT ((MemoryMap->Type == EfiRuntimeServicesData) || (MemoryMap->Type == EfiConventionalMemory));
> - //
> - // Set other type memory as NX.
> - //
> - MemoryAttribute = EFI_MEMORY_XP;
> + MemoryAttribute = MemoryMap->Attribute & EFI_MEMORY_ACCESS_MASK;
OK, so this line is what makes SetMemMapAttributes() rely on
EnforceMemoryMapAttribute().
What ensures the proper data flow, from EnforceMemoryMapAttribute() to
SetMemMapAttributes()?
> + if (MemoryAttribute == 0) {
So this seems to identify case [1] (... or an entirely newly added
descriptor)...
> + if (MemoryMap->Type == EfiRuntimeServicesCode) {
> + MemoryAttribute = EFI_MEMORY_RO;
> + } else {
> + ASSERT ((MemoryMap->Type == EfiRuntimeServicesData) || (MemoryMap->Type == EfiConventionalMemory));
> + //
> + // Set other type memory as NX.
> + //
> + MemoryAttribute = EFI_MEMORY_XP;
> + }
> }
>
> //
Makes sense to me, but there are many open questions about the data
flow; I'd like the commit message to ELI5.
Thanks
Laszlo
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110929): https://edk2.groups.io/g/devel/message/110929
Mute This Topic: https://groups.io/mt/102368851/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2023-11-08 21:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-03 17:16 [edk2-devel] [PATCH v4 00/14] Add ImagePropertiesRecordLib and Fix MAT Bugs Taylor Beebe
2023-11-03 17:16 ` [edk2-devel] [PATCH v4 01/14] MdeModulePkg: Add ImagePropertiesRecordLib Taylor Beebe
2023-11-03 17:16 ` [edk2-devel] [PATCH v4 02/14] ArmVirtPkg: Add ImagePropertiesRecordLib Instance Taylor Beebe
2023-11-03 17:16 ` [edk2-devel] [PATCH v4 03/14] EmulatorPkg: " Taylor Beebe
2023-11-03 17:16 ` [edk2-devel] [PATCH v4 04/14] OvmfPkg: " Taylor Beebe
2023-11-03 17:16 ` [edk2-devel] [PATCH v4 05/14] UefiPayloadPkg: " Taylor Beebe
2023-11-03 17:16 ` [edk2-devel] [PATCH v4 06/14] MdeModulePkg: Update MemoryAttributesTable.c to Reduce Global Variable Use Taylor Beebe
2023-11-03 17:16 ` [edk2-devel] [PATCH v4 07/14] MdeModulePkg: Move Some DXE MAT Logic to ImagePropertiesRecordLib Taylor Beebe
2023-11-03 17:17 ` [edk2-devel] [PATCH v4 08/14] MdeModulePkg: Add ImagePropertiesRecordLib Host-Based Unit Test Taylor Beebe
2023-11-03 17:17 ` [edk2-devel] [PATCH v4 09/14] MdeModulePkg: Fix Bugs in MAT Logic Taylor Beebe
2023-11-03 17:17 ` [edk2-devel] [PATCH v4 10/14] MdeModulePkg: Add NULL checks and Return Status to ImagePropertiesRecordLib Taylor Beebe
2023-11-03 17:17 ` [edk2-devel] [PATCH v4 11/14] UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero Taylor Beebe
2023-11-08 21:57 ` Laszlo Ersek [this message]
2023-11-20 22:57 ` Taylor Beebe
2023-11-23 9:54 ` Laszlo Ersek
2023-11-03 17:17 ` [edk2-devel] [PATCH v4 12/14] MdeModulePkg: Transition SMM MAT Logic to Use ImagePropertiesRecordLib Taylor Beebe
2023-11-03 17:17 ` [edk2-devel] [PATCH v4 13/14] MdeModulePkg: Add Logic to Create/Delete Image Properties Records Taylor Beebe
2023-11-03 17:17 ` [edk2-devel] [PATCH v4 14/14] MdeModulePkg: Update DumpImageRecord() in ImagePropertiesRecordLib Taylor Beebe
-- strict thread matches above, loose matches on Subject: below --
2023-08-04 19:46 [edk2-devel] [PATCH v4 00/14] Add ImagePropertiesRecordLib and Fix MAT Bugs Taylor Beebe
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 11/14] UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero Taylor Beebe
[not found] ` <177845D23ACA42F9.19347@groups.io>
2023-11-01 20:11 ` Taylor Beebe
2023-11-02 11:33 ` Laszlo Ersek
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=7afb99f9-67c1-0a4a-6d0b-5818ca017185@redhat.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