From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 0E16B33A037 for ; Fri, 19 Dec 2025 13:20:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766150453; cv=none; b=C1qK0WaIvZZ18zb/lZYZX2gyTKQ38ZZAjJL35E1vT52AGJsKUVfYDT8RlmPYCAjM2NHGwUD/BmrgRPU17I65YBURXsSZHvNlvsmGm4E6v+ML8aGiNEk5R7TaXJqQpH7rZm0zveVjmZIbnggY3cEbwz0TvOgxqA78J5BD0GEYKAA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766150453; c=relaxed/simple; bh=f0sb46hShgEmBn++3KKU6DlH/HUmKOnchsckBopK7AI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DZoVe+Ym5x/HfdRiSMimQC/ODz1aYQWdYVm6fBdHfg4G4fk6xXpgk4XX/REHGz/ue/b/5EmB8WHcczKs3PjKqG2xMpjkknby/mzemmn9Brda4h6dF2dn/79OYX4ld1nws8++myGG3bHagcKYUuf2T5TSVhPBc8KM8SX99o6Z33k= 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=J+igCxaS; arc=none smtp.client-ip=198.175.65.19 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="J+igCxaS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1766150452; x=1797686452; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=f0sb46hShgEmBn++3KKU6DlH/HUmKOnchsckBopK7AI=; b=J+igCxaSDl0UNpjULMHC6L1xt5dK3ap4mXati7eVIWtWxW7MCUZoUwNh nVJ7IsFl5CfXW/mxl2iWnypFgs0v9hPuFmAv9tcLU/25mPc22AkQhxwqf VMiEa8k46Y9lzshrac8Rg+qr+DiiEsQxLoNakCS2QNKUYNtpMkQE+CNDV uT99mer9Qv898i4aj+tJKrug7/6xlt6Q+Uio3l/NkItDTiMdjLoOmAWcC tRBWY1vfHVrD33lLrWps2W1OWnmLvUZc23ZLJYimm04bNT3sYH+SC0Wi/ ZEgoa2KsfifmDD2o8YzmFKbQvT9MIVBWiQD5WkQaEQguWaY6QQxQEJb+u A==; X-CSE-ConnectionGUID: GGvOs42iRQC70sLx5s2L4A== X-CSE-MsgGUID: sj6V8/POQz6pwm01+DFAHA== X-IronPort-AV: E=McAfee;i="6800,10657,11646"; a="68005915" X-IronPort-AV: E=Sophos;i="6.21,161,1763452800"; d="scan'208";a="68005915" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2025 05:20:51 -0800 X-CSE-ConnectionGUID: cgKRPYbxTeqSA8bqcKwKWw== X-CSE-MsgGUID: jlI0wWT2TOeRGNdaDL8Png== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,161,1763452800"; d="scan'208";a="229544196" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by orviesa002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2025 05:20:51 -0800 Date: Fri, 19 Dec 2025 05:27:31 -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 v3] kho: validate preserved memory map during population Message-ID: <20251219132731.GA18378@ranerica-svr.sc.intel.com> References: <20251219071209.3696755-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=us-ascii Content-Disposition: inline In-Reply-To: <20251219071209.3696755-1-pasha.tatashin@soleen.com> User-Agent: Mutt/1.9.4 (2018-02-28) On Fri, Dec 19, 2025 at 02:12:09AM -0500, 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_phys is 0) 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 Neri > Closes: https://lore.kernel.org/all/20251218215613.GA17304@ranerica-svr.sc.intel.com > Signed-off-by: Pasha Tatashin > Reviewed-by: Mike Rapoport (Microsoft) Thanks for the patch (and fixing my e-mail ;)). This fixes the reported issue and now I can kexec reboot correctly with an empty, unfinalized KHO FDT. Tested-by: Ricardo Neri