From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAC2DC7EE30 for ; Wed, 25 Jun 2025 09:36:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3FFB46B00AB; Wed, 25 Jun 2025 05:36:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D70E6B00AC; Wed, 25 Jun 2025 05:36:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 313C86B00B0; Wed, 25 Jun 2025 05:36:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1DB0E6B00AB for ; Wed, 25 Jun 2025 05:36:59 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C59305FE27 for ; Wed, 25 Jun 2025 09:36:58 +0000 (UTC) X-FDA: 83593418916.21.383F8E8 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf13.hostedemail.com (Postfix) with ESMTP id EC71E20006 for ; Wed, 25 Jun 2025 09:36:56 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=u7luPxmv; spf=pass (imf13.hostedemail.com: domain of brauner@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=brauner@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750844217; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=C47tyzNjAXqQH2LqgzfxUuYtQhWcNRqUcEJdMyUYEtE=; b=nnYQeb/xlS6AW0PTYTpD5+d/gjvtAZlfX5sVHFZeojO4vIhxI4q0qq9y26FhlCKzlKuN5W hsuhkP9iOMbWeSFyXn4rfp/MJmFeTj7dIqlhczkwru+LL06nL9d4St2vCZw/NU7Txxpi0P QJVe7irpSytK6NtZS/GFSoWRoOP4fnY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750844217; a=rsa-sha256; cv=none; b=zBdT2PfTFDKosZU2CRwof4NLZffGrDv0uFErJcqXTNKtHgpwD4El7LJEbRByaclzxB0JIl UdYx0UaGXzO6s2J1IIVwWMG6tt2rZ0VbpYWSTm+lTu3AN+8NVgdEDy5OfrminuV44BRwLM GGx7JiMUMThQzk8IsKeoBgIykL5scLw= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=u7luPxmv; spf=pass (imf13.hostedemail.com: domain of brauner@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=brauner@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 97FE345355; Wed, 25 Jun 2025 09:36:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6093C4CEEA; Wed, 25 Jun 2025 09:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750844215; bh=LrBJpzLZVKD/XyYH7qiSh64rD3KiYAMp2WwFDXgbxuA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=u7luPxmvAG9P9gnxLi1A3yj+TGZe9hymhackeGESDMt8cglDHW8K030A7/lXrC7BA ZqqzyA2UeYCa5rWcnQb5uOQvXpCMOuqKPCskFiSHeJeowZQigNSnXsbAdfY18oIbzO I+J752qUcO9IMpx2HRaR3j/9E1xSXo4YTLztGaono20osr3OCGfdvCdyAHdd06Gvn5 iQrQiI44bszW+2AssC6Z5/dNmyWOj5L2gRCNZwPLTjJ8+g7wEHxRcoV61QNMskB2QJ jyII/W1OJp+b6cPS2eepOQNhh/sOnJ/0nKsdkvCkZ4gpKQ7E9XZtS4oMbHMb3VHUmC +AvrUrt2Ocaxg== Date: Wed, 25 Jun 2025 11:36:40 +0200 From: Christian Brauner To: Pasha Tatashin Cc: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.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 Subject: Re: [RFC v2 10/16] luo: luo_ioctl: add ioctl interface Message-ID: <20250625-akrobatisch-libellen-352997eb08ef@brauner> References: <20250515182322.117840-1-pasha.tatashin@soleen.com> <20250515182322.117840-11-pasha.tatashin@soleen.com> <20250624-akzeptabel-angreifbar-9095f4717ca4@brauner> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: EC71E20006 X-Stat-Signature: 1yijw757wp8gzdkdwtjshtmu8sb33tx9 X-Rspam-User: X-HE-Tag: 1750844216-48256 X-HE-Meta: U2FsdGVkX1971KJyP+G91iBa7GLlMoIelx0+eYnGiHQvFapSVk1Ww4i46y0aqeHv1vTG1l4m8KAUw+at1EO/tlasDYz25kpywLTKyhkxugf7mQj1O5nNdQgUwsfqI2mJ3+88RgsKgypgCzS9m3wzfglcUGiZG2jRGM4U5cwGwqUCemVfTQHhekUSKSiczMOL1Y3koA5/Wcd9hrCCDIPdYpSlug+2MJZOc/+agLIQWf4yxqvigroUPVLrB0dvU5NAgebVkFZgyQ2z8m2wgLkA4F5jWJS5aOYoS4A3QqnHUXV0t39cF0QNxkOIsWve+FguhYD4oty3clopEUW9sUJdT+XYubKzlAYcMp+MpU1wdFCtlpgK3h22lYjMURWbJRgQaJmzD1Xw2gMl1GRA2MSeH4o/o6fzkpfLUq+XBlElQmL6FRfmMg3GE3l7M5KT1Kfz6YqYiNlRsnZl/mdZjq4/LOTcuTbD/ifY6nattFrKeY35Q/+AGLnpPR4XqilED62vT1zSqk9k2rWiixtKpml1jRwnx3/4fmMrzTMy1Rv0+tWnxHxvzFw2EPfbwz7pX0aVqtirXjHEaCcFH3+5xCMtymhfCt24NzNY1yt/Y5QkxUzIyO2sr3NMpVvh6EI9FzA2IOGCwjW7ZsG5IHoxFbLmm/u/9Y9Wg6MwgJlQdnYFSW+fc7fez+1EOxD96X7dhzOlbgSTTCuRNNC9lN2yYFA3MLa1ZwGDixjceeEaWGHV7zyoq69+DXz+IzX2+2IDpQmHQnVP9vyojTut76a1SWFpjyK8JqyD25Udt37+l2MKv6AjF+G288XdB7h977Y9A4fwUx3sTMIeFu2yZ4HNKFYCV/HZGYs9JDEt9MohhnHbTz3DbX5XevdDaGuIjOJ0cRiFKDFlG5b9Ov5ddwrTO15HqZEJZ+LBgPR5L4bxMxnLzC488DjOtBArUisXd93RkDpMsAnfJFV8lVMG8S7TVvK rrK4+W7T d2WVpLyMYaaa3bMMIQkxfl/2gZZyUH2iXV59PKOPnATr0YXZZ6ngtfbaF++SIrxmkUHrYE3lw2eiWMo5dS3POw/5by2VF1/jTSswDegKAR1e2c480YvSHeeG8Gz6wDQsU2BruX9FC+NaQts09eXyyB+R+XK5wCFq1zf5MT1VO1Xna8qdvyOl+UnAaZkpmygYumaQlFueMLQuZedcg2KIVg2JDmnWBvm7RKOu5h8cHMPmBm+TV8NK1SQDP5umbgYsEMoGkPoTfigQtk1Kq5zqJfsZsbxhUBTn9rd1KYdNHbFookkW/XgDlL63M6U7Uvft7IQfYxBh87MM12lG4+P2FinErHXmgosrKRY25+zSplvmrnbE1C5INjvo5YmHQH4G+YG21 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: > > I'm not sure why people are so in love with character device based apis. > > It's terrible. It glues everything to devtmpfs which isn't namespacable > > in any way. It's terrible to delegate and extremely restrictive in terms > > of extensiblity if you need additional device entries (aka the loop > > driver folly). > > > > One stupid question: I probably have asked this before and just swapped > > out that I a) asked this already and b) received an explanation. But why > > isn't this a singleton simple in-memory filesystem with a flat > > hierarchy? > > Hi Christian, > > Thank you for the detailed feedback and for raising this important I don't know about detailed but no problem. > design question. I appreciate the points you've made about the > benefits of a filesystem-based API. > > I have thought thoroughly about this and explored various alternatives > before settling on the ioctl-based interface. This design isn't a > sudden decision but is based on ongoing conversations that have been > happening for over two years at LPC, as well as incorporating direct > feedback I received on LUOv1 at LSF/MM. Well, Mike mentioned that ultimately you want to interface this with systemd? And we certainly have never been privy to any of these uapi design conversations. Which is usually not a good sign... > > The choice for an ioctl-based character device was ultimately driven > by the specific lifecycle and dependency management requirements of > the live update process. While a filesystem API offers great > advantages in visibility and hierarchy, filesystems are not typically > designed to be state machines with the complex lifecycle, dependency, > and ownership tracking that LUO needs to manage. > > Let me elaborate on the key aspects that led to the current design: > > 1. session based lifecycle management: The preservation of an FD is > tied to the open instance of /dev/liveupdate. If a userspace agent > opens /dev/liveupdate, registers several FDs for preservation, and > then crashes or exits before the prepare phase is triggered, all FDs > it registered are automatically unregistered. This "session-scoped" > behavior is crucial to prevent leaking preserved resources into the > next kernel if the controlling process fails. This is naturally > handled by the open() and release() file operations on a character > device. It's not immediately obvious how a similar automatic, > session-based cleanup would be implemented with a singleton > filesystem. fwiw fd_context = fsopen("kexecfs") fd_context = fsconfig(FSCONFIG_CMD_CREATE, ...) fd_mnt = fsmount(fd_context, ...) This gets you a private kexecfs instances that's never visible anywhere in the filesystem hierarchy. When the fd is closed everything gets auto cleaned up by the kernel. No need to umount or anything. > 2. state machine: LUO is fundamentally a state machine (NORMAL -> > PREPARED -> FROZEN -> UPDATED -> NORMAL). As part of this, it provides > a crucial guarantee: any resource that was successfully preserved but > not explicitly reclaimed by userspace in the new kernel by the time > the FINISH event is triggered will be automatically cleaned up and its > memory released. This prevents leaks of unreclaimed resources and is > managed by the orchestrator, which is a concept that doesn't map > cleanly onto standard VFS semantics. I'm not following this. See above. And also any umount can trivially just destroy whatever resource is still left in the filesystem. > > 3. dependency tracking: Unlike normal files, preserved resources for > live update have strong, often complex interdependencies. For example, > a kvmfd might depend on a guestmemfd; an iommufd can depend on vfiofd, > eventfd, memfd, and kvmfd. LUO's current design provides explicit > callback points (prepare, freeze) where these dependencies can be > validated and tracked by the participating subsystems. If a dependency > is not met when we are about to freeze, we can fail the entire > operation and return an error to userspace. The cancel callback > further allows this complex dependency graph to be unwound safely. A > filesystem interface based on linkat() or unlink() doesn't inherently > provide these critical, ordered points for dependency verification and > rollback. > > While I agree that a filesystem offers superior introspection and > integration with standard tools, building this complex, stateful > orchestration logic on top of VFS seemed to be forcing a square peg > into a round hole. The ioctl interface, while more opaque, provides a > direct and explicit way to command the state machine and manage these > complex lifecycle and dependency rules. I'm not going to argue that you have to switch to this kexecfs idea but... You're using a character device that's tied to devmptfs. In other words, you're already using a filesystem interface. Literally the whole code here is built on top of filesystem APIs. So this argument is just very wrong imho. If you can built it on top of a character device using VFS interfaces you can do it as a minimal filesystem. You're free to define the filesystem interface any way you like it. We have a ton of examples there. All your ioctls would just be tied to the fileystem instance instead of the /dev/somethingsomething character device. The state machine could just be implemented the same way. One of my points is that with an fs interface you can have easy state seralization on a per-service level. IOW, you have a bunch of virtual machines running as services or some networking services or whatever. You could just bind-mount an instance of kexecfs into the service and the service can persist state into the instance and easily recover it after kexec. But anyway, you seem to be set on the ioctl() interface, fine.