From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (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 76EE6361DCB for ; Tue, 26 May 2026 13:00:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779800435; cv=none; b=CQ7skG7jjcTxvKOochbty6HCLtBPOddwfaNj4V6gwYS4jNrgAS7otRrNov8XdO9i8Jmyd3FR9OCdMWbI2UFpI+i6LNJbMzLN3qNawf64140HGmVubt+ry6VwKch0RxrMGsQNqiQTEbW/XVzlSyGC+Mwd1Ux17Yy7oL75/RLUGFE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779800435; c=relaxed/simple; bh=DvvLRt3F5ORP7dlAdhtBqO4qrwFJRT7s3Reb5HxK6k8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X5uvEPqNlBitLYpshCrFcLb2HJCQ62h9P6Pe3g510XdR7Xt7UEx/cbTbc5TIkiJ68RI9HkDlDrAzOwgYniiTq78PT1n7OYgIgUQ2fLs0iSHOQMwC6aqitariHaOv9IMFxL/U5FxJSVRcjS3tPLy2HQNJX0VtjyLhx9GQP+3tZDs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=UPOjpcEJ; arc=none smtp.client-ip=95.215.58.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="UPOjpcEJ" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779800432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eqRAcpX+3JOcvVi4m9jMhaxftvCUQ9zppcLisuvJR1I=; b=UPOjpcEJWndGHzC2ELYwgruh15sSq4mQI7oByMYoO7O9/299xlLZuMnojhcNFoD2Wrmaez U3DRab8XDCYasgGLBuOp9fGzAP9fRTUlocJOrMu1kUe5QNBOKApY/nT3RnQRhMnhL84Ns2 DvrVl0na3WVlsRfBH/4NweaRYxXT6CM= From: Usama Arif To: Muchun Song Cc: Usama Arif , Andrew Morton , David Hildenbrand , linux-mm@kvack.org, Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Frank van der Linden , linux-kernel@vger.kernel.org, stable@vger.kernel.org, muchun.song@linux.dev Subject: Re: [PATCH v2] mm/cma: fix reserved page leak on activation failure Date: Tue, 26 May 2026 06:00:25 -0700 Message-ID: <20260526130026.3881822-1-usama.arif@linux.dev> In-Reply-To: <20260523060123.2207992-1-songmuchun@bytedance.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On Sat, 23 May 2026 14:01:23 +0800 Muchun Song wrote: > If cma_activate_area() fails after allocating only part of the range > bitmaps, the cleanup path still has to release the reserved pages when > CMA_RESERVE_PAGES_ON_ERROR is clear. > > That is still worth doing even in this __init path. A bitmap_zalloc() > failure does not necessarily mean the system cannot make further progress: > freeing the reserved CMA pages can return a substantial amount of memory > to the buddy allocator and may relieve the temporary memory shortage that > caused the allocation failure in the first place. > > However, the cleanup path currently uses the bitmap-freeing bound for page > release as well. That is only correct for ranges whose bitmap allocation > already succeeded. The failed range and all later ranges still keep their > reserved pages, so a partial bitmap allocation failure can permanently > leak them. > > Fix this by releasing reserved pages for all ranges. Use the saved > early_pfn[] value for ranges whose bitmap allocation already succeeded and > for the failed range, and use cmr->early_pfn for later ranges whose bitmap > allocation was never attempted. > > Fixes: c009da4258f9 ("mm, cma: support multiple contiguous ranges, if requested") > Cc: stable@vger.kernel.org > Signed-off-by: Muchun Song Acked-by: Usama Arif