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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 379E2C624CF for ; Tue, 1 Sep 2026 01:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:CC:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zPvP1K9EnRd/mao8eJm5iib0cl/6wBDf4gm9yBOU/uA=; b=LFrVhXAKyYvOWzrJE6ttNojfbN pgduH26R73LqxkSePdMeYccfTUnn2XFHV+xQx3hCZuNg1sVjtDp0slpQHn6iTzKxmmWSdpagpl7cw ulR0x+GCiH4FosxNFnzFRhDWgZWqCoTcA8JeyDoLQ2h8yvtTqSFjXunugG2rncA2otMcpCYUl6PAE MBV+d2Czij4ZX/rnSj9G/pndQMcU1nvHCA2XRJM0n0k0/LT8eeKbtfOu6xSPkbXlU2UJYUkfqEGMi PrWBmVtV0np0Bxp5PC6cAH+YAw8iXQG0TxdMmZhAmT7WWq00uYeK6Are9mRxFkKSeizJHPkZ6fmzC wdKD026g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x1DVM-0000000Aoje-3S55; Tue, 01 Sep 2026 01:41:40 +0000 Received: from [113.46.200.221] (helo=canpmsgout06.his.huawei.com) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x1DVJ-0000000Aoj1-1ZHK; Tue, 01 Sep 2026 01:41:39 +0000 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 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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260831_184137_791867_5F59C70B X-CRM114-Status: GOOD ( 18.73 ) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org 在 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 >>