From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout06.his.huawei.com (canpmsgout06.his.huawei.com [113.46.200.221]) (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 7D019359A89 for ; Tue, 1 Sep 2026 01:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.221 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788226883; cv=none; b=OyFcUcZTjyTmu8UpYEjYiWoOXMfRDiWl51bg7YW/DFE4dNPcqvSnt4Hi+DSWJ8LzmI0UlTMsJ1bbxTgBp5g2wpk5O/SIhhQWsYiQeZJXF05TSlPYd2oh3x6mlONpJFYmhAI5prAxXrQF/9aPTVAa6NHUrAXQTHtxo7u4vL2PDQw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788226883; c=relaxed/simple; bh=8V/iJ1syJzk3Ej0PD6xyVpop3GjTd8FsA+LFSMddAWw=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=hpRRj/4jJaRe4RjHncwbVOXjj/A+aZqMFPpQ70pYstu67CmXXdzzjuT54w43m1hOOT74V8Q0mOwcyww6OamjzAjdEN7CHKg9ZQI6nAf96cpR6ey1e4b0x91I5ThxSaLKrQkHHDHtbDxMUy8espnFfVUsjulPcnybEf/PKCAC7Js= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=Jml/HTTQ; arc=none smtp.client-ip=113.46.200.221 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="Jml/HTTQ" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=zPvP1K9EnRd/mao8eJm5iib0cl/6wBDf4gm9yBOU/uA=; b=Jml/HTTQck/emuqLeeU2tibQLYjU8fXxCCcdo3klXPgO8NzCaTkbd5ycSpoG64qAUTvikX/3F 607VcvF+fmYaem7r38R+LD9SNSgKkzUeX3TLkcP4y7zA0vceMDXkYNbj0KO3qWM1ZVKio3aaJuW cW+wJefcVETqqA/xk+td/6E= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4hYpFv2FTwzRhVN; Tue, 1 Sep 2026 09:30:27 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 689A840561; Tue, 1 Sep 2026 09:41:14 +0800 (CST) Received: from [10.67.109.254] (10.67.109.254) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 1 Sep 2026 09:41:10 +0800 Message-ID: Date: Tue, 1 Sep 2026 09:41:09 +0800 Precedence: bulk X-Mailing-List: loongarch@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 05/17] LoongArch: kexec: Fix CMA page leaks in segment placement retry loops To: Huacai Chen CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20260826092541.3905933-1-ruanjinjie@huawei.com> <20260826092541.3905933-6-ruanjinjie@huawei.com> From: Jinjie Ruan In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To dggpemf500011.china.huawei.com (7.185.36.131) 在 2026/8/31 22:09, Huacai Chen 写道: > Hi, Jinjie, > > Why does the ARM64 version of this patch use "kexec_file" in the > subject line but the LoongArch version uses "kexec"? It is better to > keep consistency. Hi Huacai, Thank you for the review. I will revise the subject in v4. Best regards, Jinjie > > Huacai > > On Wed, Aug 26, 2026 at 5:25 PM Jinjie Ruan wrote: >> >> During kexec image placement retry loops, any midway failure causes >> the loader to truncate `image->nr_segments` back to its initial state >> to purge the failed segments. >> >> However, this truncation introduces a memory leak. The CMA pages >> allocated via kexec_add_buffer() during the failed attempt are tracked >> in the `image->segment_cma` array. Because the subsequent cleanup paths >> only iterate up to the truncated `nr_segments` boundary, these allocated >> CMA pages outside the new boundary are permanently leaked. >> >> Fix this by explicitly releasing the associated CMA buffers in >> the failure paths before `image->nr_segments` is reduced. >> >> Cc: Huacai Chen >> Cc: WANG Xuerui >> Cc: Youling Tang >> Cc: "Mike Rapoport (Microsoft)" >> Cc: Sourabh Jain >> Cc: Kees Cook >> Cc: stable@vger.kernel.org >> Link: https://sashiko.dev/#/patchset/20260729031235.2840255-1-ruanjinjie%40huawei.com >> Fixes: 55d990f0084c ("LoongArch: Add EFI binary support for kexec_file") >> Signed-off-by: Jinjie Ruan >> --- >> arch/loongarch/kernel/kexec_efi.c | 1 + >> arch/loongarch/kernel/machine_kexec_file.c | 6 +++++- >> 2 files changed, 6 insertions(+), 1 deletion(-) >> >> diff --git a/arch/loongarch/kernel/kexec_efi.c b/arch/loongarch/kernel/kexec_efi.c >> index 5ee78ebb1546..15fd797ff3de 100644 >> --- a/arch/loongarch/kernel/kexec_efi.c >> +++ b/arch/loongarch/kernel/kexec_efi.c >> @@ -86,6 +86,7 @@ static void *efi_kexec_load(struct kimage *image, >> * We couldn't find space for the other segments; erase the >> * kernel segment and try the next available hole. >> */ >> + kexec_free_segment_cma(image, kernel_segment_number); >> image->nr_segments -= 1; >> kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz; >> kbuf.mem = KEXEC_BUF_MEM_UNKNOWN; >> diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c >> index 5412aa9f3568..62a5be102065 100644 >> --- a/arch/loongarch/kernel/machine_kexec_file.c >> +++ b/arch/loongarch/kernel/machine_kexec_file.c >> @@ -217,7 +217,11 @@ int load_other_segments(struct kimage *image, >> return 0; >> >> out_err: >> - image->nr_segments = orig_segments; >> + while (image->nr_segments > orig_segments) { >> + kexec_free_segment_cma(image, image->nr_segments - 1); >> + image->nr_segments--; >> + } >> + >> kfree(modified_cmdline); >> return ret; >> } >> -- >> 2.34.1 >>