From nobody Mon Feb 9 04:27:57 2026 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.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 EBF031A317D for ; Wed, 22 Oct 2025 00:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094645; cv=none; b=SFzj65Ym2nr5HC5YGzsoB9iIh+Ex6NhgTsD3bDuFWO57b8rSMXnF6oL7E2+KknNxWBoBoKfRe4iNWHfTDf9VobNdvgHVXPeUuUxal2YTtcOTS2Cjal7gP90FyJz29pe24fvpgr0JDSQClDs76c3FHmaBA+e9uIgqVpASsltuO5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094645; c=relaxed/simple; bh=ROlC0Rmq6oglp3SIiwWhTf6bfbx9oH9CcVgMhO5a408=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fQBOxkbIGR4/XSfseaCUa8x1Iv0YZ9A/l5t4Bhc+QT2axW87f4NkMgGwwykYGsN+hxgYMu7oDp3maACBhtGggrmHCdwBSRwhZyia0PD3Lpx7D2zuPYZOdotp73yFQKFuTRAjnWjuCzPEsGlRwT76z5NCIBRW34ZqquDi75nxnfo= 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=BGq/vUUi; arc=none smtp.client-ip=209.85.222.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="BGq/vUUi" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-892d1443e48so809214885a.0 for ; Tue, 21 Oct 2025 17:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1761094642; x=1761699442; 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=Nnhz8RmEJ4aJVyp94lmGqv0dP2Oq39IOopI61ahIsMs=; b=BGq/vUUitFqzI+BhMSncBwqtq/Gmj0/LhheeZxjZn8YWHQa258Xgss6Bw7kEckYBu6 N/RkEzSG74aKSoQRXMkr5HOJxwR0+VIpsfN8QfL0jtKwYCUzeWcB3DuzfCJO5kCQbxp7 V125Wrqgfkv9At2zlBe3Wil3gKInkTN6djnvGLfc07CB81fP4w5icAmIVbvGfgUsiTIV VrJFe3MDQvReW0fdzPDML++md8hlnc8gChVhu7PE3CK9/tp2ctSFlLy68DUByqCOz0NB FeV68+JfnRJhiT6orZfC5Bfm6kQ9Tng58gItRQmfuJ7g35jjNkCO0c7JuYUbAzwsFFjf Jkjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761094642; x=1761699442; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nnhz8RmEJ4aJVyp94lmGqv0dP2Oq39IOopI61ahIsMs=; b=FLIyVIgwgUPyEe2K9jpZ9Wzm98bmfPiPl1q5sVEA07s7h5qx8Rin8pWdHdopv9cQuG GZVu8TdGQaXzi5gVRCZJOAsg/yNbtt5G6WIwHkWbKICjpeaHqlnxpque1IoXze8go6Zv cUKplJ0nbvonLJsPuzgEWrV985HSeRZR3UiAgL39qQ1cgDSjEbzz4T5yr2t7FvNwRoXm ZxSaVbP6nY1l26gG06ukdNYtiH8yTQeGr30r3M9KRm62zG6OvZgoFDVE0jwYLmeHE+b2 +gwaqOEvGrvvLz+Q7ZkuxmUVMzFp27O1BzfA5gneYIZ4pI5WunjocKoZhGfrTzS4J4l3 Cj8w== X-Forwarded-Encrypted: i=1; AJvYcCWjNr0SWITaSINPrl7f8lyojHa99Ze9xAm62l/G7qAmpQlGS9A9pF+Gm95F83smWNo+NKjEYJGeV5E8cPA=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9+kVgQ6oh0W2CTpsEKocb/ZSzYMJUifBT+XWenR1nJTc1DgDq XPUnVsu/OsHgTXw/n56f67D/GBNUwEieLKiJcccIa9hUq9/iY8GmGC+m1/aBNeoFid0= X-Gm-Gg: ASbGncu5PZEFdhDe8N7MAhAwmoLLs+tiwT7aU/yNOKq1mW7QjjHDu/IpI/RToTaMmoU SP31WKTW/UUhV+s4ye4pwOOE1G4b43DRcWwBzVyY8NRsaOPRe6Bw5mXGuAW/fzXWgmoj5kTtqI8 Es/V2UoP/xJFqgWe7iqAQ/z4rLdB9lVgQHMAIo/B1ftK60gT915Y4t39zIvrmescCfyDAfOVZ5I IGrXxUpZqBt6vQhdgW/jxH33MPsGKongcLSrHFGTMc/BDoV/3mTF8Kq6GEdA5hjhS9OWpcrrJlp mEYPJcu5vOFHpCRfD8Q2ejYufP5e8gOuH9hQfzJgxebM7fh2VEyp6IlithhQcrdZ32F0zl2XAYU rLbDgPJymY7oLvb8C+GEAaq2mhrdxZ2YuJMgjBP1qoLz2OiaNk3fEzBXPmsL1eShN7wVGQJGGX6 lY95xJj1cl1XZyehWzBn2Oh5dHkSePhvQX98AGn+EOziWPy+pEqXhnDVcLGPIKicdPFlped1omP gPIwjniwTn7pXBAytlAXhdPTWM/CuL1 X-Google-Smtp-Source: AGHT+IEaIzHHvFJMRfSnJtfU36gVB4GsmRc7NSrbXKPCCo1QHLpqLpx5MupgzuVuHjY2hx1vePG7Pw== X-Received: by 2002:a05:620a:3186:b0:877:bc0f:985b with SMTP id af79cd13be357-8906fd1837fmr2516115385a.49.1761094641789; Tue, 21 Oct 2025 17:57:21 -0700 (PDT) Received: from soleen.us-east4-b.c.cloudtop-prod-us-east.internal (53.47.86.34.bc.googleusercontent.com. [34.86.47.53]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4e8aaf3432dsm84169501cf.2.2025.10.21.17.57.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 17:57:21 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, brauner@kernel.org, corbet@lwn.net, graf@amazon.com, jgg@ziepe.ca, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, masahiroy@kernel.org, ojeda@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, rdunlap@infradead.org, rppt@kernel.org, tj@kernel.org Subject: [PATCHv7 1/7] kho: allow to drive kho from within kernel Date: Tue, 21 Oct 2025 20:57:13 -0400 Message-ID: <20251022005719.3670224-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.51.0.915.g61a8936c21-goog In-Reply-To: <20251022005719.3670224-1-pasha.tatashin@soleen.com> References: <20251022005719.3670224-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" Allow kernel to drive finalize and abort without requiring triggers from the userspace. Signed-off-by: Pasha Tatashin Reviewed-by: Pratyush Yadav Reviewed-by: Mike Rapoport (Microsoft) --- include/linux/kexec_handover.h | 15 +++++++ kernel/kexec_handover.c | 75 +++++++++++++++++++++------------- 2 files changed, 61 insertions(+), 29 deletions(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 25042c1d8d54..04d0108db98e 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -67,6 +67,10 @@ void kho_memory_init(void); =20 void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t scratch_p= hys, u64 scratch_len); + +int kho_finalize(void); +int kho_abort(void); + #else static inline bool kho_is_enabled(void) { @@ -139,6 +143,17 @@ static inline void kho_populate(phys_addr_t fdt_phys, = u64 fdt_len, phys_addr_t scratch_phys, u64 scratch_len) { } + +static inline int kho_finalize(void) +{ + return -EOPNOTSUPP; +} + +static inline int kho_abort(void) +{ + return -EOPNOTSUPP; +} + #endif /* CONFIG_KEXEC_HANDOVER */ =20 #endif /* LINUX_KEXEC_HANDOVER_H */ diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index de4466b47455..6458f369a346 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -1087,7 +1087,7 @@ static int kho_out_update_debugfs_fdt(void) return err; } =20 -static int kho_abort(void) +static int __kho_abort(void) { int err; unsigned long order; @@ -1120,7 +1120,27 @@ static int kho_abort(void) return err; } =20 -static int kho_finalize(void) +int kho_abort(void) +{ + int ret =3D 0; + + if (!kho_enable) + return -EOPNOTSUPP; + + guard(mutex)(&kho_out.lock); + if (!kho_out.finalized) + return -ENOENT; + + ret =3D __kho_abort(); + if (ret) + return ret; + + kho_out.finalized =3D false; + + return kho_out_update_debugfs_fdt(); +} + +static int __kho_finalize(void) { int err =3D 0; u64 *preserved_mem_map; @@ -1163,12 +1183,32 @@ static int kho_finalize(void) abort: if (err) { pr_err("Failed to convert KHO state tree: %d\n", err); - kho_abort(); + __kho_abort(); } =20 return err; } =20 +int kho_finalize(void) +{ + int ret; + + if (!kho_enable) + return -EOPNOTSUPP; + + guard(mutex)(&kho_out.lock); + if (kho_out.finalized) + return -EEXIST; + + ret =3D __kho_finalize(); + if (ret) + return ret; + + kho_out.finalized =3D true; + + return kho_out_update_debugfs_fdt(); +} + static int kho_out_finalize_get(void *data, u64 *val) { mutex_lock(&kho_out.lock); @@ -1178,35 +1218,12 @@ static int kho_out_finalize_get(void *data, u64 *va= l) return 0; } =20 -static int kho_out_finalize_set(void *data, u64 _val) +static int kho_out_finalize_set(void *data, u64 val) { - int ret =3D 0; - bool val =3D !!_val; - - mutex_lock(&kho_out.lock); - - if (val =3D=3D kho_out.finalized) { - if (kho_out.finalized) - ret =3D -EEXIST; - else - ret =3D -ENOENT; - goto unlock; - } - if (val) - ret =3D kho_finalize(); + return kho_finalize(); else - ret =3D kho_abort(); - - if (ret) - goto unlock; - - kho_out.finalized =3D val; - ret =3D kho_out_update_debugfs_fdt(); - -unlock: - mutex_unlock(&kho_out.lock); - return ret; + return kho_abort(); } =20 DEFINE_DEBUGFS_ATTRIBUTE(fops_kho_out_finalize, kho_out_finalize_get, --=20 2.51.0.915.g61a8936c21-goog From nobody Mon Feb 9 04:27:57 2026 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (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 539FA1DA0E1 for ; Wed, 22 Oct 2025 00:57:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094648; cv=none; b=D/ZqOTMIn+hN63Lq0L4n2sLF3oGI7NDkdNSlH/wlChXmQhJf21sEJxZnfHl+vMFGyRqf5gfA/k+pUrWU77Cs5hbSgcExs3oiSlbKolSqNQ6KM3g1VqftKjo0AX4OEyjuYWnYZyxP7vrr9jMwJtuBgtewW70uQ4vUD6zXoAYiwxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094648; c=relaxed/simple; bh=8Uj6qYlxOGo/NYhwfNl/6XCLyNNvP+xuNUohlLogCQA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Op37oX3jjqS9OHPa4zTOsd3p7wKqMFCrSMHLOAjmb5mlb+qzUXuRPF6tTsRH51vxvC9EUAHSDF/YfEORANeAN7IVsh2jVJVU+Bh3idJa9oJPCNKZYGWsW+3+QeEP/FmMqlmkFbS96XuM4lVNsbi4ObVm2w4ov9hpH7z5PdmDxeQ= 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=YpKDPakj; arc=none smtp.client-ip=209.85.160.182 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="YpKDPakj" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-4de1b5a6b7fso5518801cf.2 for ; Tue, 21 Oct 2025 17:57:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1761094643; x=1761699443; 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=3htOkkE6tLr9XQMsjRIleWEzhmuFW+NgH8K7EYlNv48=; b=YpKDPakjnrLjT6W7/31tXfSV+bd7VUzHMZFt64tdHJJHOzzIb7LZZuvzFz6Q6IJ9vj xCKUazHMn5oLlqZ5wnB2gIFp9x1lOxlnwFP0Ue/73Uf+q9wgUupzfKU0X7I97J5QLkGv ymp+SNIBzhrFfegP+Df75/vYq5qLsADMG3Jm5BTJVYrLQv4hknNqC5iwh2083zaQ1mX5 JLLNLS8h4oZ03527Scn7x3ghP5qJMId3ye15py7mSt4OHJd1E7FbugC+Nss/hBuclkmk YilT63cBnQWzaUyvx3R7PpO0JX8t/fp7HiwAP0ik3UTE9JTjdQsQfFZ8WE1409St8G2l vQxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761094643; x=1761699443; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3htOkkE6tLr9XQMsjRIleWEzhmuFW+NgH8K7EYlNv48=; b=kGFPu7OVOnEFjfAwwA/yliaFTvxiozYr6CMJe+Vrw5vnrLnAezbQxe3S1IX3Qi5kc9 OAum3/WynSTNdALFRktY8CFEJhzRqTIEUQeySUlYDO/m3Uoa5tjeFHLjuNFtqQCnOWNW D97VjGo21V0HfeGsIFxRutVfq2EDuHoSqjJIQYluzxa/1Ue04bcCdaVEISeDJLjXYnNo Y3NEjIETwjNk/EkQEuxo14v2phcT7NiKp20ns0ysqh10DqHsmEVSFD9Ra/goYhtdZZ4U 1myeRbGk+98bitisbNyn8fRi2KQh8i+M5ABN3rK1vNxushudUz4ot/nHna6TGFIwZb8O kNNA== X-Forwarded-Encrypted: i=1; AJvYcCVeNjuFtDmuz8A9d50oG0ausTCVK5XU7ECO7KsZUbOei1h0OhKToCbjc8c/ojtd9RX9QQXlUwHQ0/KIJJ4=@vger.kernel.org X-Gm-Message-State: AOJu0YzIBM0St9g+BYasL7VXoLKg1uaimGRevdDqWZLPpHcK4iwMJxbK hmq6EouQbsE+soSrLO1PiaNQbGEsJvT8f+QToFWTuH6/ztoC+4RaqHzGnpbedd7i25Y= X-Gm-Gg: ASbGncurcq8zdGVz0fzF+XqAuYJI+DeMqk0mtqXzVR+U6uvycAO77NBDbBQnDKhKh1f ZcSAhS5G8tahdrmePh5b3UwKQHLHvlZZGA7CrKqu0Kn4ZuUg/+Lcnijo33RZpTERtzsd8bs68Rm uAtGfNMo2C2Yp4RvEJcq9s2s04EYNauUFfthJXNtyFkjYSf+uvpOivoUWDUyeRN39y77ZLKHBub y36W3hAhPA8XSgGo/uB0g9HBJRZub/Oq9uWzvcvbTYHRZ5Kddmo7dM7uLStfOkq5R9RHXVNwJIR 7463xvAD0u2WzgmS3tHHunwTUTMJugL+ppRY/rqmCIEwzno/ISgAUSOMs/QNDCx+zt2ZhkeCU2p B9i8lm2D6VWkNU53Ug++E/ld5alNOBI86fY9nIGOcyACkADC9zHnlggPnM97VMP5yuw3Im4r2v6 BE7z/OFzMdMmfQDtZPd8uJ7omKw/KyhUMxLPOjkhyP83lm8CMSL44uIlIlQA9EB4MBJPbr/UeHt N+FVOvkD7rl4YF283wgVA== X-Google-Smtp-Source: AGHT+IE30DjQoURw3OLoSJWPeE8p1b5XiDawhMr+MEwTjm1n0csTxUbQYBHPDC2cv9r8K9sUbtZRnQ== X-Received: by 2002:ac8:59d4:0:b0:4e8:979d:c220 with SMTP id d75a77b69052e-4e89d21c2c3mr241270661cf.13.1761094642919; Tue, 21 Oct 2025 17:57:22 -0700 (PDT) Received: from soleen.us-east4-b.c.cloudtop-prod-us-east.internal (53.47.86.34.bc.googleusercontent.com. [34.86.47.53]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4e8aaf3432dsm84169501cf.2.2025.10.21.17.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 17:57:22 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, brauner@kernel.org, corbet@lwn.net, graf@amazon.com, jgg@ziepe.ca, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, masahiroy@kernel.org, ojeda@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, rdunlap@infradead.org, rppt@kernel.org, tj@kernel.org Subject: [PATCHv7 2/7] kho: make debugfs interface optional Date: Tue, 21 Oct 2025 20:57:14 -0400 Message-ID: <20251022005719.3670224-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.51.0.915.g61a8936c21-goog In-Reply-To: <20251022005719.3670224-1-pasha.tatashin@soleen.com> References: <20251022005719.3670224-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 is controlled via debugfs interface, but once LUO is introduced, it can control KHO, and the debug interface becomes optional. Add a separate config CONFIG_KEXEC_HANDOVER_DEBUGFS that enables the debugfs interface, and allows to inspect the tree. Move all debugfs related code to a new file to keep the .c files clear of ifdefs. Co-developed-by: Mike Rapoport (Microsoft) Signed-off-by: Mike Rapoport (Microsoft) Signed-off-by: Pasha Tatashin Reviewed-by: Pratyush Yadav --- MAINTAINERS | 3 +- kernel/Kconfig.kexec | 10 ++ kernel/Makefile | 1 + kernel/kexec_handover.c | 226 +++----------------------- kernel/kexec_handover_debugfs.c | 216 ++++++++++++++++++++++++ kernel/kexec_handover_internal.h | 37 +++++ tools/testing/selftests/kho/vmtest.sh | 1 + 7 files changed, 286 insertions(+), 208 deletions(-) create mode 100644 kernel/kexec_handover_debugfs.c diff --git a/MAINTAINERS b/MAINTAINERS index 6c0f154cb76d..0a6ba2717caa 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13774,13 +13774,14 @@ KEXEC HANDOVER (KHO) M: Alexander Graf M: Mike Rapoport M: Changyuan Lyu +M: Pasha Tatashin L: kexec@lists.infradead.org L: linux-mm@kvack.org S: Maintained F: Documentation/admin-guide/mm/kho.rst F: Documentation/core-api/kho/* F: include/linux/kexec_handover.h -F: kernel/kexec_handover.c +F: kernel/kexec_handover* F: tools/testing/selftests/kho/ =20 KEYS-ENCRYPTED diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec index c94d36b5fcd9..9308a0fb1419 100644 --- a/kernel/Kconfig.kexec +++ b/kernel/Kconfig.kexec @@ -118,6 +118,16 @@ config KEXEC_HANDOVER_DEBUG scenarios and the extra code might be adding overhead it is only optionally enabled. =20 +config KEXEC_HANDOVER_DEBUGFS + bool "kexec handover debugfs interface" + depends on KEXEC_HANDOVER + depends on DEBUG_FS + help + Allow to control kexec handover device tree via debugfs + interface, i.e. finalize the state or aborting the finalization. + Also, enables inspecting the KHO fdt trees with the debugfs binary + blobs. + config CRASH_DUMP bool "kernel crash dumps" default ARCH_DEFAULT_CRASH_DUMP diff --git a/kernel/Makefile b/kernel/Makefile index 9fe722305c9b..2cf7909a74e5 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -84,6 +84,7 @@ obj-$(CONFIG_KEXEC_FILE) +=3D kexec_file.o obj-$(CONFIG_KEXEC_ELF) +=3D kexec_elf.o obj-$(CONFIG_KEXEC_HANDOVER) +=3D kexec_handover.o obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) +=3D kexec_handover_debug.o +obj-$(CONFIG_KEXEC_HANDOVER_DEBUGFS) +=3D kexec_handover_debugfs.o obj-$(CONFIG_BACKTRACE_SELF_TEST) +=3D backtracetest.o obj-$(CONFIG_COMPAT) +=3D compat.o obj-$(CONFIG_CGROUPS) +=3D cgroup/ diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index 6458f369a346..da071277d85e 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -30,6 +29,7 @@ */ #include "../mm/internal.h" #include "kexec_internal.h" +#include "kexec_handover_internal.h" =20 #define KHO_FDT_COMPATIBLE "kho-v1" #define PROP_PRESERVED_MEMORY_MAP "preserved-memory-map" @@ -105,8 +105,6 @@ struct khoser_mem_chunk; =20 struct kho_serialization { struct page *fdt; - struct list_head fdt_list; - struct dentry *sub_fdt_dir; struct kho_mem_track track; /* First chunk of serialized preserved memory map */ struct khoser_mem_chunk *preserved_mem_map; @@ -114,20 +112,16 @@ struct kho_serialization { =20 struct kho_out { struct blocking_notifier_head chain_head; - - struct dentry *dir; - struct mutex lock; /* protects KHO FDT finalization */ - struct kho_serialization ser; bool finalized; + struct kho_debugfs dbg; }; =20 static struct kho_out kho_out =3D { .chain_head =3D BLOCKING_NOTIFIER_INIT(kho_out.chain_head), .lock =3D __MUTEX_INITIALIZER(kho_out.lock), .ser =3D { - .fdt_list =3D LIST_HEAD_INIT(kho_out.ser.fdt_list), .track =3D { .orders =3D XARRAY_INIT(kho_out.ser.track.orders, 0), }, @@ -477,8 +471,8 @@ static void __init kho_mem_deserialize(const void *fdt) * area for early allocations that happen before page allocator is * initialized. */ -static struct kho_scratch *kho_scratch; -static unsigned int kho_scratch_cnt; +struct kho_scratch *kho_scratch; +unsigned int kho_scratch_cnt; =20 /* * The scratch areas are scaled by default as percent of memory allocated = from @@ -674,37 +668,6 @@ static void __init kho_reserve_scratch(void) kho_enable =3D false; } =20 -struct fdt_debugfs { - struct list_head list; - struct debugfs_blob_wrapper wrapper; - struct dentry *file; -}; - -static int kho_debugfs_fdt_add(struct list_head *list, struct dentry *dir, - const char *name, const void *fdt) -{ - struct fdt_debugfs *f; - struct dentry *file; - - f =3D kmalloc(sizeof(*f), GFP_KERNEL); - if (!f) - return -ENOMEM; - - f->wrapper.data =3D (void *)fdt; - f->wrapper.size =3D fdt_totalsize(fdt); - - file =3D debugfs_create_blob(name, 0400, dir, &f->wrapper); - if (IS_ERR(file)) { - kfree(f); - return PTR_ERR(file); - } - - f->file =3D file; - list_add(&f->list, list); - - return 0; -} - /** * kho_add_subtree - record the physical address of a sub FDT in KHO root = tree. * @ser: serialization control object passed by KHO notifiers. @@ -716,7 +679,8 @@ static int kho_debugfs_fdt_add(struct list_head *list, = struct dentry *dir, * by KHO for the new kernel to retrieve it after kexec. * * A debugfs blob entry is also created at - * ``/sys/kernel/debug/kho/out/sub_fdts/@name``. + * ``/sys/kernel/debug/kho/out/sub_fdts/@name`` when kernel is configured = with + * CONFIG_KEXEC_HANDOVER_DEBUGFS * * Return: 0 on success, error code on failure */ @@ -733,7 +697,7 @@ int kho_add_subtree(struct kho_serialization *ser, cons= t char *name, void *fdt) if (err) return err; =20 - return kho_debugfs_fdt_add(&ser->fdt_list, ser->sub_fdt_dir, name, fdt); + return kho_debugfs_fdt_add(&kho_out.dbg, name, fdt, false); } EXPORT_SYMBOL_GPL(kho_add_subtree); =20 @@ -1064,29 +1028,6 @@ void *kho_restore_vmalloc(const struct kho_vmalloc *= preservation) } EXPORT_SYMBOL_GPL(kho_restore_vmalloc); =20 -/* Handling for debug/kho/out */ - -static struct dentry *debugfs_root; - -static int kho_out_update_debugfs_fdt(void) -{ - int err =3D 0; - struct fdt_debugfs *ff, *tmp; - - if (kho_out.finalized) { - err =3D kho_debugfs_fdt_add(&kho_out.ser.fdt_list, kho_out.dir, - "fdt", page_to_virt(kho_out.ser.fdt)); - } else { - list_for_each_entry_safe(ff, tmp, &kho_out.ser.fdt_list, list) { - debugfs_remove(ff->file); - list_del(&ff->list); - kfree(ff); - } - } - - return err; -} - static int __kho_abort(void) { int err; @@ -1136,8 +1077,9 @@ int kho_abort(void) return ret; =20 kho_out.finalized =3D false; + kho_debugfs_cleanup(&kho_out.dbg); =20 - return kho_out_update_debugfs_fdt(); + return 0; } =20 static int __kho_finalize(void) @@ -1206,92 +1148,23 @@ int kho_finalize(void) =20 kho_out.finalized =3D true; =20 - return kho_out_update_debugfs_fdt(); + return kho_debugfs_fdt_add(&kho_out.dbg, "fdt", + page_to_virt(kho_out.ser.fdt), true); } =20 -static int kho_out_finalize_get(void *data, u64 *val) +bool kho_finalized(void) { - mutex_lock(&kho_out.lock); - *val =3D kho_out.finalized; - mutex_unlock(&kho_out.lock); - - return 0; -} - -static int kho_out_finalize_set(void *data, u64 val) -{ - if (val) - return kho_finalize(); - else - return kho_abort(); -} - -DEFINE_DEBUGFS_ATTRIBUTE(fops_kho_out_finalize, kho_out_finalize_get, - kho_out_finalize_set, "%llu\n"); - -static int scratch_phys_show(struct seq_file *m, void *v) -{ - for (int i =3D 0; i < kho_scratch_cnt; i++) - seq_printf(m, "0x%llx\n", kho_scratch[i].addr); - - return 0; -} -DEFINE_SHOW_ATTRIBUTE(scratch_phys); - -static int scratch_len_show(struct seq_file *m, void *v) -{ - for (int i =3D 0; i < kho_scratch_cnt; i++) - seq_printf(m, "0x%llx\n", kho_scratch[i].size); - - return 0; -} -DEFINE_SHOW_ATTRIBUTE(scratch_len); - -static __init int kho_out_debugfs_init(void) -{ - struct dentry *dir, *f, *sub_fdt_dir; - - dir =3D debugfs_create_dir("out", debugfs_root); - if (IS_ERR(dir)) - return -ENOMEM; - - sub_fdt_dir =3D debugfs_create_dir("sub_fdts", dir); - if (IS_ERR(sub_fdt_dir)) - goto err_rmdir; - - f =3D debugfs_create_file("scratch_phys", 0400, dir, NULL, - &scratch_phys_fops); - if (IS_ERR(f)) - goto err_rmdir; - - f =3D debugfs_create_file("scratch_len", 0400, dir, NULL, - &scratch_len_fops); - if (IS_ERR(f)) - goto err_rmdir; - - f =3D debugfs_create_file("finalize", 0600, dir, NULL, - &fops_kho_out_finalize); - if (IS_ERR(f)) - goto err_rmdir; - - kho_out.dir =3D dir; - kho_out.ser.sub_fdt_dir =3D sub_fdt_dir; - return 0; - -err_rmdir: - debugfs_remove_recursive(dir); - return -ENOENT; + guard(mutex)(&kho_out.lock); + return kho_out.finalized; } =20 struct kho_in { - struct dentry *dir; phys_addr_t fdt_phys; phys_addr_t scratch_phys; - struct list_head fdt_list; + struct kho_debugfs dbg; }; =20 static struct kho_in kho_in =3D { - .fdt_list =3D LIST_HEAD_INIT(kho_in.fdt_list), }; =20 static const void *kho_get_fdt(void) @@ -1355,56 +1228,6 @@ int kho_retrieve_subtree(const char *name, phys_addr= _t *phys) } EXPORT_SYMBOL_GPL(kho_retrieve_subtree); =20 -/* Handling for debugfs/kho/in */ - -static __init int kho_in_debugfs_init(const void *fdt) -{ - struct dentry *sub_fdt_dir; - int err, child; - - kho_in.dir =3D debugfs_create_dir("in", debugfs_root); - if (IS_ERR(kho_in.dir)) - return PTR_ERR(kho_in.dir); - - sub_fdt_dir =3D debugfs_create_dir("sub_fdts", kho_in.dir); - if (IS_ERR(sub_fdt_dir)) { - err =3D PTR_ERR(sub_fdt_dir); - goto err_rmdir; - } - - err =3D kho_debugfs_fdt_add(&kho_in.fdt_list, kho_in.dir, "fdt", fdt); - if (err) - goto err_rmdir; - - fdt_for_each_subnode(child, fdt, 0) { - int len =3D 0; - const char *name =3D fdt_get_name(fdt, child, NULL); - const u64 *fdt_phys; - - fdt_phys =3D fdt_getprop(fdt, child, "fdt", &len); - if (!fdt_phys) - continue; - if (len !=3D sizeof(*fdt_phys)) { - pr_warn("node `%s`'s prop `fdt` has invalid length: %d\n", - name, len); - continue; - } - err =3D kho_debugfs_fdt_add(&kho_in.fdt_list, sub_fdt_dir, name, - phys_to_virt(*fdt_phys)); - if (err) { - pr_warn("failed to add fdt `%s` to debugfs: %d\n", name, - err); - continue; - } - } - - return 0; - -err_rmdir: - debugfs_remove_recursive(kho_in.dir); - return err; -} - static __init int kho_init(void) { int err =3D 0; @@ -1419,27 +1242,16 @@ static __init int kho_init(void) goto err_free_scratch; } =20 - debugfs_root =3D debugfs_create_dir("kho", NULL); - if (IS_ERR(debugfs_root)) { - err =3D -ENOENT; + err =3D kho_debugfs_init(); + if (err) goto err_free_fdt; - } =20 - err =3D kho_out_debugfs_init(); + err =3D kho_out_debugfs_init(&kho_out.dbg); if (err) goto err_free_fdt; =20 if (fdt) { - err =3D kho_in_debugfs_init(fdt); - /* - * Failure to create /sys/kernel/debug/kho/in does not prevent - * reviving state from KHO and setting up KHO for the next - * kexec. - */ - if (err) - pr_err("failed exposing handover FDT in debugfs: %d\n", - err); - + kho_in_debugfs_init(&kho_in.dbg, fdt); return 0; } =20 diff --git a/kernel/kexec_handover_debugfs.c b/kernel/kexec_handover_debugf= s.c new file mode 100644 index 000000000000..a91b279f1b23 --- /dev/null +++ b/kernel/kexec_handover_debugfs.c @@ -0,0 +1,216 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * kexec_handover_debugfs.c - kexec handover debugfs interfaces + * Copyright (C) 2023 Alexander Graf + * Copyright (C) 2025 Microsoft Corporation, Mike Rapoport + * Copyright (C) 2025 Google LLC, Changyuan Lyu + * Copyright (C) 2025 Google LLC, Pasha Tatashin + */ + +#define pr_fmt(fmt) "KHO: " fmt + +#include +#include +#include +#include +#include "kexec_handover_internal.h" + +static struct dentry *debugfs_root; + +struct fdt_debugfs { + struct list_head list; + struct debugfs_blob_wrapper wrapper; + struct dentry *file; +}; + +static int __kho_debugfs_fdt_add(struct list_head *list, struct dentry *di= r, + const char *name, const void *fdt) +{ + struct fdt_debugfs *f; + struct dentry *file; + + f =3D kmalloc(sizeof(*f), GFP_KERNEL); + if (!f) + return -ENOMEM; + + f->wrapper.data =3D (void *)fdt; + f->wrapper.size =3D fdt_totalsize(fdt); + + file =3D debugfs_create_blob(name, 0400, dir, &f->wrapper); + if (IS_ERR(file)) { + kfree(f); + return PTR_ERR(file); + } + + f->file =3D file; + list_add(&f->list, list); + + return 0; +} + +int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const char *name, + const void *fdt, bool root) +{ + struct dentry *dir; + + if (root) + dir =3D dbg->dir; + else + dir =3D dbg->sub_fdt_dir; + + return __kho_debugfs_fdt_add(&dbg->fdt_list, dir, name, fdt); +} + +void kho_debugfs_cleanup(struct kho_debugfs *dbg) +{ + struct fdt_debugfs *ff, *tmp; + + list_for_each_entry_safe(ff, tmp, &dbg->fdt_list, list) { + debugfs_remove(ff->file); + list_del(&ff->list); + kfree(ff); + } +} + +static int kho_out_finalize_get(void *data, u64 *val) +{ + *val =3D kho_finalized(); + + return 0; +} + +static int kho_out_finalize_set(void *data, u64 val) +{ + if (val) + return kho_finalize(); + else + return kho_abort(); +} + +DEFINE_DEBUGFS_ATTRIBUTE(kho_out_finalize_fops, kho_out_finalize_get, + kho_out_finalize_set, "%llu\n"); + +static int scratch_phys_show(struct seq_file *m, void *v) +{ + for (int i =3D 0; i < kho_scratch_cnt; i++) + seq_printf(m, "0x%llx\n", kho_scratch[i].addr); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(scratch_phys); + +static int scratch_len_show(struct seq_file *m, void *v) +{ + for (int i =3D 0; i < kho_scratch_cnt; i++) + seq_printf(m, "0x%llx\n", kho_scratch[i].size); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(scratch_len); + +__init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt) +{ + struct dentry *dir, *sub_fdt_dir; + int err, child; + + INIT_LIST_HEAD(&dbg->fdt_list); + + dir =3D debugfs_create_dir("in", debugfs_root); + if (IS_ERR(dir)) { + err =3D PTR_ERR(dir); + goto err_out; + } + + sub_fdt_dir =3D debugfs_create_dir("sub_fdts", dir); + if (IS_ERR(sub_fdt_dir)) { + err =3D PTR_ERR(sub_fdt_dir); + goto err_rmdir; + } + + err =3D __kho_debugfs_fdt_add(&dbg->fdt_list, dir, "fdt", fdt); + if (err) + goto err_rmdir; + + fdt_for_each_subnode(child, fdt, 0) { + int len =3D 0; + const char *name =3D fdt_get_name(fdt, child, NULL); + const u64 *fdt_phys; + + fdt_phys =3D fdt_getprop(fdt, child, "fdt", &len); + if (!fdt_phys) + continue; + if (len !=3D sizeof(*fdt_phys)) { + pr_warn("node %s prop fdt has invalid length: %d\n", + name, len); + continue; + } + err =3D __kho_debugfs_fdt_add(&dbg->fdt_list, sub_fdt_dir, name, + phys_to_virt(*fdt_phys)); + if (err) { + pr_warn("failed to add fdt %s to debugfs: %d\n", name, + err); + continue; + } + } + + dbg->dir =3D dir; + dbg->sub_fdt_dir =3D sub_fdt_dir; + + return; +err_rmdir: + debugfs_remove_recursive(dir); +err_out: + /* + * Failure to create /sys/kernel/debug/kho/in does not prevent + * reviving state from KHO and setting up KHO for the next + * kexec. + */ + if (err) + pr_err("failed exposing handover FDT in debugfs: %d\n", err); +} + +__init int kho_out_debugfs_init(struct kho_debugfs *dbg) +{ + struct dentry *dir, *f, *sub_fdt_dir; + + INIT_LIST_HEAD(&dbg->fdt_list); + + dir =3D debugfs_create_dir("out", debugfs_root); + if (IS_ERR(dir)) + return -ENOMEM; + + sub_fdt_dir =3D debugfs_create_dir("sub_fdts", dir); + if (IS_ERR(sub_fdt_dir)) + goto err_rmdir; + + f =3D debugfs_create_file("scratch_phys", 0400, dir, NULL, + &scratch_phys_fops); + if (IS_ERR(f)) + goto err_rmdir; + + f =3D debugfs_create_file("scratch_len", 0400, dir, NULL, + &scratch_len_fops); + if (IS_ERR(f)) + goto err_rmdir; + + f =3D debugfs_create_file("finalize", 0600, dir, NULL, + &kho_out_finalize_fops); + if (IS_ERR(f)) + goto err_rmdir; + + dbg->dir =3D dir; + dbg->sub_fdt_dir =3D sub_fdt_dir; + return 0; + +err_rmdir: + debugfs_remove_recursive(dir); + return -ENOENT; +} + +__init int kho_debugfs_init(void) +{ + debugfs_root =3D debugfs_create_dir("kho", NULL); + if (IS_ERR(debugfs_root)) + return -ENOENT; + return 0; +} diff --git a/kernel/kexec_handover_internal.h b/kernel/kexec_handover_inter= nal.h index 05e9720ba7b9..28c0e971613d 100644 --- a/kernel/kexec_handover_internal.h +++ b/kernel/kexec_handover_internal.h @@ -2,8 +2,45 @@ #ifndef LINUX_KEXEC_HANDOVER_INTERNAL_H #define LINUX_KEXEC_HANDOVER_INTERNAL_H =20 +#include +#include #include =20 +#ifdef CONFIG_KEXEC_HANDOVER_DEBUGFS +#include + +struct kho_debugfs { + struct dentry *dir; + struct dentry *sub_fdt_dir; + struct list_head fdt_list; +}; + +#else +struct kho_debugfs {}; +#endif + +extern struct kho_scratch *kho_scratch; +extern unsigned int kho_scratch_cnt; + +bool kho_finalized(void); + +#ifdef CONFIG_KEXEC_HANDOVER_DEBUGFS +int kho_debugfs_init(void); +void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt); +int kho_out_debugfs_init(struct kho_debugfs *dbg); +int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const char *name, + const void *fdt, bool root); +void kho_debugfs_cleanup(struct kho_debugfs *dbg); +#else +static inline int kho_debugfs_init(void) { return 0; } +static inline void kho_in_debugfs_init(struct kho_debugfs *dbg, + const void *fdt) { } +static inline int kho_out_debugfs_init(struct kho_debugfs *dbg) { return 0= ; } +static inline int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const char = *name, + const void *fdt, bool root) { return 0; } +static inline void kho_debugfs_cleanup(struct kho_debugfs *dbg) {} +#endif /* CONFIG_KEXEC_HANDOVER_DEBUGFS */ + #ifdef CONFIG_KEXEC_HANDOVER_DEBUG bool kho_scratch_overlap(phys_addr_t phys, size_t size); #else diff --git a/tools/testing/selftests/kho/vmtest.sh b/tools/testing/selftest= s/kho/vmtest.sh index 3f6c17166846..49fdac8e8b15 100755 --- a/tools/testing/selftests/kho/vmtest.sh +++ b/tools/testing/selftests/kho/vmtest.sh @@ -59,6 +59,7 @@ function build_kernel() { tee "$kconfig" > "$kho_config" <; Wed, 22 Oct 2025 00:57:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094648; cv=none; b=PQQDF8Mx2YZcB2YCsENdx4HWUTkQ1rsqi4SpKvgEUi0QCmCscsdWA0By1tbaorWwFok0d0ILHiOLmaWNLWUGr7usXeayn69BjP9h2474Ypr7P1YJ/pgIVM791zrXrnCl9PcrWNFRfXiL3WVJyEqk/HO3kUI3WVczdHSrEIkn4yI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094648; c=relaxed/simple; bh=RJpncTnlsUR1CF5BmdZj9BBNKKKOVyCkplMdvt8dG1I=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZcggOckfUhAuP30Yx7f2x48OqCM0CYSyD8L/47fivOixVRAtTLOVMG9SFiG/sVYIvUwsD3IEfi2A8tf/+7pZeBEyuOtLKGp6DKxc7Vf6y0bQWZt2yblE4uawFXsDFtjAnaXALtEYTgjoCL/aXUlPdpn8447Id52MDxYAuM7qWyw= 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=UO5uI5+N; arc=none smtp.client-ip=209.85.160.169 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="UO5uI5+N" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-4e896e91368so6089721cf.0 for ; Tue, 21 Oct 2025 17:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1761094644; x=1761699444; 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=OvCKFxa6vImrc7itzom7XLQjDWDOVx6Kf2lD/YWuxDQ=; b=UO5uI5+NMvGK8WRrQrZbWwl4aaG7LFoqq+GhfOGXDMAwY1ZZGGtwOTx+Y59DoSENqI +7gG54cBxGSOmLAeZFOg2qfIav0hmyRxVdpDq3MUT6HCvWZczPy6YjPRKUxzPaBZ40Nm 1PLwBX5aop/lBNvcJPCKvwvhTWHtLaiHySm2AbqxIdFSVcnGUolzq2NjvWSebQ1YnPOR lOOcRaV6eZGX76u0EbXsPqvTIcfK1QlHGrZIEsouywLVN52dROxhjVeks85pmMa1CMLu cvyBJaJu5LzSqQDlvLuiGvFkeYRZcedpU1txiHdehsv8lm+R0zn/xIq4Y7ZwSZ+Y2Idd WM2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761094644; x=1761699444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OvCKFxa6vImrc7itzom7XLQjDWDOVx6Kf2lD/YWuxDQ=; b=AAq3zU+RBfVqzdGbUk1sbmcEHOYBU2AZene+KLKi5N5r+eKI6zUfLzj2PjpOriBS95 XINryspIsLxO4/QvvVNWX+C0ubehXLAAlFPNKXjMAWHMBGM5fprf9C8dpi/8rYgz/0P9 VYdzgP2u8rIhUTtZ+4+yMU3ydAneQxR2ZGUVMDg+hsELaMFHGNohCx5XjtKo+7J531wZ 0Zqc/1AyZF/0Gkxp+l1tVXlnvZfFTpbboUiLW2joxyV4xjMaBp1TXgq8WzoCFWjE+Zh9 Ddqey3sCQm0Dw4iGanxlWk1dI+vDNfCtNV8bjdbyET1oq13AvjHMUgS+SHJ1KOAkkWSe jk3g== X-Forwarded-Encrypted: i=1; AJvYcCUNjAwMUQdZ56u/rPcaOq/OPXhN4ZLH0tChXDBEP0a247oqevJO1otRA7ly41I8rKxE801jJ+oEYVaeysQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzIMfbEsoM+Z+1DeT9v6j5/FDHcK0Px7UrL3VXmCc/twHmFQB7C dMP5gI6IgqzGngq8/YyGbApHeGEaguvTzyU/2+LQQ3Qaz3RA3KKWYPGW3ZHQOH9c4zg= X-Gm-Gg: ASbGncvjv6z1FvfjnNkRP+BAhzeB+X/cM4DUtKA18RUtv+6DSDebWIHcBVzBh6Wmfz5 rAiXHtprvQpItdzCLG1bRdYzQr+IyhtXHzsTS641C8QLrvcxZRCY5Xz4R28I9WToVg96Y8yeyO7 oRE2d1ukXqxY1ezxGbrPi6fEdHHlzdNAPm7RlgBpPyGWhKzxGFx5wYH4HBZUgzTr/zDkSVAHID6 fXSxppaOlloQZYjhiqI90oyEVSRAOGwKnjgwbQEm4gBX6dMgngXjv48JKAfFeDpy1f0UTyrqyOH hfIJDjBeWXFCUlSlpbIoHx/ovbrMgosb8DaLdLYh6Dk/EJuJCh2tiOvB9CK+twn63nDZTAIaJKs /wRUcMh2dGhOJj6FPy4CioAHQEFN507vbLzTg4+guFIL/hcp/FioQPsxIJEQ4/XA9cWshbfw+DJ v+Dc8KaUxcVDhuQ1dZp1GWO83ieK9Kq22fO2aVxfOgOLlaUfD+r1/Rwk8J64NZosYBDjgOLAMJJ UzCEcGsa7YYodjURAe+ce7rKTgllZeh X-Google-Smtp-Source: AGHT+IEkF4NxRop9PUR4cBO4VtWbdt8BmHF+ZRLpywe4q/M7Dx81KpSdt3p8Ex2ZGVlVDs7zZrazYA== X-Received: by 2002:ac8:5708:0:b0:4de:515e:6215 with SMTP id d75a77b69052e-4e89d357933mr246458351cf.46.1761094644059; Tue, 21 Oct 2025 17:57:24 -0700 (PDT) Received: from soleen.us-east4-b.c.cloudtop-prod-us-east.internal (53.47.86.34.bc.googleusercontent.com. [34.86.47.53]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4e8aaf3432dsm84169501cf.2.2025.10.21.17.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 17:57:23 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, brauner@kernel.org, corbet@lwn.net, graf@amazon.com, jgg@ziepe.ca, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, masahiroy@kernel.org, ojeda@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, rdunlap@infradead.org, rppt@kernel.org, tj@kernel.org Subject: [PATCHv7 3/7] kho: drop notifiers Date: Tue, 21 Oct 2025 20:57:15 -0400 Message-ID: <20251022005719.3670224-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.51.0.915.g61a8936c21-goog In-Reply-To: <20251022005719.3670224-1-pasha.tatashin@soleen.com> References: <20251022005719.3670224-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" From: "Mike Rapoport (Microsoft)" The KHO framework uses a notifier chain as the mechanism for clients to participate in the finalization process. While this works for a single, central state machine, it is too restrictive for kernel-internal components like pstore/reserve_mem or IMA. These components need a simpler, direct way to register their state for preservation (e.g., during their initcall) without being part of a complex, shutdown-time notifier sequence. The notifier model forces all participants into a single finalization flow and makes direct preservation from an arbitrary context difficult. This patch refactors the client participation model by removing the notifier chain and introducing a direct API for managing FDT subtrees. The core kho_finalize() and kho_abort() state machine remains, but clients now register their data with KHO beforehand. Signed-off-by: Mike Rapoport (Microsoft) Co-developed-by: Pasha Tatashin Signed-off-by: Pasha Tatashin --- include/linux/kexec_handover.h | 28 +----- kernel/kexec_handover.c | 164 +++++++++++++++++-------------- kernel/kexec_handover_debugfs.c | 17 ++-- kernel/kexec_handover_internal.h | 5 +- lib/test_kho.c | 30 +----- mm/memblock.c | 62 +++--------- 6 files changed, 127 insertions(+), 179 deletions(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 04d0108db98e..2faf290803ce 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -10,14 +10,7 @@ struct kho_scratch { phys_addr_t size; }; =20 -/* KHO Notifier index */ -enum kho_event { - KEXEC_KHO_FINALIZE =3D 0, - KEXEC_KHO_ABORT =3D 1, -}; - struct folio; -struct notifier_block; struct page; =20 #define DECLARE_KHOSER_PTR(name, type) \ @@ -37,8 +30,6 @@ struct page; (typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \ }) =20 -struct kho_serialization; - struct kho_vmalloc_chunk; struct kho_vmalloc { DECLARE_KHOSER_PTR(first, struct kho_vmalloc_chunk *); @@ -57,12 +48,10 @@ int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc = *preservation); 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); -int kho_add_subtree(struct kho_serialization *ser, const char *name, void = *fdt); +int kho_add_subtree(const char *name, void *fdt); +void kho_remove_subtree(void *fdt); int kho_retrieve_subtree(const char *name, phys_addr_t *phys); =20 -int register_kho_notifier(struct notifier_block *nb); -int unregister_kho_notifier(struct notifier_block *nb); - void kho_memory_init(void); =20 void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t scratch_p= hys, @@ -114,23 +103,16 @@ static inline void *kho_restore_vmalloc(const struct = kho_vmalloc *preservation) return NULL; } =20 -static inline int kho_add_subtree(struct kho_serialization *ser, - const char *name, void *fdt) +static inline int kho_add_subtree(const char *name, void *fdt) { return -EOPNOTSUPP; } =20 -static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys) +static inline void kho_remove_subtree(void *fdt) { - return -EOPNOTSUPP; } =20 -static inline int register_kho_notifier(struct notifier_block *nb) -{ - return -EOPNOTSUPP; -} - -static inline int unregister_kho_notifier(struct notifier_block *nb) +static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys) { return -EOPNOTSUPP; } diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index da071277d85e..0a4234269fe5 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include =20 @@ -103,29 +102,34 @@ struct kho_mem_track { =20 struct khoser_mem_chunk; =20 -struct kho_serialization { - struct page *fdt; - struct kho_mem_track track; - /* First chunk of serialized preserved memory map */ - struct khoser_mem_chunk *preserved_mem_map; +struct kho_sub_fdt { + struct list_head l; + const char *name; + void *fdt; }; =20 struct kho_out { - struct blocking_notifier_head chain_head; - struct mutex lock; /* protects KHO FDT finalization */ - struct kho_serialization ser; + void *fdt; bool finalized; + struct mutex lock; /* protects KHO FDT finalization */ + + struct list_head sub_fdts; + struct mutex fdts_lock; + + struct kho_mem_track track; + /* First chunk of serialized preserved memory map */ + struct khoser_mem_chunk *preserved_mem_map; + struct kho_debugfs dbg; }; =20 static struct kho_out kho_out =3D { - .chain_head =3D BLOCKING_NOTIFIER_INIT(kho_out.chain_head), .lock =3D __MUTEX_INITIALIZER(kho_out.lock), - .ser =3D { - .track =3D { - .orders =3D XARRAY_INIT(kho_out.ser.track.orders, 0), - }, + .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 @@ -369,7 +373,7 @@ static void kho_mem_ser_free(struct khoser_mem_chunk *f= irst_chunk) } } =20 -static int kho_mem_serialize(struct kho_serialization *ser) +static int kho_mem_serialize(struct kho_out *kho_out) { struct khoser_mem_chunk *first_chunk =3D NULL; struct khoser_mem_chunk *chunk =3D NULL; @@ -377,7 +381,7 @@ static int kho_mem_serialize(struct kho_serialization *= ser) unsigned long order; int err =3D -ENOMEM; =20 - xa_for_each(&ser->track.orders, order, physxa) { + xa_for_each(&kho_out->track.orders, order, physxa) { struct kho_mem_phys_bits *bits; unsigned long phys; =20 @@ -409,7 +413,7 @@ static int kho_mem_serialize(struct kho_serialization *= ser) } } =20 - ser->preserved_mem_map =3D first_chunk; + kho_out->preserved_mem_map =3D first_chunk; =20 return 0; =20 @@ -670,7 +674,6 @@ static void __init kho_reserve_scratch(void) =20 /** * kho_add_subtree - record the physical address of a sub FDT in KHO root = tree. - * @ser: serialization control object passed by KHO notifiers. * @name: name of the sub tree. * @fdt: the sub tree blob. * @@ -684,34 +687,45 @@ static void __init kho_reserve_scratch(void) * * Return: 0 on success, error code on failure */ -int kho_add_subtree(struct kho_serialization *ser, const char *name, void = *fdt) +int kho_add_subtree(const char *name, void *fdt) { - int err =3D 0; - u64 phys =3D (u64)virt_to_phys(fdt); - void *root =3D page_to_virt(ser->fdt); + struct kho_sub_fdt *sub_fdt; + int err; =20 - err |=3D fdt_begin_node(root, name); - err |=3D fdt_property(root, PROP_SUB_FDT, &phys, sizeof(phys)); - err |=3D fdt_end_node(root); + sub_fdt =3D kmalloc(sizeof(*sub_fdt), GFP_KERNEL); + if (!sub_fdt) + return -ENOMEM; =20 - if (err) - return err; + INIT_LIST_HEAD(&sub_fdt->l); + sub_fdt->name =3D name; + sub_fdt->fdt =3D fdt; =20 - return kho_debugfs_fdt_add(&kho_out.dbg, name, fdt, false); + mutex_lock(&kho_out.fdts_lock); + list_add_tail(&sub_fdt->l, &kho_out.sub_fdts); + err =3D kho_debugfs_fdt_add(&kho_out.dbg, name, fdt, false); + mutex_unlock(&kho_out.fdts_lock); + + return err; } EXPORT_SYMBOL_GPL(kho_add_subtree); =20 -int register_kho_notifier(struct notifier_block *nb) +void kho_remove_subtree(void *fdt) { - return blocking_notifier_chain_register(&kho_out.chain_head, nb); -} -EXPORT_SYMBOL_GPL(register_kho_notifier); + struct kho_sub_fdt *sub_fdt; + + mutex_lock(&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); + kho_debugfs_fdt_remove(&kho_out.dbg, fdt); + break; + } + } + mutex_unlock(&kho_out.fdts_lock); =20 -int unregister_kho_notifier(struct notifier_block *nb) -{ - return blocking_notifier_chain_unregister(&kho_out.chain_head, nb); } -EXPORT_SYMBOL_GPL(unregister_kho_notifier); +EXPORT_SYMBOL_GPL(kho_remove_subtree); =20 /** * kho_preserve_folio - preserve a folio across kexec. @@ -726,7 +740,7 @@ int kho_preserve_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.ser.track; + struct kho_mem_track *track =3D &kho_out.track; =20 if (WARN_ON(kho_scratch_overlap(pfn << PAGE_SHIFT, PAGE_SIZE << order))) return -EINVAL; @@ -747,7 +761,7 @@ EXPORT_SYMBOL_GPL(kho_preserve_folio); */ int kho_preserve_pages(struct page *page, unsigned int nr_pages) { - struct kho_mem_track *track =3D &kho_out.ser.track; + 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; unsigned long pfn =3D start_pfn; @@ -848,7 +862,7 @@ static struct kho_vmalloc_chunk *new_vmalloc_chunk(stru= ct kho_vmalloc_chunk *cur =20 static void kho_vmalloc_unpreserve_chunk(struct kho_vmalloc_chunk *chunk) { - struct kho_mem_track *track =3D &kho_out.ser.track; + struct kho_mem_track *track =3D &kho_out.track; unsigned long pfn =3D PHYS_PFN(virt_to_phys(chunk)); =20 __kho_unpreserve(track, pfn, pfn + 1); @@ -1030,11 +1044,11 @@ EXPORT_SYMBOL_GPL(kho_restore_vmalloc); =20 static int __kho_abort(void) { - int err; + int err =3D 0; unsigned long order; struct kho_mem_phys *physxa; =20 - xa_for_each(&kho_out.ser.track.orders, order, physxa) { + xa_for_each(&kho_out.track.orders, order, physxa) { struct kho_mem_phys_bits *bits; unsigned long phys; =20 @@ -1044,17 +1058,13 @@ static int __kho_abort(void) xa_destroy(&physxa->phys_bits); kfree(physxa); } - xa_destroy(&kho_out.ser.track.orders); + xa_destroy(&kho_out.track.orders); =20 - if (kho_out.ser.preserved_mem_map) { - kho_mem_ser_free(kho_out.ser.preserved_mem_map); - kho_out.ser.preserved_mem_map =3D NULL; + if (kho_out.preserved_mem_map) { + kho_mem_ser_free(kho_out.preserved_mem_map); + kho_out.preserved_mem_map =3D NULL; } =20 - err =3D blocking_notifier_call_chain(&kho_out.chain_head, KEXEC_KHO_ABORT, - NULL); - err =3D notifier_to_errno(err); - if (err) pr_err("Failed to abort KHO finalization: %d\n", err); =20 @@ -1077,7 +1087,8 @@ int kho_abort(void) return ret; =20 kho_out.finalized =3D false; - kho_debugfs_cleanup(&kho_out.dbg); + + kho_debugfs_fdt_remove(&kho_out.dbg, kho_out.fdt); =20 return 0; } @@ -1086,41 +1097,46 @@ static int __kho_finalize(void) { int err =3D 0; u64 *preserved_mem_map; - void *fdt =3D page_to_virt(kho_out.ser.fdt); + void *root =3D kho_out.fdt; + struct kho_sub_fdt *fdt; =20 - err |=3D fdt_create(fdt, PAGE_SIZE); - err |=3D fdt_finish_reservemap(fdt); - err |=3D fdt_begin_node(fdt, ""); - err |=3D fdt_property_string(fdt, "compatible", KHO_FDT_COMPATIBLE); + 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(fdt, PROP_PRESERVED_MEMORY_MAP, + err |=3D fdt_property_placeholder(root, PROP_PRESERVED_MEMORY_MAP, sizeof(*preserved_mem_map), (void **)&preserved_mem_map); if (err) goto abort; =20 - err =3D kho_preserve_folio(page_folio(kho_out.ser.fdt)); + err =3D kho_preserve_folio(virt_to_folio(kho_out.fdt)); if (err) goto abort; =20 - err =3D blocking_notifier_call_chain(&kho_out.chain_head, - KEXEC_KHO_FINALIZE, &kho_out.ser); - err =3D notifier_to_errno(err); + err =3D kho_mem_serialize(&kho_out); if (err) goto abort; =20 - err =3D kho_mem_serialize(&kho_out.ser); - if (err) - goto abort; + *preserved_mem_map =3D (u64)virt_to_phys(kho_out.preserved_mem_map); + + 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); =20 - *preserved_mem_map =3D (u64)virt_to_phys(kho_out.ser.preserved_mem_map); + 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); =20 - err |=3D fdt_end_node(fdt); - err |=3D fdt_finish(fdt); + err |=3D fdt_end_node(root); + err |=3D fdt_finish(root); =20 abort: if (err) { @@ -1149,7 +1165,7 @@ int kho_finalize(void) kho_out.finalized =3D true; =20 return kho_debugfs_fdt_add(&kho_out.dbg, "fdt", - page_to_virt(kho_out.ser.fdt), true); + kho_out.fdt, true); } =20 bool kho_finalized(void) @@ -1232,15 +1248,17 @@ static __init int kho_init(void) { int err =3D 0; const void *fdt =3D kho_get_fdt(); + struct page *fdt_page; =20 if (!kho_enable) return 0; =20 - kho_out.ser.fdt =3D alloc_page(GFP_KERNEL); - if (!kho_out.ser.fdt) { + fdt_page =3D alloc_page(GFP_KERNEL); + if (!fdt_page) { err =3D -ENOMEM; goto err_free_scratch; } + kho_out.fdt =3D page_to_virt(fdt_page); =20 err =3D kho_debugfs_init(); if (err) @@ -1268,8 +1286,8 @@ static __init int kho_init(void) return 0; =20 err_free_fdt: - put_page(kho_out.ser.fdt); - kho_out.ser.fdt =3D NULL; + put_page(fdt_page); + kho_out.fdt =3D NULL; err_free_scratch: for (int i =3D 0; i < kho_scratch_cnt; i++) { void *start =3D __va(kho_scratch[i].addr); @@ -1280,7 +1298,7 @@ static __init int kho_init(void) kho_enable =3D false; return err; } -late_initcall(kho_init); +fs_initcall(kho_init); =20 static void __init kho_release_scratch(void) { @@ -1416,7 +1434,7 @@ int kho_fill_kimage(struct kimage *image) if (!kho_out.finalized) return 0; =20 - image->kho.fdt =3D page_to_phys(kho_out.ser.fdt); + image->kho.fdt =3D virt_to_phys(kho_out.fdt); =20 scratch_size =3D sizeof(*kho_scratch) * kho_scratch_cnt; scratch =3D (struct kexec_buf){ diff --git a/kernel/kexec_handover_debugfs.c b/kernel/kexec_handover_debugf= s.c index a91b279f1b23..46e9e6c0791f 100644 --- a/kernel/kexec_handover_debugfs.c +++ b/kernel/kexec_handover_debugfs.c @@ -61,14 +61,17 @@ int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const = char *name, return __kho_debugfs_fdt_add(&dbg->fdt_list, dir, name, fdt); } =20 -void kho_debugfs_cleanup(struct kho_debugfs *dbg) +void kho_debugfs_fdt_remove(struct kho_debugfs *dbg, void *fdt) { - struct fdt_debugfs *ff, *tmp; - - list_for_each_entry_safe(ff, tmp, &dbg->fdt_list, list) { - debugfs_remove(ff->file); - list_del(&ff->list); - kfree(ff); + struct fdt_debugfs *ff; + + list_for_each_entry(ff, &dbg->fdt_list, list) { + if (ff->wrapper.data =3D=3D fdt) { + debugfs_remove(ff->file); + list_del(&ff->list); + kfree(ff); + break; + } } } =20 diff --git a/kernel/kexec_handover_internal.h b/kernel/kexec_handover_inter= nal.h index 28c0e971613d..17ae101dc6ae 100644 --- a/kernel/kexec_handover_internal.h +++ b/kernel/kexec_handover_internal.h @@ -30,7 +30,7 @@ void kho_in_debugfs_init(struct kho_debugfs *dbg, const v= oid *fdt); int kho_out_debugfs_init(struct kho_debugfs *dbg); int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const char *name, const void *fdt, bool root); -void kho_debugfs_cleanup(struct kho_debugfs *dbg); +void kho_debugfs_fdt_remove(struct kho_debugfs *dbg, void *fdt); #else static inline int kho_debugfs_init(void) { return 0; } static inline void kho_in_debugfs_init(struct kho_debugfs *dbg, @@ -38,7 +38,8 @@ static inline void kho_in_debugfs_init(struct kho_debugfs= *dbg, static inline int kho_out_debugfs_init(struct kho_debugfs *dbg) { return 0= ; } static inline int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const char = *name, const void *fdt, bool root) { return 0; } -static inline void kho_debugfs_cleanup(struct kho_debugfs *dbg) {} +static inline void kho_debugfs_fdt_remove(struct kho_debugfs *dbg, + void *fdt) { } #endif /* CONFIG_KEXEC_HANDOVER_DEBUGFS */ =20 #ifdef CONFIG_KEXEC_HANDOVER_DEBUG diff --git a/lib/test_kho.c b/lib/test_kho.c index 60cd899ea745..8d57049e8c8c 100644 --- a/lib/test_kho.c +++ b/lib/test_kho.c @@ -39,33 +39,17 @@ struct kho_test_state { =20 static struct kho_test_state kho_test_state; =20 -static int kho_test_notifier(struct notifier_block *self, unsigned long cm= d, - void *v) +static int kho_test(void) { struct kho_test_state *state =3D &kho_test_state; - struct kho_serialization *ser =3D v; int err =3D 0; =20 - switch (cmd) { - case KEXEC_KHO_ABORT: - return NOTIFY_DONE; - case KEXEC_KHO_FINALIZE: - /* Handled below */ - break; - default: - return NOTIFY_BAD; - } - err |=3D kho_preserve_folio(state->fdt); - err |=3D kho_add_subtree(ser, KHO_TEST_FDT, folio_address(state->fdt)); + err |=3D kho_add_subtree(KHO_TEST_FDT, folio_address(state->fdt)); =20 return err ? NOTIFY_BAD : NOTIFY_DONE; } =20 -static struct notifier_block kho_test_nb =3D { - .notifier_call =3D kho_test_notifier, -}; - static int kho_test_save_data(struct kho_test_state *state, void *fdt) { phys_addr_t *folios_info __free(kvfree) =3D NULL; @@ -102,6 +86,9 @@ static int kho_test_save_data(struct kho_test_state *sta= te, void *fdt) if (!err) state->folios_info =3D no_free_ptr(folios_info); =20 + if (!err) + err =3D kho_test(); + return err; } =20 @@ -203,14 +190,8 @@ static int kho_test_save(void) if (err) goto err_free_folios; =20 - err =3D register_kho_notifier(&kho_test_nb); - if (err) - goto err_free_fdt; - return 0; =20 -err_free_fdt: - folio_put(state->fdt); err_free_folios: kvfree(folios); return err; @@ -326,7 +307,6 @@ static void kho_test_cleanup(void) =20 static void __exit kho_test_exit(void) { - unregister_kho_notifier(&kho_test_nb); kho_test_cleanup(); } module_exit(kho_test_exit); diff --git a/mm/memblock.c b/mm/memblock.c index e23e16618e9b..e3bef9b35d63 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2444,53 +2444,18 @@ int reserve_mem_release_by_name(const char *name) #define MEMBLOCK_KHO_FDT "memblock" #define MEMBLOCK_KHO_NODE_COMPATIBLE "memblock-v1" #define RESERVE_MEM_KHO_NODE_COMPATIBLE "reserve-mem-v1" -static struct page *kho_fdt; - -static int reserve_mem_kho_finalize(struct kho_serialization *ser) -{ - int err =3D 0, i; - - for (i =3D 0; i < reserved_mem_count; i++) { - struct reserve_mem_table *map =3D &reserved_mem_table[i]; - struct page *page =3D phys_to_page(map->start); - unsigned int nr_pages =3D map->size >> PAGE_SHIFT; - - err |=3D kho_preserve_pages(page, nr_pages); - } - - err |=3D kho_preserve_folio(page_folio(kho_fdt)); - err |=3D kho_add_subtree(ser, MEMBLOCK_KHO_FDT, page_to_virt(kho_fdt)); - - return notifier_from_errno(err); -} - -static int reserve_mem_kho_notifier(struct notifier_block *self, - unsigned long cmd, void *v) -{ - switch (cmd) { - case KEXEC_KHO_FINALIZE: - return reserve_mem_kho_finalize((struct kho_serialization *)v); - case KEXEC_KHO_ABORT: - return NOTIFY_DONE; - default: - return NOTIFY_BAD; - } -} - -static struct notifier_block reserve_mem_kho_nb =3D { - .notifier_call =3D reserve_mem_kho_notifier, -}; =20 static int __init prepare_kho_fdt(void) { int err =3D 0, i; + struct page *fdt_page; void *fdt; =20 - kho_fdt =3D alloc_page(GFP_KERNEL); - if (!kho_fdt) + fdt_page =3D alloc_page(GFP_KERNEL); + if (!fdt_page) return -ENOMEM; =20 - fdt =3D page_to_virt(kho_fdt); + fdt =3D page_to_virt(fdt_page); =20 err |=3D fdt_create(fdt, PAGE_SIZE); err |=3D fdt_finish_reservemap(fdt); @@ -2499,7 +2464,10 @@ static int __init prepare_kho_fdt(void) err |=3D fdt_property_string(fdt, "compatible", MEMBLOCK_KHO_NODE_COMPATI= BLE); for (i =3D 0; i < reserved_mem_count; i++) { struct reserve_mem_table *map =3D &reserved_mem_table[i]; + struct page *page =3D phys_to_page(map->start); + unsigned int nr_pages =3D map->size >> PAGE_SHIFT; =20 + err |=3D kho_preserve_pages(page, nr_pages); err |=3D fdt_begin_node(fdt, map->name); err |=3D fdt_property_string(fdt, "compatible", RESERVE_MEM_KHO_NODE_COM= PATIBLE); err |=3D fdt_property(fdt, "start", &map->start, sizeof(map->start)); @@ -2507,13 +2475,16 @@ static int __init prepare_kho_fdt(void) err |=3D fdt_end_node(fdt); } err |=3D fdt_end_node(fdt); - err |=3D fdt_finish(fdt); =20 + err |=3D kho_preserve_folio(page_folio(fdt_page)); + + if (!err) + err =3D kho_add_subtree(MEMBLOCK_KHO_FDT, fdt); + if (err) { pr_err("failed to prepare memblock FDT for KHO: %d\n", err); - put_page(kho_fdt); - kho_fdt =3D NULL; + put_page(fdt_page); } =20 return err; @@ -2529,13 +2500,6 @@ static int __init reserve_mem_init(void) err =3D prepare_kho_fdt(); if (err) return err; - - err =3D register_kho_notifier(&reserve_mem_kho_nb); - if (err) { - put_page(kho_fdt); - kho_fdt =3D NULL; - } - return err; } late_initcall(reserve_mem_init); --=20 2.51.0.915.g61a8936c21-goog From nobody Mon Feb 9 04:27:57 2026 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.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 DF7421E8342 for ; Wed, 22 Oct 2025 00:57:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094647; cv=none; b=hF276NaRxXkBncPjnWhjHRvWNjqMbyPEDqLf+8qJ13CzUpUt4PPWn3N+dEI4WKlFTSSlmTIGZN/Dohvr/oxYOp/Oa2mzs3Mw2/FjbgKQiB88AKffng0zKWXE3aElqO+8lQQRgpd6O808PsDUyVFJFY6O2J+hI6Qa9cbZg3bmwUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094647; c=relaxed/simple; bh=ICrvdx6JwZ+a9++79jXeIGR5Tgq/AzAu/D2kWon/kzQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n8MjvfMu9NWjSPTC5tnDJjnYGZU6rCIQvVNhe2f53blVULuHZgv29wJeh3bvBRw99u2wC1ijZhWfvBPAxvj3x0gyMfeGHKqXC764s+1ZYMuwnPJW86AJkJK4SObXwxrqP7x6Z+WFZlUGprVN0bTi3v6t0FjMB/6f3Mltqyuzl68= 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=X0sPomhC; arc=none smtp.client-ip=209.85.160.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="X0sPomhC" Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-4b109c6b9fcso5591061cf.3 for ; Tue, 21 Oct 2025 17:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1761094645; x=1761699445; 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=W+qadFBBotkNKd/oqO1HqvVbgecomYazxdkikuzLBKg=; b=X0sPomhCLY/za10BMUYzO3YCpBv6ifhfY5YBgblyYdNfZpp1rBTFv6KgMISA3PLC7n 7wdjPzDyqJrdV/IleZW0OPDf1wvPxCJvWTbvOk508wBjbDbzBpQW4o4sZyFnevg/YoaW 8Xr1aQVMKewz2KKzW/3w5ns7efMfeAR5xMKQ2cpFs/ZS+LcnzXJmcfbDY5W9TSGJ1rOJ XfG85lfKaoLqg6eeIoht5IF04oUbXOMH5ZoreFZhFqxVZnwNZl7Yn7QkRvCCP6HvjX5o Hxyh63ExI70DnHnv+vlqwa3HRt5wO06P/muW1aaI2Z6U4rnXfFKZAmQyjUZnKHSTuhvF qdiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761094645; x=1761699445; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W+qadFBBotkNKd/oqO1HqvVbgecomYazxdkikuzLBKg=; b=tdUdILPIMmdKjKuZELYLb+JqfkHEKcbxK0c5u0Qs08ZKebY8zDw3+/LjyXktZBWB/6 amchqzwgOkdWJt/oPJ+bWAl2N53TpWpudILNAjsFGUqRl0X3eec5tArOuPyZAHxwCX9n FrtPdg04R3amCI1NV+avmDcAXUTr1arLPB59QHjtxlssKTSmNTSPGLArx2+7TgBGGvdT aEL+MCjtHFcdMOWK0HMzDOCfor6sACuJJuM4GQt61dWnwW3z1LzeogjG8r2aiR75eAaz 49Pb7thGJ23OR7zVGqwio8O3RcRQb30DsQnohnbN//X6C95kpfNE8OsIxqTSKywdIfv7 h0Tw== X-Forwarded-Encrypted: i=1; AJvYcCU3lVdtVw9IFy0a4IL3Tll2fZeJGJiKPKAM7AIVosfaknLzvOOpB5FNy5aNM3xWAQb3Pkts3k/XST2K9Zc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2Gt5wl/+IpJGKPN/bRZ2yN3uCPHNRLXD0+b16+9HQtTWlBHvr l0aMkMoJkGLbc1iDOTpKuqJQ8Ii6rRMe9gNs24lk6f0iBehfwWzqhxP3cEIVW+bzmGs= X-Gm-Gg: ASbGncuS/W4SFu9vyTOT1kv1crpRqom4hHM2gUJa2GZEpt+E9tXABNJzgJV5NbwRgsa 16iymDxIQIY+kzW/YxMdTat6TO0H5xhcibv0P5XB8faHruNYqWfreXVPK6JiRyCq/74fi/4leVu B7bSqHmr+NLSgt4rkEL19c6eWAb+yLK4if+D+QSyHFS3jW2+LbUUZkgi3IAxX0XCPKl9kgYAtKB c+b7KCXEweJ5menQ+plVwyLkQfRFluF5PgGTBcqHbJS/HpE5pyQYjdK+QEPlCBM5Kl7aqp3XLK7 4DajCSzjRJL6AIL/2nvDmL6H8UbpaytMz2qnpoUG7putjMQtwWruN8HP8w6/XSTNGdUmGXBzQbP PZfEZs6B6XM+JyywgkpVZjey44Y4I1rDGaU4hlfRY4UeFbPBfXK05IKbZfRHadaM3Rwk+maD4OJ JCvZU/aOrH0Q35LT76cj+2VdqoqX+ZKwd4gHjQ2aL2fu614VlyyZxNr7OfLIplVTc6orJEYx2K8 0AxzAerIImA/tJOyRyFuhaugTNU8z3l X-Google-Smtp-Source: AGHT+IEbvWQwrifIahe6E5wZ3o39RE/3lexOa2z4QGwcdffIuvb1yOyb5Y/9vOdhLrPU2DTeJO1H3Q== X-Received: by 2002:a05:622a:1206:b0:4e8:b23e:8558 with SMTP id d75a77b69052e-4ea0dea50e5mr93304831cf.77.1761094644824; Tue, 21 Oct 2025 17:57:24 -0700 (PDT) Received: from soleen.us-east4-b.c.cloudtop-prod-us-east.internal (53.47.86.34.bc.googleusercontent.com. [34.86.47.53]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4e8aaf3432dsm84169501cf.2.2025.10.21.17.57.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 17:57:24 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, brauner@kernel.org, corbet@lwn.net, graf@amazon.com, jgg@ziepe.ca, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, masahiroy@kernel.org, ojeda@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, rdunlap@infradead.org, rppt@kernel.org, tj@kernel.org Subject: [PATCHv7 4/7] kho: add interfaces to unpreserve folios and page ranges Date: Tue, 21 Oct 2025 20:57:16 -0400 Message-ID: <20251022005719.3670224-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.51.0.915.g61a8936c21-goog In-Reply-To: <20251022005719.3670224-1-pasha.tatashin@soleen.com> References: <20251022005719.3670224-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" Allow users of KHO to cancel the previous preservation by adding the necessary interfaces to unpreserve folio and pages. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- include/linux/kexec_handover.h | 12 +++++ kernel/kexec_handover.c | 85 ++++++++++++++++++++++++++++------ 2 files changed, 84 insertions(+), 13 deletions(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 2faf290803ce..4ba145713838 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -43,7 +43,9 @@ 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); 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); struct folio *kho_restore_folio(phys_addr_t phys); struct page *kho_restore_pages(phys_addr_t phys, unsigned int nr_pages); @@ -76,11 +78,21 @@ 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 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 int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation) { diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index 0a4234269fe5..8412897385ad 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -157,26 +157,33 @@ static void *xa_load_or_alloc(struct xarray *xa, unsi= gned long index) return no_free_ptr(elm); } =20 -static void __kho_unpreserve(struct kho_mem_track *track, unsigned long pf= n, - unsigned long end_pfn) +static void __kho_unpreserve_order(struct kho_mem_track *track, unsigned l= ong pfn, + unsigned int order) { struct kho_mem_phys_bits *bits; struct kho_mem_phys *physxa; + const unsigned long pfn_high =3D pfn >> order; =20 - while (pfn < end_pfn) { - const unsigned int order =3D - min(count_trailing_zeros(pfn), ilog2(end_pfn - pfn)); - const unsigned long pfn_high =3D pfn >> order; + physxa =3D xa_load(&track->orders, order); + if (!physxa) + return; + + bits =3D xa_load(&physxa->phys_bits, pfn_high / PRESERVE_BITS); + if (!bits) + return; =20 - physxa =3D xa_load(&track->orders, order); - if (!physxa) - continue; + clear_bit(pfn_high % PRESERVE_BITS, bits->preserve); +} + +static void __kho_unpreserve(struct kho_mem_track *track, unsigned long pf= n, + unsigned long end_pfn) +{ + unsigned int order; =20 - bits =3D xa_load(&physxa->phys_bits, pfn_high / PRESERVE_BITS); - if (!bits) - continue; + while (pfn < end_pfn) { + order =3D min(count_trailing_zeros(pfn), ilog2(end_pfn - pfn)); =20 - clear_bit(pfn_high % PRESERVE_BITS, bits->preserve); + __kho_unpreserve_order(track, pfn, order); =20 pfn +=3D 1 << order; } @@ -749,6 +756,30 @@ int kho_preserve_folio(struct folio *folio) } EXPORT_SYMBOL_GPL(kho_preserve_folio); =20 +/** + * kho_unpreserve_folio - unpreserve a folio. + * @folio: folio to unpreserve. + * + * 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) +{ + 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; + + if (kho_out.finalized) + return -EBUSY; + + __kho_unpreserve_order(track, pfn, order); + return 0; +} +EXPORT_SYMBOL_GPL(kho_unpreserve_folio); + /** * kho_preserve_pages - preserve contiguous pages across kexec * @page: first page in the list. @@ -793,6 +824,34 @@ int kho_preserve_pages(struct page *page, unsigned int= nr_pages) } EXPORT_SYMBOL_GPL(kho_preserve_pages); =20 +/** + * kho_unpreserve_pages - unpreserve contiguous pages. + * @page: first page in the list. + * @nr_pages: number of pages. + * + * Instructs KHO to unpreserve @nr_pages contigious pages starting from @= page. + * This call must exactly match a granularity at which memory was original= ly + * preserved by kho_preserve_pages, call with the same @page and + * @nr_pages). Unpreserving arbitrary sub-ranges of larger preserved block= s is + * not supported. + * + * Return: 0 on success, error code on failure + */ +int 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; + + if (kho_out.finalized) + return -EBUSY; + + __kho_unpreserve(track, start_pfn, end_pfn); + + return 0; +} +EXPORT_SYMBOL_GPL(kho_unpreserve_pages); + struct kho_vmalloc_hdr { DECLARE_KHOSER_PTR(next, struct kho_vmalloc_chunk *); }; --=20 2.51.0.915.g61a8936c21-goog From nobody Mon Feb 9 04:27:57 2026 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 F21F81F181F for ; Wed, 22 Oct 2025 00:57:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094648; cv=none; b=lyMzp/NkN1J9QbrmTAh3WmLDfhLjGBhpBKug7igWPrZQap50d6VBcRRFhwjWJrE9bX8eiHh0RS5tGB8RYDAiRb6qEttFUpDXfLtDAr2pANvz/EFqNmGE9e5XQCxm5c7/LXAkI1sqDOWKQHrk9yeTPbXyo+G7OOgKRzXVV6f2Kos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094648; c=relaxed/simple; bh=NGuveJk2P3XFlSgQ+moH+HF3wVf2P/A5UKylVtCRxfA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IpSJGf0AX/kxiFPl5hoxS2lltaZ8HPpasRQkVUf/X3zApZIUzt3z+iJeWoe6gqL8/IRtvoxiYk4vsmonxKiUIHX+yyznURp+sJvzhyHzBcpwmSUAAJXCQT20b6oavdZP9sKv+DlsrTq+WyLjhSBw+KcVcgJpWf6YjhDVkv2pTVE= 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=cjgtpnfJ; arc=none smtp.client-ip=209.85.160.180 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="cjgtpnfJ" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-4e89e689ec7so3607271cf.2 for ; Tue, 21 Oct 2025 17:57:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1761094646; x=1761699446; 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=mUTWKaAwDcLFEMDYOAPCNVz4GAFYSZN3Yq9aKSos2/I=; b=cjgtpnfJRQRa0bR+LN65GdHPNb2c+9dUntXfHLpWv+8cyIyvM8XpICbmsqZxj5NesR XD7Za7ot4g2AEsZdBEI6CtZuizwnk4hK5vtXgndS1uR7qfWQBfquLyfCY6zaq8CaBoRb J3kgAsRRE8rsk7QnEZ58P1seDxEXGRCAPTIyT12Xnity67H7/Ywxn36v9MygPQ3bIFy9 a3pCB2suUME9/DBJDOaGJhtF3hW2NNl5cH2D7DXYGk2UOoekDN95jl57wpNIPDFZJQWm w/Vj8BgdezUFJTNd1hcf5RnPa/O1Q+IQysNpBn4dPzLdFLFWT6E6WvY/mo7xQLaInvXL VAyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761094646; x=1761699446; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mUTWKaAwDcLFEMDYOAPCNVz4GAFYSZN3Yq9aKSos2/I=; b=IpvN/Ci640cRQ1QwZPCYcQDMLCAD6kVsOll3bZKHweVI0cvLPtKumY1QtsMH3XBKL+ qlarIgGjFUuGY2/LjqSk0e3P4btROUe2KLKY6v63oE9y7XuQ5IQVBXuU5f/Jm08J/2Mi EXTo2LCAn/q7q5RzK2ev6PkiSXInRUZC6HN314tU5IDRfSl2RyQT3CZ88eqU/oxI6duW U9KyfAi2c+ZbOVe5ekqlpaXk7niSoplLBO7b/Uews2kJpXwcv7ySUHGY5pL9px5WuEN/ oZDCaHhmhz7t1bbxMc1DDOt9uETgqTV8HQgY219uY1s0cGQzpE6hZjSBYPoZPJmPmOwF MhZg== X-Forwarded-Encrypted: i=1; AJvYcCWVFQa2arQISVP26Uzr6LWnsNQWnisdJUinQf1aw5KkJ6OkrAhUanzDimJ63BlMsFzgnAUMOFTh46xbBIc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1lWjPnVse6xCVqsAOnaPVETcOBawEDh2NY7GFJvz0BdM6L/L9 cnqJuz//BU6JiHGIXxStwIcLB9NR+L18HdXCTRMRxnlP1vH+oIz6TtHNxWgRZcyFAMQ= X-Gm-Gg: ASbGncuw0PipZARWTeSFIvD5bicQVjmNjiESnoweuUDjLWEq2RiUPLT3mNECN8nPnU6 R0Dxn/dbrvMK+MhEVYfWTLnkRzuKkj0ZRBCdUyDNPFkLDO7wszk4rvE7JQaAqdGdba+qhoBGMK0 Aoi/crXKTeSbjefW6tTOojraPR/gDzWAfEH523Z/IF+k5YciKyQSB+ODRLU0S+g9NoiWuaFeQ6r IyxYj+61Gp0J4NrA/26t5Yy3Yq013YBaU/UyjerePi+Zllc0xiJvWabmg41Ox1ipgzEkA+c/WVg 1eB5DtMkqKS+ce10TeM8h0gR/hTA7KAV3I1Qserc/o6PFUFs+9v639vU1WUC8bmpanWk96G1SdV bn9DEjxKtQ8PhNkaIVhVJB2Qmwv0OwVQav5+KLitQFnOeVaNgWZCCAAGp0u76nXNXBJQQy3h0L7 DuX7pEiN07+7mrQNDBAAAJxd9htEA/P1Jm+iPyC22escyTqxHLtNeb17mvAU8tSlFEkLDORh25U M014hP6BQ4Wmu5IwN+uSQ== X-Google-Smtp-Source: AGHT+IHQH5S7ZkBo/f+yTi+bMGIOL+QuMwmJCvKKYbXx1vIv8VH/9TwZ606gNIBVjYEELqz69qTPIg== X-Received: by 2002:a05:622a:110:b0:4e4:6b32:697a with SMTP id d75a77b69052e-4e8b6e0b299mr139105201cf.29.1761094645817; Tue, 21 Oct 2025 17:57:25 -0700 (PDT) Received: from soleen.us-east4-b.c.cloudtop-prod-us-east.internal (53.47.86.34.bc.googleusercontent.com. [34.86.47.53]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4e8aaf3432dsm84169501cf.2.2025.10.21.17.57.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 17:57:25 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, brauner@kernel.org, corbet@lwn.net, graf@amazon.com, jgg@ziepe.ca, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, masahiroy@kernel.org, ojeda@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, rdunlap@infradead.org, rppt@kernel.org, tj@kernel.org Subject: [PATCHv7 5/7] kho: don't unpreserve memory during abort Date: Tue, 21 Oct 2025 20:57:17 -0400 Message-ID: <20251022005719.3670224-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.51.0.915.g61a8936c21-goog In-Reply-To: <20251022005719.3670224-1-pasha.tatashin@soleen.com> References: <20251022005719.3670224-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" KHO allows clients to preserve memory regions at any point before the KHO state is finalized. The finalization process itself involves KHO performing its own actions, such as serializing the overall preserved memory map. If this finalization process is aborted, the current implementation destroys KHO's internal memory tracking structures (`kho_out.ser.track.orders`). This behavior effectively unpreserves all memory from KHO's perspective, regardless of whether those preservations were made by clients before the finalization attempt or by KHO itself during finalization. This premature unpreservation is incorrect. An abort of the finalization process should only undo actions taken by KHO as part of that specific finalization attempt. Individual memory regions preserved by clients prior to finalization should remain preserved, as their lifecycle is managed by the clients themselves. These clients might still need to call kho_unpreserve_folio() or kho_unpreserve_phys() based on their own logic, even after a KHO finalization attempt is aborted. Signed-off-by: Pasha Tatashin Reviewed-by: Pratyush Yadav --- kernel/kexec_handover.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index 8412897385ad..89a3fa89db0a 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -1103,31 +1103,12 @@ EXPORT_SYMBOL_GPL(kho_restore_vmalloc); =20 static int __kho_abort(void) { - int err =3D 0; - unsigned long order; - struct kho_mem_phys *physxa; - - xa_for_each(&kho_out.track.orders, order, physxa) { - struct kho_mem_phys_bits *bits; - unsigned long phys; - - xa_for_each(&physxa->phys_bits, phys, bits) - kfree(bits); - - xa_destroy(&physxa->phys_bits); - kfree(physxa); - } - xa_destroy(&kho_out.track.orders); - if (kho_out.preserved_mem_map) { kho_mem_ser_free(kho_out.preserved_mem_map); kho_out.preserved_mem_map =3D NULL; } =20 - if (err) - pr_err("Failed to abort KHO finalization: %d\n", err); - - return err; + return 0; } =20 int kho_abort(void) --=20 2.51.0.915.g61a8936c21-goog From nobody Mon Feb 9 04:27:57 2026 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.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 1AED51F5851 for ; Wed, 22 Oct 2025 00:57:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094650; cv=none; b=u8FuOtTooeiDbqTOJUaQVEi8C5dX2Q7zdkVm9JdnGMFmM2SR0g2i/sZJ8AS1LiDlZJDxoiz7l/HsSE6puM5X+yfzvYWnMbmVE9yQpyoRCSnkU8mzrgv++LrY+CpN3mljxSxzxMt7obdSSy0cGmQJBfWD4plbeaAPafz4T3B5DrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094650; c=relaxed/simple; bh=NmbTUiBeJIAp3Sftn5nSMFfqUDzv5mGL6pZj0cOMllg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DEgpiP1hYEKt4sn2Urs+dey83oMGHs8hd18foLbkoatVCPMPCATHdB8V2OSzNlIb8Pwcg6+cs57h65JOKjpksTDfM8LJi7csCEQMkpvcyTVokvztNa2nsW5do0mcHNKQHVA/4lZWXRxUg+54ZnPT65ou464HZGSp0rTzbBjEo7U= 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=lFRqTJQD; arc=none smtp.client-ip=209.85.160.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="lFRqTJQD" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-4e88cacc5d9so4612801cf.0 for ; Tue, 21 Oct 2025 17:57:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1761094647; x=1761699447; 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=Mkf+L3c0j3AWYDNtEMZGYy1f4Qen54RZIiHrdIXZ3Iw=; b=lFRqTJQDdisTf6d7Rqaba4I6QNt+aSqtFwpcD9nPvByFPkctF7bKExi+aPYQArmRH2 X5KgELMLyBuqCTc0IZLf2HhgM3621A1C37h5UNKqKWYtcibwTOmiZFI/dv1bpnHnH/2d NisBpessdA94i8Uop5Ubfq8KBx+nQHkIeAqrdvYzauOPE7i3TboJ15Pl1lKj+XBA4jcR XoqncwSFPsZ3OYm6f8IWQ4WKPETncnTV2L3GnLVcRRalzWqbd194Mb9+GuUjavmXdvtP JxR4BD5SfMG/lQTRTlNGgqUYHDoAH4crqzOoWAMYz2iT+Qau6xFh+y8v5H1cOiKn3qL7 hLFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761094647; x=1761699447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Mkf+L3c0j3AWYDNtEMZGYy1f4Qen54RZIiHrdIXZ3Iw=; b=LkM6Z0hIavTqrxe0/DQSO5nf3ZJzYPJB0owAVBxjnWBfs4XezGDuhzVa5q6LiVGjUu MksTkfmZhRUvWAYvsrrv5How8aANxNHxPm4tOOhClgbwzN7p9g3kqAp4q6QasCcK4OTv ATMpYxXIBLtDL7lxvyDuFaXZ67DEn16KWwgIW/QUqZyp3ruwjwWvN3G/jiAK1Lp+WMoz 3yRkY0TRdziyA3uFw1ZiK2nbHOR8ZqLMvq6tG8P/4yIC762OtlahR8dwCyXurJBVQuee OdunACtq7g40mn/2Ns8vEzd7qTNxBLNdBJEk6zhtozrnYrSkJRoG2/Jskq88boTgf8hq SFvw== X-Forwarded-Encrypted: i=1; AJvYcCVx70DnTyVkPOY95R3AqX0479IldQWH4LH0Ewnzt8wx9PCREZFgURHFy3Q+p4igYkhdwcA6ahYo1jiwWY8=@vger.kernel.org X-Gm-Message-State: AOJu0YzlAlZwnZfNV6wZ1QFmau+cVimeKqj6saYzL/wTxqD11UbabZra 8M85o6sZCvRQfdQQqP3TCmctbWjIM6YtBOH/eFjlbudePMnKH8h/KWoUwI5SdMOCF8s= X-Gm-Gg: ASbGncushVEcam2m5KJo7Ao1cVBYQ5zYXtPBFYYmZUrfZtiLbRp/0iaz1AdqxCHrP0U Tkwbl/yZwefUAmUSONBkgis40UDhTH7rYgbjPLuOuAZyoJwkgMWDWO0tLN5l4ihK7nY9qpSYPr0 cif8XI/YDma33Qpp0cIuponEBd3+DlQbt6JVa3AWMi3CpE/YAD721JjJYuIN5iSvPDtsLRmqEGH 1J9T9ZobPnR1eNo80S8QI1WNput05Z3e5o3vh4UlgZaT5IYh4UyeLbyqNX8suZYMaPMmdkR3+5a guH8LxS6rrNaM2l6Ss3s4hbAyms/ED7ItJjGa/PIOrz4QjsXuzDoMz4AqIACVygzOm3MeLjvly2 DRIA0xygZNyj26QFnqDTWoAp9x7WlVfDszL+XVRTVH7oH9yNd1MLVtXDiISXYGde0ZivqZtjcsu sqJ4iwmn7MqkgMm4kQ2VCEBVE9cuIKzVdTK/KQ0hjZsjbKKxJEV9qibU9Sf27juOyImWJ14zru6 0dM7dHmlkRKTfN9YUw5DcFNAHDMCt85 X-Google-Smtp-Source: AGHT+IEq405mhVu8WrJEowIq1Y0TON8S9urCYucYQMKi2jjKbXRB8hoU3h4s0GEYArtyzYzgjkDVKw== X-Received: by 2002:ac8:57c2:0:b0:4b5:f6c5:cfc with SMTP id d75a77b69052e-4e89d274b1dmr235263421cf.19.1761094646848; Tue, 21 Oct 2025 17:57:26 -0700 (PDT) Received: from soleen.us-east4-b.c.cloudtop-prod-us-east.internal (53.47.86.34.bc.googleusercontent.com. [34.86.47.53]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4e8aaf3432dsm84169501cf.2.2025.10.21.17.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 17:57:26 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, brauner@kernel.org, corbet@lwn.net, graf@amazon.com, jgg@ziepe.ca, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, masahiroy@kernel.org, ojeda@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, rdunlap@infradead.org, rppt@kernel.org, tj@kernel.org Subject: [PATCHv7 6/7] liveupdate: kho: move to kernel/liveupdate Date: Tue, 21 Oct 2025 20:57:18 -0400 Message-ID: <20251022005719.3670224-7-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.51.0.915.g61a8936c21-goog In-Reply-To: <20251022005719.3670224-1-pasha.tatashin@soleen.com> References: <20251022005719.3670224-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" Move KHO to kernel/liveupdate/ in preparation of placing all Live Update core kernel related files to the same place. Signed-off-by: Pasha Tatashin Reviewed-by: Jason Gunthorpe Reviewed-by: Mike Rapoport (Microsoft) --- Documentation/core-api/kho/concepts.rst | 2 +- MAINTAINERS | 2 +- init/Kconfig | 2 + kernel/Kconfig.kexec | 34 ---------------- kernel/Makefile | 4 +- kernel/liveupdate/Kconfig | 39 +++++++++++++++++++ kernel/liveupdate/Makefile | 5 +++ kernel/{ =3D> liveupdate}/kexec_handover.c | 4 +- .../{ =3D> liveupdate}/kexec_handover_debug.c | 0 .../{ =3D> liveupdate}/kexec_handover_debugfs.c | 0 .../kexec_handover_internal.h | 0 11 files changed, 51 insertions(+), 41 deletions(-) create mode 100644 kernel/liveupdate/Kconfig create mode 100644 kernel/liveupdate/Makefile rename kernel/{ =3D> liveupdate}/kexec_handover.c (99%) rename kernel/{ =3D> liveupdate}/kexec_handover_debug.c (100%) rename kernel/{ =3D> liveupdate}/kexec_handover_debugfs.c (100%) rename kernel/{ =3D> liveupdate}/kexec_handover_internal.h (100%) diff --git a/Documentation/core-api/kho/concepts.rst b/Documentation/core-a= pi/kho/concepts.rst index 36d5c05cfb30..d626d1dbd678 100644 --- a/Documentation/core-api/kho/concepts.rst +++ b/Documentation/core-api/kho/concepts.rst @@ -70,5 +70,5 @@ in the FDT. That state is called the KHO finalization pha= se. =20 Public API =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -.. kernel-doc:: kernel/kexec_handover.c +.. kernel-doc:: kernel/liveupdate/kexec_handover.c :export: diff --git a/MAINTAINERS b/MAINTAINERS index 0a6ba2717caa..eae55bb6ab4d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13781,7 +13781,7 @@ S: Maintained F: Documentation/admin-guide/mm/kho.rst F: Documentation/core-api/kho/* F: include/linux/kexec_handover.h -F: kernel/kexec_handover* +F: kernel/liveupdate/kexec_handover* F: tools/testing/selftests/kho/ =20 KEYS-ENCRYPTED diff --git a/init/Kconfig b/init/Kconfig index cab3ad28ca49..0605de5d96c0 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2138,6 +2138,8 @@ config TRACEPOINTS =20 source "kernel/Kconfig.kexec" =20 +source "kernel/liveupdate/Kconfig" + endmenu # General setup =20 source "arch/Kconfig" diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec index 9308a0fb1419..15632358bcf7 100644 --- a/kernel/Kconfig.kexec +++ b/kernel/Kconfig.kexec @@ -94,40 +94,6 @@ config KEXEC_JUMP Jump between original kernel and kexeced kernel and invoke code in physical address mode via KEXEC =20 -config KEXEC_HANDOVER - bool "kexec handover" - depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE - depends on !DEFERRED_STRUCT_PAGE_INIT - select MEMBLOCK_KHO_SCRATCH - select KEXEC_FILE - select DEBUG_FS - select LIBFDT - select CMA - help - Allow kexec to hand over state across kernels by generating and - passing additional metadata to the target kernel. This is useful - to keep data or state alive across the kexec. For this to work, - both source and target kernels need to have this option enabled. - -config KEXEC_HANDOVER_DEBUG - bool "Enable Kexec Handover debug checks" - depends on KEXEC_HANDOVER_DEBUGFS - help - This option enables extra sanity checks for the Kexec Handover - subsystem. Since, KHO performance is crucial in live update - scenarios and the extra code might be adding overhead it is - only optionally enabled. - -config KEXEC_HANDOVER_DEBUGFS - bool "kexec handover debugfs interface" - depends on KEXEC_HANDOVER - depends on DEBUG_FS - help - Allow to control kexec handover device tree via debugfs - interface, i.e. finalize the state or aborting the finalization. - Also, enables inspecting the KHO fdt trees with the debugfs binary - blobs. - config CRASH_DUMP bool "kernel crash dumps" default ARCH_DEFAULT_CRASH_DUMP diff --git a/kernel/Makefile b/kernel/Makefile index 2cf7909a74e5..e83669841b8c 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -52,6 +52,7 @@ obj-y +=3D printk/ obj-y +=3D irq/ obj-y +=3D rcu/ obj-y +=3D livepatch/ +obj-y +=3D liveupdate/ obj-y +=3D dma/ obj-y +=3D entry/ obj-y +=3D unwind/ @@ -82,9 +83,6 @@ obj-$(CONFIG_CRASH_DUMP_KUNIT_TEST) +=3D crash_core_test.o obj-$(CONFIG_KEXEC) +=3D kexec.o obj-$(CONFIG_KEXEC_FILE) +=3D kexec_file.o obj-$(CONFIG_KEXEC_ELF) +=3D kexec_elf.o -obj-$(CONFIG_KEXEC_HANDOVER) +=3D kexec_handover.o -obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) +=3D kexec_handover_debug.o -obj-$(CONFIG_KEXEC_HANDOVER_DEBUGFS) +=3D kexec_handover_debugfs.o obj-$(CONFIG_BACKTRACE_SELF_TEST) +=3D backtracetest.o obj-$(CONFIG_COMPAT) +=3D compat.o obj-$(CONFIG_CGROUPS) +=3D cgroup/ diff --git a/kernel/liveupdate/Kconfig b/kernel/liveupdate/Kconfig new file mode 100644 index 000000000000..ae8bdd87458a --- /dev/null +++ b/kernel/liveupdate/Kconfig @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0-only + +menu "Live Update and Kexec HandOver" + +config KEXEC_HANDOVER + bool "kexec handover" + depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE + depends on !DEFERRED_STRUCT_PAGE_INIT + select MEMBLOCK_KHO_SCRATCH + select KEXEC_FILE + select DEBUG_FS + select LIBFDT + select CMA + help + Allow kexec to hand over state across kernels by generating and + passing additional metadata to the target kernel. This is useful + to keep data or state alive across the kexec. For this to work, + both source and target kernels need to have this option enabled. + +config KEXEC_HANDOVER_DEBUG + bool "Enable Kexec Handover debug checks" + depends on KEXEC_HANDOVER_DEBUGFS + help + This option enables extra sanity checks for the Kexec Handover + subsystem. Since, KHO performance is crucial in live update + scenarios and the extra code might be adding overhead it is + only optionally enabled. + +config KEXEC_HANDOVER_DEBUGFS + bool "kexec handover debugfs interface" + depends on KEXEC_HANDOVER + depends on DEBUG_FS + help + Allow to control kexec handover device tree via debugfs + interface, i.e. finalize the state or aborting the finalization. + Also, enables inspecting the KHO fdt trees with the debugfs binary + blobs. + +endmenu diff --git a/kernel/liveupdate/Makefile b/kernel/liveupdate/Makefile new file mode 100644 index 000000000000..f52ce1ebcf86 --- /dev/null +++ b/kernel/liveupdate/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_KEXEC_HANDOVER) +=3D kexec_handover.o +obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) +=3D kexec_handover_debug.o +obj-$(CONFIG_KEXEC_HANDOVER_DEBUGFS) +=3D kexec_handover_debugfs.o diff --git a/kernel/kexec_handover.c b/kernel/liveupdate/kexec_handover.c similarity index 99% rename from kernel/kexec_handover.c rename to kernel/liveupdate/kexec_handover.c index 89a3fa89db0a..a1b97cc37cea 100644 --- a/kernel/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -26,8 +26,8 @@ * KHO is tightly coupled with mm init and needs access to some of mm * internal APIs. */ -#include "../mm/internal.h" -#include "kexec_internal.h" +#include "../../mm/internal.h" +#include "../kexec_internal.h" #include "kexec_handover_internal.h" =20 #define KHO_FDT_COMPATIBLE "kho-v1" diff --git a/kernel/kexec_handover_debug.c b/kernel/liveupdate/kexec_handov= er_debug.c similarity index 100% rename from kernel/kexec_handover_debug.c rename to kernel/liveupdate/kexec_handover_debug.c diff --git a/kernel/kexec_handover_debugfs.c b/kernel/liveupdate/kexec_hand= over_debugfs.c similarity index 100% rename from kernel/kexec_handover_debugfs.c rename to kernel/liveupdate/kexec_handover_debugfs.c diff --git a/kernel/kexec_handover_internal.h b/kernel/liveupdate/kexec_han= dover_internal.h similarity index 100% rename from kernel/kexec_handover_internal.h rename to kernel/liveupdate/kexec_handover_internal.h --=20 2.51.0.915.g61a8936c21-goog From nobody Mon Feb 9 04:27:57 2026 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (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 EBC6F1FE47C for ; Wed, 22 Oct 2025 00:57:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094650; cv=none; b=RZCLvvEWS3EsLN50fp2NipQI7IdIJJtmD6Wh4CLzu8k2cfBlqJ1nMTYfBmINQfwdzI3IJbLA6kft5Ko4qPV62DLdC6P7b5M6I+80tzaQTlBoVO4XS3YDRLo2VYnTZGJJ0Rt3VwislnGr26GVnCCZwjTcS3EcM/UNDWRreTHincE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761094650; c=relaxed/simple; bh=rDk7y3w4IR2m5puAiIrkuPe+hYp57EQM6DHhAf+5F9U=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jw082LX/qJnVJUD2RmRs/OHxoF2FRo74M5luy52R994CHOWIPFbIkuB9lsY+yVjRPCLdfQ/yyuE0zYjKyJ+dbgjdLX2F9Ig/ISxGtfAV1PZasCfsunAx2b43ci6q8g9Xm81Et3Wdd5TpwUfrlmo0C7n2p7Q2KigcuhSJLjwDIeQ= 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=F0MoXSj9; arc=none smtp.client-ip=209.85.160.173 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="F0MoXSj9" Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-4e89183fe47so5307231cf.2 for ; Tue, 21 Oct 2025 17:57:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1761094648; x=1761699448; 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=Pcy9ROlMFFrxYmRYWOB+KoxotgZLEgmv04f04lRuCLg=; b=F0MoXSj9PuNjYQPKxdf2O0UytO+qmDlZ5fSk2mOquUKlDDH7Rn4Toc9s4miLMc9cJV Uhk9r2z2kB8++EQI+Vr3OgWXWlqd6MxFi7ZstARpy356hQ8EdAaHgTP6/0gokYBcAWXd tCNR+0tSk7AdmDZA7ayYzUJUYyCIsPzdxEg0fehN9iydwRMY1o4ut4mqxtA3OBdPL81B TWphsMlj/gUpUV4ocath0eNximfZEMGMYdsd5mvlTxXl2OpYhnvMxRaPcM+CAAwAO8L3 vdHKPT4KFw12pkH4fQlc3pYurEF/s8+OTdpaP4MHC/1WhKxjQ6xc59IG084Q3yUCrqNZ SxZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761094648; x=1761699448; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pcy9ROlMFFrxYmRYWOB+KoxotgZLEgmv04f04lRuCLg=; b=IJz1xfgfnm8cCiBbk8xyclNYff7TxtFAb07azTcx7p+Bg2yZ7IAon0klEeCyNhkjPC zWIqzkWNL7ZbKfquQXeGS6bhFC/89F8WKTyp9aLD83RO01vDMAz+fOkMfepH2laE+S91 KcSLwS+bI4F2lYduqP+NWtdlzSt16BIct6gn4GEx+0DXXlL/JVq8pQIdVQK3S5g/wSF1 a+kKEHx5b8W0fz4GGDn1hSks2Ls3PSnKj8VZ9e2OEG833TR+jSXlQkW/PrbB8OTaiXCr iAVFmaz0mNP/8nyNk6/kZldvkVclsuRizNnCh6iDjrXiSqDniTiyAuS+tvI9lza0bhis 42gQ== X-Forwarded-Encrypted: i=1; AJvYcCW2IAL106PojLQR74d0oiOcFf2YVl9G0ER448kOUSyU+5tRQhs/rm82FkiaELsFVOv06NNX8xkDzDPRprw=@vger.kernel.org X-Gm-Message-State: AOJu0YxWbfzLbcrqClbXUuzXKYukapBWQwCnOIEmFtgOZMdaGhQWzENp wIUghQcMpiu+Ghpzsm6JnLrVgQR6UpXFD127Zpw9dzq7ukKWaIc0XxvO1ynkjArEqpM= X-Gm-Gg: ASbGncuRiW5USkue37L2HecnLpzKP/lMgQU/2EU4WKTSUAWV9iGN4iC/1SqgzygrxfB a5a2xQAbnSwHLvrTFiFxwtTq7gSmN9MuX3ynV6d2oTs5Eeb97alq5Bbgoa+l+8osu80xEvWLnUk e22KjxgE27E80T3HUSJoKksVwH0gP+UdaVEWuLpuDZPlb5TKexFX8Tvh7wh4AqhthWlilHrwG3F Owx5MT6VJX6u20g2iRtTgxOY5Ai5GDq/EWbEpA/IZd8Gt0AzkVxWrPwWNK7PO/x2yBETJT476jb kOdwO93WRTCqO0culfY18L9ONfqqJB5bHwHR9DnVFKOlLW3JkhzhAXNcUsEVPA6+Bnt8EqOwwLv iIlcMq+2uT3R7HhXph9VpMvh18IEUaxktAOSePQG5BtWArt3Xqpua5vLxssLoc7HEDXiAqobK6B 3vednq8giXeUw3HoXPX+X3kUmLtb4zHZjTWcM+aG/G0QnrFtMlQpXRq3KZ+kNGY5GYYFEhVQvyE r3Pi124Du4H6ICIr+rpnw== X-Google-Smtp-Source: AGHT+IE6c9SGq1VaL57v0krF0Yo2JROYiPXfKdfjnZS+o2r+gBektScJV8dUmdmPm+e/5KTw56WryA== X-Received: by 2002:ac8:7c54:0:b0:4e8:b3cf:b9fa with SMTP id d75a77b69052e-4e8b3cfbabdmr154195831cf.29.1761094647906; Tue, 21 Oct 2025 17:57:27 -0700 (PDT) Received: from soleen.us-east4-b.c.cloudtop-prod-us-east.internal (53.47.86.34.bc.googleusercontent.com. [34.86.47.53]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4e8aaf3432dsm84169501cf.2.2025.10.21.17.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 17:57:27 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, brauner@kernel.org, corbet@lwn.net, graf@amazon.com, jgg@ziepe.ca, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, masahiroy@kernel.org, ojeda@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, rdunlap@infradead.org, rppt@kernel.org, tj@kernel.org Subject: [PATCHv7 7/7] liveupdate: kho: move kho debugfs directory to liveupdate Date: Tue, 21 Oct 2025 20:57:19 -0400 Message-ID: <20251022005719.3670224-8-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.51.0.915.g61a8936c21-goog In-Reply-To: <20251022005719.3670224-1-pasha.tatashin@soleen.com> References: <20251022005719.3670224-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" Now, that LUO and KHO both live under kernel/liveupdate, it makes sense to also move the kho debugfs files to liveupdate/ The old names: /sys/kernel/debug/kho/out/ /sys/kernel/debug/kho/in/ The new names: /sys/kernel/debug/liveupdate/kho_out/ /sys/kernel/debug/liveupdate/kho_in/ Also, export the liveupdate_debufs_root, so future LUO selftests could use it as well. Signed-off-by: Pasha Tatashin --- kernel/liveupdate/kexec_handover_debugfs.c | 10 +++++----- kernel/liveupdate/kexec_handover_internal.h | 2 ++ tools/testing/selftests/kho/init.c | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/kernel/liveupdate/kexec_handover_debugfs.c b/kernel/liveupdate= /kexec_handover_debugfs.c index 46e9e6c0791f..454b7d34ddc3 100644 --- a/kernel/liveupdate/kexec_handover_debugfs.c +++ b/kernel/liveupdate/kexec_handover_debugfs.c @@ -15,7 +15,7 @@ #include #include "kexec_handover_internal.h" =20 -static struct dentry *debugfs_root; +struct dentry *liveupdate_debugfs_root; =20 struct fdt_debugfs { struct list_head list; @@ -118,7 +118,7 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg= , const void *fdt) =20 INIT_LIST_HEAD(&dbg->fdt_list); =20 - dir =3D debugfs_create_dir("in", debugfs_root); + dir =3D debugfs_create_dir("kho_in", liveupdate_debugfs_root); if (IS_ERR(dir)) { err =3D PTR_ERR(dir); goto err_out; @@ -178,7 +178,7 @@ __init int kho_out_debugfs_init(struct kho_debugfs *dbg) =20 INIT_LIST_HEAD(&dbg->fdt_list); =20 - dir =3D debugfs_create_dir("out", debugfs_root); + dir =3D debugfs_create_dir("kho_out", liveupdate_debugfs_root); if (IS_ERR(dir)) return -ENOMEM; =20 @@ -212,8 +212,8 @@ __init int kho_out_debugfs_init(struct kho_debugfs *dbg) =20 __init int kho_debugfs_init(void) { - debugfs_root =3D debugfs_create_dir("kho", NULL); - if (IS_ERR(debugfs_root)) + liveupdate_debugfs_root =3D debugfs_create_dir("liveupdate", NULL); + if (IS_ERR(liveupdate_debugfs_root)) return -ENOENT; return 0; } diff --git a/kernel/liveupdate/kexec_handover_internal.h b/kernel/liveupdat= e/kexec_handover_internal.h index 17ae101dc6ae..92798346fa5a 100644 --- a/kernel/liveupdate/kexec_handover_internal.h +++ b/kernel/liveupdate/kexec_handover_internal.h @@ -15,6 +15,8 @@ struct kho_debugfs { struct list_head fdt_list; }; =20 +extern struct dentry *liveupdate_debugfs_root; + #else struct kho_debugfs {}; #endif diff --git a/tools/testing/selftests/kho/init.c b/tools/testing/selftests/k= ho/init.c index 6d9e91d55d68..f0136a30ce8b 100644 --- a/tools/testing/selftests/kho/init.c +++ b/tools/testing/selftests/kho/init.c @@ -11,7 +11,7 @@ /* from arch/x86/include/asm/setup.h */ #define COMMAND_LINE_SIZE 2048 =20 -#define KHO_FINALIZE "/debugfs/kho/out/finalize" +#define KHO_FINALIZE "/debugfs/liveupdate/kho_out/finalize" #define KERNEL_IMAGE "/kernel" =20 static int mount_filesystems(void) --=20 2.51.0.915.g61a8936c21-goog