From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0788E36D51D for ; Sun, 30 Nov 2025 15:03:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764515002; cv=none; b=LI44jRE6COoO1r3HHmZv7FqsFvZSQjM9NlFYSBenIEMXAZ7733189D+t1dozD1QZCYTHqVEjfMq27BcjqXs6XmHYxpngGipSjmnKypgzzZKd4gTgSwHi8tPdAgqrVTammk+m/5bEYs1gq9H7Zi2p0BtVIiJS3X4eFZZkCpv4ra4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764515002; c=relaxed/simple; bh=TAFCf3q2vPDWAup7NTYassPHAwy/rjIhZi3HHAzQAXk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BKE9xXML9mzg1Po7lHg/33H5ua3ASTU20PHnrCRmr0IyfVPE8fCv362iZiVOfqBSiTf3zylWVsHD5hbsk0hJ7PqkPF6FBa7TQiD/Y/Xq2au6r4Z1+uoq5wpCI2s2hkhvLocWAOUz28D3MwNoLI6z2UAJ1z6wwnpLX/U/P3bnSD8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qiog9cdW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qiog9cdW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69566C4CEF8; Sun, 30 Nov 2025 15:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764515001; bh=TAFCf3q2vPDWAup7NTYassPHAwy/rjIhZi3HHAzQAXk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qiog9cdWZvZoObq+tZ3+DPSDK4vw6aDshZ7M6M1PNiSXN2Jwpt9lZcKqChTf3S6Ud qSIuMNQeH9mzwyaM2u6X3+2SI58lWnLxeK+W105FUen4WRDxUK/jEbfFn/zG7n1X0+ rtII6a1IMqVJsW8/UuwFdjTj/eHlcus95iKdYRYsh7uDtqnyIVCfFweZdb1NokcCDX Kjv3nfwJSlDwRHCXYgO0XCNLjoKs9tWG0R1gw3Cd1jVd44z5WkbwCm0kU4Xckk9IPc 3DEqr8LaUP1gFZ62TjAQUXi/LF3vqPJ4Zv+VKLZBegR6s4BiCuXV3QCYz6PSmxpROf L4lIfRKJR3F9g== Date: Sun, 30 Nov 2025 17:03:15 +0200 From: Mike Rapoport To: Swaraj Gaikwad Cc: Andrew Morton , "open list:MEMBLOCK AND MEMORY MANAGEMENT INITIALIZATION" , open list , skhan@linuxfoundation.org, david.hunter.linux@gmail.com Subject: Re: [PATCH RFC] mm/memblock: Fix reserve_mem allocation overlapping KHO scratch regions Message-ID: References: <20251130172939.574999-1-swarajgaikwad1925@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251130172939.574999-1-swarajgaikwad1925@gmail.com> Hi, On Sun, Nov 30, 2025 at 05:29:39PM +0000, Swaraj Gaikwad wrote: > Currently, `reserve_mem=` does not check for overlap with these KHO > scratch areas. As a result, a memblock allocation may land inside a > KHO-provided scratch region, leading to corruption or loss of the data. > Noted by the following TODO: > /* TODO: Allocation must be outside of scratch region */ > This RFC proposes extending `reserve_mem()` to allocate memory *only* in > gaps outside the KHO scratch intervals. The logic is: > > 1. Walk through all KHO scratch ranges (kho_scratch[]). > 2. Attempt allocation in each safe gap: > [curr_start_addr, scratch_start) > 3. If not found, attempt to allocate after the last scratch block. > 4. If all attempts fail, return -ENOMEM. > > The allocation is done via `memblock_phys_alloc_range()`, which already > supports constrained range allocation and preserves alignment guarantees. > > This is posted as an RFC because I would like feedback on: > > - Whether the allocation-gap scanning approach is acceptable. > - Whether this logic belongs in reserve_mem() or should be abstracted > into a helper for reuse. > - I would appreciate guidance on testing this change. So this is completely untested? Kernel documentation asks for submitters to test their code: https://docs.kernel.org/process/submit-checklist.html#test-your-code Please study the code you are changing to understand how it should be tested and don't submit untested patches. > Signed-off-by: Swaraj Gaikwad -- Sincerely yours, Mike.