From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796420803; b=Ttf+nq/5Af5xXayCX9JYKBWWALfzEw+CigeDx9sP7+YK07Rln5ldq+gtc3rB/wFlaj1v q8igKQwBKnYODb5PfvexCT0pdWq8maqfcLMBQFnD7yXDOXK9eY+Fm4+SSSr32uhtNQ+q+ skBmQxezwixpWwFy1rSvGYVK5Kf9allo017j1v9cikZGNRcYXk97KsgiUoZr8HVng3P4c B1FfcjHDrfU8WXXev6Zhtac02vE0jltiHb7Ziq4D6oLyDvL4vUno88pvqoo5CahxQ1ND4 BZeIIlFbRnVf+GyC19gsewDy6T49AS3KksCTV4zVnWABULnHQvO1XZm2f9K8aJ2jfMw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796420803; 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=0KZ019SPS0FObR0AOIOKslyywNZIQL+icnvn7cVsRH4=; b=ba3hcuFj4z5M+lQBJL7RHQ9adsSH/1pYtWj+zpOssNn1LwaQod3NkyKGkUS4eGEnHu78 6yIyNQriJ+HjUyDceIhoWAslUHR0jGxNZ6nDe5VpWmgkO3WlW7+E6xzck4GnI4Wio6fCI BqqJ2NGU+RKaU2FZ9/zFhATTYTLyTUYfoPEtT+ZlrmSO8Jur6NGrzv62InwEisU77GJIf 8DzIKBfgK1xUGRvo1hr5bKLBExftJ2oJCac8r1hUdysuKJ37N4x+3roYwPnrttzOE8Ytw pLMBDgYIYCtAir5NQD6Oas0y/7J6Zt69KuYf/rNm1M/oarqQfmRH/ZIwPw59PjgG/Xg== 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=eoW1+d42; arc=none smtp.remote-ip=209.85.214.171 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 63615606A322 for ; Fri, 4 Dec 2026 21:46:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 63615606A322 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, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=eoW1+d42 Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2f146d5607aso16345ad.0 for ; Fri, 04 Dec 2026 13:46:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796420802; x=1797025602; 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=0KZ019SPS0FObR0AOIOKslyywNZIQL+icnvn7cVsRH4=; b=eoW1+d42kamrdId8pxwep2c+uVjUKzh25RwmXnCRGs7+FUk03rmPM7WmD2vmlTD2V/ Vz4faqtCCnF0id0rJImpfl+hP4ZUlnojmiafx34AFMS3Im6Q6izsBp6pJsGAgp1Fpboo 8X9wgsv5cdbCfXHDisiTTfk9hnTxJ0kMugEvDJNea2F3x/b1/ccDT6i0LbXOrkMkVBsj Kio4WHVWqHHQ0w0lRMZ3QsonfcPXkLxQXINrEIBv6fawHl1W+U9EkEh6ONURUvOHn9D0 6xvVWHEraOIVN4luD6wfE2tqK39d61sMlXDJK4r5MAlMpFXP0rUG/zK6LRs+Al2Q52kf lHFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796420802; x=1797025602; 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=0KZ019SPS0FObR0AOIOKslyywNZIQL+icnvn7cVsRH4=; b=a0R+i5EsSG+VnxjoajEWNl5wBuLUHnzcqbgtcf16T7PH1Ryr1+9CDtaweGV4QfEDdN IslYVxYtrglJGN0VAOg5YChDJW7k9utdYe5oMUQ5xyw3iBEgrI+d0CsMC6SDQ/J2Zf9D R4hId1lIn1RxDxmG5np7zxliobxt3Kcre8p30dtTmmtbw9FOVPfwJKF3ZQeH9eoTytGz 7F0EPwzjfm04VIA+JDpTqhDuhc8Sv3cIEBWaKGPvQ92IFIuD3Tu5T7ofQiYjkzOJYpDs QURzsR3qLS2QpFoPqhxxA5GOwXc+shklhC16vE6Db2MuoM+zo09m4G4db/8bGH4x5GGN LJaA== X-Forwarded-Encrypted: i=1; AL+hErG4AAXibvqaPh+ZbAJi3AafCZjwd8RScqrlETXUH8H7cWvfRVOu7+Qa28TcIk5b9yWz9HM=@vger.kernel.org X-Gm-Message-State: AB4q+uFgC9kzsQhHYcj9IEcHvixTSLOKTxESHoiBLbNU4vnyIzzkPd3h +AI7TeOE+lLZdGKbe4kPNKJ4MvZ7tivuL4MryyUNWvcgnsWb7bXxm+H31CkJbcdS6Q== X-Gm-Gg: AZFdTZeNxkTtfaYrq74LOeYFaebfVA/W4MBArFfzzIeVDiy8U75Z7NGY+JGCwz3NIA1 YHc4JhiAzEQsskJq+J+3W09pXtfqZtOPntbUEoo3n4PmElPFr5Xl+mapOymfgkQ9I3fJp1Drrn2 Yk9TEMf2KurgU7k3zvHpsIV7yDJykVhEyxdJT64+XGtAW8ysZty9jTFBTubk/OuHKYhYt7/bHfQ J3LlH+25JUpfFz87Lm1L2rsaMSC64ijGEqcWXbDlYCCG3Z1zq/mB0kuD/fH0D5nLwQu0BFz0GdP dQRjgxlwpraw4u1j4DDrrl+hHlvSfYbsmYYI2oKrPlcedorVTM5j8HHBj5Xr9oa6AeTNWsJqWbH RpKEyvERjsijpqIzH+lrp5o6/m0rkJTlKS1DO4N9YxTxuguih1FMxUEYHwcQYL+Gws5hFu4QQJW xGEoBRsg5me9+Y+rjZrIv/Ym9Wx7ZtmNm/hxJ4FJxZ8eXIh0eJWvZyo3vHDGjHAZ5qvvAAheNSn Fhb5MUGCLg5lAstlv8a5FnRxbc23074q+pcXWhKZ2rJxRkSJDTvPZSjF0vlC2u5/cob5ZBcNZ0E mKt35RcUIf50BsHIzKJDRvdk3tk+gRbwUuR8Uu0tsggiYw+73tMGHwVcxLvcQhe7xa9Dsba3nEG 8J+sVkC5iGay5pRCEF+Ks X-Received: by 2002:a17:902:ef46:b0:2f1:b890:506e with SMTP id d9443c01a7336-2f1f4d282ccmr222345ad.21.1796420802098; Fri, 04 Dec 2026 13:46:42 -0800 (PST) Received: from google.com (25.75.145.34.bc.googleusercontent.com. [34.145.75.25]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b78f9d99sm18602395ad.16.2026.12.04.13.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 13:46:39 -0800 (PST) Date: Fri, 4 Dec 2026 21:46:35 +0000 From: Samiullah Khawaja To: Baolu Lu Cc: Joerg Roedel , Will Deacon , Jason Gunthorpe , David Woodhouse , YiFei Zhu , 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 , Pranjal Shrivastava , Vipin Sharma , Ankit Soni , Nicolin Chen , John Starks Subject: Re: [PATCH v8 16/18] iommufd: Persist iommu hardware pagetables for live update Message-ID: References: <20261123044949.3610702-1-skhawaja@google.com> <20261123044949.3610702-17-skhawaja@google.com> <13a27f99-5ac4-4e46-9d40-944800125f4f@linux.intel.com> X-Mailing-List: kvm@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; format=flowed Content-Disposition: inline In-Reply-To: <13a27f99-5ac4-4e46-9d40-944800125f4f@linux.intel.com> On Fri, Dec 04, 2026 at 09:47:52PM +0800, Baolu Lu wrote: >On 11/23/2026 12:49 PM, Samiullah Khawaja wrote: >>From: YiFei Zhu >> >>Register iommufd with the LUO framework and implement the preserve and >>unpreserve ops to save marked HWPTs. >> >>To make sure mappings do not change during preserved state, add a >>liveupdate_immutable flag to IOAS. When an HWPT is preserved, its IOAS > >The "liveupdate_immutable flag" is out of date. The code uses >iopt->num_preserved_domains instead. Please update it. I will update this in next revision. > >>is marked immutable and any map/unmap attempts will fail with -EBUSY. >>This is synchronized using the domains_rwsem to prevent races with >>concurrent mapping operations. >> >>The preserve callback iterates over the marked HWPTs, verifies that the >>backing memory pages are preserved, and calls iommu_preserve_domain() to >>preserve the associated IOMMU domain. >> >>Signed-off-by: YiFei Zhu >>Signed-off-by: Samiullah Khawaja >>--- >> MAINTAINERS | 1 + >> drivers/iommu/iommufd/io_pagetable.c | 24 ++ >> drivers/iommu/iommufd/iommufd_private.h | 16 ++ >> drivers/iommu/iommufd/liveupdate.c | 344 ++++++++++++++++++++++++ >> drivers/iommu/iommufd/main.c | 10 +- >> include/linux/kho/abi/iommufd.h | 56 ++++ >> 6 files changed, 450 insertions(+), 1 deletion(-) >> create mode 100644 include/linux/kho/abi/iommufd.h >> > >[...] > >>diff --git a/drivers/iommu/iommufd/io_pagetable.c b/drivers/iommu/iommufd/io_pagetable.c >>index 5ac736cf5bb5..01d0613ad617 100644 >>--- a/drivers/iommu/iommufd/io_pagetable.c >>+++ b/drivers/iommu/iommufd/io_pagetable.c >>@@ -30,6 +30,19 @@ struct iopt_pages_list { >> unsigned long length; >> }; >>+static inline bool iopt_liveupdate_immutable(const struct io_pagetable *iopt) >>+{ >>+ bool immutable = false; >>+ >>+ lockdep_assert_held(&iopt->domains_rwsem); >>+ >>+#ifdef CONFIG_IOMMU_LIVEUPDATE >>+ /* iopt becomes immutable once liveupdate preservation starts */ >>+ immutable = iopt->num_preserved_domains; >>+#endif >>+ return immutable; >>+} > >Nit: drop the "inline" in a .c file. Will update this. > >>+ >> struct iopt_area *iopt_area_contig_init(struct iopt_area_contig_iter *iter, >> struct io_pagetable *iopt, >> unsigned long iova, >>@@ -384,6 +397,11 @@ int iopt_map_pages(struct io_pagetable *iopt, struct list_head *pages_list, >> return rc; >> down_read(&iopt->domains_rwsem); >>+ if (iopt_liveupdate_immutable(iopt)) { >>+ rc = -EBUSY; >>+ goto out_unlock_domains; >>+ } >>+ >> rc = iopt_fill_domains_pages(pages_list); >> if (rc) >> goto out_unlock_domains; >>@@ -758,6 +776,12 @@ static int iopt_unmap_iova_range(struct io_pagetable *iopt, unsigned long start, >> again: >> down_read(&iopt->domains_rwsem); >> down_write(&iopt->iova_rwsem); >>+ >>+ if (iopt_liveupdate_immutable(iopt)) { >>+ rc = -EBUSY; >>+ goto out_unlock_iova; >>+ } >>+ >> while ((area = iopt_area_iter_first(iopt, start, last))) { >> unsigned long area_last = iopt_area_last_iova(area); >> unsigned long area_first = iopt_area_iova(area); > >[...] > >>diff --git a/drivers/iommu/iommufd/liveupdate.c b/drivers/iommu/iommufd/liveupdate.c >>index 9d73917157cd..21a6efafb960 100644 >>--- a/drivers/iommu/iommufd/liveupdate.c >>+++ b/drivers/iommu/iommufd/liveupdate.c >>@@ -9,9 +9,28 @@ >> #include >> #include >>+#include >>+#include >> #include >>+#include >>+#include >>+#include > >Nit: keep the includes sorted. Also, nothing in this file seems to use >linux/pci.h. Agreed. Will update. > >> #include "iommufd_private.h" >>+#include "io_pagetable.h" >>+ >>+static u32 iopt_inc_num_preserved_domains(struct io_pagetable *iopt) >>+{ >>+ guard(rwsem_write)(&iopt->domains_rwsem); >>+ return ++iopt->num_preserved_domains; >>+} >>+ >>+static void iopt_dec_num_preserved_domains(struct io_pagetable *iopt) >>+{ >>+ guard(rwsem_write)(&iopt->domains_rwsem); >>+ if (!WARN_ON(!iopt->num_preserved_domains)) >>+ iopt->num_preserved_domains--; >>+} >> int iommufd_hwpt_liveupdate_mark_preserve(struct iommufd_ucmd *ucmd) >> { >>@@ -40,6 +59,12 @@ int iommufd_hwpt_liveupdate_mark_preserve(struct iommufd_ucmd *ucmd) >> goto out_unlock; >> } >>+ /* The token of a preserved HWPT can't change. */ >>+ if (hwpt->liveupdate_preserved) { >>+ rc = -EBUSY; >>+ goto out_unlock; >>+ } >>+ >> xa_for_each_marked(&ictx->objects, index, obj, IOMMUFD_OBJ_LIVEUPDATE_MARK) { >> struct iommufd_hwpt_paging *hwpt_marked; >>@@ -73,3 +98,322 @@ int iommufd_hwpt_liveupdate_mark_preserve(struct iommufd_ucmd *ucmd) >> iommufd_put_object(ictx, &hwpt->common.obj); >> return rc; >> } >>+ >>+static int iopt_area_validate_file_pages(struct iopt_area *area) >>+{ >>+ unsigned long last_index = iopt_area_last_index(area); >>+ unsigned long index = iopt_area_index(area); >>+ unsigned int page_offset = area->page_offset; >>+ struct iopt_pages *pages = area->pages; >>+ unsigned long iova = iopt_area_iova(area); >>+ >>+ guard(mutex)(&pages->mutex); >>+ if (WARN_ON(!area->storage_domain)) >>+ return -EINVAL; >>+ >>+ /* >>+ * Walk the domain one page at a time instead of jumping ahead by the >>+ * folio size. When filling a domain, iommufd reuses pages that are >>+ * already pinned (by an access or another domain), so if the memfd >>+ * was punched in between, an old page from a different folio can sit >>+ * in the middle of a folio range. batch_from_domain() walks the domain >>+ * the same way. >>+ */ >>+ while (index <= last_index) { >>+ phys_addr_t phys = iommu_iova_to_phys(area->storage_domain, iova); >>+ struct folio *folio; >>+ >>+ if (!phys) >>+ return -EINVAL; >>+ >>+ folio = page_folio(pfn_to_page(PHYS_PFN(phys - page_offset))); >>+ if (folio->mapping != pages->file->f_mapping) >>+ return -EINVAL; >>+ >>+ iova += PAGE_SIZE - page_offset; >>+ page_offset = 0; >>+ index++; >>+ } >>+ >>+ return 0; >>+} >>+ >>+static int iopt_validate_preserved_memory(struct io_pagetable *iopt, >>+ struct liveupdate_session *s) >>+{ >>+ struct iopt_area *area; >>+ int ret = 0; >>+ >>+ down_read(&iopt->iova_rwsem); >>+ for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area; >>+ area = iopt_area_iter_next(area, 0, ULONG_MAX)) { >>+ struct iopt_pages *pages = area->pages; >>+ >>+ if (!pages) >>+ continue; >>+ >>+ /* Only allow file based mapping */ >>+ if (pages->type != IOPT_ADDRESS_FILE) { >>+ ret = -EINVAL; >>+ break; >>+ } >>+ >>+ /* Make sure that the file was preserved. */ >>+ ret = liveupdate_get_token_outgoing(s, pages->file, NULL); >>+ if (ret) >>+ break; >>+ >>+ /* >>+ * Make sure the mapped pages are still associated with the >>+ * preserved memfd. >>+ */ >>+ ret = iopt_area_validate_file_pages(area); >>+ if (ret) >>+ break; >>+ } >>+ up_read(&iopt->iova_rwsem); >>+ >>+ return ret; >>+} >>+ >>+static int iommufd_preserve_hwpt(struct iommufd_hwpt_paging *hwpt, >>+ struct iommufd_hwpt_ser *hwpt_ser, >>+ struct liveupdate_session *session) >>+{ >>+ struct iommu_domain_ser *domain_ser; >>+ int rc; >>+ >>+ /* >>+ * Make IOAS immutable so the DMA mappings do not change while >>+ * the HWPT is preserved. Since one IOAS can have multiple >>+ * HWPTs, if an error occurs this call needs to make the IOAS >>+ * mutable again if it was the one that made it immutable. >>+ */ >>+ if (iopt_inc_num_preserved_domains(&hwpt->ioas->iopt) == 1) { >>+ rc = iopt_validate_preserved_memory(&hwpt->ioas->iopt, session); >>+ if (rc) >>+ goto err; >>+ } >>+ >>+ hwpt_ser->size = sizeof(*hwpt_ser); >>+ hwpt_ser->token = hwpt->liveupdate_token; >>+ >>+ rc = iommu_preserve_domain(hwpt->common.domain, &domain_ser); >>+ if (rc < 0) >>+ goto err; >>+ >>+ hwpt_ser->domain_ser_phys = virt_to_phys(domain_ser); >>+ return 0; >>+ >>+err: >>+ iopt_dec_num_preserved_domains(&hwpt->ioas->iopt); >>+ return rc; >>+} >>+ >>+static void _iommufd_unpreserve(struct iommufd_ctx *ictx, >>+ struct iommufd_ser *ser) >>+{ >>+ struct iommufd_hwpt_paging *hwpt; >>+ struct iommufd_object *obj; >>+ unsigned long index; >>+ >>+ xa_lock(&ictx->objects); >>+ xa_for_each_marked(&ictx->objects, index, obj, IOMMUFD_OBJ_LIVEUPDATE_MARK) { >>+ if (obj->type != IOMMUFD_OBJ_HWPT_PAGING) >>+ continue; >>+ >>+ hwpt = to_hwpt_paging(container_of(obj, struct iommufd_hw_pagetable, obj)); >>+ if (!hwpt->liveupdate_preserved) >>+ continue; >>+ >>+ xa_unlock(&ictx->objects); >>+ >>+ iommu_unpreserve_domain(hwpt->common.domain); >>+ iopt_dec_num_preserved_domains(&hwpt->ioas->iopt); >>+ >>+ hwpt->liveupdate_preserved = false; >>+ iommufd_put_object(ictx, obj); >>+ >>+ xa_lock(&ictx->objects); >>+ } >>+ xa_unlock(&ictx->objects); >>+ >>+ kho_unpreserve_free(ser); >>+} >>+ >>+static int iommufd_liveupdate_preserve(struct liveupdate_file_op_args *args) >>+{ >>+ struct iommufd_ctx *ictx; >>+ struct iommufd_hwpt_paging *hwpt; >>+ struct iommufd_ser *iommufd_ser; >>+ struct iommufd_object *obj; >>+ unsigned int num_hwpts; >>+ unsigned long index; >>+ unsigned int i; >>+ void *mem; >>+ int rc; >>+ >>+ ictx = iommufd_ctx_from_file(args->file); >>+ if (IS_ERR(ictx)) >>+ return PTR_ERR(ictx); >>+ >>+ mutex_lock(&ictx->liveupdate_mutex); >>+ >>+ /* Count the number of HWPTs to preserve */ >>+ num_hwpts = 0; >>+ xa_lock(&ictx->objects); >>+ xa_for_each_marked(&ictx->objects, index, obj, IOMMUFD_OBJ_LIVEUPDATE_MARK) { >>+ if (obj->type != IOMMUFD_OBJ_HWPT_PAGING) >>+ continue; >>+ >>+ hwpt = to_hwpt_paging(container_of(obj, struct iommufd_hw_pagetable, obj)); >>+ if (!hwpt->common.domain) { >>+ rc = -EINVAL; >>+ xa_unlock(&ictx->objects); >>+ goto out_unlock; >>+ } >>+ num_hwpts++; >>+ } >>+ xa_unlock(&ictx->objects); >>+ >>+ mem = kho_alloc_preserve(struct_size(iommufd_ser, >>+ hwpt_array, num_hwpts)); >>+ if (IS_ERR(mem)) { >>+ rc = PTR_ERR(mem); >>+ goto out_unlock; >>+ } >>+ >>+ iommufd_ser = mem; >>+ iommufd_ser->size = sizeof(*iommufd_ser); >>+ >>+ /* Preserve HWPTs */ >>+ i = 0; >>+ xa_lock(&ictx->objects); >>+ xa_for_each_marked(&ictx->objects, index, obj, IOMMUFD_OBJ_LIVEUPDATE_MARK) { >>+ if (obj->type != IOMMUFD_OBJ_HWPT_PAGING) >>+ continue; >>+ >>+ if (!iommufd_lock_obj(obj)) { >>+ rc = -ENOENT; >>+ xa_unlock(&ictx->objects); >>+ goto out_unpreserve; >>+ } > >iommufd_lock_obj() increments both users and wait_cnt, and this >reference is held until unpreserve. Is the intent to keep the >hwpt_paging object from being destroyed for as long as it stays >preserved? If so, this conflicts with the comment in >iommufd_object_remove(): > > /* > * The purpose of the wait_cnt is to ensure deterministic >destruction > * of objects used by external drivers and destroyed by this >function. > * Incrementing this wait_cnt should either be short lived, such as > * during ioctl execution, or be revoked and blocked during > * pre_destroy(), such as vdev holding the idev's refcount. > */ > if (flags & REMOVE_WAIT) { > ret = iommufd_object_dec_wait(ictx, to_destroy); > if (ret) { > /* > * We have a bug. Put back the callers >reference and > * defer cleaning this object until close. > */ > refcount_dec(&to_destroy->users); > return ret; > } > zerod_wait_cnt = true; > } > >Would holding a users reference alone be sufficient? Otherwise, need an >update on the wait_cnt comment to describe this new usage. Yes the hwpt_paging object needs to be kept alive until it stays preserved. I will update this to inc/dec users directly instead of using lock_obj() and put_object(). > >>+ >>+ /* >>+ * HWPT is locked so it will not be destroyed. The xarray lock >>+ * can be released here before preserving the HWPT. >>+ */ >>+ xa_unlock(&ictx->objects); >>+ hwpt = to_hwpt_paging(container_of(obj, struct iommufd_hw_pagetable, obj)); >>+ rc = iommufd_preserve_hwpt(hwpt, &iommufd_ser->hwpt_array[i++], args->session); >>+ if (rc) { >>+ iommufd_put_object(ictx, obj); >>+ goto out_unpreserve; >>+ } >>+ >>+ /* >>+ * Mark the HWPT as successfully preserved. This is distinct >>+ * from IOMMUFD_OBJ_LIVEUPDATE_MARK, which only indicates the >>+ * userspace intent to preserve. >>+ */ >>+ hwpt->liveupdate_preserved = true; >>+ xa_lock(&ictx->objects); >>+ } >>+ xa_unlock(&ictx->objects); >>+ >>+ /* Store the actual number of HWPTs that are preserved */ >>+ iommufd_ser->num_hwpts = i; >>+ >>+ args->serialized_data = virt_to_phys(iommufd_ser); >>+ mutex_unlock(&ictx->liveupdate_mutex); >>+ iommufd_ctx_put(ictx); >>+ return 0; >>+ >>+out_unpreserve: >>+ _iommufd_unpreserve(ictx, iommufd_ser); >>+out_unlock: >>+ mutex_unlock(&ictx->liveupdate_mutex); >>+ iommufd_ctx_put(ictx); >>+ return rc; >>+} >>+ >>+static void iommufd_liveupdate_unpreserve(struct liveupdate_file_op_args *args) >>+{ >>+ struct iommufd_ctx *ictx; >>+ >>+ ictx = iommufd_ctx_from_file(args->file); >>+ if (WARN_ON(IS_ERR(ictx))) >>+ return; >>+ >>+ mutex_lock(&ictx->liveupdate_mutex); >>+ _iommufd_unpreserve(ictx, phys_to_virt(args->serialized_data)); >>+ mutex_unlock(&ictx->liveupdate_mutex); >>+ >>+ iommufd_ctx_put(ictx); >>+} >>+ > [snip] >Thanks, >baolu Thanks, Sami