From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 622A4261B9B for ; Fri, 19 Dec 2025 02:27:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766111249; cv=none; b=uztmOi/uCVouXAOcnlypHubL7dHsKmjFNCIUcmxeQ2xr4PuB9IUlw3hddVoxUH4veee7qIsOUYMS1t7iFeB+CEdWc//y8uL+t4NJcm4JaupB+O4c6FCJBUPQFTrx/h5IdmHX4UMQmrJmfrJFUxPM39DvWssRg2dwssD9fVw5Dic= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766111249; c=relaxed/simple; bh=dgyZ1SYYxbkXsRSaMQJDEWAQojccW/3/f0lWLPaWOz4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fUwWJY4tC6EAiWTKP1X7kEM1RmXpitMvGmX4f2YwHFZfvBXHkJxGGcJVZvZ47YzTBz36rXQIAcmfuNUd5XGtt/k3S0Qf9qznaEaTT6I02aPXwhx+Ta2SxrFIKRjUy0X1wVcacPZX0xAdXqPRAhmrRlr8UAw3QdWQ+SXqRBM4KAM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=W0yNMhgj; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="W0yNMhgj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1766111247; x=1797647247; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=dgyZ1SYYxbkXsRSaMQJDEWAQojccW/3/f0lWLPaWOz4=; b=W0yNMhgjmC331zH59uOm9ul/u7sD/1awqUdLdCmDeWYXTd3Du5qDu26x 3BNZVfsHQKETL3TO6PDzmfaML+SofpT/RFZS8NTsCRkl7rJj80wDOarCE YTcK3EnNDzYYuarxZRZ1arUliBDux3qzmcxv2KjQadZFXhxXvECOHUMsh 8uojvT5sQFl/xybiKrAExOOl8n6SJLcngTI/mEVhqlwP3RMZjrrpPBDGy qhtcGvbVIEGC/zMw9CHaOUkLeygI78R9dla27ETLHbiaeGJbumBhJXYnF GGuWfMo5DnAJsAMDMjZHyorZ360f4sqq3E5+cTMNXkW45MXHtRXKwbdEt w==; X-CSE-ConnectionGUID: vjGpC7oTTv++PkxgwV/5hQ== X-CSE-MsgGUID: ycb03wfYSZidBMmrapHxCw== X-IronPort-AV: E=McAfee;i="6800,10657,11646"; a="78390292" X-IronPort-AV: E=Sophos;i="6.21,159,1763452800"; d="scan'208";a="78390292" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2025 18:27:27 -0800 X-CSE-ConnectionGUID: EFGqsiXkQ6KiBY6ZIPhLRA== X-CSE-MsgGUID: JO9Z8eITTyS0SstkhI2Wiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,159,1763452800"; d="scan'208";a="198645971" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by fmviesa006.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2025 18:27:27 -0800 Date: Thu, 18 Dec 2025 18:34:08 -0800 From: Ricardo Neri To: Pasha Tatashin Cc: akpm@linux-foundation.org, rppt@kernel.org, graf@amazon.com, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org, pratyush@kernel.org Subject: Re: [PATCH] kho: validate preserved memory map during population Message-ID: <20251219023408.GA17600@ranerica-svr.sc.intel.com> References: <20251219002355.3323896-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) On Thu, Dec 18, 2025 at 07:49:11PM -0500, Pasha Tatashin wrote: > On Thu, Dec 18, 2025 at 7:23 PM Pasha Tatashin > wrote: > > > > If the previous kernel enabled KHO but did not call kho_finalize() > > (e.g., CONFIG_LIVEUPDATE=n or userspace skipped the finalization step), > > the 'preserved-memory-map' property in the FDT remains empty/zero. > > > > Previously, kho_populate() would succeed regardless of the memory map's > > state, reserving the incoming scratch regions in memblock. However, > > kho_memory_init() would later fail to deserialize the empty map. By that > > time, the scratch regions were already registered, leading to partial > > initialization and subsequent list corruption (double-free) during > > kho_init(). > > > > Move the validation of the preserved memory map earlier into > > kho_populate(). If the memory map is empty/NULL: > > 1. Abort kho_populate() immediately with -ENOENT. > > 2. Do not register or reserve the incoming scratch memory, allowing the new > > kernel to reclaim those pages as standard free memory. > > 3. Leave the global 'kho_in' state uninitialized. > > > > Consequently, kho_memory_init() sees no active KHO context > > (kho_in.mem_chunks is NULL) and falls back to kho_reserve_scratch(), > > allocating fresh scratch memory as if it were a standard cold boot. > > > > Fixes: de51999e687c ("kho: allow memory preservation state updates after finalization") > > Reported-by: Ricardo > > Closes: https://lore.kernel.org/all/20251218215613.GA17304@ranerica-svr.sc.intel.com > > Signed-off-by: Pasha Tatashin > > --- > > kernel/liveupdate/kexec_handover.c | 36 +++++++++++++++++------------- > > 1 file changed, 21 insertions(+), 15 deletions(-) > > > > diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c > > index 9dc51fab604f..96c708f753d4 100644 > > --- a/kernel/liveupdate/kexec_handover.c > > +++ b/kernel/liveupdate/kexec_handover.c > > @@ -460,10 +460,9 @@ static void __init deserialize_bitmap(unsigned int order, > > } > > } > > > > -/* Return true if memory was deserizlied */ > > -static bool __init kho_mem_deserialize(const void *fdt) > > +/* Returns head of preserved physical memory chunks pointer from FDT */ > > +static struct khoser_mem_chunk * __init kho_get_mem_chunks(const void *fdt) > > { > > - struct khoser_mem_chunk *chunk; > > const void *mem_ptr; > > u64 mem; > > int len; > > @@ -471,16 +470,16 @@ static bool __init kho_mem_deserialize(const void *fdt) > > mem_ptr = fdt_getprop(fdt, 0, PROP_PRESERVED_MEMORY_MAP, &len); > > if (!mem_ptr || len != sizeof(u64)) { > > pr_err("failed to get preserved memory bitmaps\n"); > > - return false; > > + return NULL; > > } > > > > mem = get_unaligned((const u64 *)mem_ptr); > > - chunk = mem ? phys_to_virt(mem) : NULL; > > > > - /* No preserved physical pages were passed, no deserialization */ > > - if (!chunk) > > - return false; > > + return mem ? phys_to_virt(mem) : NULL; > > I need to update this patch, phys_to_virt() should not be called from > kho_populate() before KASLR is initialized. This causes a problem with > my live update test. I will send a new version soon. Thanks for the patch Pasha! FWIW, I no longer see the issue I reported. I will test your v2 when posted. BR, Ricardo > > Pasha