From patchwork Wed Dec 11 02:17:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 849131 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:2c4:b0:385:e875:8a9e with SMTP id o4csp98483wry; Tue, 10 Dec 2024 18:17:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV7przOPAe4gJfmDtw6/TGbfmZbG24kv6oxvHemvrWhe0Bt7pvMzMUgvNqDlAltm5kQUahwkA==@linaro.org X-Google-Smtp-Source: AGHT+IEhAZzZuxCwQEJQqr5N9eJ53VLDek9DXcyQezFZ46BEWpsVK0jksPEue/tWvMH63uPVGFuV X-Received: by 2002:a05:6402:278f:b0:5d0:f830:ef4e with SMTP id 4fb4d7f45d1cf-5d43316d97cmr980148a12.34.1733883431704; Tue, 10 Dec 2024 18:17:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733883431; cv=none; d=google.com; s=arc-20240605; b=T7KnqE3OnRpayx4k8Vh1oWj8G4gLmtnIKKakF0oikMGJodD/uHxRRr2sUhyWQ6ZMMb HvTN+VUKBWPE/bfkHTk6NHblVQgqbPDUc0abqKaAP/TcTWjREIbU5k0edM/uMmuD1hSf 22z8CqZh36DDxOHAUSfXSvkAoU4Ho80haVjq/qAAHGx5ZySVrW7Ajnn1c5gaAExEJpf3 xTHVL5LZexANFh4J3h2s1+lpBe9o3BrtHazbsXPL2oUUv4vyHf/DzamBzRt2jUU1FML8 qmBJBJUg7ICT5hgOb6aFPfsuRNRCgTb0yYRaALXniORR1VV/E0rgHE3R/gmhca6h72Aq JnHQ== 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:dkim-signature; bh=ZfT2oHWqRp0PVk8k7czp5K4KtbbiEK7iXob/kIGyjfQ=; fh=DzNbFdv91sdxgVhufd0rm0W525w/8e7KpAlVrm6dz2U=; b=IWR1vDWEDNtPfGisBYdrX0WBJM2o2U8uw7gX4GKin32Su8XKoZsd4dpn4Unv97SoSp PmY4zdFeM4wGkhG0xqW/xL4EqVJ+Lo5+OCWUBmyVEExkG2i0NS2XQoF/TMnpfbsTUhWe wtMmONg+ts+VuWZIQ1z9rgyZKyM4TrjBJ6ptwjPNy/5orABgnjIeGPYBVSdKr/tnXJQp +Pd9lvUmxGnlmGFEWMtolRhe2t3NLbmV9lq9t7oRd5SuVZcSUuMOrq0aCjRAoeLqN6OG yR0gDE8D9JrxB3tu+XMNntqVHlXaT+9BvQkYiPn+t9Ig8O2vv/l88A76hLWWWwsAHzMN 9Now==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FqShcZ+Y; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@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 4fb4d7f45d1cf-5d14c7c7220si9231692a12.313.2024.12.10.18.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 18:17:11 -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; dkim=pass header.i=@linaro.org header.s=google header.b=FqShcZ+Y; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D492B80200; Wed, 11 Dec 2024 03:17:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="FqShcZ+Y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 27EEB80214; Wed, 11 Dec 2024 03:17:09 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6CFB180207 for ; Wed, 11 Dec 2024 03:17:06 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=semen.protsenko@linaro.org Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-71deb2025dbso1562697a34.1 for ; Tue, 10 Dec 2024 18:17:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733883425; x=1734488225; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZfT2oHWqRp0PVk8k7czp5K4KtbbiEK7iXob/kIGyjfQ=; b=FqShcZ+YAWMO7oVYj0r7jmZJlpRVAfY+EbaAOM5hh1H9F6PYq03BqhmNufIsBllFvM AYEZ2XqkDaXQzmJWv1wO5VcLUIypQh7ppPfZk2fCWr8jznV2PF+gwdLwwzr2DgA2IDpy wcqYSMJ2dPeQpnbyaQf/bHLFV3F5yBGQlTtnODfJdQDyeS2056F1R/U8IvlfWPBxwFeX YWT/nFcK1zNc5sIGuyozygnOcviT/j2XDqP4eym+t6v7LQbv+oLKPplBlEtIB54P0qZI 7lL/48PRwPBLUOSFeXHzjHnC3Ts1KiDjlxK7Q1GQxjkiv5XaOkMBk3dx3QypblvDjSnW 0u8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733883425; x=1734488225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZfT2oHWqRp0PVk8k7czp5K4KtbbiEK7iXob/kIGyjfQ=; b=R7NsYlGIjvQ5Yw3ks1vGIvAHI4H8r+chuax30bynicZXaQwc1DmJAo1GuNMiqbWUp4 c8N+lav7JwrZAG/aIhcX7E1iyO2uGMEKQHqWRDiPQlbLQ3VA5A+KIr2j0BA1UT3zZF9t riuQzb6SJYvV9ftTiYWJ5MHZf9vE4VQ36BIs3nNmZvPFG3HdSEk9lUNCyAtvpPjxG0lf q0TrE1+ioUeVMf71/qnFtWG0q0KFFAfh9zewt6vCdE14hNM0JQgBq0BeXoEQSlPhNDtd IhOrUrXVmEJ+nMtRAWUUJk50prLT5mzaj2dh0/5PUaucQCEbIuLwkJt4RJP9cRqq/nIl XB8g== X-Forwarded-Encrypted: i=1; AJvYcCWCawwVir9Dft1P55jO5OBbORNZ2mkhOkI0NTqnmGsCGCwENCOplILBBomNTvhmnotMFwPEDIc=@lists.denx.de X-Gm-Message-State: AOJu0YyPY9odHHnnkDpoBOcTmsoAe/V5v6tXjoBrtbeMXj7kzljsRhX1 Qu8WHmV1YwLdna6v950LL+YnMdFuJbh33basBRg0R2F73hxlOFD4RA7ZEyadp/o= X-Gm-Gg: ASbGncvLC4sV4B9IkqkWWB+EsM8LwTRcOPhA91tRGZQpY5YOoLGvXc1XFbnmeDTDzha CQPmfY78yb2+HQKZRyukJRpBUL30MF6a65sZ3HpMosWldeQfNFe/vvK86CbmZSApCmw6igR3Bn8 iPyVfd+YUnd8CCpuaCyOCcWQiaElOTBXa48bSIQXddXg0PZ59gdWenHOOqcNgpD2QuGwFUPbbe6 Mbh50kSmrhmNeuhi7Vdm+F7s0zS793wa7WBZcZCjtcKMK+Qvx4qk48UJzY= X-Received: by 2002:a05:6870:658d:b0:288:60d6:f183 with SMTP id 586e51a60fabf-2a012f9ea1dmr790606fac.38.1733883425171; Tue, 10 Dec 2024 18:17:05 -0800 (PST) Received: from localhost ([136.62.192.75]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-29fbee2df31sm1985912fac.13.2024.12.10.18.17.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 18:17:04 -0800 (PST) From: Sam Protsenko To: Tom Rini Cc: Ilias Apalodimas , Sughosh Ganu , Heinrich Schuchardt , Simon Glass , Caleb Connolly , Marek Vasut , Laurent Pinchart , Patrick Delaunay , u-boot@lists.denx.de Subject: [PATCH v2 1/2] lmb: Return -EEXIST in lmb_add_region_flags() if region already added Date: Tue, 10 Dec 2024 20:17:01 -0600 Message-Id: <20241211021703.2333-2-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241211021703.2333-1-semen.protsenko@linaro.org> References: <20241211021703.2333-1-semen.protsenko@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 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 Reviewed-by: Ilias Apalodimas --- Changes in v2: - Removed the check for exactly the same region, and return -EEXIST in the branch handling overlapping regions instead - Reworded the commit message accordingly lib/lmb.c | 26 +++++++++++++------------- test/lib/lmb.c | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/lmb.c b/lib/lmb.c index b03237bc06cb..a695edf70dfa 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -183,8 +183,10 @@ static long lmb_resize_regions(struct alist *lmb_rgn_lst, * the function might resize an already existing region or coalesce two * adjacent regions. * - * - * Returns: 0 if the region addition successful, -1 on failure + * Return: + * * %0 - Added successfully, or it's already added (only if LMB_NONE) + * * %-EEXIST - The region is already added, and flags != LMB_NONE + * * %-1 - Failure */ static long lmb_add_region_flags(struct alist *lmb_rgn_lst, phys_addr_t base, phys_size_t size, enum lmb_flags flags) @@ -217,17 +219,15 @@ static long lmb_add_region_flags(struct alist *lmb_rgn_lst, phys_addr_t base, coalesced++; break; } else if (lmb_addrs_overlap(base, size, rgnbase, rgnsize)) { - if (flags == LMB_NONE) { - ret = lmb_resize_regions(lmb_rgn_lst, i, base, - size); - if (ret < 0) - return -1; + if (flags != LMB_NONE) + return -EEXIST; - coalesced++; - break; - } else { + ret = lmb_resize_regions(lmb_rgn_lst, i, base, size); + if (ret < 0) return -1; - } + + coalesced++; + break; } } @@ -667,7 +667,7 @@ long lmb_add(phys_addr_t base, phys_size_t size) * * Free up a region of memory. * - * Return: 0 if successful, -1 on failure + * Return: 0 if successful, negative error code on failure */ long lmb_free_flags(phys_addr_t base, phys_size_t size, uint flags) @@ -818,7 +818,7 @@ static phys_addr_t _lmb_alloc_addr(phys_addr_t base, phys_size_t size, lmb_memory[rgn].size, base + size - 1, 1)) { /* ok, reserve the memory */ - if (lmb_reserve_flags(base, size, flags) >= 0) + if (!lmb_reserve_flags(base, size, flags)) return base; } } diff --git a/test/lib/lmb.c b/test/lib/lmb.c index 0bd29e2a4fe7..48c3c966f8f2 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -754,7 +754,7 @@ static int lib_test_lmb_flags(struct unit_test_state *uts) /* reserve again, same flag */ ret = lmb_reserve_flags(0x40010000, 0x10000, LMB_NOMAP); - ut_asserteq(ret, -1L); + ut_asserteq(ret, -EEXIST); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000, 0, 0, 0, 0); From patchwork Wed Dec 11 02:17:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 849133 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:2c4:b0:385:e875:8a9e with SMTP id o4csp98583wry; Tue, 10 Dec 2024 18:17:36 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUBXc0mC0PenEC6oujMUnuH9oqCqwN1UeWF5RMiKBGsYnLA7oRrW7/6cWzhxJwYanq9jRz2IQ==@linaro.org X-Google-Smtp-Source: AGHT+IFxwqQJF+i9mH6WLRTZ4jB4MY7Ntfqbr7fCvjbDw/0Qx58RDqEfZPQBLQrE+oed0EVLAMo0 X-Received: by 2002:a17:907:9557:b0:aa6:19f3:d083 with SMTP id a640c23a62f3a-aa6b11ef28dmr86424666b.30.1733883456401; Tue, 10 Dec 2024 18:17:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733883456; cv=none; d=google.com; s=arc-20240605; b=IUeB4Wjdb1YuM4C1MpFaSH+hbC4Vw3AWZkoLj0Gdnz2Nv7kbVlKHUMTdGFfp4PWRiV W0TPrct8DkVqQXMqbU1lsUliMhoWkAPnIBC1TQrDtlTKs1VgoZb2PH37xFCGfLzcIGC0 m7r0t7lKAcOrlgOHJ037UL7807wFPkRsyJgFQfCQ/EMU9x2w3uL+6caxyFl4UUyKDvDO nytJCvNXNb6TobqDGUH5GAKY1j8EzCIm891aSIPvBk216LBc/M6BdiMejCJKgF+mCH3n E0xHsCQI2NikceGg8QXoswdifCSO5bZ+tHoUMuF5qz5jJ0y95orYCCQm4SQ6FCnvPOBy EAug== 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:dkim-signature; bh=z/V6Slifq/SZc9zepx0sUboIXo723LgvGKKgmbOvzOI=; fh=nxBbvc//fG7k5ADXOhjloH2eKp9yhKZCpsa86Tg1U6A=; b=eppgYj67q+gbHp+K3dnRYGcx9BduGGLUNaJuxHcJRPirG1rf+bYx6eU/g2Ku1lPr2C 3kvNtnR6enmQCxxuTafxaux8CP5xCJyEr5FZeW9z5na/UWARIXityAGmI5sJj9UWWaqr 649JUjOBKKhh1HqwvTnKqYL9eAr0+uFbL2DZl9+GHzWsgJ8+pL72R00QbduzdN1WzdK7 2SchlfTEF15u+I5bBUDa1CM07+JPbTuai3jOvAI58JXRmJZPdZt8UDqVYf7MT6C4Zh1L 1jEv+zrgirBjrhz+mxplCAoBU7440I8T7Wb4vDel6G4D29n8dGicE7zyyuP53nSuwyNA padQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pdG5o93A; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@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 a640c23a62f3a-aa6691f2209si546613066b.870.2024.12.10.18.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 18:17:36 -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; dkim=pass header.i=@linaro.org header.s=google header.b=pdG5o93A; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 69F7980234; Wed, 11 Dec 2024 03:17:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="pdG5o93A"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F18B08021F; Wed, 11 Dec 2024 03:17:11 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2123380210 for ; Wed, 11 Dec 2024 03:17:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=semen.protsenko@linaro.org Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-71decc7de4eso805105a34.2 for ; Tue, 10 Dec 2024 18:17:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733883426; x=1734488226; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z/V6Slifq/SZc9zepx0sUboIXo723LgvGKKgmbOvzOI=; b=pdG5o93AUTfGDIJSTkiYmiZsrok2yGpCcCeoHXCb3Fd80hCV5/r0PRoiZxHwZiD+im M3nFJgkdCRRyYcgXCLAcjwznY8otOLJVRSTOYh9itdUzIZKFqpYKAWeDhhPM/wgoZc7r 1Nn4ggWNpyshrzMttV/1IVvKiT/mOIKrMW1obdDUmDg+CUU1FUeqQvtgDwv6qDJs+Yuo a8FAaYQp/PL1RO9nO6RLy2f3aaL8H8+md57ZnJEtllc1JZrz1/MrOpWT0CXVCCbbt5oV kyZJH066XCYuI1sCG5o6mfijVeldnJMupbvoCNjTfd6vP6+1/lNY1JD+hGEhrnqmmLwR rNzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733883426; x=1734488226; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z/V6Slifq/SZc9zepx0sUboIXo723LgvGKKgmbOvzOI=; b=WP94GwqCrqn1nxtHypEZiVWbne8XDXIc788raYOSyg1n2WEgxErF0DaL9EkT7Kv75u ZysGGredi+p5VgUy0lPVT74aZm5jkDFDThFtx10dAFqOXLyaiZWrT9QBbohfu94zajt7 RtBO8TiywnzsUlB37TIUSi1aYtAuAOVQhIb3xH1juNCO17bDJelyZZYVzBeoATS9wP98 NDEJdv/wffSV0kYWoVwiEG3DACazwT/w/DELLZBioX6MEPiGvc5szGxv+4e/fc64QtnV 6WZfTanqxT1Hy8Z13k/D/4XnUfxSOIu9y8f4m2dvE/heVDYYFOAF0YRkfTULYrfqwGCs rxNg== X-Forwarded-Encrypted: i=1; AJvYcCUXCXMrPP0tElbgl7ON3E6WIqAF8tqc4BvFkfB4DD8mJd0kmP5qfpqR5Wui1Z4SZWb4rrUbbt4=@lists.denx.de X-Gm-Message-State: AOJu0YxO7W+0LSngmbErfrqEcJBgbuM3qTguTZHSulBU+xRZzOU/Jy+x lbTRzvMMcgbkSJxzWLpAo9ZpHXrtX330U8oSm8AheF5CmBN+2cx6ZzyvAbpDFN8= X-Gm-Gg: ASbGncuSG3S1FSIgVbBxyUjd0YNEysq5M+Q+/IrMBqu0YzaSi/yYVIvZch2oZhPWASX 4zZ4PQTKDUSkPOhHDh6zt7YXCrW/nxK5kX/lGVXNR2QlNMTQUvUi30Hf/loy/XmLke/mt9NuZXK +B12vs6tMiczbDbgiMOjhEFnvstJm3A4xJgTLO4mZ6hepWJwVq/F6ohuY8Lr2TyNlOyt/uw9Ulf k7jZqBZXFDKSboBxfEpkIg4SzuFc30pdOgWrM0VuCurHqcHQvUODUzRbFc= X-Received: by 2002:a05:6830:6d89:b0:718:6da0:72b with SMTP id 46e09a7af769-71e197b7692mr661231a34.7.1733883426417; Tue, 10 Dec 2024 18:17:06 -0800 (PST) Received: from localhost ([136.62.192.75]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5f2793225d5sm2791021eaf.42.2024.12.10.18.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 18:17:05 -0800 (PST) From: Sam Protsenko To: Tom Rini Cc: Ilias Apalodimas , Sughosh Ganu , Heinrich Schuchardt , Simon Glass , Caleb Connolly , Marek Vasut , Laurent Pinchart , Patrick Delaunay , u-boot@lists.denx.de Subject: [PATCH v2 2/2] boot: fdt: Handle already reserved memory in boot_fdt_reserve_region() Date: Tue, 10 Dec 2024 20:17:02 -0600 Message-Id: <20241211021703.2333-3-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241211021703.2333-1-semen.protsenko@linaro.org> References: <20241211021703.2333-1-semen.protsenko@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 boot_fdt_add_mem_rsv_regions() function can be called twice, e.g. first time during the board init (as a part of LMB init), and then when booting the OS with 'booti' command: lmb_add_region_flags lmb_reserve_flags boot_fdt_reserve_region boot_fdt_add_mem_rsv_regions ^ | +-----------------------+ | (1) | (2) lmb_reserve_common image_setup_linux lmb_init ... initr_lmb do_booti board_init_r 'booti' That consequently leads to the attempt of reserving the same memory areas (described in the 'reserved-memory' dts node) in LMB. The lmb_add_region_flags() returns -EEXIST error code in such cases, but boot_fdt_reserve_region() handles all negative error codes as a failure to reserve fdt memory region, printing corresponding error messages, which are essentially harmless, but misleading. For example, this is the output of 'booti' command on E850-96 board: => booti $loadaddr - $fdtaddr ... ERROR: reserving fdt memory region failed (addr=bab00000 size=5500000 flags=2) ERROR: reserving fdt memory region failed (addr=f0000000 size=200000 flags=4) ... Starting kernel ... The mentioned false positive error messages are observed starting with commit 1d9aa4a283da ("lmb: Fix the allocation of overlapping memory areas with !LMB_NONE"), which removes the check for the already added memory regions in lmb_add_region_flags(), making it return -1 for !LMB_NONE cases. Another commit 827dee587b75 ("fdt: lmb: add reserved regions as no-overwrite") changes flags used for reserving memory in boot_fdt_add_mem_rsv_regions() from LMB_NONE to LMB_NOOVERWRITE. So together with the patch mentioned earlier, it makes lmb_add_region_flags() return -1 when called from boot_fdt_reserve_region(). Since then, the different patch was implemented, returning -EEXIST error code in described cases, which is: lmb: Return -EEXIST in lmb_add_region_flags() if region already added Handle -EEXIST error code as a normal (successful) case in lmb_reserve_flags() and don't print any messages. Fixes: 1d9aa4a283da ("lmb: Fix the allocation of overlapping memory areas with !LMB_NONE") Signed-off-by: Sam Protsenko Reviewed-by: Ilias Apalodimas --- Changes in v2: - Added R-b tag from Ilias - Reworded the commit message a bit, reflecting changes in the lmb patch boot/image-fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot/image-fdt.c b/boot/image-fdt.c index 3d5b6f9e2dc7..73c43c30684f 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -77,7 +77,7 @@ static void boot_fdt_reserve_region(u64 addr, u64 size, enum lmb_flags flags) debug(" reserving fdt memory region: addr=%llx size=%llx flags=%x\n", (unsigned long long)addr, (unsigned long long)size, flags); - } else { + } else if (ret != -EEXIST) { puts("ERROR: reserving fdt memory region failed "); printf("(addr=%llx size=%llx flags=%x)\n", (unsigned long long)addr,