From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796211555; b=r4vGseiA5pZ5djq+jT7tv6lTgHY68hJxS5F/rfViWPL6MgmHAqtBps4jWGO1Zi9UxSqu gu2/IWv4QGVnQ2uXZfZuJ6RtrQ1Iq/B/VQ/2dHxK6QONO7cCaDWy65AwoP/uiF0qJpUOg LDAwY0gnOsekijdsMubZ4/cn/iN7hMDFE1LTLRXyiQn7JfvcoP3Jq8mVualz7yZKPnMgQ 1i6Altvf/n2PYE7XHj2q6h0iOlN/pNHar3Rsh+ba0NAYWp9igqRGIF40yVfbZCkGP1gbc y/MBeXIMG633xp8jO62JSKrRyRY74vIrpkPkKynY2TMBfLi3Wc5QSZAQNFyAw0385AQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796211555; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=Q3GOrn1MJD61AXLVMREkti8baOvybMdAxjEIB6YrWGo=; b=ODM952DrBL48jEdJXL3v1IDfQetVcjN3UTzAzRfrnOleMY0C80fUndT8r+u6TZonS/nE ewzUhE9pCvwB9qy9Bx4QGVw5u273MRQ8ylDZZTgAxlgReYLewt80ebvPHBjOCAksF+lYJ nK7PAxMNn4XexTK/V0O32fo1UusCdwv3vyl0dFqeVB2mTe59Ag4vZQb+inwB5r9QBZjBr BRmTRwvWJPTlI658/Kl4Q5x0aF6tqr7k/9MTMhB/lsIv+v/WjPvddlrvof3HzPt7jTh8N 858ffUNjctTVihZuUzUzO0dRFpaieJklk0OjOi6QIYNcozBPSKzhhOy8lDWGO58Oqhg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jqyUumdB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65C43606A31A for ; Wed, 2 Dec 2026 11:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jqyUumdB Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB05B1F000C1; Wed, 2 Dec 2026 11:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796211555; bh=Q3GOrn1MJD61AXLVMREkti8baOvybMdAxjEIB6YrWGo=; h=From:To:Cc:Subject:Date; b=jqyUumdBsrIUvCcyDOQfGV6Xzlkgml0Otk5Wy+GXh6MVg8RfWcXrlQfwvADEqyQGw VdF2NrrVY2Re+7xMyvHQp6YbIzkc0ZyrELFcMz4Olrvtq7TEUo7PtOx6sQqk+eiBnn cSnFjrrhHS+kOoGc8uOixlRsmtOx875NY0+bJzi9VspS2p7f+lFvphvk5RzyJVaqHY jTNUWq//xhAChZB0lTaPUadYJ0uF298InK3Ie35zNzDrc6/Jzxoypiyse5rRo7qJwq D5dqkuCyRjL+3c4Ub9DPcVLFLEh01vVohQdtb5KXYFgNVfGMYzqio03ptAjHMIUzxe IzT+SbfU5pMcQ== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: "Liam R. Howlett" , Michal Hocko , Mike Rapoport , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sashiko Subject: [PATCH] mm/cma: fix handling of free ranges that cross 4G for multi-range areas Date: Wed, 2 Dec 2026 13:39:09 +0200 Message-ID: <20261202113910.1412130-1-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Mike Rapoport (Microsoft)" Multi-range CMA areas are placed only above 4G. cma_find_free_range() enforces this by skipping free ranges that start below 4G, including the ranges that cross 4G. On systems where RAM is contiguous across 4G, like QEMU arm64 virt machines with more than 3G of RAM, the largest free range of a node may cross 4G. When hugetlb_cma falls back to a multi-range area, it cannot use any part of that range and the reservation fails if the remaining ranges are too small. Use the part of such ranges above 4G instead of skipping them. Comparing a phys_addr_t with SZ_4G causes warnings on 32-bit builds, so make cma_find_free_range() a stub that returns 0. Reported-by: Sashiko Closes: https://sashiko.dev/bug/linux-59c2cbb5-4dcf-49a5-90c2-72f5b734d510 Fixes: c009da4258f9 ("mm, cma: support multiple contiguous ranges, if requested") Signed-off-by: Mike Rapoport (Microsoft) --- This can be folded into commit 64910601efce ("mm/cma: simplify cma_declare_contiguous_multi()") in the current mm-unstable. mm/cma.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 0c97aadcfea40..de35cfc023404 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -504,6 +504,7 @@ static int __init __cma_declare_contiguous_nid(phys_addr_t *basep, * Find the largest free range above 4G that can hold a part of a multi-range * CMA area. */ +#ifdef CONFIG_PHYS_ADDR_T_64BIT static phys_addr_t __init cma_find_free_range(phys_addr_t align, phys_addr_t size_align, int nid, phys_addr_t *basep) { @@ -511,13 +512,9 @@ static phys_addr_t __init cma_find_free_range(phys_addr_t align, phys_addr_t max = 0; u64 i; - /* no point searching if the system can't address above 4G */ - if (!IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT)) - return 0; - for_each_free_mem_range(i, nid, MEMBLOCK_NONE, &start, &end, NULL) { - if (!upper_32_bits(start)) - continue; + if (start < SZ_4G) + start = SZ_4G; start = ALIGN(start, align); if (start >= end) @@ -532,6 +529,14 @@ static phys_addr_t __init cma_find_free_range(phys_addr_t align, return max; } +#else +/* no point searching if the system can't address above 4G */ +static inline phys_addr_t __init cma_find_free_range(phys_addr_t align, + phys_addr_t size_align, int nid, phys_addr_t *basep) +{ + return 0; +} +#endif /* CONFIG_PHYS_ADDR_T_64BIT */ static int __init cma_range_cmp(const void *a, const void *b) { base-commit: e685fdf67323bade713c5f81015eda5094b3261b -- 2.53.0