Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ppc64: Avoid restricted memory areas when allocating memory #152

Open
wants to merge 10 commits into
base: rhel-9.3.0
Choose a base branch
from

Conversation

stefanberger
Copy link
Contributor

@stefanberger stefanberger commented Dec 7, 2023

This is a backport of a recently posted patch series resolving grub memory allocation issues: https://lists.gnu.org/archive/html/grub-devel/2023-11/msg00188.html

This series affects only the memory allocations for kernel and initrd so they don't get placed into 640-768MB region. All other allocations that grub makes have already been 'fixed':

This series of patches converts the PowerPC ieee1275 memory allocator
for kernel and initrd to use the (PowerPC) regions_claim memory allocator
that takes into account memory regions that are not allowed to be used,
such as the gap between 640MB and 768MB as well as memory regions beyond
an address in case an fadump is present. Otherwise those two could be
loaded into restricted memory regions and either cause a crash or
corruption of the fadump.

I adjusted the kernel and initrd load in loader/powerpc/ieee1275 to use
the new memory allocator only on PowerVM and PowerKVM since this code is
shared with other platforms, such as old PowerMACs and i386.

Resolves: https://issues.redhat.com/browse/RHEL-14282

The regions_claim() function limits the allocation of memory regions
by excluding certain memory areas from being used by GRUB. This for
example includes a gap between 640MB and 768MB as well as an upper
limit beyond which no memory may be used when an fadump is present.
However, the ieee1275 loader for kernel and initrd currently does not
use regions_claim() for memory allocation on PowerVM and KVM on Power
and therefore may allocate memory in those areas that it should not use.

To make the regions_claim() function more flexible and ultimately usable
for the ieee1275 loader, introduce a request structure to pass various
parameters to the regions_claim() function that describe the properties
of requested memory chunks. In a first step, move the total and flags
variables into this structure.

Signed-off-by: Stefan Berger <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Pavithra Prakash <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Carolyn Scherrer <[email protected]>
Cc: Mahesh Salgaonkar <[email protected]>
Cc: Sourabh Jain <[email protected]>
Let the regions_claim() request structure's init_region determine whether
to call grub_mm_init_region() on it. This allows for adding memory to
GRUB's memory heap if init_region is set to true, or direct usage of the
memory otherwise. Set all current callers' init_region to true since they
want to add memory regions to GRUB's heap.

Signed-off-by: Stefan Berger <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Pavithra Prakash <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Carolyn Scherrer <[email protected]>
Cc: Mahesh Salgaonkar <[email protected]>
Cc: Sourabh Jain <[email protected]>
Return the allocated address of the memory block in the request structure
if a memory allocation was actually done. Leave the address untouched
otherwise. This enables a caller who wants to use the allocated memory
directly, rather than adding the memory to the heap, to see where memory
was allocated. None of the current callers need this but the converted
ieee1275 loader will make use of it.

Signed-off-by: Stefan Berger <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Pavithra Prakash <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Carolyn Scherrer <[email protected]>
Cc: Mahesh Salgaonkar <[email protected]>
Cc: Sourabh Jain <[email protected]>
Add support for memory alignment requirements and adjust a candidate
address to it before checking whether the block is large enough. This
must be done in this order since the alignment adjustment can make
a block smaller than what was requested.

None of the current callers has memory alignment requirements but the
ieee1275 loader for kernel and initrd will use it to convey them.

Signed-off-by: Stefan Berger <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Pavithra Prakash <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Carolyn Scherrer <[email protected]>
Cc: Mahesh Salgaonkar <[email protected]>
Cc: Sourabh Jain <[email protected]>
Rename regions_claim() to grub_regions_claim() to make it available for
memory allocation. The ieee1275 loader will use this function on PowerVM
and KVM on Power and thus avoid usage of memory that it is not allowed
to use.

Signed-off-by: Stefan Berger <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Pavithra Prakash <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Carolyn Scherrer <[email protected]>
Cc: Mahesh Salgaonkar <[email protected]>
Cc: Sourabh Jain <[email protected]>
Introduce flags to identify PowerVM and KVM on Power and set them where
each type of host has been detected.

Signed-off-by: Stefan Berger <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Pavithra Prakash <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Carolyn Scherrer <[email protected]>
Cc: Mahesh Salgaonkar <[email protected]>
Cc: Sourabh Jain <[email protected]>
…nitrd

On PowerVM and KVM on Power use the new memory allocation function that
honors restrictions on which memory GRUB can actually use. In the request
structure indicate the request for a single memory block along with
address alignment restrictions. Request direct usage of the memory block
by setting init_region to false (prevent it from being added to GRUB's
heap). Initialize the found addr to -1, so that -1 will be returned
to the loader in case no memory could be allocated.

Report an out-of-memory error in case the initrd could not be loaded.

Signed-off-by: Stefan Berger <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Pavithra Prakash <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Carolyn Scherrer <[email protected]>
Cc: Mahesh Salgaonkar <[email protected]>
Cc: Sourabh Jain <[email protected]>
Display successful memory claims with exact address and rounded-down
MiB location and rounded-up size in MiB.

Signed-off-by: Stefan Berger <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
Cc: Eric Snowberg <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Pavithra Prakash <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Carolyn Scherrer <[email protected]>
Cc: Mahesh Salgaonkar <[email protected]>
Cc: Sourabh Jain <[email protected]>
Signed-off-by: Stefan Berger <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
Display upper_mem_limit and its rounded-down value in MiB.

Signed-off-by: Stefan Berger <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]>
@nfrayer
Copy link
Contributor

nfrayer commented Apr 5, 2024

Hi Stefan,

Is this an addendum to 9f0f2df ?
Is this still needed in relation to this JIRA ticket https://issues.redhat.com/browse/RHEL-14282 ?

@stefanberger
Copy link
Contributor Author

stefanberger commented Apr 11, 2024

Is this an addendum to 9f0f2df ?

The patch series avoids having grub touch the memory area 640-768MB, which is supposed to be available for the Linux kernel to allocate initial memory iiuc. In some case it could happen that grub loaded kernel or initrd touching this area.

Is this still needed in relation to this JIRA ticket https://issues.redhat.com/browse/RHEL-14282 ?

Let's defer applying this series for now. fadump should also work without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants