From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796064012; b=Ho6aKPMxTxgfTjCereoSalg1kkHlRwuhXXEb16VPzDoSCNps8xqMKAhqAHJjUMFalMdD zOCFBnR9c/vVkH58JU1Tpc0RZJyLqkhPlXRZDOSWgEQEOmBgeIAsRjHpEPZJWWRa/Pm+y HTYHMAr6/R/rSVLfAcCc8Rdqxrh3DyrdqSczJFXZIiK8JCvF0yS8+bSPby/T833jAU67x os0KdQTWgt4tZ7Zh9wUDLtDOpwdZVy0KVywoxATY1x2QufFTfH2f0lP+ZfSzplXY6Nba+ KpjkjOfHZq23w9d0R2drv6Ff3y167g9aB7K1uxNFykX+AJrBXNpa+TNZDM4fm8jB4PA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796064012; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=YWJ/SVVy2ZrlWNGcYqlitUU+YYVA4+tL7JKQsuCaE0M=; b=36DpButvah0wl+1reov/Kzf8N7pk867U+cFJxmaGWWHKHiQ5NsFxEgvV1skClIVyRGOB s88lFVBSNUreyQ8y03iTH71Us1oU2hQEQ74rsNkpw/FczGdbABUO45xdpq23leLZveFbr pRENheheuwNJxff58viBQduZ5l4uHaqH3kGYWymjgTOJPybZ1uRYhnogTDAO+xkaJk5xv BznFKiZzXUalqeWF+iZ3JncntKJRZLmnJuzlC2Uo8lViHFhH/GtqsXy8oeow7nDji6Twg Ri+VGaCb2PjaE+yj1ke4A6O8bYHT0Is4H5ItwrLA0xg9s+FcV94r2FjHVg5Ft3cEjhA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=eYjMkpTT; arc=none smtp.remote-ip=209.85.214.176 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F422F606A32C for ; Mon, 30 Nov 2026 18:40:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F422F606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=eYjMkpTT Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2f0e8bbc7a4so256165ad.1 for ; Mon, 30 Nov 2026 10:40:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796064011; x=1796668811; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=YWJ/SVVy2ZrlWNGcYqlitUU+YYVA4+tL7JKQsuCaE0M=; b=eYjMkpTTvZzYqiHf077ctfeINNC1w9oQ25M5u/7Dhv1HtBRyyC8ETsWQS49yg1c+55 zjfF98tCvCmtVzScoPQqS45k+XO5UjCkCDF2pd+AD+8xirU5SC9pFOjqq9Kp3J5JuIWr 5Kd3XmNGO6Eve8jmg7y6I3uXSAW+GFOpUJTgmfSvSiqzjgmX+CR3WqnIeUHqvNQwQvFw 5CyMPiSMCcLEEXpwpHsIRL8DN4OEp0/KnnY0fgn046rxsJg2ysY/B14VnyzuE7Zjn5xu 6hwsVc6Y+c5vd2VWwdDtAbtITINSFgzmP4YAgPnCN4ypOG3N7edlWpxAfogGR3Bzf/Oo ptyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796064011; x=1796668811; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=YWJ/SVVy2ZrlWNGcYqlitUU+YYVA4+tL7JKQsuCaE0M=; b=KH9e6azntcW85+x6CRw2NUedGctHloAj2ASu68Pn8jm6/NB7fbGsJwzrsdL3aggMyc Cszjic89l0aNrDPEgK5idfb968ram9Jybtrr3A+uT7muwecCNhRcpf1e/9oTLnicr0+X KGBLLfx6SEnR3WzcO642ZYPR0y6kA16XtY0BeP7PkL9oxV6axOfxQgvkp4XqhDF5odVN CzWGPSAipGj+LwXVkzZLjaCOH7Jyb/f4wVpVoogIi/LNr81ZTfWAQUfJdWPwxrCNvrBJ DsiqI1nOLhxSaFWyHHGMqUX4x/NLR8pKuX9/qd3RlEF+lrNwsquv32TkXJzJPkiDgHX0 /bIQ== X-Forwarded-Encrypted: i=1; AL+hErHgbI/znuOquJPR25shACpb+aZONSgDfF3MERnnSCRUwpar62oSgAL22aUA/7AluInfFUYbCQavGbQDroM=@vger.kernel.org X-Gm-Message-State: APuU4Z/6b9bRLBftFReh6Df69gH8yDH/w2CqMCToFDSAfwA4j8W/JcSd R6xkh8pqQoUmlxUQXgwMEmI77PQ6BlSQAb5ZKG1qd8cpxdhNuxbcCWGXQ8x+2flSHg== X-Gm-Gg: AZFdTZdRFboNh5HHcNYmdPVvzsF6+H+veV1m9vL0pgqjX4WpwacCoitB42epcSNdn9R s//m71+b/G2xhFNfZBLeqGLEtG728wBFxN5wS5iDelB1IHQ5fg0vlLQsaz83wmXZHx38HoWa5qX +ONkypNykhjRcd5o9PHvquTLtFcxTWtj7pdzOxpASiHTUMxlVNVfG2rwlc13XJ0fnHCVRuX28+E g8yn49mjsei1XSq8OCA3KeNivHanKuTIs9k6Rt325ot7zgX/ZSF83qNMBBXwaRsqYQbDT92ZFYk S4jcNPOveJduXdRtm5jEBUdne8qVgJbcfH379el6kHN3D8mWx/8FwqXNwP6RyAm1w1OCH5qAYpE 1LwhT6XLw1WjSiNTJJSOowiefnY47BejgRxFMb65ufeEM3I9AARk0+P6fNCNXR2AcTULz+2usku Zym1sCav05CT2IQQ7KqVc+BDle1PRG1TGpY4WSz15R8oN4kR+YTXiTKrwTSTLiSPj7ZS1wUUXpr rpV8iWpPPQeGD2gRcMYdVD8K13z1SfmS5slLC+jGqLrPYHxV1Gx7FA0ahb5rdVAreLGCJ5U8yni T7Y4XRTRrb0ZYNsaiCBuEYRLZyecp9XjXPWMKe8LXlWH8lkTs+84hmKg0dh9oRJi+5XsjqJr1k3 PmURdTemoSpmQ X-Received: by 2002:a17:903:ace:b0:2f0:18e:8fe4 with SMTP id d9443c01a7336-2f0666f7f86mr29627745ad.15.1796064010512; Mon, 30 Nov 2026 10:40:10 -0800 (PST) Received: from google.com (105.211.142.34.bc.googleusercontent.com. [34.142.211.105]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87077944bsm18482352b3a.2.2026.11.30.10.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 10:40:09 -0800 (PST) Date: Mon, 30 Nov 2026 18:40:01 +0000 From: Pranjal Shrivastava To: Samiullah Khawaja Cc: Joerg Roedel , Will Deacon , Lu Baolu , Jason Gunthorpe , David Woodhouse , Robin Murphy , Kevin Tian , Alex Williamson , Shuah Khan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Pratyush Yadav , Pasha Tatashin , David Matlack , Andrew Morton , Vipin Sharma , Ankit Soni , Nicolin Chen , John Starks Subject: Re: [PATCH v8 02/18] iommu: Implement IOMMU Live update FLB callbacks Message-ID: References: <20261123044949.3610702-1-skhawaja@google.com> <20261123044949.3610702-3-skhawaja@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261123044949.3610702-3-skhawaja@google.com> On Mon, Nov 23, 2026 at 04:49:33AM +0000, Samiullah Khawaja wrote: > Add liveupdate FLB for IOMMU state preservation. Use KHO preserve memory > alloc/free helper functions to allocate memory for the IOMMU Live update > FLB object and the serialization structs for device, domain and iommu. > > During retrieve, walk through the preserved obj array headers and > restore each folio. Also recreate the FLB obj. > Minor nit: This still describes the pre-v6 array scheme. Now, retrieve doesn't restore each folio, block folios are restored at teardown via kho_restore_free(). The FLB obj itself is kzalloc'd. Let's refresh it? > Signed-off-by: Samiullah Khawaja > --- > MAINTAINERS | 9 ++ > drivers/iommu/Kconfig | 12 ++ > drivers/iommu/Makefile | 1 + > drivers/iommu/liveupdate.c | 241 +++++++++++++++++++++++++++++++ > include/linux/iommu-liveupdate.h | 28 ++++ > include/linux/kho/abi/iommu.h | 190 ++++++++++++++++++++++++ > 6 files changed, 481 insertions(+) > create mode 100644 drivers/iommu/liveupdate.c > create mode 100644 include/linux/iommu-liveupdate.h > create mode 100644 include/linux/kho/abi/iommu.h > > diff --git a/MAINTAINERS b/MAINTAINERS > index c00d3612c9ac..96ac907af0d6 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -14139,6 +14139,15 @@ F: include/linux/iova.h > F: include/linux/of_iommu.h > F: rust/kernel/iommu/ > > +IOMMU LIVEUPDATE > +M: Samiullah Khawaja > +R: Pranjal Shrivastava > +L: iommu@lists.linux.dev > +S: Maintained > +F: drivers/iommu/liveupdate.c > +F: include/linux/iommu-liveupdate.h > +F: include/linux/kho/abi/iommu.h > + > IOMMUFD > M: Jason Gunthorpe > M: Kevin Tian > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig > index 85a8d7fdfa30..13d4759c3f4c 100644 > --- a/drivers/iommu/Kconfig > +++ b/drivers/iommu/Kconfig > @@ -421,6 +421,18 @@ config IOMMU_DEBUG_PAGEALLOC > line to activate the runtime checks. > > If unsure, say N. > + > +config IOMMU_LIVEUPDATE > + bool "IOMMU live update state preservation support" > + depends on LIVEUPDATE && IOMMUFD && 64BIT > + help > + Enable support for preserving IOMMU state across a kexec live update. > + > + This allows devices managed by iommufd to maintain their DMA mappings > + during kexec base kernel update. > + > + If unsure, say N. > + > endif # IOMMU_SUPPORT > > source "drivers/iommu/generic_pt/Kconfig" > diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile > index 29a26d2a3af1..248adfabd1bc 100644 > --- a/drivers/iommu/Makefile > +++ b/drivers/iommu/Makefile > @@ -17,6 +17,7 @@ obj-$(CONFIG_IOMMU_IO_PGTABLE_LPAE) += io-pgtable-arm.o > obj-$(CONFIG_IOMMU_IO_PGTABLE_LPAE_KUNIT_TEST) += io-pgtable-arm-selftests.o > obj-$(CONFIG_IOMMU_IO_PGTABLE_DART) += io-pgtable-dart.o > obj-$(CONFIG_IOMMU_IOVA) += iova.o > +obj-$(CONFIG_IOMMU_LIVEUPDATE) += liveupdate.o > obj-$(CONFIG_OF_IOMMU) += of_iommu.o > obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o > obj-$(CONFIG_IPMMU_VMSA) += ipmmu-vmsa.o > diff --git a/drivers/iommu/liveupdate.c b/drivers/iommu/liveupdate.c > new file mode 100644 > index 000000000000..a1f40e242d93 > --- /dev/null > +++ b/drivers/iommu/liveupdate.c > @@ -0,0 +1,241 @@ > +// SPDX-License-Identifier: GPL-2.0-only > + > +/* > + * Copyright (C) 2026, Google LLC > + * Author: Samiullah Khawaja > + */ > + > +/** > + * DOC: IOMMU Live Update > + * > + * The IOMMU subsystem participates in the Live Update process to preserve its > + * IOMMU domains and IOMMU specific state of preserved devices. > + * > + * File-Lifecycle-Bound (FLB) Data > + * =============================== > + * > + * Preserved state of IOMMU HW needs to be restored during boot when the IOMMU is > + * initialized and registered. The preserved IOMMU domains also need to be > + * restored and associated with the preserved devices early during boot. For > + * this reason, IOMMU subsystem uses LUO File-Lifecycle-Bound Data to store some > + * state globally. > + * > + * During preservation of IOMMUFD into LUO, some of the state is stored in the > + * IOMMU FLB so it can be restored during boot. Once the FDs are retrieved from LUO > + * the restored state can be reassociated with the relevant IOMMUFDs. > + * > + * The FLB also contains the state of IOMMU HW that might be shared between > + * multiple devices, domains and iommufds. This is restored early during boot > + * and no re-association of this state is needed later. > + * > + * As the state is preserved using KHO, the FLB handler callbacks are called by > + * LUO only when the KHO is enabled. So there is no need to check whether KHO is > + * enabled in the callback implementation. > + * > + */ > + > +#define pr_fmt(fmt) "iommu: liveupdate: " fmt > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +/** > + * struct iommu_ser_set - Set of serialized objects of one type > + * @bs: KHO block set holding the serialized objects > + * @it: Iterator used to reserve new objects at the end of @bs > + * @count: Number of reserved objects, including the deleted ones > + * @head_pa: Field of struct iommu_flb_ser that records the head of @bs > + */ > +struct iommu_ser_set { > + struct kho_block_set bs; > + struct kho_block_set_it it; > + u64 count; > + u64 *head_pa; > +}; > + > +struct iommu_flb_obj { > + /* Protects the serialized state and the object sets */ > + struct mutex lock; > + struct iommu_flb_ser *ser; > + > + struct iommu_ser_set iommu_set; > + struct iommu_ser_set domain_set; > + struct iommu_ser_set device_set; > +}; > + > +/* > + * Restore a set of serialized objects from the previous kernel. The objects > + * are read using the size recorded by the previous kernel in their header. > + * > + * Failure to restore preserved IOMMU state is considered fatal. This is > + * because the IOMMU translations for preserved IOMMUs were kept enabled in the > + * previous kernel and the preserved devices have their IOMMU domains still > + * present. Not being able to restore means that the memory mapped into > + * preserved domains might be already corrupted by the preserved devices. > + */ > +static void iommu_ser_set_restore(struct iommu_ser_set *set, u64 head_pa) > +{ > + size_t entry_size = sizeof(struct iommu_hdr_ser); > + > + if (head_pa) { > + struct kho_block_header_ser *block = phys_to_virt(head_pa); > + struct iommu_hdr_ser *hdr = (void *)(block + 1); > + > + entry_size = hdr->size; > + } > + > + if (entry_size < sizeof(struct iommu_hdr_ser) || > + entry_size > KHO_BLOCK_SIZE - sizeof(struct kho_block_header_ser)) > + goto err_fatal; > + With the callers passing sizeof(struct iommu_domain_ser) etc. Or, if every layout change is supposed to bump IOMMU_LUO_FLB_VERSION (see the comment on the ABI doc below), simply require that entry_size matches sizeof() of the struct. > + kho_block_set_init(&set->bs, entry_size); > + if (kho_block_set_restore(&set->bs, head_pa)) > + goto err_fatal; > + > + return; > + > +err_fatal: > + panic("Failed to restore IOMMU Live Update FLB\n"); > +} > + > +static void iommu_liveupdate_flb_free(struct iommu_flb_obj *obj) > +{ > + kho_block_set_destroy(&obj->domain_set.bs); > + kho_block_set_destroy(&obj->device_set.bs); > + kho_block_set_destroy(&obj->iommu_set.bs); > + > + kho_unpreserve_free(obj->ser); > + mutex_destroy(&obj->lock); > + kfree(obj); > +} > + [...] > +static void iommu_liveupdate_flb_finish(struct liveupdate_flb_op_args *argp) > +{ > + struct iommu_flb_obj *obj = argp->obj; > + > + kho_block_set_destroy(&obj->domain_set.bs); > + kho_block_set_destroy(&obj->device_set.bs); > + kho_block_set_destroy(&obj->iommu_set.bs); > + > + folio_put(virt_to_folio(obj->ser)); > + mutex_destroy(&obj->lock); > + kfree(obj); > +} Nit: these two differ only in how ser is released. Could they share a common helper? > + > +static int iommu_liveupdate_flb_retrieve(struct liveupdate_flb_op_args *argp) > +{ > + struct iommu_flb_obj *obj; > + struct iommu_flb_ser *ser; > + > + obj = kzalloc_obj(*obj, GFP_KERNEL); > + if (!obj) { > + /* > + * If retrieve fails, the finish path won't be called as > + * can_finish() will fail, preventing the restore. > + */ > + return -ENOMEM; > + } > + > + /* Data must be present and valid from the previous kernel */ > + if (!kho_restore_folio(argp->data)) > + panic("Failed to restore IOMMU Live Update FLB\n"); > + > + ser = phys_to_virt(argp->data); > + > + /* > + * FLB version mismatch is considered fatal for security reasons for > + * now. Check it before restoring the arrays, as their layout depends > + * on the version. > + */ > + if (ser->version != IOMMU_LUO_FLB_VERSION) > + panic("Incoming IOMMU FLB version (v%llu) is incompatible with this kernel (v%d)\n", > + ser->version, IOMMU_LUO_FLB_VERSION); > + > + mutex_init(&obj->lock); > + obj->ser = ser; > + > + iommu_ser_set_restore(&obj->domain_set, ser->domain_block_phys); > + iommu_ser_set_restore(&obj->device_set, ser->device_block_phys); > + iommu_ser_set_restore(&obj->iommu_set, ser->iommu_block_phys); > + argp->obj = obj; > + return 0; > +} > + > +static struct liveupdate_flb_ops iommu_flb_ops = { > + .preserve = iommu_liveupdate_flb_preserve, > + .unpreserve = iommu_liveupdate_flb_unpreserve, > + .retrieve = iommu_liveupdate_flb_retrieve, > + .finish = iommu_liveupdate_flb_finish, > +}; > + > +static struct liveupdate_flb iommu_flb = { > + .compatible = IOMMU_LUO_FLB_COMPATIBLE, > + .ops = &iommu_flb_ops, > +}; > + > +/** > + * iommu_liveupdate_register_flb() - Register IOMMU Live Update FLB > + * @handler: Live Update file handler to associate FLB with > + * > + * Register a Live Update FLB for IOMMU state preservation with the file > + * handler. > + * > + * Return: 0 on success, or negative error code. > + */ > +int iommu_liveupdate_register_flb(struct liveupdate_file_handler *handler) > +{ > + return liveupdate_register_flb(handler, &iommu_flb); > +} > +EXPORT_SYMBOL_GPL(iommu_liveupdate_register_flb); > + > +/** > + * iommu_liveupdate_unregister_flb() - Unregister IOMMU Live Update FLB > + * @handler: Live Update file handler to associate FLB with > + */ > +void iommu_liveupdate_unregister_flb(struct liveupdate_file_handler *handler) > +{ > + liveupdate_unregister_flb(handler, &iommu_flb); > +} > +EXPORT_SYMBOL_GPL(iommu_liveupdate_unregister_flb); > diff --git a/include/linux/iommu-liveupdate.h b/include/linux/iommu-liveupdate.h > new file mode 100644 > index 000000000000..4755ab3cd67a > --- /dev/null > +++ b/include/linux/iommu-liveupdate.h > @@ -0,0 +1,28 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > + > +/* > + * Copyright (C) 2026, Google LLC > + * Author: Samiullah Khawaja > + */ > + > +#ifndef _LINUX_IOMMU_LIVEUPDATE_H > +#define _LINUX_IOMMU_LIVEUPDATE_H > + > +#include > +#include > +#include > + > +#ifdef CONFIG_IOMMU_LIVEUPDATE > +int iommu_liveupdate_register_flb(struct liveupdate_file_handler *handler); > +void iommu_liveupdate_unregister_flb(struct liveupdate_file_handler *handler); > +#else > +static inline int iommu_liveupdate_register_flb(struct liveupdate_file_handler *handler) > +{ > + return 0; > +} > + > +static inline void iommu_liveupdate_unregister_flb(struct liveupdate_file_handler *handler) > +{ > +} > +#endif > +#endif /* _LINUX_IOMMU_LIVEUPDATE_H */ > diff --git a/include/linux/kho/abi/iommu.h b/include/linux/kho/abi/iommu.h > new file mode 100644 > index 000000000000..a36b498941b0 > --- /dev/null > +++ b/include/linux/kho/abi/iommu.h > @@ -0,0 +1,190 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > + > +/* > + * Copyright (C) 2026, Google LLC > + * Author: Samiullah Khawaja > + */ > + > +#ifndef _LINUX_KHO_ABI_IOMMU_H > +#define _LINUX_KHO_ABI_IOMMU_H > + > +#include Nit: This seems to be unused now? Can we remove this? > +#include > +#include > +#include > +#include > + > +/** > + * DOC: IOMMU File-Lifecycle Bound (FLB) Live Update ABI > + * > + * This header defines the ABI for preserving IOMMU state across kexec using > + * Live Update File-Lifecycle Bound (FLB) data. > + * > + * This interface is a contract. Any modification to any of the serialization > + * structs defined here constitutes a breaking change. Such changes require > + * incrementing the version number in IOMMU_LUO_FLB_VERSION. > + * > + * Memory Layout of Serialization Structures: > + * ========================================== > + * > + * Each serialized type (IOMMU, Domain, Device) is stored in a set of KHO > + * serialization blocks (see include/linux/kho/abi/block.h). Each block starts > + * with a struct kho_block_header_ser, followed by the serialized objects of > + * the respective type. Blocks are linked through the next field of the header. > + * These two paragraphs seem to contradict each other. If every change to the structs bumps IOMMU_LUO_FLB_VERSION, and retrieve panics on a version mismatch, then two kernels that successfully hand over state always have identical layouts. The object size can then never change, and hdr.size (and hdr.features) carry no information. If instead size/features are meant to allow compatible changes (e.g. appending a field) without a version bump, the restore side needs to handle that: require entry_size >= sizeof() of the struct being read (see iommu_ser_set_restore() above) and reject unknown feature bits (see below). Let's clarify the policy and update the doc accordingly? > + * Top Level (struct iommu_flb_ser): > + * +---------------------------+ > + * | - iommu_block_phys | > + * | - domain_block_phys | > + * | - device_block_phys | > + * +---------------------------+ > + * > + * For example see below the representation of the domain blocks. > + * > + * +---------------------------+ +---------------------------+ > + * | kho_block_header_ser |-->| kho_block_header_ser |--> NULL > + * | - next | | - next | > + * | - count | | - count | > + * | | | | > + * | [ iommu_domain_ser ] | | [ iommu_domain_ser ] | > + * | [ iommu_domain_ser ] | | [ iommu_domain_ser ] | > + * | ... | | ... | > + * +---------------------------+ +---------------------------+ > + * > + * Each object in a block starts with a common header (iommu_hdr_ser). The > + * size in the header is the size of each object in the block, so the next > + * kernel can read the objects even if their size has changed. > + * For example, the layout of struct iommu_domain_ser is: > + * > + * +-----------------------------+ > + * | iommu_domain_ser | > + * | +-------------------------+ | > + * | | hdr (iommu_hdr_ser) | | > + * | | - ref_count | | > + * | | - deleted / incoming | | > + * | +-------------------------+ | > + * | - top_table_phys | | > + * | - top_level | | > + * | - restored_domain | | > + * +-----------------------------+ > + * This diagram seems to be out of date now, for e.g. hdr_ser now has ref_count, flags, size, features AND iommu_domain_ser also has max_vasz_lg2 and sign_extend which are missing from the diagram. > + * This pattern applies identically to iommu_device_ser and iommu_hw_ser. > + */ > + > +#define IOMMU_LUO_FLB_COMPATIBLE "iommu-liveupdate" > +#define IOMMU_LUO_FLB_VERSION 1 > + > +/** > + * enum iommu_type_ser - Type of the IOMMU being preserved > + * @IOMMU_SER_TYPE_INVALID: Invalid type of IOMMU > + * > + * IOMMU type is stored in the IOMMU HW state to differentiate between various > + * IOMMU HWs. > + */ > +enum iommu_type_ser { > + IOMMU_SER_TYPE_INVALID, > +}; > + > +#define IOMMU_SER_FLAG_DELETED BIT(0) > +#define IOMMU_SER_FLAG_INCOMING BIT(1) > + > +/** > + * struct iommu_hdr_ser - Common header for all serialized IOMMU objects > + * @ref_count: Reference count for the object > + * @flags: Bitmask of IOMMU_SER_FLAG_* flags indicating object state > + * @size: Size of the serialized object > + * @features: Bitmask of object specific features used by the preserved state > + */ > +struct iommu_hdr_ser { > + u32 ref_count; > + u32 flags; > + u32 size; > + u32 features; > +} __packed; > + I'm wondering if we should reject unknown feature bits on restore? IIUC, features (along with size and reserved) was added in v6 to manage compatibility, but it's always written as 0 and never checked on restore (same for the driver specific features fields later in the series). If a feature bit can be added later without bumping IOMMU_LUO_FLB_VERSION, a kernel that doesn't know about it (e.g. after a rollback to this kernel) would silently restore the state without it, unless it rejects unknown bits from the start. Also, this looks like a per-object version of the generic KHO feature header being worked on in [1] (struct kho_ser_hdr, which rejects unknown required features), and also records the entry size in the KHO block header. Would it make sense to move to that once it lands, rather than carrying a separate size/features scheme in the IOMMU ABI? Alternatively, we could cross that bridge when we get to it.. > +/** > + * struct iommu_domain_ser - Serialized state of an IOMMU domain > + * @hdr: Common object header > + * @top_table_phys: Physical address of the top-level page table > + * @top_level: Level of the top-level page table > + * @max_vasz_lg2: Maximum number of bits the VA can contain > + * @sign_extend: FEAT_SIGN_EXTEND is enabled for this domain > + * @padding: Padding > + * @restored_domain: Pointer to the restored domain (valid only after restore) > + */ > +struct iommu_domain_ser { > + struct iommu_hdr_ser hdr; > + u64 top_table_phys; > + u64 top_level; > + u32 max_vasz_lg2; > + u8 sign_extend; > + u8 padding[3]; > + struct iommu_domain *restored_domain; > +} __packed; > + > +/** > + * struct iommu_attachment_ser - Serialized attachment between device and domain. > + * @attachment_id: ID of the attachment between device and domain. > + * @domain_phys: Physical address of the domain > + * @pasid: PASID of the attachment > + * @padding: Padding > + */ > +struct iommu_attachment_ser { > + u64 attachment_id; > + u64 domain_phys; > + u32 pasid; > + u32 padding; > +} __packed; > + > +/** > + * struct iommu_device_ser - Serialized state of a device > + * @hdr: Common object header > + * @devid: Device ID > + * @pci_domain_nr: PCI domain number > + * @dma_owner_token: Token to identify the DMA owner of this device > + * @iommu_phys: Physical address of the serialized IOMMU the device is behind > + * @attachment: Attachment of the device to its domain > + * @reserved: Reserved for future common fields. > + */ > +struct iommu_device_ser { > + struct iommu_hdr_ser hdr; > + u32 devid; > + u32 pci_domain_nr; > + u64 dma_owner_token; > + u64 iommu_phys; > + struct iommu_attachment_ser attachment; > + u64 reserved[2]; > +} __packed; > + > +/** > + * struct iommu_hw_ser - Serialized state of an IOMMU instance > + * @hdr: Common object header > + * @token: Unique token to identify the IOMMU instance > + * @type: IOMMU type serialized state belongs to > + * @reserved: Reserved for future common fields. > + */ > +struct iommu_hw_ser { > + struct iommu_hdr_ser hdr; > + u64 token; > + u64 type; > + u64 reserved[2]; > +} __packed; > + > +/** > + * struct iommu_flb_ser - Top-level serialization structure > + * @version: Version of the serialized data, IOMMU_LUO_FLB_VERSION > + * @iommu_block_phys: Physical address of the first KHO block of IOMMU HWs, or > + * 0 if none > + * @domain_block_phys: Physical address of the first KHO block of domains, or > + * 0 if none > + * @device_block_phys: Physical address of the first KHO block of devices, or 0 > + * if none > + */ > +struct iommu_flb_ser { > + u64 version; > + u64 iommu_block_phys; > + u64 domain_block_phys; > + u64 device_block_phys; > +} __packed; > + > +#endif /* _LINUX_KHO_ABI_IOMMU_H */ > -- Apart from those nits: Reviewed-by: Pranjal Shrivastava Thanks, Praan [1] https://lore.kernel.org/all/20261110050202.529473-1-tarunsahu@google.com/