public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: edk2-devel-groups-io <devel@edk2.groups.io>,
	Ray Ni <ray.ni@intel.com>,  Jiewen Yao <jiewen.yao@intel.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	 Laszlo Ersek <lersek@redhat.com>,
	Taylor Beebe <t@taylorbeebe.com>,
	 Oliver Smith-Denny <osd@smith-denny.com>
Subject: managing memory attributes in PEI
Date: Mon, 22 May 2023 13:31:21 +0200	[thread overview]
Message-ID: <CAMj1kXHy22V86txgAvog49EjqGmU43MfTrLSMEphzFHhqrARng@mail.gmail.com> (raw)

Hello all,

(OVMF specific questions below - please keep reading)

As a follow-up to the discussion we had last week regarding DXE core,
I'd like to raise the issue of managing memory permissions in PEI,
including the mapping attributes of the code and data regions of DXE
core itself.

This is about good hygiene in general, but on arm64 in particular,
limiting execution permissions to memory regions that are mapped
read-only allows the MMU to be enabled in WXN mode, where all writable
regions are non-executable by default.

I have implemented a proof-of-concept of this for ArmVirtQemu and
Raspberry Pi 4 (the former using PEI and the latter PEI-less), and
this seems quite feasible in practice, but there are a few issues that
I have identified:

- PEI shadowing is currently disabled entirely - this is actually an
advantage for the [virtual] platform in question, given that shadowing
is more work for no benefit, but it is something that needs to be
addressed in the general case;
- no generic method exists to manage page table permissions.

So what I would like to propose (and what I intend to prototype) is a
PPI that abstracts this capability, and which can be used by the PEI
image loader as well as the DxeIpl to manage read-only and non-exec
permissions. Most PEIMs only have a code region anyway, so hopefully
there is some room for optimization where not all PEIMs need 4k
alignment.

That leaves one big issue, and this is related to OVMF's use of IA32
PEI with X64 DXE. This complicates the DxeIpl substantially already,
but would make this effort rather tricky as well.

So my questions are:
- do we need to retain mixed IA32 / X64 support, and if so, why? (I
think it is related to SMM emulation but I need someone to confirm
this)
- if we need to retain it, could we run PEI in long mode but with
32-bit compatibility enabled, so that we don't need two or three
incompatible sets of page tables?

In the latter case, the PPI in question would carry the same logic for
IA32 and X64 builds, and create 4-level page tables with the code
still being 32-bit.

Once we clear this up, I'm happy to look into extending my prototype
to x86 as well.

Thanks,
Ard.

             reply	other threads:[~2023-05-22 11:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22 11:31 Ard Biesheuvel [this message]
2023-05-22 12:06 ` managing memory attributes in PEI Gerd Hoffmann
2023-05-22 23:20   ` Ni, Ray
2023-05-23  4:49     ` Gerd Hoffmann
2023-05-23  5:46       ` Laszlo Ersek
2023-05-23  5:50         ` [edk2-devel] " Ni, Ray
2023-05-23  5:44   ` Laszlo Ersek
2023-05-23  5:31 ` Laszlo Ersek
2023-05-23  5:39   ` Ni, Ray
2023-05-23  7:34     ` Laszlo Ersek
2023-05-23  7:52       ` Ni, Ray
2023-05-23  7:54       ` Ard Biesheuvel
2023-05-23  8:05       ` Gerd Hoffmann
2023-05-23  8:15         ` Ard Biesheuvel
2023-05-23 14:49       ` [edk2-devel] " Michael D Kinney
2023-05-23 14:58         ` Ard Biesheuvel
2023-05-23 15:14           ` Michael D Kinney
2023-05-23 15:51             ` Ard Biesheuvel
2023-05-23 16:47               ` Michael D Kinney
2023-05-24  2:54                 ` Ni, Ray

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=CAMj1kXHy22V86txgAvog49EjqGmU43MfTrLSMEphzFHhqrARng@mail.gmail.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