<feed xmlns='http://www.w3.org/2005/Atom'>
<title>u-boot.git/lib/lmb.c, branch v2025.01</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.</subtitle>
<id>http://cgit.235523.xyz/u-boot.git/atom/lib/lmb.c?h=v2025.01</id>
<link rel='self' href='http://cgit.235523.xyz/u-boot.git/atom/lib/lmb.c?h=v2025.01'/>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/'/>
<updated>2024-12-12T15:20:32Z</updated>
<entry>
<title>lmb: Return -EEXIST in lmb_add_region_flags() if region already added</title>
<updated>2024-12-12T15:20:32Z</updated>
<author>
<name>Sam Protsenko</name>
<email>semen.protsenko@linaro.org</email>
</author>
<published>2024-12-11T02:17:01Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=8b8b35a4f5edc8c3579ff82500b32655f94ec4c8'/>
<id>urn:sha1:8b8b35a4f5edc8c3579ff82500b32655f94ec4c8</id>
<content type='text'>
An attempt to add the already added LMB region using
lmb_add_region_flags() ends up in lmb_addrs_overlap() check, which
eventually leads to either returning 0 if 'flags' is LMB_NONE, or -1
otherwise. It makes it impossible for the user of this function to catch
the case when the region is already added and differentiate it from
regular errors. That in turn may lead to incorrect error handling in the
caller code, like reporting misleading errors or interrupting the normal
code path where it could be treated as the normal case. An example is
boot_fdt_reserve_region() function, which might be called twice (e.g.
during board startup in initr_lmb(), and then during 'booti' command
booting the OS), thus trying to reserve exactly the same memory regions
described in the device tree twice, which produces an error message on
second call.

Return -EEXIST error code in case when the added region exists and it's
not LMB_NONE; for LMB_NONE return 0, to conform to unit tests
(specifically test_alloc_addr() in test/lib/lmb.c) and the preferred
behavior described in commit 1d9aa4a283da ("lmb: Fix the allocation of
overlapping memory areas with !LMB_NONE"). The change of
lmb_add_region_flags() return values is described in the table below:

    Return case                        Pre-1d9   1d9    New
    -----------------------------------------------------------
    Added successfully                    0      0      0
    Failed to add                         -1     -1     -1
    Already added, flags == LMB_NONE      0      0      0
    Already added, flags != LMB_NONE      0      -1     -EEXIST

Rework all affected functions and their documentation. Also fix the
corresponding unit test which checks reserving the same region with the
same flags to account for the changed return value.

No functional change is intended (by this patch itself).

Fixes: 1d9aa4a283da ("lmb: Fix the allocation of overlapping memory areas with !LMB_NONE")
Signed-off-by: Sam Protsenko &lt;semen.protsenko@linaro.org&gt;
Reviewed-by: Ilias Apalodimas &lt;ilias.apalodimas@linaro.org&gt;
Tested-by: Michal Simek &lt;michal.simek@amd.com&gt;
</content>
</entry>
<entry>
<title>lmb: prohibit allocations above ram_top even from same bank</title>
<updated>2024-12-06T23:47:23Z</updated>
<author>
<name>Sughosh Ganu</name>
<email>sughosh.ganu@linaro.org</email>
</author>
<published>2024-12-02T07:06:24Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=1a48b0be93d48f9ec5498297ec775fb572d3d150'/>
<id>urn:sha1:1a48b0be93d48f9ec5498297ec775fb572d3d150</id>
<content type='text'>
There are platforms which set the value of ram_top based on certain
restrictions that the platform might have in accessing memory above
ram_top, even when the memory region is in the same DRAM bank. So,
even though the LMB allocator works as expected, when trying to
allocate memory above ram_top, prohibit this by marking all memory
above ram_top as reserved, even if the said memory region is from the
same bank.

Signed-off-by: Sughosh Ganu &lt;sughosh.ganu@linaro.org&gt;
Tested-by: Andreas Schwab &lt;schwab@suse.de&gt;
</content>
</entry>
<entry>
<title>lmb: Fix the allocation of overlapping memory areas with !LMB_NONE</title>
<updated>2024-12-05T07:01:44Z</updated>
<author>
<name>Ilias Apalodimas</name>
<email>ilias.apalodimas@linaro.org</email>
</author>
<published>2024-12-02T14:42:45Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=1d9aa4a283daa1e609130b5457c9857d62f1d1cb'/>
<id>urn:sha1:1d9aa4a283daa1e609130b5457c9857d62f1d1cb</id>
<content type='text'>
At the moment the LMB allocator will return 'success' immediately on two
consecutive allocations if the second one is smaller and the flags match
without resizing the reserved area.

This is problematic for two reasons, first of all the new updated
allocation won't update the size and we end up holding more memory than
needed, but most importantly it breaks the EFI SCT tests since EFI
now allocates via LMB.

More specifically when EFI requests a specific address twice with the
EFI_ALLOCATE_ADDRESS flag set, the first allocation will succeed and
update the EFI memory map. Due to the LMB behavior the second allocation
will also succeed but the address ranges are already in the EFI memory
map due the first allocation. EFI will then fail to update the memory map,
returning EFI_OUT_OF_RESOURCES instead of EFI_NOT_FOUND which break EFI
conformance.

So let's remove the fast check with is problematic anyway and leave LMB
resize and calculate address properly. LMB will now
- try to resize the reservations for LMB_NONE
- return -1 if the memory is not LMB_NONE and already reserved

The LMB code needs some cleanup in that part, but since we are close to
2025.01 do the easy fix and plan to refactor it later.
Also update the dm tests with the new behavior.

Fixes: commit 22f2c9ed9f53 ("efi: memory: use the lmb API's for allocating and freeing memory")
Signed-off-by: Ilias Apalodimas &lt;ilias.apalodimas@linaro.org&gt;
</content>
</entry>
<entry>
<title>lmb.c: add missing comma in lmb_dump_region()</title>
<updated>2024-11-15T00:14:06Z</updated>
<author>
<name>Heinrich Schuchardt</name>
<email>heinrich.schuchardt@canonical.com</email>
</author>
<published>2024-11-07T10:14:42Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=dfe7ab35147c2a2c8a63b2155227a86684d6dd4d'/>
<id>urn:sha1:dfe7ab35147c2a2c8a63b2155227a86684d6dd4d</id>
<content type='text'>
In the message string " %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: "
a comma is missing before flags.

To avoid increasing the code size replace '0x%' by '%#'.

Printing the size with leading zeros but not the addresses does not really
make sense. Remove the leading zeros from the size output.

Signed-off-by: Heinrich Schuchardt &lt;heinrich.schuchardt@canonical.com&gt;
[trini: Fix test/cmd/bdinfo.c for these changes]
Signed-off-by: Tom Rini &lt;trini@konsulko.com&gt;
</content>
</entry>
<entry>
<title>lmb: do not panic in lmb_print_region_flags</title>
<updated>2024-11-15T00:14:05Z</updated>
<author>
<name>Heinrich Schuchardt</name>
<email>heinrich.schuchardt@canonical.com</email>
</author>
<published>2024-11-02T06:32:26Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=1f66c0e1f4ffb2f9f0fea8fcb7118028039e76a2'/>
<id>urn:sha1:1f66c0e1f4ffb2f9f0fea8fcb7118028039e76a2</id>
<content type='text'>
Commit c3cf0dc64f1c ("lmb: add a check to prevent memory overrun")
addressed a possible buffer overrun using assert_noisy().

Resetting via panic() in lmb_print_region() while allowing invalid
lmb flags elsewhere is not reasonable.

Instead of panicking print a message indicating the problem.

fls() returns an int. Using a u64 for bitpos does not match.
Use int instead.

fls() takes an int as argument. Using 1ull &lt;&lt; bitpos generates a u64.
Use 1u &lt;&lt; bitpos instead.

Signed-off-by: Heinrich Schuchardt &lt;heinrich.schuchardt@canonical.com&gt;
Acked-by: Sughosh Ganu &lt;sughosh.ganu@linaro.org&gt;
</content>
</entry>
<entry>
<title>lmb: Add basic io_lmb functionality</title>
<updated>2024-11-11T13:26:44Z</updated>
<author>
<name>Janne Grunau</name>
<email>j@jannau.net</email>
</author>
<published>2024-11-11T06:56:33Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=f6999cb554954c9fde2070cd70919d2d714daf64'/>
<id>urn:sha1:f6999cb554954c9fde2070cd70919d2d714daf64</id>
<content type='text'>
These functions can be used with struct lmb pointers and will be used to
manage IOVA space in the apple_dart iommu driver. This restores part of
the pointer base struct lmb API from before commit ed17a33fed29 ("lmb:
make LMB memory map persistent and global").
io_lmb_add() and io_lmb_free() can trivially reuse exisiting lmb
functions. io_lmb_setup() is separate for unique error log messages.
io_lmb_alloc() is a simplified copy of _lmb_alloc_base() since the
later has unused features and internal use of the global LMB memory map.

Signed-off-by: Janne Grunau &lt;j@jannau.net&gt;
</content>
</entry>
<entry>
<title>lmb: cosmetic: reorder functions and global LMB variable</title>
<updated>2024-11-11T13:26:44Z</updated>
<author>
<name>Janne Grunau</name>
<email>j@jannau.net</email>
</author>
<published>2024-11-11T06:56:32Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=174f53d2f2f466f67719c84f24ae49d0ffd5ecc0'/>
<id>urn:sha1:174f53d2f2f466f67719c84f24ae49d0ffd5ecc0</id>
<content type='text'>
Low lovel LMB functionality will be used to manage IOVA space in the
Apple dart iommu driver. This reordering ensures that those function
can not access the global LMB memory map variable.

Signed-off-by: Janne Grunau &lt;j@jannau.net&gt;
</content>
</entry>
<entry>
<title>lmb: Do not use global LMB variable in _lmb_free()</title>
<updated>2024-11-11T13:26:44Z</updated>
<author>
<name>Janne Grunau</name>
<email>j@jannau.net</email>
</author>
<published>2024-11-11T06:56:31Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=408b4ae8e33c18fed5a3e6829059b128db199743'/>
<id>urn:sha1:408b4ae8e33c18fed5a3e6829059b128db199743</id>
<content type='text'>
It will be re-used with a lmb list pointer as argument for IOVA
allocations in the apple_dart iommu driver.

Reviewed-by: Tom Rini &lt;trini@konsulko.com&gt;
Signed-off-by: Janne Grunau &lt;j@jannau.net&gt;
</content>
</entry>
<entry>
<title>lmb: Drop extra 16KB of stack space</title>
<updated>2024-11-09T08:52:43Z</updated>
<author>
<name>Simon Glass</name>
<email>sjg@chromium.org</email>
</author>
<published>2024-10-28T12:47:59Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=6e6a940c70b63c1d0e11221adb18973568ac9ec9'/>
<id>urn:sha1:6e6a940c70b63c1d0e11221adb18973568ac9ec9</id>
<content type='text'>
There is already a defined stack-size which is used to reserve space for
the stack. It is confusing to add more in the lmb module, since then the
memory map (with meminfo command) seems to have a hole in it.

Drop this unnecessary feature.

Signed-off-by: Simon Glass &lt;sjg@chromium.org&gt;
</content>
</entry>
<entry>
<title>lmb: remove __maybe_unused from lmb_map_update_notify</title>
<updated>2024-11-01T19:36:47Z</updated>
<author>
<name>Heinrich Schuchardt</name>
<email>heinrich.schuchardt@canonical.com</email>
</author>
<published>2024-10-28T06:21:36Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=62fe870632fc6a8f18ff59c2e9579be9a80df3d7'/>
<id>urn:sha1:62fe870632fc6a8f18ff59c2e9579be9a80df3d7</id>
<content type='text'>
Function lmb_map_update_notify() is always referenced.

Signed-off-by: Heinrich Schuchardt &lt;heinrich.schuchardt@canonical.com&gt;
Reviewed-by: Ilias Apalodimas &lt;ilias.apalodimas@linaro.org&gt;
</content>
</entry>
</feed>
