From nobody Mon Oct 6 08:26:54 2025 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.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 C76482FC005 for ; Wed, 23 Jul 2025 14:47:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753282051; cv=none; b=D9EQBYVggKfRfS9c2Z95eblRz3RbnCD8GjSX7v+u+fdAg2FOH2vXk/YlGvgZndzRN0FU8nJYJ+pvTuFvDFXG0hEhLd0/DBi2Rrq7KScr2dpvVENtF5KGCkvH1E0t06SZVhAXKZ37wdG0xD4Aw/rtXtsmdVsAPz6b8htSWwm/SYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753282051; c=relaxed/simple; bh=Cfi9j2oHaj3a+1RPOlQ6V9S6n7G0Pg+wsLencW8TXUg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tRGkRTZKJu7eyWVrdF1rdYyVbC5GsoDCCNboau47XmTx9MraU14G25SBwBh/hRq/jGnrwQulNWrD6EhnaLQVdLFr32sgBhh1ZlZqDjIsdURg5+zNeN4IQo1Xde9Deq89OAoSAd2PcIcWM0AbkQYrvWsfkQWgw7sGsksIYKyeauo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=3VLGzvMI; arc=none smtp.client-ip=209.85.128.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="3VLGzvMI" Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-70e3e0415a7so262597b3.0 for ; Wed, 23 Jul 2025 07:47:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1753282045; x=1753886845; 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=3VLGzvMIMKYavfCYFadg0jiuAu3OUzrL0BaH9/F63R5glO8OibHyupSKD8hSxQMUIR NOEhS+pD/U7P4QAXFrnu8rBAlciyDtkhYKQnUFTHKnudoSvwua97UteWOkaHJkXOhSr6 fJ6CjLCTtUCuU2+pZEqaFTQkSBRb3WCY0dr7MTYURuet8nSaPA90PO7eEL7lbO+0N1Od WvV6EiHXEkgkTGxSDiFvn7BGCIY6UQQrY6s6oNwUJWt9FERzYewmXPnAmTpFR2uBchKm JTvolDWKXnOLW2bdRKNMqSYM7yFIpA91aTfwX8MFJQXyXgM4YVEX/55Lt/fTRdRTX1lR sXRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753282045; x=1753886845; 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=f5vnhKxEzy7BCK+qA8QbcZL+8O0oOPcmbgPag6JHFj3KoH+LxvfJNKz5RdtzZt5yOl 0e2YIW3mYwg8pKHm5B91W2bm7yMhc4JRij5it3OnCyV8swAA1BHLVCpBqyt6tKo9MoLB BeVChcPWmTuyDKlo7vywPGTJAov2ChDkIW/GaZMcAY+8JqNO07AKyL+yDPLRsGywkenp y3tOMzRfe/DSZa8jryj10R0KTyAvNuGUGwKYCgCz1fW7Q5vEHgIBHRDl5e01KHA6nLS6 W33DyCaAJblBskBh81dZe9fiq9RUKw6PNY/i1a6yRd6SR0hlfzZv6G9KG/9+fSaooKdh f9fg== X-Forwarded-Encrypted: i=1; AJvYcCUedoaW43fA3QVx9uHFHLb/LE7QHZYOKxLXNTPdjq4OxJ1OjtE3sfD3vIqPdcr7qS8fH6X+pSuFnmkdp/o=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/RchY6tIZDN7yWO+6YA2zLVSkASrMAjMcr+b49J6af0t1YifB J/E814jarmEqGwpWbcAVNoR82JhDjwRhwLkxcBzCKybpKJDFgmTjMnvUE2szQngspOM= X-Gm-Gg: ASbGncs6HdM7D+EZqiILMuYcw4rfOblil3Yy4z8aRhHUZhv0I9RC1nlQP7OB4mClqJ9 LCaZhnfnxshXsnDaaYe/idNC0Niok7f5VkgFHrQTRtdWS9eDHTP4zXjxA1zmz6/8KykeYGoC+sI t6LwljdG6UpBGPHMudSQdwn0Yozub0H19Al6JuoP5DxGLPKJTSSvukgQxPBcV5Kr2Bu7C5V0I7I QX4EZg9nJSwFFZxQUkecDtfQHBflvYkSUxr4eyUO4uNdBYOWbM9ug5ZSnVtKjI2/z0RWhIN4iKr 1gY/dkyeqEx6YvFH+kViTQvDZhCLNsp24M8SF7+xrCPB+iDrRYqQ5Dvd6xsfxRLjkzOGGqihEGs TwAl8scmvwIK4kFg2kGZXUlmjTJLhRXm0HZkIC+1htfW3YxyENlH+8rIt/u3g+sUfLdgWObLYB7 DkGXvJWjx2whQ9JQ== X-Google-Smtp-Source: AGHT+IHGYfjoIy8qo73uD860AaG0pKa+DBLv7UTBP+7WtZjAXyEb/laqBGmfDkMsPVthzLrkCs+A9A== X-Received: by 2002:a05:690c:d84:b0:712:c5f7:1f11 with SMTP id 00721157ae682-719a0b52782mr94165947b3.10.1753282044761; Wed, 23 Jul 2025 07:47:24 -0700 (PDT) Received: from soleen.c.googlers.com.com (235.247.85.34.bc.googleusercontent.com. [34.85.247.235]) by smtp.gmail.com with ESMTPSA id 00721157ae682-719532c7e4fsm30482117b3.72.2025.07.23.07.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jul 2025 07:47:23 -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, saeedm@nvidia.com, ajayachandra@nvidia.com, jgg@nvidia.com, parav@nvidia.com, leonro@nvidia.com, witu@nvidia.com Subject: [PATCH v2 15/32] liveupdate: luo_files: implement file systems callbacks Date: Wed, 23 Jul 2025 14:46:28 +0000 Message-ID: <20250723144649.1696299-16-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250723144649.1696299-1-pasha.tatashin@soleen.com> References: <20250723144649.1696299-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