On Wed, 31 May 2023 at 10:56, Ni, Ray <ray...@intel.com> wrote: > > > > > > 2. > > > > > When a memory region is marked from not-present to present, > > PageTableLib > > > > expects > > > > > caller to supply all memory attributes (including RW, NX, etc.) as > > > > > the lib > > > > implementation doesn't > > > > > want to carry any default attributes.. > > > > > Do you think the MemoryAttribute PPI should expect the same to caller? > > > > > > > > > > > > > I'm not sure I follow. > > > > > > > > The PPI (as well as the UEFI protocol) can only operate on valid > > > > mapping, and can only be used to manipulate RP/RO/XP. It cannot be > > > > used to create mappings from scratch. > > > When a range of memory is marked as "RP", X86 page table clears the > > > "Present" bit for that range memory. > > > "Present" bit is a master bit in X86 page table. When that bit is clear, > > > all > > > other bits ("Writable", "Non-Execution", etc.) are ignored by CPU. > > > > > > So, if caller clears the "RP" bit (setting "Present" bit in page table), > > > that's an > > > operation to map back some memory. > > > X86 CpuPageTableLib requires all attributes be provided for mapping back > > > some memory. > > > > > > > > > > > Do you think this capability should be added? If so, I think it is > > > > reasonable to require the caller to provide all attributes, and on ARM > > > > this would have to include the memory cacheability type as we should > > > > not provide a default for that either. > > > > > > Yes. I think this is required. Having this rule can help caller write > > > robust code > > > instead of depending on some default attributes in PPI/Protocol > > implementation. > > > > > > > I still don't follow. How does that work in the context of the > > attribute mask? Can you given some examples? > > OK. Let's reset the discussion. > For example, one caller's code as below: > // mark 0-4k as not-present > MemoryAttrributePpi->SetMemoryAttribute (0, 4K, RP, RP); // Use > Attribute/Mask pattern to set RP > > Another caller's code: > // mark 0-4k as present > * MemoryAttributePpi->SetMemoryAttribute (0, 4K, 0, RP); // Use > Attribute/Mask pattern to clear RP >
OK, I see what you mean now. > Q1: Does the PPI support this usage? My current implementation for ARM does not support this, because the RP flag is not tied to the present bit but to the access flag. This means that setting and clearing RP will not create a valid region. > Q2: If it supports, what're the other attributes of 0-4k memory? Is XP set? > Is RO set? > I am leaning towards not supporting this, at least initially, as updating permissions and creating mappings are two different things, and I am not convinced a generic PPI for creating mappings from scratch is needed at this point. This is a major difference between ARM and x86, as on x86, it is quite common to create mappings for regions that may have no memory at all. On ARM, this is not permited, and so we carefully create mappings only where we detect DRAM. However, I understand that it is not trivial to implement this restriction on x86, unless we remove RP from the set of attributes that this API can manipulate. -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105490): https://edk2.groups.io/g/devel/message/105490 Mute This Topic: https://groups.io/mt/99131184/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-