From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9B23C61DFD for ; Tue, 1 Sep 2026 01:41:33 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4hYpVg4X7pz2y2S; Tue, 01 Sep 2026 11:41:31 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=113.46.200.221 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1788226891; cv=none; b=JHQwDhkB/mK114xB623wno98y4xdF6CrTirVhw57wTrlyXLrNAoVHPGQEW+Z0S0PV8UNZs2QTdKoxQ9cocxXEqYFq47zl6XQg8L7cv3GHIYnfbGB9JzAp5dCBuH0tBqc/tw4n3Vh2O5gyethej6JI7V/Vz7Hkl1/GC6TgzzKy3YL80+NDJEhaww89DqeOptCFeg2M0omvDGZHXjx+p7uKOeAfvaZhDgo5dyv7XBFW7PBlu5pdpAzuYnSNEEs2U+CgWjDwb3FLkZruMhq8qon4e/IHZwW+VVPkJjELke/hPgSXUGXywZQfOPC/qktcRoNQHoqwkZ+/h5XOGH1+6ouiw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1788226891; c=relaxed/relaxed; bh=zPvP1K9EnRd/mao8eJm5iib0cl/6wBDf4gm9yBOU/uA=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=U89/UVIy0npn1UJWilyrZAGIaNnjcgtiP27ctsg4olqaatC+Dq9LIRqEMCg1MyFiG7po4kjFV3OL8OE4E/kz3bcrVgAEfJsQzN238ky8XcYDl0kJHcXI9txAPq8sn6zUxP/tdGQE9NcSNFBT1mpeO5682u7UBfE7RNbg4sDdFUo43BrXIFwyOEMRPXKfmY6vqLwgYVqdEm2BRorU9rEjMU9KuP4Jr7noddcrrkNPkfq4yOGKOVtU/7oiMqeyr6DyKCieq1M2/WRNco8XAawV2WkaSLKZnx29ZzdYL+pjskXLsX0RCaMKuFWORYQ0MjHOrp0D58Rd0jI9Fr/jQuUpTw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; dkim=pass (1024-bit key; unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=Jml/HTTQ; dkim-atps=neutral; spf=pass (client-ip=113.46.200.221; helo=canpmsgout06.his.huawei.com; envelope-from=ruanjinjie@huawei.com; receiver=lists.ozlabs.org) smtp.mailfrom=huawei.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=Jml/HTTQ; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=huawei.com (client-ip=113.46.200.221; helo=canpmsgout06.his.huawei.com; envelope-from=ruanjinjie@huawei.com; receiver=lists.ozlabs.org) Received: from canpmsgout06.his.huawei.com (canpmsgout06.his.huawei.com [113.46.200.221]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4hYpVb04Zsz2y2P for ; Tue, 01 Sep 2026 11:41:24 +1000 (AEST) 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 X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list 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-Originating-IP: [10.67.109.254] 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 >>