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 697BEC982D7 for ; Fri, 18 Sep 2026 10:04:25 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4hmSs34LVkz2yps; Fri, 18 Sep 2026 20:04:23 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=113.46.200.217 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1789725863; cv=none; b=mZr+sG+DR4l/Bi/x0m86VddSHqo6+YnD2QMd2FiTAlnsNxy3/HBW/55IR7I8ddzD2gOEenMnbBQBnvOo/i7cD5PeFtnUT3ELtixoBTjxO6seIujJ9wnD5TqFIPhZtmcaDeadPaJmkD0NKolr/oKKzA9OHLpBPpam33k/QSpbZLMeDA1xrfxoL4RZsR47zRkg3Qr9GmaS2RKeSfSdBV2McISVEP6aEB0a5yGdjnkkpduOIUpgmH475qm4kL8FxiNxc+vMEFYD9e3cFNMKWGlvCZJFMwGCvd4HuEmBsqCNQvZ1OSWYdrwav6me+Fu10kbQpdi2RrmpaYh2YZc6SIf3hQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1789725863; c=relaxed/relaxed; bh=gzeLYP4W/HVtauBH6zrP+s/J9Q0YG9Qv0eMgDswYLO0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=StRj55vfWdusJvZqk+flNbOfpN29J7aEBtVKEKW+oQHcLnNvAawa9c/VFtad4OOMkbenuEcDamXsbPbLNusqGmWSCeOGPnmj+wfLOP6PrURnYrMfFjCPrsr2AYNajh7Y6JYfYqSvgLm6M/xMnjBP6a7GYMFeGT67y153dw+DfmacEwXcX3uJuGh1mhomMpR8EoCp7eLqm6cQwczDfTBNZlCxE8Uz+y4klCzB7SR3qKcNjnnlJWY3oC57Zq55PBDQ7dnAu7eff1vnM7yBF+VpMTmbeg061yQNGjC/+CqXJms/UrIf3NGsTNNgYZkYt0CfkTOBW2w63oCEWvAekbtATA== 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=Ez/wOSF7; dkim-atps=neutral; spf=pass (client-ip=113.46.200.217; helo=canpmsgout02.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=Ez/wOSF7; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=huawei.com (client-ip=113.46.200.217; helo=canpmsgout02.his.huawei.com; envelope-from=ruanjinjie@huawei.com; receiver=lists.ozlabs.org) Received: from canpmsgout02.his.huawei.com (canpmsgout02.his.huawei.com [113.46.200.217]) (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 4hmSs04pZtz2xYg for ; Fri, 18 Sep 2026 20:04:19 +1000 (AEST) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=gzeLYP4W/HVtauBH6zrP+s/J9Q0YG9Qv0eMgDswYLO0=; b=Ez/wOSF7kN0QxhLrYOxwsAq0t/qVSH7zO1LO6a7rzHbsnPODXfipqqsojEw0qCoGxc7ny7coD r5CTzt7mwcrfYR0Ns1b2jGOyjEoC1z/DtVergIB5XHUbsALHHtqEUbsn6WEYdxjWUtLytZbUcoZ lEboIM0h4256GoXqxjGf9KM= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4hmSbq5r7Yzcb4D; Fri, 18 Sep 2026 17:52:55 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id E5DD54057D; Fri, 18 Sep 2026 18:04:10 +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, 18 Sep 2026 18:04:09 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 01/17] kexec: Fix CMA segment address translation with non-zero text_offset Date: Fri, 18 Sep 2026 18:04:26 +0800 Message-ID: <20260918100442.3841135-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260918100442.3841135-1-ruanjinjie@huawei.com> References: <20260918100442.3841135-1-ruanjinjie@huawei.com> 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemk200008.china.huawei.com (7.202.194.74) kimage_load_cma_segment() and kimage_map_segment() translate a CMA segment to a kernel virtual address with page_address(cma), ignoring segment->mem. But arm64's image_load() adds text_offset to segment->mem, so the kernel payload is copied to the wrong offset while image->start points past it, and kexec jumps into the middle of the kernel. kimage_map_segment() has the same problem for any CMA segment whose mem was moved. Add kimage_cma_vaddr() to translate a boot physical address inside a CMA segment to its virtual address, and use it in both places. Cc: Andrew Morton Cc: Baoquan He Cc: Mike Rapoport Cc: Pasha Tatashin Cc: Pratyush Yadav Cc: Pingfan Liu Cc: Justinien Bouron Cc: Sourabh Jain Cc: stable@vger.kernel.org Fixes: 07d24902977e ("kexec: enable CMA based contiguous allocation") Signed-off-by: Jinjie Ruan --- kernel/kexec_core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index dc770b9a6d05..7f7cb77f0caa 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -738,11 +738,23 @@ static struct page *kimage_alloc_page(struct kimage *image, return page; } +/* + * Translate a boot physical address inside a CMA segment to a kernel + * virtual address. Architecture loaders may move segment->mem away from + * the CMA base (arm64 adds text_offset), so the offset must be preserved. + */ +static void *kimage_cma_vaddr(struct page *cma, unsigned long mem) +{ + unsigned long cma_base = page_to_boot_pfn(cma) << PAGE_SHIFT; + + return page_address(cma) + (mem - cma_base); +} + static int kimage_load_cma_segment(struct kimage *image, int idx) { struct kexec_segment *segment = &image->segment[idx]; struct page *cma = image->segment_cma[idx]; - char *ptr = page_address(cma); + char *ptr = kimage_cma_vaddr(cma, segment->mem); size_t ubytes, mbytes; int result = 0; unsigned char __user *buf = NULL; @@ -965,7 +977,7 @@ void *kimage_map_segment(struct kimage *image, int idx) cma = image->segment_cma[idx]; if (cma) - return page_address(cma); + return kimage_cma_vaddr(cma, image->segment[idx].mem); addr = image->segment[idx].mem; size = image->segment[idx].memsz; -- 2.34.1