From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 AD7734D9917 for ; Thu, 9 Jul 2026 17:38:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783618723; cv=none; b=UeNCPqHHFVkYNgD3VVWV9tjjdgYO2c/5e1DJJ22NWc3XwfIKf3Wrt2h9Pf9c0KMnmkhupprV1e29Ecx+whnLGlrvBjZnMDpOs0Se3SdpRRc62tCgqy4D0FrirAlS50Ig2CnrOvY4XCX9f1MxObDAs29diBhtvLUt22ISc1AZyRA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783618723; c=relaxed/simple; bh=+8S8zPnmbN0x9KLNtv3OWa9iXhYF2/PbeDUZwKX4yI4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bDICnwDzsl1KrWP43HYZAM+kAIMh4QciQxiueq7z2y4o51Yxy9ze+xuunjlM5tbsw64gYUrG4Q8pD1YSw2pqHe6LBawET6liMxQr9OoXcp9BDOjKvhMa5SRBKSWosWH7ldT2DCd5BRFL2FQrRLhFAB3jVJFSpvE0v87WQ/6PPSs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X1Y97Jra; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X1Y97Jra" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FE331F000E9; Thu, 9 Jul 2026 17:38:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783618722; bh=OdR3sfWoKe3cnBBg7L3z1+zE6eZi3SJfP8R+a0w376E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=X1Y97Jrahs8hijJTCASPXnmlJiKUoiDP6LV1Xv047Hm9DwwiT5rhMHZw0xgMpmbWd mc6R2mkHp2mqY5XK9SyoSLjISgCDlUbfLhJ2k8iTlKS1m8nsEv77Hf3fJU+gfqgMwM lL4cXCNbMtg2TkjNaDaDPC/a+3qyDQbJezObq5pMXAyLkFV9UINwK/LYFJhLGuqlnv 39TqSrDFUVgeXfi2jmdkwqAx0VT1CysRe2z2Z/R+fLi1yPSYxE4EviTMvTsjxLppfX 9nhzYy85aBfE1OWke3RQvFWic4FUU47hgiYJ6w6zFjG+Q7bmAFWxI4KOajnLYvIoUJ 4y7mZVXIIHhHw== From: Pratyush Yadav To: Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Alexander Graf , Muchun Song , Oscar Salvador , David Hildenbrand , Andrew Morton , Jason Miu , Jork Loeser Cc: kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 04/21] kho: return virtual address of mem_map Date: Thu, 9 Jul 2026 19:37:53 +0200 Message-ID: <20260709173821.429921-5-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260709173821.429921-1-pratyush@kernel.org> References: <20260709173821.429921-1-pratyush@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pratyush Yadav (Google)" Currently it is only used by kho_populate(), which doesn't care whether the address is virtual or physical and only cares that it exists and is valid. In coming patches, more callers will be added, all of which will need the virtual address. Make things simpler by directly returning the virtual address. Rename kho_get_mem_map_phys() to kho_get_mem_map() to accurately reflect what it returns. Signed-off-by: Pratyush Yadav (Google) --- kernel/liveupdate/kexec_handover.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index e7451743b87e..5c35c11c273b 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -512,19 +512,24 @@ static int __init kho_preserved_memory_reserve(unsigned long key) return 0; } -/* Returns physical address of the preserved memory map from FDT */ -static phys_addr_t __init kho_get_mem_map_phys(const void *fdt) +/* Returns virtual address of the preserved memory map from FDT */ +static __init void *kho_get_mem_map(const void *fdt) { const void *mem_ptr; + phys_addr_t mem_map_phys; int len; mem_ptr = fdt_getprop(fdt, 0, KHO_FDT_MEMORY_MAP_PROP_NAME, &len); if (!mem_ptr || len != sizeof(u64)) { pr_err("failed to get preserved memory map\n"); - return 0; + return NULL; } - return get_unaligned((const u64 *)mem_ptr); + mem_map_phys = get_unaligned((const u64 *)mem_ptr); + if (!mem_map_phys) + return NULL; + + return phys_to_virt(mem_map_phys); } /* @@ -1647,9 +1652,8 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len, { unsigned int scratch_cnt = scratch_len / sizeof(*kho_scratch); struct kho_scratch *scratch = NULL; - phys_addr_t mem_map_phys; - void *fdt = NULL; bool populated = false; + void *fdt = NULL; int err; /* Validate the input FDT */ @@ -1671,8 +1675,13 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len, goto unmap_fdt; } - mem_map_phys = kho_get_mem_map_phys(fdt); - if (!mem_map_phys) + /* + * At this point phys_to_virt() doesn't work properly and so + * kho_get_mem_map() can return a pre-KASLR virtual address. But here we + * only want to make sure the mem_map is valid so the actual value + * doesn't matter as long as it isn't NULL. + */ + if (!kho_get_mem_map(fdt)) goto unmap_fdt; scratch = early_memremap(scratch_phys, scratch_len); -- 2.55.0.141.g00534a21ce-goog