From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yx1-f45.google.com (mail-yx1-f45.google.com [74.125.224.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E7FC2E0B68 for ; Fri, 14 Nov 2025 19:00:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146821; cv=none; b=SQh/MjMe1o8oglI7oklyCeOe+ZFolnoZG4SqhwLOxiB8EKzSuZzAzZSZHDk2K/q4/KQNlO/hFXCvV8OUv4HSb9L5LxaPp2R/8Bxlw5/5zz/7I5jtFrVC5//IEuuoaew1nppiXQlVczvYHPrlYbsSEIenDsE2o9VtQByyt7QyeO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146821; c=relaxed/simple; bh=ZaGz61pYxbvpyxAtP26yZsDF8C71aOsqX2b51O5fW38=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Iiu5apDwZkuDyuNJj49FhFeHz4Eald8MtAgwcSjiP0sWi1Etz4PRWKVWC+O/wEzrvQNQcNfPFre7ay3N6DmMrAJ97pfkJUYQ1xItG3e6Zu44JY0ZeVuUp86XjZ+l+QLxnzK1X64mDF1Z9AhNN4/QEixBxx3JJM+KScFA+M5/xbA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=YGLtRzQC; arc=none smtp.client-ip=74.125.224.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="YGLtRzQC" Received: by mail-yx1-f45.google.com with SMTP id 956f58d0204a3-640d0895d7cso2967232d50.1 for ; Fri, 14 Nov 2025 11:00:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146808; x=1763751608; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=MRhbySqLkOs1S7yd4SZQFQOHiDhSCvUI44/bvvGGGJM=; b=YGLtRzQCctF3Z6q1abWG5X56GKjTPf2w1qtGbGvxrWXK2RNYdUP+3/5Pp+P/IBVp36 Gi4Ly59uR6ApKkHv0suEXw4tCJRzHvYcylPoXF/pqtVaHUGkzkvv5zdFycQOIU08cn3X OHa1EvXCZIXj1JxiWSXGacxiixQFXX3Dpxx/8LbPQDdl3/VJ4IzYIWxkpmybWZRv5RJs +roUIH1ybefDAmbp/o5LLpt+gXKh0Il3mMNy4f9XDddDOc2fnKGTRd/HsGZCrBcVgbz5 0W3pIgmiqZSC9hNbA59ksoRoeB9lX3e/cSEbGFZGIORktjzkyK5rmVNxeGWpBfrRIUZY olAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146808; x=1763751608; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=MRhbySqLkOs1S7yd4SZQFQOHiDhSCvUI44/bvvGGGJM=; b=OSNAosJi2sAhd9wTaD+4GUsFYchAchXU0QBr6IzKqYC30Q7sbfFzPSE+H08vDxnXMo UkMTdhaATFKO+knZXYaWGNh5TUlwmPBPZrRlUqrPx3FQaRD4RlLzqZKmEO1VbTU7m38p e+DezVblH5NWbffQyISF8MRTmPEaZpt92L2EEEPZPkUytgB+Ii4gTTzTFrmS6rqiJHEf CIcG5Auznryf+5qcuXsQzBxgwO6vWUWsy3N1fIUAYoAq7yocFmyxmIf+yWYXhGjosYdZ DXiqMJokWn1Ghk/C3rNFk+r9mg8Jvodadig4xiaV5jIik17PkGg/56kaqEsrziA7mb89 mN7A== X-Forwarded-Encrypted: i=1; AJvYcCUKoiK4/ynY6HMD82CjbB29TZ1BbJvYHrFZjRhcE8CR9CrgHWlfQKr6aDYqeNEpir0xrbC2oSQY4BX1/LU=@vger.kernel.org X-Gm-Message-State: AOJu0Yxjq0SJrfeKeacPQfynNCx5cFFyd4whcmG3x6cC+wIXYihA8Zvu 8E7r8XOfGHdJx5vcvFXLhnhzbx8L4bUfvTgoKyQ7wwCaeVAZ4R2nHItc/p8SahQUXb0= X-Gm-Gg: ASbGncsOtdxuwQTOUsy0qXq0n62kv7eswS32YXrhdXIzNZ1S/SeTqCOHMr3VcsXtQCS AzqhTdaoLHdjWcwspaOD57qOutI7iquy9U7F52Ypdisa0UevkfaXaNUHYlwlIbdINerOj3vIg2l xJIKrI5WHJorDfsGWGn7w9N/RAiLZUGGobG0QJZQMTxua+iRY6i6lLlEWKYDrQBVFa2h5u0tc1/ CUU4X2YxQsmHQn7BGW7wjNFsOYHE+pQBVSTMGHzyUZDAY0kl4odjQVlvxZe3+CZtt4N4Zq81lS7 CjB3Z6cMWHNTgFFISKf0hpZANlN2YKSNgaejNECW4o7QD/rRHvC94thvqyT9QKopBXOmPCyMtz6 s2xVxqkTRIgCKOYi/qISv3sMcLXG4rZ6ilny5aNW9qeVjWEx5YTvrctmeAY2Pe8BsEdUrjUIPmu bFXPieSAXDMdE/J7GFAEkRYrtciooCEDUK9SF8qr0S+qtagWQ7df/re1CvVdTUJHM6pfRgQU4Xa mw8IGY= X-Google-Smtp-Source: AGHT+IFRipa5kdjo6USd5eBEs8ufSqG98/LGRDsWM12ipJewFI9gcyDDCxwJYHschZedkB4cInZt7g== X-Received: by 2002:a53:d013:0:b0:63f:b61a:71fb with SMTP id 956f58d0204a3-641e6d71af4mr3935840d50.3.1763146808367; Fri, 14 Nov 2025 11:00:08 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:07 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 01/13] kho: Fix misleading log message in kho_populate() Date: Fri, 14 Nov 2025 13:59:50 -0500 Message-ID: <20251114190002.3311679-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The log message in kho_populate() currently states "Will skip init for some devices". This implies that Kexec Handover always involves skipping device initialization. However, KHO is a generic mechanism used to preserve kernel memory across reboot for various purposes, such as memfd, telemetry, or reserve_mem. Skipping device initialization is a specific property of live update drivers using KHO, not a property of the mechanism itself. Remove the misleading suffix to accurately reflect the generic nature of KHO discovery. Signed-off-by: Pasha Tatashin Reviewed-by: Pratyush Yadav Reviewed-by: Mike Rapoport (Microsoft) --- kernel/liveupdate/kexec_handover.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 9f0913e101be..6ad45e12f53b 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1470,7 +1470,7 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fd= t_len, kho_in.fdt_phys =3D fdt_phys; kho_in.scratch_phys =3D scratch_phys; kho_scratch_cnt =3D scratch_cnt; - pr_info("found kexec handover data. Will skip init for some devices\n"); + pr_info("found kexec handover data.\n"); =20 out: if (fdt) --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yx1-f53.google.com (mail-yx1-f53.google.com [74.125.224.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CB592D7DD4 for ; Fri, 14 Nov 2025 19:00:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146821; cv=none; b=rvJ0Gkn6uP30ZTf39DpT2DK4civguBEEXDJhjY22H8Jc2zBCJfue7cXxXSGCdWy/WTcA1o5I2roAB33WV7AnG3YT6FWqK/L7sZXbrswAhBxEt51MSp6EtZCT0+G3JGviJ6jO3nmMW1ZDiRwzUbsrgSv8/p14/KufwUnWlA9ZQ20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146821; c=relaxed/simple; bh=Kc6M27pZNkJLL4cazBuaHXleRG5TOOwePfhoBu8mz4Y=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p8O3a5aWJ5UhUjlaiajP9g5PN+tVEemiw5uZ0fDhvpJioqMZNPQ8YWua4LzYpa+6Sox4qFYjACAWwVhj+A16MtDvv13LlkaaEC0fwi6wubDMt2/OV/hPfjtABR/OPm9HL9lXkEag43awybnZgCiONfAiSQuM2tXYXFbBYZmCqlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=ehx5m1Ll; arc=none smtp.client-ip=74.125.224.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="ehx5m1Ll" Received: by mail-yx1-f53.google.com with SMTP id 956f58d0204a3-640d790d444so2124218d50.0 for ; Fri, 14 Nov 2025 11:00:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146809; x=1763751609; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=YXc2jA2YT77trJs8AGCJnVExYUqZkyW6ilvAJCLy6vQ=; b=ehx5m1Ll6IwZ90vx1Oa8UAJ6MTELYeMxaUjSGvQDwP1N+f562fnwxwO504WEg+pxHh FAPTeX8DoyD9DmoWpnHUTBqq1n/11Qc/jdfmJIu1ZQwEHJggcWZ3eyZTZluG1Vz2c9Bh 9RbtIx89rDY7UIT5XInKuzCrIv8cI6pIyvzi39Ftdyg9UjlcmH3oUaBMP7FnP2FqjNHd WHhSqsbDMKVXB1wzEcBD7rThJpbspS9EXkVtEONZ3I5tKsowGo4bPhVxa2qP2PdOoo1O iPyxPGpnXijKrY8iib1omrw1Rle7JoVctynKxCv5R8X652jZSnj641sWZS6V9rbFR5fc ysJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146809; x=1763751609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=YXc2jA2YT77trJs8AGCJnVExYUqZkyW6ilvAJCLy6vQ=; b=ulin6IdAz84vBU3j5ODtb8Fvn3l36A15bBF7yvdYgy9UbUVx1IyotPTPDPGjGcupD+ R/UMucXy5T1dO5nyNdwR3ZkzteyJ3GSd7ZCV9peZvxmDolqLAa+mMAgDeN5XdgUu42Q2 tJ3GpwCeYuNebg6XEMHqgJYxA5eJlJ9DtCjJCoRgk+UDKs1B12bZ+MVF731VxB4bREnc 0D9ua1+aQiV30W6eLSSS7axhzoalAT440D0vJh/xgWPsrLmPQ1KKd4WGth5hCZNJbpTp ifnZOyytaDwYgpZm81fcbXRvcGpvZJLQSUE2QcWwTcfO7DFWpgQqhqu8pWps54DkqGCK Z69w== X-Forwarded-Encrypted: i=1; AJvYcCVYgOTjpYcQiIw0YkbDxjNTaWuHY9B43wQp2qjWnZEObzsVuOJdrWfkADhzLmxbImawfItrOhgjlts4Erg=@vger.kernel.org X-Gm-Message-State: AOJu0YyZs37gXmUKrYfmmmS1sUt4YorxB4rDEvRkNm/rP1EpicOTYY09 dudVBQnd8Wooe+vqFADqW7IbSlM7RwfP06KLqQIqID8pkjyWqmRfBi0znAm05FBH0tM= X-Gm-Gg: ASbGncuLF8eqp2wWW5GIkHzYyBpqou3mJwBxUjA4iCRxmHXW17rkqtXbLNe52nYaxAH /0vlyznD9kwW9wC2vgdEILx45ikF//NxCYS/Kfblx2FUfqfGfmM7joZS6pRhj0ZI8wKqtms009m RDklSs4iP+aLdrke7BdlaYLWflgqRJjXn2ki2mPLrLPFbsUu2TXDrIEa8VGjdkHW8qO4tcSpvHl OBQSOV2eq5aY67BicRUgN1NuwUmkCX7Tna15s/t7j7hawIj4CXwdalIwK6tqr5kZOy70q+ZDedm BD3FhQcSfGKwhMhGKJC+cHgY+pnOIEBo9+PW6xaiGS5QsSYRCHEfbt5PupPy8Fg0yvaWYFogGb7 s8eaFvYZfkn7LieEyIujFP9tABsWyQs+qzwDYa1UVD54baaB2vPBzmtwiSAJPtlW1VGlS+5eaxV kUR0sgQ235jOzVPff76ZzbT+mn4RJ5iXGg3WK/T5OzizDdvKrmxc4LtiuFX3eHmkN5Ek1km2JWF miDP20= X-Google-Smtp-Source: AGHT+IGOGhN9och8baUfhKaHjASGw/VORaspSG14Cq33C7ESIM+RUb/oPIKDQj3zWRv1mHSuuySjxg== X-Received: by 2002:a05:690e:249c:b0:63f:bab4:fdcd with SMTP id 956f58d0204a3-641e76cac43mr2599528d50.48.1763146809421; Fri, 14 Nov 2025 11:00:09 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:08 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 02/13] kho: Convert __kho_abort() to return void Date: Fri, 14 Nov 2025 13:59:51 -0500 Message-ID: <20251114190002.3311679-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The internal helper __kho_abort() always returns 0 and has no failure paths. Its return value is ignored by __kho_finalize and checked needlessly by kho_abort. Change the return type to void to reflect that this function cannot fail, and simplify kho_abort by removing dead error handling code. Signed-off-by: Pasha Tatashin Reviewed-by: Pratyush Yadav Reviewed-by: Mike Rapoport (Microsoft) --- kernel/liveupdate/kexec_handover.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 6ad45e12f53b..bc7f046a1313 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1117,20 +1117,16 @@ void *kho_restore_vmalloc(const struct kho_vmalloc = *preservation) } EXPORT_SYMBOL_GPL(kho_restore_vmalloc); =20 -static int __kho_abort(void) +static void __kho_abort(void) { if (kho_out.preserved_mem_map) { kho_mem_ser_free(kho_out.preserved_mem_map); kho_out.preserved_mem_map =3D NULL; } - - return 0; } =20 int kho_abort(void) { - int ret =3D 0; - if (!kho_enable) return -EOPNOTSUPP; =20 @@ -1138,10 +1134,7 @@ int kho_abort(void) if (!kho_out.finalized) return -ENOENT; =20 - ret =3D __kho_abort(); - if (ret) - return ret; - + __kho_abort(); kho_out.finalized =3D false; =20 kho_debugfs_fdt_remove(&kho_out.dbg, kho_out.fdt); --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yx1-f51.google.com (mail-yx1-f51.google.com [74.125.224.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EFD22D5938 for ; Fri, 14 Nov 2025 19:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146821; cv=none; b=RBYjPjmTtYl4lKeeBYAmSXJdVhnxqmLWj3mpWxkYUVvXZa4nK0UhwtPrqOLzqRnrxnHayx4rDc31YSCU1x1XBWUlDomRjRsKtaahClRcfxa1qoGu2d7sQ7+RAxDaAeGGy30tNjImXP0oOpKP4SDqQaTsL8CTX0wlJxTXIwSUFBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146821; c=relaxed/simple; bh=J7/W6C6ENMusCfv2at49pc4MZ2P1DOOurmGOftGx8uU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vFhuw0zfVXkoqrBS38AXUjhhSTzLE3YXnw9BIoQ76n/nJDHz30rlIv/L/duTdshY93sBi12Pavx0H+HomGzDb6OjRePoopCWjcQHMlsublsRzJ+VXKZtzcbMVqKJxlbdcBL6Tf8Fbh8rKdiK1UveC09vZA9t6vUKjyVXpkLAMiI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=L+xT/JHm; arc=none smtp.client-ip=74.125.224.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="L+xT/JHm" Received: by mail-yx1-f51.google.com with SMTP id 956f58d0204a3-640d8b78608so1811542d50.1 for ; Fri, 14 Nov 2025 11:00:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146810; x=1763751610; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Ihe0loas1LrTsn9bRuxuUBOFUFQUEsXdHcA1ZYhZ3IY=; b=L+xT/JHmJ5PxuVzVQWgadFo5zjYiWeMPpThXNPYS38RZW9QlH+wjlzwF0Ms5dwkqAy coC/4K32CBQWn5ynXyT7T9mq3R9W6blgnt3cY9o+ldwxsDuzhunp+cSFPH09qrSF+u4T k6WNuzGrsBN2Wfg86Efg2mgsIGBSBIMYGtu07oCdBwEbFZgnbCq5jcJDXdCPchfhRB9/ sFrYN5SeaTPsqfjUHdlPrYuO2FIA5zT1R8+vQgw8YE/8oqFDva4agV/J7CwqLyw5PHnB oMe4vyGI4WNjNcu2FaaZWlWIBYAE59vLw64d16oNjQO1EDXUyZdiaejGV4CqjwIhIXnF C9ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146810; x=1763751610; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Ihe0loas1LrTsn9bRuxuUBOFUFQUEsXdHcA1ZYhZ3IY=; b=ftbzuqYjG3REbdY8MjUtBRJBmIlkTXp08NojLsWmCGCbQSQhKC8bEZ8Z8HEhMJqM8E pHII3EE3NSUVZUE3xI/vo8DE3PE1a4WJIhYtf8lFrdoJhUd0tYL8p39eLJqzjsrA6rF8 GixNKQCNQrTAQVGhUNJbrV9AHcWmLUoXJhx7jWyiW9dXHfD4IzHZEZBvzaml8McS4P2r iZ1M14WwIEuZzMCnqAq8tAqr5x7PqZekLzfavM/jlQG1C/omPYACtspabEVYTco2TYBe YmlWPf9cKkTnPgLJKgF3rxD2HHpCoAaam7OGXQFjDj98WG1HBxTxeBASrt5IyizPGFLf TbtA== X-Forwarded-Encrypted: i=1; AJvYcCVGzo+Kj3Gflg0PsSFCo359cjMZAt7bPANhW8Cl7qBo3eXrKwegxE/sWY9Dv/Qdm5aUrCR3yA0QBFuKHPg=@vger.kernel.org X-Gm-Message-State: AOJu0YwUdSWBTHRmDr8vY0xmawi4oetkNVdZnrUrzBMowPI7pqNRpGLG ACLnY7alkLhulaNvSwg/0WMbBccA5z6fOaWpSezysIeZrDK/22VwM0OMbH3A9zb94Ts= X-Gm-Gg: ASbGncvcmpAj31oJvelidoCKhI2q4pdb2vl2GL+QmOmFewsFDry9T0RAQUB/wFLs5PN 7VIAWhO9Ajiowe5C++7sDW944M6XQ3nuYQJFzUDuLkadzv1+EvLELwHm8Ca+D0hayKM+rOYsseS kQncm3EiY5fOLaJcUIkGVOkw8UDngrcDsdaWwoDYgnBqtuHiZHMzbqhqqgLz3hG1sL78kuvkqBB hqLA2LnDAUMI9dz5eLw7aXOnRvEjaWaMbRXvhMEmQyPFDJ2ii9o+lfKFYvJy7TGETNsai8qrVbU RXTcI/gIEuQ1KnE9SVASVdKesD35IFTOmGh3doIah4/BRRUX3mAvAOlBJVLHdQtMY6bQeZ3UOXx 6168X7RWZgZ0Ey9hZgiXTxZBtdMTl2C/wIrkzC5kIWnEVlVNsqKCXTG6eeFwi87PiZUtNTfc8TV q9jbwk0De9XJvtJy55VHzmAKAJuAZ8+9X9nful0Sv/UIHyiEZwwfhpq+6xf6Pd6riW6iMvH492V qsapxw= X-Google-Smtp-Source: AGHT+IHtcsADCaRWmb9vZYl521slB2k1TyP9yi6kP/peGKq0p/n4sbxoK2XQz6YSUfgIDyLwv/pwEw== X-Received: by 2002:a05:690e:23c3:b0:636:563a:6725 with SMTP id 956f58d0204a3-641e7644cefmr2737299d50.49.1763146810418; Fri, 14 Nov 2025 11:00:10 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:10 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 03/13] kho: Introduce high-level memory allocation API Date: Fri, 14 Nov 2025 13:59:52 -0500 Message-ID: <20251114190002.3311679-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, clients of KHO must manually allocate memory (e.g., via alloc_pages), calculate the page order, and explicitly call kho_preserve_folio(). Similarly, cleanup requires separate calls to unpreserve and free the memory. Introduce a high-level API to streamline this common pattern: - kho_alloc_preserve(size): Allocates physically contiguous, zeroed memory and immediately marks it for preservation. - kho_unpreserve_free(ptr): Unpreserves and frees the memory in the current kernel. - kho_restore_free(ptr): Restores the struct page state of preserved memory in the new kernel and immediately frees it to the page allocator. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- include/linux/kexec_handover.h | 22 +++++--- kernel/liveupdate/kexec_handover.c | 87 ++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 7 deletions(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 80ece4232617..38a9487a1a00 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -2,8 +2,9 @@ #ifndef LINUX_KEXEC_HANDOVER_H #define LINUX_KEXEC_HANDOVER_H =20 -#include +#include #include +#include =20 struct kho_scratch { phys_addr_t addr; @@ -48,6 +49,9 @@ int kho_preserve_pages(struct page *page, unsigned int nr= _pages); int kho_unpreserve_pages(struct page *page, unsigned int nr_pages); int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation); int kho_unpreserve_vmalloc(struct kho_vmalloc *preservation); +void *kho_alloc_preserve(size_t size); +void kho_unpreserve_free(void *mem); +void kho_restore_free(void *mem); struct folio *kho_restore_folio(phys_addr_t phys); struct page *kho_restore_pages(phys_addr_t phys, unsigned int nr_pages); void *kho_restore_vmalloc(const struct kho_vmalloc *preservation); @@ -101,6 +105,14 @@ static inline int kho_unpreserve_vmalloc(struct kho_vm= alloc *preservation) return -EOPNOTSUPP; } =20 +void *kho_alloc_preserve(size_t size) +{ + return ERR_PTR(-EOPNOTSUPP); +} + +void kho_unpreserve_free(void *mem) { } +void kho_restore_free(void *mem) { } + static inline struct folio *kho_restore_folio(phys_addr_t phys) { return NULL; @@ -122,18 +134,14 @@ static inline int kho_add_subtree(const char *name, v= oid *fdt) return -EOPNOTSUPP; } =20 -static inline void kho_remove_subtree(void *fdt) -{ -} +static inline void kho_remove_subtree(void *fdt) { } =20 static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys) { return -EOPNOTSUPP; } =20 -static inline void kho_memory_init(void) -{ -} +static inline void kho_memory_init(void) { } =20 static inline void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t scratch_phys, u64 scratch_len) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index bc7f046a1313..5c5c9c46fe92 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -4,6 +4,7 @@ * Copyright (C) 2023 Alexander Graf * Copyright (C) 2025 Microsoft Corporation, Mike Rapoport * Copyright (C) 2025 Google LLC, Changyuan Lyu + * Copyright (C) 2025 Pasha Tatashin */ =20 #define pr_fmt(fmt) "KHO: " fmt @@ -1117,6 +1118,92 @@ void *kho_restore_vmalloc(const struct kho_vmalloc *= preservation) } EXPORT_SYMBOL_GPL(kho_restore_vmalloc); =20 +/** + * kho_alloc_preserve - Allocate, zero, and preserve memory. + * @size: The number of bytes to allocate. + * + * Allocates a physically contiguous block of zeroed pages that is large + * enough to hold @size bytes. The allocated memory is then registered with + * KHO for preservation across a kexec. + * + * Note: The actual allocated size will be rounded up to the nearest + * power-of-two page boundary. + * + * @return A virtual pointer to the allocated and preserved memory on succ= ess, + * or an ERR_PTR() encoded error on failure. + */ +void *kho_alloc_preserve(size_t size) +{ + struct folio *folio; + int order, ret; + + if (!size) + return ERR_PTR(-EINVAL); + + order =3D get_order(size); + if (order > MAX_PAGE_ORDER) + return ERR_PTR(-E2BIG); + + folio =3D folio_alloc(GFP_KERNEL | __GFP_ZERO, order); + if (!folio) + return ERR_PTR(-ENOMEM); + + ret =3D kho_preserve_folio(folio); + if (ret) { + folio_put(folio); + return ERR_PTR(ret); + } + + return folio_address(folio); +} +EXPORT_SYMBOL_GPL(kho_alloc_preserve); + +/** + * kho_unpreserve_free - Unpreserve and free memory. + * @mem: Pointer to the memory allocated by kho_alloc_preserve(). + * + * Unregisters the memory from KHO preservation and frees the underlying + * pages back to the system. This function should be called to clean up + * memory allocated with kho_alloc_preserve(). + */ +void kho_unpreserve_free(void *mem) +{ + struct folio *folio; + + if (!mem) + return; + + folio =3D virt_to_folio(mem); + WARN_ON_ONCE(kho_unpreserve_folio(folio)); + folio_put(folio); +} +EXPORT_SYMBOL_GPL(kho_unpreserve_free); + +/** + * kho_restore_free - Restore and free memory after kexec. + * @mem: Pointer to the memory (in the new kernel's address space) + * that was allocated by the old kernel. + * + * This function is intended to be called in the new kernel (post-kexec) + * to take ownership of and free a memory region that was preserved by the + * old kernel using kho_alloc_preserve(). + * + * It first restores the pages from KHO (using their physical address) + * and then frees the pages back to the new kernel's page allocator. + */ +void kho_restore_free(void *mem) +{ + struct folio *folio; + + if (!mem) + return; + + folio =3D kho_restore_folio(__pa(mem)); + if (!WARN_ON(!folio)) + folio_put(folio); +} +EXPORT_SYMBOL_GPL(kho_restore_free); + static void __kho_abort(void) { if (kho_out.preserved_mem_map) { --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yx1-f52.google.com (mail-yx1-f52.google.com [74.125.224.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B40A2E2EE5 for ; Fri, 14 Nov 2025 19:00:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146822; cv=none; b=u98fxPgEkEiuLryr/DcLbogXNwld8CpQqJUiqjatzM5Gbj6JR9vDV8qNbPu/k8p45plOtpzr42Q7j8h4wazgNsY4Sx5DgfhiUGxEbpEOPSllNN9KiS1VeDX8Xm8nN6GRNcYda7kc+0KFSaAzaZvWrPB7G5Dh2do5mkk10rDUD98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146822; c=relaxed/simple; bh=jew01/robjrCWS+BGWYsoqBT1NvFNHQf5xWWd+N1VXk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fCR8kTBPyyF8fUCvJ+bynjUgCTXfrGxIBUllcxvHIwnkbFQyNqsJwI80iqCdEaY1XMAceCWGq+IiIZi3xTxAG21YPW3M3MDAUus+VCPvYcxyFffL5S6+RVe53MHEFbgrqIw5jKE4YipjIW07GwrpYz/iM5ZiOr7viW4UuXDjwyY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=L1TvAzUT; arc=none smtp.client-ip=74.125.224.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="L1TvAzUT" Received: by mail-yx1-f52.google.com with SMTP id 956f58d0204a3-63fc72db706so2192742d50.2 for ; Fri, 14 Nov 2025 11:00:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146811; x=1763751611; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=u7XVvQovi1B87PI8BOl3fRcDQNVRDW1j8jgntLzdzQ0=; b=L1TvAzUTDrAFPmFrRYfn6j+VkMYHpyFr9UI9BQirSB7Y3wdA/RxxW7aTtmJluNnmtq ySN4J6ORIGKwAPUpKrhPKq9r7Gj9VmSU0t/fDzmQksqCrRy+n7TYAVqnv8rbMT2PWy7Z D0u2jMpv6a6ET1+8gZtUEpON7CYgHARb9pKxt/Phn0B2SgYvl9NFfLZvdJpgUJo2fv/p tu04pz+QaLGZ7P2hGu9msfNKIUcu8fPqzsmk5fADILE/HnfL5BFkLuqXD9NzEWert83k IWTOxLa2juY4GObklJIIJZYf31U9rmmZpscdp3Q/nEjqpth92qnRfHQroEjPSaTutvi5 Z7Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146811; x=1763751611; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=u7XVvQovi1B87PI8BOl3fRcDQNVRDW1j8jgntLzdzQ0=; b=RnrYtTeepQROv5fnYj6U02sNp3C6OL5gLGB0ObmQeQaMQ+ugQnyyEB6X79uEq5KaN4 eSUKcxyd8foawMsQjTRL1WgStzPLcYor0n9QrdV7ODLqdEnwqxY14w96v3GJ5NlutlvA 1/wFgp/NEWHltKnkowGMqMMTWmRxmlgznYQJQzICr/PD37reKYI3DH3rVHKlhboEBfzF JLHDPr/H5T6LczLFTBFuPZRlTR0Iti2SeQiTT46cto5IsE47ZQ+4XmWASZHsxIQ0rq/n mM3i2o1zVEdxFauhGO/qr+M+FDM5dqd2CchGCIO+iE8MyQMAyeFkaJcjiqFtzYyqZT6N F9lQ== X-Forwarded-Encrypted: i=1; AJvYcCVsDbg+/8WgRwVD0aKaRZM45eJsmYwXQlPEuH2oCzmvPPda8dz9si0XeihYuyVdIa5DkluBwM+Lfb7Co94=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8DvjvZsaNei96m49d15TDops+f+8KSLoMgfGuIcM/pidFr7Us /8ZNVI/nDfUf+/tz1EUkVUFN7r3EaS/wPishvEm/NitIYL8rHTMGt6SSRP3o8cIvxbc= X-Gm-Gg: ASbGncvur2vWzKY0A4FtEmm9O/yyFZ/u5ZA+c3Pub+US9LN5Q7D5Uib63xnJr+Zhtu1 ptLjZBszSYhEZJBBJVW5hV68yw/2AfwCo5RRFI2GpRlUu5QY0p/uQIxJG8OZEVuRhygf1CzzapZ Na2KbnzQVzMUIl7LwrT2l6x+e4SBAVbzpt+nHAJpX8eH7lgd7qigI2sgY4eYQRZSJQCVDyVrAfT PKQCJdf4QN6FOMtq2/txyBjvCdJMcex5WoCMWfGpRhgXPZ3hRI6eJG9kvdUMyJBTZWfxLbt3Mm1 LTkr6Pnzmpne6RifKnwGFS5U1LBOvtsr95VvFR6AA8n8gwB6mZ8QXicu150qYgBpYB287XSsPQF 3kpTISwkt4mF7wa/Dxl5xOF/RpB0zhEkM9dZBG9y6GovnZvnI3gLDz4D66MjpdoliHBkHy7vNuJ JJhg2eSNXLhqeb9+jMciI0OE5xMDDUnDp5XqoD2XMTnq+cm3PKjXvhX2gipjIv/JfsdfbEjUwKv p1IiUYH9SOfcXrM0Q== X-Google-Smtp-Source: AGHT+IF0iKCWHE07PgWFg/A1CwFMxmaP8Ueh0K2652mZRWA2JKfJppAhp60Gzd/8KnWhTuvrWjbQjA== X-Received: by 2002:a53:d048:0:10b0:63f:7de1:7acf with SMTP id 956f58d0204a3-641e74e13cemr2926186d50.22.1763146811446; Fri, 14 Nov 2025 11:00:11 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:10 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 04/13] kho: Preserve FDT folio only once during initialization Date: Fri, 14 Nov 2025 13:59:53 -0500 Message-ID: <20251114190002.3311679-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, the FDT folio is preserved inside __kho_finalize(). If the user performs multiple finalize/abort cycles, kho_preserve_folio() is called repeatedly for the same FDT folio. Since the FDT folio is allocated once during kho_init(), it should be marked for preservation at the same time. Move the preservation call to kho_init() to align the preservation state with the object's lifecycle and simplify the finalize path. Also, pre-zero the FDT tree so we do not expose random bits to the user and to the next kernel by using the new kho_alloc_preserve() api. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 5c5c9c46fe92..704e91418214 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1251,10 +1251,6 @@ static int __kho_finalize(void) if (err) goto abort; =20 - err =3D kho_preserve_folio(virt_to_folio(kho_out.fdt)); - if (err) - goto abort; - err =3D kho_mem_serialize(&kho_out); if (err) goto abort; @@ -1384,19 +1380,17 @@ EXPORT_SYMBOL_GPL(kho_retrieve_subtree); =20 static __init int kho_init(void) { - int err =3D 0; const void *fdt =3D kho_get_fdt(); - struct page *fdt_page; + int err =3D 0; =20 if (!kho_enable) return 0; =20 - fdt_page =3D alloc_page(GFP_KERNEL); - if (!fdt_page) { - err =3D -ENOMEM; + kho_out.fdt =3D kho_alloc_preserve(PAGE_SIZE); + if (IS_ERR(kho_out.fdt)) { + err =3D PTR_ERR(kho_out.fdt); goto err_free_scratch; } - kho_out.fdt =3D page_to_virt(fdt_page); =20 err =3D kho_debugfs_init(); if (err) @@ -1424,9 +1418,9 @@ static __init int kho_init(void) return 0; =20 err_free_fdt: - put_page(fdt_page); - kho_out.fdt =3D NULL; + kho_unpreserve_free(kho_out.fdt); err_free_scratch: + kho_out.fdt =3D NULL; for (int i =3D 0; i < kho_scratch_cnt; i++) { void *start =3D __va(kho_scratch[i].addr); void *end =3D start + kho_scratch[i].size; --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yx1-f44.google.com (mail-yx1-f44.google.com [74.125.224.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B84EC2DE1E3 for ; Fri, 14 Nov 2025 19:00:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146821; cv=none; b=fXGV/AnHEXjrcdQDKF03nxZf7v7/Tqs4QmXFg7k6W1mA5OwfZR2HnnPVq5pkBtHM33C4CHy9giM4y5GgxnWFbWcSYhyOZ9dLnv7K1zW9SoVmQ5moh7ydfJK3jcq21SwhL71K39DaHRduIQQLRaA39HH02jbsy5m/P1qyi1+PPdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146821; c=relaxed/simple; bh=o0zvz+ex74fmsOkX2dx3qTlCtxsfWnru4svlJYsefQU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VlBYIFJ4xiZwklFvzJqeOv53NFmrleJqVq3bSnu3miphGQEQEh27SnEttZLezoKtN44+6EVZlqmj8r+mRlWUKI2PQzDcz6Bs+HKZEnzUjrt0UfNEl2Nv2WeO+uw7sSiIcCapq0Srtwuaqqlc+miuWW1eCS8Fb23OFI2PoRCX2vk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=UuaJlWJT; arc=none smtp.client-ip=74.125.224.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="UuaJlWJT" Received: by mail-yx1-f44.google.com with SMTP id 956f58d0204a3-640c9c85255so2494773d50.3 for ; Fri, 14 Nov 2025 11:00:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146813; x=1763751613; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=l2RJjwQybqCNudNEQM/yW3I9X0XoWZDL8m1h5Nt8Pcs=; b=UuaJlWJT/r8dcPB0lZyVSHg/Kdv9czhrJCgMG0+fmSVNYTYHdGC8F24FlKNbSOwPaV 205hGZiSII3d5S+sc8/vS/bOjXCVZjbGVNT/P6SeeXUfNwVCMwBPyMUSZUHUj4f51GQ2 VYhgAez6jBr1q50ahXnISbNZXGCUk37SvGs5T5T4jHMbIBqHRLfu/BsB6fvB40Vhfiup A/q6cKBQ3UQCMIV86TZZpIU3MxtKRCPsVfxJmOSLaQ/Hd5vzsEvA+wVlebrjv4B/AF2m QSntWmfIEad52Q3JeIXtXqeGEmLVDjGkwOqXwvSe9wcEit2rVxViZULYl8BqGV+IvQz2 IHew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146813; x=1763751613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=l2RJjwQybqCNudNEQM/yW3I9X0XoWZDL8m1h5Nt8Pcs=; b=ntHhQcaBW0+KV8MeL6XVwwdSUU4816aQ+3oh5OagBUH93SMF8I9ZraNWKxYS5pfeq3 kjuGCSV0hNHz6y7TnlmL8oRLmuw2vg08IfEfZoo3paQQg0Ubw87ALmiIP0HiYP/N0ckQ xSKbPfGduCkiTpsadow2Q/kme0s+WWSUcRCtkVt/tEjZS0vxba65a/ASrW6LubxJKcDU ZUC7DFAtWusWd9G/d5VPmCjTRJdoBsKYz1m743v5PRUl255Zdmx7z8TT3P1bzSOuSeVk gu8gGs89DkSEx67pb2pEOlssop2PVyzCaxWHWFuC9qa3IhtdcdC0K0hkXuSeK7rt5jp8 qalw== X-Forwarded-Encrypted: i=1; AJvYcCX3Y4bHIa5A8QDpMAZGmAKsrbzGhU98fLNeIHId9xSuJBPnSxrNUBV02N8I5KI3eFynkobqApzkZUfJdsg=@vger.kernel.org X-Gm-Message-State: AOJu0YzZaCXZSPuPJ79Bw54R0yL8yE9UJ+yEuBfy8u/9iQ9MCETNAvL5 DRGmVbVSAq/yimNkaUONF3mXghG+WxIp5WgqRXjS0Shbrtmukot2uubULduYLGV9ddY= X-Gm-Gg: ASbGncsUVk1jJGS6ihJJeY284OLw1QM4LG+u57fr44s27i+t/LSV+LgZAyBKKErCJrr ZUxZlBxuQ0fFiGvYauj6QmNjf2skzMaxdfKMlMxQD7HFDxYrPFS/79rH7xH0bNCzu78jq62OyXB j49vFmTgtrFFQsoZqZKDHLGm2wIF64VxYFWHllvlKRTr2bgGNBWgo5vS4pnBcC6YOR3ORF/c1Lh Si9DqabKAORAUyV4/LGveBrzG9owhwAdM82s5JU5hwEDf3p7nGMygALbc4jaGJbf92ezkC0Jgme 1c1NKQCPFKIbFVmDhu0baDmk4bV3Ak59FbbH6QGb6N930qywYdOoy0BZyJMQ5QSgcfU4JDB8WAO TIZs48E2h/KJeMuT4BtSkzeY16zonD92kM2iI45BcBoOosE63kwdzLqXSeE2fVqL5w61BVETDhR vpiM4Qs+V+hhfj8NpH/n6txPrtJoKIN7m5F4tOkuzeDIPefJ7dQjxGwfQShDrHdgcilgfJ X-Google-Smtp-Source: AGHT+IELgQoKzNLiqxIk7OfyWTZZMKRkFfp9XFZAkA8ePupq0CHZkUurfOFSw9PuZ2noGq0xfhQIkw== X-Received: by 2002:a05:690e:42cf:b0:63e:1e80:99cb with SMTP id 956f58d0204a3-641e764225dmr2603590d50.34.1763146812573; Fri, 14 Nov 2025 11:00:12 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:12 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 05/13] kho: Verify deserialization status and fix FDT alignment access Date: Fri, 14 Nov 2025 13:59:54 -0500 Message-ID: <20251114190002.3311679-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" During boot, kho_restore_folio() relies on the memory map having been successfully deserialized. If deserialization fails or no map is present, attempting to restore the FDT folio is unsafe. Update kho_mem_deserialize() to return a boolean indicating success. Use this return value in kho_memory_init() to disable KHO if deserialization fails. Also, the incoming FDT folio is never used, there is no reason to restore it. Additionally, use get_unaligned() to retrieve the memory map pointer from the FDT. FDT properties are not guaranteed to be naturally aligned, and accessing a 64-bit value via a pointer that is only 32-bit aligned can cause faults. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover.c | 32 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 704e91418214..bed611bae1df 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -18,6 +18,7 @@ #include #include #include +#include #include =20 #include @@ -451,20 +452,27 @@ static void __init deserialize_bitmap(unsigned int or= der, } } =20 -static void __init kho_mem_deserialize(const void *fdt) +/* Return true if memory was deserizlied */ +static bool __init kho_mem_deserialize(const void *fdt) { struct khoser_mem_chunk *chunk; - const phys_addr_t *mem; + const void *mem_ptr; + u64 mem; int len; =20 - mem =3D fdt_getprop(fdt, 0, PROP_PRESERVED_MEMORY_MAP, &len); - - if (!mem || len !=3D sizeof(*mem)) { + mem_ptr =3D fdt_getprop(fdt, 0, PROP_PRESERVED_MEMORY_MAP, &len); + if (!mem_ptr || len !=3D sizeof(u64)) { pr_err("failed to get preserved memory bitmaps\n"); - return; + return false; } =20 - chunk =3D *mem ? phys_to_virt(*mem) : NULL; + mem =3D get_unaligned((const u64 *)mem_ptr); + chunk =3D mem ? phys_to_virt(mem) : NULL; + + /* No preserved physical pages were passed, no deserialization */ + if (!chunk) + return false; + while (chunk) { unsigned int i; =20 @@ -473,6 +481,8 @@ static void __init kho_mem_deserialize(const void *fdt) &chunk->bitmaps[i]); chunk =3D KHOSER_LOAD_PTR(chunk->hdr.next); } + + return true; } =20 /* @@ -1458,16 +1468,12 @@ static void __init kho_release_scratch(void) =20 void __init kho_memory_init(void) { - struct folio *folio; - if (kho_in.scratch_phys) { kho_scratch =3D phys_to_virt(kho_in.scratch_phys); kho_release_scratch(); =20 - kho_mem_deserialize(kho_get_fdt()); - folio =3D kho_restore_folio(kho_in.fdt_phys); - if (!folio) - pr_warn("failed to restore folio for KHO fdt\n"); + if (!kho_mem_deserialize(kho_get_fdt())) + kho_in.fdt_phys =3D 0; } else { kho_reserve_scratch(); } --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yx1-f42.google.com (mail-yx1-f42.google.com [74.125.224.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD8992E54D7 for ; Fri, 14 Nov 2025 19:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146822; cv=none; b=f9Tz0GPA2PBOdr/EHSIswCcS5+WAotCj519EZKtVHuxy1ChkTz0gzxOG1AeM3DeMGVu9tSag1gosjY9edwMFIvCHrPf7IPLF1Tp6ikZC5FmBIwjpanA3b7JIJ51ufPDRrQ9kvCF/QGvvUovw7OtPqYQMxFh0eStiEc9SOG9xmcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146822; c=relaxed/simple; bh=NFxbJJe1DdmI76qNnaxYOBeXRiOlFHUXXIDINHeFhNE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z+YUkaKBQLH3qp2SGKOPVMzPjY90If4u6KUkacosSrwtFZUBfccJUvDChPZ5wbG0PHMViCi7FPpc4ungEPLkVaYu1rpwTyi2/2KCgWoW1Jf9qJAxTBIdipFNXlyJEbTpm7Qod5e2eAIUW0GRZW+fKEpcJ8GkgRPw2jj8b93AVCc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=OUFe0b5s; arc=none smtp.client-ip=74.125.224.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="OUFe0b5s" Received: by mail-yx1-f42.google.com with SMTP id 956f58d0204a3-640f88b8613so2026060d50.2 for ; Fri, 14 Nov 2025 11:00:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146814; x=1763751614; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=CmV4Tapi6eaC+qTnDSzcGvKGmED+q5xqWekcnxWZ1ms=; b=OUFe0b5sXCjF9mbQWM655dNM/c/nmvagk0tzs9Mf3OKjuEGzw/ZnY3/Bi6AwmrT0dC m5k2sQ/HZ/06EQziKnIXkhjQoWaY4q4d/i432zIjt0gR4rDEt4z+8ze9DgJfuvfrGPj4 10bDTIAbbOXBLcJYEP8uLHYKmPCu1Xez5GSc/Y8orzYIrPxtMZfnvbA+T+fJO9206ZOX VnDch8bibhOUGlXckB2ciWZoESGitSQ33hj8Js9N2I++RmOq/H/M2fHvuQLLcJWa+41D 4PoO0FhlPF+BQEcQz8uZGGi5zimQNu5ikOu52F8sFhQoOP0mjhT0cc1qf+wvnW7bIzsr 2svw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146814; x=1763751614; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=CmV4Tapi6eaC+qTnDSzcGvKGmED+q5xqWekcnxWZ1ms=; b=SHXPGhF+10pPpwKVoWaYpb5zq1+el62mPyiPmLLk9ODaKQc1rySOQjmM89Hu3I0C5V p/e8EZoPlHpn8LdvqqPtxWY9v3aZlz/AmTyttB2SfyxiqdCgGgBlSItAC/7EGVQigooK eZfKEY7QJkr9NSd8QvPHHoAakp/oXqbWeNhcCjANxtuM3e92tEH4KMqtFLEjrAZRpm+c wxAF8Umzi6nntCpSauS08Z6HLUizAjQR9eBbqE98P3K/g0LLqIfRucydsCW/hD3dIXRn PwZVmXd45IaJrpQvy8AUlLeY4bCzSePfe7fGLj+IcrNYeRowuxsr5Q1SkPBR8ua1noA4 TnsQ== X-Forwarded-Encrypted: i=1; AJvYcCURKNGZgqUfD9C+iuL7FjBLWKOaEoLKnetOCQvPp4tLgQ+YKL8AoTe3gtG7U1TQrxkbgni8cmGeAUc7+nc=@vger.kernel.org X-Gm-Message-State: AOJu0YyhNYaBQKnvZ9pvLRxGdZEA+VdaTK4hj1ZyZKbF+i0bSX6qQuRd 4VP7fzf9Cs482OEVKClh7lFbW2XZobP1V9rJBfjJlQt4RDp+kJkEHAql4fqZqPOpxLw= X-Gm-Gg: ASbGncuSEuUTv3uR2nibvlrhfW5L+yGuJjHFRpRXzfeHtmhLK+7hK/6yXWgBoH20H/q RELqJQUbkv6mXb/ztUbsJe/frNRYyGudumAPphNeFh+C1bDZZQLDIYqpkHI7d4v9tqt5rDqxyZn IXgTZUOtUQgvnqUduWQHGlX4G3om1kCTDH6HvGXUVsISLg0Nm0MnlBarWq1FvrFaBXbsQTq1Ltr Cu4tL8WDrWLn9yOQoxA9F+KkQkgBAdVq3xkIPdD9uvU+WSxeMjZ+Rsd6Lp6Fm2CKbenWwyR0gML 6N4haH/EicS/YEwnwYkdHzmii9Qq4z5ETrdjUZ61js6dRvR5/4jeCtk/ws44e0OhTsr+ousrGzF B0CBo4HmbAFjUYdnhap7ob9HeQ77Ooa3GMiYWOFGwCckwmWE9b1aL/GWlZLiM5Le8paYwugZqDH /Ugr6UdToYVBSHMgXJH/s2dy6MWfdn8ZAJYWD5F2f5bLjlmPY+GhoxM6pQwBMXe3tyYRc7 X-Google-Smtp-Source: AGHT+IFAKuuH0ctE7rv8UKB4xSpR2fZv8zxYrTA+ywvPJYYrpw0z8KKJWcD+1hoAuKOrrQSN5X6HsA== X-Received: by 2002:a05:690e:d06:b0:63e:b62:5826 with SMTP id 956f58d0204a3-641e7716e5fmr3272878d50.67.1763146813743; Fri, 14 Nov 2025 11:00:13 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:13 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 06/13] kho: Always expose output FDT in debugfs Date: Fri, 14 Nov 2025 13:59:55 -0500 Message-ID: <20251114190002.3311679-7-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, the output FDT is added to debugfs only when KHO is finalized and removed when aborted. There is no need to hide the FDT based on the state. Always expose it starting from initialization. This aids the transition toward removing the explicit abort functionality and converting KHO to be fully stateless. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index bed611bae1df..3e32c61a64b1 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1234,8 +1234,6 @@ int kho_abort(void) __kho_abort(); kho_out.finalized =3D false; =20 - kho_debugfs_fdt_remove(&kho_out.dbg, kho_out.fdt); - return 0; } =20 @@ -1306,9 +1304,6 @@ int kho_finalize(void) =20 kho_out.finalized =3D true; =20 - WARN_ON_ONCE(kho_debugfs_fdt_add(&kho_out.dbg, "fdt", - kho_out.fdt, true)); - return 0; } =20 @@ -1425,6 +1420,9 @@ static __init int kho_init(void) init_cma_reserved_pageblock(pfn_to_page(pfn)); } =20 + WARN_ON_ONCE(kho_debugfs_fdt_add(&kho_out.dbg, "fdt", + kho_out.fdt, true)); + return 0; =20 err_free_fdt: --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yx1-f43.google.com (mail-yx1-f43.google.com [74.125.224.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBCED2E54A8 for ; Fri, 14 Nov 2025 19:00:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146823; cv=none; b=WZns83MlkwKz8RhPPpHaueyW5fV9eUdnKsnp1fhnjyQ4qF/RIU9/qOtvaL/YedKZJv/VpU9+z6rVdFxNc5Rjqiurt+LvJOX6GDVFtUrEsOMDIhqfq/YW2lyG1uSqZGRXHnkk+fofrYA9hbM5+A0rrtPc5mHkkrxkl0YmUTjSj74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146823; c=relaxed/simple; bh=Fb5b7K2uS6gPwCC40pOss7yb78DkFF8zQx+9l3PR5ug=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MrW0Jg61+aAOBYCj0QFyBa0m6f9WIOeCf/FnCm5K3sVnT2oT5KGRUmWX3xyL6D2tG8g+W1Tp/HQysXRsRCrQ6MkZowehPQ/xbvB8hWPoppUJ7Kl1oZPhxY4Yld7lB2Lu6IJkvImcCRB1d6hMEqdNDvag3ShNNe48mglvlnUCnsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=XM0GeG+A; arc=none smtp.client-ip=74.125.224.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="XM0GeG+A" Received: by mail-yx1-f43.google.com with SMTP id 956f58d0204a3-63f97c4eccaso2329288d50.2 for ; Fri, 14 Nov 2025 11:00:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146815; x=1763751615; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=sKXqn4UCsx5taExigGhwZ/uQl6fonqpp/y9tU9NzApw=; b=XM0GeG+AZ8c8Wx2buRw4LXkJ8ntzIphxTzNJeQm/aH70CsBun5LdyhJRkSfOZWNdT2 JoiKw2ERNxp3WqQ3INWQlUbqp563YGKPkC1jw3ApcLpzpAp9Ifxk17XhjM+YRRQMKrlV A822ZfNyh5vQamxpCm7bpjOeTWAUQuPrQRcnKhTtlbd5KFKHFMHK4VZ9HnZ3KoBmZYh0 Q+2B7jPAGpJ6CO1sEhQK0KYIItrhb1D+R4EY0ig/uUiqk0SRaXE9kGpABzMlR9qeVY3k Y6zcRtBU+ln212mDlG5FRvAZPyJWsVJtJolJDcZig/P6ADm93o4bt+klilAWtqwVOMTQ xVCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146815; x=1763751615; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=sKXqn4UCsx5taExigGhwZ/uQl6fonqpp/y9tU9NzApw=; b=Oq4Jcq348s+PbNMWNBxl0epmkarnNiN5+s6Nj6U2rLmjV7Fsgx1WQ6BcRNck440sSM sLe9q4QMQRMr7ImIhU0+TZHbMNHbYmGK6Pd1sEmnFCWyHd4yvl0CsxQERcTaBhQFO/Oj HzxoasHjwSTv2o59ZHaQSuMj02+4h2vX3qaZIN8FM0E17f3lzn2wK7wo/cXXxE5dSKfh 23mxvFs35A5y2E1Ywfvj+xypoCYBWXNFTcKFb/EaTtPD+vURrpDIiXeq4rjkEvOdi6ic KcosKXDV3hJUxfS9tbtKl/Gn4M+WVNFZV6dgHjqKjuZHRXz2dOHp7nnjznK44hBGVcZc R+kg== X-Forwarded-Encrypted: i=1; AJvYcCUcaOeZwn7gzRmBCrSWo+uFoyr9R/ZmV4b+FDa5gGMhtX7LlMI4WVGzWcT5S7E5nuGAsk1bLOzF8+6oT4Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yybw1wGdcVHaH+mKqLfa30w70yyxqUh0W05lQ6+NmIL6Nz+P7NX bDaTpVIADNFdk9G4a6XdhZb8aDnzo87+E8wlzHrAE8lp0tqHJgoAUTIKcJ3kdWd2S0k= X-Gm-Gg: ASbGncvDHQGgfOJVSVRpoTXDOHqc4kKL+tSaogL/HGagmda3zsv5TxuMgDrxfZ/HWfe 5ga+kGDBnN8iPoyaGyaPIwEpRK6fna1vsY2NtWEKXZqxiVhZbmqP3cG7zcACGR1E9s9tWGBN8t1 QqZ1MyOgS9mt99WI8fFHscmBWZ5qlAXXMAZqdIJ4l0qNRsX6RnGITn3ZHuDs3JdiPI3pOnawlbU pZm0x4SbY87AEOIm+umugslsU7cDJ74IqYFmTqg6SI+bfxDYt6WCY3VfqsRjqc/mySZjKzj4N2I AcyP5i2F4WcP/QAuBT+qxSqTG3oYZVGJLNSjy1veriW38N7Ht7NO9JB+/QT5MH/BvtcoXIRtfgJ ZPMfGshl8+G1UVgCfVTduOKYpsSt3oK6CQXU6pcmyYsSL7idoQ4+1BgNhEL4EVLBCntn+NiWoQB DwpSXrCde1q0vC8zxAJlkoEcQg6/wNqVm8cUMgekm0Li1JbgICg3cPrpNCdFymy6gOKMWr X-Google-Smtp-Source: AGHT+IGombylFpcjG2djxoO/obQ9YcdXjb9GnKr8tqI/Af7HjHJJG+neoAQar3y1uITvPYzUr69PHg== X-Received: by 2002:a05:690e:15d7:b0:641:718:8a08 with SMTP id 956f58d0204a3-641e76834camr2719966d50.52.1763146814781; Fri, 14 Nov 2025 11:00:14 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:14 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 07/13] kho: Simplify serialization and remove __kho_abort Date: Fri, 14 Nov 2025 13:59:56 -0500 Message-ID: <20251114190002.3311679-8-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, __kho_finalize() performs memory serialization in the middle of FDT construction. If FDT construction fails later, the function must manually clean up the serialized memory via __kho_abort(). Refactor __kho_finalize() to perform kho_mem_serialize() only after the FDT has been successfully constructed and finished. This reordering has two benefits: 1. It avoids expensive serialization work if FDT generation fails. 2. It removes the need for cleanup in the FDT error path. As a result, the internal helper __kho_abort() is no longer needed for internal error handling. Inline its remaining logic (cleanup of the preserved memory map) directly into kho_abort() and remove the helper. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover.c | 41 +++++++++++++----------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 3e32c61a64b1..297136054f75 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1214,14 +1214,6 @@ void kho_restore_free(void *mem) } EXPORT_SYMBOL_GPL(kho_restore_free); =20 -static void __kho_abort(void) -{ - if (kho_out.preserved_mem_map) { - kho_mem_ser_free(kho_out.preserved_mem_map); - kho_out.preserved_mem_map =3D NULL; - } -} - int kho_abort(void) { if (!kho_enable) @@ -1231,7 +1223,8 @@ int kho_abort(void) if (!kho_out.finalized) return -ENOENT; =20 - __kho_abort(); + kho_mem_ser_free(kho_out.preserved_mem_map); + kho_out.preserved_mem_map =3D NULL; kho_out.finalized =3D false; =20 return 0; @@ -1239,12 +1232,12 @@ int kho_abort(void) =20 static int __kho_finalize(void) { - int err =3D 0; - u64 *preserved_mem_map; void *root =3D kho_out.fdt; struct kho_sub_fdt *fdt; + u64 *preserved_mem_map; + int err; =20 - err |=3D fdt_create(root, PAGE_SIZE); + err =3D fdt_create(root, PAGE_SIZE); err |=3D fdt_finish_reservemap(root); err |=3D fdt_begin_node(root, ""); err |=3D fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE); @@ -1257,13 +1250,7 @@ static int __kho_finalize(void) sizeof(*preserved_mem_map), (void **)&preserved_mem_map); if (err) - goto abort; - - err =3D kho_mem_serialize(&kho_out); - if (err) - goto abort; - - *preserved_mem_map =3D (u64)virt_to_phys(kho_out.preserved_mem_map); + goto err_exit; =20 mutex_lock(&kho_out.fdts_lock); list_for_each_entry(fdt, &kho_out.sub_fdts, l) { @@ -1277,13 +1264,19 @@ static int __kho_finalize(void) =20 err |=3D fdt_end_node(root); err |=3D fdt_finish(root); + if (err) + goto err_exit; =20 -abort: - if (err) { - pr_err("Failed to convert KHO state tree: %d\n", err); - __kho_abort(); - } + err =3D kho_mem_serialize(&kho_out); + if (err) + goto err_exit; + + *preserved_mem_map =3D (u64)virt_to_phys(kho_out.preserved_mem_map); + + return 0; =20 +err_exit: + pr_err("Failed to convert KHO state tree: %d\n", err); return err; } =20 --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yx1-f47.google.com (mail-yx1-f47.google.com [74.125.224.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE9742DF12B for ; Fri, 14 Nov 2025 19:00:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146822; cv=none; b=GeqmEVgPpaRHOk+evR00Nn1Gs63ycBSYqWexoDqteqokN/qSKr1r0XbGn1rfJkCgSJ8Di0yNJoG/xQuCfv5qYgzfpcd7iX4jmO0xF5AS+Ve5hQKZ7bUjwM6qPVwAZTBXE8V4UkzDmAAp/1qBLJWQVc0jf8WQhGAKCqiY7H4z+Fc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146822; c=relaxed/simple; bh=Uqq2r+qcIbSWV/pQBdQ0mG+2V9Cin/ndNvuaMmJlpQM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f/XN9T8crllsYaq04P+he3SEcTlWY+19tDWNr6u4x96+d/rzuLf82vlAPBcngVo8LlF1e8+9g6f0E0u2BiTbGOqXbL1VtniaTwk1RGRpE47LjYtwn/SA+lB9SIqY27EnmiE8JvElPx8rhVbPJ/UNdgI1E26ySUJkexz0sWf4210= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=Ta42OBpx; arc=none smtp.client-ip=74.125.224.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="Ta42OBpx" Received: by mail-yx1-f47.google.com with SMTP id 956f58d0204a3-640f88b873bso2108048d50.3 for ; Fri, 14 Nov 2025 11:00:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146816; x=1763751616; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=vhwkZEBEr5WhXa61Cp+OEzgGPmuzFUzbgIvGt1K8dx0=; b=Ta42OBpxVamrlGAtLEy3btkKkV13u9DjSV8I70L/LaWXxICw0RkQlhiPas9UKeY4aW 3vR0b6Bbaz66CcBFnxDqUNQalvw8qWhwa9G0T9Vkcara7ZIPf6swp+T890oI1/8I6MyD cf+ox+CniXg9gmRGdU8dcRb0ZhFrWq5lHsA5+Dtwc+Ec7GLTASJn06OlQSDlO4iipwhX zorTO1xPBA6eX+MTEC8SeIMN4jS4uEbeqkmSz5hpGHOJ7R2PlcZxF1g1PvpaP1PmrVHV zy5Lv0AhN2B7AGebpah7krnYwuJyT72ynzyqCDwer4NvrwMBLtRuBqOtQOXcbnmWIx05 +XHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146816; x=1763751616; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=vhwkZEBEr5WhXa61Cp+OEzgGPmuzFUzbgIvGt1K8dx0=; b=iHWylUTAaRGeoRtsTw2YlHJobRU7+6qEr+Ojch+to2NHBAtCd/0PxjAl6uXk/zp7qw hNT263fTvgNVW90JlSWFWpfsfNyB1shs00WLOizZiBkR6cYGiG/SL2z2dZK/Cd604+cb 6NZhQmuEeTgHAYGFtybqvzqc9E9ggN1tWlaaBlVWQIH76u8OPXLxfXb96ZgzLa8O0SwW 0v3wdvgMCJvKX0vBMKx0XNiSZVvzinCjPawQIb4+6acCF5dzUkn61HUujgArwEtPp9PF JAB0B41LxXhodwMznm0Pj3yKhFVRNZuSd56NWwPbhXgkfpY1U/U3RQY5E7yrCtab+gZv 5ziA== X-Forwarded-Encrypted: i=1; AJvYcCVT3oL/7zQaw1C2sAGPoPcD9Y4IPjha2Nn1eIJ3loNrwD7RhM0KHTiCs8rt7bJnALSf1ftSEh1NJJthZjc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy77zKVa8Twpy8JZaVUrAIySLkWFoFgohOvcaVnXTxh4y65KxQt E3AG/uZQmuqz21Heyei0Nnan291GjnVhsYgubh2HpT99Bo+dpGvJkcwvlIKJKz9sPqA741HLOTI 0YN+2 X-Gm-Gg: ASbGncvftDi9WF0HPgTOawXolW7WOWrTPuPD4vAXqnN/oSSMMQPHQg99cMPsHqyBk9j GBeb5zhepX8YLFInY5BD91xClTsD/M7A4hXKsNIMR01oDyicXakAS2FotY0/JfGxTxmYwk3pR/I jr8AhivZtLqtcy0SbV3UdQYjH3BvtA0EyyBuT+yytpgisYeOjvv7vA2/w6wOw+WvY6mk8tC7oWk r5+ci06JbYLhuChiAE5JSM1VNyT0Q+PF0TiRgZnBsnnEEZfkHhFJapAplgulg8Ss7sr84rMKpvc egbThMwhSDAiX3rUyX8VNZJBq+hARJnct7S8ER9ltzOs+fPleiDjKGJ3fDIwF4R29PXBS8Qc/Ot 9GEl46aakQv5yzkUeoGoo4DqUIrq3/QJS6DHebs1QLHj/7nSvOC2WsNTW4x3KGgdcdVEzeBc36y xoVeVZcdOnmjascnPR/fYw2Wy06NaDxj8XDG3yZ3bLvwXjoQu8iHWFBAWB6UwQAYQiNS/mg2oZZ fKhWCg= X-Google-Smtp-Source: AGHT+IHftz04artgctWkQtgZIqMhYzNUfbd5DWlI95J4Cany7ZO/gJCBBXAhqFr39ej1tMVzPCYDjg== X-Received: by 2002:a53:acc3:0:10b0:63f:ba88:e905 with SMTP id 956f58d0204a3-641e757cfa3mr2955979d50.30.1763146815780; Fri, 14 Nov 2025 11:00:15 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:15 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 08/13] kho: Remove global preserved_mem_map and store state in FDT Date: Fri, 14 Nov 2025 13:59:57 -0500 Message-ID: <20251114190002.3311679-9-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, the serialized memory map is tracked via kho_out.preserved_mem_map and copied to the FDT during finalization. This double tracking is redundant. Remove preserved_mem_map from kho_out. Instead, maintain the physical address of the head chunk directly in the preserved-memory-map FDT property. Introduce kho_update_memory_map() to manage this property. This function handles: 1. Retrieving and freeing any existing serialized map (handling the abort/retry case). 2. Updating the FDT property with the new chunk address. This establishes the FDT as the single source of truth for the handover state. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover.c | 43 ++++++++++++++++++------------ 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 297136054f75..63800f63551f 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -119,9 +119,6 @@ struct kho_out { struct mutex fdts_lock; =20 struct kho_mem_track track; - /* First chunk of serialized preserved memory map */ - struct khoser_mem_chunk *preserved_mem_map; - struct kho_debugfs dbg; }; =20 @@ -382,6 +379,27 @@ static void kho_mem_ser_free(struct khoser_mem_chunk *= first_chunk) } } =20 +/* + * Update memory map property, if old one is found discard it via + * kho_mem_ser_free(). + */ +static void kho_update_memory_map(struct khoser_mem_chunk *first_chunk) +{ + void *ptr; + u64 phys; + + ptr =3D fdt_getprop_w(kho_out.fdt, 0, PROP_PRESERVED_MEMORY_MAP, NULL); + + /* Check and discard previous memory map */ + phys =3D get_unaligned((u64 *)ptr); + if (phys) + kho_mem_ser_free((struct khoser_mem_chunk *)phys_to_virt(phys)); + + /* Update with the new value */ + phys =3D first_chunk ? (u64)virt_to_phys(first_chunk) : 0; + put_unaligned(phys, (u64 *)ptr); +} + static int kho_mem_serialize(struct kho_out *kho_out) { struct khoser_mem_chunk *first_chunk =3D NULL; @@ -422,7 +440,7 @@ static int kho_mem_serialize(struct kho_out *kho_out) } } =20 - kho_out->preserved_mem_map =3D first_chunk; + kho_update_memory_map(first_chunk); =20 return 0; =20 @@ -1223,8 +1241,7 @@ int kho_abort(void) if (!kho_out.finalized) return -ENOENT; =20 - kho_mem_ser_free(kho_out.preserved_mem_map); - kho_out.preserved_mem_map =3D NULL; + kho_update_memory_map(NULL); kho_out.finalized =3D false; =20 return 0; @@ -1234,21 +1251,15 @@ static int __kho_finalize(void) { void *root =3D kho_out.fdt; struct kho_sub_fdt *fdt; - u64 *preserved_mem_map; + u64 empty_mem_map =3D 0; int err; =20 err =3D fdt_create(root, PAGE_SIZE); err |=3D fdt_finish_reservemap(root); err |=3D fdt_begin_node(root, ""); err |=3D fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE); - /** - * Reserve the preserved-memory-map property in the root FDT, so - * that all property definitions will precede subnodes created by - * KHO callers. - */ - err |=3D fdt_property_placeholder(root, PROP_PRESERVED_MEMORY_MAP, - sizeof(*preserved_mem_map), - (void **)&preserved_mem_map); + err |=3D fdt_property(root, PROP_PRESERVED_MEMORY_MAP, &empty_mem_map, + sizeof(empty_mem_map)); if (err) goto err_exit; =20 @@ -1271,8 +1282,6 @@ static int __kho_finalize(void) if (err) goto err_exit; =20 - *preserved_mem_map =3D (u64)virt_to_phys(kho_out.preserved_mem_map); - return 0; =20 err_exit: --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yx1-f48.google.com (mail-yx1-f48.google.com [74.125.224.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1A6F2E5B1D for ; Fri, 14 Nov 2025 19:00:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146823; cv=none; b=RTdj0LPeH2V2Ye8YAWW+54hJ4oyv2kB4ppOQ1mNBkLPq14FErGtk/wZ+FThEHrx2UKavcdNcAJynHAZyMea+dNObvsMKmASKomLp2dJS+CRjz+Is0R6tnK9oszUKZBsIptZHvHRPA/1TJg9nCnWVmn7B0PDZmf8tD+qVGJ4/wvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146823; c=relaxed/simple; bh=nSAwfY2J0FrlXoH20NASZ16MFoernp4Ig+8UIlCo4YU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b5NKY4BT6CwMyVjVT9obRmJ1Ro7j+mvhf/h4fLFMZyYsUkadzm0K9pJGEHoCw/pI0obyXZlIevPlrNoxiDrzaYQR2jM8XetjI6UVG9lnGvOh/sX2XoqzjxDC2AcuEkFkI7bTt8NNcutgSP0Uw7PeHzmBPNkob4qSE88IgARcTpM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=EyBWSQ+V; arc=none smtp.client-ip=74.125.224.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="EyBWSQ+V" Received: by mail-yx1-f48.google.com with SMTP id 956f58d0204a3-640f2c9ccbdso2066601d50.1 for ; Fri, 14 Nov 2025 11:00:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146817; x=1763751617; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=kUeee70aoCoEDH7tpogbMA7MC1e04DJkCX99vV5Wq8c=; b=EyBWSQ+V2RP9Eku/TOEfQmBs9555+M92t1IHme9nBXHafYOxivC6eDATfWZ0zaMNHP BhYBwU4K7NcmyHxmyKKSViYAB1DbecbGAhERBI/4WWPsd/51Lp8FJrHsID2BmpTZ+FWx 1WJU4fZK9La3FML7bxkUGEVDI0M6U9Nz3ByoPHt0SPCxSd9riLWhNAfQW0uUCZvt7nbO B3sV75Y0lcXAF1Jxzpro7bcSzamQBkHg11FVfrvceFLyOz1lHzwYhjM+vwHJ/nWyXmJA 8vmiVafnJTf3o/1VWbtPpd/IgFgMo8WCwA32yz4aePdEydkM/8qCgxdb8O6hjPSbcIh9 d+vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146817; x=1763751617; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=kUeee70aoCoEDH7tpogbMA7MC1e04DJkCX99vV5Wq8c=; b=Tyuyetdj287i2sCfotGU3JZuq3Dwi804Tl6CI3M1f67C61HKww1++LO8AW9QcTNGzu K+4FQZ2h3hGjypJOP9oHuidWhOjfALYS//YOZNpK/sBO3KpB4Vjgsc2NjRHoDmSKhEKD Bx2K39vHqro/Pkuaq1wdGsKxdKpgHta3aO19YOxKqaoLTsGIjWd0E/EUdylQWCSs/pkW 7oDlYw1eM9MmP1t4Tap3uXCZuwBMFBQ53Qi32wyLY8deoJZqfER6EOjOJeraFyg3tnWA uykW3DfvXlXygozQ1BDqMNVjPHrfOUN4yinrrNnYt/3ECDNT2GmYG0/umGJ0gVOBsjsl YAMw== X-Forwarded-Encrypted: i=1; AJvYcCWiIG0EnWz62+I9QfPRTnDcNU/K/y6RjL/gl7S/pUoQeG7z9hUdREN/mRdA4dpy9UWi5cVWqh8VdWOU7a8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7OCJmxer8sNNTlMjVNuig1nPVCVO8KNxOhdjpATMaSQjNdrof S8GkeoXhLUaSULYEe0uiLD1YRhtNSW3jQ+c7IgAN6bUSe0LKbhlY2F0Th67cYqQjPAE= X-Gm-Gg: ASbGncu+0BlQuwbY5UYbUfZMBMJTfaTkraqbDN+rzWV1H5i+IhMsdbtHXGkY2MMOQ47 cr1zk8d2cq1wIcKVEvrWIiP+Zh0V+FV4d4e27zE/8bjfhjH+uDWVa1a2QWL/wnzilTPiYIDigV3 JSF0+Xlf88jFktyYiy5ZD0rq5BvtvGnun1GR5iAAsmaUDit9eJXACa5C3S/UDl0mlYkSK2a40Cd SPSTXg22qZuVwtKKSRQRide7gqQbWxvgBLHzmxQPYWkrN+247OYtxI1SaIl0lTJdfzdSFcuYLN3 8xFEPvNg2UqeEgKDKltDGD7CztOwYoFwXbN60TdJ0wNTf1SPgYadLyw9jYSMq1bWewzB4qTfYzP /o0rVJR3fns3rWMjiCfTNx+wxfLe1H1Dpqeu83iNwpiEtTEmtT7LVJlOAqcE4pvfXwv/CrE86De 4aRlBMSK5cWHc2JGwuM/2J5NjRkK4CJpVW4iuAoKb5MqeLO+wCM/4FgdRb6lNojIJ1ESC7z5GvS ocegJI= X-Google-Smtp-Source: AGHT+IEDAZBpiF1oFEsVLGFJo+UdrqqTZLyy4yADm49I+si1ealVeGbZmEoKhxOu20FcmsBgPYr9rw== X-Received: by 2002:a53:b10f:0:b0:63f:9c11:cfed with SMTP id 956f58d0204a3-641e76402b0mr2553029d50.32.1763146816706; Fri, 14 Nov 2025 11:00:16 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:16 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 09/13] kho: Remove abort functionality and support state refresh Date: Fri, 14 Nov 2025 13:59:58 -0500 Message-ID: <20251114190002.3311679-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously, KHO required a dedicated kho_abort() function to clean up state before kho_finalize() could be called again. This was necessary to handle complex unwind paths when using notifiers. With the shift to direct memory preservation, the explicit abort step is no longer strictly necessary. Remove kho_abort() and refactor kho_finalize() to handle re-entry. If kho_finalize() is called while KHO is already finalized, it will now automatically clean up the previous memory map and state before generating a new one. This allows the KHO state to be updated/refreshed simply by triggering finalize again. Update debugfs to return -EINVAL if userspace attempts to write 0 to the finalize attribute, as explicit abort is no longer supported. Suggested-by: Mike Rapoport (Microsoft) Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover.c | 21 ++++----------------- kernel/liveupdate/kexec_handover_debugfs.c | 2 +- kernel/liveupdate/kexec_handover_internal.h | 1 - 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 63800f63551f..624fd648d21f 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1232,21 +1232,6 @@ void kho_restore_free(void *mem) } EXPORT_SYMBOL_GPL(kho_restore_free); =20 -int kho_abort(void) -{ - if (!kho_enable) - return -EOPNOTSUPP; - - guard(mutex)(&kho_out.lock); - if (!kho_out.finalized) - return -ENOENT; - - kho_update_memory_map(NULL); - kho_out.finalized =3D false; - - return 0; -} - static int __kho_finalize(void) { void *root =3D kho_out.fdt; @@ -1297,8 +1282,10 @@ int kho_finalize(void) return -EOPNOTSUPP; =20 guard(mutex)(&kho_out.lock); - if (kho_out.finalized) - return -EEXIST; + if (kho_out.finalized) { + kho_update_memory_map(NULL); + kho_out.finalized =3D false; + } =20 ret =3D __kho_finalize(); if (ret) diff --git a/kernel/liveupdate/kexec_handover_debugfs.c b/kernel/liveupdate= /kexec_handover_debugfs.c index ac739d25094d..2abbf62ba942 100644 --- a/kernel/liveupdate/kexec_handover_debugfs.c +++ b/kernel/liveupdate/kexec_handover_debugfs.c @@ -87,7 +87,7 @@ static int kho_out_finalize_set(void *data, u64 val) if (val) return kho_finalize(); else - return kho_abort(); + return -EINVAL; } =20 DEFINE_DEBUGFS_ATTRIBUTE(kho_out_finalize_fops, kho_out_finalize_get, diff --git a/kernel/liveupdate/kexec_handover_internal.h b/kernel/liveupdat= e/kexec_handover_internal.h index 52ed73659fe6..0202c85ad14f 100644 --- a/kernel/liveupdate/kexec_handover_internal.h +++ b/kernel/liveupdate/kexec_handover_internal.h @@ -24,7 +24,6 @@ extern unsigned int kho_scratch_cnt; =20 bool kho_finalized(void); int kho_finalize(void); -int kho_abort(void); =20 #ifdef CONFIG_KEXEC_HANDOVER_DEBUGFS int kho_debugfs_init(void); --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 836A42E1C7A for ; Fri, 14 Nov 2025 19:00:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146823; cv=none; b=hTpDgO58q8bcxGODpR8ReXNjeJO+4Du2ijEH+OOzgCMZ08n4BOfzF+MK0ipO/dtMo/5S2PDiJnVJm0QLC/HP1XRGElrPPvfWpsCl+iIXUSzaxJNPa0uxykV+Drf0aOv4IttAwXTDxlpDb79hJqQCojD8DTxmb2lgFPtu7CCW18I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146823; c=relaxed/simple; bh=ObPb7rYcD0sksQl5nozqQKKzSdYIbEg6yhfuX2l2xOs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SxBPgzcobj+VwFl4iUS8RXQ7NQRAOtevTlODQVJIZ7AHm8EdT5TKcmC7VEhSE1Y9NOhZ7lvS8zLqpU8sBuIHI5JjJ/dkh/jHJ2xwmqWbir7/ZH98cFMBPiQnElXh8w4/KqEarmpKFwdTIusc/9xHLL4UnkEseP8ULvR+dvjs6Ko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=UBdV/b9f; arc=none smtp.client-ip=209.85.128.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="UBdV/b9f" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-7815092cd0bso23026887b3.2 for ; Fri, 14 Nov 2025 11:00:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146818; x=1763751618; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=7N5yt00Qno1MwWJjfGBPy1ItOdOrLJaGZ6crOfgTrsk=; b=UBdV/b9faXURjHGZAkHEd483Rp6wYfBxLoiE4WGXZLInlTfkBnWjXDmiOiqBaJ+waD 95pFR/hhIymMfrdOEFck0HeBeexAo8ebH7Jy7kF3K2kOMlS4uDCy/GrMRigKWUhm4b5z v6G0S14lzCcj2HwDP5LWf7lyePKNu4qLR0JCNaJvWzyFc8WBb0f+wRtgtGPN1b6CQdKu puZsNS8tZX44PyZscM3Kw0mXSfkX9kh1iVJ3GCeEcSj9SpU8CGvWagTrCD4tYdDtz5yA KlqZIW2w7MZEI7YX1Qec0gJBiADwa5bJHx9dBO3qtibVDcUFB2CoyCyvLJ4KVHjZh8rr JNrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146818; x=1763751618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=7N5yt00Qno1MwWJjfGBPy1ItOdOrLJaGZ6crOfgTrsk=; b=DORlP3VdCcyibEUqVXB6rRjZqaF5A1IJSqFXUUcXHM9/r0OkTist8eMGlLIRtDOu1K YzCjwfHlPupyxZJ1WrkG2DGgh7zXez+mCdQ386j7nTf2Xw1t9b3EgZ4LJooRlczTvg05 igzYpdWjI51w5p+hTm8LUdOgE4YwWDIWiTRqh1uNFuXK/buyhSZhOnIsp6SRf+WrIAKr QRY8ZikyEnBVFhumfk36KpxObM36L/1wFAseQexBX3jZfEsHEFvXsfbzF4vpJSdep4iJ gFog8gOgGCwq+JI347BqkaZt4cWl+YlS47C0TrlB/4RkndAEX9TMYsXLQtAwzHI5cGG1 I+Wg== X-Forwarded-Encrypted: i=1; AJvYcCWNa2+V+LzfVWffgT8qbcucIXXmOk/exgjv+NFBA91ieOgypwH/ZubP4xX8UwcxDfb8rcO1gmCf36EHc8o=@vger.kernel.org X-Gm-Message-State: AOJu0YyDEA7c0WfQNVQM3oDP0SG+dC9QlfzGst+4w2TIP53efta5ThIC 0S0TfEJjCatKBaVZ4xJtPSE5FJoLz54pyitqUSFyaH5dpasQybiKAAE0WIqELlp82Tk= X-Gm-Gg: ASbGncvYCwu31ADY6EG9JvKgiqo317FRmDMFcM3/iX6fFyFWh1V88hSeciUJl655s3c f5rBKAuHkbCNzMt30C07DJRuipvGRZ40XwfrZl3bc41i52BXphtJt73wsCffE9GYUUgNR/+uZhd Lh9neQOZgJtziFE9DNh3tXngZ4/pBcUE30Ctuj5ifsMwWgk3HZpy0pwdKMnifO/hUTBfN1znaLK gSPbeUtJaVcwXkxzsdkP01QZMC/gAlKpc5HbLMw3YsGM2EnLntg+MqdKqsctUb5UDHYpWSM9sJp Zum4bAGFe8h4GKls5Ty0dBxOzo+owcJtharPODgz2Y9GkkDyC4AmuS2esczf/OLFSQWSzsLZh3h mixzH2nARxzfhtGosO6ScM4hoD1rp/peUeorYdI8yfVIm/lYFHkm5O3lioS8T6LPv29infEOQse MnZpFTxwM2ISyzmNogjFsxuyBWgO9UmG55/xnyW3wSr1oCZRsAU5bGcY0HvTKhDpsILUJ6 X-Google-Smtp-Source: AGHT+IEgGDASb7ywJuNlU8tH7U5fvJZheQWqPab57YBnjKIGG/4PXsbTcQgkrxJdQmu9tDmb9/dD3A== X-Received: by 2002:a05:690c:338b:b0:783:6f8d:e7a6 with SMTP id 00721157ae682-78929ef6a1bmr60582517b3.51.1763146817769; Fri, 14 Nov 2025 11:00:17 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:17 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 10/13] kho: Update FDT dynamically for subtree addition/removal Date: Fri, 14 Nov 2025 13:59:59 -0500 Message-ID: <20251114190002.3311679-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, sub-FDTs were tracked in a list (kho_out.sub_fdts) and the final FDT is constructed entirely from scratch during kho_finalize(). We can maintain the FDT dynamically: 1. Initialize a valid, empty FDT in kho_init(). 2. Use fdt_add_subnode and fdt_setprop in kho_add_subtree to update the FDT immediately when a subsystem registers. 3. Use fdt_del_node in kho_remove_subtree to remove entries. This removes the need for the intermediate sub_fdts list and the reconstruction logic in kho_finalize(). kho_finalize() now only needs to trigger memory map serialization. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover.c | 144 ++++++++++++++--------------- 1 file changed, 69 insertions(+), 75 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 624fd648d21f..461d96084c12 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -104,20 +104,11 @@ struct kho_mem_track { =20 struct khoser_mem_chunk; =20 -struct kho_sub_fdt { - struct list_head l; - const char *name; - void *fdt; -}; - struct kho_out { void *fdt; bool finalized; struct mutex lock; /* protects KHO FDT finalization */ =20 - struct list_head sub_fdts; - struct mutex fdts_lock; - struct kho_mem_track track; struct kho_debugfs dbg; }; @@ -127,8 +118,6 @@ static struct kho_out kho_out =3D { .track =3D { .orders =3D XARRAY_INIT(kho_out.track.orders, 0), }, - .sub_fdts =3D LIST_HEAD_INIT(kho_out.sub_fdts), - .fdts_lock =3D __MUTEX_INITIALIZER(kho_out.fdts_lock), .finalized =3D false, }; =20 @@ -725,37 +714,67 @@ static void __init kho_reserve_scratch(void) */ int kho_add_subtree(const char *name, void *fdt) { - struct kho_sub_fdt *sub_fdt; + phys_addr_t phys =3D virt_to_phys(fdt); + void *root_fdt =3D kho_out.fdt; + int err =3D -ENOMEM; + int off, fdt_err; =20 - sub_fdt =3D kmalloc(sizeof(*sub_fdt), GFP_KERNEL); - if (!sub_fdt) - return -ENOMEM; + guard(mutex)(&kho_out.lock); + + fdt_err =3D fdt_open_into(root_fdt, root_fdt, PAGE_SIZE); + if (fdt_err < 0) + return err; =20 - INIT_LIST_HEAD(&sub_fdt->l); - sub_fdt->name =3D name; - sub_fdt->fdt =3D fdt; + off =3D fdt_add_subnode(root_fdt, 0, name); + if (off < 0) { + if (off =3D=3D -FDT_ERR_EXISTS) + err =3D -EEXIST; + goto out_pack; + } + + err =3D fdt_setprop(root_fdt, off, PROP_SUB_FDT, &phys, sizeof(phys)); + if (err < 0) + goto out_pack; =20 - guard(mutex)(&kho_out.fdts_lock); - list_add_tail(&sub_fdt->l, &kho_out.sub_fdts); WARN_ON_ONCE(kho_debugfs_fdt_add(&kho_out.dbg, name, fdt, false)); =20 - return 0; +out_pack: + fdt_pack(root_fdt); + + return err; } EXPORT_SYMBOL_GPL(kho_add_subtree); =20 void kho_remove_subtree(void *fdt) { - struct kho_sub_fdt *sub_fdt; + phys_addr_t target_phys =3D virt_to_phys(fdt); + void *root_fdt =3D kho_out.fdt; + int off; + int err; + + guard(mutex)(&kho_out.lock); + + err =3D fdt_open_into(root_fdt, root_fdt, PAGE_SIZE); + if (err < 0) + return; + + for (off =3D fdt_first_subnode(root_fdt, 0); off >=3D 0; + off =3D fdt_next_subnode(root_fdt, off)) { + const u64 *val; + int len; + + val =3D fdt_getprop(root_fdt, off, PROP_SUB_FDT, &len); + if (!val || len !=3D sizeof(phys_addr_t)) + continue; =20 - guard(mutex)(&kho_out.fdts_lock); - list_for_each_entry(sub_fdt, &kho_out.sub_fdts, l) { - if (sub_fdt->fdt =3D=3D fdt) { - list_del(&sub_fdt->l); - kfree(sub_fdt); + if ((phys_addr_t)*val =3D=3D target_phys) { + fdt_del_node(root_fdt, off); kho_debugfs_fdt_remove(&kho_out.dbg, fdt); break; } } + + fdt_pack(root_fdt); } EXPORT_SYMBOL_GPL(kho_remove_subtree); =20 @@ -1232,48 +1251,6 @@ void kho_restore_free(void *mem) } EXPORT_SYMBOL_GPL(kho_restore_free); =20 -static int __kho_finalize(void) -{ - void *root =3D kho_out.fdt; - struct kho_sub_fdt *fdt; - u64 empty_mem_map =3D 0; - int err; - - err =3D fdt_create(root, PAGE_SIZE); - err |=3D fdt_finish_reservemap(root); - err |=3D fdt_begin_node(root, ""); - err |=3D fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE); - err |=3D fdt_property(root, PROP_PRESERVED_MEMORY_MAP, &empty_mem_map, - sizeof(empty_mem_map)); - if (err) - goto err_exit; - - mutex_lock(&kho_out.fdts_lock); - list_for_each_entry(fdt, &kho_out.sub_fdts, l) { - phys_addr_t phys =3D virt_to_phys(fdt->fdt); - - err |=3D fdt_begin_node(root, fdt->name); - err |=3D fdt_property(root, PROP_SUB_FDT, &phys, sizeof(phys)); - err |=3D fdt_end_node(root); - } - mutex_unlock(&kho_out.fdts_lock); - - err |=3D fdt_end_node(root); - err |=3D fdt_finish(root); - if (err) - goto err_exit; - - err =3D kho_mem_serialize(&kho_out); - if (err) - goto err_exit; - - return 0; - -err_exit: - pr_err("Failed to convert KHO state tree: %d\n", err); - return err; -} - int kho_finalize(void) { int ret; @@ -1282,12 +1259,7 @@ int kho_finalize(void) return -EOPNOTSUPP; =20 guard(mutex)(&kho_out.lock); - if (kho_out.finalized) { - kho_update_memory_map(NULL); - kho_out.finalized =3D false; - } - - ret =3D __kho_finalize(); + ret =3D kho_mem_serialize(&kho_out); if (ret) return ret; =20 @@ -1372,6 +1344,24 @@ int kho_retrieve_subtree(const char *name, phys_addr= _t *phys) } EXPORT_SYMBOL_GPL(kho_retrieve_subtree); =20 +static __init int kho_out_fdt_setup(void) +{ + void *root =3D kho_out.fdt; + u64 empty_mem_map =3D 0; + int err; + + err =3D fdt_create(root, PAGE_SIZE); + err |=3D fdt_finish_reservemap(root); + err |=3D fdt_begin_node(root, ""); + err |=3D fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE); + err |=3D fdt_property(root, PROP_PRESERVED_MEMORY_MAP, &empty_mem_map, + sizeof(empty_mem_map)); + err |=3D fdt_end_node(root); + err |=3D fdt_finish(root); + + return err; +} + static __init int kho_init(void) { const void *fdt =3D kho_get_fdt(); @@ -1394,6 +1384,10 @@ static __init int kho_init(void) if (err) goto err_free_fdt; =20 + err =3D kho_out_fdt_setup(); + if (err) + goto err_free_fdt; + if (fdt) { kho_in_debugfs_init(&kho_in.dbg, fdt); return 0; --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF7942DF158 for ; Fri, 14 Nov 2025 19:00:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146822; cv=none; b=WsvzVrzU4QSU77LmDjWLqzxh/NnnOAltAxaYWcAsR+DlYYEWo5i7wZyPZtB2rLL/KCaoQHM+pH0uA0d8melFvF9CK99J5Y5WWcyboEHz5Wg6J/moUgRnRQciVzVTmR7d3aXnXV3YPQSKgydHpTC73cEjvis2gbyhNxH7ylqFxHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146822; c=relaxed/simple; bh=1HbAJDs1cE8PPm5NxBgENjTLqdxG0YIHQ9mrIeZo39c=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=etnrq8U1wZ743pTmixy7MyJ/AGnarQXYHbsiH8sOd7JQ4xF4j7jCCwESYMEIggIc7OzoheaAppGpk6Ug8tGfVqqm4geVr+lB5VceCJTNBytqyrSDKVSNFALmQcknlOU8QfnjAyj4epzHjaVmTpnad+afQpDGxt1zgRPLPqqMuis= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=jAeo1+Vw; arc=none smtp.client-ip=209.85.128.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="jAeo1+Vw" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-786d1658793so22745717b3.1 for ; Fri, 14 Nov 2025 11:00:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146819; x=1763751619; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=osro0vvPDoUw7oalQJZ+pquNaUniT3EqRQtsUW/shDY=; b=jAeo1+VwWD2QnEATqm6a7eLGGtx/x4fMJp43tGPlAFiqmsbdml5xkuMUK7w4mDRe+8 V50B0Z9BbtmdLXiiUAn3AyHo4L5FzfPjwvd4FLYKUIkzKYrhOWQvR67K97JCQRI52gvY 1Dwcpq7jUl/iB+/6JaBceYILrsVV9rKOOvVhREdlKUk76XFQ3hqD2Gxa4pJk6lfaSVlz tKIAjhCky0vR7txBZu/QKUSZzoh5WEEkL5jkwqzgfekzlgh780NHFCcO5mzkeOycZdVh kVlTeDhihWuQMujWbNteMCgtBn93O9hdAjJ+1NqvTOHsb+QkvLtZEIWD5eKXFohGtY9w Z2kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146819; x=1763751619; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=osro0vvPDoUw7oalQJZ+pquNaUniT3EqRQtsUW/shDY=; b=JiUedv3wjYdIeDn8uuEgytqGPXQ36OC/QBFUlNSzRboQS832I2LCnIKY6f6SP7t4t6 HcuhYHg5+Q+avk1G/nYWDUObTQ5QU+XR4zuW/07FC6T1CHdsVWU9YgxGgLfotKAz0uWW dy6SFfnCZKuaCdnfvvIARWxc6INvJHidGD6RoT3hy793eMkDxrh2cXz4h9wkehA4IQ+H NmGjuQ5XNYrrbLokjgyyYFzivFPHht/KBpoG2QGV6tTisvhLJ5yRZE7fDkNSkVlGYgfH QiCjveAfkcdQk9weanpyTb+Qonfie1ZTgvDcDGHCVVB3OkS9ieqayCBa4QM/Ga1aLx4j 9DJA== X-Forwarded-Encrypted: i=1; AJvYcCWWuvbN+GWjJkurH/bfNHPUKXr+zP/i/PxDTlcsTimdPhZ6lZ7tU1mHd0Evq8oUUYH7YXyblnhcs63Ro4Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yyb+U6At88D9+76HidZCS0cm2UpRh5PbXLJh8F2pA+1osCKzEZM yvzdb+DcNO3BrGuFoI1Mz934DGBAg75J2ZTgaNtx6qEstCUePRHdNkzjUwUzuHik2h8= X-Gm-Gg: ASbGncuPTFIWjTA+4uuoXo3rEgzXcVlRUKRhum0gBn7ISZdIf4nzeDUr09fmdALKojW m0pI3YrBFaM58giMlvTEIL1Ea0hzt0/ysnabiOsLXJy9Yr94lBCVN0u9pgPgKwRxmtiO6beQTcz CW+nDg4Pl/A9oyuj6S+nm3T41XbXPu5eDKtl8LhgNj9FngmwME3pHiXepwYs+H2vuJc7a39QGwc F1Wz3Gk1MngzwzRBAHLM3ido/YOHlrMlVRT5KH4q9CtYL0cPwQAy4fMTAo3vZAbvq9ePJJQMPg6 RUSLUBQe7e8lo55Bp//nVsW52EJZaQzyUJW89YIjdgcIk5Hjf9fXYiRCqsy614bq4/uzIfA0SN0 qPwsDDInI8TEzA5YnvCZ+QkpBDiuahE5PE+8Gga9GPNBwGUMaNb+1yzqoX3i099JYGy4gXVuQob EVk9STOVg/xEi7Zl+St0gEi3BOx8R9DClNIyd1xJcCx0KPimhMt/8NMcZG8yPa3Hdhxy9iQppJJ L1SRRY= X-Google-Smtp-Source: AGHT+IGvr9tG1xjF2akJwFSXf2zHKR6TH3Z9kXWzZ9fYjencDngFKKzCA89Ng2VGtn4u+YBqr0oiew== X-Received: by 2002:a05:690c:a0aa:20b0:781:64f:2b18 with SMTP id 00721157ae682-78929f0ce7fmr58794497b3.58.1763146818865; Fri, 14 Nov 2025 11:00:18 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:18 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 11/13] kho: Allow kexec load before KHO finalization Date: Fri, 14 Nov 2025 14:00:00 -0500 Message-ID: <20251114190002.3311679-12-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, kho_fill_kimage() checks kho_out.finalized and returns early if KHO is not yet finalized. This enforces a strict ordering where userspace must finalize KHO *before* loading the kexec image. This is restrictive, as standard workflows often involve loading the target kernel early in the lifecycle and finalizing the state (FDT) only immediately before the reboot. Since the KHO FDT resides at a physical address allocated during boot (kho_init), its location is stable. We can attach this stable address to the kimage regardless of whether the content has been finalized yet. Relax the check to only require kho_enable, allowing kexec_file_load to proceed at any time. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 461d96084c12..4596e67de832 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1550,7 +1550,7 @@ int kho_fill_kimage(struct kimage *image) int err =3D 0; struct kexec_buf scratch; =20 - if (!kho_out.finalized) + if (!kho_enable) return 0; =20 image->kho.fdt =3D virt_to_phys(kho_out.fdt); --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yx1-f46.google.com (mail-yx1-f46.google.com [74.125.224.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31E522264B1 for ; Fri, 14 Nov 2025 19:00:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146824; cv=none; b=ND7vEUOKAQS0jgR7MeKrle2ip1JRnqKxBj8UUYGHAIbK9c6HdohtIHNvVr5nKK5ZJeR7sVQ7X9A8LVEwz0wDFAUVqmQV1OLWjQJ23+5S8lpN8qes/5qil0EDADFdB60qFyRQONzlX13xCvsnd3CtrP4dqzZu/YbkIOsloq57bf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146824; c=relaxed/simple; bh=0gMlTzMwbX4TYBDiSwohDR9JrsbDYwp4FNBw9J+3Wns=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fMBlhagbSMmMR7NQZHmZa9qe7y9Xv0eUrW+SbH41Lh66+7EmY4NQyx6+bxAXvmjoGzSknT4Fx7vpaqi1kwI9wsYjvsRipv4NeBCZDtuEONKnI5TaLdgoW3NCVP2rzEAz3RhGjSggxHcC16IrjLZjGAnEHgsM4NQYAwp+CTNEIwM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=XDVFKwa2; arc=none smtp.client-ip=74.125.224.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="XDVFKwa2" Received: by mail-yx1-f46.google.com with SMTP id 956f58d0204a3-640c9c85255so2494966d50.3 for ; Fri, 14 Nov 2025 11:00:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146820; x=1763751620; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ffjFNwR3lXfHPjG3OmQVmnhwINj2hMoShbrtcOYEMn4=; b=XDVFKwa29T42b2BJLtBD35q2q9NCYaX4SZk+JV96d9nbvq/Ok5LCTgWr7NvLzPbCHT yfYrBzwVDlvbJffd+v0myUcLsD2f3Ha8PrikOyatFQ2ExrJ3XaVHshwBfN1I4Nxy3KS6 EaU+R11wgcF1miTDwnj07LUO4jfeo+qCNbdZdyQ2y/aJpWv3Cm5uRa5zhhPQ5HFiVps1 lVWnV3v+P+GVAuXk+D35K4fFjkY5fkbwvaRhFyGqFUX7qA7XSJ6z1y6YNkK1IJ8Gcf38 2qHx0hG/fyXSIeI+6QD/caHKdqpoWSAwBRpJEwkzm/Npwodcg2I+V+WwdDJpAUF2b3TZ juSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146820; x=1763751620; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ffjFNwR3lXfHPjG3OmQVmnhwINj2hMoShbrtcOYEMn4=; b=rHZHpTDUkMxM7lXOyDKNiVN+DwSPMun4rIBdyIcuKQr7+kBkFl9ncJgg+HKXFr5tU4 Y6K9b+8rjaOCcY/4hDIZeUFiYLY0bck6HM6echcCMYtxLTXkRHyHRM83vKWXwUa6/zYs L0DP8onwFe/JZrpvDsIYpXlkcMb5PCfO1tzCA9LwXnZVZWHYucTX8sIk5dp6Ki3QPURs DMrlKOaQXA3QQEVmCRTctxf2FGYgovhTjIMT5FiHxXxrJlruja1GcgRcY6paRPsHKoN1 k0EBXJlaMsd9Gq5UmmszN7eYVX8sQ+VjFl7icHlkwtp9AtIWLIAPF+2ED5qtUpfoPccJ 4xIw== X-Forwarded-Encrypted: i=1; AJvYcCWy6qU0Y8BcEkKnZnoJxgp7HCOMLrbDbzINOcIVhRyk2OHJ5o1HrMTwaFLCHA9Pn0O8ILZqcmTEBWN3Ywg=@vger.kernel.org X-Gm-Message-State: AOJu0YzQkcwC3xrpZefv3DbZL+IWXRL27zKRzrFIrtt+B6KLHlrzPfTT 6zquHdFHS0wX9lMo9QD/VVxMy7mw0JPqpo0NyWYUXn32cyeL4mc+zBHeATbf2Zb3eQM= X-Gm-Gg: ASbGncsKdpezWRiU9AALvdkqrp+cSHBUWDmFTQe+g7iiamxBRUQvRbrNB6nY9V5qr2R NKH5aI1goFb9LddMi5fMoDhdWC/fGJH7NlDCtL+4pFHXk/vCfgwc+KeejbaXBfmV+Rv3hpt17LQ 2pe/KbmVYsCnS00o+Bt3ht7fiuSOCNQHGzcy07TMsafqxr91sAGQj5mpUcnnk8+aj4JSECongS7 bdQCgbqIoVEtBh5ZCabqo+37OkNlEVXvpB/rYM544OsIs8lDbWFwRgz/hiOGddvRl5SW0ZZprYi ikaUJixU71hJr+1Y4fUkyaJjNrKCExYAZ5zly8yR16fkH4CPnlGRrbifmTfTCdttnXjWZ2gtIDP 3HWNmzbvcxAGQCGY80DZ4Tn672bbq2qs+B8qENegr01lm6G0uPUB4EbIm6IAKjhGrCS7QU1c42l qQ5TuRPI0YDgtdoEbpqWTiQ1PwhJKeVZcofp/8j1Q+neb1IJKc3U+NrrEnSTvxD/zHgals X-Google-Smtp-Source: AGHT+IHr72sxnwnDW01eveiKOMN8ReuV1UUnXNulAeH1fLWng/AE/xORbhmHjOyCI/0xtighT8mEng== X-Received: by 2002:a05:690e:1546:20b0:640:e5e1:190e with SMTP id 956f58d0204a3-641e769b270mr3139275d50.57.1763146820114; Fri, 14 Nov 2025 11:00:20 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:19 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 12/13] kho: Allow memory preservation state updates after finalization Date: Fri, 14 Nov 2025 14:00:01 -0500 Message-ID: <20251114190002.3311679-13-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, kho_preserve_* and kho_unpreserve_* return -EBUSY if KHO is finalized. This enforces a rigid "freeze" on the KHO memory state. With the introduction of re-entrant finalization, this restriction is no longer necessary. Users should be allowed to modify the preservation set (e.g., adding new pages or freeing old ones) even after an initial finalization. The intended workflow for updates is now: 1. Modify state (preserve/unpreserve). 2. Call kho_finalize() again to refresh the serialized metadata. Remove the kho_out.finalized checks to enable this dynamic behavior. This also allows to convert kho_unpreserve_* functions to void, as they do not return any error anymore. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- include/linux/kexec_handover.h | 21 ++++-------- kernel/liveupdate/kexec_handover.c | 55 +++++++----------------------- 2 files changed, 19 insertions(+), 57 deletions(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 38a9487a1a00..6dd0dcdf0ec1 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -44,11 +44,11 @@ bool kho_is_enabled(void); bool is_kho_boot(void); =20 int kho_preserve_folio(struct folio *folio); -int kho_unpreserve_folio(struct folio *folio); +void kho_unpreserve_folio(struct folio *folio); int kho_preserve_pages(struct page *page, unsigned int nr_pages); -int kho_unpreserve_pages(struct page *page, unsigned int nr_pages); +void kho_unpreserve_pages(struct page *page, unsigned int nr_pages); int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation); -int kho_unpreserve_vmalloc(struct kho_vmalloc *preservation); +void kho_unpreserve_vmalloc(struct kho_vmalloc *preservation); void *kho_alloc_preserve(size_t size); void kho_unpreserve_free(void *mem); void kho_restore_free(void *mem); @@ -79,20 +79,14 @@ static inline int kho_preserve_folio(struct folio *foli= o) return -EOPNOTSUPP; } =20 -static inline int kho_unpreserve_folio(struct folio *folio) -{ - return -EOPNOTSUPP; -} +static inline void kho_unpreserve_folio(struct folio *folio) { } =20 static inline int kho_preserve_pages(struct page *page, unsigned int nr_pa= ges) { return -EOPNOTSUPP; } =20 -static inline int kho_unpreserve_pages(struct page *page, unsigned int nr_= pages) -{ - return -EOPNOTSUPP; -} +static inline void kho_unpreserve_pages(struct page *page, unsigned int nr= _pages) { } =20 static inline int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation) @@ -100,10 +94,7 @@ static inline int kho_preserve_vmalloc(void *ptr, return -EOPNOTSUPP; } =20 -static inline int kho_unpreserve_vmalloc(struct kho_vmalloc *preservation) -{ - return -EOPNOTSUPP; -} +static inline void kho_unpreserve_vmalloc(struct kho_vmalloc *preservation= ) { } =20 void *kho_alloc_preserve(size_t size) { diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 4596e67de832..a7f876ece445 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -185,10 +185,6 @@ static int __kho_preserve_order(struct kho_mem_track *= track, unsigned long pfn, const unsigned long pfn_high =3D pfn >> order; =20 might_sleep(); - - if (kho_out.finalized) - return -EBUSY; - physxa =3D xa_load(&track->orders, order); if (!physxa) { int err; @@ -807,20 +803,14 @@ EXPORT_SYMBOL_GPL(kho_preserve_folio); * Instructs KHO to unpreserve a folio that was preserved by * kho_preserve_folio() before. The provided @folio (pfn and order) * must exactly match a previously preserved folio. - * - * Return: 0 on success, error code on failure */ -int kho_unpreserve_folio(struct folio *folio) +void kho_unpreserve_folio(struct folio *folio) { const unsigned long pfn =3D folio_pfn(folio); const unsigned int order =3D folio_order(folio); struct kho_mem_track *track =3D &kho_out.track; =20 - if (kho_out.finalized) - return -EBUSY; - __kho_unpreserve_order(track, pfn, order); - return 0; } EXPORT_SYMBOL_GPL(kho_unpreserve_folio); =20 @@ -877,21 +867,14 @@ EXPORT_SYMBOL_GPL(kho_preserve_pages); * This must be called with the same @page and @nr_pages as the correspond= ing * kho_preserve_pages() call. Unpreserving arbitrary sub-ranges of larger * preserved blocks is not supported. - * - * Return: 0 on success, error code on failure */ -int kho_unpreserve_pages(struct page *page, unsigned int nr_pages) +void kho_unpreserve_pages(struct page *page, unsigned int nr_pages) { struct kho_mem_track *track =3D &kho_out.track; const unsigned long start_pfn =3D page_to_pfn(page); const unsigned long end_pfn =3D start_pfn + nr_pages; =20 - if (kho_out.finalized) - return -EBUSY; - __kho_unpreserve(track, start_pfn, end_pfn); - - return 0; } EXPORT_SYMBOL_GPL(kho_unpreserve_pages); =20 @@ -976,20 +959,6 @@ static void kho_vmalloc_unpreserve_chunk(struct kho_vm= alloc_chunk *chunk, } } =20 -static void kho_vmalloc_free_chunks(struct kho_vmalloc *kho_vmalloc) -{ - struct kho_vmalloc_chunk *chunk =3D KHOSER_LOAD_PTR(kho_vmalloc->first); - - while (chunk) { - struct kho_vmalloc_chunk *tmp =3D chunk; - - kho_vmalloc_unpreserve_chunk(chunk, kho_vmalloc->order); - - chunk =3D KHOSER_LOAD_PTR(chunk->hdr.next); - free_page((unsigned long)tmp); - } -} - /** * kho_preserve_vmalloc - preserve memory allocated with vmalloc() across = kexec * @ptr: pointer to the area in vmalloc address space @@ -1051,7 +1020,7 @@ int kho_preserve_vmalloc(void *ptr, struct kho_vmallo= c *preservation) return 0; =20 err_free: - kho_vmalloc_free_chunks(preservation); + kho_unpreserve_vmalloc(preservation); return err; } EXPORT_SYMBOL_GPL(kho_preserve_vmalloc); @@ -1062,17 +1031,19 @@ EXPORT_SYMBOL_GPL(kho_preserve_vmalloc); * * Instructs KHO to unpreserve the area in vmalloc address space that was * previously preserved with kho_preserve_vmalloc(). - * - * Return: 0 on success, error code on failure */ -int kho_unpreserve_vmalloc(struct kho_vmalloc *preservation) +void kho_unpreserve_vmalloc(struct kho_vmalloc *preservation) { - if (kho_out.finalized) - return -EBUSY; + struct kho_vmalloc_chunk *chunk =3D KHOSER_LOAD_PTR(preservation->first); =20 - kho_vmalloc_free_chunks(preservation); + while (chunk) { + struct kho_vmalloc_chunk *tmp =3D chunk; =20 - return 0; + kho_vmalloc_unpreserve_chunk(chunk, preservation->order); + + chunk =3D KHOSER_LOAD_PTR(chunk->hdr.next); + free_page((unsigned long)tmp); + } } EXPORT_SYMBOL_GPL(kho_unpreserve_vmalloc); =20 @@ -1221,7 +1192,7 @@ void kho_unpreserve_free(void *mem) return; =20 folio =3D virt_to_folio(mem); - WARN_ON_ONCE(kho_unpreserve_folio(folio)); + kho_unpreserve_folio(folio); folio_put(folio); } EXPORT_SYMBOL_GPL(kho_unpreserve_free); --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Mon Feb 9 02:23:44 2026 Received: from mail-yx1-f52.google.com (mail-yx1-f52.google.com [74.125.224.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A6F92E54A7 for ; Fri, 14 Nov 2025 19:00:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146824; cv=none; b=T81d1omSVUbqAHjup5QL8wPL9GQIo4RCCOoqJyzX2TbTNOwZ+jiPdD8aJWhdV2o527AufdlZPxVZhI0TLoCgG6HBzrZNQxIUh18/L0g/Dc0rDyfrANHhM+MziocxijJXvbxt3M7xKnuiVFmSDAqd30EylIKyRQq47kpvuFTMNfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146824; c=relaxed/simple; bh=QbiPl9slsE7jLJ0ocsqH/+MGnKsobGTfsHQSThyWxlU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gySXbHaK9mFUf8vlT2A/g4W3pPXCks6lBAnw1EEq0caDPvyCyn/JI75y8fDtM6YjtiyJ3O4Q8+IbtbtlQtF0aRVIiV14oij0v/uekRxSuK9mpRg300eC1H2mYp3T5JGb/xMD7DkFcATMvmgN8YHwgBLoXZH+TQcnbEj2HdVvReM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=UEaE10/P; arc=none smtp.client-ip=74.125.224.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="UEaE10/P" Received: by mail-yx1-f52.google.com with SMTP id 956f58d0204a3-640d43060d2so2086399d50.2 for ; Fri, 14 Nov 2025 11:00:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146821; x=1763751621; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=01MmDex2Pd6rSH6pN9DP4qcg9OhX2+hS8KGFIWtKr/Y=; b=UEaE10/Ph5t3HLMTwlGcBlOZE+bHFE3DZT/D3oG0w4ORodYSVKqjYnigIqSb/xavfq +yRMoTNVhZbzDDVbjXrwyNnq9SSRMO4QI5xYWx4EG5xYnFMb4bwbxBPYf/ONxkAgLRp9 vfpjPL/Lwl+/hcqmXp9Pi/YK+mXCDPzfDU8NWdFinupOX6lrGn3MU0o0ZsVPWImKxKo8 kuduKT20WPbX8IhYqHwIWPYE/iHEMT4A34nrFDMz7RJV040guBRmedphl3KpKXKIMw5a hrhjoTAWWGz+Vdry7I0xzPrSAf1C8QjTRsfgNp+PU4NixL62lIG0eWrHUeco3hELRWXl qQYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146821; x=1763751621; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=01MmDex2Pd6rSH6pN9DP4qcg9OhX2+hS8KGFIWtKr/Y=; b=q+bpEA+6Nmk2gplZHu8040v0FZ2AvGBF2NJlInKFEzlKxvxiKNVhfmFouQNkJIXZTX MTI6jbH2m+rK3uU77sNqGn0DVDOQobK6RehFbBADd47kb8fLwgXKGSl3+A0fWjpsNO7a jMReHa/aRDb09BCl8jStmhATBEVG1dNqV19PWBgOUqN980cwEZ6BSjCkbuW8pm2EsGRo Z1ZrWQ0wH1cHDcU7w8LGeE62EFDoX7stgxS7lnBdTW3Yiof3PhBJqLDBkvWRW5uBUEAC hIPaWH9gVctvPkk556P2PHPJT7r9Qf4Hu1zZ3w3HEDU03OBLIGXWh67QW+R8aGOgAhOg C7Tg== X-Forwarded-Encrypted: i=1; AJvYcCVXtt0olNutE1DwITtq5IMTEC4kn27zYR9LUUycc6lSGoUybGQuDR/TIYboS223It61KHfxaos5jo3VWgQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxxGKYJoqF01uvL08v7Re7B4d+Gzw0InP/ep0mllLFiNfPvjZhF pu4GZJwoGVU0CM9oTvPjAERBuuEMqsmICMX8BkKWej0ui1NKcv//HwcMq2HxJEkjg+U= X-Gm-Gg: ASbGncuV7Z4uolLDBGCdIXbJEJ5sXOvOaFFXqYfNR4Qwau8j7v79PX9c5G13n8TIN5i hhIkqMM83xxafRaA02YwJAhV3lWn3sic+spXorp2cbbE3xC3MfHN6LuIfg+Rkj6JQY+VAz9xvsb AB4Zte2opNfRVxXPt6S5zz+xFH5NpVls7DTkUkN4iyOCz9/nyHaVTe6vSlKs3tjzhuo0VEhkHEF cdOr2FF4qYDzcdOWVdzOQAkRYkcwEukPu9YDE1vXS8ZyL6rTINYhGPY9XWNALFph/V8zxqJ2o1k LtNZ4jx+Lz8HtWQuSHxQHd/9x40CzcIelWCcfnnOhsiUInx4+jDfKEzla2JoPuMJCq32ORsZQRF OyGv/8gVMIR7a6V15e9NFdILTC9PradHQTUQEzTXFQ2uZ1V948/stXQf48wD3cGJuy/dJUs00nc rpkwI94ixQMexKymbBAsEdmH0rB0yOgg6HkMBCmxuFR/qrgnnHH8yLtae0Dr5/PIVwtqllgGlq+ 64BTOI= X-Google-Smtp-Source: AGHT+IEh8QcCgJsbND6ZreOs/yM1aLmQLxoU8QELH1/e0TqxBuMxcDBXrCAfWHESdHhM0I5QjIMNCg== X-Received: by 2002:a05:690e:1581:10b0:63f:b366:98e3 with SMTP id 956f58d0204a3-641e75052bdmr3181860d50.23.1763146821080; Fri, 14 Nov 2025 11:00:21 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:20 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 13/13] kho: Add Kconfig option to enable KHO by default Date: Fri, 14 Nov 2025 14:00:02 -0500 Message-ID: <20251114190002.3311679-14-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, Kexec Handover must be explicitly enabled via the kernel command line parameter `kho=3Don`. For workloads that rely on KHO as a foundational requirement (such as the upcoming Live Update Orchestrator), requiring an explicit boot parameter adds redundant configuration steps. Introduce CONFIG_KEXEC_HANDOVER_ENABLE_DEFAULT. When selected, KHO defaults to enabled. This is equivalent to passing kho=3Don at boot. The behavior can still be disabled at runtime by passing kho=3Doff. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/liveupdate/Kconfig | 14 ++++++++++++++ kernel/liveupdate/kexec_handover.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/kernel/liveupdate/Kconfig b/kernel/liveupdate/Kconfig index eae428309332..a973a54447de 100644 --- a/kernel/liveupdate/Kconfig +++ b/kernel/liveupdate/Kconfig @@ -37,4 +37,18 @@ config KEXEC_HANDOVER_DEBUGFS Also, enables inspecting the KHO fdt trees with the debugfs binary blobs. =20 +config KEXEC_HANDOVER_ENABLE_DEFAULT + bool "Enable kexec handover by default" + depends on KEXEC_HANDOVER + help + Enable Kexec Handover by default. This avoids the need to + explicitly pass 'kho=3Don' on the kernel command line. + + This is useful for systems where KHO is a prerequisite for other + features, such as Live Update, ensuring the mechanism is always + active. + + The default behavior can still be overridden at boot time by + passing 'kho=3Doff'. + endmenu diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index a7f876ece445..224bdf5becb6 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -52,7 +52,7 @@ union kho_page_info { =20 static_assert(sizeof(union kho_page_info) =3D=3D sizeof(((struct page *)0)= ->private)); =20 -static bool kho_enable __ro_after_init; +static bool kho_enable __ro_after_init =3D IS_ENABLED(CONFIG_KEXEC_HANDOVE= R_ENABLE_DEFAULT); =20 bool kho_is_enabled(void) { --=20 2.52.0.rc1.455.g30608eb744-goog