From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.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 92DB53EFFD6 for ; Tue, 19 May 2026 17:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779210907; cv=none; b=Ale5i7TB/LLlk2rRJI6X97bfCJcXa1lZldQG1i1nFXn5mpH//zpZJ7OgPv8u2JkJo28uJ7ub1Ai07dV1v+uerKsGmG+G2XfVSRENL95LWxmZ7bRWU8Cz1V+it5X0bcRS6Z5bJ0hySXLquwSTos/1GhSLHZVyS9UXhuw5mjgH74E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779210907; c=relaxed/simple; bh=N0olbpp4+tbbF00EjqkPnSM7waYwBC1YIklDoPh4SKI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UiLrTbjVAzNC3E84uJPgziq2EWe5TYsAT2aeQ7dk2MSC2mv4QU4ehNRJjmmK+gbaePp82P1/I6T+1SedsaO7cgeuHUjZipRAkU8XcyNh70I26ViFr/Mmx66X9X1604OflOX3vCvI1MGA/Aq0WNDPCRxA5WevD4Qa9vpw9JuybO0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=danw2frI; arc=none smtp.client-ip=209.85.214.171 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.b="danw2frI" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2ba3b9bcf69so455ad.0 for ; Tue, 19 May 2026 10:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779210903; x=1779815703; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=yvUscp3TmdBdYJXRIEvO1MdmjothbiB8jYKdWN5DkYE=; b=danw2frIg5E9TklgFEB/t36bxzS0UKmxVX6X0fkSA13/oJFptPYkN/N0Q7cNNYNf+q NMVFYthq3JFt83JOiayT1+3USXDyup0SjT+XPt6wDEGt0GyIHwqPAkYhR/vclZHgR7ns +5KQDsZJI7SPrhiXbYHdugJBKGtuPKJtTPN9+caoDybP1vSG0MNTdAOAzy64qoij2Xwp DWuanTi1w5KUbFhkkqvcGldTVYd1fYuJzk9jDGkPqDtL3MLj/upGFDPSKF0OG51Kyrzt SmCmfc31vAv6muCQG9YHACAWneShcLkHSqwG27gnDbd9Hlz1/OBK/cbyaJBIZnmyKa1F JCRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779210903; x=1779815703; h=in-reply-to:content-disposition: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; bh=yvUscp3TmdBdYJXRIEvO1MdmjothbiB8jYKdWN5DkYE=; b=r+J15yb1AyYaJdPgZT/ZDMjKqqI8oR5p+rYxu2DD/9e8XqlmesOyya7Nn4LN2AkXPX kJcmkvq+Z38MPIeGJwWtndobZuut4l2QZKw6yAoO1fojLyl1Oc92QY7m+/V8hR8UruI6 jJZ84C1AHYQ1ElZzLWD3o80V5AUPXfxf8T1PUMOk3mIDs9Tni78SDjQap3hPBUIcc2FG Qzq2TaFuj8Xnue+xhYX14MmtFLOcrc8qAIvgfy1VKhEcMEQUb9QwYUhA48ox7Bnp7twG 0pU/MSANV+raMo7T9PZnhgvFIspVEVjMn2W6AeTSO3K7KfOo9/QIuOcXs9jCgGVysG4/ yvTQ== X-Forwarded-Encrypted: i=1; AFNElJ/+bWS4vo0TMr5WuFz4uLv/s+r3Jxx5cmM2K9wLbjp2qcGbVE9ZjhyVPHgUsW+pmAMpH+PcjmZsseKWNzE=@vger.kernel.org X-Gm-Message-State: AOJu0Yylqs7bWG3jVkv2IWUKjbBGLVnHkepZKGKIRwYfY9uAPuYi1ca0 CXAOhkvk/XjJZ+/0Lu1QNoHS8xXb+aCD46J2Ww8LSGgbCQbLXU9RDa08fpM5qC0wNw== X-Gm-Gg: Acq92OHCBKCRaJqt/np/ejPqH4hR1T2HHByYUSJDKr9wPlwPIOMtutq5u+2KRC0n8nj HpA/RORd7ILkuiH+jT/CuxFqAuP4QhTXhmokpHTYEw1eu491wqtTDcIQcHF94ZQWHGkiaXRJNrW hv6q/GefLezxiahwNh/6dAS/jL5vVFKi//UbGexQW8KX1k4wTGTzOaqGyM5TphE3qfT5ulHUk4R iWzhCqpOaxaCz8i4HITb4rlMDcxBWJChXJJA8b8OI86W/g83kXihSUsLcRx8AYW1xlyIczW8vqN GOL2dykaVTbJDjDGTew1VQSkQXSG/W+ig5mR5YYVtPf+n5tAPhRApT9SC+/DSUflY13grd73vxz 8MUTcr9/R1SlH9zpW7hxrRqxNx22vmvWbngNj/NjBCZPpFGn2x0ioXmU3OnUHiD+U5/5lbKABZ6 iaK8JvreNj4f8TIDhYumomlA42DlaVnWOvWdJ9foC+mtUNN0eXqXfT9eHsZFtlvVCmkmTxZQ== X-Received: by 2002:a17:903:1b67:b0:2bd:3bfd:74f1 with SMTP id d9443c01a7336-2bdb03a2d5dmr6496795ad.2.1779210902187; Tue, 19 May 2026 10:15:02 -0700 (PDT) Received: from google.com (153.46.83.34.bc.googleusercontent.com. [34.83.46.153]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c82bb114c08sm18103728a12.23.2026.05.19.10.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 10:15:01 -0700 (PDT) Date: Tue, 19 May 2026 17:14:58 +0000 From: Samiullah Khawaja To: Pranjal Shrivastava Cc: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Jason Gunthorpe , Robin Murphy , Kevin Tian , Alex Williamson , Shuah Khan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Saeed Mahameed , Adithya Jayachandran , Parav Pandit , Leon Romanovsky , William Tu , Pratyush Yadav , Pasha Tatashin , David Matlack , Andrew Morton , Chris Li , Vipin Sharma , YiFei Zhu Subject: Re: [PATCH v2 06/16] iommupt: Implement preserve/unpreserve/restore callbacks Message-ID: References: <20260427175633.1978233-1-skhawaja@google.com> <20260427175633.1978233-7-skhawaja@google.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=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: On Tue, May 19, 2026 at 01:15:08PM +0000, Pranjal Shrivastava wrote: >On Mon, Apr 27, 2026 at 05:56:23PM +0000, Samiullah Khawaja wrote: >> Implement the iommu domain ops for presevation, unpresevation and >> restoration of iommu domains for liveupdate. Use the existing page >> walker to preserve the ioptdesc of the top_table and the lower tables. >> >> Preserve top_level, VASZ and FEAT Sign Extended to restore the domain in >> the next kernel. On restore the domain has only the preserved features >> enabled and all the other features are zeroed. This is ok since the >> restored domain is made immutable and can only be freed. A kunit test is >> added to verify that the IOMMU domain free can be done with trimmed >> features. >> >> Signed-off-by: Samiullah Khawaja >> --- >> drivers/iommu/generic_pt/iommu_pt.h | 131 ++++++++++++++++++++++ >> drivers/iommu/generic_pt/kunit_iommu_pt.h | 28 +++++ >> include/linux/generic_pt/iommu.h | 19 +++- >> 3 files changed, 177 insertions(+), 1 deletion(-) >> > >[...] > >> +static const struct pt_iommu_ops NS(ops_immutable); >> + >> +/** >> + * restore() - Restore page tables and other state of a domain. >> + * @domain: Domain to preserve >> + * >> + * Returns: -ERRNO on failure, 0 on success. >> + */ >> +int DOMAIN_NS(restore)(struct iommu_domain *domain, struct iommu_domain_ser *ser) >> +{ >> + struct pt_iommu *iommu_table = >> + container_of(domain, struct pt_iommu, domain); >> + struct pt_common *common = common_from_iommu(iommu_table); >> + struct pt_range range; >> + >> + common->max_vasz_lg2 = ser->vasz; >> + >> + /* Make this domain immutable.*/ >> + iommu_table->ops = &NS(ops_immutable); >> + > >Nit: Let's consider adding a comment since we just have .deinit in ops: > >/* > * Restored page tables are strictly transient and only permitted to be > * destroyed via .deinit. Because we only preserve user-assigned devices > * utilizing pass-through frameworks (VFIO / IOMMUFD), any concurrent or > * subsequent map/unmap operations on a restored domain are explicitly > * blocked at the subsystem boundary (e.g., via IOAS immutability seals). > */ > >This makes it explicitly clear that any nullptr dererfs occuring due to >immutable_ops->map_range etc. (in the future) are considered as bugs. Sounds great, will add a comment here. > >> + /* >> + * It is safe to override this here since this domain is immutable and >> + * can only be freed. >> + */ >> + common->features = 0; >> + if (ser->sign_extend) >> + common->features |= BIT(PT_FEAT_SIGN_EXTEND); >> + >> + range = pt_all_range(common); >> + iommu_restore_page(ser->top_table_phys); >> + >> + /* Free new table */ >> + iommu_free_pages(range.top_table); >> + >> + /* Set the restored top table */ >> + pt_top_set(common, phys_to_virt(ser->top_table_phys), ser->top_level); >> + >> + /* Restore all pages*/ >> + range = pt_all_range(common); >> + return pt_walk_range(&range, __restore_tables, NULL); >> +} >> +EXPORT_SYMBOL_NS_GPL(DOMAIN_NS(restore), "GENERIC_PT_IOMMU"); >> +#endif >> + >> struct pt_unmap_args { >> struct iommu_pages_list free_list; >> pt_vaddr_t unmapped; >> @@ -1138,6 +1265,10 @@ static const struct pt_iommu_ops NS(ops) = { >> .deinit = NS(deinit), >> }; >> >> +static const struct pt_iommu_ops NS(ops_immutable) = { >> + .deinit = NS(deinit), >> +}; >> + > >[...] > >Thanks, >Praan Sami