From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B34EC606A321 for ; Fri, 27 Nov 2026 10:11:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=oyPM1LHY Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4jbTgP2XFLz2yKn; Fri, 27 Nov 2026 21:10:09 +1100 (AEDT) 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=1795774209; cv=none; b=NefU0QSv3Ui5M9n670G/LV2cF3sbmE/Dx5X32/f62Y8y8B9tLd+JPwbEZOXcsr3xrBJxM377m1YkMwZie++3edW0scwnfmGtPI3W3LclvRjSPIJjw+Ln0U89ntYkn+CZTdNsGy0CtAgfuLm3RCGwN2wVGyaCY3LtTRYXVQpmAWl+xoMW//ZTOSEb1bp1LBEVo/3XX1K0nULhVgQ2RdEr0ApX5I0M9govgfwX3RoTNTsKirRq1mGm5NU8p+dgrzDMpIqpZjgJtk0RwuosJZiGYbSuTB9yveJ8bEEWjx4LdUlbWtmVTLwbKtaAXwvG9iyHxZtRiNh/Ko+7L5mYtpsKVA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1795774209; c=relaxed/relaxed; bh=g2aQKnf0jkhqB/I9ZHGtic+nzES7sUc76+DfqqwSp3U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=D0NBhpSx5bzYQuQ9VGszx6aLYMvQRtDPn6CrLkCFsLEa6E2fiiPtCt6OuA7SIcPi0LryiaT17R6qNO7cwm5g8BTRd9BTfIeqRY8WVjEI1qXrOOdMySKBUEC+nn2N95kYMsS1Bnt0/STjBMRsBMdqeH6brvhFS39nKBa6R0OTO+47tNmPK0Eq2zDq8ax5q4/Chaslu8pOa4PcfwB8IBMexjfKsgllC8d1GSSznLwE6OPu4CWi+XuNo+2cv0G76D/MKsfTVZi+LjNfKT6898hHobdUPX2x8mToJZH2vn2xewmtBPGXsOIdYZb9C3z13dfXu1jB452bllnGvhh8ihS2rA== 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=oyPM1LHY; 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=oyPM1LHY; 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) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4jbTgM6NlYz3bf4 for ; Fri, 27 Nov 2026 21:10:07 +1100 (AEDT) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=g2aQKnf0jkhqB/I9ZHGtic+nzES7sUc76+DfqqwSp3U=; b=oyPM1LHY89iXEB/3m8eV7j/JnAvgIAmIVdOB3B0IFDd3WF/qjOBWoPQKp5QuLXZhR6PVx6H/Y 1dPu66Tj827doYjgQXafxjgCASuqLAY5JFDlN2FcJGp8tMdwFfK/b5JFqj8ZQSX6tXe2R8eYfbV Nn0Eonw/t6FYr3r3mWlR4F4= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4jbTfr6DyczRhXD; Fri, 27 Nov 2026 18:09:40 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id B5B074057D; Fri, 27 Nov 2026 18:10:00 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Fri, 27 Nov 2026 18:09:58 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v9 10/11] arm64: kexec_file: Fix CMA segment placement retries Date: Fri, 27 Nov 2026 18:09:24 +0800 Message-ID: <20261127100925.3019877-11-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261127100925.3019877-1-ruanjinjie@huawei.com> References: <20261127100925.3019877-1-ruanjinjie@huawei.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , Precedence: list X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemk200008.china.huawei.com (7.202.194.74) X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The file-based kexec system call places segments with kexec_add_buffer(), which takes them from CMA when kexec_alloc_contig() succeeds, to avoid copying the payload at kexec time. When load_other_segments() cannot place the initrd or the DTB, the segments of the attempt are dropped but their CMA pages are leaked. Release them with kexec_rollback_segments() in the retry loop and in the error path of load_other_segments(). The loop makes progress by advancing buf_min past a segment placed by the walk. kexec_alloc_contig() ignores buf_min, so once the pages of a CMA segment are released, the next attempt can get the same region again and the retry makes no progress. Disable CMA for the retry. A CMA segment can be anywhere in RAM, so moving buf_min to its end can raise the walk's lower bound close to the top of memory and leave the retry with too little space for the initrd and DTB, failing with -EADDRNOTAVAIL. Only advance buf_min for segments found by the walk. Tested with a non-crash kexec_file_load() on QEMU virt, 1 GiB RAM and cma=64M, which places CMA at the top of RAM. Before the fix: The retry leaks the CMA pages and kexec_file_load() returns -EADDRNOTAVAIL even though RAM below CMA is free. After the fix: The kernel and initrd are placed below CMA and the second kernel boots. Fixes: 07d24902977e ("kexec: enable CMA based contiguous allocation") Cc: Catalin Marinas Cc: Will Deacon Cc: Breno Leitao Cc: Pratyush Yadav Cc: Andrew Morton Cc: Yeoreum Yun Cc: Baoquan He Cc: stable@vger.kernel.org Signed-off-by: Jinjie Ruan --- arch/arm64/kernel/kexec_image.c | 12 ++++++++---- arch/arm64/kernel/machine_kexec_file.c | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index a2a7c283b331..1cbb3c73c6e9 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -109,11 +109,15 @@ static void *image_load(struct kimage *image, break; /* - * We couldn't find space for the other segments; erase the - * kernel segment and try the next available hole. + * kexec_alloc_contig() ignores buf_min and always returns + * CMA memory, so disable it and keep buf_min. */ - image->nr_segments -= 1; - kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz; + if (image->segment_cma[kernel_segment_number]) + image->no_cma = true; + else + kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz; + + kexec_rollback_segments(image, kernel_segment_number); kbuf.mem = KEXEC_BUF_MEM_UNKNOWN; } diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index dff2cd613f87..169d991488ff 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -132,7 +132,7 @@ int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, return 0; out_err: - image->nr_segments = orig_segments; + kexec_rollback_segments(image, orig_segments); kvfree(dtb); return ret; } -- 2.34.1