From patchwork Thu Feb 13 13:11:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 864824 Delivered-To: patch@linaro.org Received: by 2002:a5d:47a6:0:b0:38f:210b:807b with SMTP id 6csp415953wrb; Thu, 13 Feb 2025 05:11:43 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWcxPSuGJn96Kb918Q6G/1rnzO35f6FaFrRIIWahzkfhN5j618vo4HA3/GsWLFWod1EBgbHgg==@linaro.org X-Google-Smtp-Source: AGHT+IHURkFgvO6o3PoamfH7Ylf7T7i2JJtJXK9Iat3IdDjq7k4PkL2THFI0hk/4uzCkaPJej05g X-Received: by 2002:a05:6000:1a8b:b0:38d:d8b2:cf14 with SMTP id ffacd0b85a97d-38dea28cffemr6749330f8f.30.1739452303379; Thu, 13 Feb 2025 05:11:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739452303; cv=none; d=google.com; s=arc-20240605; b=WsxsLStC2oACPoWicGUYBzFe8hr8xFTTUVuc5m7UfyboIrOaKjbpB88CRtNM4kTnqJ xeMgt3ShI3nIR7kzoN///SqTnCgjgYs2Vbi768gaXhkaLSVKHqH6F09mZrWwtQ8T7SaL gTqJpX7AiM9+0ixUibDgg+jBzZ/YJDd82BbvwgD9oJ6+gpOd1Rendkfgg/yE4WAw8x8z KFl7iLysYSIvBvV0ZN4vp0vGc4TU7DSAuWrVq5EUvJEcu3h9JST2bmZXXIhvUKTFu8ok DGT3OFY0+z9Xac7DCpvEtjcJCmAhCkVdy5uoY/rdqgH8qs5VXziPWtPDgagnStPJ9LXQ IeSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=h9uR4GsbgrGeSYDg/CsobnX8QhSRKKKzC7cT+Zwf9q8=; fh=2HGKihHUAicyV3F+aHiaoPpwvqWA0zlC04Ew6QaQoEg=; b=TX1IH1Qhj28+lq+KiyW8KZNQohUNQsS+vVQKHpRGksd6diraFiJh9kzrsl7LeRWDWa /ozxCu0dx2/AuxclnPBCXG8oGjVQgjXV/jbyJa98Ybk4rfekWYUD6ORBkVyr/7aDiRuV z/TpVfy/+UkbQp0Ini8rAE73Cd1Gg1/5VVSTFlPoNkpzVJrIn9cBXTAS3n1+I7WM4PZZ SRSb4ktM0hWI5kkfsW7SGnkM6mQiPkju0szRHfK0gjccdF3W6bRq+8FAvcm4RUIfylG+ eBiE56GJuYZC+UBeKt8qWliNylnBxpY0ReoDvw2QR2ejP3Na+7rHnOZ5bvAxv2V8ZIH4 7Ewg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-38f25a2967bsi1399100f8f.728.2025.02.13.05.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 05:11:43 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 8D8D380ECC; Thu, 13 Feb 2025 14:11:39 +0100 (CET) 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 2C2BE806FE; Thu, 13 Feb 2025 14:11:38 +0100 (CET) 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_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL 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 D4D9C80E94 for ; Thu, 13 Feb 2025 14:11:35 +0100 (CET) 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 03E5016F3; Thu, 13 Feb 2025 05:11:56 -0800 (PST) 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 A6FCE3F58B; Thu, 13 Feb 2025 05:11:32 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Tom Rini , Quentin Schulz , Udit Kumar , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH 1/4] lmb: check if a region can be reserved by lmb_reserve() Date: Thu, 13 Feb 2025 18:41:01 +0530 Message-Id: <20250213131104.186663-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250213131104.186663-1-sughosh.ganu@linaro.org> References: <20250213131104.186663-1-sughosh.ganu@linaro.org> 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 logic used in lmb_alloc() takes into consideration the existing reserved regions, and ensures that the allocated region does not overlap with any existing allocated regions. The lmb_reserve() function is not doing any such checks -- the requested region might overlap with an existing region. This also shows up with lmb_alloc_addr() as this function ends up calling lmb_reserve(). Add a function which checks if the region requested is overlapping with an existing reserved region, and allow for the reservation to happen only if both the regions have LMB_NONE flag, which allows re-requesting of the region. In any other scenario of an overlap, have lmb_reserve() return -EEXIST, implying that the requested region is already reserved. Also add corresponding test cases which checks for overlapping reservation requests made through lmb_reserve() and lmb_alloc_addr(). Signed-off-by: Sughosh Ganu --- lib/lmb.c | 23 ++++++++++++ test/lib/lmb.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 122 insertions(+), 1 deletion(-) diff --git a/lib/lmb.c b/lib/lmb.c index 7ca44591e1d..aeaf120f57d 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -595,6 +595,26 @@ static __maybe_unused void lmb_reserve_common_spl(void) } } +static bool lmb_can_reserve_region(phys_addr_t base, phys_size_t size, + u32 flags) +{ + uint i; + struct lmb_region *lmb_reserved = lmb.used_mem.data; + + for (i = 0; i < lmb.used_mem.count; i++) { + u32 rgnflags = lmb_reserved[i].flags; + phys_addr_t rgnbase = lmb_reserved[i].base; + phys_size_t rgnsize = lmb_reserved[i].size; + + if (lmb_addrs_overlap(base, size, rgnbase, rgnsize)) { + if (flags != LMB_NONE || flags != rgnflags) + return false; + } + } + + return true; +} + void lmb_add_memory(void) { int i; @@ -667,6 +687,9 @@ long lmb_reserve(phys_addr_t base, phys_size_t size, u32 flags) long ret = 0; struct alist *lmb_rgn_lst = &lmb.used_mem; + if (!lmb_can_reserve_region(base, size, flags)) + return -EEXIST; + ret = lmb_add_region_flags(lmb_rgn_lst, base, size, flags); if (ret) return ret; diff --git a/test/lib/lmb.c b/test/lib/lmb.c index fcb5f1af532..6b995c976dd 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -499,6 +499,32 @@ static int lib_test_lmb_overlapping_reserve(struct unit_test_state *uts) ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40000000, 0x40000, 0, 0, 0, 0); + /* try to allocate overlapping region with a different flag, should fail */ + ret = lmb_reserve(0x40008000, 0x1000, LMB_NOOVERWRITE); + ut_asserteq(ret, -EEXIST); + + /* allocate another region at 0x40050000 with a different flag */ + ret = lmb_reserve(0x40050000, 0x10000, LMB_NOOVERWRITE); + ut_asserteq(ret, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x40000, + 0x40050000, 0x10000, 0, 0); + + /* + * try to allocate a region adjacent to region 1 overlapping the 2nd region, + * should fail + */ + ret = lmb_reserve(0x40040000, 0x20000, LMB_NONE); + ut_asserteq(ret, -EEXIST); + + /* + * try to allocate a region between the two regions, but without an overlap, + * should succeed. this added region coalesces with the region 1 + */ + ret = lmb_reserve(0x40040000, 0x10000, LMB_NONE); + ut_asserteq(ret, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x50000, + 0x40050000, 0x10000, 0, 0); + lmb_pop(&store); return 0; @@ -549,6 +575,78 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram) ret = lmb_free(alloc_addr_a, 0x1000); ut_asserteq(ret, 0); + /* + * Add two regions with different flags, region1 and region2 with + * a gap between them. + * Try adding another region, adjacent to region 1 and overlapping + * region 2. Should fail. + */ + a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE); + ut_asserteq(a, alloc_addr_a); + + b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NOOVERWRITE); + ut_asserteq(b, alloc_addr_a + 0x4000); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000, + b, 0x1000, 0, 0); + + c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NONE); + ut_asserteq(c, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000, + b, 0x1000, 0, 0); + + ret = lmb_free(a, 0x1000); + ut_asserteq(ret, 0); + ret = lmb_free(b, 0x1000); + ut_asserteq(ret, 0); + + + /* + * Add two regions with same flags(LMB_NONE), region1 and region2 + * with a gap between them. + * Try adding another region, adjacent to region 1 and overlapping + * region 2. Should succeed. All regions should coalesce into a + * single region. + */ + a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE); + ut_asserteq(a, alloc_addr_a); + + b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NONE); + ut_asserteq(b, alloc_addr_a + 0x4000); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000, + b, 0x1000, 0, 0); + + c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NONE); + ut_asserteq(c, alloc_addr_a + 0x1000); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, 0x6000, + 0, 0, 0, 0); + + ret = lmb_free(a, 0x6000); + ut_asserteq(ret, 0); + + /* + * Add two regions with same flags(LMB_NOOVERWRITE), region1 and + * region2 with a gap between them. + * Try adding another region, adjacent to region 1 and overlapping + * region 2. Should fail. + */ + a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE); + ut_asserteq(a, alloc_addr_a); + + b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NOOVERWRITE); + ut_asserteq(b, alloc_addr_a + 0x4000); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000, + b, 0x1000, 0, 0); + + c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NOOVERWRITE); + ut_asserteq(c, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000, + b, 0x1000, 0, 0); + + ret = lmb_free(a, 0x1000); + ut_asserteq(ret, 0); + ret = lmb_free(b, 0x1000); + ut_asserteq(ret, 0); + /* reserve 3 blocks */ ret = lmb_reserve(alloc_addr_a, 0x10000, LMB_NONE); ut_asserteq(ret, 0); @@ -760,7 +858,7 @@ static int lib_test_lmb_flags(struct unit_test_state *uts) /* reserve again, new flag */ ret = lmb_reserve(0x40010000, 0x10000, LMB_NONE); - ut_asserteq(ret, -1); + ut_asserteq(ret, -EEXIST); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000, 0, 0, 0, 0); From patchwork Thu Feb 13 13:11:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 864825 Delivered-To: patch@linaro.org Received: by 2002:a5d:47a6:0:b0:38f:210b:807b with SMTP id 6csp416023wrb; Thu, 13 Feb 2025 05:11:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWliyrcUsGAsXzyKP+37RVqOS3ddYRGpdy1hahtW8afCOJBVb8ynS5pyzN3SqeDTXk0Az23vQ==@linaro.org X-Google-Smtp-Source: AGHT+IHRWAZc+TuTmS0eAe/YfppOpXTFJUMSvn4lYSPmGpCdqbZ/uT1gVLGlPojVIrZORwtk4wi2 X-Received: by 2002:a05:600c:3151:b0:431:5c3d:1700 with SMTP id 5b1f17b1804b1-439601b85f4mr34598365e9.21.1739452312058; Thu, 13 Feb 2025 05:11:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739452311; cv=none; d=google.com; s=arc-20240605; b=Svut5mABoNjOSrxMLIIGwh9pJ4+aZ2LbSU8gdYr38PzbDy85agty//I/Jvk9EYKZz4 28/EuKUCksctsY7XTBcvywrMrsk+NKKNbKqebM4DsnyjnA/72bgn8iistCPNJfN04mYd h/GotBAesyyLjv4P5/tZ5RbMqxl3N2IdtvpZBPv0kTd6HMmcA4HcjGQOMpnkIlxaMBoO 6OTQUCyY/n6+ZmI8m0kXEzL/w21bwvPaFYrPt1l/OSrYvhnJf4A9pqSkm6o74carrZYm lc5aoUqAKDkBipHxU8io5tg+DZ7CzskovFGAPnw+pXG2BOWQThYUKhHWTKcKXLVqyygX 805Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=olkOoiczJGdsIm6UjoBQpcZaKp25YwNQ9zP3RoPDANg=; fh=2HGKihHUAicyV3F+aHiaoPpwvqWA0zlC04Ew6QaQoEg=; b=dgfFXwtsdYOeTRXwqZtGjPtjpvoDFFfvXfewptm8prg/yeookisA0NLXR5YfkWjK0l DtuzFeJyWXbPBjKXSf+Ee34wGH+wIJ7sckZL8pfqPglFOyHbda9FI1VP68yPef9E88MF AIMGFCoCzioAJNS+NeV36O34mA3+aU01GepljZFftlk/zvboHNIr3B00Lq+Pnb2UzS1p JUOXRy+Q0HijWfJrxP/OBc9gjaDGmL3cu6Xsl7MvxUeegD72sc9kn1LqQcRSfhs+t6s8 wGhYJAR1PvaR+oOAlk+goGbLR1nbde5a96Snby+bf0UPA8V6YhHnCy8Z2CQ4yyb2UMco OIVQ==; 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 5b1f17b1804b1-439617e9c59si13869915e9.41.2025.02.13.05.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 05:11:51 -0800 (PST) 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 DEEDF80F1A; Thu, 13 Feb 2025 14:11:42 +0100 (CET) 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 314C080F03; Thu, 13 Feb 2025 14:11:41 +0100 (CET) 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_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL 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 14937806FE for ; Thu, 13 Feb 2025 14:11:39 +0100 (CET) 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 386AD16F3; Thu, 13 Feb 2025 05:11:59 -0800 (PST) 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 DB3793F58B; Thu, 13 Feb 2025 05:11:35 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Tom Rini , Quentin Schulz , Udit Kumar , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH 2/4] lmb: handle scenario of of encompassing overlap Date: Thu, 13 Feb 2025 18:41:02 +0530 Message-Id: <20250213131104.186663-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250213131104.186663-1-sughosh.ganu@linaro.org> References: <20250213131104.186663-1-sughosh.ganu@linaro.org> 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 lmb_fix_over_lap_regions() function is called if the added region overlaps with an existing region. The function then fixes the overlap and removes the redundant region. However, it makes an assumption that the overlap would not encompass the existing region, and in such a scenario, it prints a message and returns without making the fix. Handle the case of an encompassing overlap also in the function. Signed-off-by: Sughosh Ganu Reported-by: Quentin Schulz --- Note: To be applied after an A-b/R-b/T-b from the original author of the lmb_fix_over_lap_regions() function on this lib/lmb.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/lmb.c b/lib/lmb.c index aeaf120f57d..a5216bdccc7 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -111,11 +111,9 @@ static void lmb_fix_over_lap_regions(struct alist *lmb_rgn_lst, phys_addr_t base2 = rgn[r2].base; phys_size_t size2 = rgn[r2].size; - if (base1 + size1 > base2 + size2) { - printf("This will not be a case any time\n"); - return; - } - rgn[r1].size = base2 + size2 - base1; + if (base1 + size1 < base2 + size2) + rgn[r1].size = base2 + size2 - base1; + lmb_remove_region(lmb_rgn_lst, r2); } From patchwork Thu Feb 13 13:11:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 864826 Delivered-To: patch@linaro.org Received: by 2002:a5d:47a6:0:b0:38f:210b:807b with SMTP id 6csp416093wrb; Thu, 13 Feb 2025 05:12:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV7OzeZVRVNAQp+6AqvYEPF0ekzDNineOlK611HqD4NVjozKhQuHblUKsZeJWWfkoaOVstszw==@linaro.org X-Google-Smtp-Source: AGHT+IGWvNnx+bhKfDWiZCJUmJ5lbsQtfm9B2pk5bh1htRsPE/UXdwnvkBVtNv5jbU6XTOkJGa2A X-Received: by 2002:adf:ec04:0:b0:38a:888c:679c with SMTP id ffacd0b85a97d-38f24519dbamr2901330f8f.42.1739452320126; Thu, 13 Feb 2025 05:12:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739452320; cv=none; d=google.com; s=arc-20240605; b=WR9lQhvKdYxyPq9VRyZNpVZ224NCJ2pAXWCRH7Ia9aVZqb8Xi6HC7z/UH7me48m/Ku fSbWhqzigOPMdpqR9ioDYC0oAUu4NyGMSgLiz7E/l6WCh73xc5eElEDLzTaLjIGugnqk 4Hb77mQkf8+oSvhUsWjmAQjLCz749JtWeyrrq3ovM3evr+seWI+FojEH+F58QcllxmbG JkUCEfz7M/qcNZB8smD+gXxjqAOkW/wpkY+cdpRhiIf5S7R5p6QF6/BuIArfDgQQcV3d zM7SKF0ccWBNoa8TgVqqST9hsycgBooqhevAC5HZYTBE3sbtVcoep7UHtcCCJfCehQ20 jg6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=uyVok02cWCEfhbicJgoFYE7LFKT3zJSkHD5oYW/Oj+0=; fh=2HGKihHUAicyV3F+aHiaoPpwvqWA0zlC04Ew6QaQoEg=; b=Rq1jYs3axjsYYZrmrFYkGp5id7GGf1+n1/NRWdkP/voK3Vfq2uYFvd8aKOQD5qyfet YggVXXafuGqgAE5cf5zbgUBW2WDdm4lG8umhsmPeqR1K0MJRlP5zbcYap36bHLwTwHFM bvThFH/M/lW/HX715GSwBHP7upP7AZiHOjBbOHrnfEpLdzS9YS1xZfYrQ81But4/Tami ESaY92lJezMKBzI/kP/9HMWaUv9bojx0CyR19WE/WNZ8uPedBvOni+jxln44SD8MU9Si A2QTsTdVwJbz2mHx3+BjvvX+8p0AYUF85U4h7e+6N6+wmhgyPjAOqFonVLd+PBiwVGGS oidA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-38f25a32b1esi1351182f8f.781.2025.02.13.05.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 05:12:00 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 3B38680F03; Thu, 13 Feb 2025 14:11:47 +0100 (CET) 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 8333980EB7; Thu, 13 Feb 2025 14:11:45 +0100 (CET) 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_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL 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 48FD680ECB for ; Thu, 13 Feb 2025 14:11:42 +0100 (CET) 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 6CB5216F3; Thu, 13 Feb 2025 05:12:02 -0800 (PST) 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 1BB173F58B; Thu, 13 Feb 2025 05:11:38 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Tom Rini , Quentin Schulz , Udit Kumar , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH 3/4] lmb: check for a region's coalescing with all existing regions Date: Thu, 13 Feb 2025 18:41:03 +0530 Message-Id: <20250213131104.186663-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250213131104.186663-1-sughosh.ganu@linaro.org> References: <20250213131104.186663-1-sughosh.ganu@linaro.org> 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 lmb_add_region_flags() first checks if the new region to be added can be coalesced with existing regions. The check stops if the two regions are adjecent but their flags do not match. However, it is possible that the newly added region might be adjacent with the next existing region and with matching flags. Check for this possibility by not breaking out of the loop. Signed-off-by: Sughosh Ganu --- lib/lmb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lmb.c b/lib/lmb.c index a5216bdccc7..a55bfe289db 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -204,14 +204,14 @@ static long lmb_add_region_flags(struct alist *lmb_rgn_lst, phys_addr_t base, ret = lmb_addrs_adjacent(base, size, rgnbase, rgnsize); if (ret > 0) { if (flags != rgnflags) - break; + continue; rgn[i].base -= size; rgn[i].size += size; coalesced++; break; } else if (ret < 0) { if (flags != rgnflags) - break; + continue; rgn[i].size += size; coalesced++; break; From patchwork Thu Feb 13 13:11:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 864827 Delivered-To: patch@linaro.org Received: by 2002:a5d:47a6:0:b0:38f:210b:807b with SMTP id 6csp416169wrb; Thu, 13 Feb 2025 05:12:08 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU3C01kCN6wo51KpLj1H+pquiNGT/a63fi7SbVkrYAgI7LwO9Q8gQ3nGsW36hf8DEDmk26XEA==@linaro.org X-Google-Smtp-Source: AGHT+IGZRww4zvQ1B1eTgm3Mf9G7LDIwP5bwTAiu7kCbpCJfS9wTaoKx6VA7SVBdmdWfJKlz7UkF X-Received: by 2002:a05:600c:4f42:b0:439:64d6:e4ee with SMTP id 5b1f17b1804b1-43964d6e748mr14471535e9.30.1739452328093; Thu, 13 Feb 2025 05:12:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739452328; cv=none; d=google.com; s=arc-20240605; b=So2kZssK+9dPFJfQ9ezFknNQmiZ70gWSnoE6/lfuZqHoniuc55H1/9pOBBP2mgCQ0I 2eilpOcxZv5/BYvVxSxigS3uimhykagLLwJvcbvEXxwZUlhPhiKw8qMBBv+qd8y0NWgF hQVWMiWwUkmtrUO+PkVcrXRcr/WxZk1hBxY+Owxz4pIkRX6NSbSTXPoYTkjN5bFctSWO POmSeJ6iS8fkJrZGxOYx2zjRSFcXdYibNBbKlQ4mEUjzb1ghuqC925Qsgoeg9A8pUHRY nHEfEBCplox/8BZ0t3H+ElV433c4aLom9hXdBTzcF+moaGobSoVbN9eFQV+6YGllc7yi w5CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=A6EedcqGd3DC4aLuhjEdo9zaAcMDSXgsHePH9KwF3rM=; fh=2HGKihHUAicyV3F+aHiaoPpwvqWA0zlC04Ew6QaQoEg=; b=HmJiLLcnvDh3fy52LRcrdpF7dXCqR4vh38kS/3YYlO1h88lUK9jlIZrosc75pHYya1 fuuiMnIDguI7GoZrUGc+OS7rYBCYHYCrb4Pws7fk2pTyT8ciaFI/Jo6/WYctaaingnzZ +qqWdGF4lhFywLkNNQ0xClwCt3WenycIWf1W60UswagIOtELaKYuxNwKeB3Q369wlNzI 4hGecjfaLYp2PMoUsQ65caTRSfV9jqa6dMm2wKqT0P97AhkYWLD82uyODpN9g/K2xwQf OPfUNZJnGlK3WhaEA+y4bmoVhXip/9N07vSHHINFkpWTb2woRfx2L/ITwupRbZkBbCEP +MCQ==; 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 ffacd0b85a97d-38f259d5d23si1423811f8f.344.2025.02.13.05.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 05:12:08 -0800 (PST) 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 9086180F3F; Thu, 13 Feb 2025 14:11:48 +0100 (CET) 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 955B9806FE; Thu, 13 Feb 2025 14:11:47 +0100 (CET) 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_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL 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 7C7FE806FE for ; Thu, 13 Feb 2025 14:11:45 +0100 (CET) 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 A11DD16F3; Thu, 13 Feb 2025 05:12:05 -0800 (PST) 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 4FF9A3F58B; Thu, 13 Feb 2025 05:11:42 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Tom Rini , Quentin Schulz , Udit Kumar , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH 4/4] lmb: build lmb_map_update_notify() only with EFI_LOADER Date: Thu, 13 Feb 2025 18:41:04 +0530 Message-Id: <20250213131104.186663-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250213131104.186663-1-sughosh.ganu@linaro.org> References: <20250213131104.186663-1-sughosh.ganu@linaro.org> 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 lmb_map_update_notify() function is used to update the EFI memory map based on corresponding changes in the LMB map. This is causing build failure with a certain old architecture(armv5) toolchain, when building with CONFIG_CC_OPTIMIZE_FOR_DEBUG symbol on platforms which do not enable the EFI_LOADER code. Build the code in lmb_map_update_notify() only when the EFI_LOADER config is enabled to get around this issue. Signed-off-by: Sughosh Ganu Suggested-by: Tom Rini Reviewed-by: Tom Rini --- lib/lmb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/lmb.c b/lib/lmb.c index a55bfe289db..7f4b2315b15 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -428,7 +428,7 @@ long io_lmb_free(struct lmb *io_lmb, phys_addr_t base, phys_size_t size) static struct lmb lmb; -static bool lmb_should_notify(u32 flags) +static bool __maybe_unused lmb_should_notify(u32 flags) { return !lmb.test && !(flags & LMB_NONOTIFY) && CONFIG_IS_ENABLED(EFI_LOADER); @@ -437,6 +437,7 @@ static bool lmb_should_notify(u32 flags) static int lmb_map_update_notify(phys_addr_t addr, phys_size_t size, u8 op, u32 flags) { +#if CONFIG_IS_ENABLED(EFI_LOADER) u64 efi_addr; u64 pages; efi_status_t status; @@ -464,7 +465,7 @@ static int lmb_map_update_notify(phys_addr_t addr, phys_size_t size, u8 op, return -1; } unmap_sysmem((void *)(uintptr_t)efi_addr); - +#endif return 0; }