From nobody Wed Oct 8 16:41:38 2025 Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (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 0CDB92F3C3F for ; Wed, 25 Jun 2025 23:18:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893527; cv=none; b=NYjzUA8dnbZ9AsXXfcH/ABJMKH6iAiYlwTqTnmPpDOzLIzIPac1UiySebasaZRd7vsOTsXSoBWUmEhwlO+RMLT5klfyXW76+5t4E8Ls2IO3ldAETgd7T/858a85vu9JRIJlTBVwoCzt9X8RJyJjYLoL9X8kaBa8ivhLZ29hMVuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893527; c=relaxed/simple; bh=f+GDZMWDZJ+VR9AGii24ODCbYkbiXkpxGsAaLIJVFdg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TyX+GLQ0lxdph07LqDDtkC/hwrydOrJdwABz59EKBwqAj1vkaStxatleFWGzBlIZVtlNoo/QhJgcEpjDciVY3R6MP6/LKlzJcO9wXxVZeSsNb2IRlK5Jz51NFwuEQ4EXGqA6c1zfhBaxgIYF1cEJseOlsJzB/a4X0SYJkCLGRPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=VxWLPP8s; arc=none smtp.client-ip=209.85.219.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="VxWLPP8s" Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-e8259b783f6so264958276.3 for ; Wed, 25 Jun 2025 16:18:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893525; x=1751498325; 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=inB1PU3JWa0vbtTol7UPnIAGavYFixpKMP3Mnwcd84A=; b=VxWLPP8sdoTqx1NZa+ByQnknb19kCXNJc4kTPASmEGQM14/7IXnhVO9f18/4xNfefP QZddIfROvU2MphkpTgwoBEcd2kNeO9Dhv7WT7xF4M2hBlbXhWDdkYpO4QaiTPpFGm2xM tYHh+DF5DTv10A22NQ8DzI+365/RBXspAo+Uygo9VjGYCtXRYTGbd4kGCU+2WX9DDUvq g2pDlhY/TdfTCGZVy2PegTcp1vVwrlVUyrXYHzFknl0iM1RJWUVBYYXeHnu5F3feqrVL fZPN2DnwYsX3hL4MAcjiMA2a2k1cvBHUWB5rWV1KWKSbrB7xaIQPuEs5+BYfaaYY9DTB cXtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893525; x=1751498325; 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=inB1PU3JWa0vbtTol7UPnIAGavYFixpKMP3Mnwcd84A=; b=iIY3Ge2Ee2n92QKYNr+9N632nUWRoo5B243zFUObMlbJSpOIjNDrf7IDF19RjRWKXQ Fclu8TOloabCZ7WK1ICQNPT5olOP+VCmLR6FUNNV7mVTISOtkF3GgU6qQ4YcRT+2DTB3 UoGWdD+v7hUzsbUzJ+9n9Vn6G8VnThkQ6GMdo3Unim9Yxb1fTe+oh3yQM9pGAD/RyxN9 yl7BkkkTI4woq6Poly43xCol5lrdNjbrzxpDby3yboI1Te8GVy/395xeINEGl0ys/RX2 zG0l372utlgtS8Wc3wNscvLmDRdUn/KEIXbpSQY06ai8FdDTkpFnb+mtDhYpLHlrxoZ0 gpkA== X-Forwarded-Encrypted: i=1; AJvYcCU3urF7TeaZepnzQIenOOoQEOMCmEeY7gXcfsdWD0kBbrSGOPyW2EqyV7DG7wMSjQqhdvUyqS8H3iuaf/Y=@vger.kernel.org X-Gm-Message-State: AOJu0YyagGucEeixpfKGoWWDAua/403ki+Whp6I7oqEUg35cTIagP+FH lZoBonxkgFv33Ymiew2NeEpMJJcj+QWlTgKxkl6xlslekFExtKQxVHy/GTyc/FQXqOI= X-Gm-Gg: ASbGncvMWLRuxBYbOBe/jVNMs9fWhVpRtWL3b1D83JaJgMiyjcTD4typ/RhRF1piIe1 XtFydPtfS3GavDrNiGfcNc3MY3ypLO/AxmScAqtY5yITHBOcliSf0XagAc0nOmuq7dGSeeZK0D9 9i92q8JYsfQNzT2YpAKsT2TuywKQIktquk0+CSMIkiIrdDzBAl6za/9IiQ4xW4MA1pEuZgkNREl VU6ZecMOSuhFAIlRZUldtnxP/xlPXbHXba0taDr62wEAw1TIW9QYxdbFUc6B4G/460GScIhPhHn 4rlc3MRNxoAtY39FgwCV2Wqd/YEBv3wMmShQ67Gn+Oi0aJ8GvM2panBqsBmMqe9kRndGeMUr3OP ZOyqOmuSZ6ECvkKH6g3+ei6Rz87D+ek46ip/BJKJuXTNTzqtB/2A7uKSIqMNXlbk= X-Google-Smtp-Source: AGHT+IHRsJtLlwzyJUd/Ox/O3krs7IL9puzl8GoqWoWuzYibrteq8e0xpTf2XL0zflmCtIomZsxpVQ== X-Received: by 2002:a05:6902:10cf:b0:e81:e333:fc38 with SMTP id 3f1490d57ef6-e8601762c25mr6548852276.19.1750893525010; Wed, 25 Jun 2025 16:18:45 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:18:44 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 01/32] kho: init new_physxa->phys_bits to fix lockdep Date: Wed, 25 Jun 2025 23:17:48 +0000 Message-ID: <20250625231838.1897085-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Lockdep shows the following warning: INFO: trying to register non-static key. The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator. [] dump_stack_lvl+0x66/0xa0 [] assign_lock_key+0x10c/0x120 [] register_lock_class+0xf4/0x2f0 [] __lock_acquire+0x7f/0x2c40 [] ? __pfx_hlock_conflict+0x10/0x10 [] ? native_flush_tlb_global+0x8e/0xa0 [] ? __flush_tlb_all+0x4e/0xa0 [] ? __kernel_map_pages+0x112/0x140 [] ? xa_load_or_alloc+0x67/0xe0 [] lock_acquire+0xe6/0x280 [] ? xa_load_or_alloc+0x67/0xe0 [] _raw_spin_lock+0x30/0x40 [] ? xa_load_or_alloc+0x67/0xe0 [] xa_load_or_alloc+0x67/0xe0 [] kho_preserve_folio+0x90/0x100 [] __kho_finalize+0xcf/0x400 [] kho_finalize+0x34/0x70 This is becase xa has its own lock, that is not initialized in xa_load_or_alloc. Modifiy __kho_preserve_order(), to properly call xa_init(&new_physxa->phys_bits); Fixes: fc33e4b44b27 ("kexec: enable KHO support for memory preservation") Signed-off-by: Pasha Tatashin --- kernel/kexec_handover.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index 5a21dbe17950..1ff6b242f98c 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -144,14 +144,35 @@ static int __kho_preserve_order(struct kho_mem_track = *track, unsigned long pfn, unsigned int order) { struct kho_mem_phys_bits *bits; - struct kho_mem_phys *physxa; + struct kho_mem_phys *physxa, *new_physxa; const unsigned long pfn_high =3D pfn >> order; =20 might_sleep(); =20 - physxa =3D xa_load_or_alloc(&track->orders, order, sizeof(*physxa)); - if (IS_ERR(physxa)) - return PTR_ERR(physxa); + physxa =3D xa_load(&track->orders, order); + if (!physxa) { + new_physxa =3D kzalloc(sizeof(*physxa), GFP_KERNEL); + if (!new_physxa) + return -ENOMEM; + + xa_init(&new_physxa->phys_bits); + physxa =3D xa_cmpxchg(&track->orders, order, NULL, new_physxa, + GFP_KERNEL); + if (xa_is_err(physxa)) { + int err_ret =3D xa_err(physxa); + + xa_destroy(&new_physxa->phys_bits); + kfree(new_physxa); + + return err_ret; + } + if (physxa) { + xa_destroy(&new_physxa->phys_bits); + kfree(new_physxa); + } else { + physxa =3D new_physxa; + } + } =20 bits =3D xa_load_or_alloc(&physxa->phys_bits, pfn_high / PRESERVE_BITS, sizeof(*bits)); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:38 2025 Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.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 C541E2F49E6 for ; Wed, 25 Jun 2025 23:18:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893530; cv=none; b=NAgFM8N1Q4Uh+OcNcQlMvO7w3iq/OZLIQnpYtbbf94S/Ta6yGcCi1nYjYk+eJgiF8yEaIf/mnnN202QjuurZFboUFe2Zj5YkEKWVjuDUq4a3GspRm2A0AZFDkMk8ZBNLoTJ/MoEXdm+ub8yn7kX2yMhQgEH/k3/vgK4QmX6EBig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893530; c=relaxed/simple; bh=PF4zPZ0Sp9cFfB82RPz+AlnuSwnkSMU7iIBj0zSOFYQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DpzuvrjylUO8/wmWBdiFdo3ZevgoWtkDk7KKNMPqUh58pU0Q+Yw6vketLWS8VE6xRVhN1ZraBpCFLHjj3sYjgqxjFdrB+7ueXI4eZgmjfJxPRPbBCOxQlUoFoO2KN2KTMSWsnBHatEI89eKxIR8Z/6GeMTMToJXJI7ApH5824+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=ViCB+3V5; arc=none smtp.client-ip=209.85.219.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="ViCB+3V5" Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-e733cd55f9eso318281276.1 for ; Wed, 25 Jun 2025 16:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893527; x=1751498327; 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=Oli2O51+2uVx0lLUJdn7wg4sXYNT345uLjNKlql1qmI=; b=ViCB+3V5htYFrHZMRHANBUKMG+bkSjOMn8AQIhMlOn+nvaOrw4Pb6+esS6L6xFmYKu hs2+nIZrpnNdYCgi5qOyECPNN+f2DM7wwi4mFyHufgiotz4Kpj1jyCCgG8kKAV4R6MlB em/T7NC40JexR821d2Euyyu07JvKz1HymVxiJTBvj0+DvHwUNR0Qj8wwZNGftTUoj5ID x2I8fABa4RfLSpkjzIeb8rqOw9DUu869p2tau+5MSmpOJPCoTpGnvCLuQj/Loae59pAT e7X5Gnlihiq32KW7A50UaDXPqnbPnYiLw+66a1OhK7J2Bwbvj7j4F8G84y5iBbLJ39TJ yDuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893527; x=1751498327; 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=Oli2O51+2uVx0lLUJdn7wg4sXYNT345uLjNKlql1qmI=; b=oj3gSgTtH1fMCgL9JoBIj+fc0PvKThhZdKJvErJ4YmoaM/1zIt4BAAw2zhw2ugX5ov 00aAH7TLNVF5x/tKnpN5Oh7Zbk36PeEKiR3BAqg7pa9+PTmNI2Hm7mWSct7fOe1Bm0Ta 2Odo/7qIeAuiP66w85l0l50xOtlWaIakNT9eOSQGbqujMwB1EXIsiQSzXe7KKKg2n+dY 8k6jzWeCKqKP5UDFLTqyxHjImzXElMDFvcSg/oDZ0egGgrHyLbXd3ewcn6qiVCoWdJcP yCNuc/70nOeoVJ/Q22N+ZF9BhyiPfWKUHi0NKYgdRN5AQE/0F83qGwsz23AktU0CoBm7 QMKA== X-Forwarded-Encrypted: i=1; AJvYcCVmLsVoj0eRVGboWlipHuC5+q5CVzo514IJ1jNjt2SgU7RTCpYi6Qg+bySpvour/KQNXpYiBxpUcA6vYp0=@vger.kernel.org X-Gm-Message-State: AOJu0YwgdZ2ayNEBXeBqF0W6OckkVmtvAkQGsYXGcDxGNDGxHLUnPbNx gsMjYliNBKcBzhRwJ5xiPU2L+fNLyXZGHRRIb85qoEew9niWePRse1rX+NDX7SkE7Gs= X-Gm-Gg: ASbGncsS4OEoDwjC25+Nj7Gz/k0tfF7g7QA+C5BqvGxEJGMMgcom69R7DVPTfW/Tux3 wb0RZPv/YbodYLBIkoqAz0DpwHUUrpZZa9o9S8zrwKSxd/cMi3yivw+7x86JJEXPFVgzkPPyTTS HYQKEJcwabKQilRFhm9qiEe4NskNwSqIRiHAJRCf0DHwa4jSYksFw9pPIscgzgYoK9kP77YXGZ1 kWbM92deEe67XYL4jxmtzDGiWvMAHkKRdMbLhmT1LRQE93Bj8LBBHALXHRw18SehCQmQltJ5mdK KRP/zQLerxDbSQyAo3Q/Nj1xAQJjBr3+uk14T9JUoeE9HNPCsOKvrjQSH2OUgfncLorSqUbEwWK +JsTYVRkz9Ss05QlprRxxjUTGMRc6cwbAR8Sip8zktqpYchWqweDK X-Google-Smtp-Source: AGHT+IF1PnL73EgTJEwVzGrV6WgSUuuJlktSvOW7rB8u8kfkaYIkr57swyuuC7E1tjKCDwfV/0m2Xg== X-Received: by 2002:a05:6902:2305:b0:e84:2a48:993f with SMTP id 3f1490d57ef6-e879b8875e2mr2677057276.7.1750893526742; Wed, 25 Jun 2025 16:18:46 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:18:46 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 02/32] kho: mm: Don't allow deferred struct page with KHO Date: Wed, 25 Jun 2025 23:17:49 +0000 Message-ID: <20250625231838.1897085-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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 uses struct pages for the preserved memory early in boot, however, with deferred struct page initialization, only a small portion of memory has properly initialized struct pages. This problem was detected where vmemmap is poisoned, and illegal flag combinations are detected. Don't allow them to be enabled together, and later we will have to teach KHO to work properly with deferred struct page init kernel feature. Fixes: 990a950fe8fd ("kexec: add config option for KHO") Signed-off-by: Pasha Tatashin --- kernel/Kconfig.kexec | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec index e64ce21f9a80..ff8ab20f9228 100644 --- a/kernel/Kconfig.kexec +++ b/kernel/Kconfig.kexec @@ -97,6 +97,7 @@ config KEXEC_JUMP 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 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:38 2025 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.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 602242F5339 for ; Wed, 25 Jun 2025 23:18:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893531; cv=none; b=nbh/KT1N177TjPLfQvW3CT3Y5nNyvIsuq7Qo2u0oUXE2PQ7OK5idYdvNisUMlOblMUBUVrgDOc8sKW9BpXTuUYd2+u3yQcaStqNfaQRIZXhty2Fh2kTnP9xSHW41xL6w4AIgMc4qXLLRCnW2DrIns+dJMAfrvDso3n1ARnFGP2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893531; c=relaxed/simple; bh=/jzvkX8kKfTXXj8MUiRnudSB6Xdv5AVsl+DY3UD5y1Y=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pxSLXAQVagPPUq3ILAuCegzdF7BT5fWIkVt8SpQixqCot2kT9YszZk/cJP5WOe7j6TDcWYAyFXf2bEyYm36pEoZjdwKj6CF20CJQdT8Jfl2d7PSwzYh/U5s2os2cOBmUbgImPLFzYEbAGAEK5soJBwbf/yzldlsYYmpR9Ja+s9A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=F9t7R7P9; arc=none smtp.client-ip=209.85.219.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="F9t7R7P9" Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-e740a09eae0so339916276.1 for ; Wed, 25 Jun 2025 16:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893528; x=1751498328; 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=1wSjS0lZdjVq2RRm0w30gwoerGRiuhO0wW0911FpMqY=; b=F9t7R7P9dOGnqua2bU1oS8V5+PpPHYjDibdhoeD7vrzFWQyO3q1F3CETLNDkq7wAYU tUCaAlNp7TmnxBG8owXlaM6m0GgnD/imjmxKUmJ23onCesxS4a8qNNV0rhuixhrYNb6X s0UB7r0YaSzJR08JqzXM2tGpF5jH6kQ+b6s9bdh1vmneDMgJqODayDn1Pdh/1lzyO8w/ 5OMBvcOr8I8YpA183bWVTpumuLgPJ0s+aYU8G8LpazAPP81Yv5Lm+8AQdEf8ehupgfLr mChA1YXOl91Esij/I+g73U47AqsGk6D6YCpZh/r8kSej1HQCGkiqfxqypBBO15pTRjRq QBJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893528; x=1751498328; 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=1wSjS0lZdjVq2RRm0w30gwoerGRiuhO0wW0911FpMqY=; b=P8qJrmcQm8YUaghtidaHeiP6n9Oyy8H2d0Tj/y8L8wllDvwFRJDmoq2LE4B2z/9Ovo jwd4mr3givzQ48ey6qJQ4WaA4fMilgMELMS693msJ0boKOkulUFHN0pvGiMgcu3KewSA A8/OdvIV3PSGiv5ZC5GLtlAhAQxUiPDRpVl2NeXP8M5KN2++hLLXBuDVr+jofouIh821 d2mfCxLNgQtTerwgoOD1zNDI/ObmuS0CWJpYWl7iw59hVsRD5p9txryvChrccBluKDSU zy1UPWfPOjkjVhdgawdqec0QhJJYnaZgVreerjkjSAPnA2SP7l5IqfotRQ3dNZrqvd+d JqlQ== X-Forwarded-Encrypted: i=1; AJvYcCXvhgWogniBk9JP1+noBj1K4XCdfe6yu4z1uczX+HqpknbFQc0QwBGn1aCIxqyNsT10yr1K9Qn+ZaQ9Y9Q=@vger.kernel.org X-Gm-Message-State: AOJu0YzhQ3907LLHUpvqs9pYgw7ItawOWs91xJBNc5IhaYWNJ/hB910I luWFujS7Bcm5Y0xXdjzcesIh+2Ied8FcpygY2baFbh5aqeBqh9UDy4kPR1HfXgKWowk= X-Gm-Gg: ASbGncv5oioCWeMJaqXgWJsZMUVroSD8DERuIWDwTQquO/SUsmdpx5E2ZFekhBRUAfY iZa4tJ/Jh7kjQfggsb4nXG1ohBG5/0TnL02ocfSkjGXb8wQSjx3Y4FdrRedTbFpwYY32izlKXxJ h5mR2lbElB1Dl/POs9DKZ89kx3DygRVHR9UeIPZJzNTp8/quwlj9NJF/FvMhq1oPokK2JT/QcfM BwntTUG5lVXcY+AkfrbrUVIaKFofcxqjuunWRLR/btGNCCC+JruERUSvW04PfWyfC2K+7Hj9gg4 SIycoxMHsoC9Wz3TTpQhcsBeS9fykswfk7Ph0FMW9/8nfV0O/vSMD+jZt/pV60BJb5pbxfD2x6w 90heyKjMqqLiZbkBnVpLXSa9YcoRvsoCkwHZKuH6/VKrtAAIeBarI X-Google-Smtp-Source: AGHT+IG5OApmmqdCJD+/fcR7XfWrM1aqENTJa6SY/4uuowksGcfqjeB+tW5gpbSUsbeJPGxBKqv3/g== X-Received: by 2002:a05:6902:488a:b0:e81:b38f:6dec with SMTP id 3f1490d57ef6-e860177ef01mr6098227276.34.1750893528412; Wed, 25 Jun 2025 16:18:48 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:18:47 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 03/32] kho: warn if KHO is disabled due to an error Date: Wed, 25 Jun 2025 23:17:50 +0000 Message-ID: <20250625231838.1897085-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" During boot scratch area is allocated based on command line parameters or auto calculated. However, scratch area may fail to allocate, and in that case KHO is disabled. Currently, no warning is printed that KHO is disabled, which makes it confusing for the end user to figure out why KHO is not available. Add the missing warning message. Signed-off-by: Pasha Tatashin --- kernel/kexec_handover.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index 1ff6b242f98c..069d5890841c 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -565,6 +565,7 @@ static void __init kho_reserve_scratch(void) err_free_scratch_desc: memblock_free(kho_scratch, kho_scratch_cnt * sizeof(*kho_scratch)); err_disable_kho: + pr_warn("Failed to reserve scratch area, disabling KHO\n"); kho_enable =3D false; } =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:38 2025 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (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 02E0E2F9491 for ; Wed, 25 Jun 2025 23:18:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893532; cv=none; b=Qsa/2vecxoKWZ/yx5nKagmPmkQkXjqq7gge/i8Sj9N1gf2eNEFtsgBP78UvNUxOLtCdAU+RRWaEAv1LsurqvcYvdb7JzE02n6QlGiSpevpI40b93DT4BEaSJqTBMQol4qkvsH3kS97OJPBGmQJ8+V5FyQEkyxKtqUn4mpz+jxjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893532; c=relaxed/simple; bh=0PDOq00Vvzpi5aidwuocO/LBH8ZpH//f3Oi/CTR/VxM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=khXmiv0hbzMsrFtr63Bedz55hEyu+8yYC4DGqOr8XUs2lmDGajjZz++O2zXOfhL8Eb66neazNIp+AwKHHpVm9HSK6BDFOfWl/I7180Oplf1J/ZhnCe0V7u4xcut14tsvcdKxHduy7VZcqHy5qa/kYYzILR2nnXU6EuWuaHqrEfw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=TQD9Ylfa; arc=none smtp.client-ip=209.85.219.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="TQD9Ylfa" Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e819ebc3144so351183276.0 for ; Wed, 25 Jun 2025 16:18:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893530; x=1751498330; 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=sEd3hEimCm47EV0AQaiIlZfu4Iz9+2FaeBATOaJn9bU=; b=TQD9Ylfa9OpH6y1QUUoAcPtowHOdIvB4ASS2jV6r0te9GUxsCNjr1ZD1sa6YrOVUne IZqTmnQ0IaKeeYUewoWaGdx58v66xdMMR1WIriO4rmI74qqi8rSx6ncKMS7itX2dZfYP HySzDgRFfqNCJzfNBYg5NfM4bdOkGb4pbBEg6i2mk9Xt/dQh/eCpPYN4yBIkG4VNmT0U +vitfnMD/vim7ztqZPJs4T+SLHEReI7HY7P4/hXKtqOQCyC7qW4lJ1z3nSIXO2EraKFw hQR//pIDLNIqKTdofkzdLX+j27ZiUukmIvgIoGILX898g0baNiu/TGYUYIr2px19Gae+ wMKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893530; x=1751498330; 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=sEd3hEimCm47EV0AQaiIlZfu4Iz9+2FaeBATOaJn9bU=; b=RhrOYgU7BPcXQAovBGwv1OpvwFabPvndPaC+TK9OWE77qy+DOxQeWzLqLrtYZSwQXV cmWBb42vJX9Btk9Vv2p+y6X2Yze6PRzE77m/pmvn5Y+oDvft2AkHeZ0Hrd8OPlPNSdxB EqzOM+2mvq+hmUziWb3J6+mXrduw7fSwMw7cQn9k9qG/xCuZoVr45kXcjjuq5UPjY/9J KXTvGtaNeL0ccTxl8gVG6iyB0FxINi41aWdroPOEFUk1hODq0WrjxPScQU887ShCTy7y Q1zcIJ5bYl+kZ4qNatUD+E/BS7lWQD0lzxk8D1Yej+fOrE4deIABMo6cPEXLAOjAYmKR lAUA== X-Forwarded-Encrypted: i=1; AJvYcCXklO+GU7rRLMcKRo0oNWE/dXCglfD55cFRB3oU0hbfto4roZJN8MuPTxgeweDoav91pK3tAqpXVjs/jZo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+Fw0woxDGy8RqIjqzjNOeSIFiSIAhXIlc8cEmEMd8JQI6ZqjQ LidTd9hE5kpQ43Pc/9YT0kc0zYn2z74oR0cSPKMCCFRRbsT09Lnuu01Wa3tsDHok/cw= X-Gm-Gg: ASbGncvVB6xB/H/XeE74KS7mt1D682OxMYkzU4zfSnUHFARnsqbBHc5NuYUHNLAUHTv iEcfjDbGCd+YTWMvb+ELeE40fKGXBVCqSQ6PLC3O3pZJqJ/OpJUUzMsjnPngATyJinzoTJHW4Yk GUTc4yrcm51LM7ltxncxZ4SBKTrZNvRXxCX4r6bmlgKMaHhwungTk/PjnnYQXtMRawaxu2nVA0q POf8VUqKv23tLM60jwOvfPf5MKQcq3wcsrlJuo7zQARunKP1Kp3Wdp4QRDm7Wf75S9eXeck+OLU vRpGNOfPtCFP5l122nrOLH3Xs20h+4eFZRxZZdswNOkPMj5umDaOM25+4qFucWwBvuGt1oAVUMY 0wtKFMnG/UzFr5Ocjy156Nh4anyUA0V/C9lk0+38ZDQg75feSgsbN X-Google-Smtp-Source: AGHT+IFV+5+LiyNG0iLZB0IHiIkVDp3jbmaFTSBcfMxeDjEUTB2cISyBkSfyxmu5nuGGQBp9zewiEQ== X-Received: by 2002:a05:6902:18c3:b0:e81:b5b8:3cc8 with SMTP id 3f1490d57ef6-e879b977913mr2507142276.41.1750893530105; Wed, 25 Jun 2025 16:18:50 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.18.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:18:49 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 04/32] kho: allow to drive kho from within kernel Date: Wed, 25 Jun 2025 23:17:51 +0000 Message-ID: <20250625231838.1897085-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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 to do finalize and abort from kernel modules, so LUO could drive the KHO sequence via its own state machine. Signed-off-by: Pasha Tatashin --- include/linux/kexec_handover.h | 15 +++++++++ kernel/kexec_handover.c | 58 ++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 348844cffb13..f98565def593 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -54,6 +54,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) { @@ -104,6 +108,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 069d5890841c..af6a11f48213 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -757,7 +757,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; @@ -790,7 +790,34 @@ 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; + + mutex_lock(&kho_out.lock); + + if (!kho_out.finalized) { + ret =3D -ENOENT; + goto unlock; + } + + ret =3D __kho_abort(); + if (ret) + goto unlock; + + kho_out.finalized =3D false; + ret =3D kho_out_update_debugfs_fdt(); + +unlock: + mutex_unlock(&kho_out.lock); + return ret; +} +EXPORT_SYMBOL_GPL(kho_abort); + +static int __kho_finalize(void) { int err =3D 0; u64 *preserved_mem_map; @@ -839,6 +866,33 @@ static int kho_finalize(void) return err; } =20 +int kho_finalize(void) +{ + int ret =3D 0; + + if (!kho_enable) + return -EOPNOTSUPP; + + mutex_lock(&kho_out.lock); + + if (kho_out.finalized) { + ret =3D -EEXIST; + goto unlock; + } + + ret =3D __kho_finalize(); + if (ret) + goto unlock; + + kho_out.finalized =3D true; + ret =3D kho_out_update_debugfs_fdt(); + +unlock: + mutex_unlock(&kho_out.lock); + return ret; +} +EXPORT_SYMBOL_GPL(kho_finalize); + static int kho_out_finalize_get(void *data, u64 *val) { mutex_lock(&kho_out.lock); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:38 2025 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (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 0D8FA2FBFFE for ; Wed, 25 Jun 2025 23:18:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893535; cv=none; b=sWt55R2BQNkJ3tuRm6fNLs3j+KomKm9sdTWflztPGBxXqr9nycvYkg/woBnnMhwjRlfIrF7MR/8UGAW3dcOcnR1qm87nC2582GzCW4Y93gXmWWlL4d8/aLqNrLkC1vobFQFHspr8wF54desJTxHVg52jJ/hfjk63H2SM7XyqR/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893535; c=relaxed/simple; bh=pZPVs3wNSmke5Ful54VmXWN7DgfJyhrekHxo42cMLiE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BfujDk6OzAt1i7ITEOFug6ir3uE0H9x41l0EwQcijO56L8CspyrRC3G+3DBxbf+QT5vm6EscPNgajCHHSmzvq2/v8y5old9o28HkrGmaNF0GTzsPTZShbzx0qVySBaWpYagNK05AckIskKnAXJSWBiqxMj2ZwmoynzjP/5kRltU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=LXc5PIVR; arc=none smtp.client-ip=209.85.219.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="LXc5PIVR" Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e81826d5b72so297265276.3 for ; Wed, 25 Jun 2025 16:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893532; x=1751498332; 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=dumZCTdWbvhK37KWwIDI5JTRGiHuCsCef+VJnwQR+pQ=; b=LXc5PIVRZCaJB/0DpPJkyoiJwD4Y7s2bYjW5N7LzVLgM95oM/jO7x8wHCd8BYWqj4B me6eBhMXWY1B7F9Cc7jZ5iT3nWneM6EdfxV5y71RIlT7joX5swLoafS1EEm/7CooJ2Wm XLi/R85J5N+HBBG0tc/TCvryvtV8YKiwbKA77RY9Jsb54QEhbatxystZ77rEporgcqps xWULVpoagybxHxX8YDFPbIKAKzk8EajyMc7eT4qoyWBTr4AZZydfvkzydYk/AFwzRZLA n15bY7tHBO/xI7HOFILWfCulDSoIcgsIdJFgk9fsaqm2E4xC0FC9Y3Yl8XZawzruaNll SPHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893532; x=1751498332; 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=dumZCTdWbvhK37KWwIDI5JTRGiHuCsCef+VJnwQR+pQ=; b=nVdJX5khsKPEXKcM6P9M41tSjRSTm0Blx+PDbGbURgtC7w0Hl7XtyK5MlA5EAlC0kJ 7jH6ovqjP18CL3NEIItSsBcxDighj7mpHvcL870sP9xIiSeEua6xjLALqLT3nwUNWuMs ag/bt2xTz8igYcX+s1BDV61Kq04By1VdLCWR3a2HxIPUJPDLhqowXWroXT7FhUXdvBsp qTuSTohfbffhrwD/QgLRZKlELn6NdSEfgcB5DUIOEWdPluwmsQK8XeAxx6Ro9fc0PIYZ 5B3WWHCQKIsTFePck5AvpXOD7KGECCPF2L6MYEvFkFSAm7UaYjqIH9JvipfcLtIQsPoG Ym/Q== X-Forwarded-Encrypted: i=1; AJvYcCU2ajErsUVhFdN0W6zYjksKk8QPfjiqDz3K+u9Zl+E5xElPUg8n45hjEIKoTpAKr49roGPJvE+1iYYhX3U=@vger.kernel.org X-Gm-Message-State: AOJu0Ywtwmrwv6H6yWFzMu0ysnqeK3kAQG5jyiH37QobIyPaLV0aiFjM AZNH3+HzqTGkguu7jCPENY00wgDEMk/JSfC9f2V3E1amzFa0VUn92L9meZA2PFNxZAQ= X-Gm-Gg: ASbGncucqCpuWGATGrmcbUGBF1vXOKv+E0rEzlb+sESS31wyKWj2fw9SolhgSmphW7H KYEMshEE8EFau7D8lNvWuRH5Pfz76s4jr70wltnQlDAeicTTI922QTi9l9wlgBoH3tyVLUqzJ9p nVxGUX+16dbmdPSgOdClNbQL/9eZL0fHVGio/r1g9WpWO03NMj/jj7DDyNBhHGFc8853q+iNprB MpJ/SaON58eWOLGvT4ThdY0scs8fE6EKe/SX7g5Eqyp+ypkgV8BiZlmVxpJsk4cGrHdATRpdMzR zshcve1Tmy6ze3mawZFE+GfNDf+A9+1IUitw2vwTsKoJne8XZMt5kbxvQOxV0ZkxKVR69XoNgq0 zunuOe4qdf0JPAGGFHV9rWbp1XYBCdm95iNWwkN5uVOEVaOGAT7v1 X-Google-Smtp-Source: AGHT+IFyFKsALyA0KkokSs0oiQ68Hbgi3tkJLo6jEj/wIJs+Ee8M7Kz8LkfX+DDtHK8ypURGMBW9Iw== X-Received: by 2002:a05:6902:120c:b0:e84:cbc:6c86 with SMTP id 3f1490d57ef6-e860177bf6bmr6206247276.33.1750893531852; Wed, 25 Jun 2025 16:18:51 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.18.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:18:51 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 05/32] kho: make debugfs interface optional Date: Wed, 25 Jun 2025 23:17:52 +0000 Message-ID: <20250625231838.1897085-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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_DEBUG 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. Signed-off-by: Pasha Tatashin Co-developed-by: Mike Rapoport (Microsoft) Signed-off-by: Mike Rapoport (Microsoft) --- MAINTAINERS | 3 +- kernel/Kconfig.kexec | 10 ++ kernel/Makefile | 1 + kernel/kexec_handover.c | 278 ++++--------------------------- kernel/kexec_handover_debug.c | 218 ++++++++++++++++++++++++ kernel/kexec_handover_internal.h | 44 +++++ 6 files changed, 311 insertions(+), 243 deletions(-) create mode 100644 kernel/kexec_handover_debug.c create mode 100644 kernel/kexec_handover_internal.h diff --git a/MAINTAINERS b/MAINTAINERS index efb51ee92683..8ef6df1c4611 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13346,13 +13346,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* =20 KEYS-ENCRYPTED M: Mimi Zohar diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec index ff8ab20f9228..2b18a06bc5b2 100644 --- a/kernel/Kconfig.kexec +++ b/kernel/Kconfig.kexec @@ -109,6 +109,16 @@ config KEXEC_HANDOVER to keep data or state alive across the kexec. For this to work, both source and target kernels need to have this option enabled. =20 +config KEXEC_HANDOVER_DEBUG + bool "kexec handover debug 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 32e80dd626af..e4b4afa86a70 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -82,6 +82,7 @@ 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_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 af6a11f48213..860046776c6c 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -10,7 +10,6 @@ =20 #include #include -#include #include #include #include @@ -27,6 +26,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" @@ -84,8 +84,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; @@ -381,8 +379,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 @@ -569,36 +567,24 @@ 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; +struct kho_out { + struct blocking_notifier_head chain_head; + struct mutex lock; /* protects KHO FDT finalization */ + struct kho_serialization ser; + bool finalized; + struct kho_debugfs dbg; }; =20 -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; -} +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), + }, + }, + .finalized =3D false, +}; =20 /** * kho_add_subtree - record the physical address of a sub FDT in KHO root = tree. @@ -611,7 +597,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_DEBUG * * Return: 0 on success, error code on failure */ @@ -628,33 +615,10 @@ int kho_add_subtree(struct kho_serialization *ser, co= nst 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 -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; -}; - -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), - }, - }, - .finalized =3D false, -}; - int register_kho_notifier(struct notifier_block *nb) { return blocking_notifier_chain_register(&kho_out.chain_head, nb); @@ -734,29 +698,6 @@ int kho_preserve_phys(phys_addr_t phys, size_t size) } EXPORT_SYMBOL_GPL(kho_preserve_phys); =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; @@ -809,7 +750,8 @@ int kho_abort(void) goto unlock; =20 kho_out.finalized =3D false; - ret =3D kho_out_update_debugfs_fdt(); + + kho_debugfs_cleanup(&kho_out.dbg); =20 unlock: mutex_unlock(&kho_out.lock); @@ -860,7 +802,7 @@ 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; @@ -885,7 +827,8 @@ int kho_finalize(void) goto unlock; =20 kho_out.finalized =3D true; - ret =3D kho_out_update_debugfs_fdt(); + ret =3D kho_debugfs_fdt_add(&kho_out.dbg, "fdt", + page_to_virt(kho_out.ser.fdt), true); =20 unlock: mutex_unlock(&kho_out.lock); @@ -893,112 +836,24 @@ int kho_finalize(void) } EXPORT_SYMBOL_GPL(kho_finalize); =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) -{ - int ret =3D 0; - bool val =3D !!_val; + bool ret; =20 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(); - else - ret =3D kho_abort(); - - if (ret) - goto unlock; - - kho_out.finalized =3D val; - ret =3D kho_out_update_debugfs_fdt(); - -unlock: + ret =3D kho_out.finalized; mutex_unlock(&kho_out.lock); - return ret; -} - -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; =20 - 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; + return ret; } =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) @@ -1042,56 +897,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; @@ -1106,27 +911,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_debug.c b/kernel/kexec_handover_debug.c new file mode 100644 index 000000000000..b88d138a97be --- /dev/null +++ b/kernel/kexec_handover_debug.c @@ -0,0 +1,218 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * kexec_handover.c - kexec handover metadata processing + * 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) +{ + bool val =3D !!_val; + + if (val) + return kho_finalize(); + + 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 new file mode 100644 index 000000000000..41e9616fcdd0 --- /dev/null +++ b/kernel/kexec_handover_internal.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef LINUX_KEXEC_HANDOVER_INTERNAL_H +#define LINUX_KEXEC_HANDOVER_INTERNAL_H + +#include +#include +#include + +#ifdef CONFIG_KEXEC_HANDOVER_DEBUG +#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_DEBUG +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_DEBUG */ + +#endif /* LINUX_KEXEC_HANDOVER_INTERNAL_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:38 2025 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (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 E725D2FEE18 for ; Wed, 25 Jun 2025 23:18:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893537; cv=none; b=LpnKedmhu8ujvIgZM7OlK2Mn8NCTq8iOlZQICZjRav9ZRoVp7gEv6ZCvma7rU8J9cSNypVu88q9orh3yk11SRlVWVUpaA3Ai30MvO1KST3B2FqvjS7XGh0dFLSsqJ94aue/JXo2Hke+n5N/vDoCNVNhocpo/Q3Hwyph7Zjw0TnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893537; c=relaxed/simple; bh=1vN0jZ2h/FXQJFTNMBB0zbwgw9DEau6uco3Fq2ALYAM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MLX0PGknjaafIWEgFXf4/KOhIiePpFqtfG4wzdVCP7Ys5jL8qxoT1uxWGO3VgdAUOWAi/pbil2zgVb7R28gjfwJDKuzBvigiEISPU1kMQTOLnSg7pBABAqAxwiPWVuNgsoPwmc3T4YZqylgyMzE2mL6a1hgHWHODcEFmvpdbWJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=gn4rfnBa; arc=none smtp.client-ip=209.85.219.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="gn4rfnBa" Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e740a09eae0so339961276.1 for ; Wed, 25 Jun 2025 16:18:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893534; x=1751498334; 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=r8lcNCxb4PfqDaMrYo/auPfdXTsh3cDB2G3Js0FKiEc=; b=gn4rfnBaVz1HhnFUmPBcM5s+EaNNpla3qEOSw5yB/G/up1EELDAHGmxx6QZB3wetsD HB+6vTf1Xr+eUa8LN6UoXW4O1Ie83FCeR0Psr0rayzJBn5JEINbhvN1uelOanDl3XdpM +ao7H82LyFAvDpN3I2k1VS5Tlv8U1JcBdagyzCLjo02QU9vhMCVOTIzpJDBdUeiIgb+E 249LnXdQFBNd73Gb8MFqUsEj8F6/E3e75MCEd8wFl3vZll8vFAt4JmGriR6BxEtclJq6 Ct1X5w3lt/W1+c69x6xgl9c6qJss+I5T9Pspi23Ji5juq/XPkrTQadRtJc9ORIuD2iMw Y+sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893534; x=1751498334; 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=r8lcNCxb4PfqDaMrYo/auPfdXTsh3cDB2G3Js0FKiEc=; b=oi8klBiBgST7ommfZDy3uv+7gDCsvg0LmGdZXItK6d5SI/YmJsu87L+w/CdC+R+6dx ouaodd0sLzQ4sR7mUM/yzL6R5oNA1Ljs/j114syOHPCYy+q/WVBh6ui0f7ozPsN7fPVZ R1Jf9U7rCZqvExzbw/53lcP0POgEKK9SwKX3yPb2diQjkNWA59lXdUxzgWqBnJuKjjmg nfkpgTzamcfcogNtT5WJhVRPQ2M1zrrgCrn5MTVQOshiV9LGWoHzaV0NN8uUhUf2pFlT HQOwsFR+dF7bzNEWdITV5p9Xk8RpiREfOcafrDtFbsK8bbtdeBPNeKVizxbMhoF4xOXG wRMw== X-Forwarded-Encrypted: i=1; AJvYcCXc3L4PIM85V7Glk2C8gCnlBlpRemijkJ+Ys78x4smMw/rzzFbfYWif+UE73blN1K+0yq8fFqME8euUuoM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/01j0DHi91i8svsRPsg2ROKqpnHgv1XvtfCJvm92wMLVuHIN4 XiNQl+2fBP9/LQX0ZGo5Jg4AFs5gIcM4OOk16rTGiMLwlqdXVzL15Qqtf0MHhju47/c= X-Gm-Gg: ASbGncu9a8uYBCO2e+34W7KpaqYZnHAJm7HADUNz7pGe/eVfYhWWaeZRVcwH0NPfz0p nYvmKVokrMEwQ08/dTziU4vZ62yk2ldy/MUejNUiT14+oXuWXhePl/4p208Cz1BHLZVSeAyUHhK vuXqAtLlPnHYpN3DlGSG8EjWqj1a4sU3qBUtamdpdYuVkahbKU2snYuaCfVEK88FQkR33D2SWg/ yhTd0mamKKCxkidrd7n3tmtzYbgtDzZThI3XrlB0IRTnjzHBfhgFi/IY5OQ81aRaHmrJG06Mj+a 0Ix/PxuI+yUGC1N2sAIinvbDb084N6OR36etNtUmjzFax2qAqAu176OOGHfQJZDpEhErkr4RCrI 7zwqt1TfeV85E9yio54faMDstAld+D+oPMtRkraKQ9XjTbbxoDcNCwKl5jUCbeLY= X-Google-Smtp-Source: AGHT+IFqM5bxfYxeQhI10JJcxhwMajGHQ1rXpU1g3SjV3eIkrQRGJH8LPjOK+gNeGUvErdkojOuSKg== X-Received: by 2002:a05:6902:100d:b0:e84:2c69:3b2a with SMTP id 3f1490d57ef6-e86016d15f1mr6056336276.7.1750893533661; Wed, 25 Jun 2025 16:18:53 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.18.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:18:53 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 06/32] kho: drop notifiers Date: Wed, 25 Jun 2025 23:17:53 +0000 Message-ID: <20250625231838.1897085-7-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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) Signed-off-by: Pasha Tatashin --- include/linux/kexec_handover.h | 28 +---- kernel/kexec_handover.c | 177 +++++++++++++++++-------------- kernel/kexec_handover_debug.c | 17 +-- kernel/kexec_handover_internal.h | 5 +- mm/memblock.c | 56 ++-------- 5 files changed, 124 insertions(+), 159 deletions(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index f98565def593..cabdff5f50a2 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; =20 #define DECLARE_KHOSER_PTR(name, type) \ union { \ @@ -36,20 +29,16 @@ struct notifier_block; (typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \ }) =20 -struct kho_serialization; - #ifdef CONFIG_KEXEC_HANDOVER bool kho_is_enabled(void); =20 int kho_preserve_folio(struct folio *folio); int kho_preserve_phys(phys_addr_t phys, size_t size); struct folio *kho_restore_folio(phys_addr_t phys); -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, @@ -79,23 +68,16 @@ static inline struct folio *kho_restore_folio(phys_addr= _t phys) 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 860046776c6c..e1f0b7a9f5e5 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -15,7 +15,6 @@ #include #include #include -#include #include =20 #include @@ -82,11 +81,35 @@ struct kho_mem_track { =20 struct khoser_mem_chunk; =20 -struct kho_serialization { - struct page *fdt; +struct kho_sub_fdt { + struct list_head l; + const char *name; + void *fdt; +}; + +struct kho_out { + void *fdt; + bool finalized; + struct mutex lock; /* protects KHO FDT finalization */ + + 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; +}; + +static struct kho_out kho_out =3D { + .lock =3D __MUTEX_INITIALIZER(kho_out.lock), + .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 static void *xa_load_or_alloc(struct xarray *xa, unsigned long index, size= _t sz) @@ -285,14 +308,14 @@ static void kho_mem_ser_free(struct khoser_mem_chunk = *first_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; struct kho_mem_phys *physxa; unsigned long order; =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 @@ -320,7 +343,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 @@ -567,28 +590,8 @@ static void __init kho_reserve_scratch(void) kho_enable =3D false; } =20 -struct kho_out { - struct blocking_notifier_head chain_head; - struct mutex lock; /* protects KHO FDT finalization */ - struct kho_serialization ser; - bool finalized; - struct kho_debugfs dbg; -}; - -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), - }, - }, - .finalized =3D false, -}; - /** * 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. * @@ -602,34 +605,45 @@ static struct kho_out kho_out =3D { * * 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; + + 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); =20 - return kho_debugfs_fdt_add(&kho_out.dbg, name, fdt, false); + 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. @@ -644,7 +658,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 (kho_out.finalized) return -EBUSY; @@ -670,7 +684,7 @@ int kho_preserve_phys(phys_addr_t phys, size_t size) const unsigned long start_pfn =3D pfn; const unsigned long end_pfn =3D PHYS_PFN(phys + size); int err =3D 0; - struct kho_mem_track *track =3D &kho_out.ser.track; + struct kho_mem_track *track =3D &kho_out.track; =20 if (kho_out.finalized) return -EBUSY; @@ -700,11 +714,11 @@ EXPORT_SYMBOL_GPL(kho_preserve_phys); =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 @@ -714,17 +728,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 @@ -751,7 +761,7 @@ int kho_abort(void) =20 kho_out.finalized =3D false; =20 - kho_debugfs_cleanup(&kho_out.dbg); + kho_debugfs_fdt_remove(&kho_out.dbg, kho_out.fdt); =20 unlock: mutex_unlock(&kho_out.lock); @@ -763,41 +773,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); =20 - *preserved_mem_map =3D (u64)virt_to_phys(kho_out.ser.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 - err |=3D fdt_end_node(fdt); - err |=3D fdt_finish(fdt); + err |=3D fdt_begin_node(root, fdt->name); + err |=3D fdt_property(root, PROP_SUB_FDT, &phys, sizeof(phys)); + err |=3D fdt_end_node(root); + }; + mutex_unlock(&kho_out.fdts_lock); + + err |=3D fdt_end_node(root); + err |=3D fdt_finish(root); =20 abort: if (err) { @@ -828,7 +843,7 @@ int kho_finalize(void) =20 kho_out.finalized =3D true; ret =3D kho_debugfs_fdt_add(&kho_out.dbg, "fdt", - page_to_virt(kho_out.ser.fdt), true); + kho_out.fdt, true); =20 unlock: mutex_unlock(&kho_out.lock); @@ -901,15 +916,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) @@ -937,8 +954,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); @@ -949,7 +966,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) { @@ -1085,7 +1102,7 @@ int kho_fill_kimage(struct kimage *image) if (!kho_enable) 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_debug.c b/kernel/kexec_handover_debug.c index b88d138a97be..af4bad225630 100644 --- a/kernel/kexec_handover_debug.c +++ b/kernel/kexec_handover_debug.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 41e9616fcdd0..240517596ea3 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_DEBUG */ =20 #endif /* LINUX_KEXEC_HANDOVER_INTERNAL_H */ diff --git a/mm/memblock.c b/mm/memblock.c index 154f1d73b61f..6af0b51b1bb7 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2501,51 +2501,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]; - - err |=3D kho_preserve_phys(map->start, map->size); - } - - 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); @@ -2555,6 +2522,7 @@ static int __init prepare_kho_fdt(void) for (i =3D 0; i < reserved_mem_count; i++) { struct reserve_mem_table *map =3D &reserved_mem_table[i]; =20 + err |=3D kho_preserve_phys(map->start, map->size); 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)); @@ -2562,13 +2530,14 @@ 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)); + 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; @@ -2584,13 +2553,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.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:38 2025 Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (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 75AE42FEE34 for ; Wed, 25 Jun 2025 23:18:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893538; cv=none; b=A54bWCET91ekOsSmf/CA4qEQ85rtF/bdb6Zlh7PKLjhHAzwUTJ+FS1R+iObj7p5tDgpoiyXpQl+LvLyd9eGVYKXVX53MlA+anZQdscDk8bGT6OGY0tdhheMpPfKGePVQEGduMw0NGP7sx/+cIeEnAFoN0o2UH4csFMkNE5EDbPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893538; c=relaxed/simple; bh=zakCa3JDr5KNv1gJv0s94oXiSv6hJeRHKFuGzzdgwsE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DJwbLdD2+yyGOIIvWqj0HQ4mjAT+I0qvLGNghYocE65SF8nFkwz5MpwtDlvaxGvLDxcqzf3606RJV62Z9Ro8TKMuIxRIETjgjCD2PIHTwpf4c3Jqnkzh7ifxxClxPo2FZPF+mpQTQbsZPH2wOemd2WdlPFjo8M3f8ndVs526TD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=g6eIHZCw; arc=none smtp.client-ip=209.85.219.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="g6eIHZCw" Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-e733cd55f9eso318364276.1 for ; Wed, 25 Jun 2025 16:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893535; x=1751498335; 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=SZDu7RJqPXAY2ruR1j/0614GYveU9RxRfC4eQg5qP6Q=; b=g6eIHZCw/IQYXZR2hLvsVboU097FxqRzJtuqCc45DXz52ytibgVqEXFfDiR0rb5USg JVLPA6LsQMcyH0Hd7trnM/LviQikhprKSBTRW+YqAdlufLfh3GjyzAdRNzXyuDDu7SE9 AmyXU/paEGrjwMN7kJls1iPZmNkYOsBz6sdvCx72x4NNyeziI1C1JmnMjUioLeo/DKNS WJ0u4oJLqf/xv1yNFa/VeGWIrRqvxXD2ZI2Rmg+pLRsPJwDRAKUmyyWJRnUMwsAcv4BY 2knK99g9tdlU+ID1ZC4tzR7QMSO43RrKbkbSY2Um1E65WoqS0kOJpAjYJaiFnbwre46z Pu3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893535; x=1751498335; 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=SZDu7RJqPXAY2ruR1j/0614GYveU9RxRfC4eQg5qP6Q=; b=awUbPCMucrY8dejp3Fhvll6u7wqwVsVP/wrFMgRgyLqYkUPEa+c8w2f4sbX80kMsp2 0tbgbwXVuoh5I3qd62N9R3MNVRVkFfN465K2ZesMuHRfpO50tsmrSh5oxeuJ+TgzX668 eebBaKjBHK5BF8t28rFQn8CFIUEEfK0AobO3Jupnax5LDck6XTsLm4I2KltOIPC1AtfZ AGbC7cdgs7hldyMdR2ytmw5Sg8Hj4Fi0o4mr9IvgAgLeBtrKGr0Fvtc0pf8UNIq6zBCh Gab6Ei+Lumr3nv4zfdfk6zDFdnMQ7zbvhovGwMMX/WZSqIc+/nskS89f8ceAxz6nQHUF akxw== X-Forwarded-Encrypted: i=1; AJvYcCUgg80eFs0txAE2NCNiw10bJfPnmkvIfPf3IUkvl3BY4hvQo0A2r6nA+5oWjaHCrPDI1C/n4Lj+smA2JYI=@vger.kernel.org X-Gm-Message-State: AOJu0YxrseEgQUFGitFTPMnr/dLB9hETlfeue61HKrcaOVDF+HDnTmXL Ok0Woz4ldTeIJIumlX+WOtUFjCbmvfYEL0UfcDS+0a7hPKyowXORAqYul0A5GmS5M3I= X-Gm-Gg: ASbGnctkkCOgnr9M0REZ6dcxuQ85ksxbk3Ctwx0WW9fqWE/Ko0dY4Wm3Wf9pfdprPxM nHQc2m+GiV0HGSYpdsgmW/yc+AwOlZgmhbgHvnhI9cxTzmLfkT4RfS8y1xU0S/iWNrUCOyhifhN qZU390xWAHCeJaBE/f/O2IFOD1iKZFbG+VfdzRTaJNfGNbOgoMPlOcqm62cuYDJ89b29UmMrny9 2SEKTcScRoEA4XP9Bmb3VIy5bBGBOa75wpgHpwvItpuUvyjtGSUlA7XVzjynMD+ovRhujEaHtr3 pkmW2ifd/svoGqRqQsGt5e8foVIoGpOs5kIaoLgMnSiC/FMURtEsaHu+jTgE4rXWnFv33O56vdk ppTFUJTD5B4woi20E7Ax5mqIi1cLfnCxMqaCLPpgAMRPYoSsd0eWU6IIna+NWvS8= X-Google-Smtp-Source: AGHT+IF6d+wQdJueaL+2XDR+0IAu1dQMzIzIZ7VLaIY39ujjcBBrFSOUIoGsCEOL7tdAla+chMnDaQ== X-Received: by 2002:a05:6902:2182:b0:e84:46f2:8233 with SMTP id 3f1490d57ef6-e879b98cebdmr2790163276.45.1750893535364; Wed, 25 Jun 2025 16:18:55 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:18:54 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 07/32] kho: add interfaces to unpreserve folios and physical memory ranges Date: Wed, 25 Jun 2025 23:17:54 +0000 Message-ID: <20250625231838.1897085-8-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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: Changyuan Lyu Allow users of KHO to cancel the previous preservation by adding the necessary interfaces to unpreserve folio. Signed-off-by: Changyuan Lyu Co-developed-by: Pasha Tatashin Signed-off-by: Pasha Tatashin --- include/linux/kexec_handover.h | 12 +++++ kernel/kexec_handover.c | 90 +++++++++++++++++++++++++++++----- 2 files changed, 89 insertions(+), 13 deletions(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index cabdff5f50a2..383e9460edb9 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -33,7 +33,9 @@ struct folio; bool kho_is_enabled(void); =20 int kho_preserve_folio(struct folio *folio); +int kho_unpreserve_folio(struct folio *folio); int kho_preserve_phys(phys_addr_t phys, size_t size); +int kho_unpreserve_phys(phys_addr_t phys, size_t size); struct folio *kho_restore_folio(phys_addr_t phys); int kho_add_subtree(const char *name, void *fdt); void kho_remove_subtree(void *fdt); @@ -58,11 +60,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_phys(phys_addr_t phys, size_t size) { return -EOPNOTSUPP; } =20 +static inline int kho_unpreserve_phys(phys_addr_t phys, size_t size) +{ + return -EOPNOTSUPP; +} + static inline struct folio *kho_restore_folio(phys_addr_t phys) { return NULL; diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index e1f0b7a9f5e5..d9e947eac041 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -136,26 +136,33 @@ static void *xa_load_or_alloc(struct xarray *xa, unsi= gned long index, size_t sz) return 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; =20 - physxa =3D xa_load(&track->orders, order); - if (!physxa) - continue; + bits =3D xa_load(&physxa->phys_bits, pfn_high / PRESERVE_BITS); + if (!bits) + return; =20 - bits =3D xa_load(&physxa->phys_bits, pfn_high / PRESERVE_BITS); - if (!bits) - continue; + clear_bit(pfn_high % PRESERVE_BITS, bits->preserve); +} =20 - 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; + + while (pfn < end_pfn) { + order =3D min(count_trailing_zeros(pfn), ilog2(end_pfn - pfn)); + + __kho_unpreserve_order(track, pfn, order); =20 pfn +=3D 1 << order; } @@ -667,6 +674,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_phys - preserve a physically contiguous range across kexec. * @phys: physical address of the range. @@ -712,6 +743,39 @@ int kho_preserve_phys(phys_addr_t phys, size_t size) } EXPORT_SYMBOL_GPL(kho_preserve_phys); =20 +/** + * kho_unpreserve_phys - unpreserve a physically contiguous range. + * @phys: physical address of the range. + * @size: size of the range. + * + * Instructs KHO to unpreserve the memory range from @phys to @phys + @siz= e. + * The @phys address must be aligned to @size, and @size must be a + * power-of-2 multiple of PAGE_SIZE. + * This call must exactly match a granularity at which memory was original= ly + * preserved (either by a `kho_preserve_phys` call with the same `phys` and + * `size`). Unpreserving arbitrary sub-ranges of larger preserved blocks i= s not + * supported. + * + * Return: 0 on success, error code on failure + */ +int kho_unpreserve_phys(phys_addr_t phys, size_t size) +{ + struct kho_mem_track *track =3D &kho_out.track; + unsigned long pfn =3D PHYS_PFN(phys); + unsigned long end_pfn =3D PHYS_PFN(phys + size); + + if (kho_out.finalized) + return -EBUSY; + + if (!PAGE_ALIGNED(phys) || !PAGE_ALIGNED(size)) + return -EINVAL; + + __kho_unpreserve(track, pfn, end_pfn); + + return 0; +} +EXPORT_SYMBOL_GPL(kho_unpreserve_phys); + static int __kho_abort(void) { int err =3D 0; --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:38 2025 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 299FA302048 for ; Wed, 25 Jun 2025 23:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893539; cv=none; b=T/6BMlEHmtW8BkM1rGKM8UTvK8i+ERZezEIOLa9WaLT3hHyRVEHtRukUMt6GDGNkvjUGslaUTy7pVgHSqYzovZjrLjyEKZqxSbTvXTSez5FDGzPf2ov9PPwHbFfm6oiWhAaHAlMkEkYifzmLtLkJcyrgQskrZI96JzwXiCdRdyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893539; c=relaxed/simple; bh=QtmBwOe5Py6ndIWGzbeMkxazGPHNwvaG1USoZ4ofzzY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dKo5S8js/GWI0IGKwAp/yh3M+GPde+j8k3BWII8LQqfgdAgqS66mQleVqXLq2V69qf+wwViCwAtW+bPC7HNQVqVDj6bLIfLu1n8zH8aAtBHOzuxdwZUm9kM382K5/2Re9qYBjDXN2OGI93fajwuEvtewU84lMsH6A0NKQ4pOgDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=pEeEZ3EQ; arc=none smtp.client-ip=209.85.219.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="pEeEZ3EQ" Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e81826d5b72so297301276.3 for ; Wed, 25 Jun 2025 16:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893537; x=1751498337; 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=IiOsnbmXgKqRz5wWOYZUUHO12tKj0FKseA6eFuor5tk=; b=pEeEZ3EQ+f6PqmtRLOCl3EhegfTA9Pfm3mt/LaUcL66MENvJ2ogWORqm2A5nILmeHT YtYTgGwZJRkiOf+1QAb+LFAHFbX/P0Z2EiwHwkPtuVftY1ko40XK0aPphpQsS6xWFONd tOtu3QUhNp7MYqaBBq89vvQOjsx3hzp1VZJzldCBj/8NVNrg2b7/sN3XE9jlrUn7uA98 Wyuf/7+FAMfn/mb9gb+kY0m3GXd0qcRLFliLGGKxvNvgS/41xeFWy5KW8pSmUyyo808+ byqowGTaYfRdYfeXwloX4qo6ckCbWBldRdyiaOfQd12ws3LYm5fLrfxzW8Ad68KN6kiC QpFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893537; x=1751498337; 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=IiOsnbmXgKqRz5wWOYZUUHO12tKj0FKseA6eFuor5tk=; b=BVWWKdQwVnp5I7ENhNY7Zk07dUB2XKoW9aqFLxcpjRigXScK07VmVZLz4hxJGmdi+9 V6StpjOtn9e1HbsD8HnG6TMXYftU+FLL1DrWMdCsS6tBn8bAiKIjj4WIZuPq53L8N7eP j3L35Oe+12IeDbtC9PbB7FSiVBIbqUe1YD3GaBgRPSyQnepI2RaJ9JwlhWqPY2YXJ5C6 3gkzWZ0KNEIZNGxWyJquKwO+ntugeyE5b4+EH1FlATGvw7proJXaph44As2lhKxZNabm VAD8VNhum2NsMQXmhPRY0fm5xIn9SssGJfKOD5HZcVwGKP+uxjDHiNlRysrC0OdLO/pS aXvA== X-Forwarded-Encrypted: i=1; AJvYcCUJOza43eOJ1IWRdW6GydoJSa78A3pAEc3Bc7yBmQOAycr3+9/WHi7oqbIS4F+30/oFWievyyHxq30THJg=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+UqIKBRsNBFlZsjMx/Tje/iPrRwzZyOtDWWH8sIzyc/gzel6W d9DXAVNFkaIbc/leZxIkAd9eEXvu8MRhSb/C8sgbtBbhx3RjSNDJtaLi8QiuMXuYmpk= X-Gm-Gg: ASbGncviR7+V/2hEFqqUq+qCiiiZayLsLHq6nWonfPNLBT7N1COfVdz/C13GnEDq+YQ avF2k0QOqDCShB3W7y0ixIVzseYFy4oR9Wusfp5FuE44J2xCgtBJUhT4pAt6Ox6/GXjafe/dWEZ fr9J0z7rV7bAz8B+AVqhkeAFrX6pXa9gEAVhCNP6nxW3FKh9UaLaWvGW5Au4trjnW/X1+WaMPyS pBNFpFERtcx0wEml3Zvj7xHQTlVhYCqppKE7ES5jUTTInAeAxJL1kykj3hs0uqMUa/haEPsvb6y iGYpDsPp7Fh5x1lblmedKKO7jYDCJmAiqWMl3YJTjINEK8YoD3d+q40E6rLW6Caktzz9+CIZ/us tBiYCoGTAafY48t1XacWBIFSYd30Hh1FlJo5NNPDIUqjFoO6PunICd7Odd3vFPBY= X-Google-Smtp-Source: AGHT+IHpMMB7jazz0bY3ev82KOYzlZveTNga66zjJgcMQk/SF9LbDk+lxuWqWkLu9eZxFgZd+C91eQ== X-Received: by 2002:a05:6902:1246:b0:e81:cab6:6db5 with SMTP id 3f1490d57ef6-e86016cfbebmr6753343276.8.1750893537044; Wed, 25 Jun 2025 16:18:57 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.18.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:18:56 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 08/32] kho: don't unpreserve memory during abort Date: Wed, 25 Jun 2025 23:17:55 +0000 Message-ID: <20250625231838.1897085-9-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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 --- 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 d9e947eac041..7ec9b0826a6e 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -778,31 +778,12 @@ EXPORT_SYMBOL_GPL(kho_unpreserve_phys); =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.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:38 2025 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.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 B307130205A for ; Wed, 25 Jun 2025 23:18:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893542; cv=none; b=o/INuhcLi+xMmEstLAD2QWIumjL2A6AsMw9nKRC482yaTX4OiloPz96GphoS9hbs9VsgGxyKvpU5oiE/g6YRUntLY7sek6H/NPMYDbN8aGZ5eWQousnW3SFJ6X90pjLdLdqFpWSP9elNFpiZM+8vK5SlB2Skm73jq7/mFRHCorM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893542; c=relaxed/simple; bh=BXlvF5+wG9a49YHeDegji45HdU5XmiXcQcZPm60p+6w=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SdKtnKIi0+aY3AW/YQCR7LO3o1PVX6SpBdlsBcP9L+1sTmI1NCXwq40tRtD/6vxBLB+WD7f+2UXzHDgivl3npqq+0G7DJAQes1TLO8L5EeIULPfq3GvxT5WJq3XRWTmZLK621YmuTbbKmS7iLu8yA4o95m9/fmkuEQdQ2Zbnls0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=LMZcWpmE; arc=none smtp.client-ip=209.85.219.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="LMZcWpmE" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e8273504c67so357624276.0 for ; Wed, 25 Jun 2025 16:18:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893539; x=1751498339; 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=/CZq9og4E2iYswOQvh/BeoWWVk3VTVb3cQyp5vwN8F0=; b=LMZcWpmEd+mGHvMWRndtZ5bjTxLeaTg+SwAC5/GblcAP/iiibpiP6S6I8YiG2SpbaZ A4t8VzmuO2EgyI9n4BAz3r5fni9q3DSnU6hJAyKklvwHE8/MSNTN76L/6Gv8wlICu7QO 0a+oigJW/gBxKuhle3RdC2Iv1SE+i4V5VrjS7Bci82A37dvS9Wv3WWKIAby02x1GGEUM KBL1WZSz9Jtlg1QQK3OJpcKRxenmToTfOzagbnUFP5EEygvbmQfW1yKliL2vv2PoJeT/ TobkeYLBk1gVr1EXb6gkfIxAdS+ym5NdFkzbV2klVCHPFpcL0axqY/gllCatFySSXn++ UlVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893539; x=1751498339; 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=/CZq9og4E2iYswOQvh/BeoWWVk3VTVb3cQyp5vwN8F0=; b=kExIEFYz62Dp3hSeQv553rbE2nBT6ZJP6cfvm3ujg0VpFXfoPcxTgDjFpG8VUm+WoL H+VChlB4AO0lrxCMxkip7FYQ4jAweSP3FRF+Y2MBjn3JM8Z+AmFoOGNcZt2l8g8g8uL1 OlXJ665AdvXiAE8nySYVpRoTD6cq3HU2LRkNmMEcp89885svdlgMY5to8HEN0ir40rx2 9AqE5VWJ7uRmvdogiMMXZDMsWPdOZCD6/I+wsuWs9bkGGeUUG+6o6f9tmk5Mwbw96z0D pA6i7ikOAkwwFmYutbdmvoT6a8fSFeH/awrXjsqxhMcsZGa46bqo6hF5TxVTPvE5mJ5C jtAQ== X-Forwarded-Encrypted: i=1; AJvYcCUOQ5kJ2xOqZIFCUTfRIUOxb2c4WCZqtutqE/N+DTbh7gd89mtugRveqFY8pLsw5ZGGpLN/BCrWHphG6w0=@vger.kernel.org X-Gm-Message-State: AOJu0Ywj2BV50OqIWs7ZvOWVxz+dS7sD/XGxyaXtXAli5jKDTmt0yFJI LNsSOss0sLKCVpD8aUNiRoIwR1I9pdsRGvJyfmFO5iiREQ1wFxrH3WD6w+aLTaNwvGQ= X-Gm-Gg: ASbGncuzC0JK+mq5dDNAZktS/ig8gumJ9dBKhuA3BoEG/iW19XvVmfrZaldsOkPIOtP PwdhLplf68jIuUSQrxQ/pglVZ6zEcTDoBzj+qBTMVx7zrf0xu4f0wcdoHPfEGKCKUXC5ikYqcsO nycpnpbOQsEHmRKnrkWT2CtOss6GF0N2wfqfkpdFa5yjc0En6TUXIx4iFnLfyo0XoP9FC2j9It4 9BsQv8NBreHJMUB7cVWZgxgota1IBl8NPx0N4cHtPPaVbG29lMVhOIJXbFLUuNowyiOkw2tx7P0 Wi2WuEnHXFV9T8wcOmk0sjW89FqUROCojfX4X8ndkNb08NojJW1TaPvh15Row/hfb5k6MKG7324 0XfiTxvQt+5KyCNzi/YOKlCs07eYDNmZESZrM5iGbxsCMfI2sVYbJ X-Google-Smtp-Source: AGHT+IEvjiL52mwTnep5Cm1LT/Mafe7xzjNymqDf9OgtY/gdqSxumZYzT41sOZggnwLsDEbcl9BxxQ== X-Received: by 2002:a05:6902:2808:b0:e82:1a1e:8b04 with SMTP id 3f1490d57ef6-e86019486d4mr6292329276.33.1750893538669; Wed, 25 Jun 2025 16:18:58 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:18:58 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 09/32] liveupdate: kho: move to kernel/liveupdate Date: Wed, 25 Jun 2025 23:17:56 +0000 Message-ID: <20250625231838.1897085-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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 --- Documentation/core-api/kho/concepts.rst | 2 +- MAINTAINERS | 2 +- init/Kconfig | 2 ++ kernel/Kconfig.kexec | 25 ---------------- kernel/Makefile | 3 +- kernel/liveupdate/Kconfig | 30 +++++++++++++++++++ kernel/liveupdate/Makefile | 7 +++++ kernel/{ =3D> liveupdate}/kexec_handover.c | 6 ++-- .../{ =3D> liveupdate}/kexec_handover_debug.c | 0 .../kexec_handover_internal.h | 0 10 files changed, 45 insertions(+), 32 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_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 8ef6df1c4611..fd097e53fff2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13353,7 +13353,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* =20 KEYS-ENCRYPTED M: Mimi Zohar diff --git a/init/Kconfig b/init/Kconfig index af4c2f085455..a144d1111be5 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2079,6 +2079,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 2b18a06bc5b2..ceadf4a66496 100644 --- a/kernel/Kconfig.kexec +++ b/kernel/Kconfig.kexec @@ -94,31 +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 "kexec handover debug 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 e4b4afa86a70..632f692512d7 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -53,6 +53,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-$(CONFIG_MODULES) +=3D module/ @@ -81,8 +82,6 @@ obj-$(CONFIG_CRASH_DM_CRYPT) +=3D crash_dump_dm_crypt.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_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..eebe564b385d --- /dev/null +++ b/kernel/liveupdate/Kconfig @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0-only + +menu "Live Update" + +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 "kexec handover debug 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..72cf7a8e6739 --- /dev/null +++ b/kernel/liveupdate/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the linux kernel. +# + +obj-$(CONFIG_KEXEC_HANDOVER) +=3D kexec_handover.o +obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) +=3D kexec_handover_debug.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 7ec9b0826a6e..d7eb0f055477 100644 --- a/kernel/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -23,8 +23,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" @@ -825,7 +825,7 @@ static int __kho_finalize(void) 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. 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_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.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:38 2025 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) (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 AA041307AC8 for ; Wed, 25 Jun 2025 23:19:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893544; cv=none; b=GHyJJ1fv8kVPbto3apUePwkBiTbkYaKW7Fa2pW/FMy4lzhHF4P+rCl0r+FmPrMaND8SCKY5jxkMnL0Opq0W37ntbuBkMJI7gKg3LjwRM1sCaXaC3+/LXeO57viDxON8Nl22s9UfTfQV6Up3x7vwcnOcFf67hReDcXJib0bX9iUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893544; c=relaxed/simple; bh=6xtfxyIVDA3x4P9xsRb/FLVHQxnX4xAqJhNXgoG+/2Y=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YDIu2kufKLNCwWmxfwWe24G50QswZpJCMWTL5L5VarUsfRYdDrHY19fZiyBex/mihDAAc3PMr3YSjqPC5gZf07d9PV2PIQthXNhk4kQRLtucJSiEZya4Zwn0+vXObdc2pnFv6RDpNDYc1IilQJ7QbMxP9+Th1vpGx7mkl0HZ93I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=ezuL8P2P; arc=none smtp.client-ip=209.85.219.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="ezuL8P2P" Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-e7b4ba530feso321608276.1 for ; Wed, 25 Jun 2025 16:19:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893540; x=1751498340; 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=vXQSCYE6FRs6KbafkWlGbnDNp03kOfKlk9RAaFRpXVc=; b=ezuL8P2PQ0nUD9QMLWuW/w1SEJ2BlYelUL9/6PPHWJj3cjDdCt6l3JjPGveji+tuO7 Ox0bP7rWdldYH/qpoFu9JwZSCpAjLc23xcX0G5SfTokJhoPsSi1GwnyGYfCAgwiqh9RG 5HXtXxB5nod9hfGOsSr+UJbC8ovVz/cxcvz33Qowp7WCdSR9eIZ7zo7J7i8OsCpAT+d0 R8IGlPjNRzRftjTMEzP2ld1+zJc6d4bCn79ozsbnAqQ+Lj7ZXR0MZjFE91upHAFGH1c9 JS8mKfyY0SpnSLG185x/7Y790G4GbD0zqGtn/lIqrktHfLsSOW2Ivilc1mlE1wr5arD8 2FSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893540; x=1751498340; 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=vXQSCYE6FRs6KbafkWlGbnDNp03kOfKlk9RAaFRpXVc=; b=J2PPOvlDTeb5KqWl8Q2/QMpaFeF6Jr//iyjzZ5HD4FPgip8VRIwfLQBjXDo5Ve6t1A TgHMuVkLvJM7HhssW1ru0P6X79lyOhRjZeEVvw6pg68zt6KksBY1bJOelQsCp9h58JYA XZGdl05Hl7a2DruJk9bH9xwmzouDK140PmnjSEzrOiqfF0wi8SZ8rSSjWV2jK8zGQU+W NB6VFD/bO2D29wU7sE5gz9B8bfuelk+7bvBT19IwbujXbL7UcX08e1AjIPml2koyE5rA I2ZM2JcTE1DUXVMfUYbE3wQ4NJ8gT1dHFRreF3hGqJLkZKN2jQCACDofJuK/adNCAVaD F1SQ== X-Forwarded-Encrypted: i=1; AJvYcCUl3qMas5RSdz1MUsoS5esaFUaXJ03rw8madG1AzvX4C68V/S2vtQcn5uXrv59/1I3rgNlo8KTA5QX/o/w=@vger.kernel.org X-Gm-Message-State: AOJu0Yw409HcwxaGDWy/xPQxkaaVCU2/EXz46QOR9eTEllpjl4Oaez0K bilbbN950Fi/xpAiiP9TuBzo2gI5kcEXiRWf9Ho/T5cMUkV098L/qiNWQKChBWYRbqs= X-Gm-Gg: ASbGncstMuZgzdKW+CWkCW+MgC0zVD/OQcMWdJnfFG3QxnUtXIxpFwR7iTivMvS4Tse +pkIzX3BPnaLV5yIGyGhqs8qItK0jzXVFymNJFvsIvG8UP5sQzr1VWDPOUkKG+YCF4FYTuRDQ2x jYFM1nJvQQgnOgupmPQXO/3w94LY2rDS1TxP5aOT2NPkKSBl8c0YuKOyrnAtfFY3IAVLyCCHDCj k7RwgEvFfwxApPFR8Z88rnGacu1acwGz2aZjfdIPOp2eAH3W7RHt+YA44iZ8cK6EWXA41mtfcLM Tof3RMONavqiU3KH5xW3G0jU3FovHpVMFeF9moQsAsjqF9cuQgN2wHlQZGKcccdoRDEciE/O/85 ivLXJD4gMhLB4aBc76wjEroGv0Eelp04l2s8aPDGtHlmYs+LLyYBC X-Google-Smtp-Source: AGHT+IGb5jpj+lR8B4V1EdiLiIhq8yNrbuVpil4bq/wKcbYtJkrB5Vn3xe5pq9zheewjqjwlpWUU3A== X-Received: by 2002:a05:6902:6303:b0:e84:1f6b:ed95 with SMTP id 3f1490d57ef6-e8601777d9fmr3908638276.26.1750893540421; Wed, 25 Jun 2025 16:19:00 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.18.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:18:59 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 10/32] liveupdate: luo_core: Live Update Orchestrator Date: Wed, 25 Jun 2025 23:17:57 +0000 Message-ID: <20250625231838.1897085-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Introduce LUO, a mechanism intended to facilitate kernel updates while keeping designated devices operational across the transition (e.g., via kexec). The primary use case is updating hypervisors with minimal disruption to running virtual machines. For userspace side of hypervisor update we have copyless migration. LUO is for updating the kernel. This initial patch lays the groundwork for the LUO subsystem. Further functionality, including the implementation of state transition logic, integration with KHO, and hooks for subsystems and file descriptors, will be added in subsequent patches. Signed-off-by: Pasha Tatashin --- include/linux/liveupdate.h | 140 ++++++++++++++ kernel/liveupdate/Kconfig | 27 +++ kernel/liveupdate/Makefile | 1 + kernel/liveupdate/luo_core.c | 301 +++++++++++++++++++++++++++++++ kernel/liveupdate/luo_internal.h | 21 +++ 5 files changed, 490 insertions(+) create mode 100644 include/linux/liveupdate.h create mode 100644 kernel/liveupdate/luo_core.c create mode 100644 kernel/liveupdate/luo_internal.h diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h new file mode 100644 index 000000000000..da8f05c81e51 --- /dev/null +++ b/include/linux/liveupdate.h @@ -0,0 +1,140 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ +#ifndef _LINUX_LIVEUPDATE_H +#define _LINUX_LIVEUPDATE_H + +#include +#include +#include + +/** + * enum liveupdate_event - Events that trigger live update callbacks. + * @LIVEUPDATE_PREPARE: PREPARE should happen *before* the blackout window. + * Subsystems should prepare for an upcoming reboot by + * serializing their states. However, it must be cons= idered + * that user applications, e.g. virtual machines are = still + * running during this phase. + * @LIVEUPDATE_FREEZE: FREEZE sent from the reboot() syscall, when the cu= rrent + * kernel is on its way out. This is the final opport= unity + * for subsystems to save any state that must persist + * across the reboot. Callbacks for this event should= be as + * fast as possible since they are on the critical pa= th of + * rebooting into the next kernel. + * @LIVEUPDATE_FINISH: FINISH is sent in the newly booted kernel after a + * successful live update and normally *after* the bl= ackout + * window. Subsystems should perform any final cleanup + * during this phase. This phase also provides an + * opportunity to clean up devices that were preserve= d but + * never explicitly reclaimed during the live update + * process. State restoration should have already occ= urred + * before this event. Callbacks for this event must n= ot + * fail. The completion of this call transitions the + * machine from ``updated`` to ``normal`` state. + * @LIVEUPDATE_CANCEL: CANCEL the live update and go back to normal state= . This + * event is user initiated, or is done automatically = when + * LIVEUPDATE_PREPARE or LIVEUPDATE_FREEZE stage fail= s. + * Subsystems should revert any actions taken during = the + * corresponding prepare event. Callbacks for this ev= ent + * must not fail. + * + * These events represent the different stages and actions within the live + * update process that subsystems (like device drivers and bus drivers) + * need to be aware of to correctly serialize and restore their state. + * + */ +enum liveupdate_event { + LIVEUPDATE_PREPARE, + LIVEUPDATE_FREEZE, + LIVEUPDATE_FINISH, + LIVEUPDATE_CANCEL, +}; + +/** + * enum liveupdate_state - Defines the possible states of the live update + * orchestrator. + * @LIVEUPDATE_STATE_UNDEFINED: State has not yet been initialized. + * @LIVEUPDATE_STATE_NORMAL: Default state, no live update in prog= ress. + * @LIVEUPDATE_STATE_PREPARED: Live update is prepared for reboot; t= he + * LIVEUPDATE_PREPARE callbacks have com= pleted + * successfully. + * Devices might operate in a limited st= ate + * for example the participating devices= might + * not be allowed to unbind, and also the + * setting up of new DMA mappings might = be + * disabled in this state. + * @LIVEUPDATE_STATE_FROZEN: The final reboot event + * (%LIVEUPDATE_FREEZE) has been sent, a= nd the + * system is performing its final state = saving + * within the "blackout window". User + * workloads must be suspended. The actu= al + * reboot (kexec) into the next kernel is + * imminent. + * @LIVEUPDATE_STATE_UPDATED: The system has rebooted into the next + * kernel via live update the system is = now + * running the next kernel, awaiting the + * finish event. + * + * These states track the progress and outcome of a live update operation. + */ +enum liveupdate_state { + LIVEUPDATE_STATE_UNDEFINED =3D 0, + LIVEUPDATE_STATE_NORMAL =3D 1, + LIVEUPDATE_STATE_PREPARED =3D 2, + LIVEUPDATE_STATE_FROZEN =3D 3, + LIVEUPDATE_STATE_UPDATED =3D 4, +}; + +#ifdef CONFIG_LIVEUPDATE + +/* Return true if live update orchestrator is enabled */ +bool liveupdate_enabled(void); + +/* Called during reboot to tell participants to complete serialization */ +int liveupdate_reboot(void); + +/* + * Return true if machine is in updated state (i.e. live update boot in + * progress) + */ +bool liveupdate_state_updated(void); + +/* + * Return true if machine is in normal state (i.e. no live update in progr= ess). + */ +bool liveupdate_state_normal(void); + +enum liveupdate_state liveupdate_get_state(void); + +#else /* CONFIG_LIVEUPDATE */ + +static inline int liveupdate_reboot(void) +{ + return 0; +} + +static inline bool liveupdate_enabled(void) +{ + return false; +} + +static inline bool liveupdate_state_updated(void) +{ + return false; +} + +static inline bool liveupdate_state_normal(void) +{ + return true; +} + +static inline enum liveupdate_state liveupdate_get_state(void) +{ + return LIVEUPDATE_STATE_NORMAL; +} + +#endif /* CONFIG_LIVEUPDATE */ +#endif /* _LINUX_LIVEUPDATE_H */ diff --git a/kernel/liveupdate/Kconfig b/kernel/liveupdate/Kconfig index eebe564b385d..f6b0bde188d9 100644 --- a/kernel/liveupdate/Kconfig +++ b/kernel/liveupdate/Kconfig @@ -1,7 +1,34 @@ # SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (c) 2025, Google LLC. +# Pasha Tatashin +# +# Live Update Orchestrator +# =20 menu "Live Update" =20 +config LIVEUPDATE + bool "Live Update Orchestrator" + depends on KEXEC_HANDOVER + help + Enable the Live Update Orchestrator. Live Update is a mechanism, + typically based on kexec, that allows the kernel to be updated + while keeping selected devices operational across the transition. + These devices are intended to be reclaimed by the new kernel and + re-attached to their original workload without requiring a device + reset. + + Ability to handover a device from current to the next kernel depends + on specific support within device drivers and related kernel + subsystems. + + This feature primarily targets virtual machine hosts to quickly update + the kernel hypervisor with minimal disruption to the running virtual + machines. + + If unsure, say N. + config KEXEC_HANDOVER bool "kexec handover" depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE diff --git a/kernel/liveupdate/Makefile b/kernel/liveupdate/Makefile index 72cf7a8e6739..b3c72c405780 100644 --- a/kernel/liveupdate/Makefile +++ b/kernel/liveupdate/Makefile @@ -5,3 +5,4 @@ =20 obj-$(CONFIG_KEXEC_HANDOVER) +=3D kexec_handover.o obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) +=3D kexec_handover_debug.o +obj-$(CONFIG_LIVEUPDATE) +=3D luo_core.o diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c new file mode 100644 index 000000000000..8cee093807ff --- /dev/null +++ b/kernel/liveupdate/luo_core.c @@ -0,0 +1,301 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: Live Update Orchestrator (LUO) + * + * Live Update is a specialized, kexec-based reboot process that allows a + * running kernel to be updated from one version to another while preservi= ng + * the state of selected resources and keeping designated hardware devices + * operational. For these devices, DMA activity may continue throughout the + * kernel transition. + * + * While the primary use case driving this work is supporting live updates= of + * the Linux kernel when it is used as a hypervisor in cloud environments,= the + * LUO framework itself is designed to be workload-agnostic. Much like Ker= nel + * Live Patching, which applies security fixes regardless of the workload, + * Live Update facilitates a full kernel version upgrade for any type of s= ystem. + * + * For example, a non-hypervisor system running an in-memory cache like + * memcached with many gigabytes of data can use LUO. The userspace service + * can place its cache into a memfd, have its state preserved by LUO, and + * restore it immediately after the kernel kexec. + * + * Whether the system is running virtual machines, containers, a + * high-performance database, or networking services, LUO's primary goal i= s to + * enable a full kernel update by preserving critical userspace state and + * keeping essential devices operational. + * + * The core of LUO is a state machine that tracks the progress of a live u= pdate, + * along with a callback API that allows other kernel subsystems to partic= ipate + * in the process. Example subsystems that can hook into LUO include: kvm, + * iommu, interrupts, vfio, participating filesystems, and memory manageme= nt. + * + * LUO uses Kexec Handover to transfer memory state from the current kerne= l to + * the next kernel. For more details see + * Documentation/core-api/kho/concepts.rst. + * + * The LUO state machine ensures that operations are performed in the corr= ect + * sequence and provides a mechanism to track and recover from potential + * failures. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include "luo_internal.h" + +static DECLARE_RWSEM(luo_state_rwsem); + +static enum liveupdate_state luo_state =3D LIVEUPDATE_STATE_UNDEFINED; + +static const char *const luo_state_str[] =3D { + [LIVEUPDATE_STATE_UNDEFINED] =3D "undefined", + [LIVEUPDATE_STATE_NORMAL] =3D "normal", + [LIVEUPDATE_STATE_PREPARED] =3D "prepared", + [LIVEUPDATE_STATE_FROZEN] =3D "frozen", + [LIVEUPDATE_STATE_UPDATED] =3D "updated", +}; + +static bool luo_enabled; + +static int __init early_liveupdate_param(char *buf) +{ + return kstrtobool(buf, &luo_enabled); +} +early_param("liveupdate", early_liveupdate_param); + +/* Return true if the current state is equal to the provided state */ +static inline bool is_current_luo_state(enum liveupdate_state expected_sta= te) +{ + return liveupdate_get_state() =3D=3D expected_state; +} + +static void __luo_set_state(enum liveupdate_state state) +{ + WRITE_ONCE(luo_state, state); +} + +static inline void luo_set_state(enum liveupdate_state state) +{ + pr_info("Switched from [%s] to [%s] state\n", + luo_current_state_str(), luo_state_str[state]); + __luo_set_state(state); +} + +static int luo_do_freeze_calls(void) +{ + return 0; +} + +static void luo_do_finish_calls(void) +{ +} + +/* Get the current state as a string */ +const char *luo_current_state_str(void) +{ + return luo_state_str[liveupdate_get_state()]; +} + +enum liveupdate_state liveupdate_get_state(void) +{ + return READ_ONCE(luo_state); +} + +int luo_prepare(void) +{ + return 0; +} + +/** + * luo_freeze() - Initiate the final freeze notification phase for live up= date. + * + * Attempts to transition the live update orchestrator state from + * %LIVEUPDATE_STATE_PREPARED to %LIVEUPDATE_STATE_FROZEN. This function is + * typically called just before the actual reboot system call (e.g., kexec) + * is invoked, either directly by the orchestration tool or potentially fr= om + * within the reboot syscall path itself. + * + * @return 0: Success. Negative error otherwise. State is reverted to + * %LIVEUPDATE_STATE_NORMAL in case of an error during callbacks, and ever= ything + * is canceled via cancel notifcation. + */ +int luo_freeze(void) +{ + int ret; + + if (down_write_killable(&luo_state_rwsem)) { + pr_warn("[freeze] event canceled by user\n"); + return -EAGAIN; + } + + if (!is_current_luo_state(LIVEUPDATE_STATE_PREPARED)) { + pr_warn("Can't switch to [%s] from [%s] state\n", + luo_state_str[LIVEUPDATE_STATE_FROZEN], + luo_current_state_str()); + up_write(&luo_state_rwsem); + + return -EINVAL; + } + + ret =3D luo_do_freeze_calls(); + if (!ret) + luo_set_state(LIVEUPDATE_STATE_FROZEN); + else + luo_set_state(LIVEUPDATE_STATE_NORMAL); + + up_write(&luo_state_rwsem); + + return ret; +} + +/** + * luo_finish - Finalize the live update process in the new kernel. + * + * This function is called after a successful live update reboot into a n= ew + * kernel, once the new kernel is ready to transition to the normal operat= ional + * state. It signals the completion of the live update sequence to subsyst= ems. + * + * @return 0 on success, ``-EAGAIN`` if the state change was cancelled by = the + * user while waiting for the lock, or ``-EINVAL`` if the orchestrator is = not in + * the updated state. + */ +int luo_finish(void) +{ + if (down_write_killable(&luo_state_rwsem)) { + pr_warn("[finish] event canceled by user\n"); + return -EAGAIN; + } + + if (!is_current_luo_state(LIVEUPDATE_STATE_UPDATED)) { + pr_warn("Can't switch to [%s] from [%s] state\n", + luo_state_str[LIVEUPDATE_STATE_NORMAL], + luo_current_state_str()); + up_write(&luo_state_rwsem); + + return -EINVAL; + } + + luo_do_finish_calls(); + luo_set_state(LIVEUPDATE_STATE_NORMAL); + + up_write(&luo_state_rwsem); + + return 0; +} + +int luo_cancel(void) +{ + return 0; +} + +void luo_state_read_enter(void) +{ + down_read(&luo_state_rwsem); +} + +void luo_state_read_exit(void) +{ + up_read(&luo_state_rwsem); +} + +static int __init luo_startup(void) +{ + __luo_set_state(LIVEUPDATE_STATE_NORMAL); + + return 0; +} +early_initcall(luo_startup); + +/* Public Functions */ + +/** + * liveupdate_reboot() - Kernel reboot notifier for live update final + * serialization. + * + * This function is invoked directly from the reboot() syscall pathway if a + * reboot is initiated while the live update state is %LIVEUPDATE_STATE_PR= EPARED + * (i.e., if the user did not explicitly trigger the frozen state). It han= dles + * the implicit transition into the final frozen state. + * + * It triggers the %LIVEUPDATE_REBOOT event callbacks for participating + * subsystems. These callbacks must perform final state saving very quickl= y as + * they execute during the blackout period just before kexec. + * + * If any %LIVEUPDATE_FREEZE callback fails, this function triggers the + * %LIVEUPDATE_CANCEL event for all participants to revert their state, ab= orts + * the live update, and returns an error. + */ +int liveupdate_reboot(void) +{ + if (!is_current_luo_state(LIVEUPDATE_STATE_PREPARED)) + return 0; + + return luo_freeze(); +} +EXPORT_SYMBOL_GPL(liveupdate_reboot); + +/** + * liveupdate_state_updated - Check if the system is in the live update + * 'updated' state. + * + * This function checks if the live update orchestrator is in the + * ``LIVEUPDATE_STATE_UPDATED`` state. This state indicates that the syste= m has + * successfully rebooted into a new kernel as part of a live update, and t= he + * preserved devices are expected to be in the process of being reclaimed. + * + * This is typically used by subsystems during early boot of the new kernel + * to determine if they need to attempt to restore state from a previous + * live update. + * + * @return true if the system is in the ``LIVEUPDATE_STATE_UPDATED`` state, + * false otherwise. + */ +bool liveupdate_state_updated(void) +{ + return is_current_luo_state(LIVEUPDATE_STATE_UPDATED); +} +EXPORT_SYMBOL_GPL(liveupdate_state_updated); + +/** + * liveupdate_state_normal - Check if the system is in the live update 'no= rmal' + * state. + * + * This function checks if the live update orchestrator is in the + * ``LIVEUPDATE_STATE_NORMAL`` state. This state indicates that no live up= date + * is in progress. It represents the default operational state of the syst= em. + * + * This can be used to gate actions that should only be performed when no + * live update activity is occurring. + * + * @return true if the system is in the ``LIVEUPDATE_STATE_NORMAL`` state, + * false otherwise. + */ +bool liveupdate_state_normal(void) +{ + return is_current_luo_state(LIVEUPDATE_STATE_NORMAL); +} +EXPORT_SYMBOL_GPL(liveupdate_state_normal); + +/** + * liveupdate_enabled - Check if the live update feature is enabled. + * + * This function returns the state of the live update feature flag, which + * can be controlled via the ``liveupdate`` kernel command-line parameter. + * + * @return true if live update is enabled, false otherwise. + */ +bool liveupdate_enabled(void) +{ + return luo_enabled; +} +EXPORT_SYMBOL_GPL(liveupdate_enabled); diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h new file mode 100644 index 000000000000..3d10f3eb20a7 --- /dev/null +++ b/kernel/liveupdate/luo_internal.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#ifndef _LINUX_LUO_INTERNAL_H +#define _LINUX_LUO_INTERNAL_H + +int luo_cancel(void); +int luo_prepare(void); +int luo_freeze(void); +int luo_finish(void); + +void luo_state_read_enter(void); +void luo_state_read_exit(void); + +const char *luo_current_state_str(void); + +#endif /* _LINUX_LUO_INTERNAL_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:38 2025 Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (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 412262FCE06 for ; Wed, 25 Jun 2025 23:19:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893545; cv=none; b=JIW8K9li4NxFIqlPc0W0VtV8jMh1NmC+ljnPNOiKvlsg4KqtN9Gh2+CfVuuuGN6MeX2IS5oHuuf2HlM95B/tpWULBHTTDoBTnradPu1LItwCVE8J3tS40qv8tvJTOBAvDSUHrkPyKa5d5oZxCYYqeBE85owrJgGG2c2Eb98FydA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893545; c=relaxed/simple; bh=68fuMsTaKD3Wnucw9AAh9zoVaQeYptH5ixtgvH+HmAU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XRpwq6K+09KOAhqevMDzKlBdb+wFy3lep3+z2UuO3VuLaJ//eaQt9V4/6P0VelbmuYwZXhauk5mMa4E6BjfpEzzmu+vyhHjvHYp9msD/DwrnyiVpCsy71Dcbz5AQZI3PGFXYM13RGlVIywjzC4kT3XeV0jttUsS7xxlJjg/DH3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=AHgVed5e; arc=none smtp.client-ip=209.85.219.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="AHgVed5e" Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e818a572828so238549276.1 for ; Wed, 25 Jun 2025 16:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893542; x=1751498342; 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=4F1QX9qtkry2jc2ztpFtzfSo3tcuBncamP+UfSK+M08=; b=AHgVed5el8rxHvGE97nC/o9UM/A34JHm83keykgYo5iwFPhG/uskYQudVAowQT91J5 htLevU7aqbOb8ZWNrt56FIPwUPCZxahnJemtKFJNGzvjYGeFhiIKfJNzOjJDAbZZoFkO 2bjPqjGTGSTHzysI69etLsta7jGVl/K26s5RoNT8TBNJggNMYUMgiLYr3MRFQgnRAzmG q23KRURCjbsUFi05CNpgVt/MQ5oC1q5AI06uam+HjiGKYz3WNEsbTYOe8gytyssEChnU MraoHYU3A7PQGOyYGdBVDu1CtbrZwkA3yrko6weFS40qCeSAvFThzg7XHhy7q68/U0hA lDnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893542; x=1751498342; 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=4F1QX9qtkry2jc2ztpFtzfSo3tcuBncamP+UfSK+M08=; b=ODCLbnBg0PvwlPrwDFKFXAd9PyBvZCjOnAFO4PWdNGI2ttmHVYsq6bXgxHETV57F28 3/YkRFAOjuTuLdChswFUlDxuJPWYvSSkEicua+q+VatfEIAozVbNY5bVwewCoRTNxHPH JckAkycwsKhtXoRSygX2BNRcAGejNmNRTw8GlmabBlITOxRZelGd9pvHmoCT2UtMXBbU hucRyuehuQlnox5ogMxjqOtvPqrz+Km+akEipLojxOeoTAaSLXNasY9Zz/eK5KybEoLg l7/f44sMEWU9oq993C3zQseeqwelh0wwXjRKqODGoZwfG8irD32Q4sUx43yokFHO8kTI NlUQ== X-Forwarded-Encrypted: i=1; AJvYcCUyelZwAPzW9RA+FADNXR0qEQkqKMGCAsTVBfLWP/93yqaaayGPTZB9ZHOBk5lCTiTaWhLB5Xtd5oDHKN8=@vger.kernel.org X-Gm-Message-State: AOJu0Yxlm7Lg/CVIYzTrsez1+hOW0FW3slIx0sJuNjUWuOz2pGbz3csL Lye4O2GUSVMtf1B2olHnH7kXSmeKSLpgkXviPBEr1OcY7qlC/1DCdC8ikEcM0XpUlCk= X-Gm-Gg: ASbGncvM13P2p/9EFhHBG+8h4kJErR7fHYsMeXQpnyWZ6Kc2jKnvSZyaqF4j9K8OTHZ k1rAu0iJK+T4A+qL6PESN4IZ/0i+vs6dHPzo0Ezavl+6r9ZUtsb3Boe81Jd6SncPCF+H7fBZlzx LIbvHtvkW7VkCBPZ6V+IUx6xtsNjBDJSXYQLxQ0lUB4cU+H7zxBn/0PUfQHHnDn2IfbdR3+wlJT p++IJowq478W4cFlTSL8+8laIq+WO/uffPqY3TgiEtaAxtImkYm26H7xn8B8w35pvC0LbGUCueB GngMrArVvm1/CD+Qa4aXfFHsGvxGHB0bp8pZuuxbM62DNS0NNordNDVqZmPZZbf+EMJEKNC1JMO sYD1lfSXr1XaIrEj032oFwZbnn8vGvj107ZyNGgcqboGFtmbCmrMV X-Google-Smtp-Source: AGHT+IGHkMSrn3CvoK+LnPabyPMjm48vR48YNssx6eYQvoszRNH0D/SmJuTrsjKeAEbDObCnKlDNnA== X-Received: by 2002:a05:6902:1b0e:b0:e85:fe89:7f7c with SMTP id 3f1490d57ef6-e860179171emr6363421276.45.1750893542157; Wed, 25 Jun 2025 16:19:02 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:01 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 11/32] liveupdate: luo_core: integrate with KHO Date: Wed, 25 Jun 2025 23:17:58 +0000 Message-ID: <20250625231838.1897085-12-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Integrate the LUO with the KHO framework to enable passing LUO state across a kexec reboot. When LUO is transitioned to a "prepared" state, it tells KHO to finalize, so all memory segments that were added to KHO preservation list are getting preserved. After "Prepared" state no new segments can be preserved. If LUO is canceled, it also tells KHO to cancel the serialization, and therefore, later LUO can go back into the prepared state. This patch introduces the following changes: - During the KHO finalization phase allocate FDT blob. - Populate this FDT with a LUO compatibility string ("luo-v1"). - Implement a KHO notifier LUO now depends on `CONFIG_KEXEC_HANDOVER`. The core state transition logic (`luo_do_*_calls`) remains unimplemented in this patch. Signed-off-by: Pasha Tatashin --- kernel/liveupdate/luo_core.c | 214 ++++++++++++++++++++++++++++++++++- 1 file changed, 211 insertions(+), 3 deletions(-) diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index 8cee093807ff..c80a1f188359 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -47,9 +47,12 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 #include +#include #include +#include #include #include +#include #include #include "luo_internal.h" =20 @@ -67,6 +70,21 @@ static const char *const luo_state_str[] =3D { =20 static bool luo_enabled; =20 +static void *luo_fdt_out; +static void *luo_fdt_in; + +/* + * The LUO FDT size depends on the number of participating subsystems, + * + * The current fixed size (4K) is large enough to handle reasonable number= of + * preserved entities. If this size ever becomes insufficient, it can eith= er be + * increased, or a dynamic size calculation mechanism could be implemented= in + * the future. + */ +#define LUO_FDT_SIZE PAGE_SIZE +#define LUO_KHO_ENTRY_NAME "LUO" +#define LUO_COMPATIBLE "luo-v1" + static int __init early_liveupdate_param(char *buf) { return kstrtobool(buf, &luo_enabled); @@ -91,6 +109,60 @@ static inline void luo_set_state(enum liveupdate_state = state) __luo_set_state(state); } =20 +/* Called during the prepare phase, to create LUO fdt tree */ +static int luo_fdt_setup(void) +{ + void *fdt_out; + int ret; + + fdt_out =3D (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, + get_order(LUO_FDT_SIZE)); + if (!fdt_out) { + pr_err("failed to allocate FDT memory\n"); + return -ENOMEM; + } + + ret =3D fdt_create_empty_tree(fdt_out, LUO_FDT_SIZE); + if (ret) + goto exit_free; + + ret =3D fdt_setprop_string(fdt_out, 0, "compatible", LUO_COMPATIBLE); + if (ret) + goto exit_free; + + ret =3D kho_preserve_phys(__pa(fdt_out), LUO_FDT_SIZE); + if (ret) + goto exit_free; + + ret =3D kho_add_subtree(LUO_KHO_ENTRY_NAME, fdt_out); + if (ret) + goto exit_unpreserve; + luo_fdt_out =3D fdt_out; + + return 0; + +exit_unpreserve: + WARN_ON_ONCE(kho_unpreserve_phys(__pa(fdt_out), LUO_FDT_SIZE)); +exit_free: + free_pages((unsigned long)fdt_out, get_order(LUO_FDT_SIZE)); + pr_err("failed to prepare LUO FDT: %d\n", ret); + + return ret; +} + +static void luo_fdt_destroy(void) +{ + WARN_ON_ONCE(kho_unpreserve_phys(__pa(luo_fdt_out), LUO_FDT_SIZE)); + kho_remove_subtree(luo_fdt_out); + free_pages((unsigned long)luo_fdt_out, get_order(LUO_FDT_SIZE)); + luo_fdt_out =3D NULL; +} + +static int luo_do_prepare_calls(void) +{ + return 0; +} + static int luo_do_freeze_calls(void) { return 0; @@ -100,6 +172,71 @@ static void luo_do_finish_calls(void) { } =20 +static void luo_do_cancel_calls(void) +{ +} + +static int __luo_prepare(void) +{ + int ret; + + if (down_write_killable(&luo_state_rwsem)) { + pr_warn("[prepare] event canceled by user\n"); + return -EAGAIN; + } + + if (!is_current_luo_state(LIVEUPDATE_STATE_NORMAL)) { + pr_warn("Can't switch to [%s] from [%s] state\n", + luo_state_str[LIVEUPDATE_STATE_PREPARED], + luo_current_state_str()); + ret =3D -EINVAL; + goto exit_unlock; + } + + ret =3D luo_fdt_setup(); + if (ret) + goto exit_unlock; + + ret =3D luo_do_prepare_calls(); + if (ret) { + luo_fdt_destroy(); + goto exit_unlock; + } + + luo_set_state(LIVEUPDATE_STATE_PREPARED); + +exit_unlock: + up_write(&luo_state_rwsem); + + return ret; +} + +static int __luo_cancel(void) +{ + if (down_write_killable(&luo_state_rwsem)) { + pr_warn("[cancel] event canceled by user\n"); + return -EAGAIN; + } + + if (!is_current_luo_state(LIVEUPDATE_STATE_PREPARED) && + !is_current_luo_state(LIVEUPDATE_STATE_FROZEN)) { + pr_warn("Can't switch to [%s] from [%s] state\n", + luo_state_str[LIVEUPDATE_STATE_NORMAL], + luo_current_state_str()); + up_write(&luo_state_rwsem); + + return -EINVAL; + } + + luo_do_cancel_calls(); + luo_fdt_destroy(); + luo_set_state(LIVEUPDATE_STATE_NORMAL); + + up_write(&luo_state_rwsem); + + return 0; +} + /* Get the current state as a string */ const char *luo_current_state_str(void) { @@ -111,9 +248,28 @@ enum liveupdate_state liveupdate_get_state(void) return READ_ONCE(luo_state); } =20 +/** + * luo_prepare - Initiate the live update preparation phase. + * + * This function is called to begin the live update process. It attempts to + * transition the luo to the ``LIVEUPDATE_STATE_PREPARED`` state. + * + * If the calls complete successfully, the orchestrator state is set + * to ``LIVEUPDATE_STATE_PREPARED``. If any call fails a + * ``LIVEUPDATE_CANCEL`` is sent to roll back any actions. + * + * @return 0 on success, ``-EAGAIN`` if the state change was cancelled by = the + * user while waiting for the lock, ``-EINVAL`` if the orchestrator is not= in + * the normal state, or a negative error code returned by the calls. + */ int luo_prepare(void) { - return 0; + int err =3D __luo_prepare(); + + if (err) + return err; + + return kho_finalize(); } =20 /** @@ -193,9 +349,28 @@ int luo_finish(void) return 0; } =20 +/** + * luo_cancel - Cancel the ongoing live update from prepared or frozen sta= tes. + * + * This function is called to abort a live update that is currently in the + * ``LIVEUPDATE_STATE_PREPARED`` state. + * + * If the state is correct, it triggers the ``LIVEUPDATE_CANCEL`` notifier= chain + * to allow subsystems to undo any actions performed during the prepare or + * freeze events. Finally, the orchestrator state is transitioned back to + * ``LIVEUPDATE_STATE_NORMAL``. + * + * @return 0 on success, or ``-EAGAIN`` if the state change was cancelled = by the + * user while waiting for the lock. + */ int luo_cancel(void) { - return 0; + int err =3D kho_abort(); + + if (err) + return err; + + return __luo_cancel(); } =20 void luo_state_read_enter(void) @@ -210,7 +385,40 @@ void luo_state_read_exit(void) =20 static int __init luo_startup(void) { - __luo_set_state(LIVEUPDATE_STATE_NORMAL); + phys_addr_t fdt_phys; + int ret; + + if (!kho_is_enabled()) { + if (luo_enabled) + pr_warn("Disabling liveupdate because KHO is disabled\n"); + luo_enabled =3D false; + return 0; + } + + /* + * Retrieve LUO subtree, and verify its format. Panic in case of + * exceptions, since machine devices and memory is in unpredictable + * state. + */ + ret =3D kho_retrieve_subtree(LUO_KHO_ENTRY_NAME, &fdt_phys); + if (ret) { + if (ret !=3D -ENOENT) { + panic("failed to retrieve FDT '%s' from KHO: %d\n", + LUO_KHO_ENTRY_NAME, ret); + } + __luo_set_state(LIVEUPDATE_STATE_NORMAL); + + return 0; + } + + luo_fdt_in =3D __va(fdt_phys); + ret =3D fdt_node_check_compatible(luo_fdt_in, 0, LUO_COMPATIBLE); + if (ret) { + panic("FDT '%s' is incompatible with '%s' [%d]\n", + LUO_KHO_ENTRY_NAME, LUO_COMPATIBLE, ret); + } + + __luo_set_state(LIVEUPDATE_STATE_UPDATED); =20 return 0; } --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (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 20EEC287242 for ; Wed, 25 Jun 2025 23:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893547; cv=none; b=f2IbmTu66yoJ6zAd2O5r59BmZJYEZGtU8YaPWbuz07JQ/vfrXFCO3HEGkCZFE1SlbBsycBl+LXqhvqVc0fdWdju8ddeF2hyYaYtVAkTDrzMxWIlbXafozDSiFUKf8YDBCTj7Fq9UEfRC7KLos2paSdy5F4fVE8RSen9BCOQzO58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893547; c=relaxed/simple; bh=LCBnkF05BFy67Dj3X9soES2dtoYMqCQz73KyCOTgCrI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YYima5FT5E76wtbT3Aee/8bcEQWmHTZek0/QgW8ZLXurQoi+63sZM+uEMVBbXMte43cBxZkEN7j6xgVk9/zKgZmd025wA9pj87srAz6RKRnjEA8EGeaoZg+DyIMZf/jsxyM3tcfAxfm88gphd5YgiPi2x7IGhJQpUXouBiygQJ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=FGgIHfX1; arc=none smtp.client-ip=209.85.219.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="FGgIHfX1" Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e8601ce24c9so272677276.1 for ; Wed, 25 Jun 2025 16:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893544; x=1751498344; 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=PZSlqdnTxC2Wjx/Crjm0HF+UsFjTh+cAEzYLoPE8XGM=; b=FGgIHfX1tvADYaLlL4oQlXAWnNyVc7s3CaHLUODjsp1KllhH9piGXd79r5ZEzQPDBv wwmHz5/uuI43VFDjhdjeE/edJI8KkQ619nUA328FDzA9xnY48wq1T2GXN8LtTfqueJwr doPy3TMesDzsvKcPfIQxQYKpYL3Aq8qXJCrMHY48PTeStM3l8VV5FUtn6Pvgmw99L+pO uGIfoFuQWW/l6ljk0d623KCbU/97udHY9sQp2YyirctaNZFNRcHUtM8kNKjGa3cJHQ9d hcDbIWGvJBfwQTzhgdZC2ki94oc1Jt5NV1HNkLl9ipnrAdFOViAWB+e2XJr7d6ymTBi9 Z8WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893544; x=1751498344; 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=PZSlqdnTxC2Wjx/Crjm0HF+UsFjTh+cAEzYLoPE8XGM=; b=GF89QGMn/cpz5W4NnXy6o1KuPjhnyyYXWIuVZWM8szNsTuS+/7Ld6qLuEW4ZSkwPsP IY3j//MptD2oKzgaay6UvQYGq6gNNzehx5CQY3v9PK2pUHC7wkwvkIUbb2W4hBvPaONQ rENH6syXpwfAnLWgfc778xnR5AARnxHyr/MaaXxnFc98JHJsOzWp8T5m/h//4MHbQCd+ tDB7oSYY9OC2iychBkBUICpTBGzlf0lygcNQySADZT50G1fCS9fX279q1suqrTMeRSfB 9k8LLDlvMv1UKeGg2VVNEdtTSr+EBSicaFnWzbRJz9rgXnDVmp6wg5GcLhWzslAMKSmo oMmg== X-Forwarded-Encrypted: i=1; AJvYcCUyghMRb6od7SxfxeV8CBg/Qp3Tm7Y7cxEaoSSLvUIAAJV2MFQ6GsfMR4RyTcWFZj2xQyTutTWVLeq+t40=@vger.kernel.org X-Gm-Message-State: AOJu0Yzr2tT9ltVKon/1wL445zZ66ypCH8n6QayyVZubAamlFzTNIkDi ktBUltu1X9R7QhV+xB95fgbmQg0XKDM39Wi4RFP7ptLi9aaTRjsLhuJBcxjHc36lurM= X-Gm-Gg: ASbGnctK3SQ4qch9Jc/LKdZdEW8hLz/sASRoyXy2vsOLuHSnqpTOJvqcVgY2sgIRFkM xlnSButlU69ZA7itq2u6g0mGbAYGpODx9MmD0lDmHH6yEVMNqh0EVfljWNVA0RX2/41JNY3ItH0 dpnSiUPom/10xp/7ecj9rTWPI2ArzF7i+wfiEY4bn8ylJXb0t9fL2GW5P4l4yS2jAm5iomBSdcg 5J7K5Mg3NxzI2n4Sp91Sl9cZMrmYIB+/yTUiAQw+bkcm0Np6JOlEfyHe7Qem9DAxfvWTeD57tOw 7SyUmJQmCUBpK3uZpw/04V32mo3O27KmEHynbpKA2sDJ/aljw5Le7QFimdfhotpTJCv4wcht8YD DvW+LmdXlf15F42RtZNhbvusLI9CfKK8CinkdvBx9dMMXF76coHjU X-Google-Smtp-Source: AGHT+IFUBGWR2vgXdeu6WMqjmysPRfKH2b0g+Y1BY72xIGjHQryfk9+9u7i490nYs2DPXKqM9VEAwA== X-Received: by 2002:a05:690c:6ac4:b0:70e:7663:8bb4 with SMTP id 00721157ae682-71406e064cbmr72906017b3.25.1750893543841; Wed, 25 Jun 2025 16:19:03 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:03 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 12/32] liveupdate: luo_subsystems: add subsystem registration Date: Wed, 25 Jun 2025 23:17:59 +0000 Message-ID: <20250625231838.1897085-13-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Introduce the framework for kernel subsystems (e.g., KVM, IOMMU, device drivers) to register with LUO and participate in the live update process via callbacks. Subsystem Registration: - Defines struct liveupdate_subsystem in linux/liveupdate.h, which subsystems use to provide their name and optional callbacks (prepare, freeze, cancel, finish). The callbacks accept a u64 *data intended for passing state/handles. - Exports liveupdate_register_subsystem() and liveupdate_unregister_subsystem() API functions. - Adds drivers/misc/liveupdate/luo_subsystems.c to manage a list of registered subsystems. Registration/unregistration is restricted to specific LUO states (NORMAL/UPDATED). Callback Framework: - The main luo_core.c state transition functions now delegate to new luo_do_subsystems_*_calls() functions defined in luo_subsystems.c. - These new functions are intended to iterate through the registered subsystems and invoke their corresponding callbacks. FDT Integration: - Adds a /subsystems subnode within the main LUO FDT created in luo_core.c. This node has its own compatibility string (subsystems-v1). - luo_subsystems_fdt_setup() populates this node by adding a property for each registered subsystem, using the subsystem's name. Currently, these properties are initialized with a placeholder u64 value (0). - luo_subsystems_startup() is called from luo_core.c on boot to find and validate the /subsystems node in the FDT received via KHO. It panics if the node is missing or incompatible. - Adds a stub API function liveupdate_get_subsystem_data() intended for subsystems to retrieve their persisted u64 data from the FDT in the new kernel. Signed-off-by: Pasha Tatashin --- include/linux/liveupdate.h | 61 +++++++ kernel/liveupdate/Makefile | 1 + kernel/liveupdate/luo_core.c | 19 +- kernel/liveupdate/luo_internal.h | 7 + kernel/liveupdate/luo_subsystems.c | 284 +++++++++++++++++++++++++++++ 5 files changed, 370 insertions(+), 2 deletions(-) create mode 100644 kernel/liveupdate/luo_subsystems.c diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index da8f05c81e51..fed68b9ab32b 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -88,6 +88,47 @@ enum liveupdate_state { LIVEUPDATE_STATE_UPDATED =3D 4, }; =20 +/** + * struct liveupdate_subsystem_ops - LUO events callback functions + * @prepare: Optional. Called during LUO prepare phase. Should perform + * preparatory actions and can store a u64 handle/state + * via the 'data' pointer for use in later callbacks. + * Return 0 on success, negative error code on failure. + * @freeze: Optional. Called during LUO freeze event (before actual = jump + * to new kernel). Should perform final state saving action= s and + * can update the u64 handle/state via the 'data' pointer. = Retur: + * 0 on success, negative error code on failure. + * @cancel: Optional. Called if the live update process is canceled = after + * prepare (or freeze) was called. Receives the u64 data + * set by prepare/freeze. Used for cleanup. + * @finish: Optional. Called after the live update is finished in th= e new + * kernel. + * Receives the u64 data set by prepare/freeze. Used for cl= eanup. + */ +struct liveupdate_subsystem_ops { + int (*prepare)(void *arg, u64 *data); + int (*freeze)(void *arg, u64 *data); + void (*cancel)(void *arg, u64 data); + void (*finish)(void *arg, u64 data); +}; + +/** + * struct liveupdate_subsystem - Represents a subsystem participating in L= UO + * @ops: Callback functions + * @name: Unique name identifying the subsystem. + * @arg: Add this argument to callback functions. + * @list: List head used internally by LUO. Should not be modified= by + * caller after registration. + * @private_data: For LUO internal use, cached value of data field. + */ +struct liveupdate_subsystem { + const struct liveupdate_subsystem_ops *ops; + const char *name; + void *arg; + struct list_head list; + u64 private_data; +}; + #ifdef CONFIG_LIVEUPDATE =20 /* Return true if live update orchestrator is enabled */ @@ -109,6 +150,10 @@ bool liveupdate_state_normal(void); =20 enum liveupdate_state liveupdate_get_state(void); =20 +int liveupdate_register_subsystem(struct liveupdate_subsystem *h); +int liveupdate_unregister_subsystem(struct liveupdate_subsystem *h); +int liveupdate_get_subsystem_data(struct liveupdate_subsystem *h, u64 *dat= a); + #else /* CONFIG_LIVEUPDATE */ =20 static inline int liveupdate_reboot(void) @@ -136,5 +181,21 @@ static inline enum liveupdate_state liveupdate_get_sta= te(void) return LIVEUPDATE_STATE_NORMAL; } =20 +static inline int liveupdate_register_subsystem(struct liveupdate_subsyste= m *h) +{ + return 0; +} + +static inline int liveupdate_unregister_subsystem(struct liveupdate_subsys= tem *h) +{ + return 0; +} + +static inline int liveupdate_get_subsystem_data(struct liveupdate_subsyste= m *h, + u64 *data) +{ + return -ENODATA; +} + #endif /* CONFIG_LIVEUPDATE */ #endif /* _LINUX_LIVEUPDATE_H */ diff --git a/kernel/liveupdate/Makefile b/kernel/liveupdate/Makefile index b3c72c405780..999208a1fdbb 100644 --- a/kernel/liveupdate/Makefile +++ b/kernel/liveupdate/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_KEXEC_HANDOVER) +=3D kexec_handover.o obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) +=3D kexec_handover_debug.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_core.o +obj-$(CONFIG_LIVEUPDATE) +=3D luo_subsystems.o diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index c80a1f188359..fff84c51d986 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -130,6 +130,10 @@ static int luo_fdt_setup(void) if (ret) goto exit_free; =20 + ret =3D luo_subsystems_fdt_setup(fdt_out); + if (ret) + goto exit_free; + ret =3D kho_preserve_phys(__pa(fdt_out), LUO_FDT_SIZE); if (ret) goto exit_free; @@ -160,20 +164,30 @@ static void luo_fdt_destroy(void) =20 static int luo_do_prepare_calls(void) { - return 0; + int ret; + + ret =3D luo_do_subsystems_prepare_calls(); + + return ret; } =20 static int luo_do_freeze_calls(void) { - return 0; + int ret; + + ret =3D luo_do_subsystems_freeze_calls(); + + return ret; } =20 static void luo_do_finish_calls(void) { + luo_do_subsystems_finish_calls(); } =20 static void luo_do_cancel_calls(void) { + luo_do_subsystems_cancel_calls(); } =20 static int __luo_prepare(void) @@ -419,6 +433,7 @@ static int __init luo_startup(void) } =20 __luo_set_state(LIVEUPDATE_STATE_UPDATED); + luo_subsystems_startup(luo_fdt_in); =20 return 0; } diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index 3d10f3eb20a7..98bf799adb61 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -18,4 +18,11 @@ void luo_state_read_exit(void); =20 const char *luo_current_state_str(void); =20 +void luo_subsystems_startup(void *fdt); +int luo_subsystems_fdt_setup(void *fdt); +int luo_do_subsystems_prepare_calls(void); +int luo_do_subsystems_freeze_calls(void); +void luo_do_subsystems_finish_calls(void); +void luo_do_subsystems_cancel_calls(void); + #endif /* _LINUX_LUO_INTERNAL_H */ diff --git a/kernel/liveupdate/luo_subsystems.c b/kernel/liveupdate/luo_sub= systems.c new file mode 100644 index 000000000000..436929a17de0 --- /dev/null +++ b/kernel/liveupdate/luo_subsystems.c @@ -0,0 +1,284 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: LUO Subsystems support + * + * Various kernel subsystems register with the Live Update Orchestrator to + * participate in the live update process. These subsystems are notified at + * different stages of the live update sequence, allowing them to serialize + * device state before the reboot and restore it afterwards. Examples incl= ude + * the device layer, interrupt controllers, KVM, IOMMU, and specific device + * drivers. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include "luo_internal.h" + +#define LUO_SUBSYSTEMS_NODE_NAME "subsystems" +#define LUO_SUBSYSTEMS_COMPATIBLE "subsystems-v1" + +static DEFINE_MUTEX(luo_subsystem_list_mutex); +static LIST_HEAD(luo_subsystems_list); +static void *luo_fdt_out; +static void *luo_fdt_in; + +/** + * luo_subsystems_fdt_setup - Adds and populates the 'subsystems' node in = the + * FDT. + * @fdt: Pointer to the LUO FDT blob. + * + * Add subsystems node and each subsystem to the LUO FDT blob. + * + * Returns: 0 on success, negative errno on failure. + */ +int luo_subsystems_fdt_setup(void *fdt) +{ + struct liveupdate_subsystem *subsystem; + const u64 zero_data =3D 0; + int ret, node_offset; + + ret =3D fdt_add_subnode(fdt, 0, LUO_SUBSYSTEMS_NODE_NAME); + if (ret < 0) + goto exit_error; + + node_offset =3D ret; + ret =3D fdt_setprop_string(fdt, node_offset, "compatible", + LUO_SUBSYSTEMS_COMPATIBLE); + if (ret < 0) + goto exit_error; + + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + ret =3D fdt_setprop(fdt, node_offset, subsystem->name, + &zero_data, sizeof(zero_data)); + if (ret < 0) + goto exit_error; + } + + luo_fdt_out =3D fdt; + return 0; +exit_error: + pr_err("Failed to setup 'subsystems' node to FDT: %s\n", + fdt_strerror(ret)); + return -ENOSPC; +} + +/** + * luo_subsystems_startup - Validates the LUO subsystems FDT node at start= up. + * @fdt: Pointer to the LUO FDT blob passed from the previous kernel. + * + * This __init function checks the existence and validity of the '/subsyst= ems' + * node in the FDT. This node is considered mandatory. It calls panic() if + * the node is missing, inaccessible, or invalid (e.g., missing compatible, + * wrong compatible string), indicating a critical configuration error for= LUO. + */ +void __init luo_subsystems_startup(void *fdt) +{ + int ret, node_offset; + + node_offset =3D fdt_subnode_offset(fdt, 0, LUO_SUBSYSTEMS_NODE_NAME); + if (node_offset < 0) + panic("Failed to find /subsystems node\n"); + + ret =3D fdt_node_check_compatible(fdt, node_offset, + LUO_SUBSYSTEMS_COMPATIBLE); + if (ret) { + panic("FDT '%s' is incompatible with '%s' [%d]\n", + LUO_SUBSYSTEMS_NODE_NAME, LUO_SUBSYSTEMS_COMPATIBLE, ret); + } + luo_fdt_in =3D fdt; +} + +/** + * luo_do_subsystems_prepare_calls - Calls prepare callbacks and updates F= DT + * if all prepares succeed. Handles cancellation on failure. + * + * Phase 1: Calls 'prepare' for all subsystems and stores results temporar= ily. + * If any 'prepare' fails, calls 'cancel' on previously prepared subsystems + * and returns the error. + * Phase 2: If all 'prepare' calls succeeded, writes the stored data to th= e FDT. + * If any FDT write fails, calls 'cancel' on *all* prepared subsystems and + * returns the FDT error. + * + * Returns: 0 on success. Negative errno on failure. + */ +int luo_do_subsystems_prepare_calls(void) +{ + return 0; +} + +/** + * luo_do_subsystems_freeze_calls - Calls freeze callbacks and updates FDT + * if all freezes succeed. Handles cancellation on failure. + * + * Phase 1: Calls 'freeze' for all subsystems and stores results temporari= ly. + * If any 'freeze' fails, calls 'cancel' on previously called subsystems + * and returns the error. + * Phase 2: If all 'freeze' calls succeeded, writes the stored data to the= FDT. + * If any FDT write fails, calls 'cancel' on *all* subsystems and + * returns the FDT error. + * + * Returns: 0 on success. Negative errno on failure. + */ +int luo_do_subsystems_freeze_calls(void) +{ + return 0; +} + +/** + * luo_do_subsystems_finish_calls- Calls finish callbacks for all subsyste= ms. + * + * This function is called at the end of live update cycle to do the final + * clean-up or housekeeping of the post-live update states. + */ +void luo_do_subsystems_finish_calls(void) +{ +} + +/** + * luo_do_subsystems_cancel_calls - Calls cancel callbacks for all subsyst= ems. + * + * This function is typically called when the live update process needs to= be + * aborted externally, for example, after the prepare phase may have run b= ut + * before actual reboot. It iterates through all registered subsystems and= calls + * the 'cancel' callback for those that implement it and likely completed + * prepare. + */ +void luo_do_subsystems_cancel_calls(void) +{ +} + +/** + * liveupdate_register_subsystem - Register a kernel subsystem handler wit= h LUO + * @h: Pointer to the liveupdate_subsystem structure allocated and populat= ed + * by the calling subsystem. + * + * Registers a subsystem handler that provides callbacks for different eve= nts + * of the live update cycle. Registration is typically done during the + * subsystem's module init or core initialization. + * + * Can only be called when LUO is in the NORMAL or UPDATED states. + * The provided name (@h->name) must be unique among registered subsystems. + * + * Return: 0 on success, negative error code otherwise. + */ +int liveupdate_register_subsystem(struct liveupdate_subsystem *h) +{ + struct liveupdate_subsystem *iter; + int ret =3D 0; + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + luo_state_read_exit(); + return -EBUSY; + } + + mutex_lock(&luo_subsystem_list_mutex); + list_for_each_entry(iter, &luo_subsystems_list, list) { + if (iter =3D=3D h) { + pr_warn("Subsystem '%s' (%p) already registered.\n", + h->name, h); + ret =3D -EEXIST; + goto out_unlock; + } + + if (!strcmp(iter->name, h->name)) { + pr_err("Subsystem with name '%s' already registered.\n", + h->name); + ret =3D -EEXIST; + goto out_unlock; + } + } + + INIT_LIST_HEAD(&h->list); + list_add_tail(&h->list, &luo_subsystems_list); + +out_unlock: + mutex_unlock(&luo_subsystem_list_mutex); + luo_state_read_exit(); + + return ret; +} +EXPORT_SYMBOL_GPL(liveupdate_register_subsystem); + +/** + * liveupdate_unregister_subsystem - Unregister a kernel subsystem handler= from + * LUO + * @h: Pointer to the same liveupdate_subsystem structure that was used du= ring + * registration. + * + * Unregisters a previously registered subsystem handler. Typically called + * during module exit or subsystem teardown. LUO removes the structure fro= m its + * internal list; the caller is responsible for any necessary memory clean= up + * of the structure itself. + * + * Return: 0 on success, negative error code otherwise. + * -EINVAL if h is NULL. + * -ENOENT if the specified handler @h is not found in the registration li= st. + * -EBUSY if LUO is not in the NORMAL state. + */ +int liveupdate_unregister_subsystem(struct liveupdate_subsystem *h) +{ + struct liveupdate_subsystem *iter; + bool found =3D false; + int ret =3D 0; + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + luo_state_read_exit(); + return -EBUSY; + } + + mutex_lock(&luo_subsystem_list_mutex); + list_for_each_entry(iter, &luo_subsystems_list, list) { + if (iter =3D=3D h) { + found =3D true; + break; + } + } + + if (found) { + list_del_init(&h->list); + } else { + pr_warn("Subsystem handler '%s' not found for unregistration.\n", + h->name); + ret =3D -ENOENT; + } + + mutex_unlock(&luo_subsystem_list_mutex); + luo_state_read_exit(); + + return ret; +} +EXPORT_SYMBOL_GPL(liveupdate_unregister_subsystem); + +/** + * liveupdate_get_subsystem_data - Retrieve raw private data for a subsyst= em + * from FDT. + * @h: Pointer to the liveupdate_subsystem structure representing the + * subsystem instance. The 'name' field is used to find the property. + * @data: Output pointer where the subsystem's raw private u64 data will= be + * stored via memcpy. + * + * Reads the 8-byte data property associated with the subsystem @h->name + * directly from the '/subsystems' node within the globally accessible + * 'luo_fdt_in' blob. Returns appropriate error codes if inputs are invali= d, or + * nodes/properties are missing or invalid. + * + * Return: 0 on success. -ENOENT on error. + */ +int liveupdate_get_subsystem_data(struct liveupdate_subsystem *h, u64 *dat= a) +{ + return 0; +} +EXPORT_SYMBOL_GPL(liveupdate_get_subsystem_data); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (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 9582828726C for ; Wed, 25 Jun 2025 23:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893549; cv=none; b=BO6Hsl4R6wf6vBV3ADVGsRXZpS5htzCnPXiDwxTs2hADxghL9zfNUg5WcB+gISuup0T4wZ0/B8oLwNQ1wjRwa7KX+SH451dnDxaBzy2gIhwIyQ9nfFV09BzQK2MZngahO0OhccstGXEvZClbKCnLep26dcdeJEOYLLJck7dBRss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893549; c=relaxed/simple; bh=h1L0cbeVfJxO9kghsvJ6bWhgk+o6POMPbs4sljzTVS0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NqtBSXf8M+WRjpF/1+7mlrpLgXvlwGHwb6cYd2mSJaZdiRTCr1YAhm2p+woVWQCG9sxp40LN51VdLu9UwdLGP7xFN7k8j1p65DgPnT7Uz32LJYzdfJawgX4WWYucDY1TUgarRbuNAY3FAYHejjqeaUSwwkcY7NAo/MRbv707brI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=dPrxG20h; arc=none smtp.client-ip=209.85.219.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="dPrxG20h" Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-e7387d4a336so312713276.2 for ; Wed, 25 Jun 2025 16:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893545; x=1751498345; 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=5UX19BNUcwB6TjSqCz6om7S5yVRpVe4SwKywfTR0ocE=; b=dPrxG20hSsMW/B3OVCiaYwjuLVCscBPrvr1/Z0Gpy59Qirdl7dwvNP8SRiOisXkCRB wdbNM2w0Pe0/8XkVHDQXEYhz3W3JaD7vSQn0diOpRBa+Hi3nMwkgX/JSk/jjaZmqd+of 2fEHz0KHUs6VOyMhJZkS3Fr4em+z0fLHagpINbXLA1VXw5JgdEh+I15S2ZzGsvtea8PN eQGzWjc09gvnvyOC1zrHdCo+T5o0b+JwUuojDdZVFW35Ew44YUaPjJGzCdoX28Nra9Zm sm+qxQ3al2dxjjGPwVVwaanpyuwtbUDD/I3Ex1NU7w2o3r14F2fQuCxQzr7QqRkHvPip +6rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893545; x=1751498345; 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=5UX19BNUcwB6TjSqCz6om7S5yVRpVe4SwKywfTR0ocE=; b=Zg4hoMCAwHVUoRYVMdg8j1xz1uAvnFOkno2ZJomSlLDx46E9eLr5FNGfc3KOSj1LC4 3jfNcFMTTXs5MervLP4TeYFyXLjCyzeO1otYJHHndf3TIwgTDpYFiGv02TmK6ecRDVLp 2Qih9jb0N4lmsW6W4Eb14+3h8mJ97X1EvknnPW5WVVu9o5axU/5LcJbNbDySzg21619a 5gSfRByi1/OKQD4Xhicu6nCxQaqQPgHpqOwzbghJvBBCfMjmayDNOYPfoSmF1XV0mbrb lFuFhv974U3Jad2a0xuhsASCQ9Kf35KvnfM5z0VgoAiRmQIMqRFMqmgBL+/E2PaXJdXP r6Hg== X-Forwarded-Encrypted: i=1; AJvYcCV/mU+KNKhEpuiHDuYR2/8Dxmkdk6WrUIfNNAjr8XIkGHFYY91yB5baR9pGGaO6TzhGffa1Ow1il2ZJ44c=@vger.kernel.org X-Gm-Message-State: AOJu0YxlE1cBHsfH5v6m0IP3/LXwVK74AdOtyT1BYXRCflqSrIyE9i5t IVCryTKIqFPsfc+wSpK8K7178So6lxE9fvKfD0A/lt8ntyW85HJpuolwS5KlONyKIVg= X-Gm-Gg: ASbGncvXmuiF8r7HSxgpMkrWM5U3KFznfnDpkOGtqnWhSMmFpxP0/7B1zwUewxoyo1B F1d4C6U+3fqWuQmnsblcXmcXNQcYgnyn/s1QeE0v//lqHV7Ea1Q1V6FuJU5cNzK8FiKQmIHsxqp uyHM1Oby3vircwpIsAH8QNfhPBOWKGZ2Uqeo1tJvyr542nR9iMrCX/iE+wu0fjaPeduvUsVgnj9 NuIep0b7kCRn4uWFzxXtjd7n5cxvXB5VP+Ba0adVBNfOHhtVIJn42744T8xGvDXnSxc/ZioZQhF pv0lKBAjlzILuqnjcfRSwCgjrTZgrPRI5VjKLg9TvwEqXdJzDlZ8bXRS8/tc3DOE7c6dxEqx0xJ Fqt6PIT/rC2fQ2kM8QwVFMRa69oNkwctr0jtLXd2eVJRLx7afAGC6zZLHYWAPxZA= X-Google-Smtp-Source: AGHT+IEUALELAR5NZDDDyivweXKXSv+YUONyeoj1fruSJbIWZ6q9777GsWvO1Or7ZMh1+hi6yBvkfg== X-Received: by 2002:a05:6902:4790:b0:e81:9da8:522d with SMTP id 3f1490d57ef6-e8601765df4mr6268713276.23.1750893545592; Wed, 25 Jun 2025 16:19:05 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:05 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 13/32] liveupdate: luo_subsystems: implement subsystem callbacks Date: Wed, 25 Jun 2025 23:18:00 +0000 Message-ID: <20250625231838.1897085-14-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Implement the core logic within luo_subsystems.c to handle the invocation of registered subsystem callbacks and manage the persistence of their state via the LUO FDT. This replaces the stub implementations from the previous patch. This completes the core mechanism enabling subsystems to actively participate in the LUO state machine, execute phase-specific logic, and persist/restore a u64 state across the live update transition using the FDT. Signed-off-by: Pasha Tatashin --- kernel/liveupdate/luo_subsystems.c | 140 ++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 2 deletions(-) diff --git a/kernel/liveupdate/luo_subsystems.c b/kernel/liveupdate/luo_sub= systems.c index 436929a17de0..0e0070d01584 100644 --- a/kernel/liveupdate/luo_subsystems.c +++ b/kernel/liveupdate/luo_subsystems.c @@ -99,6 +99,66 @@ void __init luo_subsystems_startup(void *fdt) luo_fdt_in =3D fdt; } =20 +static void __luo_do_subsystems_cancel_calls(struct liveupdate_subsystem *= boundary_subsystem) +{ + struct liveupdate_subsystem *subsystem; + + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + if (subsystem =3D=3D boundary_subsystem) + break; + + if (subsystem->ops->cancel) { + subsystem->ops->cancel(subsystem->arg, + subsystem->private_data); + } + subsystem->private_data =3D 0; + } +} + +static void luo_subsystems_retrieve_data_from_fdt(void) +{ + struct liveupdate_subsystem *subsystem; + int node_offset, prop_len; + const void *prop; + + if (!luo_fdt_in) + return; + + node_offset =3D fdt_subnode_offset(luo_fdt_in, 0, + LUO_SUBSYSTEMS_NODE_NAME); + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + prop =3D fdt_getprop(luo_fdt_in, node_offset, + subsystem->name, &prop_len); + + if (!prop || prop_len !=3D sizeof(u64)) { + panic("In FDT node '/%s' can't find property '%s': %s\n", + LUO_SUBSYSTEMS_NODE_NAME, subsystem->name, + fdt_strerror(node_offset)); + } + memcpy(&subsystem->private_data, prop, sizeof(u64)); + } +} + +static int luo_subsystems_commit_data_to_fdt(void) +{ + struct liveupdate_subsystem *subsystem; + int ret, node_offset; + + node_offset =3D fdt_subnode_offset(luo_fdt_out, 0, + LUO_SUBSYSTEMS_NODE_NAME); + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + ret =3D fdt_setprop(luo_fdt_out, node_offset, subsystem->name, + &subsystem->private_data, sizeof(u64)); + if (ret < 0) { + pr_err("Failed to set FDT property for subsystem '%s' %s\n", + subsystem->name, fdt_strerror(ret)); + return -ENOENT; + } + } + + return 0; +} + /** * luo_do_subsystems_prepare_calls - Calls prepare callbacks and updates F= DT * if all prepares succeed. Handles cancellation on failure. @@ -114,7 +174,29 @@ void __init luo_subsystems_startup(void *fdt) */ int luo_do_subsystems_prepare_calls(void) { - return 0; + struct liveupdate_subsystem *subsystem; + int ret; + + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + if (!subsystem->ops->prepare) + continue; + + ret =3D subsystem->ops->prepare(subsystem->arg, + &subsystem->private_data); + if (ret < 0) { + pr_err("Subsystem '%s' prepare callback failed [%d]\n", + subsystem->name, ret); + __luo_do_subsystems_cancel_calls(subsystem); + + return ret; + } + } + + ret =3D luo_subsystems_commit_data_to_fdt(); + if (ret) + __luo_do_subsystems_cancel_calls(NULL); + + return ret; } =20 /** @@ -132,7 +214,29 @@ int luo_do_subsystems_prepare_calls(void) */ int luo_do_subsystems_freeze_calls(void) { - return 0; + struct liveupdate_subsystem *subsystem; + int ret; + + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + if (!subsystem->ops->freeze) + continue; + + ret =3D subsystem->ops->freeze(subsystem->arg, + &subsystem->private_data); + if (ret < 0) { + pr_err("Subsystem '%s' freeze callback failed [%d]\n", + subsystem->name, ret); + __luo_do_subsystems_cancel_calls(subsystem); + + return ret; + } + } + + ret =3D luo_subsystems_commit_data_to_fdt(); + if (ret) + __luo_do_subsystems_cancel_calls(NULL); + + return ret; } =20 /** @@ -143,6 +247,17 @@ int luo_do_subsystems_freeze_calls(void) */ void luo_do_subsystems_finish_calls(void) { + struct liveupdate_subsystem *subsystem; + + luo_subsystems_retrieve_data_from_fdt(); + + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + if (subsystem->ops->finish) { + subsystem->ops->finish(subsystem->arg, + subsystem->private_data); + } + subsystem->private_data =3D 0; + } } =20 /** @@ -156,6 +271,8 @@ void luo_do_subsystems_finish_calls(void) */ void luo_do_subsystems_cancel_calls(void) { + __luo_do_subsystems_cancel_calls(NULL); + luo_subsystems_commit_data_to_fdt(); } =20 /** @@ -279,6 +396,25 @@ EXPORT_SYMBOL_GPL(liveupdate_unregister_subsystem); */ int liveupdate_get_subsystem_data(struct liveupdate_subsystem *h, u64 *dat= a) { + int node_offset, prop_len; + const void *prop; + + luo_state_read_enter(); + if (WARN_ON_ONCE(!luo_fdt_in || !liveupdate_state_updated())) { + luo_state_read_exit(); + return -ENOENT; + } + + node_offset =3D fdt_subnode_offset(luo_fdt_in, 0, + LUO_SUBSYSTEMS_NODE_NAME); + prop =3D fdt_getprop(luo_fdt_in, node_offset, h->name, &prop_len); + if (!prop || prop_len !=3D sizeof(u64)) { + luo_state_read_exit(); + return -ENOENT; + } + memcpy(data, prop, sizeof(u64)); + luo_state_read_exit(); + return 0; } EXPORT_SYMBOL_GPL(liveupdate_get_subsystem_data); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) (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 7984228727E for ; Wed, 25 Jun 2025 23:19:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893551; cv=none; b=Ednq0GIZzqkZ6C2HvKf+Nd8piazNnwuOJwQm+zChwU6G08nAXTexTkMaiA7lDsluEstYv8iF1u066h1f1/tS3siMbOxQPZhaof1RiOTEXZp+8qoiFe+Al1oYqnznDsL+31MzbhNI30YJNWZKkFLMVfYNCHiq3PZZax4s2BO/fyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893551; c=relaxed/simple; bh=JEBv7ujCg/6ppGBPUrQkC9q5/Jniw7vqQmsSqDtLHdM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WjKcEMSEgzXza/2j9IujZOgq1X+edGQ0cXEOKPwkDWdTXFqEur5uU7o6a4/ka9JxcUYcBuZk0Ou0R5yxqZnZ3ecdfj5RDm4bKjUsMTdYEAlmnCq78aPAYZKsMirjR8Q5tXo8UEFac6v+0YlD8ewENx7jk5X43hXoYjCiQ0VQyJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=sP89KzmU; arc=none smtp.client-ip=209.85.219.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="sP89KzmU" Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-e733e25bfc7so315204276.3 for ; Wed, 25 Jun 2025 16:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893547; x=1751498347; 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=LimjlICD6sUHgsbY/Y2oVH6YvmC/VDcU5uGtC2pfHEg=; b=sP89KzmUJSP1w6eLr5RmWbXJDy1y3q5merdtcRli4gFLkCd+/BRAdG6cU/Ag+Ku0ZN 0aIKSWJoLrAOpjzymcwQemEAIpyAgOHvtoqPQJBoa5yTEtngD9Fwm1dMYIsocr32mkMQ 4IyksvUfFFzQTSuyR4e2zoEN+C6r1uqzJ6+fEHE4VT5bZ16zwn3E1XAJBOJBPEviYoKD 9LOW/CallSgXTagNapQTnrLwOCq3GFtkQzpCYCOqI9cvUInmCm2XiszPqtdozQ3Rp4Np IQI49MrNbBLLKBDZ6CH2VHIyN7GuK8q/ua87SVkbke+gVmX3MWL3DKNeeMO266wKfkgJ qTsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893547; x=1751498347; 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=LimjlICD6sUHgsbY/Y2oVH6YvmC/VDcU5uGtC2pfHEg=; b=wGUFBtMiZJJ7Dqtvzrd7vIvpFgWEUC3wtIGBreqSJFNLRzk163KO21zag4E2PAeXqj 8ewXTYPnot3OE11EMyz+gXHIgeOuwyzZ/KYzBe16xKxUr2U7azfNgis5+7Q8+ZV3HloP ll6VXWIyq3Cae9T/gBvgZYUzDN40D5YjPgExBIG2AU9ZQiWxLlMGndYSKKWB1sLxDjaO nwLVu+nbQDR2Kv3KGw1R0DdTukPpQ7qIOzangs50gEDp15ync482+UBvPUqGGY4AXeRc iXDRQfoja/vxmYJwAS1tOX5TTOpkzGj5pAtfE62T4BbS/K31H9ET8LNQ+22WzcillFqd tqBQ== X-Forwarded-Encrypted: i=1; AJvYcCW4uLKMho4RiN3Z4BLBk8mrqOWP6Rhi5W3GzlmfUnn4Za+G18P5T3/BleaUAzkLF26uVXVpKQcHd6dZoxs=@vger.kernel.org X-Gm-Message-State: AOJu0YxnF9ONNSH5PGLkEF5QHqkeCwSI6pomLyDjGhBicX/ZnyhmQiwx VlUaLR6fDL+h5w4k8tI352lFdn4R0XcfzgZ4mSIkmRNWZbhuaxcsFiH1i017+iiScwo= X-Gm-Gg: ASbGncuFWwhn/m3aTFvdVQiwOIlsIoEzE8U+V5175M+ReH42gna3L3NrnUqAfrDAsiR Wr10+foGrIMEllc0CpcLFJVUK3oeEUIP0RE2uco753pNB3x97MrIH80fzCReaxUUFxU4uPEcHOK GuP/4KwvZRtjL6lx8Bht+nsJuAUj2VlSUsZLYehutNOds9HY1nWUT4dawqRqz6EqcOK2PU39tei dmmdRAt6A6i4EoBUNtzG7TcUpY2AliyhhK7bMwG6ybFe1JyDdJHnQBqW4pzCGJDCvTTnwaCTg0X UYxAx/FcqWJsrpxNH5SpAS4RAUn0J2LT0YedoEYS348+V/uDardb1PHLwq0H4GJK6SyKvcRsO2d bqGl/ZXJ9uWnZVSbttSeTO9KkxHoOINtJJZZ5cSbjnAdnWj8ImqaDpJuKykw6IyE= X-Google-Smtp-Source: AGHT+IGu2WAR4FR4EPR+F7ziPNzvRl1Fc8v7SjdbR09dC5+Z93Z5wRlVgHdrsEbJjK/h3jUtwcIiXw== X-Received: by 2002:a05:6902:138d:b0:e84:13c9:67d7 with SMTP id 3f1490d57ef6-e860171d6d3mr5935837276.20.1750893547311; Wed, 25 Jun 2025 16:19:07 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:06 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 14/32] liveupdate: luo_files: add infrastructure for FDs Date: Wed, 25 Jun 2025 23:18:01 +0000 Message-ID: <20250625231838.1897085-15-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Introduce the framework within LUO to support preserving specific types of file descriptors across a live update transition. This allows stateful FDs (like memfds or vfio FDs used by VMs) to be recreated in the new kernel. Note: The core logic for iterating through the luo_files_list and invoking the handler callbacks (prepare, freeze, cancel, finish) within luo_do_files_*_calls, as well as managing the u64 data persistence via the FDT for individual files, is currently implemented as stubs in this patch. This patch sets up the registration, FDT layout, and retrieval framework. Signed-off-by: Pasha Tatashin --- include/linux/liveupdate.h | 68 ++++ kernel/liveupdate/Makefile | 1 + kernel/liveupdate/luo_files.c | 663 +++++++++++++++++++++++++++++++ kernel/liveupdate/luo_internal.h | 4 + 4 files changed, 736 insertions(+) create mode 100644 kernel/liveupdate/luo_files.c diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index fed68b9ab32b..28a8aa4cafca 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -88,6 +88,61 @@ enum liveupdate_state { LIVEUPDATE_STATE_UPDATED =3D 4, }; =20 +struct file; + +/** + * struct liveupdate_file_ops - Callbacks for for live-updatable files. + * @prepare: Optional. Saves state for a specific file instance (@fi= le, + * @arg) before update, potentially returning value via @d= ata. + * Returns 0 on success, negative errno on failure. + * @freeze: Optional. Performs final actions just before kernel + * transition, potentially reading/updating the handle via + * @data. + * Returns 0 on success, negative errno on failure. + * @cancel: Optional. Cleans up state/resources if update is aborted + * after prepare/freeze succeeded, using the @data handle = (by + * value) from the successful prepare. Returns void. + * @finish: Optional. Performs final cleanup in the new kernel usin= g the + * preserved @data handle (by value). Returns void. + * @retrieve: Retrieve the preserved file. Must be called before fini= sh. + * @can_preserve: callback to determine if @file with associated context = (@arg) + * can be preserved by this handler. + * Return bool (true if preservable, false otherwise). + */ +struct liveupdate_file_ops { + int (*prepare)(struct file *file, void *arg, u64 *data); + int (*freeze)(struct file *file, void *arg, u64 *data); + void (*cancel)(struct file *file, void *arg, u64 data); + void (*finish)(struct file *file, void *arg, u64 data, bool reclaimed); + int (*retrieve)(void *arg, u64 data, struct file **file); + bool (*can_preserve)(struct file *file, void *arg); +}; + +/** + * struct liveupdate_file_handler - Represents a handler for a live-updata= ble + * file type. + * @ops: Callback functions + * @compatible: The compatibility string (e.g., "memfd-v1", "vfiofd-v1") + * that uniquely identifies the file type this handler sup= ports. + * This is matched against the compatible string associate= d with + * individual &struct liveupdate_file instances. + * @arg: An opaque pointer to implementation-specific context da= ta + * associated with this file handler registration. + * @list: used for linking this handler instance into a global li= st of + * registered file handlers. + * + * Modules that want to support live update for specific file types should + * register an instance of this structure. LUO uses this registration to + * determine if a given file can be preserved and to find the appropriate + * operations to manage its state across the update. + */ +struct liveupdate_file_handler { + const struct liveupdate_file_ops *ops; + const char *compatible; + void *arg; + struct list_head list; +}; + /** * struct liveupdate_subsystem_ops - LUO events callback functions * @prepare: Optional. Called during LUO prepare phase. Should perform @@ -154,6 +209,9 @@ int liveupdate_register_subsystem(struct liveupdate_sub= system *h); int liveupdate_unregister_subsystem(struct liveupdate_subsystem *h); int liveupdate_get_subsystem_data(struct liveupdate_subsystem *h, u64 *dat= a); =20 +int liveupdate_register_file_handler(struct liveupdate_file_handler *h); +int liveupdate_unregister_file_handler(struct liveupdate_file_handler *h); + #else /* CONFIG_LIVEUPDATE */ =20 static inline int liveupdate_reboot(void) @@ -197,5 +255,15 @@ static inline int liveupdate_get_subsystem_data(struct= liveupdate_subsystem *h, return -ENODATA; } =20 +static inline int liveupdate_register_file_handler(struct liveupdate_file_= handler *h) +{ + return 0; +} + +static inline int liveupdate_unregister_file_handler(struct liveupdate_fil= e_handler *h) +{ + return 0; +} + #endif /* CONFIG_LIVEUPDATE */ #endif /* _LINUX_LIVEUPDATE_H */ diff --git a/kernel/liveupdate/Makefile b/kernel/liveupdate/Makefile index 999208a1fdbb..b5054140b9a9 100644 --- a/kernel/liveupdate/Makefile +++ b/kernel/liveupdate/Makefile @@ -6,4 +6,5 @@ obj-$(CONFIG_KEXEC_HANDOVER) +=3D kexec_handover.o obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) +=3D kexec_handover_debug.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_core.o +obj-$(CONFIG_LIVEUPDATE) +=3D luo_files.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_subsystems.o diff --git a/kernel/liveupdate/luo_files.c b/kernel/liveupdate/luo_files.c new file mode 100644 index 000000000000..3582f1ec96c4 --- /dev/null +++ b/kernel/liveupdate/luo_files.c @@ -0,0 +1,663 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: LUO file descriptors + * + * LUO provides the infrastructure necessary to preserve + * specific types of stateful file descriptors across a kernel live + * update transition. The primary goal is to allow workloads, such as virt= ual + * machines using vfio, memfd, or iommufd to retain access to their essent= ial + * resources without interruption after the underlying kernel is updated. + * + * The framework operates based on handler registration and instance track= ing: + * + * 1. Handler Registration: Kernel modules responsible for specific file + * types (e.g., memfd, vfio) register a &struct liveupdate_file_handler + * handler. This handler contains callbacks + * (&liveupdate_file_handler.ops->prepare, + * &liveupdate_file_handler.ops->freeze, + * &liveupdate_file_handler.ops->finish, etc.) and a unique 'compatible' s= tring + * identifying the file type. Registration occurs via + * liveupdate_register_file_handler(). + * + * 2. File Instance Tracking: When a potentially preservable file needs to= be + * managed for live update, the core LUO logic (luo_register_file()) finds= a + * compatible registered handler using its + * &liveupdate_file_handler.ops->can_preserve callback. If found, an inte= rnal + * &struct luo_file instance is created, assigned a unique u64 'token', and + * added to a list. + * + * 3. State Persistence (FDT): During the LUO prepare/freeze phases, the + * registered handler callbacks are invoked for each tracked file instance. + * These callbacks can generate a u64 data payload representing the minimal + * state needed for restoration. This payload, along with the handler's + * compatible string and the unique token, is stored in a dedicated + * '/file-descriptors' node within the main LUO FDT blob passed via + * Kexec Handover (KHO). + * + * 4. Restoration: In the new kernel, the LUO framework parses the incoming + * FDT to reconstruct the list of &struct luo_file instances. When the + * original owner requests the file, luo_retrieve_file() uses the correspo= nding + * handler's &liveupdate_file_handler.ops->retrieve callback, passing the + * persisted u64 data, to recreate or find the appropriate &struct file ob= ject. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "luo_internal.h" + +#define LUO_FILES_NODE_NAME "file-descriptors" +#define LUO_FILES_COMPATIBLE "file-descriptors-v1" + +static DEFINE_XARRAY(luo_files_xa_in); +static DEFINE_XARRAY(luo_files_xa_out); +static bool luo_files_xa_in_recreated; + +/* Registered files. */ +static DECLARE_RWSEM(luo_register_file_list_rwsem); +static LIST_HEAD(luo_register_file_list); + +static void *luo_file_fdt_out; +static void *luo_file_fdt_in; + +static size_t luo_file_fdt_out_size; + +static atomic64_t luo_files_count; + +/** + * struct luo_file - Represents a file descriptor instance preserved + * across live update. + * @fh: Pointer to the &struct liveupdate_file_handler containi= ng + * the implementation of prepare, freeze, cancel, and fini= sh + * operations specific to this file's type. + * @file: A pointer to the kernel's &struct file object represent= ing + * the open file descriptor that is being preserved. + * @private_data: Internal storage used by the live update core framework + * between phases. + * @reclaimed: Flag indicating whether this preserved file descriptor = has + * been successfully 'reclaimed' (e.g., requested via an i= octl) + * by user-space or the owning kernel subsystem in the new + * kernel after the live update. + * @state: The current state of file descriptor, it is allowed to + * prepare, freeze, and finish FDs before the global state + * switch. + * @mutex: Lock to protect FD state, and allow independently to c= hange + * the FD state compared to global state. + * + * This structure holds the necessary callbacks and context for managing a + * specific open file descriptor throughout the different phases of a live + * update process. Instances of this structure are typically allocated, + * populated with file-specific details (&file, &arg, callbacks, compatibi= lity + * string, token), and linked into a central list managed by the LUO. The + * private_data field is used internally by the core logic to store state + * between phases. + */ +struct luo_file { + struct liveupdate_file_handler *fh; + struct file *file; + u64 private_data; + bool reclaimed; + enum liveupdate_state state; + struct mutex mutex; +}; + +static void luo_files_recreate_luo_files_xa_in(void) +{ + const char *node_name, *fdt_compat_str; + struct liveupdate_file_handler *fh; + struct luo_file *luo_file; + const void *data_ptr; + int file_node_offset; + int ret =3D 0; + + if (luo_files_xa_in_recreated || !luo_file_fdt_in) + return; + + /* Take write in order to guarantee that we re-create list once */ + down_write(&luo_register_file_list_rwsem); + if (luo_files_xa_in_recreated) + goto exit_unlock; + + fdt_for_each_subnode(file_node_offset, luo_file_fdt_in, 0) { + bool handler_found =3D false; + u64 token; + + node_name =3D fdt_get_name(luo_file_fdt_in, file_node_offset, + NULL); + if (!node_name) { + panic("FDT subnode at offset %d: Cannot get name\n", + file_node_offset); + } + + ret =3D kstrtou64(node_name, 0, &token); + if (ret < 0) { + panic("FDT node '%s': Failed to parse token\n", + node_name); + } + + if (xa_load(&luo_files_xa_in, token)) { + panic("Duplicate token %llu found in incoming FDT for file descriptors.= \n", + token); + } + + fdt_compat_str =3D fdt_getprop(luo_file_fdt_in, file_node_offset, + "compatible", NULL); + if (!fdt_compat_str) { + panic("FDT node '%s': Missing 'compatible' property\n", + node_name); + } + + data_ptr =3D fdt_getprop(luo_file_fdt_in, file_node_offset, "data", + NULL); + if (!data_ptr) { + panic("Can't recover property 'data' for FDT node '%s'\n", + node_name); + } + + list_for_each_entry(fh, &luo_register_file_list, list) { + if (!strcmp(fh->compatible, fdt_compat_str)) { + handler_found =3D true; + break; + } + } + + if (!handler_found) { + panic("FDT node '%s': No registered handler for compatible '%s'\n", + node_name, fdt_compat_str); + } + + luo_file =3D kmalloc(sizeof(*luo_file), + GFP_KERNEL | __GFP_NOFAIL); + luo_file->fh =3D fh; + luo_file->file =3D NULL; + memcpy(&luo_file->private_data, data_ptr, sizeof(u64)); + luo_file->reclaimed =3D false; + mutex_init(&luo_file->mutex); + luo_file->state =3D LIVEUPDATE_STATE_UPDATED; + ret =3D xa_err(xa_store(&luo_files_xa_in, token, luo_file, + GFP_KERNEL | __GFP_NOFAIL)); + if (ret < 0) { + panic("Failed to store luo_file for token %llu in XArray: %d\n", + token, ret); + } + } + luo_files_xa_in_recreated =3D true; + +exit_unlock: + up_write(&luo_register_file_list_rwsem); +} + +static size_t luo_files_fdt_size(void) +{ + u64 num_files =3D atomic64_read(&luo_files_count); + + /* Estimate a 1K overhead, + 128 bytes per file entry */ + return PAGE_SIZE << get_order(SZ_1K + (num_files * 128)); +} + +static void luo_files_fdt_cleanup(void) +{ + WARN_ON_ONCE(kho_unpreserve_phys(__pa(luo_file_fdt_out), + luo_file_fdt_out_size)); + + free_pages((unsigned long)luo_file_fdt_out, + get_order(luo_file_fdt_out_size)); + + luo_file_fdt_out_size =3D 0; + luo_file_fdt_out =3D NULL; +} + +static int luo_files_to_fdt(struct xarray *files_xa_out) +{ + const u64 zero_data =3D 0; + unsigned long token; + struct luo_file *h; + char token_str[19]; + int ret =3D 0; + + xa_for_each(files_xa_out, token, h) { + snprintf(token_str, sizeof(token_str), "%#0llx", (u64)token); + + ret =3D fdt_begin_node(luo_file_fdt_out, token_str); + if (ret < 0) + break; + + ret =3D fdt_property_string(luo_file_fdt_out, "compatible", + h->fh->compatible); + if (ret < 0) { + fdt_end_node(luo_file_fdt_out); + break; + } + + ret =3D fdt_property_u64(luo_file_fdt_out, "data", zero_data); + if (ret < 0) { + fdt_end_node(luo_file_fdt_out); + break; + } + + ret =3D fdt_end_node(luo_file_fdt_out); + if (ret < 0) + break; + } + + return ret; +} + +static int luo_files_fdt_setup(void) +{ + int ret; + + luo_file_fdt_out_size =3D luo_files_fdt_size(); + luo_file_fdt_out =3D (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, + get_order(luo_file_fdt_out_size)); + if (!luo_file_fdt_out) { + pr_err("Failed to allocate FDT memory (%zu bytes)\n", + luo_file_fdt_out_size); + luo_file_fdt_out_size =3D 0; + return -ENOMEM; + } + + ret =3D kho_preserve_phys(__pa(luo_file_fdt_out), luo_file_fdt_out_size); + if (ret) { + pr_err("Failed to kho preserve FDT memory (%zu bytes)\n", + luo_file_fdt_out_size); + luo_file_fdt_out_size =3D 0; + luo_file_fdt_out =3D NULL; + return ret; + } + + ret =3D fdt_create(luo_file_fdt_out, luo_file_fdt_out_size); + if (ret < 0) + goto exit_cleanup; + + ret =3D fdt_finish_reservemap(luo_file_fdt_out); + if (ret < 0) + goto exit_finish; + + ret =3D fdt_begin_node(luo_file_fdt_out, LUO_FILES_NODE_NAME); + if (ret < 0) + goto exit_finish; + + ret =3D fdt_property_string(luo_file_fdt_out, "compatible", + LUO_FILES_COMPATIBLE); + if (ret < 0) + goto exit_end_node; + + ret =3D luo_files_to_fdt(&luo_files_xa_out); + if (ret < 0) + goto exit_end_node; + + ret =3D fdt_end_node(luo_file_fdt_out); + if (ret < 0) + goto exit_finish; + + ret =3D fdt_finish(luo_file_fdt_out); + if (ret < 0) + goto exit_cleanup; + + return 0; + +exit_end_node: + fdt_end_node(luo_file_fdt_out); +exit_finish: + fdt_finish(luo_file_fdt_out); +exit_cleanup: + pr_err("Failed to setup FDT: %s (ret %d)\n", fdt_strerror(ret), ret); + luo_files_fdt_cleanup(); + + return ret; +} + +static int luo_files_prepare(void *arg, u64 *data) +{ + int ret; + + ret =3D luo_files_fdt_setup(); + if (ret) + return ret; + + *data =3D __pa(luo_file_fdt_out); + + return ret; +} + +static int luo_files_freeze(void *arg, u64 *data) +{ + return 0; +} + +static void luo_files_finish(void *arg, u64 data) +{ + luo_files_recreate_luo_files_xa_in(); +} + +static void luo_files_cancel(void *arg, u64 data) +{ +} + +static const struct liveupdate_subsystem_ops luo_file_subsys_ops =3D { + .prepare =3D luo_files_prepare, + .freeze =3D luo_files_freeze, + .cancel =3D luo_files_cancel, + .finish =3D luo_files_finish, +}; + +static struct liveupdate_subsystem luo_file_subsys =3D { + .ops =3D &luo_file_subsys_ops, + .name =3D LUO_FILES_NODE_NAME, +}; + +static int __init luo_files_startup(void) +{ + int ret; + + if (!liveupdate_enabled()) + return 0; + + ret =3D liveupdate_register_subsystem(&luo_file_subsys); + if (ret) { + pr_warn("Failed to register luo_file subsystem [%d]\n", ret); + return ret; + } + + if (liveupdate_state_updated()) { + u64 fdt_pa; + + ret =3D liveupdate_get_subsystem_data(&luo_file_subsys, &fdt_pa); + if (ret) + panic("Failed to retrieve luo_file data [%d]\n", ret); + + ret =3D fdt_node_check_compatible(__va(fdt_pa), 0, + LUO_FILES_COMPATIBLE); + if (ret) { + panic("FDT '%s' is incompatible with '%s' [%d]\n", + LUO_FILES_NODE_NAME, LUO_FILES_COMPATIBLE, ret); + } + luo_file_fdt_in =3D __va(fdt_pa); + } + + return ret; +} +late_initcall(luo_files_startup); + +/** + * luo_register_file - Register a file descriptor for live update manageme= nt. + * @token: Token value for this file descriptor. + * @fd: file descriptor to be preserved. + * + * Context: Must be called when LUO is in 'normal' state. + * + * Return: 0 on success. Negative errno on failure. + */ +int luo_register_file(u64 token, int fd) +{ + struct liveupdate_file_handler *fh; + struct luo_file *luo_file; + bool found =3D false; + int ret =3D -ENOENT; + struct file *file; + + file =3D fget(fd); + if (!file) { + pr_err("Bad file descriptor\n"); + return -EBADF; + } + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + pr_warn("File can be registered only in normal or updated state\n"); + luo_state_read_exit(); + fput(file); + return -EBUSY; + } + + down_read(&luo_register_file_list_rwsem); + list_for_each_entry(fh, &luo_register_file_list, list) { + if (fh->ops->can_preserve(file, fh->arg)) { + found =3D true; + break; + } + } + + if (!found) + goto exit_unlock; + + luo_file =3D kmalloc(sizeof(*luo_file), GFP_KERNEL); + if (!luo_file) { + ret =3D -ENOMEM; + goto exit_unlock; + } + + luo_file->private_data =3D 0; + luo_file->reclaimed =3D false; + + luo_file->file =3D file; + luo_file->fh =3D fh; + mutex_init(&luo_file->mutex); + luo_file->state =3D LIVEUPDATE_STATE_NORMAL; + + if (xa_load(&luo_files_xa_out, token)) { + ret =3D -EEXIST; + pr_warn("Token %llu is already taken\n", token); + mutex_destroy(&luo_file->mutex); + kfree(luo_file); + goto exit_unlock; + } + + ret =3D xa_err(xa_store(&luo_files_xa_out, token, luo_file, + GFP_KERNEL)); + if (ret < 0) { + pr_warn("Failed to store file for token %llu in XArray: %d\n", + token, ret); + mutex_destroy(&luo_file->mutex); + kfree(luo_file); + goto exit_unlock; + } + atomic64_inc(&luo_files_count); + +exit_unlock: + up_read(&luo_register_file_list_rwsem); + luo_state_read_exit(); + + if (ret) + fput(file); + + return ret; +} + +/** + * luo_unregister_file - Unregister a file instance using its token. + * @token: The unique token of the file instance to unregister. + * + * Finds the &struct luo_file associated with the @token in the + * global list and removes it. This function *only* removes the entry from= the + * list; it does *not* free the memory allocated for the &struct luo_file + * itself. The caller is responsible for freeing the structure after this + * function returns successfully. + * + * Context: Can be called when a preserved file descriptor is closed or + * no longer needs live update management. + * + * Return: 0 on success. Negative errno on failure. + */ +int luo_unregister_file(u64 token) +{ + struct luo_file *luo_file; + int ret =3D 0; + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + pr_warn("File can be unregistered only in normal or updates state\n"); + luo_state_read_exit(); + return -EBUSY; + } + + luo_file =3D xa_erase(&luo_files_xa_out, token); + if (luo_file) { + fput(luo_file->file); + mutex_destroy(&luo_file->mutex); + kfree(luo_file); + atomic64_dec(&luo_files_count); + } else { + pr_warn("Failed to unregister: token %llu not found.\n", + token); + ret =3D -ENOENT; + } + luo_state_read_exit(); + + return ret; +} + +/** + * luo_retrieve_file - Find a registered file instance by its token. + * @token: The unique token of the file instance to retrieve. + * @filep: Output parameter. On success (return value 0), this will point + * to the retrieved "struct file". + * + * Searches the global list for a &struct luo_file matching the @token. Us= es a + * read lock, allowing concurrent retrievals. + * + * Return: 0 on success. Negative errno on failure. + */ +int luo_retrieve_file(u64 token, struct file **filep) +{ + struct luo_file *luo_file; + int ret =3D 0; + + luo_files_recreate_luo_files_xa_in(); + luo_state_read_enter(); + if (!liveupdate_state_updated()) { + pr_warn("File can be retrieved only in updated state\n"); + luo_state_read_exit(); + return -EBUSY; + } + + luo_file =3D xa_load(&luo_files_xa_in, token); + if (luo_file && !luo_file->reclaimed) { + mutex_lock(&luo_file->mutex); + if (!luo_file->reclaimed) { + luo_file->reclaimed =3D true; + ret =3D luo_file->fh->ops->retrieve(luo_file->fh->arg, + luo_file->private_data, + filep); + if (!ret) + luo_file->file =3D *filep; + } + mutex_unlock(&luo_file->mutex); + } else if (luo_file && luo_file->reclaimed) { + pr_err("The file descriptor for token %lld has already been retrieved\n", + token); + ret =3D -EINVAL; + } else { + ret =3D -ENOENT; + } + + luo_state_read_exit(); + + return ret; +} + +/** + * liveupdate_register_file_handler - Register a file handler with LUO. + * @fh: Pointer to a caller-allocated &struct liveupdate_file_handler. + * The caller must initialize this structure, including a unique + * 'compatible' string and a valid 'fh' callbacks. This function adds the + * handler to the global list of supported file handlers. + * + * Context: Typically called during module initialization for file types t= hat + * support live update preservation. + * + * Return: 0 on success. Negative errno on failure. + */ +int liveupdate_register_file_handler(struct liveupdate_file_handler *fh) +{ + struct liveupdate_file_handler *fh_iter; + int ret =3D 0; + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + luo_state_read_exit(); + return -EBUSY; + } + + down_write(&luo_register_file_list_rwsem); + list_for_each_entry(fh_iter, &luo_register_file_list, list) { + if (!strcmp(fh_iter->compatible, fh->compatible)) { + pr_err("File handler registration failed: Compatible string '%s' alread= y registered.\n", + fh->compatible); + ret =3D -EEXIST; + goto exit_unlock; + } + } + + INIT_LIST_HEAD(&fh->list); + list_add_tail(&fh->list, &luo_register_file_list); + +exit_unlock: + up_write(&luo_register_file_list_rwsem); + luo_state_read_exit(); + + return ret; +} +EXPORT_SYMBOL_GPL(liveupdate_register_file_handler); + +/** + * liveupdate_unregister_file - Unregister a file handler. + * @fh: Pointer to the specific &struct liveupdate_file_handler instance + * that was previously returned by or passed to + * liveupdate_register_file_handler. + * + * Removes the specified handler instance @fh from the global list of + * registered file handlers. This function only removes the entry from the + * list; it does not free the memory associated with @fh itself. The caller + * is responsible for freeing the structure memory after this function ret= urns + * successfully. + * + * Return: 0 on success. Negative errno on failure. + */ +int liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh) +{ + unsigned long token; + struct luo_file *h; + int ret =3D 0; + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + luo_state_read_exit(); + return -EBUSY; + } + + down_write(&luo_register_file_list_rwsem); + + xa_for_each(&luo_files_xa_out, token, h) { + if (h->fh =3D=3D fh) { + up_write(&luo_register_file_list_rwsem); + luo_state_read_exit(); + return -EBUSY; + } + } + + list_del_init(&fh->list); + up_write(&luo_register_file_list_rwsem); + luo_state_read_exit(); + + return ret; +} +EXPORT_SYMBOL_GPL(liveupdate_unregister_file_handler); diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index 98bf799adb61..f77e8b3044f9 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -25,4 +25,8 @@ int luo_do_subsystems_freeze_calls(void); void luo_do_subsystems_finish_calls(void); void luo_do_subsystems_cancel_calls(void); =20 +int luo_retrieve_file(u64 token, struct file **filep); +int luo_register_file(u64 token, int fd); +int luo_unregister_file(u64 token); + #endif /* _LINUX_LUO_INTERNAL_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.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 205982D3EC7 for ; Wed, 25 Jun 2025 23:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893553; cv=none; b=GqGEZuOb1SefzlI37ZSjfsCZhMqpzVAhMkRpVSaisENcQtr0njIk3beA4LpvYv+JiBdsA5+0/ofqbdzuU9SyCJK1g2N5pjgbOW/jorUMXKVscmV74m3PZAvHv1dbNaEx2ZC3L1h0J5+yo0BpVsM+SZW74zRoT6v8g1cpexeRkKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893553; c=relaxed/simple; bh=Cfi9j2oHaj3a+1RPOlQ6V9S6n7G0Pg+wsLencW8TXUg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BOgQqAs/kjV8lCSHtbk8EsI720j+4gzlSbDbFxaj8TU/iFg/xDKfa2X6580zkB6HxFQn9IzYDWD/PhIM427qzGSdmwZiEgpWyPyn90w1dYhfMwrxBdRXm5gjFEGk/NkbeAh0ZRr2ijypG3QMyt8lSH8tF/GSB1kGXrnwjnFko0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=pOY+I0Ux; arc=none smtp.client-ip=209.85.219.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="pOY+I0Ux" Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-e812c817de0so347530276.0 for ; Wed, 25 Jun 2025 16:19:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893549; x=1751498349; 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=sk38mGBhqK7qzK3HNwB+80JVX/lHD/SIvkcYryZBkd4=; b=pOY+I0UxdKQFTSBy93acHuTY4hqY1W+Ye9acZfjYXHsYXo6ah1Kz+RnyjrdmSCc4yT 9Opu3R+xhCJIWZN0N0dVgs8I0+s9XCp9iUS4iuQ3tpUQE3gsTjgSW12znb78e3k5nt/5 mectUkj5025YU6T8EcV2p49MzBai4NfTpdElgVoYAfY6imlv3PoTdPpFmZsYkNAFyQNH P6ur8CYcUKof9gAUiyrVi2p3pCwiPJ/eBY2y+ecd9JyikmYAHezogaItiU4VLhllTz/t iE7Rz+OhtjIuLRFMjmAx/m9+EK5DG3sDr7fk3C2e1oUUs7rbdqJ21a7vpBM3wwIS/oF4 COXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893549; x=1751498349; 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=sk38mGBhqK7qzK3HNwB+80JVX/lHD/SIvkcYryZBkd4=; b=r7HtoTNV6gpFlGJONwq9vnkhJ+0tHDX97PXEADVblRbDEBWrVhDlPs3iyTjDBTjKIN cLw7T15VSrYNkY7rph9zbQF2KGgL9bZL0ZxF9xex26IIlm5V1yKmu4mpG9WcMOzui0GL HMSt09hLcMo9TeMT12OIRDqpfL7iyQhQWdvNm3OySV3QwwMH11Nu+q/qBLfsYsz0pLPI 0SNg995kBqdDbz8n62+rLrOIu1Z8iYNyJqoQ/5as4mkBLg0srHVaozfQTPnKjIaAhbX1 b6/ZlL0Oi+9BfdrPdex9s8UNMSm2PVSWPIhNTLCMrgh0ulsZzfx2ihJRL4SRbWxpevPb PUIw== X-Forwarded-Encrypted: i=1; AJvYcCV45cII9xiqpxU3W6uiHE7aWPpB7z/kLQclBGwxj0n9CiUsnjMggZc5KfUIwSVmEqkBG6ktL+A6E4m+2L4=@vger.kernel.org X-Gm-Message-State: AOJu0Yyy9dIyAoVKvwFK3ob5JAdDA3vxNvrH1a1dsw3HYGIcezCW/YWD OeHObAoLtX/z3hbes+IYT9/VJ/suM1+lRnuhE+a4B02s/Jx0PtPup2exXEOrtVWtPbI= X-Gm-Gg: ASbGncvsZE6wL9wSaB5uQlbbb8wYuJJUsCe5cF/UGtDBV0tc6SdrQZhPrDJr91AWOX6 TVuO1bg6meXDox+u1QOoI5VOgDo/XxoeYZM3ixlOH9zuEaKk1ID+WEVaPgncuBAFIuHgRG/1XNR K7x+dWpBorbUV+qHEx+v2z08gjxXhcH0/NmsmGvZCEA8R0FTJV3e56JUifXapsWUSPHz6uu0StM 67c4nfVCgOpNncbxkM/fmwyVoT6l4ToLXVVY2VzP+UpVPFLEA0U0lbmg+37nDAcA6EOGxozP0Ar X1OuD4Nk4hI5OQp0YzVEhJgMLj8ZJe4XJFqHQpsCS30DT7xdOesffjc7R5ZG3LXhzgNkMBg8+oB e1mT4qJ1Njiy3+cl5kH4FgsfdijPuCXtkj5KvQVLYfvU3vDjxPW/u X-Google-Smtp-Source: AGHT+IF/RgxxhWmfB1Y2MqbieDB4I6eRiGrckxjMs1m4U+N2pAXqAFN4tpFMCdmuvzDLcl2Fl05y+g== X-Received: by 2002:a05:6902:114b:b0:e84:363a:133e with SMTP id 3f1490d57ef6-e8601760f75mr6660102276.13.1750893549002; Wed, 25 Jun 2025 16:19:09 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:08 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 15/32] liveupdate: luo_files: implement file systems callbacks Date: Wed, 25 Jun 2025 23:18:02 +0000 Message-ID: <20250625231838.1897085-16-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Implements the core logic within luo_files.c to invoke the prepare, reboot, finish, and cancel callbacks for preserved file instances, replacing the previous stub implementations. It also handles the persistence and retrieval of the u64 data payload associated with each file via the LUO FDT. This completes the core mechanism enabling registered files handlers to act= ively manage file state across the live update transition using the LUO framework. Signed-off-by: Pasha Tatashin --- kernel/liveupdate/luo_files.c | 166 +++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 2 deletions(-) diff --git a/kernel/liveupdate/luo_files.c b/kernel/liveupdate/luo_files.c index 3582f1ec96c4..cd956ea69f43 100644 --- a/kernel/liveupdate/luo_files.c +++ b/kernel/liveupdate/luo_files.c @@ -325,31 +325,193 @@ static int luo_files_fdt_setup(void) return ret; } =20 +static int luo_files_prepare_one(struct luo_file *h) +{ + int ret =3D 0; + + mutex_lock(&h->mutex); + if (h->state =3D=3D LIVEUPDATE_STATE_NORMAL) { + if (h->fh->ops->prepare) { + ret =3D h->fh->ops->prepare(h->file, h->fh->arg, + &h->private_data); + } + if (!ret) + h->state =3D LIVEUPDATE_STATE_PREPARED; + } else { + WARN_ON_ONCE(h->state !=3D LIVEUPDATE_STATE_PREPARED && + h->state !=3D LIVEUPDATE_STATE_FROZEN); + } + mutex_unlock(&h->mutex); + + return ret; +} + +static int luo_files_freeze_one(struct luo_file *h) +{ + int ret =3D 0; + + mutex_lock(&h->mutex); + if (h->state =3D=3D LIVEUPDATE_STATE_PREPARED) { + if (h->fh->ops->freeze) { + ret =3D h->fh->ops->freeze(h->file, h->fh->arg, + &h->private_data); + } + if (!ret) + h->state =3D LIVEUPDATE_STATE_FROZEN; + } else { + WARN_ON_ONCE(h->state !=3D LIVEUPDATE_STATE_FROZEN); + } + mutex_unlock(&h->mutex); + + return ret; +} + +static void luo_files_finish_one(struct luo_file *h) +{ + mutex_lock(&h->mutex); + if (h->state =3D=3D LIVEUPDATE_STATE_UPDATED) { + if (h->fh->ops->finish) { + h->fh->ops->finish(h->file, h->fh->arg, h->private_data, + h->reclaimed); + } + h->state =3D LIVEUPDATE_STATE_NORMAL; + } else { + WARN_ON_ONCE(h->state !=3D LIVEUPDATE_STATE_NORMAL); + } + mutex_unlock(&h->mutex); +} + +static void luo_files_cancel_one(struct luo_file *h) +{ + int ret; + + mutex_lock(&h->mutex); + if (h->state =3D=3D LIVEUPDATE_STATE_NORMAL) + goto exit_unlock; + + ret =3D WARN_ON_ONCE(h->state !=3D LIVEUPDATE_STATE_PREPARED && + h->state !=3D LIVEUPDATE_STATE_FROZEN); + if (ret) + goto exit_unlock; + + if (h->fh->ops->cancel) + h->fh->ops->cancel(h->file, h->fh->arg, h->private_data); + h->private_data =3D 0; + h->state =3D LIVEUPDATE_STATE_NORMAL; + +exit_unlock: + mutex_unlock(&h->mutex); +} + +static void __luo_files_cancel(struct luo_file *boundary_file) +{ + unsigned long token; + struct luo_file *h; + + xa_for_each(&luo_files_xa_out, token, h) { + if (h =3D=3D boundary_file) + break; + + luo_files_cancel_one(h); + } + luo_files_fdt_cleanup(); +} + +static int luo_files_commit_data_to_fdt(void) +{ + int node_offset, ret; + unsigned long token; + char token_str[19]; + struct luo_file *h; + + xa_for_each(&luo_files_xa_out, token, h) { + snprintf(token_str, sizeof(token_str), "%#0llx", (u64)token); + node_offset =3D fdt_subnode_offset(luo_file_fdt_out, + 0, + token_str); + ret =3D fdt_setprop(luo_file_fdt_out, node_offset, "data", + &h->private_data, sizeof(h->private_data)); + if (ret < 0) { + pr_err("Failed to set data property for token %s: %s\n", + token_str, fdt_strerror(ret)); + return -ENOSPC; + } + } + + return 0; +} + static int luo_files_prepare(void *arg, u64 *data) { + unsigned long token; + struct luo_file *h; int ret; =20 ret =3D luo_files_fdt_setup(); if (ret) return ret; =20 - *data =3D __pa(luo_file_fdt_out); + xa_for_each(&luo_files_xa_out, token, h) { + ret =3D luo_files_prepare_one(h); + if (ret < 0) { + pr_err("Prepare failed for file token %#0llx handler '%s' [%d]\n", + (u64)token, h->fh->compatible, ret); + __luo_files_cancel(h); + + return ret; + } + } + + ret =3D luo_files_commit_data_to_fdt(); + if (ret) + __luo_files_cancel(NULL); + else + *data =3D __pa(luo_file_fdt_out); =20 return ret; } =20 static int luo_files_freeze(void *arg, u64 *data) { - return 0; + unsigned long token; + struct luo_file *h; + int ret; + + xa_for_each(&luo_files_xa_out, token, h) { + ret =3D luo_files_freeze_one(h); + if (ret < 0) { + pr_err("Freeze callback failed for file token %#0llx handler '%s' [%d]\= n", + (u64)token, h->fh->compatible, ret); + __luo_files_cancel(h); + + return ret; + } + } + + ret =3D luo_files_commit_data_to_fdt(); + if (ret) + __luo_files_cancel(NULL); + + return ret; } =20 static void luo_files_finish(void *arg, u64 data) { + unsigned long token; + struct luo_file *h; + luo_files_recreate_luo_files_xa_in(); + xa_for_each(&luo_files_xa_in, token, h) { + luo_files_finish_one(h); + mutex_destroy(&h->mutex); + kfree(h); + } + xa_destroy(&luo_files_xa_in); } =20 static void luo_files_cancel(void *arg, u64 data) { + __luo_files_cancel(NULL); } =20 static const struct liveupdate_subsystem_ops luo_file_subsys_ops =3D { --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.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 10CCA2FCE06 for ; Wed, 25 Jun 2025 23:19:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893554; cv=none; b=IUdg+NjSMthbODL0t/DGor7SBCszxIlqTdS6v2Msei5XlXpocRf0hKd7i8LMfOSPYYTnr0C948lhQn6wwCtbdIKKQ3hXEhzE0nORw3ieWmNzn/+SRDf0gXHQIk4fPLnT/FxfT0gNvY87KC7te+fapfso8SD/At0s1y9fCUi8WDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893554; c=relaxed/simple; bh=S+USuASgiAWLoGLEg40jmspH2nuy/XVSxxvs0BOFsVY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EzSPAF/3V9vIbtYnYOCxVMe4KwqjQF7LgAQl9/h/YAofFrCfnEw4mYXEWAhdSUglXiKqDEtT9gHot2fJTa4svwLhBeIO3pAhFSmEIgEpD4lcehEV09oT0LA1+2DlnyNhRZeKVAsW9HyDj+cMq/syEo9ZLIqD6gE9B4OP8KqAowE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=i3xFptcD; arc=none smtp.client-ip=209.85.219.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="i3xFptcD" Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-e7d9d480e6cso246213276.2 for ; Wed, 25 Jun 2025 16:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893551; x=1751498351; 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=q9OeQwvAtSpE7KYIsGHzDzwJJRVZThZJEHAd4sog2is=; b=i3xFptcD/U7quPFTmW2Ljdj58v7u98wRxAmu7vFEcTbyYEBaUqVbfyHREA+8oeYnHL Uu05lYVQ3gGp07Ckm718CPN21jgeCXGACEg3TdDbRZVAazxbT/hHK0ChswY3cB3f9WEA BjnVW4KNvPNtpvyO7Yeva7BENOyR4mRwkBIx8xXeoStRvCgH5hrWHIayIpdMMYMJ1pG1 /OGfqrRsoZeIKH5eMyB1SdKB3Fd6/4slHHl2pOAxOj+FVqFpIGSKCjTia6ijR50dtsrF gQIOhlyFPRnZtRbEwIe4/0nGdsZQQP+7HzMzDtS7ph0ekYULO0o9cfiNya8gcpD2+uVQ xhZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893551; x=1751498351; 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=q9OeQwvAtSpE7KYIsGHzDzwJJRVZThZJEHAd4sog2is=; b=UDpJZGCfhXFyJmk8QAie/VhACVfBfsD3PKjWMTCLeBiU87eimgZKwokr30AWn5pFEf eOq4NXW4pjMwGcyn+94+tTspsV4kQpr3J8w6Q75wMsMGEWioMpd4m4ckAqRZM0Km7EOM PV9cvYeB5scrYkjiBTBswPLg510hfgOrZVWF4zSV2bKYjok0damPVlZuO1exTl5lV6Z3 Cz0nLDytJOtVbBp/MlSjX91BKH4uT0ewpySSv5TEQg0U1wJ8ci0vkrNB8IACB4S7lt69 YZDxr91paRRU1w6BsImv0shtpR1P+m7OUyiw18yXcdD6kyT80kmhLwLyTvP6cs7GLFCU GW6Q== X-Forwarded-Encrypted: i=1; AJvYcCXwO7YmFpzfBayAyb8htfwQdXNLV6f2wT7BJqXCCKI8lPMLwLnMb1E+6Q26mtsFtf8eCMcyKtBGkqUnEZQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxyuWjf7u2pxkZNg2unvBCFcLeJdFr9jgeiazF/8KQfNZp8ltND mqdzgp7swbSKzvOSOzGkona+nAxfo40VbKPPhB+/MdI0pS5ZJLpAb7iQu+TJo6ndegc= X-Gm-Gg: ASbGnctDXwmsu9mMPZ6VccIQrg57gO7uV/HDpvfOwzHY4gO4Q0qa+VU+tF1TWdzTG2o PFnZ0vpRrmndlYkimR457+8CAjD1U0wWECdt3zZv1MtdnYT7WnwHufo4yYVa47okSyLLSztNtEV +KOdjGmu8gxo6TBhfyXNdKoivZPeKqLqQRqflSKENqpcDyniLls6tGenMfXtmSbEN4yM+C2wSBf wwXGVWi//VprzXgJs6zHTxw6M3vKU745YgxYh8mylVuw3TEyim3eWrtHpzS18FwSGhv5Hxs9zu5 ZW+WDVk5/PJzDk2WBiJ/duY0yXk08gNgFrC1PANy//p6A47voPvT8AD8rgQlfvYQ7fxsFfCJH4I g4IqAgx/y4ES0MStmeCo9vE90HtqpFoSs05VjDBF+Ab44R5xDiYtV X-Google-Smtp-Source: AGHT+IF28eiwjJHMy7Ve+TxPexX03L5N+dFsr5T9nLJ5gUzi03DI4MbfpJsnWZJhna2trPwN4u1gRA== X-Received: by 2002:a05:6902:724:b0:e7d:59e0:f65e with SMTP id 3f1490d57ef6-e86016db6b6mr5123970276.1.1750893550859; Wed, 25 Jun 2025 16:19:10 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:10 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 16/32] liveupdate: luo_ioctl: add ioctl interface Date: Wed, 25 Jun 2025 23:18:03 +0000 Message-ID: <20250625231838.1897085-17-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Introduce the user-space interface for the Live Update Orchestrator via ioctl commands, enabling external control over the live update process and management of preserved resources. Create a character device at /dev/liveupdate. Access to this device requires the CAP_SYS_ADMIN capability. A new uAPI header, , defines the necessary structures. The magic number is registered in Documentation/userspace-api/ioctl/ioctl-number.rst. Signed-off-by: Pasha Tatashin --- .../userspace-api/ioctl/ioctl-number.rst | 2 + include/linux/liveupdate.h | 36 +-- include/uapi/linux/liveupdate.h | 265 ++++++++++++++++++ kernel/liveupdate/Makefile | 1 + kernel/liveupdate/luo_ioctl.c | 178 ++++++++++++ 5 files changed, 447 insertions(+), 35 deletions(-) create mode 100644 include/uapi/linux/liveupdate.h create mode 100644 kernel/liveupdate/luo_ioctl.c diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documenta= tion/userspace-api/ioctl/ioctl-number.rst index bc91756bde73..8368aa05b4df 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -380,6 +380,8 @@ Code Seq# Include File = Comments 0xB8 01-02 uapi/misc/mrvl_cn10k_dpi.h Marve= ll CN10K DPI driver 0xB8 all uapi/linux/mshv.h Micro= soft Hyper-V /dev/mshv driver +0xBA all uapi/linux/liveupdate.h Pasha= Tatashin + 0xC0 00-0F linux/usb/iowarrior.h 0xCA 00-0F uapi/misc/cxl.h Dead = since 6.15 0xCA 10-2F uapi/misc/ocxl.h diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index 28a8aa4cafca..970447de5d8c 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -10,6 +10,7 @@ #include #include #include +#include =20 /** * enum liveupdate_event - Events that trigger live update callbacks. @@ -53,41 +54,6 @@ enum liveupdate_event { LIVEUPDATE_CANCEL, }; =20 -/** - * enum liveupdate_state - Defines the possible states of the live update - * orchestrator. - * @LIVEUPDATE_STATE_UNDEFINED: State has not yet been initialized. - * @LIVEUPDATE_STATE_NORMAL: Default state, no live update in prog= ress. - * @LIVEUPDATE_STATE_PREPARED: Live update is prepared for reboot; t= he - * LIVEUPDATE_PREPARE callbacks have com= pleted - * successfully. - * Devices might operate in a limited st= ate - * for example the participating devices= might - * not be allowed to unbind, and also the - * setting up of new DMA mappings might = be - * disabled in this state. - * @LIVEUPDATE_STATE_FROZEN: The final reboot event - * (%LIVEUPDATE_FREEZE) has been sent, a= nd the - * system is performing its final state = saving - * within the "blackout window". User - * workloads must be suspended. The actu= al - * reboot (kexec) into the next kernel is - * imminent. - * @LIVEUPDATE_STATE_UPDATED: The system has rebooted into the next - * kernel via live update the system is = now - * running the next kernel, awaiting the - * finish event. - * - * These states track the progress and outcome of a live update operation. - */ -enum liveupdate_state { - LIVEUPDATE_STATE_UNDEFINED =3D 0, - LIVEUPDATE_STATE_NORMAL =3D 1, - LIVEUPDATE_STATE_PREPARED =3D 2, - LIVEUPDATE_STATE_FROZEN =3D 3, - LIVEUPDATE_STATE_UPDATED =3D 4, -}; - struct file; =20 /** diff --git a/include/uapi/linux/liveupdate.h b/include/uapi/linux/liveupdat= e.h new file mode 100644 index 000000000000..7b12a1073c3c --- /dev/null +++ b/include/uapi/linux/liveupdate.h @@ -0,0 +1,265 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +/* + * Userspace interface for /dev/liveupdate + * Live Update Orchestrator + * + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#ifndef _UAPI_LIVEUPDATE_H +#define _UAPI_LIVEUPDATE_H + +#include +#include + +/** + * enum liveupdate_state - Defines the possible states of the live update + * orchestrator. + * @LIVEUPDATE_STATE_UNDEFINED: State has not yet been initialized. + * @LIVEUPDATE_STATE_NORMAL: Default state, no live update in prog= ress. + * @LIVEUPDATE_STATE_PREPARED: Live update is prepared for reboot; t= he + * LIVEUPDATE_PREPARE callbacks have com= pleted + * successfully. + * Devices might operate in a limited st= ate + * for example the participating devices= might + * not be allowed to unbind, and also the + * setting up of new DMA mappings might = be + * disabled in this state. + * @LIVEUPDATE_STATE_FROZEN: The final reboot event + * (%LIVEUPDATE_FREEZE) has been sent, a= nd the + * system is performing its final state = saving + * within the "blackout window". User + * workloads must be suspended. The actu= al + * reboot (kexec) into the next kernel is + * imminent. + * @LIVEUPDATE_STATE_UPDATED: The system has rebooted into the next + * kernel via live update the system is = now + * running the next kernel, awaiting the + * finish event. + * + * These states track the progress and outcome of a live update operation. + */ +enum liveupdate_state { + LIVEUPDATE_STATE_UNDEFINED =3D 0, + LIVEUPDATE_STATE_NORMAL =3D 1, + LIVEUPDATE_STATE_PREPARED =3D 2, + LIVEUPDATE_STATE_FROZEN =3D 3, + LIVEUPDATE_STATE_UPDATED =3D 4, +}; + +/** + * struct liveupdate_fd - Holds parameters for preserving and restoring fi= le + * descriptors across live update. + * @fd: Input for %LIVEUPDATE_IOCTL_FD_PRESERVE: The user-space file + * descriptor to be preserved. + * Output for %LIVEUPDATE_IOCTL_FD_RESTORE: The new file descriptor + * representing the fully restored kernel resource. + * @flags: Unused, reserved for future expansion, must be set to 0. + * @token: Input for %LIVEUPDATE_IOCTL_FD_PRESERVE: An opaque, unique token + * preserved for preserved resource. + * Input for %LIVEUPDATE_IOCTL_FD_RESTORE: The token previously + * provided to the preserve ioctl for the resource to be restored. + * + * This structure is used as the argument for the %LIVEUPDATE_IOCTL_FD_PRE= SERVE + * and %LIVEUPDATE_IOCTL_FD_RESTORE ioctls. These ioctls allow specific ty= pes + * of file descriptors (for example memfd, kvm, iommufd, and VFIO) to have= their + * underlying kernel state preserved across a live update cycle. + * + * To preserve an FD, user space passes this struct to + * %LIVEUPDATE_IOCTL_FD_PRESERVE with the @fd field set. On success, the + * kernel uses the @token field to uniquly associate the preserved FD. + * + * After the live update transition, user space passes the struct populate= d with + * the *same* @token to %LIVEUPDATE_IOCTL_FD_RESTORE. The kernel uses the = @token + * to find the preserved state and, on success, populates the @fd field wi= th a + * new file descriptor referring to the restored resource. + */ +struct liveupdate_fd { + int fd; + __u32 flags; + __aligned_u64 token; +}; + +/* The ioctl type, documented in ioctl-number.rst */ +#define LIVEUPDATE_IOCTL_TYPE 0xBA + +/** + * LIVEUPDATE_IOCTL_FD_PRESERVE - Validate and initiate preservation for a= file + * descriptor. + * + * Argument: Pointer to &struct liveupdate_fd. + * + * User sets the @fd field identifying the file descriptor to preserve + * (e.g., memfd, kvm, iommufd, VFIO). The kernel validates if this FD type + * and its dependencies are supported for preservation. If validation pass= es, + * the kernel marks the FD internally and *initiates the process* of prepa= ring + * its state for saving. The actual snapshotting of the state typically oc= curs + * during the subsequent %LIVEUPDATE_IOCTL_PREPARE execution phase, though + * some finalization might occur during freeze. + * On successful validation and initiation, the kernel uses the @token + * field with an opaque identifier representing the resource being preserv= ed. + * This token confirms the FD is targeted for preservation and is required= for + * the subsequent %LIVEUPDATE_IOCTL_FD_RESTORE call after the live update. + * + * Return: 0 on success (validation passed, preservation initiated), negat= ive + * error code on failure (e.g., unsupported FD type, dependency issue, + * validation failed). + */ +#define LIVEUPDATE_IOCTL_FD_PRESERVE \ + _IOW(LIVEUPDATE_IOCTL_TYPE, 0x00, struct liveupdate_fd) + +/** + * LIVEUPDATE_IOCTL_FD_UNPRESERVE - Remove a file descriptor from the + * preservation list. + * + * Argument: Pointer to __u64 token. + * + * Allows user space to explicitly remove a file descriptor from the set of + * items marked as potentially preservable. User space provides a pointer = to the + * __u64 @token that was previously returned by a successful + * %LIVEUPDATE_IOCTL_FD_PRESERVE call (potentially from a prior, possibly + * cancelled, live update attempt). The kernel reads the token value from = the + * provided user-space address. + * + * On success, the kernel removes the corresponding entry (identified by t= he + * token value read from the user pointer) from its internal preservation = list. + * The provided @token (representing the now-removed entry) becomes invalid + * after this call. + * + * Return: 0 on success, negative error code on failure (e.g., -EBUSY or -= EINVAL + * if not in %LIVEUPDATE_STATE_NORMAL, bad address provided, invalid token= value + * read, token not found). + */ +#define LIVEUPDATE_IOCTL_FD_UNPRESERVE \ + _IOW(LIVEUPDATE_IOCTL_TYPE, 0x01, __u64) + +/** + * LIVEUPDATE_IOCTL_FD_RESTORE - Restore a previously preserved file descr= iptor. + * + * Argument: Pointer to &struct liveupdate_fd. + * + * User sets the @token field to the value obtained from a successful + * %LIVEUPDATE_IOCTL_FD_PRESERVE call before the live update. On success, + * the kernel restores the state (saved during the PREPARE/FREEZE phases) + * associated with the token and populates the @fd field with a new file + * descriptor referencing the restored resource in the current (new) kerne= l. + * This operation must be performed *before* signaling completion via + * %LIVEUPDATE_IOCTL_FINISH. + * + * Return: 0 on success, negative error code on failure (e.g., invalid tok= en). + */ +#define LIVEUPDATE_IOCTL_FD_RESTORE \ + _IOWR(LIVEUPDATE_IOCTL_TYPE, 0x02, struct liveupdate_fd) + +/** + * LIVEUPDATE_IOCTL_GET_STATE - Query the current state of the live update + * orchestrator. + * + * Argument: Pointer to &enum liveupdate_state. + * + * The kernel fills the enum value pointed to by the argument with the cur= rent + * state of the live update subsystem. Possible states are: + * + * - %LIVEUPDATE_STATE_NORMAL: Default state; no live update operation is + * currently in progress. + * - %LIVEUPDATE_STATE_PREPARED: The preparation phase (triggered by + * %LIVEUPDATE_IOCTL_PREPARE) has completed + * successfully. The system is ready for the + * reboot transition. Note that some + * device operations (e.g., unbinding, new D= MA + * mappings) might be restricted in this sta= te. + * - %LIVEUPDATE_STATE_UPDATED: The system has successfully rebooted into= the + * new kernel via live update. It is now run= ning + * the new kernel code and is awaiting the + * completion signal from user space via + * %LIVEUPDATE_IOCTL_FINISH after + * restoration tasks are done. + * + * See the definition of &enum liveupdate_state for more details on each s= tate. + * + * Return: 0 on success, negative error code on failure. + */ +#define LIVEUPDATE_IOCTL_GET_STATE \ + _IOR(LIVEUPDATE_IOCTL_TYPE, 0x03, enum liveupdate_state) + +/** + * LIVEUPDATE_IOCTL_PREPARE - Initiate preparation phase and trigger state + * saving. + * + * Argument: None. + * + * Initiates the live update preparation phase. This action corresponds to + * the internal %LIVEUPDATE_PREPARE. This typically triggers the saving pr= ocess + * for items marked via the PRESERVE ioctls. This typically occurs *before* + * the "blackout window", while user applications (e.g., VMs) may still be + * running. Kernel subsystems receiving the %LIVEUPDATE_PREPARE event shou= ld + * serialize necessary state. This command does not transfer data. + * + * Return: 0 on success, negative error code on failure. Transitions state + * towards %LIVEUPDATE_STATE_PREPARED on success. + */ +#define LIVEUPDATE_IOCTL_PREPARE \ + _IO(LIVEUPDATE_IOCTL_TYPE, 0x04) + +/** + * LIVEUPDATE_IOCTL_CANCEL - Cancel the live update preparation phase. + * + * Argument: None. + * + * Notifies the live update subsystem to abort the preparation sequence + * potentially initiated by %LIVEUPDATE_IOCTL_PREPARE. This action + * typically corresponds to the internal %LIVEUPDATE_CANCEL kernel event, + * which might also be triggered automatically if the PREPARE stage fails + * internally. + * + * When triggered, subsystems receiving the %LIVEUPDATE_CANCEL event should + * revert any state changes or actions taken specifically for the aborted + * prepare phase (e.g., discard partially serialized state). The kernel + * releases resources allocated specifically for this *aborted preparation + * attempt*. + * + * This operation cancels the current *attempt* to prepare for a live upda= te + * but does **not** remove previously validated items from the internal li= st + * of potentially preservable resources. Consequently, preservation tokens + * previously generated by successful %LIVEUPDATE_IOCTL_FD_PRESERVE or cal= ls + * generally **remain valid** as identifiers for those potentially preserv= able + * resources. However, since the system state returns towards + * %LIVEUPDATE_STATE_NORMAL, user space must initiate a new live update se= quence + * (starting with %LIVEUPDATE_IOCTL_PREPARE) to proceed with an update + * using these (or other) tokens. + * + * This command does not transfer data. Kernel callbacks for the + * %LIVEUPDATE_CANCEL event must not fail. + * + * Return: 0 on success, negative error code on failure. Transitions state= back + * towards %LIVEUPDATE_STATE_NORMAL on success. + */ +#define LIVEUPDATE_IOCTL_CANCEL \ + _IO(LIVEUPDATE_IOCTL_TYPE, 0x06) + +/** + * LIVEUPDATE_IOCTL_EVENT_FINISH - Signal restoration completion and trigg= er + * cleanup. + * + * Argument: None. + * + * Signals that user space has completed all necessary restoration actions= in + * the new kernel (after a live update reboot). This action corresponds to= the + * internal %LIVEUPDATE_FINISH kernel event. Calling this ioctl triggers t= he + * cleanup phase: any resources that were successfully preserved but were = *not* + * subsequently restored (reclaimed) via the RESTORE ioctls will have their + * preserved state discarded and associated kernel resources released. Inv= olved + * devices may be reset. All desired restorations *must* be completed *bef= ore* + * this. Kernel callbacks for the %LIVEUPDATE_FINISH event must not fail. + * Successfully completing this phase transitions the system state from + * %LIVEUPDATE_STATE_UPDATED back to %LIVEUPDATE_STATE_NORMAL. This comman= d does + * not transfer data. + * + * Return: 0 on success, negative error code on failure. + */ +#define LIVEUPDATE_IOCTL_FINISH \ + _IO(LIVEUPDATE_IOCTL_TYPE, 0x07) + +#endif /* _UAPI_LIVEUPDATE_H */ diff --git a/kernel/liveupdate/Makefile b/kernel/liveupdate/Makefile index b5054140b9a9..cb3ea380f6b9 100644 --- a/kernel/liveupdate/Makefile +++ b/kernel/liveupdate/Makefile @@ -7,4 +7,5 @@ obj-$(CONFIG_KEXEC_HANDOVER) +=3D kexec_handover.o obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) +=3D kexec_handover_debug.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_core.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_files.o +obj-$(CONFIG_LIVEUPDATE) +=3D luo_ioctl.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_subsystems.o diff --git a/kernel/liveupdate/luo_ioctl.c b/kernel/liveupdate/luo_ioctl.c new file mode 100644 index 000000000000..3de1d243df5a --- /dev/null +++ b/kernel/liveupdate/luo_ioctl.c @@ -0,0 +1,178 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: LUO ioctl Interface + * + * The IOCTL user-space control interface for the LUO subsystem. + * It registers a misc character device, typically found at ``/dev/liveupd= ate``, + * which allows privileged userspace applications (requiring %CAP_SYS_ADMI= N) to + * manage and monitor the LUO state machine and associated resources like + * preservable file descriptors. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "luo_internal.h" + +static int luo_ioctl_fd_restore(struct liveupdate_fd *luo_fd) +{ + struct file *file; + int ret; + int fd; + + fd =3D get_unused_fd_flags(O_CLOEXEC); + if (fd < 0) { + pr_err("Failed to allocate new fd: %d\n", fd); + return fd; + } + + ret =3D luo_retrieve_file(luo_fd->token, &file); + if (ret < 0) { + put_unused_fd(fd); + + return ret; + } + + fd_install(fd, file); + luo_fd->fd =3D fd; + + return 0; +} + +static int luo_open(struct inode *inodep, struct file *filep) +{ + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (filep->f_flags & O_EXCL) + return -EINVAL; + + return 0; +} + +static long luo_ioctl(struct file *filep, unsigned int cmd, unsigned long = arg) +{ + void __user *argp =3D (void __user *)arg; + struct liveupdate_fd luo_fd; + enum liveupdate_state state; + int ret =3D 0; + u64 token; + + if (_IOC_TYPE(cmd) !=3D LIVEUPDATE_IOCTL_TYPE) + return -ENOTTY; + + switch (cmd) { + case LIVEUPDATE_IOCTL_GET_STATE: + state =3D liveupdate_get_state(); + if (copy_to_user(argp, &state, sizeof(state))) + ret =3D -EFAULT; + break; + + case LIVEUPDATE_IOCTL_PREPARE: + ret =3D luo_prepare(); + break; + + case LIVEUPDATE_IOCTL_FINISH: + ret =3D luo_finish(); + break; + + case LIVEUPDATE_IOCTL_CANCEL: + ret =3D luo_cancel(); + break; + + case LIVEUPDATE_IOCTL_FD_PRESERVE: + if (copy_from_user(&luo_fd, argp, sizeof(luo_fd))) { + ret =3D -EFAULT; + break; + } + + ret =3D luo_register_file(luo_fd.token, luo_fd.fd); + if (!ret && copy_to_user(argp, &luo_fd, sizeof(luo_fd))) { + WARN_ON_ONCE(luo_unregister_file(luo_fd.token)); + ret =3D -EFAULT; + } + break; + + case LIVEUPDATE_IOCTL_FD_UNPRESERVE: + if (copy_from_user(&token, argp, sizeof(u64))) { + ret =3D -EFAULT; + break; + } + + ret =3D luo_unregister_file(token); + break; + + case LIVEUPDATE_IOCTL_FD_RESTORE: + if (copy_from_user(&luo_fd, argp, sizeof(luo_fd))) { + ret =3D -EFAULT; + break; + } + + ret =3D luo_ioctl_fd_restore(&luo_fd); + if (!ret && copy_to_user(argp, &luo_fd, sizeof(luo_fd))) + ret =3D -EFAULT; + break; + + default: + pr_warn("ioctl: unknown command nr: 0x%x\n", _IOC_NR(cmd)); + ret =3D -ENOTTY; + break; + } + + return ret; +} + +static const struct file_operations fops =3D { + .owner =3D THIS_MODULE, + .open =3D luo_open, + .unlocked_ioctl =3D luo_ioctl, +}; + +static struct miscdevice liveupdate_miscdev =3D { + .minor =3D MISC_DYNAMIC_MINOR, + .name =3D "liveupdate", + .fops =3D &fops, +}; + +static int __init liveupdate_init(void) +{ + int err; + + if (!liveupdate_enabled()) + return 0; + + err =3D misc_register(&liveupdate_miscdev); + if (err < 0) { + pr_err("Failed to register misc device '%s': %d\n", + liveupdate_miscdev.name, err); + } + + return err; +} +module_init(liveupdate_init); + +static void __exit liveupdate_exit(void) +{ + misc_deregister(&liveupdate_miscdev); +} +module_exit(liveupdate_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Pasha Tatashin"); +MODULE_DESCRIPTION("Live Update Orchestrator"); +MODULE_VERSION("0.1"); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.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 A16182D97AA for ; Wed, 25 Jun 2025 23:19:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893557; cv=none; b=c+sis9QeEVdirgIXXzdtqPI5MUfqtKmYrSdMDTtqgaGjalJ7BWKYJf7OAuHfz3jJVFCjyiYQ7GWhTI2NRpl1xjgUS2oNSGEnT2zYNPO13F7kl1Ceksl0qiJJkc4a5C8wP2/pGtxALHZ2xdFm4kHClSIIXpIs+R8ZRMaN6RBp1Og= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893557; c=relaxed/simple; bh=4uXFzkhAgls9Xj902YoK9MVGibAbK+dj8dD8nmwNbG0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g4oSlNxWGmHcfJWZXbkKOcCWql3BM+0Y1dIet1PKd4B+++WPuQi68yctkfNmAoccLOop/MPxXGXvTNfHy0BziaAov2spxJ4LgkmClk2weshcyZVNNNxB0sQjgc+hKXUIFStykWXYo2kWqsUY6w9MfXAuRzRKbuqUwkSiQF2ROzw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=hhwTiWjz; arc=none smtp.client-ip=209.85.219.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="hhwTiWjz" Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-e8273504c67so357727276.0 for ; Wed, 25 Jun 2025 16:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893553; x=1751498353; 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=EGXsAiDVkMVJtKH71i02C+/FO8+/QxHPULS+B5odwkM=; b=hhwTiWjz1STlhRISpXaDJdkVzPzWDl0Z7G7dvdSEJT0BNTyANX1GJc8Hl05HpBK8Uc dp6kAesaI4kmdzVrbXaswBGEkgQ9hvp9U5sFE9HYUIQIFTqrMPmecQ0jxssswZ3PGTbI /mbSRWp29SfL2PkxISna113cQYqTPAAYygnY2D5Q1iGWoyAE4cPRlnjdWLhcgklEBjLf EG1BZwbVqLzz9nTpQaVrBWEe77iwzlH+F681rjYSt9KcYuPtMle7tLnD/zFhShKfYfx0 LCUeln0ONd1HEYxMuYLF8UX9zgB5ypOWhXpe5gTZ6RJz7uwWAGNKYaKDuvcUtItvVNPW AVBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893553; x=1751498353; 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=EGXsAiDVkMVJtKH71i02C+/FO8+/QxHPULS+B5odwkM=; b=nDtbyInlDSbrhc/kqYnL7GF980t+W1+G7J5tQ0XdOFM460AkQpIQfxlsrh8GCbt5ug 352gxvDxJ8HevSE9vOpdDsH6Ut+bkJvlb3MyMc0cqHZFw5O2IMEpTraAmQr7LrTi8QsO QWodQBmWz2yvJP1eNiRsWcTdVOfsqDk+qE773QpTkJC5hRP3UcWCcAI2InUFhZRK13zp DIwPNwBDXp83LNtz0o97spxAWK9s6c+yALjrg4QeB7HKwdmXMy/7lUF64VsJKwUPY+0X B1Evi/AEytgljnHJaq+gemzjgBEp8jvHHjTLWjwnhOudmHBLha2J1QcNpnmpCyXaUFXK 211Q== X-Forwarded-Encrypted: i=1; AJvYcCUpGGHOkUXQya5VpYs1YlFGbxRsIKaa3GKXz2ftYA+7OZ/C0VZl2V7L/Gy5Q6ksddWsKserl1CfLaGn0/M=@vger.kernel.org X-Gm-Message-State: AOJu0YxvgilNSZEMgGChN6YuUQ/3akmXS40Va/Y/y+UH/qU3Gn8yzE+L Rz1JFEGy3AtoJ72ifyrI6y7MJEbxCVd9pFQOVbFnzHzROrsB1JXFDbPKZkZBj03x+5k= X-Gm-Gg: ASbGncul8q9Mx5FkTP/ecG6dwc19DKeOD9tJquzMiQsVWK3/HB/8Ls+gwsGMp2PatQQ YP6II3IKcYp4V7nrP1Kxv77lUJ7YWPlbsYafA3sJWloZDA33YNizN+04hg+5HXG4qt9N4CCjPRA +IQDINjq4VXq/GfSDRPcRyKmL1kTImlYt1b9tWPu6hagnmpieK3HR3enx9UkkrP2I6jL8Gm9YJ1 layQYao1Rz/MnfwqquSJvv4c1nR6QDiWeNYQMFs/zgFCgYeB764W8WyWIY7iaECGlmviG2XDfEC iIp/BCIISLde2myrrCbBjFYIKL47i+05FafeiHEb5+YuE9jUUYjH6h1hxwZvAb4ql8KcwMM5MkR oQG8iZpoSBVZtryqu1ZxXStp4bSzYCZNjhlCTDHSr8g9t35JlSe9S X-Google-Smtp-Source: AGHT+IHdS1AStvuIn7CbxKX1ftelfPKYabeTwO6G58N8aQkbNpg+M43jhUkLMwJemZXj4yOKAfCWAg== X-Received: by 2002:a05:6902:114a:b0:e82:ff8:e6a1 with SMTP id 3f1490d57ef6-e86017a7afemr5969375276.2.1750893552587; Wed, 25 Jun 2025 16:19:12 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:12 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 17/32] liveupdate: luo_sysfs: add sysfs state monitoring Date: Wed, 25 Jun 2025 23:18:04 +0000 Message-ID: <20250625231838.1897085-18-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Introduce a sysfs interface for the Live Update Orchestrator under /sys/kernel/liveupdate/. This interface provides a way for userspace tools and scripts to monitor the current state of the LUO state machine. The main feature is a read-only file, state, which displays the current LUO state as a string ("normal", "prepared", "frozen", "updated"). The interface uses sysfs_notify to allow userspace listeners (e.g., via poll) to be efficiently notified of state changes. ABI documentation for this new sysfs interface is added in Documentation/ABI/testing/sysfs-kernel-liveupdate. This read-only sysfs interface complements the main ioctl interface provided by /dev/liveupdate, which handles LUO control operations and resource management. Signed-off-by: Pasha Tatashin --- .../ABI/testing/sysfs-kernel-liveupdate | 51 ++++++++++ kernel/liveupdate/Kconfig | 18 ++++ kernel/liveupdate/Makefile | 1 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_internal.h | 6 ++ kernel/liveupdate/luo_sysfs.c | 92 +++++++++++++++++++ 6 files changed, 169 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-kernel-liveupdate create mode 100644 kernel/liveupdate/luo_sysfs.c diff --git a/Documentation/ABI/testing/sysfs-kernel-liveupdate b/Documentat= ion/ABI/testing/sysfs-kernel-liveupdate new file mode 100644 index 000000000000..4cd4a4fe2f93 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-kernel-liveupdate @@ -0,0 +1,51 @@ +What: /sys/kernel/liveupdate/ +Date: May 2025 +KernelVersion: 6.16.0 +Contact: pasha.tatashin@soleen.com +Description: Directory containing interfaces to query the live + update orchestrator. Live update is the ability to reboot the + host kernel (e.g., via kexec, without a full power cycle) while + keeping specifically designated devices operational ("alive") + across the transition. After the new kernel boots, these devices + can be re-attached to their original workloads (e.g., virtual + machines) with their state preserved. This is particularly + useful, for example, for quick hypervisor updates without + terminating running virtual machines. + + +What: /sys/kernel/liveupdate/state +Date: May 2025 +KernelVersion: 6.16.0 +Contact: pasha.tatashin@soleen.com +Description: Read-only file that displays the current state of the live + update orchestrator as a string. Possible values are: + + "normal": No live update operation is in progress. This is + the default operational state. + + "prepared": The live update preparation phase has completed + successfully (e.g., triggered via the + /dev/liveupdate event). Kernel subsystems have + been notified via the %LIVEUPDATE_PREPARE + event/callback and should have initiated state + saving. User workloads (e.g., VMs) are generally + still running, but some operations (like device + unbinding or new DMA mappings) might be + restricted. The system is ready for the reboot + trigger. + + "frozen": The final reboot notification has been sent + (e.g., triggered via the 'reboot()' syscall), + corresponding to the %LIVEUPDATE_REBOOT kernel + event. Subsystems have had their final chance to + save state. User workloads must be suspended. + The system is about to execute the reboot into + the new kernel (imminent kexec). This state + corresponds to the "blackout window". + + "updated": The system has successfully rebooted into the + new kernel via live update. Restoration of + preserved resources can now occur (typically via + ioctl commands). The system is awaiting the + final 'finish' signal after user space completes + restoration tasks. diff --git a/kernel/liveupdate/Kconfig b/kernel/liveupdate/Kconfig index f6b0bde188d9..75a17ca8a592 100644 --- a/kernel/liveupdate/Kconfig +++ b/kernel/liveupdate/Kconfig @@ -29,6 +29,24 @@ config LIVEUPDATE =20 If unsure, say N. =20 +config LIVEUPDATE_SYSFS_API + bool "Live Update sysfs monitoring interface" + depends on SYSFS + depends on LIVEUPDATE + help + Enable a sysfs interface for the Live Update Orchestrator + at /sys/kernel/liveupdate/. + + This allows monitoring the LUO state ('normal', 'prepared', + 'frozen', 'updated') via the read-only 'state' file. + + This interface complements the primary /dev/liveupdate ioctl + interface, which handles the full update process. + This sysfs API may be useful for scripting, or userspace monitoring + needed to coordinate application restarts and minimize downtime. + + If unsure, say N. + config KEXEC_HANDOVER bool "kexec handover" depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE diff --git a/kernel/liveupdate/Makefile b/kernel/liveupdate/Makefile index cb3ea380f6b9..e35ddc51ab2b 100644 --- a/kernel/liveupdate/Makefile +++ b/kernel/liveupdate/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_LIVEUPDATE) +=3D luo_core.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_files.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_ioctl.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_subsystems.o +obj-$(CONFIG_LIVEUPDATE_SYSFS_API) +=3D luo_sysfs.o diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index fff84c51d986..41dbe784445e 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -100,6 +100,7 @@ static inline bool is_current_luo_state(enum liveupdate= _state expected_state) static void __luo_set_state(enum liveupdate_state state) { WRITE_ONCE(luo_state, state); + luo_sysfs_notify(); } =20 static inline void luo_set_state(enum liveupdate_state state) diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index f77e8b3044f9..05cd861ed2a8 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -29,4 +29,10 @@ int luo_retrieve_file(u64 token, struct file **filep); int luo_register_file(u64 token, int fd); int luo_unregister_file(u64 token); =20 +#ifdef CONFIG_LIVEUPDATE_SYSFS_API +void luo_sysfs_notify(void); +#else +static inline void luo_sysfs_notify(void) {} +#endif + #endif /* _LINUX_LUO_INTERNAL_H */ diff --git a/kernel/liveupdate/luo_sysfs.c b/kernel/liveupdate/luo_sysfs.c new file mode 100644 index 000000000000..935946bb741b --- /dev/null +++ b/kernel/liveupdate/luo_sysfs.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: LUO sysfs interface + * + * Provides a sysfs interface at ``/sys/kernel/liveupdate/`` for monitorin= g LUO + * state. Live update allows rebooting the kernel (via kexec) while prese= rving + * designated device state for attached workloads (e.g., VMs), useful for + * minimizing downtime during hypervisor updates. + * + * /sys/kernel/liveupdate/state + * ---------------------------- + * - Permissions: Read-only + * - Description: Displays the current LUO state string. + * - Valid States: + * @normal + * Idle state. + * @prepared + * Preparation phase complete (triggered via '/dev/liveupdate'). Res= ources + * checked, state saving initiated via %LIVEUPDATE_PREPARE event. + * Workloads mostly running but may be restricted. Ready forreboot + * trigger. + * @frozen + * Final reboot notification sent (triggered via 'reboot'). Correspo= nds to + * %LIVEUPDATE_REBOOT event. Final state saving. Workloads must be + * suspended. System about to kexec ("blackout window"). + * @updated + * New kernel booted via live update. Awaiting 'finish' signal. + * + * Userspace Interaction & Blackout Window Reduction + * ------------------------------------------------- + * Userspace monitors the ``state`` file to coordinate actions: + * - Suspend workloads before @frozen state is entered. + * - Initiate resource restoration upon entering @updated state. + * - Resume workloads after restoration, minimizing downtime. + */ + +#include +#include +#include +#include "luo_internal.h" + +static bool luo_sysfs_initialized; + +#define LUO_DIR_NAME "liveupdate" + +void luo_sysfs_notify(void) +{ + if (luo_sysfs_initialized) + sysfs_notify(kernel_kobj, LUO_DIR_NAME, "state"); +} + +/* Show the current live update state */ +static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *att= r, + char *buf) +{ + return sysfs_emit(buf, "%s\n", luo_current_state_str()); +} + +static struct kobj_attribute state_attribute =3D __ATTR_RO(state); + +static struct attribute *luo_attrs[] =3D { + &state_attribute.attr, + NULL +}; + +static struct attribute_group luo_attr_group =3D { + .attrs =3D luo_attrs, + .name =3D LUO_DIR_NAME, +}; + +static int __init luo_init(void) +{ + int ret; + + ret =3D sysfs_create_group(kernel_kobj, &luo_attr_group); + if (ret) { + pr_err("Failed to create group\n"); + return ret; + } + + luo_sysfs_initialized =3D true; + pr_info("Initialized\n"); + + return 0; +} +subsys_initcall(luo_init); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.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 766252FCE38 for ; Wed, 25 Jun 2025 23:19:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893557; cv=none; b=fWTZSWw/Ptt3g3PYlfPTRbf8FggCg9fD3pZ8csdre6aM2beFFi9u/PzIFwzMHmQ54kPLL/7mRh0Jfft8OUTxe9rYmHhTTiN4Keq9p0b2T4DCU7nTp+UWORMb+NkD+Pcw3F3KDDyswnxYG0irANUWDZ2Lt7Amcdu26uE80D+aRas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893557; c=relaxed/simple; bh=MeL5rpabCOQ9W64WCDzEoX0aCqKWSq3A09PvP5YRATc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gwstJGo5nic0vra750GDP4jcnBGnEWXGiPDiR283B/rV6Yv/Vty9hCeTjHOrjJJT4+G4THfNtA1QcYL9ruIQszZ6n+mWstYHx1SM66NArNmmVJqWtWl4MppHlP6BKlTI5c1J861hYxLAVSw+xhZiW73bwXlWH5OmPbUvVbQt5ZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=B1eRO5Hg; arc=none smtp.client-ip=209.85.219.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="B1eRO5Hg" Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-e73e9e18556so556528276.0 for ; Wed, 25 Jun 2025 16:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893554; x=1751498354; 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=+FWnE5Bow2uoaZcwISvBgq/4l5cKqkAoia4t69mDLc0=; b=B1eRO5HgatGq4rstuHwQb5lRLPCJUJPeYDwYtXoaXEQ6M2ydVeMdgP5sfHosPCqzX+ 826BuhtF/jpBSjO5u3Cd+iCrP6EZuAeF4wz4RAtfsPcJZDSHrbN0ug8kX514GEaI6IfH 1HTxR5Xakww2tpQn/usIrCPwX1y8c0DJzwCGf5kSvD93mJ3XzDwh+LBjP0HOw48/JdUY xOnYtcV+oCc+PEIUc7ZjHB1O/cr6DZCTCT+v6avxVYgKQPF3P1fHAREVroltDj+JPWcR Rrz2ol7e7zdDcJGEEJe1LKpcg/jZUsxt8owjNaN31J2PanxwMS43usRsTmUcBQFkLv3h i3gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893554; x=1751498354; 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=+FWnE5Bow2uoaZcwISvBgq/4l5cKqkAoia4t69mDLc0=; b=O4uP2MpdtbNg/QmJH8hzYKXRE/kVQD6vkPug63lAdbhCbC6vAXdtsOeLrwKMbNgVPe Sm1a7YfF+menw4Ddjk8gE+hJtG0ZGBb5eAV5CGRVVc6kzyBqqtmT5OdzANzmL1m28tql 1hDmY2AfzjNUwR9h0Sf6ULgGspkFOI3y2rC2mDssvRAwgwC3pYaxxRH9fxZ3L0Uq5KoQ JBOyt+YRvmQYkXa6Q1O+GITRnQE0P2vOg5N2IMzqRlGgnVNVRMtaubfr0YZAcCqUfhe4 iL9yL0m9gXgAUIoHe+AlCQdcbTJ6ZCsGVn62hupGPpyzjlwM7HUb6tO3CzzptSaw2LZ9 Rt2Q== X-Forwarded-Encrypted: i=1; AJvYcCU+tTN1m2L1nPQT3e6CDINbv4kFrebIC91DsBVX23/TKBBOlf4JUBCwwJNmDBnXpns0JpVncZrc1Y72FgE=@vger.kernel.org X-Gm-Message-State: AOJu0YzHWaYm5baGeEzsuOpuIciMSOrtckT3xcTw9GS/RWsgNzL3xTmh X9Duo4KZtalpOob6qpTiSvtjc1sOWZ9lrkxka7fqHx21qlTqM5HSu7FcacNkrFXF7GI= X-Gm-Gg: ASbGncsmRrVLTwrgpkqsn6qSvN8H3YXIQxsgjycsb0yEngn4NS0cwN1Q3f2Zu7wnqM9 lbIjxsUDoxo4ii3b983xh+CwoGTGLZV3zVgnqCcVp2bYKHhuYotJgbvHgba/6PAsooOql1Muou0 yCpGtxcWtgGfWkAFyxL4I3AYjZc+NyqWuPycSmpmuKWNvRwYwiVNx+pzjqlMOetnOZLNqv0SQkG Be6lM48P+20syzO5LpyKRutnFxZOujBlL0Qc0w2kmTMNti0sLz1bx3KNi+EpESjLSxju5Elxbxz tWS0WafIMx2P2wdGQXssnTTktRu9ZGLxkPQQ0/5EkjVd15uisRozV/OizzQDRHxQ2oTTaxxrNC9 qAI9e1JfpA+ZXbzF0xTlK9iRzWpKxoPPflBGNoz/uePD57LILbkHE X-Google-Smtp-Source: AGHT+IEYYs2N6RASXojR+QxIpPej80Rm+js0xnYmL5jy1Q+a192E7kIXIViEBMDkie7fGIqIBRd0Pg== X-Received: by 2002:a05:6902:138b:b0:e81:8305:b8d9 with SMTP id 3f1490d57ef6-e879c092ef1mr2020971276.1.1750893554316; Wed, 25 Jun 2025 16:19:14 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:13 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 18/32] reboot: call liveupdate_reboot() before kexec Date: Wed, 25 Jun 2025 23:18:05 +0000 Message-ID: <20250625231838.1897085-19-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Modify the reboot() syscall handler in kernel/reboot.c to call liveupdate_reboot() when processing the LINUX_REBOOT_CMD_KEXEC command. This ensures that the Live Update Orchestrator is notified just before the kernel executes the kexec jump. The liveupdate_reboot() function triggers the final LIVEUPDATE_FREEZE event, allowing participating subsystems to perform last-minute state saving within the blackout window, and transitions the LUO state machine to FROZEN. The call is placed immediately before kernel_kexec() to ensure LUO finalization happens at the latest possible moment before the kernel transition. If liveupdate_reboot() returns an error (indicating a failure during LUO finalization), the kexec operation is aborted to prevent proceeding with an inconsistent state. Signed-off-by: Pasha Tatashin --- kernel/reboot.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/reboot.c b/kernel/reboot.c index ec087827c85c..bdeb04a773db 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -797,6 +798,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsig= ned int, cmd, =20 #ifdef CONFIG_KEXEC_CORE case LINUX_REBOOT_CMD_KEXEC: + ret =3D liveupdate_reboot(); + if (ret) + break; ret =3D kernel_kexec(); break; #endif --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.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 28AA42DD602 for ; Wed, 25 Jun 2025 23:19:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893559; cv=none; b=euHrUS4funuvkCiUCQnAY1IZk7zpPzh34OLgB2UMqKCAxU6bkfiA7NaLpCEGMvbJnPisfQeKZSQN6zy9uw8GJcdxt0mZmYWHjmlUpHcfn2LNa8QqXzBnnY1d8uskRPHBDxIuGdYmhl7se0E+8PbC0f2UN9OPu3sYznZemDMw/t8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893559; c=relaxed/simple; bh=BYE6CFYNp+bC24GEWjI/kpdlZd1bkuK5lqVnOzx7zbo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rf381uceRPConplYlYgYbsd+rPRhuChq3NUq4wfltZbXjT2R0/WF8/2qHOzSyThqTAaFVjnhHhg9TmuyZwqxuEQAwXkcNt7C3PMm4ZJb9MEa25UtP5C5QS89+KIHTzAXicxWu0xpjtTRhA1ifIe06+dV0SgooHFFA4z7fYklxd8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=RW0rI+zM; arc=none smtp.client-ip=209.85.219.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="RW0rI+zM" Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-e7387d4a336so312827276.2 for ; Wed, 25 Jun 2025 16:19:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893556; x=1751498356; 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=+trs6zLLPmtqa3TLX7M9IRokbE5V0+8Th4y6mj0Kyj4=; b=RW0rI+zMbscmhAeWoghYePJVe0R6sOaspstF9Pse4tQDYGOn3GicaZ4V9fq37rEW7k JY6UmbNJ5Dv46YXzxrV7c6HrYz3bFqJdXbX6wcgFrqxvTfF8ec10zi4NfjzRdJy+zpyD 7fRzdUMyPecpA1rtMOeOxG4yscB0q0kcB3JlP9lyg7LzyrekJEdPbaKtA1RPsZ4oGLZ8 nfEjGRS6kkjraHdJklSIMpY3XNOGu4EQek+Vf/YwfBDZAp7FF7UFTiD+1fvkal1AJ1g2 ibrwBOv7kBRtlt4Ymkm8FzvGNonrcTzyWhHLefskUUCXULBiT47sDIUAaPanz09EbTCs W7kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893556; x=1751498356; 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=+trs6zLLPmtqa3TLX7M9IRokbE5V0+8Th4y6mj0Kyj4=; b=ERLQZ0cY2R1j5znh3wA1ctPmg42wh6y/lklfBP8j3+6hVE4uQpziRcqBeX/NwUjigz Z2dsPZNmPqnbG8+7lSBcZbRpyEyp4QD9QByKJ1kG4xm8bBg5MaN5J6uvym4Vf6iE8UbO o8+KxnrgW8JlwvShDrcrwObdmYinBcJQ4xIdcxVbcOQbkMy/LwI/bbFMzXGAZGBEYBjs OUkRjgY+PV76b1TXtj9pIemiUgwAq3cj58TPs5zF7B2M+0te/wsUDxDwu6Q+eB2LI5Af hQaWp3c8wa+3SdrScoFTd1DgDyZzbHIzNWNyKmStYEonP5iA3fmVN2iC7YqRSF+Gyce/ psSA== X-Forwarded-Encrypted: i=1; AJvYcCXtWPiINlUjcREmhRFHnuV+MWtL6ssg6EO2ReUK8am7hHshk/TAPc89JQVpigquO3rogo0dr27EKUCUsbE=@vger.kernel.org X-Gm-Message-State: AOJu0Yzs4IxgLsFsvTO2mXElutIXUD6MRk4zHWTLNVY7ZoHl4giZMF6V 5G6hJ/HLPEuC89XOAaT6GANdxzQSq4HZ6V9c8a3kdT6PNpEWDV/ZIPnTcFhKKwDmVTA= X-Gm-Gg: ASbGncsc60s8ZA59V46+eEWN25UBkJytJ+HgZNAVLljKv2HgKx/16bBXPBl+4MPn9Vg swVEvvkSNlZ//+StpvZg98pTYm0d8bTIjLUO9AHtGDi6lEnwkWfJvYVzlOpZZ4yPdkSz42dz3D1 4vlTlV1jlUkIe5o6EsQYTnVbbdCmCjkOgjQf/Na+VEyYus8xJTTNK14sh457wP3MCS0LTK6faxY RkB0K+B+fISEkdKlONX7360ySV0LH5oneIqn46c8raslqxftiJWdhiaIYQvM+5wOFFxmhAq0klO 9Panl9HB2O06nYbvvDxySw6lNr5VVOs3XXlA3HOF8a+uZyPyNn6GP8fgGEkiU4rJ8up+8taW8i2 414GfCYQPSkCbmogCVufXKy24nC/GdcYUIOSpRESH61k4LaVdNAe9 X-Google-Smtp-Source: AGHT+IH/3Me+d0MJXQ76VamD4M41LLWG4p+AbovI1Fc939AypUIUrA9tKZEx4Bpr6+xiqohW1hf6SQ== X-Received: by 2002:a05:6902:1246:b0:e81:cab6:6db5 with SMTP id 3f1490d57ef6-e86016cfbebmr6754388276.8.1750893556113; Wed, 25 Jun 2025 16:19:16 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:15 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 19/32] liveupdate: luo_files: luo_ioctl: session-based file descriptor tracking Date: Wed, 25 Jun 2025 23:18:06 +0000 Message-ID: <20250625231838.1897085-20-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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, file descriptors registered for preservation via /dev/liveupdate remain globally registered with the LUO core until explicitly unregistered. This behavior can lead to unintended consequences: if a userspace process (e.g., a VMM or an agent managing FDs) registers FDs for preservation and then crashes or exits prematurely before LUO transitions to a PREPARED state (and without explicitly unregistering them), these FDs would remain marked for preservation. This could result in unnecessary resources being carried over to the next kernel or stale state or leaks. Introduce a session-based approach to FD preservation to address this issue. Each open instance of /dev/liveupdate now corresponds to a "LUO session," which tracks the FDs registered through it. If a LUO session is closed (i.e., the file descriptor for /dev/liveupdate is closed by userspace) while LUO is still in the NORMAL or UPDATED state, all FDs registered during that specific session are automatically unregistered. This ensures that FD preservations are tied to the lifetime of the controlling userspace entity's session, preventing unintentional leakage of preserved FD state into the next kernel if the live update process is not fully initiated and completed for those FDs. FDs are only globally committed for preservation if the LUO state machine progresses beyond NORMAL (i.e., into PREPARED or FROZEN) before the managing session is closed. In the future, we can relax this even further, and preserve only when the session is still open while we are already in reboot() system call. Signed-off-by: Pasha Tatashin --- kernel/liveupdate/luo_files.c | 225 ++++++++++++++++++++++++------- kernel/liveupdate/luo_internal.h | 9 +- kernel/liveupdate/luo_ioctl.c | 20 ++- 3 files changed, 197 insertions(+), 57 deletions(-) diff --git a/kernel/liveupdate/luo_files.c b/kernel/liveupdate/luo_files.c index cd956ea69f43..256b5261f81e 100644 --- a/kernel/liveupdate/luo_files.c +++ b/kernel/liveupdate/luo_files.c @@ -67,7 +67,6 @@ #define LUO_FILES_COMPATIBLE "file-descriptors-v1" =20 static DEFINE_XARRAY(luo_files_xa_in); -static DEFINE_XARRAY(luo_files_xa_out); static bool luo_files_xa_in_recreated; =20 /* Registered files. */ @@ -81,6 +80,15 @@ static size_t luo_file_fdt_out_size; =20 static atomic64_t luo_files_count; =20 +/* Opened sessions */ +static DECLARE_RWSEM(luo_sessions_list_rwsem); +static LIST_HEAD(luo_sessions_list); + +struct luo_session { + struct xarray files_xa_out; + struct list_head list; +}; + /** * struct luo_file - Represents a file descriptor instance preserved * across live update. @@ -262,6 +270,7 @@ static int luo_files_to_fdt(struct xarray *files_xa_out) =20 static int luo_files_fdt_setup(void) { + struct luo_session *s; int ret; =20 luo_file_fdt_out_size =3D luo_files_fdt_size(); @@ -300,9 +309,15 @@ static int luo_files_fdt_setup(void) if (ret < 0) goto exit_end_node; =20 - ret =3D luo_files_to_fdt(&luo_files_xa_out); - if (ret < 0) - goto exit_end_node; + down_read(&luo_sessions_list_rwsem); + list_for_each_entry(s, &luo_sessions_list, list) { + ret =3D luo_files_to_fdt(&s->files_xa_out); + if (ret < 0) { + up_read(&luo_sessions_list_rwsem); + goto exit_end_node; + } + } + up_read(&luo_sessions_list_rwsem); =20 ret =3D fdt_end_node(luo_file_fdt_out); if (ret < 0) @@ -405,44 +420,59 @@ static void luo_files_cancel_one(struct luo_file *h) =20 static void __luo_files_cancel(struct luo_file *boundary_file) { + struct luo_session *s; unsigned long token; struct luo_file *h; =20 - xa_for_each(&luo_files_xa_out, token, h) { - if (h =3D=3D boundary_file) - break; + down_read(&luo_sessions_list_rwsem); + list_for_each_entry(s, &luo_sessions_list, list) { + xa_for_each(&s->files_xa_out, token, h) { + if (h =3D=3D boundary_file) + goto exit; =20 - luo_files_cancel_one(h); + luo_files_cancel_one(h); + } } +exit: + up_read(&luo_sessions_list_rwsem); luo_files_fdt_cleanup(); } =20 static int luo_files_commit_data_to_fdt(void) { + struct luo_session *s; int node_offset, ret; unsigned long token; char token_str[19]; struct luo_file *h; =20 - xa_for_each(&luo_files_xa_out, token, h) { - snprintf(token_str, sizeof(token_str), "%#0llx", (u64)token); - node_offset =3D fdt_subnode_offset(luo_file_fdt_out, - 0, - token_str); - ret =3D fdt_setprop(luo_file_fdt_out, node_offset, "data", - &h->private_data, sizeof(h->private_data)); - if (ret < 0) { - pr_err("Failed to set data property for token %s: %s\n", - token_str, fdt_strerror(ret)); - return -ENOSPC; + down_read(&luo_sessions_list_rwsem); + list_for_each_entry(s, &luo_sessions_list, list) { + xa_for_each(&s->files_xa_out, token, h) { + snprintf(token_str, sizeof(token_str), "%#0llx", + (u64)token); + node_offset =3D fdt_subnode_offset(luo_file_fdt_out, + 0, token_str); + ret =3D fdt_setprop(luo_file_fdt_out, node_offset, "data", + &h->private_data, + sizeof(h->private_data)); + if (ret < 0) { + up_read(&luo_sessions_list_rwsem); + pr_err("Failed to set data property for token %s: %s\n", + token_str, fdt_strerror(ret)); + up_read(&luo_sessions_list_rwsem); + return -ENOSPC; + } } } + up_read(&luo_sessions_list_rwsem); =20 return 0; } =20 static int luo_files_prepare(void *arg, u64 *data) { + struct luo_session *s; unsigned long token; struct luo_file *h; int ret; @@ -451,16 +481,21 @@ static int luo_files_prepare(void *arg, u64 *data) if (ret) return ret; =20 - xa_for_each(&luo_files_xa_out, token, h) { - ret =3D luo_files_prepare_one(h); - if (ret < 0) { - pr_err("Prepare failed for file token %#0llx handler '%s' [%d]\n", - (u64)token, h->fh->compatible, ret); - __luo_files_cancel(h); - - return ret; + down_read(&luo_sessions_list_rwsem); + list_for_each_entry(s, &luo_sessions_list, list) { + xa_for_each(&s->files_xa_out, token, h) { + ret =3D luo_files_prepare_one(h); + if (ret < 0) { + pr_err("Prepare failed for file token %#0llx handler '%s' [%d]\n", + (u64)token, h->fh->compatible, ret); + __luo_files_cancel(h); + up_read(&luo_sessions_list_rwsem); + + return ret; + } } } + up_read(&luo_sessions_list_rwsem); =20 ret =3D luo_files_commit_data_to_fdt(); if (ret) @@ -473,20 +508,26 @@ static int luo_files_prepare(void *arg, u64 *data) =20 static int luo_files_freeze(void *arg, u64 *data) { + struct luo_session *s; unsigned long token; struct luo_file *h; int ret; =20 - xa_for_each(&luo_files_xa_out, token, h) { - ret =3D luo_files_freeze_one(h); - if (ret < 0) { - pr_err("Freeze callback failed for file token %#0llx handler '%s' [%d]\= n", - (u64)token, h->fh->compatible, ret); - __luo_files_cancel(h); - - return ret; + down_read(&luo_sessions_list_rwsem); + list_for_each_entry(s, &luo_sessions_list, list) { + xa_for_each(&s->files_xa_out, token, h) { + ret =3D luo_files_freeze_one(h); + if (ret < 0) { + pr_err("Freeze callback failed for file token %#0llx handler '%s' [%d]= \n", + (u64)token, h->fh->compatible, ret); + __luo_files_cancel(h); + up_read(&luo_sessions_list_rwsem); + + return ret; + } } } + up_read(&luo_sessions_list_rwsem); =20 ret =3D luo_files_commit_data_to_fdt(); if (ret) @@ -561,6 +602,7 @@ late_initcall(luo_files_startup); =20 /** * luo_register_file - Register a file descriptor for live update manageme= nt. + * @s: Session for the file that is being registered * @token: Token value for this file descriptor. * @fd: file descriptor to be preserved. * @@ -568,10 +610,11 @@ late_initcall(luo_files_startup); * * Return: 0 on success. Negative errno on failure. */ -int luo_register_file(u64 token, int fd) +int luo_register_file(struct luo_session *s, u64 token, int fd) { struct liveupdate_file_handler *fh; struct luo_file *luo_file; + struct luo_session *_s; bool found =3D false; int ret =3D -ENOENT; struct file *file; @@ -615,15 +658,20 @@ int luo_register_file(u64 token, int fd) mutex_init(&luo_file->mutex); luo_file->state =3D LIVEUPDATE_STATE_NORMAL; =20 - if (xa_load(&luo_files_xa_out, token)) { - ret =3D -EEXIST; - pr_warn("Token %llu is already taken\n", token); - mutex_destroy(&luo_file->mutex); - kfree(luo_file); - goto exit_unlock; + down_read(&luo_sessions_list_rwsem); + list_for_each_entry(_s, &luo_sessions_list, list) { + if (xa_load(&_s->files_xa_out, token)) { + up_read(&luo_sessions_list_rwsem); + ret =3D -EEXIST; + pr_warn("Token %llu is already taken\n", token); + mutex_destroy(&luo_file->mutex); + kfree(luo_file); + goto exit_unlock; + } } + up_read(&luo_sessions_list_rwsem); =20 - ret =3D xa_err(xa_store(&luo_files_xa_out, token, luo_file, + ret =3D xa_err(xa_store(&s->files_xa_out, token, luo_file, GFP_KERNEL)); if (ret < 0) { pr_warn("Failed to store file for token %llu in XArray: %d\n", @@ -646,6 +694,7 @@ int luo_register_file(u64 token, int fd) =20 /** * luo_unregister_file - Unregister a file instance using its token. + * @s: Session for the file that is being registered. * @token: The unique token of the file instance to unregister. * * Finds the &struct luo_file associated with the @token in the @@ -659,7 +708,7 @@ int luo_register_file(u64 token, int fd) * * Return: 0 on success. Negative errno on failure. */ -int luo_unregister_file(u64 token) +int luo_unregister_file(struct luo_session *s, u64 token) { struct luo_file *luo_file; int ret =3D 0; @@ -671,7 +720,7 @@ int luo_unregister_file(u64 token) return -EBUSY; } =20 - luo_file =3D xa_erase(&luo_files_xa_out, token); + luo_file =3D xa_erase(&s->files_xa_out, token); if (luo_file) { fput(luo_file->file); mutex_destroy(&luo_file->mutex); @@ -736,6 +785,74 @@ int luo_retrieve_file(u64 token, struct file **filep) return ret; } =20 +/** + * luo_create_session - Create and register a new LUO file preservation se= ssion. + * + * This function is called when a userspace process opens the /dev/liveupd= ate + * character device. + * + * Each session allows a specific open instance of /dev/liveupdate to + * independently register file descriptors for preservation. These registr= ations + * are local to the session until LUO's prepare phase aggregates them. + * If the /dev/liveupdate file descriptor is closed while LUO is still in + * the NORMAL or UPDATES states, all file descriptors registered within th= at + * session will be automatically unregistered by luo_destroy_session(). + * + * Return: Pointer to the newly allocated &struct luo_session on success, + * NULL on memory allocation failure. + */ +struct luo_session *luo_create_session(void) +{ + struct luo_session *s; + + s =3D kmalloc(sizeof(struct luo_session), GFP_KERNEL); + if (s) { + xa_init(&s->files_xa_out); + INIT_LIST_HEAD(&s->list); + + down_write(&luo_sessions_list_rwsem); + list_add_tail(&s->list, &luo_sessions_list); + up_write(&luo_sessions_list_rwsem); + } + + return s; +} + +/** + * luo_destroy_session - Release a LUO file preservation session. + * @s: Pointer to the &struct luo_session to be destroyed, previously obta= ined + * from luo_create_session(). + * + * This function must be called when a userspace file descriptor for + * /dev/liveupdate is being closed (typically from the .release file + * operation). It is responsible for cleaning up all resources associated + * with the given LUO session @s. + */ +void luo_destroy_session(struct luo_session *s) +{ + unsigned long token; + struct luo_file *h; + + down_write(&luo_sessions_list_rwsem); + list_del(&s->list); + up_write(&luo_sessions_list_rwsem); + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + luo_state_read_exit(); + goto skip_unregister; + } + + xa_for_each(&s->files_xa_out, token, h) + luo_unregister_file(s, token); + + luo_state_read_exit(); + +skip_unregister: + xa_destroy(&s->files_xa_out); + kfree(s); +} + /** * liveupdate_register_file_handler - Register a file handler with LUO. * @fh: Pointer to a caller-allocated &struct liveupdate_file_handler. @@ -796,6 +913,7 @@ EXPORT_SYMBOL_GPL(liveupdate_register_file_handler); */ int liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh) { + struct luo_session *s; unsigned long token; struct luo_file *h; int ret =3D 0; @@ -807,15 +925,18 @@ int liveupdate_unregister_file_handler(struct liveupd= ate_file_handler *fh) } =20 down_write(&luo_register_file_list_rwsem); - - xa_for_each(&luo_files_xa_out, token, h) { - if (h->fh =3D=3D fh) { - up_write(&luo_register_file_list_rwsem); - luo_state_read_exit(); - return -EBUSY; + down_read(&luo_sessions_list_rwsem); + list_for_each_entry(s, &luo_sessions_list, list) { + xa_for_each(&s->files_xa_out, token, h) { + if (h->fh =3D=3D fh) { + up_read(&luo_sessions_list_rwsem); + up_write(&luo_register_file_list_rwsem); + luo_state_read_exit(); + return -EBUSY; + } } } - + up_read(&luo_sessions_list_rwsem); list_del_init(&fh->list); up_write(&luo_register_file_list_rwsem); luo_state_read_exit(); diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index 05cd861ed2a8..8fef414e7e3e 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -25,9 +25,14 @@ int luo_do_subsystems_freeze_calls(void); void luo_do_subsystems_finish_calls(void); void luo_do_subsystems_cancel_calls(void); =20 +struct luo_session; + int luo_retrieve_file(u64 token, struct file **filep); -int luo_register_file(u64 token, int fd); -int luo_unregister_file(u64 token); +int luo_register_file(struct luo_session *s, u64 token, int fd); +int luo_unregister_file(struct luo_session *s, u64 token); + +struct luo_session *luo_create_session(void); +void luo_destroy_session(struct luo_session *s); =20 #ifdef CONFIG_LIVEUPDATE_SYSFS_API void luo_sysfs_notify(void); diff --git a/kernel/liveupdate/luo_ioctl.c b/kernel/liveupdate/luo_ioctl.c index 3de1d243df5a..d2c49cf33dd3 100644 --- a/kernel/liveupdate/luo_ioctl.c +++ b/kernel/liveupdate/luo_ioctl.c @@ -62,6 +62,17 @@ static int luo_open(struct inode *inodep, struct file *f= ilep) if (filep->f_flags & O_EXCL) return -EINVAL; =20 + filep->private_data =3D luo_create_session(); + if (!filep->private_data) + return -ENOMEM; + + return 0; +} + +static int luo_release(struct inode *inodep, struct file *filep) +{ + luo_destroy_session(filep->private_data); + return 0; } =20 @@ -101,9 +112,11 @@ static long luo_ioctl(struct file *filep, unsigned int= cmd, unsigned long arg) break; } =20 - ret =3D luo_register_file(luo_fd.token, luo_fd.fd); + ret =3D luo_register_file(filep->private_data, luo_fd.token, + luo_fd.fd); if (!ret && copy_to_user(argp, &luo_fd, sizeof(luo_fd))) { - WARN_ON_ONCE(luo_unregister_file(luo_fd.token)); + WARN_ON_ONCE(luo_unregister_file(filep->private_data, + luo_fd.token)); ret =3D -EFAULT; } break; @@ -114,7 +127,7 @@ static long luo_ioctl(struct file *filep, unsigned int = cmd, unsigned long arg) break; } =20 - ret =3D luo_unregister_file(token); + ret =3D luo_unregister_file(filep->private_data, token); break; =20 case LIVEUPDATE_IOCTL_FD_RESTORE: @@ -140,6 +153,7 @@ static long luo_ioctl(struct file *filep, unsigned int = cmd, unsigned long arg) static const struct file_operations fops =3D { .owner =3D THIS_MODULE, .open =3D luo_open, + .release =3D luo_release, .unlocked_ioctl =3D luo_ioctl, }; =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (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 D53EB2E1C41 for ; Wed, 25 Jun 2025 23:19:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893560; cv=none; b=Z+AX38MwqKFeaoaB4xkl8qrSRSEdkQNf/kMk4JUpyRsajUifE6zqVC875pd6bVUjfM6Wm1guew30CqZU93ITukFLQX4Uk2rH6azNIii2s2BQmwJ837UNKZUwjD+OB2VvS6hXlCdp/iguBew7qpoBGjw2mBmibB/DyDQwwcB+nQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893560; c=relaxed/simple; bh=0K/tRVmbaZ0VX6fH8M8cdhr3USMmOz4iPh58HsL+dDs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QyzOM3PaLTI/2URjfWhB4QJLIsV3rRghZyYYyL8u1YBri6mxwl184oQvFPDh/rpl4UcSOfLmaXcbwsLrgz+n/D+6z1Q7kvdDRNh4RDHti1Hxg/67402CbK0AHCEa4hxg9+XPXRD/Re82XbBKoH3r//RaQd89Fo68I099SPhKvro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=fZcXEyXH; arc=none smtp.client-ip=209.85.128.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="fZcXEyXH" Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-70e4b1acf41so3714097b3.3 for ; Wed, 25 Jun 2025 16:19:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893558; x=1751498358; 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=/ZJDnzlkjFdal2Rjq5d+u9z1RQAbXbOPFvsyuVPVQrw=; b=fZcXEyXHF9NuvYm8Whls0JQk1JDl8m27PgnvY39aUbeV1Euuq9WgtTgh/xHZLi//YI BTaACvoBu5k510wQinRTpKUvGIIavm0n1sF1qxpz2c6delQeR6D5+fEoacCdF9bF570a xdIQ+RiSkCeTmcTZVapDE4eJptI3OLfLlf9sINNuYP8EeoR4+DN+i7lQOHu+eM0kFG36 hZiTLNjYhdgIuqOQtQakDtOzQ8MC3pfCK+EgXumz98J8VrRo+cpBTWcsU7cL1Ot5LpW+ GgWqy0q3zg1l8H8HIGy5PfBcgllc17jXLogviZhhNkswaIKuImunvyLFCdhbd3umzyX2 iOMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893558; x=1751498358; 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=/ZJDnzlkjFdal2Rjq5d+u9z1RQAbXbOPFvsyuVPVQrw=; b=w8bAmQ2RKxVqPutUCAdScBAR/tvP6co5PWtXzWlHllerhVJxYsnpkc9NJRbsnd0bNf 7RHhDATm+h2lQYkrs/FzVDKw/cRRvMCZonpzphFvstNDADslvqfPPoT4qj6d5WFLgA2i TOP7vO7mFhumKt8HrZEnnZYunZMY2mf9dbrjKZELUM1ltGHMTfdryBYl+k6s60tfgRrl sCXEKZkSRUMsNXYE+VxmEnrGWCNK1Y7L0P0oUzzXhCr6JagX33rCcMeRFpB5234zbBQF XUslkFRkXAl04lbr7MOuoT6Wi4tHkRF/KmdndjPkB9ezR4iJnqJZzaA7ZwqsVLqhwk3R Eflw== X-Forwarded-Encrypted: i=1; AJvYcCUB8noz9D3YGoTGjdlzcYe7ErBVjai8gcOrY9ZHDjeKRUleBc8F/GITS+Z+G/Js+uXNJB/p21nsXBirsxk=@vger.kernel.org X-Gm-Message-State: AOJu0YzVP5FiuRfLCS5f/XYMSh18DOJVtKrzDNXzmC0rK9ZuPF4fTMbm CxWHCRu76u3wFSh7W8eaMKsGOQStMLNz99ZWeZLKN7XgCB8SQHZv3GIlBp8onQk6TzI= X-Gm-Gg: ASbGncuuq8vFLCvP/XYVO56v+VYDnx2haRLG76jHYviluoympwvBD3/1QVS1lS4kQ+u E7RI0jyAd0VHbjar/6tO6dKHLGzAoLPeUpPwoBMpwpDLebWP+38hrXat4iUPMQZxAuKQzhsisK4 /6HcbbE8RMItuX0DVI/upFbKC1dqaXkEYku2wcK5kS93wuR1ykmUT8ZTQRmEMxpxYap5LSWw+gI Z5zbi/XUjmFenmbKyxHlTNtbjRPOUpML2YoC0yt2UCtLNLNwsx9y+VrNIvwTDjPmvh2hhog0rx4 tq9b949o9OB1C+1uVkvtkzFKwGpx9MfMcZ5EOUhdKcV9xle1pnufYScZ4xUroDOy+sw1ZwcSk1v S90otM1JIA0xceW5W2hxdh8duka579SES0i7j+lRwwxi4l0EbQMrb X-Google-Smtp-Source: AGHT+IEy6gDp+TLxoQz7i8XJK92N1YqMToyOrPaa/RNISf+e+ji+erXXV1um4VBOajJ98t+L3IMAZw== X-Received: by 2002:a05:690c:6089:b0:70e:1474:63f2 with SMTP id 00721157ae682-71406c7cfb8mr66969267b3.7.1750893557847; Wed, 25 Jun 2025 16:19:17 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:17 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 20/32] kho: move kho debugfs directory to liveupdate Date: Wed, 25 Jun 2025 23:18:07 +0000 Message-ID: <20250625231838.1897085-21-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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 LUO selftests could use it as well. Signed-off-by: Pasha Tatashin --- kernel/liveupdate/kexec_handover_debug.c | 11 ++++++----- kernel/liveupdate/luo_internal.h | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/kernel/liveupdate/kexec_handover_debug.c b/kernel/liveupdate/k= exec_handover_debug.c index af4bad225630..f06d6cdfeab3 100644 --- a/kernel/liveupdate/kexec_handover_debug.c +++ b/kernel/liveupdate/kexec_handover_debug.c @@ -14,8 +14,9 @@ #include #include #include "kexec_handover_internal.h" +#include "luo_internal.h" =20 -static struct dentry *debugfs_root; +struct dentry *liveupdate_debugfs_root; =20 struct fdt_debugfs { struct list_head list; @@ -120,7 +121,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("in", liveupdate_debugfs_root); if (IS_ERR(dir)) { err =3D PTR_ERR(dir); goto err_out; @@ -180,7 +181,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("out", liveupdate_debugfs_root); if (IS_ERR(dir)) return -ENOMEM; =20 @@ -214,8 +215,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/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index 8fef414e7e3e..fbb9c6642d19 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -40,4 +40,8 @@ void luo_sysfs_notify(void); static inline void luo_sysfs_notify(void) {} #endif =20 +#ifdef CONFIG_KEXEC_HANDOVER_DEBUG +extern struct dentry *liveupdate_debugfs_root; +#endif + #endif /* _LINUX_LUO_INTERNAL_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) (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 0335B2E1C7B for ; Wed, 25 Jun 2025 23:19:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893563; cv=none; b=jE0bnFrQjCTArWZYzJSI9W4xnTQDCQ+fm+j7+gJhnpBUX0VmtRs+W2/bT6rEzPITtjNOmEI2tCgIeS3Pnxof9/d87MlCMGN3kzuKI/3Fj+tZ4Mjop43GISHWMUk7BQiATo0+h2EbEQ7SgnTRRTAnuDPign5e6xa6eAWbRGffhjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893563; c=relaxed/simple; bh=1ZdCFquQkyRNueWxeU6SeROx6wUdyomulb4+TybeFt8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A4H0ZPjUEBdimClzlSuRil8yPRxblQjLhyZoexT/E5cIZ/4QHRGsej/ajGS0V83OvlomgC0y6QcRnQyYfHOb1u4DzvlNmQXXKPRuiPLlkHYTdgykAKpKB95qdApRkfFkgIcnH6l63qlxrTSojXdczlMNu8J9GpXE21JU6xHoR4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=yUccnlmz; arc=none smtp.client-ip=209.85.219.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="yUccnlmz" Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e73e9e18556so556597276.0 for ; Wed, 25 Jun 2025 16:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893560; x=1751498360; 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=4jfla5x7ckr8CkKy2mLCVoSzWi+LYEZztBrXOX1KMjs=; b=yUccnlmz8urkKJ5d/5Z5BiiZywy9J7XciQFXi5/VLdufe4yBEre+wi9/u8Z4s87sjx d+fbZYLWaB2ftBQo8MbxVz3zqqFiixKvYeDw7maBxNaHOKhX4VWh6eLGCvdgSZgQNw7o /H4Uww8VP5aJD6u25jodtMNa0GH5iYcbMyQbtfcnvnL2P/UGGw8foJ/9UbRTmCsy5q8b XS96qarRJUg4CvLzreh7Z3j6tQLKu1wg7GNjnvhh4BW5NiaReun/HphonOlmHnL1bzoJ vxcz8vlAz4TiSj9ohlvKM5Eczah0qXrqlNW4RImHrb2CAP1cMCrdf7ozlDDiSmBILhkh t8bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893560; x=1751498360; 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=4jfla5x7ckr8CkKy2mLCVoSzWi+LYEZztBrXOX1KMjs=; b=JpDz4vID6kyiyy/mTGpj0rrCCqWppqYE1p7nX6+rw4Hpk+awhpqrS2VRtrml+acd70 m2/qM6PPI7wF0YAgDdeEN4fJMNyf8oJgCPmEfe031jpQYdgnbQE3M1SwSgo3fLslAM/y 5CegqJC6bd2edOXpLPWybWU7z+fzBToftJPDgvAxG4bRNtM6+IEOyZf4C4BXaaaNQ4qu HlG6hDnbCVx8cmINifR7Z5cj8iVHv4F39WwKE58UIWEjSxL5t1fjLQNzvypISWtLc/qD ietC0YTLfFZ8PiAuA/Ykv1C7agBQwBylGwM4yuMpz09LbkcxDdWY5ez788J2AkKt9sK0 ADhA== X-Forwarded-Encrypted: i=1; AJvYcCWPaM2KSAnqVQDlU9ir0uIK34viXfe7ireD+HiUmpoX7sw7m3d6nrVy6+38g+pr4tGRWRedvz/mvu3g7kA=@vger.kernel.org X-Gm-Message-State: AOJu0Yzyr2iEWJa8cGsyz8eFVOSwRJBCRUefo8JHMQ/e0aFM7z7yMbXn puY6amXh9LFZQpo4Jg7X4dudUhGxt2DWY/UUA3OVR+4G05Vqw0yEcCaW4K70eoApJ8A= X-Gm-Gg: ASbGnctA4raQY8wzPPdMmooc+Dl73KBiWimLgJ22ylUrX3uFVv63GW/Tc5y6z64xJ9E Xo1O1/zSeX/JLM3uVAC6/RV1F7nNNXilZuO+fbmHVSUSy5PsSOPk4ESSzxvV4lZilRopRa/3dt4 nAr98eVDfQ3N3A+tvGY5yHIrf5KdbdzJ1SRpW4pJOmLsvxrT5hhIVb4W9BN6LFV81VyRYkM2pf5 QEUjg38tRdK64dpEEv0kT7FXzhaBfJi6vthpbVFY9Txiz/lPOWLudLoxa54SHCsigZHiOYeTq3D U7RUuuiycQeVcV32zFoSREi93iTwp+js4UNx8c/YS29kXknUdWchii8qp6o/A2h+dvv5rZG6ZdK tWmePIDkuu3V/63j/0wxfG/7IjS2o5Qqkor1x+wB5mAozO+w8xFonl4MoDVmhYTE= X-Google-Smtp-Source: AGHT+IHiH1K8Mgn3xvyvtDaRl7AscFVVK9rMnROwu3GAljZCWizZs76GVeq0z0Bx1QUxo2AdTfpsXQ== X-Received: by 2002:a05:6902:1690:b0:e81:87e9:ebd3 with SMTP id 3f1490d57ef6-e879c28c4a3mr2101773276.20.1750893559639; Wed, 25 Jun 2025 16:19:19 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:19 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 21/32] liveupdate: add selftests for subsystems un/registration Date: Wed, 25 Jun 2025 23:18:08 +0000 Message-ID: <20250625231838.1897085-22-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Introduce a self-test mechanism for the LUO to allow verification of core subsystem management functionality. This is primarily intended for developers and system integrators validating the live update feature. The tests are enabled via the new Kconfig option CONFIG_LIVEUPDATE_SELFTESTS (default 'n') and are triggered through a new ioctl command, LIVEUPDATE_IOCTL_SELFTESTS, added to the /dev/liveupdate device node. This ioctl accepts commands defined in luo_selftests.h to: - LUO_CMD_SUBSYSTEM_REGISTER: Creates and registers a dummy LUO subsystem using the liveupdate_register_subsystem() function. It allocates a data page and copies initial data from userspace. - LUO_CMD_SUBSYSTEM_UNREGISTER: Unregisters the specified dummy subsystem using the liveupdate_unregister_subsystem() function and cleans up associated test resources. - LUO_CMD_SUBSYSTEM_GETDATA: Copies the data page associated with a registered test subsystem back to userspace, allowing verification of data potentially modified or preserved by test callbacks. This provides a way to test the fundamental registration and unregistration flows within the LUO framework from userspace without requiring a full live update sequence. Signed-off-by: Pasha Tatashin --- kernel/liveupdate/Kconfig | 15 ++ kernel/liveupdate/Makefile | 1 + kernel/liveupdate/luo_selftests.c | 344 ++++++++++++++++++++++++++++++ kernel/liveupdate/luo_selftests.h | 84 ++++++++ 4 files changed, 444 insertions(+) create mode 100644 kernel/liveupdate/luo_selftests.c create mode 100644 kernel/liveupdate/luo_selftests.h diff --git a/kernel/liveupdate/Kconfig b/kernel/liveupdate/Kconfig index 75a17ca8a592..db7bbff3edec 100644 --- a/kernel/liveupdate/Kconfig +++ b/kernel/liveupdate/Kconfig @@ -47,6 +47,21 @@ config LIVEUPDATE_SYSFS_API =20 If unsure, say N. =20 +config LIVEUPDATE_SELFTESTS + bool "Live Update Orchestrator - self tests" + depends on LIVEUPDATE + help + =C2=A0 Say Y here to build self-tests for the LUO framework. When enabled, + these tests can be initiated via the ioctl interface to help verify + the core live update functionality. + + =C2=A0 This option is primarily intended for developers working on the + =C2=A0 live update feature or for validation purposes during system + =C2=A0 integration. + + =C2=A0 If you are unsure or are building a production kernel where size + =C2=A0 or attack surface is a concern, say N. + config KEXEC_HANDOVER bool "kexec handover" depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE diff --git a/kernel/liveupdate/Makefile b/kernel/liveupdate/Makefile index e35ddc51ab2b..dfb63414cab2 100644 --- a/kernel/liveupdate/Makefile +++ b/kernel/liveupdate/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_KEXEC_HANDOVER) +=3D kexec_handover.o obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) +=3D kexec_handover_debug.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_core.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_files.o +obj-$(CONFIG_LIVEUPDATE_SELFTESTS) +=3D luo_selftests.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_ioctl.o obj-$(CONFIG_LIVEUPDATE) +=3D luo_subsystems.o obj-$(CONFIG_LIVEUPDATE_SYSFS_API) +=3D luo_sysfs.o diff --git a/kernel/liveupdate/luo_selftests.c b/kernel/liveupdate/luo_self= tests.c new file mode 100644 index 000000000000..a198195fd1a5 --- /dev/null +++ b/kernel/liveupdate/luo_selftests.c @@ -0,0 +1,344 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: LUO Selftests + * + * We provide ioctl-based selftest interface for the LUO. It provides a + * mechanism to test core LUO functionality, particularly the registration, + * unregistration, and data handling aspects of LUO subsystems, without + * requiring a full live update event sequence. + * + * The tests are intended primarily for developers working on the LUO fram= ework + * or for validation purposes during system integration. This functionalit= y is + * conditionally compiled based on the `CONFIG_LIVEUPDATE_SELFTESTS` Kconf= ig + * option and should typically be disabled in production kernels. + * + * Interface: + * The selftests are accessed via the `/dev/liveupdate` character device u= sing + * the `LIVEUPDATE_IOCTL_SELFTESTS` ioctl command. The argument to the ioc= tl + * is a pointer to a `struct liveupdate_selftest` structure (defined in + * `uapi/linux/liveupdate.h`), which contains: + * - `cmd`: The specific selftest command to execute (e.g., + * `LUO_CMD_SUBSYSTEM_REGISTER`). + * - `arg`: A pointer to a command-specific argument structure. For subsys= tem + * tests, this points to a `struct luo_arg_subsystem` (defined in + * `luo_selftests.h`). + * + * Commands: + * - `LUO_CMD_SUBSYSTEM_REGISTER`: + * Registers a new dummy LUO subsystem. It allocates kernel memory for test + * data, copies initial data from the user-provided `data_page`, sets up + * simple logging callbacks, and calls the core + * `liveupdate_register_subsystem()` + * function. Requires `arg` pointing to `struct luo_arg_subsystem`. + * - `LUO_CMD_SUBSYSTEM_UNREGISTER`: + * Unregisters a previously registered dummy subsystem identified by `name= `. + * It calls the core `liveupdate_unregister_subsystem()` function and then + * frees the associated kernel memory and internal tracking structures. + * Requires `arg` pointing to `struct luo_arg_subsystem` (only `name` used= ). + * - `LUO_CMD_SUBSYSTEM_GETDATA`: + * Copies the content of the kernel data page associated with the specified + * dummy subsystem (`name`) back to the user-provided `data_page`. This al= lows + * userspace to verify the state of the data after potential test operatio= ns. + * Requires `arg` pointing to `struct luo_arg_subsystem`. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include "luo_internal.h" +#include "luo_selftests.h" + +static struct luo_subsystems { + struct liveupdate_subsystem handle; + char name[LUO_NAME_LENGTH]; + void *data; + bool in_use; + bool preserved; +} luo_subsystems[LUO_MAX_SUBSYSTEMS]; + +/* Only allow one selftest ioctl operation at a time */ +static DEFINE_MUTEX(luo_ioctl_mutex); + +static int luo_subsystem_prepare(void *arg, u64 *data) +{ + unsigned long i =3D (unsigned long)arg; + unsigned long phys_addr =3D __pa(luo_subsystems[i].data); + int ret; + + ret =3D kho_preserve_phys(phys_addr, PAGE_SIZE); + if (ret) + return ret; + + luo_subsystems[i].preserved =3D true; + *data =3D phys_addr; + pr_info("Subsystem '%s' prepare data[%lx]\n", + luo_subsystems[i].name, phys_addr); + + if (strstr(luo_subsystems[i].name, NAME_PREPARE_FAIL)) + return -EAGAIN; + + return 0; +} + +static int luo_subsystem_freeze(void *arg, u64 *data) +{ + unsigned long i =3D (unsigned long)arg; + + pr_info("Subsystem '%s' freeze data[%llx]\n", + luo_subsystems[i].name, *data); + + return 0; +} + +static void luo_subsystem_cancel(void *arg, u64 data) +{ + unsigned long i =3D (unsigned long)arg; + + pr_info("Subsystem '%s' canel data[%llx]\n", + luo_subsystems[i].name, data); + luo_subsystems[i].preserved =3D false; + WARN_ON(kho_unpreserve_phys(data, PAGE_SIZE)); +} + +static void luo_subsystem_finish(void *arg, u64 data) +{ + unsigned long i =3D (unsigned long)arg; + + pr_info("Subsystem '%s' finish data[%llx]\n", + luo_subsystems[i].name, data); +} + +static const struct liveupdate_subsystem_ops luo_selftest_subsys_ops =3D { + .prepare =3D luo_subsystem_prepare, + .freeze =3D luo_subsystem_freeze, + .cancel =3D luo_subsystem_cancel, + .finish =3D luo_subsystem_finish, +}; + +static int luo_subsystem_idx(char *name) +{ + int i; + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + if (luo_subsystems[i].in_use && + !strcmp(luo_subsystems[i].name, name)) + break; + } + + if (i =3D=3D LUO_MAX_SUBSYSTEMS) { + pr_warn("Subsystem with name '%s' is not registred\n", name); + + return -EINVAL; + } + + return i; +} + +static void luo_put_and_free_subsystem(char *name) +{ + int i =3D luo_subsystem_idx(name); + + if (i < 0) + return; + + if (luo_subsystems[i].preserved) + kho_unpreserve_phys(__pa(luo_subsystems[i].data), PAGE_SIZE); + free_page((unsigned long)luo_subsystems[i].data); + luo_subsystems[i].in_use =3D false; + luo_subsystems[i].preserved =3D false; +} + +static int luo_get_and_alloc_subsystem(char *name, void __user *data, + struct liveupdate_subsystem **hp) +{ + unsigned long page_addr, i; + + page_addr =3D get_zeroed_page(GFP_KERNEL); + if (!page_addr) { + pr_warn("Failed to allocate memory for subsystem data\n"); + return -ENOMEM; + } + + if (copy_from_user((void *)page_addr, data, PAGE_SIZE)) { + free_page(page_addr); + return -EFAULT; + } + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + if (!luo_subsystems[i].in_use) + break; + } + + if (i =3D=3D LUO_MAX_SUBSYSTEMS) { + pr_warn("Maximum number of subsystems registered\n"); + free_page(page_addr); + return -ENOMEM; + } + + luo_subsystems[i].in_use =3D true; + luo_subsystems[i].handle.ops =3D &luo_selftest_subsys_ops; + luo_subsystems[i].handle.name =3D luo_subsystems[i].name; + luo_subsystems[i].handle.arg =3D (void *)i; + strscpy(luo_subsystems[i].name, name, LUO_NAME_LENGTH); + luo_subsystems[i].data =3D (void *)page_addr; + + *hp =3D &luo_subsystems[i].handle; + + return 0; +} + +static int luo_cmd_subsystem_unregister(void __user *argp) +{ + struct luo_arg_subsystem arg; + int ret, i; + + if (copy_from_user(&arg, argp, sizeof(arg))) + return -EFAULT; + + i =3D luo_subsystem_idx(arg.name); + if (i < 0) + return i; + + ret =3D liveupdate_unregister_subsystem(&luo_subsystems[i].handle); + if (ret) + return ret; + + luo_put_and_free_subsystem(arg.name); + + return 0; +} + +static int luo_cmd_subsystem_register(void __user *argp) +{ + struct liveupdate_subsystem *h; + struct luo_arg_subsystem arg; + int ret; + + if (copy_from_user(&arg, argp, sizeof(arg))) + return -EFAULT; + + ret =3D luo_get_and_alloc_subsystem(arg.name, + (void __user *)arg.data_page, &h); + if (ret) + return ret; + + ret =3D liveupdate_register_subsystem(h); + if (ret) + luo_put_and_free_subsystem(arg.name); + + return ret; +} + +static int luo_cmd_subsystem_getdata(void __user *argp) +{ + struct luo_arg_subsystem arg; + int i; + + if (copy_from_user(&arg, argp, sizeof(arg))) + return -EFAULT; + + i =3D luo_subsystem_idx(arg.name); + if (i < 0) + return i; + + if (copy_to_user(arg.data_page, luo_subsystems[i].data, + PAGE_SIZE)) { + return -EFAULT; + } + + return 0; +} + +static int luo_ioctl_selftests(void __user *argp) +{ + struct liveupdate_selftest luo_st; + void __user *cmd_argp; + int ret =3D 0; + + if (copy_from_user(&luo_st, argp, sizeof(luo_st))) + return -EFAULT; + + cmd_argp =3D (void __user *)luo_st.arg; + + mutex_lock(&luo_ioctl_mutex); + switch (luo_st.cmd) { + case LUO_CMD_SUBSYSTEM_REGISTER: + ret =3D luo_cmd_subsystem_register(cmd_argp); + break; + + case LUO_CMD_SUBSYSTEM_UNREGISTER: + ret =3D luo_cmd_subsystem_unregister(cmd_argp); + break; + + case LUO_CMD_SUBSYSTEM_GETDATA: + ret =3D luo_cmd_subsystem_getdata(cmd_argp); + break; + + default: + pr_warn("ioctl: unknown self-test command nr: 0x%llx\n", + luo_st.cmd); + ret =3D -ENOTTY; + break; + } + mutex_unlock(&luo_ioctl_mutex); + + return ret; +} + +static long luo_selftest_ioctl(struct file *filep, unsigned int cmd, + unsigned long arg) +{ + int ret =3D 0; + + if (_IOC_TYPE(cmd) !=3D LIVEUPDATE_IOCTL_TYPE) + return -ENOTTY; + + switch (cmd) { + case LIVEUPDATE_IOCTL_FREEZE: + ret =3D luo_freeze(); + break; + + case LIVEUPDATE_IOCTL_SELFTESTS: + ret =3D luo_ioctl_selftests((void __user *)arg); + break; + + default: + pr_warn("ioctl: unknown command nr: 0x%x\n", _IOC_NR(cmd)); + ret =3D -ENOTTY; + break; + } + + return ret; +} + +static const struct file_operations luo_selftest_fops =3D { + .open =3D nonseekable_open, + .unlocked_ioctl =3D luo_selftest_ioctl, +}; + +static int __init luo_seltesttest_init(void) +{ + if (!liveupdate_debugfs_root) { + pr_err("liveupdate root is not set\n"); + return 0; + } + debugfs_create_file_unsafe("luo_selftest", 0600, + liveupdate_debugfs_root, NULL, + &luo_selftest_fops); + return 0; +} + +late_initcall(luo_seltesttest_init); diff --git a/kernel/liveupdate/luo_selftests.h b/kernel/liveupdate/luo_self= tests.h new file mode 100644 index 000000000000..098f2e9e6a78 --- /dev/null +++ b/kernel/liveupdate/luo_selftests.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#ifndef _LINUX_LUO_SELFTESTS_H +#define _LINUX_LUO_SELFTESTS_H + +#include +#include + +/* Maximum number of subsystem self-test can register */ +#define LUO_MAX_SUBSYSTEMS 16 +#define LUO_NAME_LENGTH 32 + +#define LUO_CMD_SUBSYSTEM_REGISTER 0 +#define LUO_CMD_SUBSYSTEM_UNREGISTER 1 +#define LUO_CMD_SUBSYSTEM_GETDATA 2 +struct luo_arg_subsystem { + char name[LUO_NAME_LENGTH]; + void *data_page; +}; + +/* + * Test name prefixes: + * normal: prepare and freeze callbacks do not fail + * prepare_fail: prepare callback fails for this test. + * freeze_fail: freeze callback fails for this test + */ +#define NAME_NORMAL "ksft_luo" +#define NAME_PREPARE_FAIL "ksft_prepare_fail" +#define NAME_FREEZE_FAIL "ksft_freeze_fail" + +/** + * struct liveupdate_selftest - Holds directions for the self-test operati= ons. + * @cmd: Selftest comman defined in luo_selftests.h. + * @arg: Argument for the self test command. + * + * This structure is used only for the selftest purposes. + */ +struct liveupdate_selftest { + __u64 cmd; + __u64 arg; +}; + +/** + * LIVEUPDATE_IOCTL_FREEZE - Notify subsystems of imminent reboot + * transition. + * + * Argument: None. + * + * Notifies the live update subsystem and associated components that the k= ernel + * is about to execute the final reboot transition into the new kernel (e.= g., + * via kexec). This action triggers the internal %LIVEUPDATE_FREEZE kernel + * event. This event provides subsystems a final, brief opportunity (withi= n the + * "blackout window") to save critical state or perform last-moment quiesc= ing. + * Any remaining or deferred state saving for items marked via the PRESERVE + * ioctls typically occurs in response to the %LIVEUPDATE_FREEZE event. + * + * This ioctl should only be called when the system is in the + * %LIVEUPDATE_STATE_PREPARED state. This command does not transfer data. + * + * Return: 0 if the notification is successfully processed by the kernel (= but + * reboot follows). Returns a negative error code if the notification fails + * or if the system is not in the %LIVEUPDATE_STATE_PREPARED state. + */ +#define LIVEUPDATE_IOCTL_FREEZE \ + _IO(LIVEUPDATE_IOCTL_TYPE, 0x05) + +/** + * LIVEUPDATE_IOCTL_SELFTESTS - Interface for the LUO selftests + * + * Argument: Pointer to &struct liveupdate_selftest. + * + * Use by LUO selftests, commands are declared in luo_selftests.h + * + * Return: 0 on success, negative error code on failure (e.g., invalid tok= en). + */ +#define LIVEUPDATE_IOCTL_SELFTESTS \ + _IOWR(LIVEUPDATE_IOCTL_TYPE, 0x08, struct liveupdate_selftest) + +#endif /* _LINUX_LUO_SELFTESTS_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.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 7B5FA2E541C for ; Wed, 25 Jun 2025 23:19:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893564; cv=none; b=psdnaE2c0l81gIFYMYDbiboiUlWP6mx9Q5vnihZRJapte5YGuPL6Xf3Gfpk2JrL/5QyO0Br1+jGOSQzE+p+u/xvDdvXsebVn71z6NPHddzBKlBrS52jj7WEJvLq9SmKT+VoJ6raEI9s38watOppSUBwCjHOAkLSyEsWPn7zU6KM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893564; c=relaxed/simple; bh=LTvazaelJup2RLQo0+ts/x55y7xfpD3AP0z69NBtyJ0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r3Gm7IsoAp0lKMix8nA6lniitB60vQsiTSY2r5NadzmNBcBEruUIcjhrwRPTrb0ZNi2Xo4+luHBkpi1Ht6Dx05gFIc1nKWq1wbNDuJgsRgPtS3WLBOPrdWJsziZ62+G9guEv3DxM+fB2Cmd+kW9wqSFcbzalZqR01byBvEYFJEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=Q7H9h6Lq; arc=none smtp.client-ip=209.85.219.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="Q7H9h6Lq" Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-e7387d4a336so312881276.2 for ; Wed, 25 Jun 2025 16:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893561; x=1751498361; 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=oWmBXVjGh1wc/IzDBDeCQXSx4hXhB+JQyCN77jCTWMc=; b=Q7H9h6LqYz7v2wW+2W7SglfaHtpTzorNxzdTRDybawToastYUJWYH4/tOqEng5EaTY UmOdT+NFbNaVAX9ixdwql0b6IraYFsQdqO+QyHkLm1mGzlfCT2PiBQdmZb3/vwh6I1VF 6Z/H4kpRTDmQLkI5stkdDuRe/OTEzlK9KbPOjcBVr9T70S42xR+WfOkE2PELnzgvV9Zz 3iC2n+UCuyIXZyXz7Yx3nDzhQ0Je/HiKWzwmTidkEhqSE+gkNn/uDDfcwaf9IxrcUIm5 Gov5anUqooxNJ749XrfzMJj+jOVaUKGG5ir2eMKF4fqct/OFLTEtJCYFy8QC0KydXEr6 4Bcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893561; x=1751498361; 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=oWmBXVjGh1wc/IzDBDeCQXSx4hXhB+JQyCN77jCTWMc=; b=YP+LlRVU34ruep8YXJoJ2DfJ2yGZ01aPK1fHKs/gLTnuxMvAFqiIJkIZaBropfkmnv 2TfSXtHTJa6ziV8tx2fft04liILl1PDpSR3SAkd/Ezj2/sMcH7K30ahpJOqX9JfWvcYS oS15xxLQF5ucgxRksx20jZCgPNcKf6NpZiwpc7nVE5ljw4T/92wEPB1vzHeFVccdHbhw 8CteYMrEteP6xEKgHMm93z/wpRfRbV+4TeUT0e5aUdPU79VsqFESqlfi30MrOxnGMYkj NYEWexe266wQMglfZkdXnc+eN6vhnpMRoWvRXHW5G8CVI5RPH/OJZGr1YC8BtchnbUq5 Aeig== X-Forwarded-Encrypted: i=1; AJvYcCVjycrcEzJeZ32UZew6SU9AcKdL4+JkX6HE+Dz7NpO4+LxcBQ/NcXBtcfDmIoyMbRK9p8oOWNYXhGglV+U=@vger.kernel.org X-Gm-Message-State: AOJu0YyNBKWWUAh7DdRhx4QxQcfrtu1wnNPTthbfaOO3hBV6HXe0sA6y fkPx7KP9o9v9RtEuGgrM0fV30e9bYQY4JIdwBavGSCmTlHGAQ3nlT24WYTqyVy2O1qo= X-Gm-Gg: ASbGncsQH7WpiSv93SD/6Vi7LWNiyWx5grBOtM/cWMuFoC7sgpguiyNJgNPtxbQxnly N4JSOrqN+qasQFmxCXP8mnMDu/zrL2fRVNx7QijZ8ILRlxEl1iwvbZBjnQ7+fBZ04+OmQ5nhWFR gdc5ZVfvqbXnGtksOBEFPGSjt/8k4Q/CgrXnCdygKecMiYi9t1XQgP+r5EsA9eXP1Xw2B6h5of1 ZBJea2D/P/HykWZeZCBUD6BbYTTJ0KV1SS3s9XMVbqTKCTgF5Vkag4g42dkNhU4iYmKwgBdzUjS cDlVlmdQQUumWW2w2Beq78SG4oKwgWpNV7wyUF/9MHRTOeKQbu4kmUthGN/h0q1UParJrEtJ6SC OE8FCHgqDzxA9ZW/HZnXsD/SMAcAfZgvvETnoKqhm1haH9AxucWdX X-Google-Smtp-Source: AGHT+IHBhcERB5WpXtZntroBtxeP7CadGo0+bxbFMxveWkVBexE1WcbHGf8ep4HdbuKr8YEvROFMiA== X-Received: by 2002:a05:6902:1609:b0:e84:4aef:49f4 with SMTP id 3f1490d57ef6-e86016eeaf5mr7008558276.13.1750893561443; Wed, 25 Jun 2025 16:19:21 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:20 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 22/32] selftests/liveupdate: add subsystem/state tests Date: Wed, 25 Jun 2025 23:18:09 +0000 Message-ID: <20250625231838.1897085-23-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Introduces a new set of userspace selftests for the LUO. These tests verify the functionality LUO by using the kernel-side selftest ioctls provided by the LUO module, primarily focusing on subsystem management and basic LUO state transitions. Signed-off-by: Pasha Tatashin --- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 7 + tools/testing/selftests/liveupdate/config | 6 + .../testing/selftests/liveupdate/liveupdate.c | 356 ++++++++++++++++++ 5 files changed, 371 insertions(+) create mode 100644 tools/testing/selftests/liveupdate/.gitignore create mode 100644 tools/testing/selftests/liveupdate/Makefile create mode 100644 tools/testing/selftests/liveupdate/config create mode 100644 tools/testing/selftests/liveupdate/liveupdate.c diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Mak= efile index 339b31e6a6b5..d8fc84ccac32 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -53,6 +53,7 @@ TARGETS +=3D kvm TARGETS +=3D landlock TARGETS +=3D lib TARGETS +=3D livepatch +TARGETS +=3D liveupdate TARGETS +=3D lkdtm TARGETS +=3D lsm TARGETS +=3D membarrier diff --git a/tools/testing/selftests/liveupdate/.gitignore b/tools/testing/= selftests/liveupdate/.gitignore new file mode 100644 index 000000000000..af6e773cf98f --- /dev/null +++ b/tools/testing/selftests/liveupdate/.gitignore @@ -0,0 +1 @@ +/liveupdate diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/se= lftests/liveupdate/Makefile new file mode 100644 index 000000000000..2a573c36016e --- /dev/null +++ b/tools/testing/selftests/liveupdate/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +CFLAGS +=3D -Wall -O2 -Wno-unused-function +CFLAGS +=3D $(KHDR_INCLUDES) + +TEST_GEN_PROGS +=3D liveupdate + +include ../lib.mk diff --git a/tools/testing/selftests/liveupdate/config b/tools/testing/self= tests/liveupdate/config new file mode 100644 index 000000000000..382c85b89570 --- /dev/null +++ b/tools/testing/selftests/liveupdate/config @@ -0,0 +1,6 @@ +CONFIG_KEXEC_FILE=3Dy +CONFIG_KEXEC_HANDOVER=3Dy +CONFIG_KEXEC_HANDOVER_DEBUG=3Dy +CONFIG_LIVEUPDATE=3Dy +CONFIG_LIVEUPDATE_SYSFS_API=3Dy +CONFIG_LIVEUPDATE_SELFTESTS=3Dy diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testin= g/selftests/liveupdate/liveupdate.c new file mode 100644 index 000000000000..989a9a67d4cf --- /dev/null +++ b/tools/testing/selftests/liveupdate/liveupdate.c @@ -0,0 +1,356 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include "../kselftest.h" +#include "../kselftest_harness.h" +#include "../../../../kernel/liveupdate/luo_selftests.h" + +struct subsystem_info { + void *data_page; + void *verify_page; + char test_name[LUO_NAME_LENGTH]; + bool registered; +}; + +FIXTURE(subsystem) { + int fd; + int fd_dbg; + struct subsystem_info si[LUO_MAX_SUBSYSTEMS]; +}; + +FIXTURE(state) { + int fd; + int fd_dbg; +}; + +#define LUO_DEVICE "/dev/liveupdate" +#define LUO_DBG_DEVICE "/sys/kernel/debug/liveupdate/luo_selftest" +#define LUO_SYSFS_STATE "/sys/kernel/liveupdate/state" +static size_t page_size; + +const char *const luo_state_str[] =3D { + [LIVEUPDATE_STATE_UNDEFINED] =3D "undefined", + [LIVEUPDATE_STATE_NORMAL] =3D "normal", + [LIVEUPDATE_STATE_PREPARED] =3D "prepared", + [LIVEUPDATE_STATE_FROZEN] =3D "frozen", + [LIVEUPDATE_STATE_UPDATED] =3D "updated", +}; + +static int run_luo_selftest_cmd(int fd_dbg, __u64 cmd_code, + struct luo_arg_subsystem *subsys_arg) +{ + struct liveupdate_selftest k_arg; + + k_arg.cmd =3D cmd_code; + k_arg.arg =3D (__u64)(unsigned long)subsys_arg; + + return ioctl(fd_dbg, LIVEUPDATE_IOCTL_SELFTESTS, &k_arg); +} + +static int register_subsystem(int fd_dbg, struct subsystem_info *si) +{ + struct luo_arg_subsystem subsys_arg; + int ret; + + memset(&subsys_arg, 0, sizeof(subsys_arg)); + snprintf(subsys_arg.name, LUO_NAME_LENGTH, "%s", si->test_name); + subsys_arg.data_page =3D si->data_page; + + ret =3D run_luo_selftest_cmd(fd_dbg, LUO_CMD_SUBSYSTEM_REGISTER, + &subsys_arg); + if (!ret) + si->registered =3D true; + + return ret; +} + +static int unregister_subsystem(int fd_dbg, struct subsystem_info *si) +{ + struct luo_arg_subsystem subsys_arg; + int ret; + + memset(&subsys_arg, 0, sizeof(subsys_arg)); + snprintf(subsys_arg.name, LUO_NAME_LENGTH, "%s", si->test_name); + + ret =3D run_luo_selftest_cmd(fd_dbg, LUO_CMD_SUBSYSTEM_UNREGISTER, + &subsys_arg); + if (!ret) + si->registered =3D false; + + return ret; +} + +static int get_sysfs_state(void) +{ + char buf[64]; + ssize_t len; + int fd, i; + + fd =3D open(LUO_SYSFS_STATE, O_RDONLY); + if (fd < 0) { + ksft_print_msg("Failed to open sysfs state file '%s': %s\n", + LUO_SYSFS_STATE, strerror(errno)); + return -errno; + } + + len =3D read(fd, buf, sizeof(buf) - 1); + close(fd); + + if (len <=3D 0) { + ksft_print_msg("Failed to read sysfs state file '%s': %s\n", + LUO_SYSFS_STATE, strerror(errno)); + return -errno; + } + if (buf[len - 1] =3D=3D '\n') + buf[len - 1] =3D '\0'; + else + buf[len] =3D '\0'; + + for (i =3D 0; i < ARRAY_SIZE(luo_state_str); i++) { + if (!strcmp(buf, luo_state_str[i])) + return i; + } + + return -EIO; +} + +FIXTURE_SETUP(state) +{ + int state; + + page_size =3D sysconf(_SC_PAGE_SIZE); + self->fd =3D open(LUO_DEVICE, O_RDWR); + if (self->fd < 0) + SKIP(return, "open(%s) failed [%d]", LUO_DEVICE, errno); + + self->fd_dbg =3D open(LUO_DBG_DEVICE, O_RDWR); + ASSERT_GE(self->fd_dbg, 0); + + state =3D get_sysfs_state(); + if (state < 0) { + if (state =3D=3D -ENOENT || state =3D=3D -EACCES) + SKIP(return, "sysfs state not accessible (%d)", state); + } +} + +FIXTURE_TEARDOWN(state) +{ + enum liveupdate_state state =3D LIVEUPDATE_STATE_NORMAL; + + ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state); + if (state !=3D LIVEUPDATE_STATE_NORMAL) + ioctl(self->fd, LIVEUPDATE_IOCTL_CANCEL, NULL); + close(self->fd); +} + +FIXTURE_SETUP(subsystem) +{ + int i; + + page_size =3D sysconf(_SC_PAGE_SIZE); + memset(&self->si, 0, sizeof(self->si)); + self->fd =3D open(LUO_DEVICE, O_RDWR); + if (self->fd < 0) + SKIP(return, "open(%s) failed [%d]", LUO_DEVICE, errno); + + self->fd_dbg =3D open(LUO_DBG_DEVICE, O_RDWR); + ASSERT_GE(self->fd_dbg, 0); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + snprintf(self->si[i].test_name, LUO_NAME_LENGTH, + NAME_NORMAL ".%d", i); + + self->si[i].data_page =3D mmap(NULL, page_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + ASSERT_NE(MAP_FAILED, self->si[i].data_page); + memset(self->si[i].data_page, 'A' + i, page_size); + + self->si[i].verify_page =3D mmap(NULL, page_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + ASSERT_NE(MAP_FAILED, self->si[i].verify_page); + memset(self->si[i].verify_page, 0, page_size); + } +} + +FIXTURE_TEARDOWN(subsystem) +{ + enum liveupdate_state state =3D LIVEUPDATE_STATE_NORMAL; + int i; + + ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state); + if (state !=3D LIVEUPDATE_STATE_NORMAL) + ioctl(self->fd, LIVEUPDATE_IOCTL_CANCEL, NULL); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + if (self->si[i].registered) + unregister_subsystem(self->fd_dbg, &self->si[i]); + munmap(self->si[i].data_page, page_size); + munmap(self->si[i].verify_page, page_size); + } + + close(self->fd); +} + +TEST_F(state, normal) +{ + enum liveupdate_state state; + + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state)); + ASSERT_EQ(state, LIVEUPDATE_STATE_NORMAL); +} + +TEST_F(state, prepared) +{ + enum liveupdate_state state; + + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_PREPARE, NULL)); + + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state)); + ASSERT_EQ(state, LIVEUPDATE_STATE_PREPARED); + + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_CANCEL, NULL)); + + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state)); + ASSERT_EQ(state, LIVEUPDATE_STATE_NORMAL); +} + +TEST_F(state, sysfs_normal) +{ + ASSERT_EQ(LIVEUPDATE_STATE_NORMAL, get_sysfs_state()); +} + +TEST_F(state, sysfs_prepared) +{ + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_PREPARE, NULL)); + ASSERT_EQ(LIVEUPDATE_STATE_PREPARED, get_sysfs_state()); + + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_CANCEL, NULL)); + ASSERT_EQ(LIVEUPDATE_STATE_NORMAL, get_sysfs_state()); +} + +TEST_F(state, sysfs_frozen) +{ + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_PREPARE, NULL)); + + ASSERT_EQ(LIVEUPDATE_STATE_PREPARED, get_sysfs_state()); + + ASSERT_EQ(0, ioctl(self->fd_dbg, LIVEUPDATE_IOCTL_FREEZE, NULL)); + ASSERT_EQ(LIVEUPDATE_STATE_FROZEN, get_sysfs_state()); + + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_CANCEL, NULL)); + ASSERT_EQ(LIVEUPDATE_STATE_NORMAL, get_sysfs_state()); +} + +TEST_F(subsystem, register_unregister) +{ + ASSERT_EQ(0, register_subsystem(self->fd_dbg, &self->si[0])); + ASSERT_EQ(0, unregister_subsystem(self->fd_dbg, &self->si[0])); +} + +TEST_F(subsystem, double_unregister) +{ + ASSERT_EQ(0, register_subsystem(self->fd_dbg, &self->si[0])); + ASSERT_EQ(0, unregister_subsystem(self->fd_dbg, &self->si[0])); + EXPECT_NE(0, unregister_subsystem(self->fd_dbg, &self->si[0])); + EXPECT_TRUE(errno =3D=3D EINVAL || errno =3D=3D ENOENT); +} + +TEST_F(subsystem, register_unregister_many) +{ + int i; + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) + ASSERT_EQ(0, register_subsystem(self->fd_dbg, &self->si[i])); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) + ASSERT_EQ(0, unregister_subsystem(self->fd_dbg, &self->si[i])); +} + +TEST_F(subsystem, getdata_verify) +{ + enum liveupdate_state state; + int i; + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) + ASSERT_EQ(0, register_subsystem(self->fd_dbg, &self->si[i])); + + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_PREPARE, NULL)); + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state)); + ASSERT_EQ(state, LIVEUPDATE_STATE_PREPARED); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + struct luo_arg_subsystem subsys_arg; + + memset(&subsys_arg, 0, sizeof(subsys_arg)); + snprintf(subsys_arg.name, LUO_NAME_LENGTH, "%s", + self->si[i].test_name); + subsys_arg.data_page =3D self->si[i].verify_page; + + ASSERT_EQ(0, run_luo_selftest_cmd(self->fd_dbg, + LUO_CMD_SUBSYSTEM_GETDATA, + &subsys_arg)); + ASSERT_EQ(0, memcmp(self->si[i].data_page, + self->si[i].verify_page, + page_size)); + } + + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_CANCEL, NULL)); + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state)); + ASSERT_EQ(state, LIVEUPDATE_STATE_NORMAL); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) + ASSERT_EQ(0, unregister_subsystem(self->fd_dbg, &self->si[i])); +} + +TEST_F(subsystem, prepare_fail) +{ + int i; + + snprintf(self->si[LUO_MAX_SUBSYSTEMS - 1].test_name, LUO_NAME_LENGTH, + NAME_PREPARE_FAIL ".%d", LUO_MAX_SUBSYSTEMS - 1); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) + ASSERT_EQ(0, register_subsystem(self->fd_dbg, &self->si[i])); + + ASSERT_EQ(-1, ioctl(self->fd, LIVEUPDATE_IOCTL_PREPARE, NULL)); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) + ASSERT_EQ(0, unregister_subsystem(self->fd_dbg, &self->si[i])); + + snprintf(self->si[LUO_MAX_SUBSYSTEMS - 1].test_name, LUO_NAME_LENGTH, + NAME_NORMAL ".%d", LUO_MAX_SUBSYSTEMS - 1); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) + ASSERT_EQ(0, register_subsystem(self->fd_dbg, &self->si[i])); + + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_PREPARE, NULL)); + ASSERT_EQ(0, ioctl(self->fd_dbg, LIVEUPDATE_IOCTL_FREEZE, NULL)); + ASSERT_EQ(0, ioctl(self->fd, LIVEUPDATE_IOCTL_CANCEL, NULL)); + ASSERT_EQ(LIVEUPDATE_STATE_NORMAL, get_sysfs_state()); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) + ASSERT_EQ(0, unregister_subsystem(self->fd_dbg, &self->si[i])); +} + +TEST_HARNESS_MAIN --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 5759E2E5415 for ; Wed, 25 Jun 2025 23:19:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893566; cv=none; b=nKfPSgZyu6vfhQkuTTyFmNcIPomkQmsrx+JW7ZpHtig0drBqjg7/wet54SSS/D7c5m7z+H1cF93Whov3vgpm4InEhnifI0bTQKCaElKVtq1MdAMWeuauHXZWofSn67XP9czLfYagli0w8V5pm4O/ju8ynOJE1dObb2S4YbaQqi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893566; c=relaxed/simple; bh=3Bs7yjVCwVYzX1qp5XJYtcpXHYaHTnRk2TWgFXsiFjo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ac2tsals+beddP+oXVFFQvWL7Hpp/xyNJdnwB1SWVi6RCkUsWiMLn8xHXBtB8T1I9KEQLviiaztRFtzPKQtoST0/TE9Kqp5iOZpnYnHgf3AZKeNEa0kWCaTfPwtnD0DXjs2B9qIZs6NidSRWcJsmAnIXQnuMlhfsf0oI2Nk3KfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=zw3yTgFD; arc=none smtp.client-ip=209.85.219.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="zw3yTgFD" Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e82314f9a51so291424276.0 for ; Wed, 25 Jun 2025 16:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893563; x=1751498363; 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=NC1ayEHkvN6ijinKURZBxrM3hNqjaSgPk5qZ/n3J1rM=; b=zw3yTgFDvVJTqB0CEMS6xo5qxldQbFl/tSMptiy1NkIiEtElya3EdUzXOOr7oaqOjy u9AyLhppc/fHCGFkRsYceqz+3zuxSylHWa4dzkbnmFJvvF/rnUsHbx/pYRBxp8WLLkVh LY+B+0E8wSK59Qaz8cFiP5zzS3GcasQ4zVqy1d7/8VQnErKzFcTUV3P73YFFx0xpS6LZ BXfA1bg35SD3zsvfJbFrET2epw5RtkHWtknrkXTvywYwBrzrMZm9o+pNDKKg6CNs6Ehy 4YSwZLvj3L7Ft+bBVN9KPZJVIXYKVZQsS5M58vJFYyWJNhtmBLNNkLkyxIuqandS9I/5 Wizw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893563; x=1751498363; 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=NC1ayEHkvN6ijinKURZBxrM3hNqjaSgPk5qZ/n3J1rM=; b=PoDjw+MY2TZwldTGgnB0i4Vi2mznZWT4aHqoaj3wuIIy8TkTtcCdGx6xiRG/5V4+Kj g30II+euXtoliTPt6K73z8FKIXcxqFwo57LluWooBqYtOZndSziX06Heb2xFygNpOd/N cGXRATBtHZyzOrnwnnEvEwSuO4M4cJIhe0e+LXzDLDfWN2+Ul2nEWrXFIGs1fElKUwPF 1pU7K3w0oH5Rqw7I4VGAcmPMda+Bc+SIrOB3ac8e51KWqC51JeuyHW9VKqQL7zszFSr6 6PkbbXKbuEOVpvuGOx6yVJq0xKRmYv7rOVeoQnLEx+RtY5Oyu6/c+0AYhLljX8sJir32 FTvg== X-Forwarded-Encrypted: i=1; AJvYcCUVcH/UARRwLgNxCj8AIz8im+Mgi2V5JXSI1iQgmA7m/Uvxt3U93So6B2JnnByFmcvOFKRLkPBr/jF6zYs=@vger.kernel.org X-Gm-Message-State: AOJu0YyhxjFgdmgj9lwXnaQAq7YvngkjFZJFUuVxuQ2Agtevx1g9rJRS /6gnvm90/uEcwI9T1UnH4DwlrLhE+aFoBRtxaYcVcnT7SazfIQ0yT2py+V0S/kXKFfQ= X-Gm-Gg: ASbGnct93q6mU4yeTJn0OstPYm6iyLhXp+QUzfKbKBCP4A081KnS18Epe2S9DqPQqA0 V3GIybkHzZ4tfPyiu+2O4iobuJdcn4w0HGWyVBftMlRRp/pr+04zE8v3BTYHMbxNC4XCtURu4Yt f9DYah6YJF+dNWTJ7EU9qNsVvH0juVpBjnkEctTxy2vByPb8qXBxOYTdr6q4Mk+BCTkiGBNOjMC tmqXHMzYiCn9mrRbJb8jY5KYFobFK9kxUmE5waEg/1gYCThd8IQLOAvpjU3kITKrOjShyvFWny+ UX0FTbVEtQGu9j5r0DSirSoYJ0zEtBYm5w7vzOJDrS/MrohOC15ZATRs8dyciybD9MhJWSFulB+ dW31awKRR8fuXfgob8j2/+7oD9ADO22BBgLE6SebmdaN494Hwx28g X-Google-Smtp-Source: AGHT+IFnAI1qCvNBz4mB5Q4FSGHdp5ZaV6ywIeny7tCD+W481rJiP0KC7KdFe65zVWMeF3cIUgLqHw== X-Received: by 2002:a05:6902:1205:b0:e84:4341:4101 with SMTP id 3f1490d57ef6-e86016d1768mr7606110276.10.1750893563223; Wed, 25 Jun 2025 16:19:23 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:22 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 23/32] docs: add luo documentation Date: Wed, 25 Jun 2025 23:18:10 +0000 Message-ID: <20250625231838.1897085-24-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Add the documentation files for the Live Update Orchestrator Signed-off-by: Pasha Tatashin --- Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/liveupdate.rst | 16 +++++++ Documentation/core-api/index.rst | 1 + Documentation/core-api/liveupdate.rst | 50 ++++++++++++++++++++++ Documentation/userspace-api/index.rst | 1 + Documentation/userspace-api/liveupdate.rst | 25 +++++++++++ 6 files changed, 94 insertions(+) create mode 100644 Documentation/admin-guide/liveupdate.rst create mode 100644 Documentation/core-api/liveupdate.rst create mode 100644 Documentation/userspace-api/liveupdate.rst diff --git a/Documentation/admin-guide/index.rst b/Documentation/admin-guid= e/index.rst index 259d79fbeb94..3f59ccf32760 100644 --- a/Documentation/admin-guide/index.rst +++ b/Documentation/admin-guide/index.rst @@ -95,6 +95,7 @@ likely to be of interest on almost any system. cgroup-v2 cgroup-v1/index cpu-load + liveupdate mm/index module-signing namespaces/index diff --git a/Documentation/admin-guide/liveupdate.rst b/Documentation/admin= -guide/liveupdate.rst new file mode 100644 index 000000000000..ff05cc1dd784 --- /dev/null +++ b/Documentation/admin-guide/liveupdate.rst @@ -0,0 +1,16 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Live Update sysfs +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +:Author: Pasha Tatashin + +LUO sysfs interface +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: kernel/liveupdate/luo_sysfs.c + :doc: LUO sysfs interface + +See Also +=3D=3D=3D=3D=3D=3D=3D=3D + +- :doc:`Live Update Orchestrator ` diff --git a/Documentation/core-api/index.rst b/Documentation/core-api/inde= x.rst index 7a4ca18ca6e2..a79d806f2c8e 100644 --- a/Documentation/core-api/index.rst +++ b/Documentation/core-api/index.rst @@ -136,6 +136,7 @@ Documents that don't fit elsewhere or which have yet to= be categorized. :maxdepth: 1 =20 librs + liveupdate netlink =20 .. only:: subproject and html diff --git a/Documentation/core-api/liveupdate.rst b/Documentation/core-api= /liveupdate.rst new file mode 100644 index 000000000000..41c4b76cd3ec --- /dev/null +++ b/Documentation/core-api/liveupdate.rst @@ -0,0 +1,50 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Live Update Orchestrator +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +:Author: Pasha Tatashin + +.. kernel-doc:: kernel/liveupdate/luo_core.c + :doc: Live Update Orchestrator (LUO) + +LUO Subsystems Participation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D +.. kernel-doc:: kernel/liveupdate/luo_subsystems.c + :doc: LUO Subsystems support + +LUO Preserving File Descriptors +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: kernel/liveupdate/luo_files.c + :doc: LUO file descriptors + +Public API +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: include/linux/liveupdate.h + +.. kernel-doc:: kernel/liveupdate/luo_core.c + :export: + +.. kernel-doc:: kernel/liveupdate/luo_subsystems.c + :export: + +.. kernel-doc:: kernel/liveupdate/luo_files.c + :export: + +Internal API +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: kernel/liveupdate/luo_core.c + :internal: + +.. kernel-doc:: kernel/liveupdate/luo_subsystems.c + :internal: + +.. kernel-doc:: kernel/liveupdate/luo_files.c + :internal: + +See Also +=3D=3D=3D=3D=3D=3D=3D=3D + +- :doc:`Live Update uAPI ` +- :doc:`Live Update SysFS ` +- :doc:`/core-api/kho/concepts` diff --git a/Documentation/userspace-api/index.rst b/Documentation/userspac= e-api/index.rst index b8c73be4fb11..ee8326932cb0 100644 --- a/Documentation/userspace-api/index.rst +++ b/Documentation/userspace-api/index.rst @@ -62,6 +62,7 @@ Everything else =20 ELF netlink/index + liveupdate sysfs-platform_profile vduse futex2 diff --git a/Documentation/userspace-api/liveupdate.rst b/Documentation/use= rspace-api/liveupdate.rst new file mode 100644 index 000000000000..70b5017c0e3c --- /dev/null +++ b/Documentation/userspace-api/liveupdate.rst @@ -0,0 +1,25 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Live Update uAPI +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +:Author: Pasha Tatashin + +ioctl interface +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: kernel/liveupdate/luo_ioctl.c + :doc: LUO ioctl Interface + +ioctl uAPI +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: include/uapi/linux/liveupdate.h + +LUO selftests ioctl +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: kernel/liveupdate/luo_selftests.c + :doc: LUO Selftests + +See Also +=3D=3D=3D=3D=3D=3D=3D=3D + +- :doc:`Live Update Orchestrator ` --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (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 D58F72F0E43 for ; Wed, 25 Jun 2025 23:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893568; cv=none; b=k/VIOnWofvdGOtTtWB6yvpEHniM087CU3mhhtWLbRpGvhlTvij4CK6hSwOSYrs9vUez5xWZQtdLGLHPaLqOeJyxbta4zhrcQ/FiY1EVIfTqlHbBnIqOBRNb12pwP6wItXvjlqm5XUsrhy9J9s9HicpMuYAo+bHPZgc/5hyBuA7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893568; c=relaxed/simple; bh=RcNYbs1efhmf/4u7FSKyFDgmK+5VrQkZtAduMmc72no=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OV3XRlnlJccGhHmHD1ukHtxXiPGCT63ZCx5ZQdIoOu7VjqNfyhVvu+SF2k61CF1kJcb+hjvSVlwUT5M8VGnaRJsPuj1A+uaVeMDQ4dtbF2bNK9EqjjDbo4sJFmIWoKHfrEyl5reXpemQoo9AJyrhuyGfhUetJJHUtgX80CR0jvE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=UhfLI+L4; arc=none smtp.client-ip=209.85.219.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="UhfLI+L4" Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-e812fc35985so335581276.0 for ; Wed, 25 Jun 2025 16:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893565; x=1751498365; 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=iRo4ArwTr+rzDEl5s/rKZCEUFMQwNFwkQlgwE4JalXY=; b=UhfLI+L4w2vOEShq7dx+0k68PsM69ZJuJnolkQJVf290inX4WSHRoaWnWTbcGALG2s xErwEmK4mGFriWQbwjiWxMSFCiSMEJbogQglUhdxgThTEzk20e/ktQrYgJurtBbbn3Mc 7qgUg5tBOweM99VcAHl+WRTsT3h6lSdEYah5jD5Q7IlqEHzA0VDRO46r5wHLYixVuepu Uzz1tS2iVPFVKYPX4MMPUj3Qm65wqOLP41uT4MeYbDYsv2PPD6qhbEMwcZgMcK69jzuC ZDdVn/rJB60PiwgmoFcYgEEK6SjHE8CdJAaSL5CPPrPieRxOrFQIkReKQ07zMYOGQmy1 p2Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893565; x=1751498365; 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=iRo4ArwTr+rzDEl5s/rKZCEUFMQwNFwkQlgwE4JalXY=; b=G6CLSZZZxaWWbTynz/0XloOOWa7SucD60QxH7axIxdz1x7gNnvtBw74PZgy1w00XBD 8Oh4wG7yCtgiHYEepU08U9ZPthQGBCK5mMO5i89Cv7pshyCvuf0OMR31QjBxm+tgRoXY NdA+9pw7O+asEsL1WUH4sjeOOBIwlrXjW3a3KUysPRyZ+doMK/WLrvxH4YCiFIv5iepp AHCTHOmnOt4Ml8C5x9ObJ1DYZ6+VxLbvFBCunuTCDL0pBVA86vZNNY1sRJvRfx/k2zAG 5A2Ar6QnDf1itAliMPW/7i5hoOBV78cUBBjosu0c+0pzhudg+2SWsyfeUyUhkEoa4p6+ 0T5w== X-Forwarded-Encrypted: i=1; AJvYcCUJE8/dCyuFUod1XuBT17oVaiSgDM5rTlkxccrhfbXcW8QP0Zj6m7rqWaazwPOii0SEHzK8IA8GHtVX/tc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3FSc05ITTNWcJEpXAm5jy7qom16AGaiZbVJaR39A4U7fi/Faq ng2jBwSBatbKvW179xC15KXY3G69K8IQh7+ys85tExZjy+yHCz99mwsMwG5Y69KLSJk= X-Gm-Gg: ASbGncsXs1SpdLuVs25KS88qqFBjr81eC1Q569i6GGeYOvIW3IZBAFsEcXRHxnJY3TT wrXnGTloUVlLLlffw7jHuGS5Cdiqxu+ZhC8CxVa0MtfAiXb/Oci+ECgp+TR4tACazX/Wft8vbcD cnZqWFKrLis8O3EbMDoiCWOg0ZyAEh3WvSgyNuqhKgGjS9IfldIOPVaLwafn468CpygfxT0cioF JiiMODAE8B9/+YkR5RKMUoXaPojVSK1DZwVdIpHZTfFdGET0uavrnq3zcU6Wo/NePbRP/firUfH 1XpglsMYlM5QaYqhW5D2EA+EN1+QWVI1hMUgZe7LlohcppKZ0izycwQgW7lgHOxp0dJhRBb23pR Ih0vDWoQhPOea+78YiqPU/YkX9q+hC0fNp6Fp2YNfaQXKFTbayzd2bnt0OaytTAg= X-Google-Smtp-Source: AGHT+IF/QqEmdOGEafHDFkdYh+DPEw7yVChLh5FM2HcZlMuGRDD+U97tQzodPIWh00zLYdSn83m6tg== X-Received: by 2002:a05:6902:1790:b0:e84:4b7f:5b67 with SMTP id 3f1490d57ef6-e86017258b6mr5603267276.1.1750893564869; Wed, 25 Jun 2025 16:19:24 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:24 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 24/32] MAINTAINERS: add liveupdate entry Date: Wed, 25 Jun 2025 23:18:11 +0000 Message-ID: <20250625231838.1897085-25-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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" Add a MAINTAINERS file entry for the new Live Update Orchestrator introduced in previous patches. Signed-off-by: Pasha Tatashin --- MAINTAINERS | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index fd097e53fff2..90554f3a1bec 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14009,6 +14009,19 @@ F: kernel/module/livepatch.c F: samples/livepatch/ F: tools/testing/selftests/livepatch/ =20 +LIVE UPDATE +M: Pasha Tatashin +L: linux-kernel@vger.kernel.org +S: Maintained +F: Documentation/ABI/testing/sysfs-kernel-liveupdate +F: Documentation/admin-guide/liveupdate.rst +F: Documentation/core-api/liveupdate.rst +F: Documentation/userspace-api/liveupdate.rst +F: include/linux/liveupdate.h +F: include/uapi/linux/liveupdate.h +F: kernel/liveupdate/ +F: tools/testing/selftests/liveupdate/ + LLC (802.2) L: netdev@vger.kernel.org S: Odd fixes --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (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 30C66306DA9 for ; Wed, 25 Jun 2025 23:19:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893570; cv=none; b=B/N/R0Z48lB+AukF6ZJxDW2R2srNHloVI5eVVz6oTtk6JhmHEmqvbwbkmJamkkpefRxB8WB7nbJEH2PWLlLPofHU5YO1c56M45Z4sUCAVUIIhAfslxFoLESJnTm+xta4xtFOEnpi7fJ8ybBvDR7jupTIkON2UZdvhvSk9R//FLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893570; c=relaxed/simple; bh=30GwfOPk4OSJwfXww5xApnDUnwtMsQ1hVV+ge74wZ9Y=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D5632wGhZNRH/U4fkX56fbkR73Gf30blfst4LHgb44vH7qoHprnQhmgXzsVcd6yPtYHz1KmMq+GkIFkn+l/EAsZ5NF2keE+a+a1TR/pKdFLoyUywyLiD3ewsvdfSOXvm8G6bnIpOVs/v39oUkykdFK10d2BWZgevtjkF8WgT7fc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=ChrAJ4UX; arc=none smtp.client-ip=209.85.219.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="ChrAJ4UX" Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e812c817de0so347642276.0 for ; Wed, 25 Jun 2025 16:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893567; x=1751498367; 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=D8ttgCxJcE3UWPna1GSp5WvPQd8LCM7eXREvoZYzvG0=; b=ChrAJ4UX2GdsUlIUj/l6PgtqRrg68uHZZiTlb3Ueh5H+FfM10T5d3mdBudf2slgRnZ 8M2gsW3bKAICWNuAOqoMRb270B/3JOX12htWydm6l92aWFR7Ks8h/a/IkpBAjtX0GJTK FDnatIx74CegqtyV8NVbuMIIkQgOitS4QAZWP6DQJ6fTcx8kcSmKn/dplz5cXc7zItKr jGoC5mdWE63GigyS1v/rrOxiiuxYOy5LcvIO6FNEhebXkZKJ48PLYbdSQyziPcUeQIr6 OI5cFYvR/qUeUmHBglRVyryLUsuPfBtU+8tPJSkv1yEHPXmhx5lgrFJRGtHxMIs24Emm lexg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893567; x=1751498367; 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=D8ttgCxJcE3UWPna1GSp5WvPQd8LCM7eXREvoZYzvG0=; b=mqtwnVwzPek7dUjCfq3HOlLK7z8dybgWuCK6ZdJurrwwshdEWDi8u3/QS1vxh1uXOO xHXsqrf6vaux3hkvS8qNJRqEf46p51C+FwUIUtbw4TVWqAdhOb7CrymEZe+cG3zGkVLr aGorLF4ZzLu1kax1GuW7pEiDEQi4N8+mEyTl/1EnPq/9d+38VZ2+YIJdb7vnpJEcm5QZ FNkahLaNs0cB68ZMDEqKB5SczwFs/RDmqNp7r0KxyqTS2VFDoiM6NEIAlfGOqRUrjqI+ 8dwdzcbiIVcrs1fFaVRdahvY2RPg4QG29j8oR6Vv3d3oruVfk4GVQw3MMSr018DwDfKd mavA== X-Forwarded-Encrypted: i=1; AJvYcCXa6RXu4XkdZKhXdR5kabUhcXEQTILIpfdrK7mqL9JzGUoHFUZMqggjgBGzxnRs5UmTP1mC2HEsOGj+/oE=@vger.kernel.org X-Gm-Message-State: AOJu0YwE3Sc6wbMdex5TpSAc8m263soM/24HD0V18KrLAOd+miUiQzVD 8dSu99iEIGaMDMBOQIBI9ZwDgXp5epj47926N6O8riaalRs0yzjDFlXKL+N4L+80TKA= X-Gm-Gg: ASbGncsymgMZy2N0og+1PMaFhmnMwo1KxywujXeDbTm3sXB600LYbltffALhU/gbNpC DQqtulNkW2v3Abyccy2JW3E7V5ujEvSxHYH18QkULCdYfWrR2pjboY3yYTgzJj1pYD9tCTZLEwv JOANLENcPSbMrv6T+A3N4GlJ4hlQC6tdIFMR+o+JVvwPqAZUPOIw91HFumTBdsy9fe4pqvrCRvB KOPSp0fcUIbrKTlF/15y244greSYxulDkuS9Emc+lME5spY6upWP9zFxqjs7zE2o9QV83KSFwLi YdzF6rIBZXqud2H3zfULwm/TzS7RoBMyPGXYy+ZiDl1UQYnt3UoC+j41Ip4Ghngg/cIo5eMqhdJ Ke1LI0E6InVjqmnip0XR+mNNkpZhVYZx4apbRDKzQ31FMmI/yLkeB X-Google-Smtp-Source: AGHT+IE1pma/OI7F9Z9q+/yKqcLVvi7QSXRzKzluPfGgyPm9xYfbfJNVSej/XTGmvtY9GN91WObkjQ== X-Received: by 2002:a05:690c:6082:b0:714:349:583d with SMTP id 00721157ae682-71406ca1431mr68358807b3.8.1750893566981; Wed, 25 Jun 2025 16:19:26 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:26 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 25/32] mm: shmem: use SHMEM_F_* flags instead of VM_* flags Date: Wed, 25 Jun 2025 23:18:12 +0000 Message-ID: <20250625231838.1897085-26-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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: Pratyush Yadav shmem_inode_info::flags can have the VM flags VM_NORESERVE and VM_LOCKED. These are used to suppress pre-accounting or to lock the pages in the inode respectively. Using the VM flags directly makes it difficult to add shmem-specific flags that are unrelated to VM behavior since one would need to find a VM flag not used by shmem and re-purpose it. Introduce SHMEM_F_NORESERVE and SHMEM_F_LOCKED which represent the same information, but their bits are independent of the VM flags. Callers can still pass VM_NORESERVE to shmem_get_inode(), but it gets transformed to the shmem-specific flag internally. No functional changes intended. Signed-off-by: Pratyush Yadav Signed-off-by: Pasha Tatashin --- include/linux/shmem_fs.h | 6 ++++++ mm/shmem.c | 24 +++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 5f03a39a26f7..578a5f3d1935 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -10,6 +10,7 @@ #include #include #include +#include =20 /* inode in-kernel data */ =20 @@ -17,6 +18,11 @@ #define SHMEM_MAXQUOTAS 2 #endif =20 +/* Suppress pre-accounting of the entire object size. */ +#define SHMEM_F_NORESERVE BIT(0) +/* Disallow swapping. */ +#define SHMEM_F_LOCKED BIT(1) + struct shmem_inode_info { spinlock_t lock; unsigned int seals; /* shmem seals */ diff --git a/mm/shmem.c b/mm/shmem.c index 3a5a65b1f41a..953d89f62882 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -175,20 +175,20 @@ static inline struct shmem_sb_info *SHMEM_SB(struct s= uper_block *sb) */ static inline int shmem_acct_size(unsigned long flags, loff_t size) { - return (flags & VM_NORESERVE) ? + return (flags & SHMEM_F_NORESERVE) ? 0 : security_vm_enough_memory_mm(current->mm, VM_ACCT(size)); } =20 static inline void shmem_unacct_size(unsigned long flags, loff_t size) { - if (!(flags & VM_NORESERVE)) + if (!(flags & SHMEM_F_NORESERVE)) vm_unacct_memory(VM_ACCT(size)); } =20 static inline int shmem_reacct_size(unsigned long flags, loff_t oldsize, loff_t newsize) { - if (!(flags & VM_NORESERVE)) { + if (!(flags & SHMEM_F_NORESERVE)) { if (VM_ACCT(newsize) > VM_ACCT(oldsize)) return security_vm_enough_memory_mm(current->mm, VM_ACCT(newsize) - VM_ACCT(oldsize)); @@ -206,7 +206,7 @@ static inline int shmem_reacct_size(unsigned long flags, */ static inline int shmem_acct_blocks(unsigned long flags, long pages) { - if (!(flags & VM_NORESERVE)) + if (!(flags & SHMEM_F_NORESERVE)) return 0; =20 return security_vm_enough_memory_mm(current->mm, @@ -215,7 +215,7 @@ static inline int shmem_acct_blocks(unsigned long flags= , long pages) =20 static inline void shmem_unacct_blocks(unsigned long flags, long pages) { - if (flags & VM_NORESERVE) + if (flags & SHMEM_F_NORESERVE) vm_unacct_memory(pages * VM_ACCT(PAGE_SIZE)); } =20 @@ -1557,7 +1557,7 @@ int shmem_writeout(struct folio *folio, struct writeb= ack_control *wbc) if (WARN_ON_ONCE(!wbc->for_reclaim)) goto redirty; =20 - if ((info->flags & VM_LOCKED) || sbinfo->noswap) + if ((info->flags & SHMEM_F_LOCKED) || sbinfo->noswap) goto redirty; =20 if (!total_swap_pages) @@ -2910,15 +2910,15 @@ int shmem_lock(struct file *file, int lock, struct = ucounts *ucounts) * ipc_lock_object() when called from shmctl_do_lock(), * no serialization needed when called from shm_destroy(). */ - if (lock && !(info->flags & VM_LOCKED)) { + if (lock && !(info->flags & SHMEM_F_LOCKED)) { if (!user_shm_lock(inode->i_size, ucounts)) goto out_nomem; - info->flags |=3D VM_LOCKED; + info->flags |=3D SHMEM_F_LOCKED; mapping_set_unevictable(file->f_mapping); } - if (!lock && (info->flags & VM_LOCKED) && ucounts) { + if (!lock && (info->flags & SHMEM_F_LOCKED) && ucounts) { user_shm_unlock(inode->i_size, ucounts); - info->flags &=3D ~VM_LOCKED; + info->flags &=3D ~SHMEM_F_LOCKED; mapping_clear_unevictable(file->f_mapping); } retval =3D 0; @@ -3062,7 +3062,9 @@ static struct inode *__shmem_get_inode(struct mnt_idm= ap *idmap, spin_lock_init(&info->lock); atomic_set(&info->stop_eviction, 0); info->seals =3D F_SEAL_SEAL; - info->flags =3D flags & VM_NORESERVE; + info->flags =3D 0; + if (flags & VM_NORESERVE) + info->flags |=3D SHMEM_F_NORESERVE; info->i_crtime =3D inode_get_mtime(inode); info->fsflags =3D (dir =3D=3D NULL) ? 0 : SHMEM_I(dir)->fsflags & SHMEM_FL_INHERITED; --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (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 A93D1306DD4 for ; Wed, 25 Jun 2025 23:19:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893571; cv=none; b=XR+Pyr/qgeNsTX6Ibo9s4JzzAbRBc0M5YVX2aBuW4Hs5PwIIOKnJDHX54ZagivP1gLsItl9oMavpN/q22Nfb+f2XnQma2L/RFexyi1AuNAbFF0548VqML1GXLiGl3erfnrfVekwztZPqEveaV6GKJXiak1xacwdTZS495sziA6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893571; c=relaxed/simple; bh=Mhpgqk+r0SEE0pBbkdly7K40a+AgWRc9ZIiXP1/YEMY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gv6bFBaEN7fquRmL5l3XPDEbDVdHQ1Gohzm95F7i1Vt1rG2SlYS8rCoZHw/kwL1cDdTOHxKwNbpCo+i1FNESk6O9Qi5/oujX2scJGZm7Q8CnO8zNzk+c3tSLHfx/VRsTuo8i3FqvXEjTyHpgS7ujMJcuOhyc69tn92gXGrOYbS0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=vv80tNiS; arc=none smtp.client-ip=209.85.219.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="vv80tNiS" Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e819aa98e7aso341800276.2 for ; Wed, 25 Jun 2025 16:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893569; x=1751498369; 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=98Jyj99BUXTmYd7+cithe+PSs3lV4fLVI7wtqO1MqXk=; b=vv80tNiSYye3mwxbHr1kO/yXpqP54HIUz8vmfdCkwK9fFUrTH5uB0LPHEJuYpnP+ux oIsraVe9QgB2MCxKuxLwKOOnwzO2LmEFMm3NaeH8wBQjIw4oc+M3TGBlnP+fBgAmOpjj C1aBDe1dGG2pHu6u65BvPGcb9w/lGoqpjwgrvXHlgxIBU38PIUD7gYIcCgiFEnlkbZeO 2l5y7PX8gYxiJXUcY8k/x+/pzx219Y49rjXt/pxqqvWVnEKHbfq6QkB2vQxIb9+n5Gdn xeeSOxwWnKQ8SRbGU8FoGa8Vlnivy0a84VIm7ExTh1ScOuHX54YdY6GwAh5875rFL3og 5HUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893569; x=1751498369; 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=98Jyj99BUXTmYd7+cithe+PSs3lV4fLVI7wtqO1MqXk=; b=Xp6T+jtSJMbB+3zbQGTgwgPYYBs0ZToyIcPkEx/8AuOk728qkm6ZRY7uLfqy7W9Pus 2tPQuyhJuUfFZEMLMe4qJSG5wR2dYm532POpUSric8Rf5R/jFXMLCQVHDHIj2uzz8WIc hV5/CwrQ8UnAT02AC396E3EXe7NUbok6TA2aYuTJ6tXymdUsihU/enH7uqcdlHxjnOQl Nr2ogpgd18kC+D3PV9K5/rkMIWXeFXD7UiwjI8MZLkzGwqSAwov/v5kuq/+zfj4liScT WUW8eCdYuC0Si2LcQOVzP5Yu2ttBZApsXETVZTzSEzHtmeN9bGMp+YIJtEQmlJQxP/+D QV8Q== X-Forwarded-Encrypted: i=1; AJvYcCVhbrb6Qz/Tfo58rtI2b8iVcbeB10Fl6ZkEEiG3a2dCB7/cENKiouNBU+IODq3UcLgaOuw/3NQLvfZxJaY=@vger.kernel.org X-Gm-Message-State: AOJu0YwHru4MHTVhdj0FeaPP8OLn3fS3hYxdil3JOTBKzINibV1Z07XW BGPxmY8mnexoIc/YqLWAnbMrU/1OsA7amplvDWbtJV2LAh1oWPe1gzUKCAOPXLx1na8= X-Gm-Gg: ASbGncuF41Jbz9WLKllP8m5WgEf/uwlarEEorPxQVwyhrHnKjb99mWELrAVXKL6ibJ6 dVItE/hNcq8Fygm0zfoEGtUy2IYDCoYNf2jRBRJ4jOhrtOMCQLhP8i3mNJ0UoPXGS3EmzOvaWM+ cqqFEYrJIu4sLvUzHR45eGqBcnTaTzQpgZ+Zsj9WMecHUcZkL5I+Xos2FXdh0qvE0v1jCXhhvEq dQLVTm/TPbA2NX0sUSnHlx8BGDHQlMs2WhAZhJw5Tf0uZMpfw3INtHIoy3GleFyDCCsJh7PGJWe +216Q1aiTvjAXBZKg5CiAOYAZ0DG1azYEhDN+RuXwH/GHiuy0TvOZMJ3zb8+zce0lrusJVR1xpH oCM6XiVRnyIki6TklspfD/FOoCvAsrov5bT6IIyK/HxP3UFo8CDu44whgUQbUgb0= X-Google-Smtp-Source: AGHT+IF8jNEFtQnuXkjTXZtOG0o687rs+JjV2eGPA9YX8TPfu5/LIAkdaGG0i8hzaFHLmFqpeuhnQw== X-Received: by 2002:a05:6902:e12:b0:e7d:ca07:ae7d with SMTP id 3f1490d57ef6-e86017c3da5mr6432810276.33.1750893568719; Wed, 25 Jun 2025 16:19:28 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:28 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 26/32] mm: shmem: allow freezing inode mapping Date: Wed, 25 Jun 2025 23:18:13 +0000 Message-ID: <20250625231838.1897085-27-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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: Pratyush Yadav To prepare a shmem inode for live update via the Live Update Orchestrator (LUO), its index -> folio mappings must be serialized. Once the mappings are serialized, they cannot change since it would cause the serialized data to become inconsistent. This can be done by pinning the folios to avoid migration, and by making sure no folios can be added to or removed from the inode. While mechanisms to pin folios already exist, the only way to stop folios being added or removed are the grow and shrink file seals. But file seals come with their own semantics, one of which is that they can't be removed. This doesn't work with liveupdate since it can be cancelled or error out, which would need the seals to be removed and the file's normal functionality to be restored. Introduce SHMEM_F_MAPPING_FROZEN to indicate this instead. It is internal to shmem and is not directly exposed to userspace. It functions similar to F_SEAL_GROW | F_SEAL_SHRINK, but additionally disallows hole punching, and can be removed. Signed-off-by: Pratyush Yadav Signed-off-by: Pasha Tatashin --- include/linux/shmem_fs.h | 17 +++++++++++++++++ mm/shmem.c | 12 +++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 578a5f3d1935..1dd2aad0986b 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -22,6 +22,14 @@ #define SHMEM_F_NORESERVE BIT(0) /* Disallow swapping. */ #define SHMEM_F_LOCKED BIT(1) +/* + * Disallow growing, shrinking, or hole punching in the inode. Combined wi= th + * folio pinning, makes sure the inode's mapping stays fixed. + * + * In some ways similar to F_SEAL_GROW | F_SEAL_SHRINK, but can be removed= and + * isn't directly visible to userspace. + */ +#define SHMEM_F_MAPPING_FROZEN BIT(2) =20 struct shmem_inode_info { spinlock_t lock; @@ -183,6 +191,15 @@ static inline bool shmem_file(struct file *file) return shmem_mapping(file->f_mapping); } =20 +/* Must be called with inode lock taken exclusive. */ +static inline void shmem_i_mapping_freeze(struct inode *inode, bool freeze) +{ + if (freeze) + SHMEM_I(inode)->flags |=3D SHMEM_F_MAPPING_FROZEN; + else + SHMEM_I(inode)->flags &=3D ~SHMEM_F_MAPPING_FROZEN; +} + /* * If fallocate(FALLOC_FL_KEEP_SIZE) has been used, there may be pages * beyond i_size's notion of EOF, which fallocate has committed to reservi= ng: diff --git a/mm/shmem.c b/mm/shmem.c index 953d89f62882..bd54300be9df 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1297,7 +1297,8 @@ static int shmem_setattr(struct mnt_idmap *idmap, loff_t newsize =3D attr->ia_size; =20 /* protected by i_rwsem */ - if ((newsize < oldsize && (info->seals & F_SEAL_SHRINK)) || + if ((info->flags & SHMEM_F_MAPPING_FROZEN) || + (newsize < oldsize && (info->seals & F_SEAL_SHRINK)) || (newsize > oldsize && (info->seals & F_SEAL_GROW))) return -EPERM; =20 @@ -3291,6 +3292,10 @@ shmem_write_begin(struct file *file, struct address_= space *mapping, return -EPERM; } =20 + if (unlikely((info->flags & SHMEM_F_MAPPING_FROZEN) && + pos + len > inode->i_size)) + return -EPERM; + ret =3D shmem_get_folio(inode, index, pos + len, &folio, SGP_WRITE); if (ret) return ret; @@ -3664,6 +3669,11 @@ static long shmem_fallocate(struct file *file, int m= ode, loff_t offset, =20 inode_lock(inode); =20 + if (info->flags & SHMEM_F_MAPPING_FROZEN) { + error =3D -EPERM; + goto out; + } + if (mode & FALLOC_FL_PUNCH_HOLE) { struct address_space *mapping =3D file->f_mapping; loff_t unmap_start =3D round_up(offset, PAGE_SIZE); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 5100A3093BC for ; Wed, 25 Jun 2025 23:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893573; cv=none; b=jMVTmMLk6NjIABBKrtIRzFFr0/O88NfRH8Z+jQKzdPCvDF8CP+Qr7vHaM0KRl+zXrdO0SqumuGd/T4/Xdwp9Wp218EN7A0gaS9XQgImIX26bRF73Xn87UCVGGwbszO11ajENz6eXxYchAWEyYzdBNLiM5nRIxbD4IQKbX5XKdzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893573; c=relaxed/simple; bh=rOKb5+BagbcTuwgLuWWQhxdztCUhJ4cU96gHLwWmcIg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xl78WnHDCYFL2su0THw5ibU1yiGg9h+QY0/Wr80YaXR0f3FzcQgFUerzJqhcX6S4XVHXEiqawA3TwmvFIIIVncaOVxRiJ4earCdOngNDIiQu/IbA32H+hyb27Cb8QF+RG4Bh5pmZbl/ZczQmjiuAsfrMnwa0HJS4P0SK3Ex8Nms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=oVBHKn2c; arc=none smtp.client-ip=209.85.219.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="oVBHKn2c" Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e81826d5b72so297586276.3 for ; Wed, 25 Jun 2025 16:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893570; x=1751498370; 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=NY4/VNSyW9YlnxXNwTl0Byyb+JX9t6CMuRa83xOM3rg=; b=oVBHKn2cRAoN/aMCcBAlVdvcThXOVeaxrjZGLJBbr/+i6wKYbOv6VXKqB5DryqXkCq nOkDhnP/NuM7MjqaIwPkdisn7ZC5OfWFnHQYgDLb1jfGm4XkdLBvrvQatPSDB40CUJFG 6Gz4vpK8mFUZY6y2Kd0aEmqODot5YL8kOJBZj//ggAvYzN6mdWsVOlVSW+8jZvJYMedk e6JdJV6hOXdwHR8PZdrosr/CzIyL62UGpV0jxfmxrjWvxXZDA3h0r1JwykmHfE9f46cR 1/licXWeOY9bUgx1pfvsCgNPAyaMTblGL3B4IDUw0AgY4nH7KTTed1Bfe5uCPLIPTrRK U6yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893570; x=1751498370; 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=NY4/VNSyW9YlnxXNwTl0Byyb+JX9t6CMuRa83xOM3rg=; b=o2YiWSlO2oF4QVwTJRFXP6myVMRbHEFLr/qEPC/YBQRheQCrRbZVrXBszYXOLVVVaJ GuR2VRcuAV776Hm8FCZ3KI4BZOUrpgrZeWJjbVVK2zzsu/0GO3ezjpwmXHdxAEiFIIOo vBVtZSGbyrWVJl3fSAbo0BJN1Cvr9YxCb2VH2z7MCJ1450kwbKp/KdZn9hWV8c5q24cN qcnDf8yCdR9LREaV6GsA4cbmRlLvjsNDbRVH1g2bTgEqxAm0JBIkYerOHQUrFsr54PpM hP9gQfQ+xa/zPOgsJFs2NNn89t4dnRLClgMUuiKXtRWd6LL+CrVbKuR28+ZVyYqlE9CB 3GqQ== X-Forwarded-Encrypted: i=1; AJvYcCXxyviCU0/XLLIfiiRmGE6W87MrAks0myw3T4+RpQgUQpjwp9upI52I0Ey/gSglUY65PrQf+hum0IxQMLU=@vger.kernel.org X-Gm-Message-State: AOJu0YzfweOohf3axXpaeO6jD08Ss1BTLSLJmduUxNuIAhhSM7r35w1q 47RKeC0G+GyNIM4MBg1JdH002COqs2x/KHM9ynL9lgZiPelxQGQjE9MBicOkOvfMNyA= X-Gm-Gg: ASbGnctxpMGCs8g4y47GBZapEjwLv+mm9EWd/8s2x6q9NnQSXHRiQBSm3NBZL6RGu9U /Ao4vkifIl4tkhLwFDh3ZenOJ4kHpUezYnnzh9Oxq5o8//eAEyGJM+dxw5sYgKooxWr8jMQ6OAG gvaQVJKx61bqQr7q+vj+V6PEyv0AzISp+kYx/jsF0h13m07LaKXlIS4o7+1OpMyF32YF1fPsO5/ veKEfqqnJ73h8LZ855A1rUpb7QCM7ehQUoW6ZApHhIZmmvdzbL0o5hR2oIo4EiIh78OcuOLjDKA lFKqcnUMyaOwg6dG+BSswwhghzZwgSFHoUIiJPLmB9TtBbiTk0zUvX5xJSQv21wuCqBtgNhbXAM +/HdzumXIXahIqXYqDCWVX+wnw6H48GF/jShUP61Paa7tbNHJ2opN X-Google-Smtp-Source: AGHT+IGdHj0p3bmRxWLsDFiXYVaVe2cuSu6WHMbrQ2HB2wcjVrL2gKyMQpNe1r2lroh5MvOICjseMg== X-Received: by 2002:a05:6902:907:b0:e7d:ce24:636e with SMTP id 3f1490d57ef6-e860176598bmr6101524276.31.1750893570357; Wed, 25 Jun 2025 16:19:30 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:29 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 27/32] mm: shmem: export some functions to internal.h Date: Wed, 25 Jun 2025 23:18:14 +0000 Message-ID: <20250625231838.1897085-28-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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: Pratyush Yadav shmem_inode_acct_blocks(), shmem_recalc_inode(), and shmem_add_to_page_cache() are used by shmem_alloc_and_add_folio(). This functionality will also be used in the future by Live Update Orchestrator (LUO) to recreate memfd files after a live update. Signed-off-by: Pratyush Yadav Signed-off-by: Pasha Tatashin --- mm/internal.h | 6 ++++++ mm/shmem.c | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 6b8ed2017743..991917a8ae23 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1535,6 +1535,12 @@ void __meminit __init_page_from_nid(unsigned long pf= n, int nid); unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memc= g, int priority); =20 +int shmem_add_to_page_cache(struct folio *folio, + struct address_space *mapping, + pgoff_t index, void *expected, gfp_t gfp); +int shmem_inode_acct_blocks(struct inode *inode, long pages); +void shmem_recalc_inode(struct inode *inode, long alloced, long swapped); + #ifdef CONFIG_SHRINKER_DEBUG static inline __printf(2, 0) int shrinker_debugfs_name_alloc( struct shrinker *shrinker, const char *fmt, va_list ap) diff --git a/mm/shmem.c b/mm/shmem.c index bd54300be9df..5fd0fb214a78 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -219,7 +219,7 @@ static inline void shmem_unacct_blocks(unsigned long fl= ags, long pages) vm_unacct_memory(pages * VM_ACCT(PAGE_SIZE)); } =20 -static int shmem_inode_acct_blocks(struct inode *inode, long pages) +int shmem_inode_acct_blocks(struct inode *inode, long pages) { struct shmem_inode_info *info =3D SHMEM_I(inode); struct shmem_sb_info *sbinfo =3D SHMEM_SB(inode->i_sb); @@ -433,7 +433,7 @@ static void shmem_free_inode(struct super_block *sb, si= ze_t freed_ispace) * But normally info->alloced =3D=3D inode->i_mapping->nrpages + info->s= wapped * So mm freed is info->alloced - (inode->i_mapping->nrpages + info->swapp= ed) */ -static void shmem_recalc_inode(struct inode *inode, long alloced, long swa= pped) +void shmem_recalc_inode(struct inode *inode, long alloced, long swapped) { struct shmem_inode_info *info =3D SHMEM_I(inode); long freed; @@ -879,9 +879,9 @@ static void shmem_update_stats(struct folio *folio, int= nr_pages) /* * Somewhat like filemap_add_folio, but error if expected item has gone. */ -static int shmem_add_to_page_cache(struct folio *folio, - struct address_space *mapping, - pgoff_t index, void *expected, gfp_t gfp) +int shmem_add_to_page_cache(struct folio *folio, + struct address_space *mapping, + pgoff_t index, void *expected, gfp_t gfp) { XA_STATE_ORDER(xas, &mapping->i_pages, index, folio_order(folio)); long nr =3D folio_nr_pages(folio); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.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 1EAC02FCFFE for ; Wed, 25 Jun 2025 23:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893575; cv=none; b=hIewMVk4NzkHbl7J5pJwnYiWD1TE56zl0Qn13zkIovUzQUTfDe8xmHUMx4UPMJ84tXz7j+AECPTXzz2vgSXmkPlkegu97vE1HjGQp/CS3Xm3lcrarZsjDcaHGor6Acd34ddi4S3t+HPF5RR9ei71YAYxH5FXiEn9lWLtYqzsLZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893575; c=relaxed/simple; bh=SUhfiaRdom8GiwIhJ8wQMxYxsTjqLfGzP5+hkUDllOo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hP3QjtGPPlVY/FiVsynIG6+v34/rcgQU9zTvDAbj5oQ8HkJDXBEyLbOKg41+rf/hZo9IbXjLKy/Z1nx1L0uKH2Y9kT5JRzMm0+tfIRLbYU7py2qdPz8dTrTi2wU66oYle3Sruqv03QdQ3aSUxGBfiv+RpvZXj9jUUx7dRhFOF3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=F2Lhy7YB; arc=none smtp.client-ip=209.85.219.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="F2Lhy7YB" Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-e733a6ff491so315270276.2 for ; Wed, 25 Jun 2025 16:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893572; x=1751498372; 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=RO9J/1O/UI39hg/+jcvh/jRjoHLl2cHs/8R58PXGL84=; b=F2Lhy7YB1bGxzjs8ds+Is+bh6ADv4Y96vttsIJMLSSPOh+wHKOKm1LLsq9qJIFDfgh wqCtSVNrapeCIMIEQfE4YE+v6qQiA6VF9W0xCmcr0F9I9rx6ragFcDtE2fdemnMtLijB eJa78XB/wXRDjxkkhlFZDA6glvm7g2+NXGYa1qklk+eKBXWrUG6Y2qwTgl4yJIoKW80m 4KhzSQkAqanS+yz6NNXmdAlK2WZZqJQgLkqpU7Fo/noBO8MrQkjqJMCsShW5yGG2eOej zPi/Kf1QdRJqjdWSdppae0B2aBhuWu0uJX639ixFUOdvNr7pXG9YucoItNMGyXUUrVLn qPvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893572; x=1751498372; 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=RO9J/1O/UI39hg/+jcvh/jRjoHLl2cHs/8R58PXGL84=; b=geOYLZcTkN055oreOUHUdMSTMufuCpSns5y9G3Gy1hsY+LmNH6GsHmKJlaRyJXI/b3 xQhjZkIHrUV6Z1lf6YMK1xf7fS0l2hBLH4YQRq3u9H2UIZG//sSNotnbUsiOnUJ6xJzy 3HPqF4q1aRaPlCZVX7uETbAnSPrHgNKtfdLecc7I/J2CpqzyUoFEGdep7oiEypgeE/S9 PAKEgDvvCOrwaX64ne4yPOYOuphz1F4kGUu3t8885imXL0zBLZn3lEsMEr+OWl3MsbDV yFkjO4CJEMoX3D23dGRkzEgCT7zQmDJS4Jrgw2QaywAWszFLlk1n6O4VymGDySLGAqSF AuqQ== X-Forwarded-Encrypted: i=1; AJvYcCU/u0u6fPIumsm3cs2awV+W70SqdAn3/hATBPjUaYPphFKZJ2bzxMtprM+LksCYBLEL6pV8o627kBgKBRA=@vger.kernel.org X-Gm-Message-State: AOJu0YxlQup8BemZQr/7BrEEIAQKD01+f6qYAmadslTqfvVDo0id/Md9 W0lWPPur0hDp8xDeoiYqD9b8ZTMkn+QO8EVgso5bUe1Ze1CpzGEa1djZs+7HKT2aq+0= X-Gm-Gg: ASbGncsLJMHVHGeJ0VNkKtwLX9Jtx/a/49XhZwVFtsIShnCayvZrYiqgQk6JYykLJoA TtKo91sJStjMG7Kt5Ld1Gqy4twaDM/g/Wshtt63BIS9EhfTo2FH6g7ZhEvTjekyrOLpPBh7Cv1t Tt/Qwal3VoWZuow4xH0tWoiP9c4wooGSZYANftHw8uDKmCuot5jvdiMiPXyqZ+5OA1/O2Aq/YYn JIFnsIBJPG/sMjvk2dfG2PEX0MqxEX91kucMv9fI1pM5UddofV3qDkJbOuK6uOJMtaMWEYZJunl gzOFJgXCmGuh3RW1nsEoEH4tfA5jiVBZw2Tx9DK/Rv1hVsU1wM8SKiFZNW0mCDuCFAtU9I9KqKk C5VnRUsDQdgNP03nJfgGJgKMk8Zu5SQdoHRoeDVgtRQNtSJ0Lckh8 X-Google-Smtp-Source: AGHT+IEHduHWl+pOl18uO8sqkAHlRHUmh8yA8zbZaW9a7AAvhsk7bTscKnxbnJ0nK8vdM9txokq8qQ== X-Received: by 2002:a05:6902:1247:b0:e82:24ae:c3ae with SMTP id 3f1490d57ef6-e8601725ac2mr6883222276.21.1750893572044; Wed, 25 Jun 2025 16:19:32 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:31 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 28/32] luo: allow preserving memfd Date: Wed, 25 Jun 2025 23:18:15 +0000 Message-ID: <20250625231838.1897085-29-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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: Pratyush Yadav The ability to preserve a memfd allows userspace to use KHO and LUO to transfer its memory contents to the next kernel. This is useful in many ways. For one, it can be used with IOMMUFD as the backing store for IOMMU page tables. Preserving IOMMUFD is essential for performing a hypervisor live update with passthrough devices. memfd support provides the first building block for making that possible. For another, applications with a large amount of memory that takes time to reconstruct, reboots to consume kernel upgrades can be very expensive. memfd with LUO gives those applications reboot-persistent memory that they can use to quickly save and reconstruct that state. While memfd is backed by either hugetlbfs or shmem, currently only support on shmem is added. To be more precise, support for anonymous shmem files is added. The handover to the next kernel is not transparent. All the properties of the file are not preserved; only its memory contents, position, and size. The recreated file gets the UID and GID of the task doing the restore, and the task's cgroup gets charged with the memory. After LUO is in prepared state, the file cannot grow or shrink, and all its pages are pinned to avoid migrations and swapping. The file can still be read from or written to. Co-developed-by: Changyuan Lyu Signed-off-by: Changyuan Lyu Co-developed-by: Pasha Tatashin Signed-off-by: Pasha Tatashin Signed-off-by: Pratyush Yadav --- MAINTAINERS | 2 + mm/Makefile | 1 + mm/memfd_luo.c | 501 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 504 insertions(+) create mode 100644 mm/memfd_luo.c diff --git a/MAINTAINERS b/MAINTAINERS index 90554f3a1bec..163f38cd55b5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14011,6 +14011,7 @@ F: tools/testing/selftests/livepatch/ =20 LIVE UPDATE M: Pasha Tatashin +R: Pratyush Yadav L: linux-kernel@vger.kernel.org S: Maintained F: Documentation/ABI/testing/sysfs-kernel-liveupdate @@ -14020,6 +14021,7 @@ F: Documentation/userspace-api/liveupdate.rst F: include/linux/liveupdate.h F: include/uapi/linux/liveupdate.h F: kernel/liveupdate/ +F: mm/memfd_luo.c F: tools/testing/selftests/liveupdate/ =20 LLC (802.2) diff --git a/mm/Makefile b/mm/Makefile index 1a7a11d4933d..63cca66c068a 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -100,6 +100,7 @@ obj-$(CONFIG_NUMA) +=3D memory-tiers.o obj-$(CONFIG_DEVICE_MIGRATION) +=3D migrate_device.o obj-$(CONFIG_TRANSPARENT_HUGEPAGE) +=3D huge_memory.o khugepaged.o obj-$(CONFIG_PAGE_COUNTER) +=3D page_counter.o +obj-$(CONFIG_LIVEUPDATE) +=3D memfd_luo.o obj-$(CONFIG_MEMCG_V1) +=3D memcontrol-v1.o obj-$(CONFIG_MEMCG) +=3D memcontrol.o vmpressure.o ifdef CONFIG_SWAP diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c new file mode 100644 index 000000000000..339824ab6729 --- /dev/null +++ b/mm/memfd_luo.c @@ -0,0 +1,501 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + * Changyuan Lyu + * + * Copyright (C) 2025 Amazon.com Inc. or its affiliates. + * Pratyush Yadav + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include "internal.h" + +static const char memfd_luo_compatible[] =3D "memfd-v1"; + +#define PRESERVED_PFN_MASK GENMASK(63, 12) +#define PRESERVED_PFN_SHIFT 12 +#define PRESERVED_FLAG_DIRTY BIT(0) +#define PRESERVED_FLAG_UPTODATE BIT(1) + +#define PRESERVED_FOLIO_PFN(desc) (((desc) & PRESERVED_PFN_MASK) >> PRESER= VED_PFN_SHIFT) +#define PRESERVED_FOLIO_FLAGS(desc) ((desc) & ~PRESERVED_PFN_MASK) +#define PRESERVED_FOLIO_MKDESC(pfn, flags) (((pfn) << PRESERVED_PFN_SHIFT)= | (flags)) + +struct memfd_luo_preserved_folio { + /* + * The folio descriptor is made of 2 parts. The bottom 12 bits are used + * for storing flags, the others for storing the PFN. + */ + u64 foliodesc; + u64 index; +}; + +static int memfd_luo_preserve_folios(struct memfd_luo_preserved_folio *pfo= lios, + struct folio **folios, + unsigned int nr_folios) +{ + unsigned int i; + int err; + + for (i =3D 0; i < nr_folios; i++) { + struct memfd_luo_preserved_folio *pfolio =3D &pfolios[i]; + struct folio *folio =3D folios[i]; + unsigned int flags =3D 0; + unsigned long pfn; + + err =3D kho_preserve_folio(folio); + if (err) + goto err_unpreserve; + + pfn =3D folio_pfn(folio); + if (folio_test_dirty(folio)) + flags |=3D PRESERVED_FLAG_DIRTY; + if (folio_test_uptodate(folio)) + flags |=3D PRESERVED_FLAG_UPTODATE; + + pfolio->foliodesc =3D PRESERVED_FOLIO_MKDESC(pfn, flags); + pfolio->index =3D folio->index; + } + + return 0; + +err_unpreserve: + i--; + for (; i >=3D 0; i--) + WARN_ON_ONCE(kho_unpreserve_folio(folios[i])); + return err; +} + +static void memfd_luo_unpreserve_folios(const struct memfd_luo_preserved_f= olio *pfolios, + unsigned int nr_folios) +{ + unsigned int i; + + for (i =3D 0; i < nr_folios; i++) { + const struct memfd_luo_preserved_folio *pfolio =3D &pfolios[i]; + struct folio *folio; + + if (!pfolio->foliodesc) + continue; + + folio =3D pfn_folio(PRESERVED_FOLIO_PFN(pfolio->foliodesc)); + + kho_unpreserve_folio(folio); + unpin_folio(folio); + } +} + +static void *memfd_luo_create_fdt(unsigned long size) +{ + unsigned int order =3D get_order(size); + struct folio *fdt_folio; + int err =3D 0; + void *fdt; + + if (order > MAX_PAGE_ORDER) + return NULL; + + fdt_folio =3D folio_alloc(GFP_KERNEL, order); + if (!fdt_folio) + return NULL; + + fdt =3D folio_address(fdt_folio); + + err |=3D fdt_create(fdt, (1 << (order + PAGE_SHIFT))); + err |=3D fdt_finish_reservemap(fdt); + err |=3D fdt_begin_node(fdt, ""); + if (err) + goto free; + + return fdt; + +free: + folio_put(fdt_folio); + return NULL; +} + +static int memfd_luo_finish_fdt(void *fdt) +{ + int err; + + err =3D fdt_end_node(fdt); + if (err) + return err; + + return fdt_finish(fdt); +} + +static int memfd_luo_prepare(struct file *file, void *arg, u64 *data) +{ + struct memfd_luo_preserved_folio *preserved_folios; + struct inode *inode =3D file_inode(file); + unsigned int max_folios, nr_folios =3D 0; + int err =3D 0, preserved_size; + struct folio **folios; + long size, nr_pinned; + pgoff_t offset; + void *fdt; + u64 pos; + + if (WARN_ON_ONCE(!shmem_file(file))) + return -EINVAL; + + inode_lock(inode); + shmem_i_mapping_freeze(inode, true); + + size =3D i_size_read(inode); + if ((PAGE_ALIGN(size) / PAGE_SIZE) > UINT_MAX) { + err =3D -E2BIG; + goto err_unlock; + } + + /* + * Guess the number of folios based on inode size. Real number might end + * up being smaller if there are higher order folios. + */ + max_folios =3D PAGE_ALIGN(size) / PAGE_SIZE; + folios =3D kvmalloc_array(max_folios, sizeof(*folios), GFP_KERNEL); + if (!folios) { + err =3D -ENOMEM; + goto err_unfreeze; + } + + /* + * Pin the folios so they don't move around behind our back. This also + * ensures none of the folios are in CMA -- which ensures they don't + * fall in KHO scratch memory. It also moves swapped out folios back to + * memory. + * + * A side effect of doing this is that it allocates a folio for all + * indices in the file. This might waste memory on sparse memfds. If + * that is really a problem in the future, we can have a + * memfd_pin_folios() variant that does not allocate a page on empty + * slots. + */ + nr_pinned =3D memfd_pin_folios(file, 0, size - 1, folios, max_folios, + &offset); + if (nr_pinned < 0) { + err =3D nr_pinned; + pr_err("failed to pin folios: %d\n", err); + goto err_free_folios; + } + /* nr_pinned won't be more than max_folios which is also unsigned int. */ + nr_folios =3D (unsigned int)nr_pinned; + + preserved_size =3D sizeof(struct memfd_luo_preserved_folio) * nr_folios; + if (check_mul_overflow(sizeof(struct memfd_luo_preserved_folio), + nr_folios, &preserved_size)) { + err =3D -E2BIG; + goto err_unpin; + } + + /* + * Most of the space should be taken by preserved folios. So take its + * size, plus a page for other properties. + */ + fdt =3D memfd_luo_create_fdt(PAGE_ALIGN(preserved_size) + PAGE_SIZE); + if (!fdt) { + err =3D -ENOMEM; + goto err_unpin; + } + + pos =3D file->f_pos; + err =3D fdt_property(fdt, "pos", &pos, sizeof(pos)); + if (err) + goto err_free_fdt; + + err =3D fdt_property(fdt, "size", &size, sizeof(size)); + if (err) + goto err_free_fdt; + + err =3D fdt_property_placeholder(fdt, "folios", preserved_size, + (void **)&preserved_folios); + if (err) { + pr_err("Failed to reserve folios property in FDT: %s\n", + fdt_strerror(err)); + err =3D -ENOMEM; + goto err_free_fdt; + } + + err =3D memfd_luo_preserve_folios(preserved_folios, folios, nr_folios); + if (err) + goto err_free_fdt; + + err =3D memfd_luo_finish_fdt(fdt); + if (err) + goto err_unpreserve; + + err =3D kho_preserve_folio(virt_to_folio(fdt)); + if (err) + goto err_unpreserve; + + kvfree(folios); + inode_unlock(inode); + + *data =3D virt_to_phys(fdt); + return 0; + +err_unpreserve: + memfd_luo_unpreserve_folios(preserved_folios, nr_folios); +err_free_fdt: + folio_put(virt_to_folio(fdt)); +err_unpin: + unpin_folios(folios, nr_pinned); +err_free_folios: + kvfree(folios); +err_unfreeze: + shmem_i_mapping_freeze(inode, false); +err_unlock: + inode_unlock(inode); + return err; +} + +static int memfd_luo_freeze(struct file *file, void *arg, u64 *data) +{ + u64 pos =3D file->f_pos; + void *fdt; + int err; + + if (WARN_ON_ONCE(!*data)) + return -EINVAL; + + fdt =3D phys_to_virt(*data); + + /* + * The pos or size might have changed since prepare. Everything else + * stays the same. + */ + err =3D fdt_setprop(fdt, 0, "pos", &pos, sizeof(pos)); + if (err) + return err; + + return 0; +} + +static void memfd_luo_cancel(struct file *file, void *arg, u64 data) +{ + const struct memfd_luo_preserved_folio *pfolios; + struct inode *inode =3D file_inode(file); + struct folio *fdt_folio; + void *fdt; + int len; + + if (WARN_ON_ONCE(!data)) + return; + + inode_lock(inode); + shmem_i_mapping_freeze(inode, false); + + fdt =3D phys_to_virt(data); + fdt_folio =3D virt_to_folio(fdt); + pfolios =3D fdt_getprop(fdt, 0, "folios", &len); + if (pfolios) + memfd_luo_unpreserve_folios(pfolios, len / sizeof(*pfolios)); + + kho_unpreserve_folio(fdt_folio); + folio_put(fdt_folio); + inode_unlock(inode); +} + +static struct folio *memfd_luo_get_fdt(u64 data) +{ + return kho_restore_folio((phys_addr_t)data); +} + +static void memfd_luo_finish(struct file *file, void *arg, u64 data, + bool reclaimed) +{ + const struct memfd_luo_preserved_folio *pfolios; + struct folio *fdt_folio; + int len; + + if (reclaimed) + return; + + fdt_folio =3D memfd_luo_get_fdt(data); + + pfolios =3D fdt_getprop(folio_address(fdt_folio), 0, "folios", &len); + if (pfolios) + memfd_luo_unpreserve_folios(pfolios, len / sizeof(*pfolios)); + + folio_put(fdt_folio); +} + +static int memfd_luo_retrieve(void *arg, u64 data, struct file **file_p) +{ + const struct memfd_luo_preserved_folio *pfolios; + int nr_pfolios, len, ret =3D 0, i =3D 0; + struct address_space *mapping; + struct folio *folio, *fdt_folio; + const u64 *pos, *size; + struct inode *inode; + struct file *file; + const void *fdt; + + fdt_folio =3D memfd_luo_get_fdt(data); + if (!fdt_folio) + return -ENOENT; + + fdt =3D page_to_virt(folio_page(fdt_folio, 0)); + + pfolios =3D fdt_getprop(fdt, 0, "folios", &len); + if (!pfolios || len % sizeof(*pfolios)) { + pr_err("invalid 'folios' property\n"); + ret =3D -EINVAL; + goto put_fdt; + } + nr_pfolios =3D len / sizeof(*pfolios); + + size =3D fdt_getprop(fdt, 0, "size", &len); + if (!size || len !=3D sizeof(u64)) { + pr_err("invalid 'size' property\n"); + ret =3D -EINVAL; + goto put_folios; + } + + pos =3D fdt_getprop(fdt, 0, "pos", &len); + if (!pos || len !=3D sizeof(u64)) { + pr_err("invalid 'pos' property\n"); + ret =3D -EINVAL; + goto put_folios; + } + + file =3D shmem_file_setup("", 0, VM_NORESERVE); + + if (IS_ERR(file)) { + ret =3D PTR_ERR(file); + pr_err("failed to setup file: %d\n", ret); + goto put_folios; + } + + inode =3D file->f_inode; + mapping =3D inode->i_mapping; + vfs_setpos(file, *pos, MAX_LFS_FILESIZE); + + for (; i < nr_pfolios; i++) { + const struct memfd_luo_preserved_folio *pfolio =3D &pfolios[i]; + phys_addr_t phys; + u64 index; + int flags; + + if (!pfolio->foliodesc) + continue; + + phys =3D PFN_PHYS(PRESERVED_FOLIO_PFN(pfolio->foliodesc)); + folio =3D kho_restore_folio(phys); + if (!folio) { + pr_err("Unable to restore folio at physical address: %llx\n", + phys); + goto put_file; + } + index =3D pfolio->index; + flags =3D PRESERVED_FOLIO_FLAGS(pfolio->foliodesc); + + /* Set up the folio for insertion. */ + /* + * TODO: Should find a way to unify this and + * shmem_alloc_and_add_folio(). + */ + __folio_set_locked(folio); + __folio_set_swapbacked(folio); + + ret =3D mem_cgroup_charge(folio, NULL, mapping_gfp_mask(mapping)); + if (ret) { + pr_err("shmem: failed to charge folio index %d: %d\n", + i, ret); + goto unlock_folio; + } + + ret =3D shmem_add_to_page_cache(folio, mapping, index, NULL, + mapping_gfp_mask(mapping)); + if (ret) { + pr_err("shmem: failed to add to page cache folio index %d: %d\n", + i, ret); + goto unlock_folio; + } + + if (flags & PRESERVED_FLAG_UPTODATE) + folio_mark_uptodate(folio); + if (flags & PRESERVED_FLAG_DIRTY) + folio_mark_dirty(folio); + + ret =3D shmem_inode_acct_blocks(inode, 1); + if (ret) { + pr_err("shmem: failed to account folio index %d: %d\n", + i, ret); + goto unlock_folio; + } + + shmem_recalc_inode(inode, 1, 0); + folio_add_lru(folio); + folio_unlock(folio); + folio_put(folio); + } + + inode->i_size =3D *size; + *file_p =3D file; + folio_put(fdt_folio); + return 0; + +unlock_folio: + folio_unlock(folio); + folio_put(folio); +put_file: + fput(file); + i++; +put_folios: + for (; i < nr_pfolios; i++) { + const struct memfd_luo_preserved_folio *pfolio =3D &pfolios[i]; + + folio =3D kho_restore_folio(PRESERVED_FOLIO_PFN(pfolio->foliodesc)); + if (folio) + folio_put(folio); + } + +put_fdt: + folio_put(fdt_folio); + return ret; +} + +static bool memfd_luo_can_preserve(struct file *file, void *arg) +{ + struct inode *inode =3D file_inode(file); + + return shmem_file(file) && !inode->i_nlink; +} + +static const struct liveupdate_file_ops memfd_luo_file_ops =3D { + .prepare =3D memfd_luo_prepare, + .freeze =3D memfd_luo_freeze, + .cancel =3D memfd_luo_cancel, + .finish =3D memfd_luo_finish, + .retrieve =3D memfd_luo_retrieve, + .can_preserve =3D memfd_luo_can_preserve, +}; + +static struct liveupdate_file_handler memfd_luo_handler =3D { + .ops =3D &memfd_luo_file_ops, + .compatible =3D memfd_luo_compatible, +}; + +static int __init memfd_luo_init(void) +{ + int err; + + err =3D liveupdate_register_file_handler(&memfd_luo_handler); + if (err) + pr_err("Could not register luo filesystem handler: %d\n", err); + + return err; +} +late_initcall(memfd_luo_init); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.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 C4C68309DC5 for ; Wed, 25 Jun 2025 23:19:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893576; cv=none; b=P78f3ncI6pF2b3LTWYPCj8dlXJVtv080ZIWatD7k2/zQgt9Pag7/WKN9hx2DcGrC3t3P7rknNiHUaKiZqLaFbqVu7CYhkhBI1/LV+u/TPK+Ik2GbCeSBCcpdRBaoijMYucG7MRms4SR+kV55rJf66npbwiAuv8L5Gq0jX86h1Lc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893576; c=relaxed/simple; bh=b7MJffhHKyxoq2EEBO61UbwBKxqvQbmcAkEkF6dggFE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EfSem58iEP8l2bI4TSPZJ5gsv2M1S/nfDvUdibdZ+aI1/o1Kv7/Xwq5Ko7xhWtYxNbI4v+dCtRgwcqh9ypkKl6sLKYcYGDkhHV9FuFDWz3VuRsp8G6UP9R403cxV5m5Rahxlu3V/C/Qv/hxKB64gKLkzm/TaGmU6MPuE/DaGkqQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=IT36rwuh; arc=none smtp.client-ip=209.85.219.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="IT36rwuh" Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-e81f8679957so307007276.2 for ; Wed, 25 Jun 2025 16:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893574; x=1751498374; 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=zNUWS5sHgPJ3/TtkkLsM0l/sndwzOVEqU/iJZvqTlnw=; b=IT36rwuhwDmmedMvCUyDrVi9/mH+2eAr1RbqCkVG7JmutYiS0f7XpbdAF5Cxgn8mST jlUxHdXirzP+dJFDAE5RmZ11KkaZA+Xx7VGXbRP6aLV3MbBr5QQWYTAcRvJpHNTG/0Se b9qKnq6VKxgjsHQAh1mSa5HPWUYfZfEbd/VVVHDwsG7y/wdfUHxWW8LMvRjRdR6Ie0IM mPPHSZCBxBjTl4IjWfajJ/PLJbvrn3Pm948G4l5K2xI9Ym+SnM7esI38oqtI6AxcyP8k WrlaCpkrv391UwCPcLac1oc6iDlDoD8807B4W9sf7NXD3Np2fkvdegQOu5GBpyC45KQE bI+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893574; x=1751498374; 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=zNUWS5sHgPJ3/TtkkLsM0l/sndwzOVEqU/iJZvqTlnw=; b=h6PT6t2ipBS/QCznNalO1nYtgELw/KzYPpLQD24iJi7EwP4At24BmCgZjXa41UkqAC X9sPjo8+CzWrS86v4Q6IuicMlDCNK8bVA1x8egA6tuX6eRCwyj7LCINoSoKp+Q0bVQJ3 oPz9d0FMXUMbpZ0E2VM3TXn8WQ7WZLCDIcURUtKnpsLUGdZirTEEhu5h5ybKhJnTMM3Y nG/kSl7SVEeXntmkqWZw5Em9G51t3W7ZTLgNXTVdDMX9b9EOWzfAThF+BEWaVYgjk5Gx ZdAjJAr0CKsJ3Ol5WA1tYGS8l1V4Tis0aR/x829z1UiZW5gFs8+Rwoezf6QnrN1t/lwq 1VAQ== X-Forwarded-Encrypted: i=1; AJvYcCUB/cqOEAWqQbDPnsRPUi/hlBStB16VAAucxHXfFq2XoxhSQr2Z9ZVO2RzmlmvS+VoNtwgPY+WFiiNOYAE=@vger.kernel.org X-Gm-Message-State: AOJu0YwfAtmf8q+qIANFkl+ThWb+xCulGPGCYnXkc6XWHuAorCaYqWQQ Q9WfQ7xIMkZ34VuuMozq6v3hDHdgOn/dEITNnUIsJfhrQP1zHOF6jA6IcqLIWTVN3oM= X-Gm-Gg: ASbGnct7fHuMgV76Jha3FcD60DgWNGMa1D7R1F5hio2AAGf8acx6w/yGs0YKtGW+mnj HatnetVLfjvxaklZzAxZtK/P9Mg/bCto8tVvAze9vnwf2qq5vJv84m458WOqw5QC+2+D47UC0Um E8YXGaMhKic1qDSR/80bbH/Yu0HiZsPFONaLRz6Wln7CT3o/pH9khrouxQsErrJT93Lo23oaj8M 0U3Ty95ACfZ3dxuwNB9TCmW9FAWl5U7X7hP8t6nRjXTzS6PfrgPnzUBKsKiRoMvrHoolkrShLEC m9seGMtmI/MGaRNSlmM3jBKYQUZKt699i8GtlYZhYdgg9R658t3E7LIaGrqai2kjh6ghhcuJkQy Xk6vi/62B8I6mVHTEAvwqkkD368v/cyWjM7B06hBpXdxUknsTYr08 X-Google-Smtp-Source: AGHT+IFDGX7NrsfyyxA53ENg0MYMTOghBYuaJBxDrL4i/eRQ4joSzHgyrsvnmaeCiyZ/P1GWMue8rQ== X-Received: by 2002:a05:6902:278a:b0:e85:eac6:7ae5 with SMTP id 3f1490d57ef6-e860176b5e1mr6314395276.9.1750893573720; Wed, 25 Jun 2025 16:19:33 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:33 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 29/32] docs: add documentation for memfd preservation via LUO Date: Wed, 25 Jun 2025 23:18:16 +0000 Message-ID: <20250625231838.1897085-30-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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: Pratyush Yadav Add the documentation under the "Preserving file descriptors" section of LUO's documentation. The doc describes the properties preserved, behaviour of the file under different LUO states, serialization format, and current limitations. Signed-off-by: Pratyush Yadav Signed-off-by: Pasha Tatashin --- Documentation/core-api/liveupdate.rst | 7 ++ Documentation/mm/index.rst | 1 + Documentation/mm/memfd_preservation.rst | 138 ++++++++++++++++++++++++ MAINTAINERS | 1 + 4 files changed, 147 insertions(+) create mode 100644 Documentation/mm/memfd_preservation.rst diff --git a/Documentation/core-api/liveupdate.rst b/Documentation/core-api= /liveupdate.rst index 41c4b76cd3ec..232d5f623992 100644 --- a/Documentation/core-api/liveupdate.rst +++ b/Documentation/core-api/liveupdate.rst @@ -18,6 +18,13 @@ LUO Preserving File Descriptors .. kernel-doc:: kernel/liveupdate/luo_files.c :doc: LUO file descriptors =20 +The following types of file descriptors can be preserved + +.. toctree:: + :maxdepth: 1 + + ../mm/memfd_preservation + Public API =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D .. kernel-doc:: include/linux/liveupdate.h diff --git a/Documentation/mm/index.rst b/Documentation/mm/index.rst index d3ada3e45e10..97267567ef80 100644 --- a/Documentation/mm/index.rst +++ b/Documentation/mm/index.rst @@ -47,6 +47,7 @@ documentation, or deleted if it has served its purpose. hugetlbfs_reserv ksm memory-model + memfd_preservation mmu_notifier multigen_lru numa diff --git a/Documentation/mm/memfd_preservation.rst b/Documentation/mm/mem= fd_preservation.rst new file mode 100644 index 000000000000..416cd1dafc97 --- /dev/null +++ b/Documentation/mm/memfd_preservation.rst @@ -0,0 +1,138 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D +Memfd Preservation via LUO +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + +Overview +=3D=3D=3D=3D=3D=3D=3D=3D + +Memory file descriptors (memfd) can be preserved over a kexec using the Li= ve +Update Orchestrator (LUO) file preservation. This allows userspace to tran= sfer +its memory contents to the next kernel after a kexec. + +The preservation is not intended to be transparent. Only select properties= of +the file are preserved. All others are reset to default. The preserved +properties are described below. + +.. note:: + The LUO API is not stabilized yet, so the preserved properties of a mem= fd are + also not stable and are subject to backwards incompatible changes. + +.. note:: + Currently a memfd backed by Hugetlb is not supported. Memfds created + with ``MFD_HUGETLB`` will be rejected. + +Preserved Properties +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The following properties of the memfd are preserved across kexec: + +File Contents + All data stored in the file is preserved. + +File Size + The size of the file is preserved. Holes in the file are filled by alloc= ating + pages for them during preservation. + +File Position + The current file position is preserved, allowing applications to continue + reading/writing from their last position. + +File Status Flags + memfds are always opened with ``O_RDWR`` and ``O_LARGEFILE``. This prope= rty is + maintained. + +Non-Preserved Properties +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +All properties which are not preserved must be assumed to be reset to defa= ult. +This section describes some of those properties which may be more of note. + +``FD_CLOEXEC`` flag + A memfd can be created with the ``MFD_CLOEXEC`` flag that sets the + ``FD_CLOEXEC`` on the file. This flag is not preserved and must be set a= gain + after restore via ``fcntl()``. + +Seals + File seals are not preserved. The file is unsealed on restore and if nee= ded, + must be sealed again via ``fcntl()``. + +Behavior with LUO states +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This section described the behavior of the memfd in the different LUO stat= es. + +Normal Phase + During the normal phase, the memfd can be marked for preservation using = the + ``LIVEUPDATE_IOCTL_FD_PRESERVE`` ioctl. The memfd acts as a regular memfd + during this phase with no additional restrictions. + +Prepared Phase + After LUO enters ``LIVEUPDATE_STATE_PREPARED``, the memfd is serialized = and + prepared for the next kernel. During this phase, the below things happen: + + - All the folios are pinned. If some folios reside in ``ZONE_MIGRATE``, = they + are migrated out. This ensures none of the preserved folios land in KHO + scratch area. + - Pages in swap are swapped in. Currently, there is no way to pass pages= in + swap over KHO, so all swapped out pages are swapped back in and pinned. + - The memfd goes into "frozen mapping" mode. The file can no longer grow= or + shrink, or punch holes. This ensures the serialized mappings stay in s= ync. + The file can still be read from or written to or mmap-ed. + +Freeze Phase + Updates the current file position in the serialized data to capture any + changes that occurred between prepare and freeze phases. After this, the= FD is + not allowed to be accessed. + +Restoration Phase + After being restored, the memfd is functional as normal with the propert= ies + listed above restored. + +Cancellation + If the liveupdate is canceled after going into prepared phase, the memfd + functions like in normal phase. + +Serialization format +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The state is serialized in an FDT with the following structure:: + + /dts-v1/; + + / { + compatible =3D "memfd-v1"; + pos =3D ; + size =3D ; + folios =3D ; + }; + +Each folio descriptor contains: + +- PFN + flags (8 bytes) + + - Physical frame number (PFN) of the preserved folio (bits 63:12). + - Folio flags (bits 11:0): + + - ``PRESERVED_FLAG_DIRTY`` (bit 0) + - ``PRESERVED_FLAG_UPTODATE`` (bit 1) + +- Folio index within the file (8 bytes). + +Limitations +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The current implementation has the following limitations: + +Size + Currently the size of the file is limited by the size of the FDT. The FD= T can + be at of most ``MAX_PAGE_ORDER`` order. By default this is 4 MiB with 4K + pages. Each page in the file is tracked using 16 bytes. This limits the + maximum size of the file to 1 GiB. + +See Also +=3D=3D=3D=3D=3D=3D=3D=3D + +- :doc:`Live Update Orchestrator ` +- :doc:`/core-api/kho/concepts` diff --git a/MAINTAINERS b/MAINTAINERS index 163f38cd55b5..8114ce1be57b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14017,6 +14017,7 @@ S: Maintained F: Documentation/ABI/testing/sysfs-kernel-liveupdate F: Documentation/admin-guide/liveupdate.rst F: Documentation/core-api/liveupdate.rst +F: Documentation/mm/memfd_preservation.rst F: Documentation/userspace-api/liveupdate.rst F: include/linux/liveupdate.h F: include/uapi/linux/liveupdate.h --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.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 07FDD30AAA1 for ; Wed, 25 Jun 2025 23:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893580; cv=none; b=ItDhXULo7T6IeXnFfOZwp3/xrhXF3TULrMzt4bKTwMU3FJgWiT90tlHZCWn07mbxGoUDiKqC3x3XV0fPUbNsYJdF3OyWPKzWMTStV/od4h8GYOmfP2sBdCsWg5tLdU6RZ+hHrREwYG9errMlUXIwZlikckfqKVw8QLdoRo088rg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893580; c=relaxed/simple; bh=/nna6MIXrF5Zp48GX5twkIJWqsZGOIk93KP4HjO93qU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qr7DKm/XffAj8gWbD6HufndMMzLH1k2GjZT08FB2BiW/QbD/QwQTaPu5Ol3yB+rCGsYfI82g3JHvBwJdWwY750TKYGdqjSQsN0YNH+zrxDxlGvS5yNd28+SheEXAgnL2yFnG5HuchsyGtu39Q2kcs72P/hC/pBt4A//e/kWXROg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=Y/hURDP3; arc=none smtp.client-ip=209.85.219.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="Y/hURDP3" Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-e81826d5b72so297631276.3 for ; Wed, 25 Jun 2025 16:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893576; x=1751498376; 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=pUi0v/GxSz+WSWS/6QeH+6tUttoSr0t3HDQg0Yx0QwY=; b=Y/hURDP3Jux4zzmlFT55LrCywpclh8E2ITl4IKzFt2Zpt3G7rNkuNLAVMSmJF2JHnV YwFfEDeV66LYIKLXkk21nsQlHM+xWe9vOEBzFJJ+MgjntGqr7Y4bsax3ilM0hpfCv1W/ GjG0D5Hhz2Zf+JpsKZpeygrUZ0o2Icadk2mq4x+hy7CIZOAcc4PLe0XtQjSvNQyI6/um RmlcPZ+9ozhJggU/UV7ZLY5Cv71J5lmrcurzz1eFTZ93GoHMZkXyCAbskpl1zrlU4BDD y1ZaIu42umQ9USYYL0QotC7o+/xhDvUeONICKgBxzzIN1mPM1ZYBB6c2dEN+7SwMgkvz Ua8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893576; x=1751498376; 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=pUi0v/GxSz+WSWS/6QeH+6tUttoSr0t3HDQg0Yx0QwY=; b=tlviV9BI7AlsSYhcQBYFt4uZkE8StuimyopF7EBr3HvmwY5x4FI/T04JrI16wYes5O ZevJQVpJ1sw9/zd8W64STbSrIO1U3ZgaOfiyvlSBjMtu9jzTNmuMDbnVSIFan8zfTrQQ oAP6VfCDJIAx5MUpLVzUvpeu4IedT/FHXRXmOFInzGjggBJPwmexh3wXGbXMk4rK35Xh hWiznEfMC4VKmybwTAq9CljaZqMIfRaMlvfadPZl64WMySW2bIPRGa0sGSWxzZhqb8Ku gsG6kSEcqa5uHkeF3hHPXDo7PiATqa4AiRp/u4h4Fzs9O1HNkkMY6MFvl8zVWi6r5iba kNSg== X-Forwarded-Encrypted: i=1; AJvYcCXJ+HixtKaWTGxr8NT8+0RSmTQj064E0g5u8+mA8XR3yws2QxHJePveGav950L1li72d65u7NmxQE338vY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1IUK6ERkvaez9kPrjLRCVKlSajAGx69j9G+TJExCv8qCGRYtR hbFP9manTl2po2hgxhQVLo0Om268rrxlFN+4bZBMNbrJzzRgBrAqgPiy4QXxouYLVgs= X-Gm-Gg: ASbGncuRQ1iRM1aWQYK70Qnm3qhwDD3SoFFnHHlZUoiEcwaCQvUmp9YeVCF28t2+Tbh MYPUcZ2V+LqGTJMJ6hRn1AvZ7r5ljtX1KDc9GnO/r4i5BrXln2zyXYVCPEdttMQJpZf6ZPlmiR+ ieM/M2VJzo2ydF31M0lXhAcd9IbcQCIAU2YIfuu3voIsLiFw3brqW731NRmW6/YdMwyM+hekHVr 6MtMb83GCKMd17e7fciMwM3Qgy19p1S8RGaRuJgsYCpOHCrYY6xjFtoKgve67LDtVfTr6C8qamf l/6mKzGyLi6a8WIIvHDYZ3RWxANTIYiJ5K9gvBIoOH6iCPGGnkFw16fXYkoU2ts92od82E30Bi8 hFgA/G4TyujAWg5pF7Qg+GFZCxt9Z6UYEx3aqzZJ0mZQmiMcaUH2S X-Google-Smtp-Source: AGHT+IGMPbvyo5YUdoFNvwH75p6ioMMW7CpH0uN+k4YPOv1VsdfQeKiDUipyvDwjv7yvFvXhNIiGew== X-Received: by 2002:a05:6902:248e:b0:e7d:c87a:6264 with SMTP id 3f1490d57ef6-e86016cf787mr6317829276.6.1750893575532; Wed, 25 Jun 2025 16:19:35 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:35 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC v1 30/32] tools: introduce libluo Date: Wed, 25 Jun 2025 23:18:17 +0000 Message-ID: <20250625231838.1897085-31-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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: Pratyush Yadav LibLUO is a C library for interacting with the Live Update Orchestrator (LUO) subsystem. It provides a set of APIs for applications to interact with LUO, avoiding the need to directly calling the LUO ioctls. It provides APIs for controlling the LUO state and preserve and restore file descriptors across live updates. Signed-off-by: Pratyush Yadav Signed-off-by: Pasha Tatashin --- MAINTAINERS | 1 + tools/lib/luo/LICENSE | 165 ++++++++++++++++++ tools/lib/luo/Makefile | 37 ++++ tools/lib/luo/README.md | 166 ++++++++++++++++++ tools/lib/luo/include/libluo.h | 128 ++++++++++++++ tools/lib/luo/include/liveupdate.h | 265 +++++++++++++++++++++++++++++ tools/lib/luo/libluo.c | 203 ++++++++++++++++++++++ 7 files changed, 965 insertions(+) create mode 100644 tools/lib/luo/LICENSE create mode 100644 tools/lib/luo/Makefile create mode 100644 tools/lib/luo/README.md create mode 100644 tools/lib/luo/include/libluo.h create mode 100644 tools/lib/luo/include/liveupdate.h create mode 100644 tools/lib/luo/libluo.c diff --git a/MAINTAINERS b/MAINTAINERS index 8114ce1be57b..2b42b66404b5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14023,6 +14023,7 @@ F: include/linux/liveupdate.h F: include/uapi/linux/liveupdate.h F: kernel/liveupdate/ F: mm/memfd_luo.c +F: tools/lib/luo/ F: tools/testing/selftests/liveupdate/ =20 LLC (802.2) diff --git a/tools/lib/luo/LICENSE b/tools/lib/luo/LICENSE new file mode 100644 index 000000000000..0a041280bd00 --- /dev/null +++ b/tools/lib/luo/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this lice= nse + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/tools/lib/luo/Makefile b/tools/lib/luo/Makefile new file mode 100644 index 000000000000..e851c37d3d0a --- /dev/null +++ b/tools/lib/luo/Makefile @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +SRCS =3D libluo.c +OBJS =3D $(SRCS:.c=3D.o) +INCLUDE_DIR =3D include +HEADERS =3D $(wildcard $(INCLUDE_DIR)/*.h) + +CC =3D gcc +AR =3D ar +CFLAGS =3D -Wall -Wextra -fPIC -O2 -g -I$(INCLUDE_DIR) +LDFLAGS =3D -shared + +LIB_NAME =3D libluo +STATIC_LIB =3D $(LIB_NAME).a +SHARED_LIB =3D $(LIB_NAME).so + +.PHONY: all clean install + +all: $(STATIC_LIB) $(SHARED_LIB) + +$(STATIC_LIB): $(OBJS) + $(AR) rcs $@ $^ + +$(SHARED_LIB): $(OBJS) + $(CC) $(LDFLAGS) -o $@ $^ + +%.o: %.c $(HEADERS) + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) $(STATIC_LIB) $(SHARED_LIB) + +install: all + install -d $(DESTDIR)/usr/local/lib + install -d $(DESTDIR)/usr/local/include + install -m 644 $(STATIC_LIB) $(DESTDIR)/usr/local/lib + install -m 755 $(SHARED_LIB) $(DESTDIR)/usr/local/lib + install -m 644 $(HEADERS) $(DESTDIR)/usr/local/include diff --git a/tools/lib/luo/README.md b/tools/lib/luo/README.md new file mode 100644 index 000000000000..a716ccb2992c --- /dev/null +++ b/tools/lib/luo/README.md @@ -0,0 +1,166 @@ +# LibLUO - Live Update Orchestrator Library + +A C library for interacting with the Linux Live Update Orchestrator (LUO) = subsystem. + +## Overview + +LibLUO provides a set of APIs for applications to interact with LUO, avoid= ing +the need to directly calling the LUO ioctls. It provides APIs for controll= ing +the LUO state and preserve and restore file descriptors across live update= s. + +## Features + +- Initialize and manage connection to the LUO device. +- Preserve file descriptors before a live update. +- Restore file descriptors after a live update. +- Control the live update state machine (prepare, cancel, finish). +- Query the current state of the LUO subsystem. +- The library also includes a test suite for testing both LibLUO and the k= ernel + LUO interface. + +## Building + +```bash +make +``` + +This will build both static (`libluo.a`) and shared (`libluo.so`) versions= of the library. + +To build the tests, do + +``` bash +make tests +``` + +This will build the `tests/test` binary. + +## Installation + +```bash +sudo make install +``` + +This will install the library to `/usr/local/lib` and the header file to `= /usr/local/include`. + +## Usage + +### Preserving a file descriptor + +```c +#include +#include +#include +#include + +int main() { + int ret; + uint64_t token; + int fd, new_fd; + enum luo_state state; + + // Initialize the library + ret =3D luo_init(); + if (ret < 0) { + fprintf(stderr, "Failed to initialize LibLUO: %d\n", ret); + return 1; + } + + // Check if LUO is available + if (!luo_is_available()) { + fprintf(stderr, "LUO is not available on this system\n"); + return 1; + } + + // Get the current LUO state + ret =3D luo_get_state(&state); + if (ret < 0) { + fprintf(stderr, "Failed to get LUO state: %d\n", ret); + luo_cleanup(); + return 1; + } + + printf("Current LUO state: %s\n", luo_state_to_string(state)); + + // Open a file descriptor to preserve + fd =3D memfd_create("luo_memfd", 0); + if (fd < 0) { + perror("Failed to open memfd"); + luo_cleanup(); + return 1; + } + + // Preserve the file descriptor + ret =3D luo_fd_preserve(fd, &token); + if (ret < 0) { + fprintf(stderr, "Failed to preserve FD: %d\n", ret); + close(fd); + luo_cleanup(); + return 1; + } + + printf("FD %d preserved with token %lu\n", fd, token); + + // After a live update, restore the file descriptor + if (state =3D=3D LUO_STATE_UPDATED) { + ret =3D luo_fd_restore(token, &new_fd); + if (ret < 0) { + fprintf(stderr, "Failed to restore FD: %d\n", ret); + } else { + printf("FD restored: %d\n", new_fd); + close(new_fd); + } + + // Signal completion of restoration + luo_finish(); + } + + close(fd); + luo_cleanup(); + return 0; +} +``` + +### Controlling the Live Update Process + +```c +#include +#include + +int main() { + int ret; + + ret =3D luo_init(); + if (ret < 0) { + return 1; + } + + // Initiate the preparation phase + ret =3D luo_prepare(); + if (ret < 0) { + fprintf(stderr, "Failed to prepare for live update: %d\n", ret); + luo_cleanup(); + return 1; + } + + // At this point, the system is ready for kexec reboot + // The freeze operation is handled internally by the kernel + // during kexec. + + // After reboot, in the new kernel + // Signal completion of restoration + ret =3D luo_finish(); + if (ret < 0) { + fprintf(stderr, "Failed to finish live update: %d\n", ret); + luo_cleanup(); + return 1; + } + + luo_cleanup(); + return 0; +} +``` + +## License + +This library is provided under the terms of the GNU Lesser General Public +License version 3.0, or (at your option) any later version. diff --git a/tools/lib/luo/include/libluo.h b/tools/lib/luo/include/libluo.h new file mode 100644 index 000000000000..86b277e8e4f6 --- /dev/null +++ b/tools/lib/luo/include/libluo.h @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +/** + * @file libluo.h + * @brief Library for interacting with the Linux Live Update Orchestrator = (LUO) + * + * This library provides a simple interface for applications to interact w= ith + * the Linux Live Update Orchestrator (LUO) subsystem, allowing them to pr= eserve + * and restore file descriptors across live kernel updates. + * + * Copyright (C) 2025 Amazon.com Inc. or its affiliates. + * Author: Pratyush Yadav + */ + +#ifndef _LIBLUO_H +#define _LIBLUO_H + +#include +#include +#include + +/** + * @brief Initialize the LUO library + * + * Opens the LUO device file and prepares the library for use. + * + * @return 0 on success, negative error code on failure + */ +int luo_init(void); + +/** + * @brief Clean up and release resources used by the LUO library + * + * Closes the LUO device file and releases any resources allocated by the + * library. + */ +void luo_cleanup(void); + +/** + * @brief Get the current state of the LUO subsystem + * + * @param[out] state Pointer to store the current LUO state + * @return 0 on success, negative error code on failure + */ +int luo_get_state(enum liveupdate_state *state); + +/** + * @brief Preserve a file descriptor for restoration after a live update + * + * Marks the specified file descriptor for preservation across a live upda= te. + * The kernel validates if the FD type is supported for preservation. + * + * @param[in] fd The file descriptor to preserve + * @param[in] token Token to associate fd with. Must be unique. + * @return 0 on success, negative error code on failure + */ +int luo_fd_preserve(int fd, uint64_t token); + +/** + * @brief Cancel preservation of a previously preserved file descriptor + * + * Removes a file descriptor from the preservation list using its token. + * + * @param[in] token The token used to preserve fd previously. + * @return 0 on success, negative error code on failure + */ +int luo_fd_unpreserve(uint64_t token); + +/** + * @brief Restore a previously preserved file descriptor + * + * Restores a file descriptor that was preserved before the live update. + * This must be called after the system has rebooted into the new kernel. + * + * @param[in] token The token returned by luo_fd_preserve before the update + * @param[out] fd Pointer to store the new file descriptor + * @return 0 on success, negative error code on failure + */ +int luo_fd_restore(uint64_t token, int *fd); + +/** + * @brief Initiate the preparation phase for a live update + * + * Triggers the PREPARE phase in the LUO subsystem, which begins the + * state saving process for items marked for preservation. + * + * @return 0 on success, negative error code on failure + */ +int luo_prepare(void); + +/** + * @brief Cancel the live update preparation phase + * + * Aborts the preparation sequence and returns the system to normal state. + * + * @return 0 on success, negative error code on failure + */ +int luo_cancel(void); + +/** + * @brief Signal completion of restoration after a live update + * + * Notifies the LUO subsystem that all necessary restoration actions + * have been completed in the new kernel. + * + * @return 0 on success, negative error code on failure + */ +int luo_finish(void); + +/** + * @brief Check if the LUO subsystem is available + * + * Tests if the LUO device file exists and can be opened. + * + * @return true if LUO is available, false otherwise + */ +bool luo_is_available(void); + +/** + * @brief Convert a liveupdate_state enum value to a string + * + * Returns a string representation of the given LUO state. + * + * @param[in] state The LUO state to convert + * @return A constant string representing the state + */ +const char *luo_state_to_string(enum liveupdate_state state); + +#endif /* _LIBLUO_H */ diff --git a/tools/lib/luo/include/liveupdate.h b/tools/lib/luo/include/liv= eupdate.h new file mode 100644 index 000000000000..7b12a1073c3c --- /dev/null +++ b/tools/lib/luo/include/liveupdate.h @@ -0,0 +1,265 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +/* + * Userspace interface for /dev/liveupdate + * Live Update Orchestrator + * + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#ifndef _UAPI_LIVEUPDATE_H +#define _UAPI_LIVEUPDATE_H + +#include +#include + +/** + * enum liveupdate_state - Defines the possible states of the live update + * orchestrator. + * @LIVEUPDATE_STATE_UNDEFINED: State has not yet been initialized. + * @LIVEUPDATE_STATE_NORMAL: Default state, no live update in prog= ress. + * @LIVEUPDATE_STATE_PREPARED: Live update is prepared for reboot; t= he + * LIVEUPDATE_PREPARE callbacks have com= pleted + * successfully. + * Devices might operate in a limited st= ate + * for example the participating devices= might + * not be allowed to unbind, and also the + * setting up of new DMA mappings might = be + * disabled in this state. + * @LIVEUPDATE_STATE_FROZEN: The final reboot event + * (%LIVEUPDATE_FREEZE) has been sent, a= nd the + * system is performing its final state = saving + * within the "blackout window". User + * workloads must be suspended. The actu= al + * reboot (kexec) into the next kernel is + * imminent. + * @LIVEUPDATE_STATE_UPDATED: The system has rebooted into the next + * kernel via live update the system is = now + * running the next kernel, awaiting the + * finish event. + * + * These states track the progress and outcome of a live update operation. + */ +enum liveupdate_state { + LIVEUPDATE_STATE_UNDEFINED =3D 0, + LIVEUPDATE_STATE_NORMAL =3D 1, + LIVEUPDATE_STATE_PREPARED =3D 2, + LIVEUPDATE_STATE_FROZEN =3D 3, + LIVEUPDATE_STATE_UPDATED =3D 4, +}; + +/** + * struct liveupdate_fd - Holds parameters for preserving and restoring fi= le + * descriptors across live update. + * @fd: Input for %LIVEUPDATE_IOCTL_FD_PRESERVE: The user-space file + * descriptor to be preserved. + * Output for %LIVEUPDATE_IOCTL_FD_RESTORE: The new file descriptor + * representing the fully restored kernel resource. + * @flags: Unused, reserved for future expansion, must be set to 0. + * @token: Input for %LIVEUPDATE_IOCTL_FD_PRESERVE: An opaque, unique token + * preserved for preserved resource. + * Input for %LIVEUPDATE_IOCTL_FD_RESTORE: The token previously + * provided to the preserve ioctl for the resource to be restored. + * + * This structure is used as the argument for the %LIVEUPDATE_IOCTL_FD_PRE= SERVE + * and %LIVEUPDATE_IOCTL_FD_RESTORE ioctls. These ioctls allow specific ty= pes + * of file descriptors (for example memfd, kvm, iommufd, and VFIO) to have= their + * underlying kernel state preserved across a live update cycle. + * + * To preserve an FD, user space passes this struct to + * %LIVEUPDATE_IOCTL_FD_PRESERVE with the @fd field set. On success, the + * kernel uses the @token field to uniquly associate the preserved FD. + * + * After the live update transition, user space passes the struct populate= d with + * the *same* @token to %LIVEUPDATE_IOCTL_FD_RESTORE. The kernel uses the = @token + * to find the preserved state and, on success, populates the @fd field wi= th a + * new file descriptor referring to the restored resource. + */ +struct liveupdate_fd { + int fd; + __u32 flags; + __aligned_u64 token; +}; + +/* The ioctl type, documented in ioctl-number.rst */ +#define LIVEUPDATE_IOCTL_TYPE 0xBA + +/** + * LIVEUPDATE_IOCTL_FD_PRESERVE - Validate and initiate preservation for a= file + * descriptor. + * + * Argument: Pointer to &struct liveupdate_fd. + * + * User sets the @fd field identifying the file descriptor to preserve + * (e.g., memfd, kvm, iommufd, VFIO). The kernel validates if this FD type + * and its dependencies are supported for preservation. If validation pass= es, + * the kernel marks the FD internally and *initiates the process* of prepa= ring + * its state for saving. The actual snapshotting of the state typically oc= curs + * during the subsequent %LIVEUPDATE_IOCTL_PREPARE execution phase, though + * some finalization might occur during freeze. + * On successful validation and initiation, the kernel uses the @token + * field with an opaque identifier representing the resource being preserv= ed. + * This token confirms the FD is targeted for preservation and is required= for + * the subsequent %LIVEUPDATE_IOCTL_FD_RESTORE call after the live update. + * + * Return: 0 on success (validation passed, preservation initiated), negat= ive + * error code on failure (e.g., unsupported FD type, dependency issue, + * validation failed). + */ +#define LIVEUPDATE_IOCTL_FD_PRESERVE \ + _IOW(LIVEUPDATE_IOCTL_TYPE, 0x00, struct liveupdate_fd) + +/** + * LIVEUPDATE_IOCTL_FD_UNPRESERVE - Remove a file descriptor from the + * preservation list. + * + * Argument: Pointer to __u64 token. + * + * Allows user space to explicitly remove a file descriptor from the set of + * items marked as potentially preservable. User space provides a pointer = to the + * __u64 @token that was previously returned by a successful + * %LIVEUPDATE_IOCTL_FD_PRESERVE call (potentially from a prior, possibly + * cancelled, live update attempt). The kernel reads the token value from = the + * provided user-space address. + * + * On success, the kernel removes the corresponding entry (identified by t= he + * token value read from the user pointer) from its internal preservation = list. + * The provided @token (representing the now-removed entry) becomes invalid + * after this call. + * + * Return: 0 on success, negative error code on failure (e.g., -EBUSY or -= EINVAL + * if not in %LIVEUPDATE_STATE_NORMAL, bad address provided, invalid token= value + * read, token not found). + */ +#define LIVEUPDATE_IOCTL_FD_UNPRESERVE \ + _IOW(LIVEUPDATE_IOCTL_TYPE, 0x01, __u64) + +/** + * LIVEUPDATE_IOCTL_FD_RESTORE - Restore a previously preserved file descr= iptor. + * + * Argument: Pointer to &struct liveupdate_fd. + * + * User sets the @token field to the value obtained from a successful + * %LIVEUPDATE_IOCTL_FD_PRESERVE call before the live update. On success, + * the kernel restores the state (saved during the PREPARE/FREEZE phases) + * associated with the token and populates the @fd field with a new file + * descriptor referencing the restored resource in the current (new) kerne= l. + * This operation must be performed *before* signaling completion via + * %LIVEUPDATE_IOCTL_FINISH. + * + * Return: 0 on success, negative error code on failure (e.g., invalid tok= en). + */ +#define LIVEUPDATE_IOCTL_FD_RESTORE \ + _IOWR(LIVEUPDATE_IOCTL_TYPE, 0x02, struct liveupdate_fd) + +/** + * LIVEUPDATE_IOCTL_GET_STATE - Query the current state of the live update + * orchestrator. + * + * Argument: Pointer to &enum liveupdate_state. + * + * The kernel fills the enum value pointed to by the argument with the cur= rent + * state of the live update subsystem. Possible states are: + * + * - %LIVEUPDATE_STATE_NORMAL: Default state; no live update operation is + * currently in progress. + * - %LIVEUPDATE_STATE_PREPARED: The preparation phase (triggered by + * %LIVEUPDATE_IOCTL_PREPARE) has completed + * successfully. The system is ready for the + * reboot transition. Note that some + * device operations (e.g., unbinding, new D= MA + * mappings) might be restricted in this sta= te. + * - %LIVEUPDATE_STATE_UPDATED: The system has successfully rebooted into= the + * new kernel via live update. It is now run= ning + * the new kernel code and is awaiting the + * completion signal from user space via + * %LIVEUPDATE_IOCTL_FINISH after + * restoration tasks are done. + * + * See the definition of &enum liveupdate_state for more details on each s= tate. + * + * Return: 0 on success, negative error code on failure. + */ +#define LIVEUPDATE_IOCTL_GET_STATE \ + _IOR(LIVEUPDATE_IOCTL_TYPE, 0x03, enum liveupdate_state) + +/** + * LIVEUPDATE_IOCTL_PREPARE - Initiate preparation phase and trigger state + * saving. + * + * Argument: None. + * + * Initiates the live update preparation phase. This action corresponds to + * the internal %LIVEUPDATE_PREPARE. This typically triggers the saving pr= ocess + * for items marked via the PRESERVE ioctls. This typically occurs *before* + * the "blackout window", while user applications (e.g., VMs) may still be + * running. Kernel subsystems receiving the %LIVEUPDATE_PREPARE event shou= ld + * serialize necessary state. This command does not transfer data. + * + * Return: 0 on success, negative error code on failure. Transitions state + * towards %LIVEUPDATE_STATE_PREPARED on success. + */ +#define LIVEUPDATE_IOCTL_PREPARE \ + _IO(LIVEUPDATE_IOCTL_TYPE, 0x04) + +/** + * LIVEUPDATE_IOCTL_CANCEL - Cancel the live update preparation phase. + * + * Argument: None. + * + * Notifies the live update subsystem to abort the preparation sequence + * potentially initiated by %LIVEUPDATE_IOCTL_PREPARE. This action + * typically corresponds to the internal %LIVEUPDATE_CANCEL kernel event, + * which might also be triggered automatically if the PREPARE stage fails + * internally. + * + * When triggered, subsystems receiving the %LIVEUPDATE_CANCEL event should + * revert any state changes or actions taken specifically for the aborted + * prepare phase (e.g., discard partially serialized state). The kernel + * releases resources allocated specifically for this *aborted preparation + * attempt*. + * + * This operation cancels the current *attempt* to prepare for a live upda= te + * but does **not** remove previously validated items from the internal li= st + * of potentially preservable resources. Consequently, preservation tokens + * previously generated by successful %LIVEUPDATE_IOCTL_FD_PRESERVE or cal= ls + * generally **remain valid** as identifiers for those potentially preserv= able + * resources. However, since the system state returns towards + * %LIVEUPDATE_STATE_NORMAL, user space must initiate a new live update se= quence + * (starting with %LIVEUPDATE_IOCTL_PREPARE) to proceed with an update + * using these (or other) tokens. + * + * This command does not transfer data. Kernel callbacks for the + * %LIVEUPDATE_CANCEL event must not fail. + * + * Return: 0 on success, negative error code on failure. Transitions state= back + * towards %LIVEUPDATE_STATE_NORMAL on success. + */ +#define LIVEUPDATE_IOCTL_CANCEL \ + _IO(LIVEUPDATE_IOCTL_TYPE, 0x06) + +/** + * LIVEUPDATE_IOCTL_EVENT_FINISH - Signal restoration completion and trigg= er + * cleanup. + * + * Argument: None. + * + * Signals that user space has completed all necessary restoration actions= in + * the new kernel (after a live update reboot). This action corresponds to= the + * internal %LIVEUPDATE_FINISH kernel event. Calling this ioctl triggers t= he + * cleanup phase: any resources that were successfully preserved but were = *not* + * subsequently restored (reclaimed) via the RESTORE ioctls will have their + * preserved state discarded and associated kernel resources released. Inv= olved + * devices may be reset. All desired restorations *must* be completed *bef= ore* + * this. Kernel callbacks for the %LIVEUPDATE_FINISH event must not fail. + * Successfully completing this phase transitions the system state from + * %LIVEUPDATE_STATE_UPDATED back to %LIVEUPDATE_STATE_NORMAL. This comman= d does + * not transfer data. + * + * Return: 0 on success, negative error code on failure. + */ +#define LIVEUPDATE_IOCTL_FINISH \ + _IO(LIVEUPDATE_IOCTL_TYPE, 0x07) + +#endif /* _UAPI_LIVEUPDATE_H */ diff --git a/tools/lib/luo/libluo.c b/tools/lib/luo/libluo.c new file mode 100644 index 000000000000..7de4bf01de16 --- /dev/null +++ b/tools/lib/luo/libluo.c @@ -0,0 +1,203 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +/* + * Copyright (C) 2025 Amazon.com Inc. or its affiliates. + * Author: Pratyush Yadav + */ +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * The liveupdate header is not mainline right now, so it is not available= on + * the system include path. It is copied from Linux tree and put in includ= e/. + * + * This can be removed when liveupdate hits mainline. + */ +#include + +#define LUO_DEVICE_PATH "/dev/liveupdate" + +/* File descriptor for the LUO device */ +static int luo_fd =3D -1; + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +int luo_init(void) +{ + if (luo_fd >=3D 0) + /* Already initialized */ + return 0; + + luo_fd =3D open(LUO_DEVICE_PATH, O_RDWR); + if (luo_fd < 0) { + int err =3D -errno; + + fprintf(stderr, "Failed to open %s: %s\n", + LUO_DEVICE_PATH, strerror(errno)); + return err; + } + + return 0; +} + +void luo_cleanup(void) +{ + if (luo_fd >=3D 0) { + close(luo_fd); + luo_fd =3D -1; + } +} + +bool luo_is_available(void) +{ + struct stat st; + + /* Use stat() to check if the device file exists and is accessible */ + if (stat(LUO_DEVICE_PATH, &st) < 0) + return false; + + /* Verify it's a character device file. */ + if (!S_ISCHR(st.st_mode)) + return false; + + return true; +} + +int luo_get_state(enum liveupdate_state *state) +{ + int ret; + + if (!state) + return -EINVAL; + + if (luo_fd < 0) + return -EBADF; + + ret =3D ioctl(luo_fd, LIVEUPDATE_IOCTL_GET_STATE, state); + if (ret < 0) + return -errno; + + return 0; +} + +int luo_fd_preserve(int fd, uint64_t token) +{ + struct liveupdate_fd fd_data; + int ret; + + if (fd < 0) + return -EINVAL; + + if (luo_fd < 0) + return -EBADF; + + fd_data.fd =3D fd; + fd_data.flags =3D 0; /* Must be set to 0 as per API documentation */ + fd_data.token =3D token; + + ret =3D ioctl(luo_fd, LIVEUPDATE_IOCTL_FD_PRESERVE, &fd_data); + if (ret < 0) + return -errno; + + return 0; +} + +int luo_fd_unpreserve(uint64_t token) +{ + int ret; + + if (luo_fd < 0) + return -EBADF; + + ret =3D ioctl(luo_fd, LIVEUPDATE_IOCTL_FD_UNPRESERVE, &token); + if (ret < 0) + return -errno; + + return 0; +} + +int luo_fd_restore(uint64_t token, int *fd) +{ + struct liveupdate_fd fd_data; + int ret; + + if (!fd) + return -EINVAL; + + if (luo_fd < 0) + return -EBADF; + + fd_data.fd =3D -1; /* Will be filled by the kernel */ + fd_data.flags =3D 0; /* Must be set to 0 as per API documentation */ + fd_data.token =3D token; + + ret =3D ioctl(luo_fd, LIVEUPDATE_IOCTL_FD_RESTORE, &fd_data); + if (ret < 0) + return -errno; + + *fd =3D fd_data.fd; + return 0; +} + +int luo_prepare(void) +{ + int ret; + + if (luo_fd < 0) + return -EBADF; + + ret =3D ioctl(luo_fd, LIVEUPDATE_IOCTL_PREPARE); + if (ret < 0) + return -errno; + + return 0; +} + +int luo_cancel(void) +{ + int ret; + + if (luo_fd < 0) + return -EBADF; + + ret =3D ioctl(luo_fd, LIVEUPDATE_IOCTL_CANCEL); + if (ret < 0) + return -errno; + + return 0; +} + +int luo_finish(void) +{ + int ret; + + if (luo_fd < 0) + return -EBADF; + + ret =3D ioctl(luo_fd, LIVEUPDATE_IOCTL_FINISH); + if (ret < 0) + return -errno; + + return 0; +} + +const char *luo_state_to_string(enum liveupdate_state state) +{ + static const char * const state_strings[] =3D { + [LIVEUPDATE_STATE_UNDEFINED] =3D "undefined", + [LIVEUPDATE_STATE_NORMAL] =3D "normal", + [LIVEUPDATE_STATE_PREPARED] =3D "prepared", + [LIVEUPDATE_STATE_FROZEN] =3D "frozen", + [LIVEUPDATE_STATE_UPDATED] =3D "updated" + }; + + if (state >=3D 0 && state < ARRAY_SIZE(state_strings) && state_strings[st= ate]) + return state_strings[state]; + + return "UNKNOWN"; +} --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.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 673DF30AAD7 for ; Wed, 25 Jun 2025 23:19:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893581; cv=none; b=NHqQNHAMxbzJPoMR9BH5XFYl3qH2uhi2OGhvUVhPwb49/hdJ9nR/4Ne2fa3cAFNmE4z4zAuw/LKWb2egiK5OZE+6QQTKL8aHin7ysD6pCv2zEBFMLUlJ3KXs9rVGObjnOqrrrhdgKqOLHHEVhPXTBAPjiNwDykumrsPk6HDY5es= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893581; c=relaxed/simple; bh=kV/i7WzK++AoKinYUIyGUJOx4XSzNlPUkIXf9Vx78zI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DGrq7SUl67VxYxoMR7+TlBjqh6JeJeRRvlUmM37S7hV5T0mTiBVPXisC9P7t2KhHwQZDKvbRnRVwWfXdAo1wqUcH3dFO7hWPzRd6YtlGrVr5POnYneC9VVrZQPp+HgjvJxHFOdF/EO1Dz1SZEdUzdwNFuDYb48tPumXMJB2GKjU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=3eNaawZU; arc=none smtp.client-ip=209.85.219.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="3eNaawZU" Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-e8600a33792so275635276.0 for ; Wed, 25 Jun 2025 16:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893578; x=1751498378; 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=hShlI4m6hw+YtxzJd2p960yByHj9Zxa7UX6hlMU7/TY=; b=3eNaawZUF+8+5E3roVGA90gE7+yciavql4ETnD9sNyPhsvJicbxHUMo4O1EVAVaysG pktjuhw5GVvoLJKoEXObkXFw8ejbC+AWCiAEEvIlAEQgoVFeq7SD4a/qarXrLcvQa+/L CSAE0F3yBWRy4oJ8ALJ3ikSTiODg+NkdYJYzc7L/UgC1pEGKjbdafamsUQQfd78mDc8O j/Oy+w0KIORdrvVz/aObPq8JIUQMJ6FshkC0lrGdjzfmyLw8hPOEmVcYLQ/cD0JAnwlC 6/7tNCzYKw/pegg6FBEaOO95r2MXM6Khpg7uqaTkOCT5MeePmlk54Xq4+rPj2owOvVf8 9XNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893578; x=1751498378; 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=hShlI4m6hw+YtxzJd2p960yByHj9Zxa7UX6hlMU7/TY=; b=X3IfpnrAaMl9D3uTtrti4nKtp/wdVeMYeAlALuB8ut5DXmRsGI7MIjLm5cWs6I9GlK 5iw/TBhS2D5zM4u8jfRfykiQmAdGnz+pj6hQ24cBa3Yr3R+Bu2w2Bm02CZU0MZkw+sU+ eSpvxcdThugTqpeh8cmZ1qFNYHrRmgBCrORaHwKGBEbOzq6lB748rQg/BObosULP+A8Q wFvQaP0Svc/eEGlBCr5U2rSDg0q5dO+iO2xCVWRu5YKKhdXrPN+DNUhTDmN/X0WzcAly GdhRJOvxBz08BeEPK0adee/qjxO+M3Q2bP/mAJOXyuiLV6WlzzQK42KeNwr/4LbeWEjv Usjw== X-Forwarded-Encrypted: i=1; AJvYcCXr1PLgO4jKmfPpOSEmfUAA3HPeo7CEcXb1CtufNjpU24gWhK44F4Kl47dHBYUxbDxAgNtchGIGbJb/I80=@vger.kernel.org X-Gm-Message-State: AOJu0YxEV4OQJNaFLrAy0Kp57nfYTWavZa8aY9Mlu42jVwhFn242wV5o RNjYf5ZKdlrZFdV5gKdoCqL9iDR8KLL16LMzfB5kCmhNHlYaf4SOS9/9CLczkJUa9IT4MHXTkfR phf4qUXA= X-Gm-Gg: ASbGnctLz49m6Pep8mHiwuFkt4dVRLZSIu741ODq8besZuWDQfFFS5odvfX1rjRm5oC gFc5r4WrEk8pvQsAa1DauIWDw9rbPouN97rcfzJxMK7dhLKU+oElymXDY1f+b4K3Kh4zQnkZwab UQ8wPIVdURKeMFQqYa7UKuG/U9ORPP+SV6DHrsbbBwioS75j7JxQ+1HXX05QGAkrgrI9jryHR6W KWZ4oHayQhvorn5RSNX/taVsJtaJm4qNjWMwJq30trDPvaURmGpAlWXdM/AyFXPvG7U31q9adn7 Sv9i1D2nrlHV5Eqy4PLx57H7sXq73cVGxB+Ai+eImWCmyhI53XmV0ah1V2OxgjHVsrPzPXkLVd7 HuUlWRe2n4NKQo4+qgABTSRNybbotBtseBlRvGpg6gJlFEBoU7ugl X-Google-Smtp-Source: AGHT+IFoGRO0KaLEBii9PY7cTsqu44dj7Ui8YGBIE2T43tz6yuSs4Jx3CDRngKDNI69FsnW2ifBMIg== X-Received: by 2002:a05:6902:1502:b0:e82:2f98:fbd3 with SMTP id 3f1490d57ef6-e8601776a97mr5709362276.32.1750893578134; Wed, 25 Jun 2025 16:19:38 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:36 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC v1 31/32] libluo: introduce luoctl Date: Wed, 25 Jun 2025 23:18:18 +0000 Message-ID: <20250625231838.1897085-32-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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: Pratyush Yadav luoctl is a utility to interact with the LUO state machine. It currently supports viewing and change the current state of LUO. This can be used by scripts, tools, or developers to control LUO state during the live update process. Example usage: $ luoctl state normal $ luoctl prepare $ luoctl state prepared $ luoctl cancel $ luoctl state normal Signed-off-by: Pratyush Yadav Signed-off-by: Pasha Tatashin --- tools/lib/luo/Makefile | 6 +- tools/lib/luo/cli/.gitignore | 1 + tools/lib/luo/cli/Makefile | 18 ++++ tools/lib/luo/cli/luoctl.c | 178 +++++++++++++++++++++++++++++++++++ 4 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 tools/lib/luo/cli/.gitignore create mode 100644 tools/lib/luo/cli/Makefile create mode 100644 tools/lib/luo/cli/luoctl.c diff --git a/tools/lib/luo/Makefile b/tools/lib/luo/Makefile index e851c37d3d0a..e8f6bd3b9e85 100644 --- a/tools/lib/luo/Makefile +++ b/tools/lib/luo/Makefile @@ -13,7 +13,7 @@ LIB_NAME =3D libluo STATIC_LIB =3D $(LIB_NAME).a SHARED_LIB =3D $(LIB_NAME).so =20 -.PHONY: all clean install +.PHONY: all clean install cli =20 all: $(STATIC_LIB) $(SHARED_LIB) =20 @@ -26,8 +26,12 @@ $(SHARED_LIB): $(OBJS) %.o: %.c $(HEADERS) $(CC) $(CFLAGS) -c $< -o $@ =20 +cli: $(STATIC_LIB) + $(MAKE) -C cli + clean: rm -f $(OBJS) $(STATIC_LIB) $(SHARED_LIB) + $(MAKE) -C cli clean =20 install: all install -d $(DESTDIR)/usr/local/lib diff --git a/tools/lib/luo/cli/.gitignore b/tools/lib/luo/cli/.gitignore new file mode 100644 index 000000000000..3a5e2d287f60 --- /dev/null +++ b/tools/lib/luo/cli/.gitignore @@ -0,0 +1 @@ +/luoctl diff --git a/tools/lib/luo/cli/Makefile b/tools/lib/luo/cli/Makefile new file mode 100644 index 000000000000..6c0cbf92a420 --- /dev/null +++ b/tools/lib/luo/cli/Makefile @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +LUOCTL =3D luoctl +INCLUDE_DIR =3D ../include +HEADERS =3D $(wildcard $(INCLUDE_DIR)/*.h) + +CC =3D gcc +CFLAGS =3D -Wall -Wextra -O2 -g -I$(INCLUDE_DIR) +LDFLAGS =3D -L.. -l:libluo.a + +.PHONY: all clean + +all: $(LUOCTL) + +luoctl: luoctl.c ../libluo.a $(HEADERS) + $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) + +clean: + rm -f $(LUOCTL) diff --git a/tools/lib/luo/cli/luoctl.c b/tools/lib/luo/cli/luoctl.c new file mode 100644 index 000000000000..39ba0bdd44f0 --- /dev/null +++ b/tools/lib/luo/cli/luoctl.c @@ -0,0 +1,178 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +/** + * @file luoctl.c + * @brief Simple utility to interact with LUO + * + * This utility allows viewing and controlling LUO state. + * + * Copyright (C) 2025 Amazon.com Inc. or its affiliates. + * Author: Pratyush Yadav + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define fatal(fmt, ...) \ + do { \ + fprintf(stderr, "Error: " fmt, ##__VA_ARGS__); \ + exit(1); \ + } while (0) + +struct command { + char *name; + int (*handler)(void); +}; + +static void usage(const char *prog_name) +{ + printf("Usage: %s [command]\n\n", prog_name); + printf("Commands:\n"); + printf(" state - Show current LUO state\n"); + printf(" prepare - Prepare for live update\n"); + printf(" cancel - Cancel live update preparation\n"); + printf(" finish - Signal completion of restoration\n"); +} + +static enum liveupdate_state get_state(void) +{ + enum liveupdate_state state; + int ret; + + ret =3D luo_get_state(&state); + if (ret) + fatal("failed to get LUO state: %s\n", strerror(-ret)); + + return state; +} + +static int show_state(void) +{ + enum liveupdate_state state; + + state =3D get_state(); + printf("%s\n", luo_state_to_string(state)); + return 0; +} + +static int do_prepare(void) +{ + enum liveupdate_state state; + int ret; + + state =3D get_state(); + if (state !=3D LIVEUPDATE_STATE_NORMAL) + fatal("can only switch to prepared state from normal state. Current stat= e: %s\n", + luo_state_to_string(state)); + + ret =3D luo_prepare(); + if (ret) + fatal("failed to prepare for live update: %s\n", strerror(-ret)); + + return 0; +} + +static int do_cancel(void) +{ + enum liveupdate_state state; + int ret; + + state =3D get_state(); + if (state !=3D LIVEUPDATE_STATE_PREPARED) + fatal("can only cancel from normal state. Current state: %s\n", + luo_state_to_string(state)); + + ret =3D luo_cancel(); + if (ret) + fatal("failed to cancel live update: %s\n", strerror(-ret)); + + return 0; +} + +static int do_finish(void) +{ + enum liveupdate_state state; + int ret; + + state =3D get_state(); + if (state !=3D LIVEUPDATE_STATE_UPDATED) + fatal("can only finish from updated state. Current state: %s\n", + luo_state_to_string(state)); + + ret =3D luo_finish(); + if (ret) + fatal("failed to finish live update: %s\n", strerror(-ret)); + + return 0; +} + +static struct command commands[] =3D { + {"state", show_state}, + {"prepare", do_prepare}, + {"cancel", do_cancel}, + {"finish", do_finish}, + {NULL, NULL}, +}; + +int main(int argc, char *argv[]) +{ + struct option long_options[] =3D { + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + struct command *command; + int ret =3D -EINVAL, opt; + char *cmd; + + if (!luo_is_available()) { + fprintf(stderr, "LUO is not available on this system\n"); + return 1; + } + + while ((opt =3D getopt_long(argc, argv, "ht:e:", long_options, NULL)) != =3D -1) { + switch (opt) { + case 'h': + usage(argv[0]); + return 0; + default: + fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); + return 1; + } + } + + if (argc - optind !=3D 1) { + usage(argv[0]); + return 1; + } + + cmd =3D argv[optind]; + + ret =3D luo_init(); + if (ret < 0) { + fprintf(stderr, "Failed to initialize LibLUO: %s\n", strerror(-ret)); + return 1; + } + + command =3D &commands[0]; + while (command->name) { + if (!strcmp(cmd, command->name)) { + ret =3D command->handler(); + break; + } + command++; + } + + if (!command->name) { + fprintf(stderr, "Unknown command %s. Try '%s --help' for more informatio= n\n", + cmd, argv[0]); + ret =3D -EINVAL; + } + + luo_cleanup(); + return (ret < 0) ? 1 : 0; +} --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 16:41:39 2025 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) (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 21DB5309DC9 for ; Wed, 25 Jun 2025 23:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893585; cv=none; b=A3spZtEwkBC6o1zCFgAxbAd4OjEu+GhzM6eV5HOewSzwo6UfP5xT3z97KavH8xd9N1d2GC4AHicvfxERB/rcQaESkeo6IkAN+/ww4gzWJvKZYpSzfGXfAohNdAldZ98ggLxoPG3X+XLvUsGhq34qE7GjWiAHfwTRO4CZLOcvzTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750893585; c=relaxed/simple; bh=8l0K6QJ4RkWllZcpyZGwgZlU9m1P2gnk5TToNIUeT/Q=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W0aJm6ieO4CU8mBUCIgGfpYgQv6XwJBDA4tDKhiU/my9cfQ95sbc3n5fdLRdo148ewiHUUDX1N6YLkAtjc5qHx36EiLBS6Aqk55cOGlGCcxtokDfE/k3GqRGagYCA6uba5EXe2f8UsZoNhlNmNM/2OFUWko64gSncb4LrtJR1Ds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=t1U6E5zd; arc=none smtp.client-ip=209.85.219.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="t1U6E5zd" Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-e7d9d480e6cso246403276.2 for ; Wed, 25 Jun 2025 16:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893580; x=1751498380; 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=60o0+pILn7oYpaQU4GzfpCaIJI/wVLOztDCQbTE/8Fw=; b=t1U6E5zd7n4RDB1Q3z5zU4DqXcrvp+PPKVVlu77s/frc2wqrUNSkkAI218tRB30EFE qJ/Vd4zkTz96nagnCxTk/alKLL976lwsBCwuDmJ8cKbPYyFtaxWBYrFaoSBO1tWeMvzv 59UjCELAnCENBcgTNf9XWZzjJ3/mUfmZIG+Ee4tvndYbVfq/mzow05R5uImnKnmTyvcr IVgQGSsXAA+30VKFN6VSxaSuen26ZM0A5R50j/us+Fy8t+qg5t2SWr69AeZx7Vr1vvlx F6UnKDAV7gI63Td5TCm/oeU858iThERqz6TXiauhP2NJTxaOFb02QAtZCSoeMVwvDel4 Ac4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893580; x=1751498380; 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=60o0+pILn7oYpaQU4GzfpCaIJI/wVLOztDCQbTE/8Fw=; b=B/H2ECyqqVq3bDtVToPzLnn02C24W6JPEejYcjT6OGqBTAvq8kGc15zo2MYzx9OeUk EUn+6C81uLleG52tkdRGK2BiiSXzL/DNX1Z9JznmT9UK5pWnBI37qz+vBBRKxHUhBYti GSuTAKa5YIx3uMYZi3PD5Tox4ZgO0gAcQb3I0GIrqsCIMuIFgufboNYL2b+iw2riW/lS DaZcI13aKA1n5qrx+DWEc153/Mv8ju4PKCywPFKxRksA9C9yoF3EL0Y9bIQpTiWhSnJ4 lrH9TmUfyzwhdpSHHjTEScDYkCjHNbZPWH4gBww0q5YlnyyXN3trpQS0s0Xm4nAaFc9p Swyw== X-Forwarded-Encrypted: i=1; AJvYcCXu5fHFnu44Ok/48udnTYmymZaf9ITlstqudeBWkcAd4Q92Jt2P6qSqKKFoEdDSG9Wcr/O4KaRAGOTr2Ws=@vger.kernel.org X-Gm-Message-State: AOJu0YxlHmJUO/TbrViXVKa329PLDpTJxGV9XhT2eiXo9eEScdnFZg+g At5wvXWrSd0vCMyqbtKSyUhqSZiE2CLSpFo6NWs7CMWBiJhZXgfWpy/rrNG0u+VsxvA= X-Gm-Gg: ASbGnctmPouwq/Jr7u6tlP13xj07F8m+d6dMYCaHl3c0jEiVy9zgR5AOmghICQEBWEu vUMfVLKO/mGR9scWzw1PDPrmEHHaiCyf0U8qcswf2hWNYzbk59NQRletF2TqDAd14vJKVL2mSZV Jrs1/sYuqW5jjRwHaTMLf0SeXQQPOUgzpkAXgLC8mVgiMt88B0F4fmATckHQGY4YgsJfUF1wMBJ v18PibWT3kban39+t67ff0j+EqnY+Um1XfJZnVAPkL02Ff6Q0qJ5MJGbEgQvbOQf9KoUm9E8Xkw rRj5M3Ki1S6hbypcTaUQG1qROZ2bowNgZ19/ZZM0oHy9eS09Btn2fAwyearg6u6S46QPIdfEAzN wZcNDTsYTWDTZVUzwsZytWOxgngyW2np0+en8PsCLdBCHib3rvkyo X-Google-Smtp-Source: AGHT+IGMtC4mqGRTCqwsD7zQuJKELdqefWUDOU17sadjrHFNIDwPtfJBpjKQ/cUFNH+/Umt7SFD3zg== X-Received: by 2002:a05:6902:90d:b0:e84:43bd:e9b6 with SMTP id 3f1490d57ef6-e86016f89damr6516568276.13.1750893580131; Wed, 25 Jun 2025 16:19:40 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:39 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC v1 32/32] libluo: add tests Date: Wed, 25 Jun 2025 23:18:19 +0000 Message-ID: <20250625231838.1897085-33-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-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: Pratyush Yadav Add a test suite for libluo itself, and for the kernel LUO interface. The below tests are added: 1. init - Tests the initialization and cleanup functions of libluo. 2. state - Tests the luo_get_state() API, which in turn tests the LIVEUPDATE_IOCTL_GET_STATE ioctl 3. preserve - Creates a memfd, preserves it, puts LUO in prepared state, cancels liveupdate, and makes sure memfd is functional. 4. prepared - Puts a memfd in LUO enters prepared state. Then it makes sure the memfd stays functional but remains in restricted mode. It makes sure the memfd can't grow or shrink, but can be read from or written to. 5. transitions - Tests transitions from normal to prepared to cancel state work. 6. error - Tests error handling of the library on invalid inputs. 7. kexec - Tests the main functionality of LUO -- preserving a FD over kexec. It creates a memfd with random data, saves the data to a file on disk, and then preserves the FD and goes into prepared state. Now the test runner must perform a kexec. Once rebooted, running the test again resumes the test. It fetches the memfd back, nd compares its content with the saved data on disk. A specific test can be selected or excluded uring the -t or -e arguments. Sample run: $ ./test LibLUO Test Suite =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Testing initialization and cleanup... PASSED Testing get_state... PASSED (current state: normal) Testing state transitions... PASSED Testing fd_preserve with freeze and cancel... PASSED Testing operations on prepared memfd... PASSED Testing error handling... PASSED Testing fd preserve for kexec... READY FOR KEXEC (token: 3) Run kexec now and then run this test again to complete. All requested tests completed. Signed-off-by: Pratyush Yadav Signed-off-by: Pasha Tatashin --- tools/lib/luo/Makefile | 4 + tools/lib/luo/tests/.gitignore | 1 + tools/lib/luo/tests/Makefile | 18 + tools/lib/luo/tests/test.c | 848 +++++++++++++++++++++++++++++++++ 4 files changed, 871 insertions(+) create mode 100644 tools/lib/luo/tests/.gitignore create mode 100644 tools/lib/luo/tests/Makefile create mode 100644 tools/lib/luo/tests/test.c diff --git a/tools/lib/luo/Makefile b/tools/lib/luo/Makefile index e8f6bd3b9e85..ef4c489efcc5 100644 --- a/tools/lib/luo/Makefile +++ b/tools/lib/luo/Makefile @@ -29,9 +29,13 @@ $(SHARED_LIB): $(OBJS) cli: $(STATIC_LIB) $(MAKE) -C cli =20 +tests: $(STATIC_LIB) + $(MAKE) -C tests + clean: rm -f $(OBJS) $(STATIC_LIB) $(SHARED_LIB) $(MAKE) -C cli clean + $(MAKE) -C tests clean =20 install: all install -d $(DESTDIR)/usr/local/lib diff --git a/tools/lib/luo/tests/.gitignore b/tools/lib/luo/tests/.gitignore new file mode 100644 index 000000000000..ee4c92682341 --- /dev/null +++ b/tools/lib/luo/tests/.gitignore @@ -0,0 +1 @@ +/test diff --git a/tools/lib/luo/tests/Makefile b/tools/lib/luo/tests/Makefile new file mode 100644 index 000000000000..7f4689722ff6 --- /dev/null +++ b/tools/lib/luo/tests/Makefile @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +TESTS =3D test +INCLUDE_DIR =3D ../include +HEADERS =3D $(wildcard $(INCLUDE_DIR)/*.h) + +CC =3D gcc +CFLAGS =3D -Wall -Wextra -O2 -g -I$(INCLUDE_DIR) +LDFLAGS =3D -L.. -l:libluo.a + +.PHONY: all clean + +all: $(TESTS) + +test: test.c ../libluo.a $(HEADERS) + $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) + +clean: + rm -f $(TESTS) diff --git a/tools/lib/luo/tests/test.c b/tools/lib/luo/tests/test.c new file mode 100644 index 000000000000..7963ae8ebadf --- /dev/null +++ b/tools/lib/luo/tests/test.c @@ -0,0 +1,848 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +#define _GNU_SOURCE +/** + * @file test.c + * @brief Test program for the LibLUO library + * + * This program tests the basic functionality of the LibLUO library. + * + * Copyright (C) 2025 Amazon.com Inc. or its affiliates. + * Author: Pratyush Yadav + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Path to store token for kexec test */ +#define TOKEN_FILE "libluo_test_token" +#define TEST_DATA_FILE "libluo_test_data" +#define MEMFD_NAME "libluo_test_memfd" + +/* Size of the random data buffer (1 MiB) */ +#define RANDOM_BUFFER_SIZE (1 << 20) +static char random_buffer[RANDOM_BUFFER_SIZE]; + +/* Test IDs */ +#define TEST_INIT_CLEANUP (1 << 0) +#define TEST_GET_STATE (1 << 1) +#define TEST_FD_PRESERVE (1 << 2) +#define TEST_ERROR_HANDLING (1 << 3) +#define TEST_FD_KEXEC (1 << 4) +#define TEST_FD_PREPARED (1 << 5) +#define TEST_STATE_TRANSITIONS (1 << 6) +#define TEST_ALL (TEST_INIT_CLEANUP | TEST_GET_STATE | \ + TEST_FD_PRESERVE | TEST_ERROR_HANDLING | \ + TEST_FD_KEXEC | TEST_FD_PREPARED | \ + TEST_STATE_TRANSITIONS) + +/* + * luo_fd_preserve() needs a unique token. Generate a monotonically increa= sing + * token. + */ +static uint64_t next_token() +{ + static uint64_t token =3D 0; + + return token++; +} + +/* Read exactly specified size from fd. Any less results in error. */ +static int read_size(int fd, char *buffer, size_t size) +{ + size_t remain =3D size; + ssize_t bytes_read; + + while (remain) { + bytes_read =3D read(fd, buffer, remain); + if (bytes_read =3D=3D 0) + return -ENODATA; + if (bytes_read < 0) + return -errno; + + remain -=3D bytes_read; + } + + return 0; +} + +/* Write exactly specified size from fd. Any less results in error. */ +static int write_size(int fd, const char *buffer, size_t size) +{ + size_t remain =3D size; + ssize_t written; + + while (remain) { + written =3D write(fd, buffer, remain); + if (written =3D=3D 0) + return -EIO; + if (written < 0) + return -errno; + + remain -=3D written; + } + + return 0; +} + +static int generate_random_data(char *buffer, size_t size) +{ + int fd, ret; + + fd =3D open("/dev/urandom", O_RDONLY); + if (fd < 0) + return -errno; + + ret =3D read_size(fd, buffer, size); + close(fd); + return ret; +} + +static int save_test_data(const char *buffer, size_t size) +{ + int fd, ret; + + fd =3D open(TEST_DATA_FILE, O_RDWR); + if (fd < 0) + return -errno; + + ret =3D write_size(fd, buffer, size); + close(fd); + return ret; +} + +static int load_test_data(char *buffer, size_t size) +{ + int fd, ret; + + fd =3D open(TEST_DATA_FILE, O_RDONLY); + if (fd < 0) + return -errno; + + ret =3D read_size(fd, buffer, size); + close(fd); + return ret; +} + +/* Create and initialize a memfd with random data. */ +static int create_test_fd(const char *memfd_name, char *buffer, size_t siz= e) +{ + int fd; + int ret; + + fd =3D memfd_create(memfd_name, 0); + if (fd < 0) + return -errno; + + ret =3D generate_random_data(buffer, size); + if (ret < 0) { + close(fd); + return ret; + } + + if (write_size(fd, buffer, size) < 0) { + close(fd); + return -errno; + } + + /* Reset file position to beginning */ + if (lseek(fd, 0, SEEK_SET) < 0) { + close(fd); + return -errno; + } + + return fd; +} + +/* + * Make sure fd contains expected data up to size. Returns 0 on success, 1= on + * data mismatch, -errno on error. + */ +static int verify_fd_content(int fd, const char *expected_data, size_t siz= e) +{ + char buffer[size]; + int ret; + + /* Reset file position to beginning */ + if (lseek(fd, 0, SEEK_SET) < 0) + return -errno; + + ret =3D read_size(fd, buffer, size); + if (ret < 0) + return ret; + + if (memcmp(buffer, expected_data, size) !=3D 0) + return 1; + + return 0; +} + +/* Save token to file for kexec test. */ +static int save_token(uint64_t token) +{ + FILE *file =3D fopen(TOKEN_FILE, "w"); + + if (!file) + return -errno; + + if (fprintf(file, "%lu", token) < 0) { + fclose(file); + return -errno; + } + + fclose(file); + return 0; +} + +/* Load token from file for kexec test. */ +static int load_token(uint64_t *token) +{ + FILE *file =3D fopen(TOKEN_FILE, "r"); + + if (!file) + return -errno; + + if (fscanf(file, "%lu", token) !=3D 1) { + fclose(file); + return -EINVAL; + } + + fclose(file); + return 0; +} + +/* Test initialization and cleanup */ +static void test_init_cleanup(void) +{ + int ret; + + printf("Testing initialization and cleanup... "); + + ret =3D luo_init(); + if (ret < 0) { + printf("FAILED (init: %s)\n", strerror(-ret)); + return; + } + + luo_cleanup(); + printf("PASSED\n"); +} + +/* Test getting LUO state */ +static void test_get_state(void) +{ + int ret; + enum liveupdate_state state; + + printf("Testing get_state... "); + + ret =3D luo_init(); + if (ret < 0) { + printf("FAILED (init: %s)\n", strerror(-ret)); + return; + } + + ret =3D luo_get_state(&state); + if (ret < 0) { + printf("FAILED (get_state: %s)\n", strerror(-ret)); + luo_cleanup(); + return; + } + + printf("PASSED (current state: %s)\n", luo_state_to_string(state)); + luo_cleanup(); +} + +/* Test preserving and unpreserving a file descriptor with prepare and can= cel */ +static void test_fd_preserve_unpreserve(void) +{ + uint64_t token =3D next_token(); + int ret, fd =3D -1; + + printf("Testing fd_preserve with freeze and cancel... "); + + ret =3D luo_init(); + if (ret < 0) { + printf("FAILED (init: %s)\n", strerror(-ret)); + return; + } + + fd =3D create_test_fd(MEMFD_NAME, random_buffer, sizeof(random_buffer)); + if (fd < 0) { + ret =3D fd; + printf("FAILED (create_test_fd: %s)\n", strerror(-ret)); + goto out_cleanup; + } + + ret =3D luo_fd_preserve(fd, token); + if (ret < 0) { + printf("FAILED (preserve: %s)\n", strerror(-ret)); + goto out_close_fd; + } + + ret =3D luo_prepare(); + if (ret < 0) { + printf("FAILED (prepare: %s)\n", strerror(-ret)); + goto out_unpreserve; + } + + ret =3D luo_cancel(); + if (ret < 0) { + printf("FAILED (cancel: %s)\n", strerror(-ret)); + goto out_unpreserve; + } + + ret =3D luo_fd_unpreserve(token); + if (ret < 0) { + printf("FAILED (unpreserve: %s)\n", strerror(-ret)); + goto out_close_fd; + } + + ret =3D verify_fd_content(fd, random_buffer, sizeof(random_buffer)); + if (ret < 0) { + printf("FAILED (verify_fd_content: %s)\n", + ret =3D=3D 1 ? "data mismatch" : strerror(-ret)); + goto out_close_fd; + } + + printf("PASSED\n"); + goto out_close_fd; + +out_unpreserve: + luo_fd_unpreserve(token); +out_close_fd: + close(fd); +out_cleanup: + luo_cleanup(); +} + +/* Test error handling with invalid inputs. */ +static void test_error_handling(void) +{ + int ret; + + printf("Testing error handling... "); + + ret =3D luo_init(); + if (ret < 0) { + printf("FAILED (init: %s)\n", strerror(-ret)); + return; + } + + /* Test with invalid file descriptor */ + ret =3D luo_fd_preserve(-1, next_token()); + if (ret !=3D -EINVAL) { + printf("FAILED (expected EINVAL for invalid fd, got %d)\n", ret); + luo_cleanup(); + return; + } + + /* Test with NULL state pointer */ + ret =3D luo_get_state(NULL); + if (ret !=3D -EINVAL) { + printf("FAILED (expected EINVAL for NULL state, got %d)\n", ret); + luo_cleanup(); + return; + } + + luo_cleanup(); + printf("PASSED\n"); +} + +/* Test preserving a file descriptor for kexec reboot */ +static void test_fd_preserve_for_kexec(void) +{ + enum liveupdate_state state; + int fd =3D -1, ret; + uint64_t token; + + ret =3D luo_init(); + if (ret < 0) { + printf("FAILED (init: %s)\n", strerror(-ret)); + return; + } + + /* Check if we're in post-kexec state */ + ret =3D luo_get_state(&state); + if (ret < 0) { + printf("FAILED (get_state: %s)\n", strerror(-ret)); + goto out_cleanup; + } + + if (state =3D=3D LIVEUPDATE_STATE_UPDATED) { + /* Post-kexec: restore the file descriptor */ + printf("Testing memfd restore after kexec... "); + + ret =3D load_token(&token); + if (ret < 0) { + printf("FAILED (load_token: %s)\n", strerror(-ret)); + goto out_cleanup; + } + + ret =3D load_test_data(random_buffer, RANDOM_BUFFER_SIZE); + if (ret < 0) { + printf("FAILED (load_test_data: %s)\n", strerror(-ret)); + goto out_cleanup; + } + + ret =3D luo_fd_restore(token, &fd); + if (ret < 0) { + printf("FAILED (restore: %s)\n", strerror(-ret)); + goto out_cleanup; + } + + /* Verify the file descriptor content with stored data. */ + ret =3D verify_fd_content(fd, random_buffer, RANDOM_BUFFER_SIZE); + if (ret) { + printf("FAILED (verify_fd_content: %s)\n", + ret =3D=3D 1 ? "data mismatch" : strerror(-ret)); + goto out_close_fd; + } + + ret =3D luo_finish(); + if (ret < 0) { + printf("FAILED (finish: %s)\n", strerror(-ret)); + goto out_close_fd; + } + + printf("PASSED\n"); + goto out_close_fd; + } else { + /* Pre-kexec: preserve the file descriptor */ + printf("Testing fd preserve for kexec... "); + + fd =3D create_test_fd(MEMFD_NAME, random_buffer, RANDOM_BUFFER_SIZE); + if (fd < 0) { + ret =3D fd; + printf("FAILED (create_test_fd: %s)\n", strerror(-ret)); + goto out_cleanup; + } + + /* Save random data to file for post-kexec verification */ + ret =3D save_test_data(random_buffer, RANDOM_BUFFER_SIZE); + if (ret < 0) { + printf("FAILED (save_test_data: %s)\n", strerror(-ret)); + goto out_close_fd; + } + + token =3D next_token(); + ret =3D luo_fd_preserve(fd, token); + if (ret < 0) { + printf("FAILED (preserve: %s)\n", strerror(-ret)); + goto out_close_fd; + } + + /* Save token to file for post-kexec restoration */ + ret =3D save_token(token); + if (ret < 0) { + printf("FAILED (save_token: %s)\n", strerror(-ret)); + goto out_unpreserve; + } + + ret =3D luo_prepare(); + if (ret < 0) { + printf("FAILED (prepare: %s)\n", strerror(-ret)); + goto out_unpreserve; + } + + printf("READY FOR KEXEC (token: %lu)\n", token); + printf("Run kexec now and then run this test again to complete.\n"); + + /* Note: At this point, the system should perform kexec reboot. + * The test will continue in the new kernel with the + * LIVEUPDATE_STATE_UPDATED state. + * + * Since the FD is now preserved, we can close it. + */ + goto out_close_fd; + } + +out_unpreserve: + luo_fd_unpreserve(token); +out_close_fd: + close(fd); +out_cleanup: + luo_cleanup(); +} + +/* + * Test that prepared memfd can't grow or shrink, but reads and writes sti= ll + * work. + */ +static void test_fd_prepared_operations(void) +{ + char write_buffer[128] =3D {'A'}; + size_t initial_size, file_size; + int ret, fd =3D -1; + uint64_t token; + + printf("Testing operations on prepared memfd... "); + + ret =3D luo_init(); + if (ret < 0) { + printf("FAILED (init: %s)\n", strerror(-ret)); + return; + } + + /* Create and initialize test file descriptor */ + fd =3D create_test_fd(MEMFD_NAME, random_buffer, sizeof(random_buffer)); + if (fd < 0) { + ret =3D fd; + printf("FAILED (create_test_fd: %s)\n", strerror(-ret)); + goto out_cleanup; + } + + /* Get initial file size */ + ret =3D lseek(fd, 0, SEEK_END); + if (ret < 0) { + printf("FAILED (lseek to end: %s)\n", strerror(errno)); + goto out_close_fd; + } + initial_size =3D (size_t)ret; + + token =3D next_token(); + ret =3D luo_fd_preserve(fd, token); + if (ret < 0) { + printf("FAILED (preserve: %s)\n", strerror(-ret)); + goto out_close_fd; + } + + ret =3D luo_prepare(); + if (ret < 0) { + printf("FAILED (prepare: %s)\n", strerror(-ret)); + goto out_unpreserve; + } + + /* Test 1: Write to the prepared file descriptor (within existing size) */ + if (lseek(fd, 0, SEEK_SET) < 0) { + printf("FAILED (lseek before write: %s)\n", strerror(errno)); + goto out_cancel; + } + + /* Write buffer is smaller than total file size. */ + ret =3D write_size(fd, write_buffer, sizeof(write_buffer)); + if (ret < 0) { + printf("FAILED (write to prepared fd: %s)\n", strerror(errno)); + goto out_cancel; + } + + ret =3D verify_fd_content(fd, write_buffer, sizeof(write_buffer)); + if (ret) { + printf("FAILED (verify_fd_content after write: %s)\n", + ret =3D=3D 1 ? "data mismatch" : strerror(-ret)); + goto out_cancel; + } + + /* Test 2: Try to grow the file using write(). */ + + /* First, seek to one byte behind initial size. */ + ret =3D lseek(fd, initial_size - 1, SEEK_SET); + if (ret < 0) { + printf("FAILED: (lseek after write verification: %s)\n", + strerror(errno)); + } + + /* + * Then, write some data that should increase the file size. This should + * fail. + */ + ret =3D write_size(fd, write_buffer, sizeof(write_buffer)); + if (ret =3D=3D 0) { + printf("FAILED: (write beyond initial size succeeded)\n"); + goto out_cancel; + } + + ret =3D lseek(fd, 0, SEEK_END); + if (ret < 0) { + printf("FAILED (lseek after larger write: %s)\n", strerror(errno)); + goto out_cancel; + } + file_size =3D (size_t)ret; + + if (file_size !=3D initial_size) { + printf("FAILED (file grew beyond initial size: %zu !=3D %zu)\n", + (size_t)file_size, initial_size); + goto out_cancel; + } + + /* Test 3: Try to shrink the file using truncate */ + ret =3D ftruncate(fd, initial_size / 2); + if (ret =3D=3D 0) { + printf("FAILED (file was truncated)\n"); + goto out_cancel; + } + + ret =3D lseek(fd, 0, SEEK_END); + if (ret < 0) { + printf("FAILED (lseek after shrink attempt: %s)\n", strerror(errno)); + goto out_cancel; + } + file_size =3D (size_t)ret; + + if (file_size !=3D initial_size) { + printf("FAILED (file shrunk from initial size: %zu !=3D %zu)\n", + (size_t)file_size, initial_size); + goto out_cancel; + } + + ret =3D luo_cancel(); + if (ret < 0) { + printf("FAILED (cancel: %s)\n", strerror(-ret)); + goto out_unpreserve; + } + + ret =3D luo_fd_unpreserve(token); + if (ret < 0) { + printf("FAILED (unpreserve: %s)\n", strerror(-ret)); + goto out_close_fd; + } + + printf("PASSED\n"); + goto out_close_fd; + +out_cancel: + luo_cancel(); +out_unpreserve: + luo_fd_unpreserve(token); +out_close_fd: + close(fd); +out_cleanup: + luo_cleanup(); +} + +static int test_prepare_cancel_sequence(const char *sequence_name) +{ + int ret; + enum liveupdate_state state; + + /* Initial state should be NORMAL */ + ret =3D luo_get_state(&state); + if (ret < 0) { + printf("FAILED (%s get initial state failed: %s)\n", + sequence_name, strerror(-ret)); + return ret; + } + + if (state !=3D LIVEUPDATE_STATE_NORMAL) { + printf("FAILED (%s unexpected initial state: %s)\n", + sequence_name, luo_state_to_string(state)); + return -EINVAL; + } + + /* Test NORMAL -> PREPARED transition */ + ret =3D luo_prepare(); + if (ret < 0) { + printf("FAILED (%s prepare failed: %s)\n", + sequence_name, strerror(-ret)); + return ret; + } + + ret =3D luo_get_state(&state); + if (ret < 0) { + printf("FAILED (%s get state after prepare failed: %s)\n", + sequence_name, strerror(-ret)); + goto out_cancel; + } + + if (state !=3D LIVEUPDATE_STATE_PREPARED) { + printf("FAILED (%s expected PREPARED state, got %s)\n", + sequence_name, luo_state_to_string(state)); + ret =3D -EINVAL; + goto out_cancel; + } + + /* Test PREPARED -> NORMAL transition via cancel */ + ret =3D luo_cancel(); + if (ret < 0) { + printf("FAILED (%s cancel failed: %s)\n", + sequence_name, strerror(-ret)); + return ret; + } + + ret =3D luo_get_state(&state); + if (ret < 0) { + printf("FAILED (%s get state after cancel failed: %s)\n", + sequence_name, strerror(-ret)); + return ret; + } + + if (state !=3D LIVEUPDATE_STATE_NORMAL) { + printf("FAILED (%s expected NORMAL state after cancel, got %s)\n", + sequence_name, luo_state_to_string(state)); + return -EINVAL; + } + + return 0; + +out_cancel: + luo_cancel(); + return ret; +} + +/* Test all state transitions */ +static void test_state_transitions(void) +{ + int ret; + + printf("Testing state transitions... "); + + ret =3D luo_init(); + if (ret < 0) { + printf("FAILED (init failed: %s)\n", strerror(-ret)); + return; + } + + /* Test first prepare -> cancel sequence */ + ret =3D test_prepare_cancel_sequence("first"); + if (ret < 0) + goto out; + + /* + * Test second prepare -> freeze -> cancel sequence in case the + * previous cancellation left some side effects. + */ + ret =3D test_prepare_cancel_sequence("second"); + if (ret < 0) + goto out; + + printf("PASSED\n"); + +out: + luo_cleanup(); +} + +/* Test name to flag mapping */ +struct test { + const char *name; + void (*fn)(void); + unsigned int flag; +}; + +/* Array of test names and their corresponding flags */ +static struct test tests[] =3D { + {"init", test_init_cleanup, TEST_INIT_CLEANUP}, + {"state", test_get_state, TEST_GET_STATE}, + {"transitions", test_state_transitions, TEST_STATE_TRANSITIONS}, + {"preserve", test_fd_preserve_unpreserve, TEST_FD_PRESERVE}, + {"prepared", test_fd_prepared_operations, TEST_FD_PREPARED}, + {"error", test_error_handling, TEST_ERROR_HANDLING}, + {"kexec", test_fd_preserve_for_kexec, TEST_FD_KEXEC}, + {NULL, NULL, 0} +}; + +static int parse_test_names(char *arg, unsigned int *flags) +{ + char *name; + struct test *test; + + *flags =3D 0; + name =3D strtok(arg, ","); + + while (name !=3D NULL) { + test =3D tests; + while (test->name) { + if (strcmp(name, test->name) =3D=3D 0) { + *flags |=3D test->flag; + break; + } + test++; + } + + /* Check if we found a match */ + if (!test->name) { + printf("Unknown test: %s\n", name); + return 1; + } + + name =3D strtok(NULL, ","); + } + + return 0; +} + +static void usage(const char *program_name) +{ + printf("Usage: %s [options]\n", program_name); + printf("Options:\n"); + printf(" -h, --help Show this help message\n"); + printf(" -t, --test=3DTEST_ID Run specific test(s)\n"); + printf(" -e, --exclude=3DTEST_ID Exclude specific test(s)\n"); + printf("\n"); + printf("Test IDs:\n"); + printf(" init - Test initialization and cleanup\n"); + printf(" state - Test getting LUO state\n"); + printf(" preserve - Test memfd preserve/unpreserve with freeze/cancel= \n"); + printf(" prepared - Test memfd functions can read/write but not grow = after prepare\n"); + printf(" transitions - Test all state transitions (NORMAL->PREPARED->FRO= ZEN->NORMAL)\n"); + printf(" error - Test error handling\n"); + printf(" kexec - Test memfd preserve for kexec\n"); + printf("\n"); + printf("Multiple tests can be specified with comma separation.\n"); + printf("Example: %s --test=3Dinit,state --exclude=3Dkexec\n", program_nam= e); + printf("By default, all tests are run.\n"); +} + +int main(int argc, char *argv[]) +{ + unsigned int tests_to_run =3D TEST_ALL; + unsigned int tests_to_exclude =3D 0; + struct option long_options[] =3D { + {"help", no_argument, 0, 'h'}, + {"test", required_argument, 0, 't'}, + {"exclude", required_argument, 0, 'e'}, + {0, 0, 0, 0} + }; + struct test *test; + int opt; + + printf("LibLUO Test Suite\n"); + printf("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n\n"); + + if (!luo_is_available()) { + printf("LUO is not available on this system. Skipping tests.\n"); + return 0; + } + + while ((opt =3D getopt_long(argc, argv, "ht:e:", long_options, NULL)) != =3D -1) { + switch (opt) { + case 'h': + usage(argv[0]); + return 0; + case 't': + if (parse_test_names(optarg, &tests_to_run)) + return 1; + break; + case 'e': + if (parse_test_names(optarg, &tests_to_exclude)) + return 1; + break; + default: + printf("Try '%s --help' for more information.\n", argv[0]); + return 1; + } + } + + /* Apply exclusions to the tests to run */ + tests_to_run &=3D ~tests_to_exclude; + if (!tests_to_run) { + printf("ERROR: all tests excluded\n"); + return 1; + } + + /* Run selected tests */ + test =3D tests; + while (test->name) { + if (tests_to_run & test->flag) + test->fn(); + test++; + } + + printf("\nAll requested tests completed.\n"); + return 0; +} --=20 2.50.0.727.gbf7dc18ff4-goog