From patchwork Fri Jun 7 18:52:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 802311 Delivered-To: patch@linaro.org Received: by 2002:adf:f147:0:b0:35b:5a80:51b4 with SMTP id y7csp948449wro; Fri, 7 Jun 2024 11:53:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW6T8LNB1/ZazT9SdiiBF+HDONnGivsLR92DZKbvXdZ91UERuDXHxnTpQSeTbTpIb/doZSoaSD+nB3xlevvoC0M X-Google-Smtp-Source: AGHT+IFcx7Vf0aYc7LOMicAZ4YkMgd16WG5JR+K2v5fNzB5vUV36968RQ1eV2jFFDbS86pgoYIZo X-Received: by 2002:a17:906:adb:b0:a6e:f655:ef29 with SMTP id a640c23a62f3a-a6ef655f132mr111634866b.17.1717786417912; Fri, 07 Jun 2024 11:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717786417; cv=none; d=google.com; s=arc-20160816; b=ZGds/wNkI+jmuZFIHnN6FNGKya6gGErtkbBOn6p2ZDXRm/Y5arlcx8nxka3pysV+2r Z3Q/It5ppPEZrd2ghckMpUjOV2bLjhHXaXFxPe4IGe5qHv0qaZ6trORfxi2Jdcr8z5w7 zE8qG2N34iCLngBabVF11CgNoQ/FZ6RSaYqYHSp5q1NidMf6C/Yz/YcMx2VS8p4aAnIT 6mtZHj/hufP/Zj5anC1jG16ariwM4uleoiWEHwRskmpqYcJPDMSur46GAhEBDk4Onoku XrxBExOe+pZM7GS7RGF5abMn/Ykh8C12lUYlhits8h2CfZoQeB2uwqcB425c0aD99IO1 6Gkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=ctPW1aSW5vkskmVTTA4CXIAJIftCHy7Vm/vn/TrUcw4=; fh=9cUQMp+COjjMdPO1C4pPNxSHSnc57j+MJxu6/LnPXeU=; b=WpSGNlV2YiJnQsQ/nmDZxhOQHKaZY26wubbFFpq+yPjUA7ZramPWLMtxryS0ew3P3L ioZWz/Q7UoVUbA9najdDJYvuXvhCADqXiAOU9iOtlH3rSgKumhzyGhPR5rJhO2AY8g1f o1OR1ToUTlBvCWVcR0pYM7pk1VeHpiOVRlreliJNuF27J5cp6pgH95sO+gE3BqEPIx5W HGJBpXEl1OUWNayx7Sn7iVUkQtNhAIcsQeA8wff4mKqBk5e0WddG5bcJGMq8jkeiFoZT 8n4eU6Jamlb16D/gFOVlmP1R0K2wg80iampAi2YeASxC22Yac3hdwITfqXnIQoREtuLz 1Kyw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-a6e8967781fsi69587966b.1031.2024.06.07.11.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 11:53:37 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3F5D088464; Fri, 7 Jun 2024 20:53:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 82671883AA; Fri, 7 Jun 2024 20:53:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 1DEEC8844F for ; Fri, 7 Jun 2024 20:53:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B6D261480; Fri, 7 Jun 2024 11:53:56 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BE43E3F792; Fri, 7 Jun 2024 11:53:29 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Tom Rini , Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Marek Vasut , Mark Kettenis , Fabio Estevam Subject: [RFC PATCH 00/31] Make U-Boot memory reservations coherent Date: Sat, 8 Jun 2024 00:22:09 +0530 Message-Id: <20240607185240.1892031-1-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The aim of this patch series is to fix the current state of incoherence between modules when it comes to memory usage. The primary issue that this series is trying to fix is that the EFI memory module which is responsible for allocating and freeing memory, does not have any visibility of the memory that is being used by the LMB module. This is further complicated by the fact that the LMB allocations are caller specific -- the LMB memory map is not global nor persistent. This means that the memory "allocated" by the LMB module might be relevant only for a given function. Hence one of the requirements for making the memory usage visible across modules is to make LMB allocations persistent and global, and then have means to communicate the use of memory across modules. The first set of patches in this series work on making the LMB memory map persistent and global. This is being done keeping in mind the usage of LMB memory by platforms where the same memory region can be used to load multiple different images. What is not allowed is to overwrite memory that has been allocated by the other module, currently the EFI memory module. This is being achieved by introducing a new flag, LMB_NOOVERWRITE, which represents memory which cannot be re-requested once allocated. The second set of patches are then introducing a notification mechanism to indicate any changes to a respective module's memory map. This way, any memory allocation/reservation by a module gets notified to any interested listners, who then update their memory map accordingly, thus keeping memory usage coherent. Todo's ------ I have run these patches through CI, but the LMB unit tests need an overhaul. I have currently marked these tests for manual run, as running these would obviously tamper the LMB memory map, thus affecting subsequent tests. The current set of LMB tests are written with the assumption of local LMB memory maps. This needs to be reworked. Secondly, there needs to be a test written for testing the various scenarios of memory being allocated and freed by different modules, namely LMB and EFI. I have written a couple of commands for testing the changes that I have made -- I have also included these temporary commands to assist anyone who might want to test these changes. But I will be working on adding a more comprehensive test. Lastly, as the series touches common code, there is obviously an increase in the size of the image, moreover since the LMB memory is now persistent, and the variables do not reside on the stack. I want to check if there can be ways of decreasing the size impact of the changes. Sughosh Ganu (31): lmb: remove the unused lmb_is_reserved() function lmb: staticize __lmb_alloc_base() lmb: make the lmb reservations persistent lmb: remove local instances of the lmb structure variable lmb: pass a flag to image_setup_libfdt() for lmb reservations lmb: reserve and add common memory regions post relocation lmb: remove lmb_init_and_reserve_range() function lmb: replcace the lmb_init_and_reserve() function lmb: allow for resizing lmb regions event: add events to notify memory map changes lib: Kconfig: add a config symbol for getting memory map updates add a function to check if an address is in RAM memory efi_memory: notify of any changes to the EFI memory map lmb: notify of any changes to the LMB memory map efi_memory: add an event handler to update memory map lmb: add an event handler to update memory map lmb: remove call to efi_lmb_reserve() sandbox: iommu: remove lmb allocation in the driver zynq: lmb: do not add to lmb map before relocation test: cedit: use allocated address for reading file test: event: update the expected event dump output test: lmb: run the LMB tests only on sandbox test: lmb: initialise the lmb structure before tests test: lmb: add a test case for checking overlapping region add test: lmb: adjust the test case to handle overlapping regions test: lmb: run lmb tests only manually test: bdinfo: dump the global LMB memory map cmd: bdinfo: only dump the current LMB memory temp: mx6sabresd: bump up the size limit of the board temp: cmd: efi_mem: add a command to test efi alloc/free temp: cmd: efi: add a command to dump EFI memory map arch/arc/lib/cache.c | 4 +- arch/arm/lib/stack.c | 4 +- arch/arm/mach-apple/board.c | 17 +- arch/arm/mach-snapdragon/board.c | 17 +- arch/arm/mach-stm32mp/dram_init.c | 8 +- arch/arm/mach-stm32mp/stm32mp1/cpu.c | 6 +- arch/m68k/lib/bootm.c | 7 +- arch/microblaze/lib/bootm.c | 4 +- arch/mips/lib/bootm.c | 11 +- arch/nios2/lib/bootm.c | 4 +- arch/powerpc/cpu/mpc85xx/mp.c | 4 +- arch/powerpc/include/asm/mp.h | 4 +- arch/powerpc/lib/bootm.c | 14 +- arch/riscv/lib/bootm.c | 4 +- arch/sandbox/cpu/cpu.c | 5 + arch/sh/lib/bootm.c | 4 +- arch/x86/lib/bootm.c | 4 +- arch/xtensa/lib/bootm.c | 4 +- board/xilinx/common/board.c | 33 -- boot/bootm.c | 26 +- boot/bootm_os.c | 5 +- boot/image-board.c | 34 +-- boot/image-fdt.c | 36 +-- cmd/Makefile | 2 + cmd/bdinfo.c | 5 +- cmd/booti.c | 2 +- cmd/bootz.c | 2 +- cmd/efi_map_dump.c | 28 ++ cmd/efi_memory.c | 155 ++++++++++ cmd/elf.c | 2 +- cmd/load.c | 7 +- common/board_r.c | 20 ++ common/event.c | 4 + configs/mx6sabresd_defconfig | 2 +- drivers/iommu/apple_dart.c | 8 +- drivers/iommu/sandbox_iommu.c | 17 +- fs/fs.c | 7 +- include/efi_loader.h | 2 + include/event.h | 28 ++ include/image.h | 27 +- include/lmb.h | 96 +++--- lib/Kconfig | 10 + lib/efi_loader/efi_dt_fixup.c | 2 +- lib/efi_loader/efi_helper.c | 2 +- lib/efi_loader/efi_memory.c | 127 +++++++- lib/lmb.c | 442 ++++++++++++++++++--------- net/tftp.c | 5 +- net/wget.c | 5 +- test/boot/cedit.c | 5 +- test/cmd/bdinfo.c | 22 +- test/lib/Makefile | 2 +- test/lib/lmb.c | 274 +++++++++-------- test/py/tests/test_event_dump.py | 2 + 53 files changed, 1001 insertions(+), 570 deletions(-) create mode 100644 cmd/efi_map_dump.c create mode 100644 cmd/efi_memory.c