From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 6EDB734041F for ; Tue, 19 May 2026 13:15:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779196519; cv=none; b=Abo3im1rcFNsjl1p9Sla2WOgmf6ozXbEHjjPpl1n2d0NxbichKgUMMWuMVaNJUoHnEpGsnx2Ofxh5xgk8QFwHuQl0QCdTDziYpCG2750PHPNqL3payovZRpUQZDb78BzxqnMLK6Rq2DaUooExVMBPhsdzAORhBNhBavEUtuSYJU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779196519; c=relaxed/simple; bh=JDx2jF0ZO5E36Lw+1qDQU4xmk3oFKLnmUzLtiIUdQIE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=J7+UrxHY6djxnieRMCs8JBLbdifCSSKTnkCUwhMe38tn/HLWmydKQ2rDvoiq4G4iOCAvSCOTEUYdWblOC558X7KGwLMFXrR7KKGCoWcgpbhrbP032kQdEBL4JKFcWVTxpUG+thtndNQyS6aXsn/TpXugf1FPOlGW4dEC/U7ZfSo= 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=RDgA5FbH; arc=none smtp.client-ip=209.85.214.178 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="RDgA5FbH" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2ba3b9bcf69so885ad.0 for ; Tue, 19 May 2026 06:15:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779196518; x=1779801318; 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=1fBCxwoiS3sf2RQXUwxoqVP717F35PJZZr1FHXrdR8c=; b=RDgA5FbHSfzT26XoBO61B2jEUjzzmHh6YTh9KSgKb8MmTH5fNZ35J0iEQDpY4GH+vz Uq/NQtELN7KC0SvAcjl/oaFCjmCnPhoGujsrdko87pMtIlknbIMerfecwGrVFDsoz6LU WNv/xWvWvCZiCBJ02VIiyAB5Br3qCrm1Lv+fM9Mi/3qSTDCoOcnlkKEYDcaeTbNEB+f4 IAQFDLmkzXMao2U1s1F3k46mPyZRw8pVWXiqkzRXPuH66HzJu5Eo1wMrYfDFfLoqshz8 zclwgYG+KHO9ogdqYssFsH4boYgn3hHuTE1S/THgxjOrchZST3LvWt75WT2JXiuGgCNu Qm1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779196518; x=1779801318; 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=1fBCxwoiS3sf2RQXUwxoqVP717F35PJZZr1FHXrdR8c=; b=cprFnHqReSNx5/+1hsoj4qRPizE/Ont6zgSBxmmWvcsryi4Jfy09oyTienBQSpchre H4URKx3nqn5hMngHBQWjMlBdRyehRUVjM+t7QYJgtrMowlDcP3UkO1hC+PExdRuB4Xf8 bgfRnL4YX3AQU25KCsfPrdmKsMN4IElyK3HgDJovHQqQs+u+RuA7FNdPOVgHjFahD9Ew iatwwf8qC1AjjWlAex+FbA9x3jdWXEnXZ7qSUZ3vfpkRrGqhuZNkwSjspH+241u+DDPq dwL3IzAxDFVorZcSu8cW3ZzsRLoiCw4GjSAbweoHFrjlQ32TWcxMFm+guFp6+vk2QlJ4 oYWQ== X-Forwarded-Encrypted: i=1; AFNElJ+kU6N4LGvUx9pwn0HTw/g9uTQZYH5CjC73emuI7ewt5uEisz0Msw0S+efatRQIZBXv9+sAZ/DWudNYr9A=@vger.kernel.org X-Gm-Message-State: AOJu0YzT03ZC/l1ySoHtE6Tu8kFLhLcqGhhlZCVuwHri95/zf4xbE0ZP vbYoEX0vHpi+2SFMGqn+L0Ykhlaqi+AMCZxF6jZgcDN8DUJ6YQyoT7mE+bHFIYyKDw== X-Gm-Gg: Acq92OH440zIvhDgu1KiZc2Ndb1GnCYT/cd/Z+ZNmASlrtIFPaIudnQZwZdP6JGFPFU CidSNRN1BP9hAbtvBtDL1drVFGm44drNhxBHxYN0Bn0UZ1qr/BMm416bTOsrxN88Izu2cTv7y9v zAVjMVYpvi0911ESrangEB0iU+SiMnPLitRXBFbA1tCZvOUH0U8+IeB7iK/D9dAvU+Fuo8zbi+Q QMcCELZIBmAfGUn+QLlAfOMUXN2Q1SrucVcOfZY8xeTQs2/niGjMr9U3zARPYvZenRN8ex41b9K K/7kuud5QLTbEo6kPIOYg2E/I8kXOI4L2OMC5HPCmDILbHQI/QjCpcJxMyIVIxRWqj/3Ysz4Vyy 7FCBKL0B3Cq9knYUnDFEhZhIiSQMIbtfevDlOwLHmKvSMpSxSl9vj0uAZQfhQRGXSzA9/vR3iv/ jpIh4+6/oexDZH07gkojGIhTwfbi6xcwAqdOmFsOeSOe0dI4dBQNn8yRH0ZXQL7Xe06JXO X-Received: by 2002:a17:903:1a2d:b0:2b4:58ad:e987 with SMTP id d9443c01a7336-2bdb32c212bmr5844565ad.17.1779196516969; Tue, 19 May 2026 06:15:16 -0700 (PDT) Received: from google.com (44.234.124.34.bc.googleusercontent.com. [34.124.234.44]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f19f7ccc7sm21316591b3a.58.2026.05.19.06.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 06:15:16 -0700 (PDT) Date: Tue, 19 May 2026 13:15:08 +0000 From: Pranjal Shrivastava To: Samiullah Khawaja 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 Content-Disposition: inline In-Reply-To: <20260427175633.1978233-7-skhawaja@google.com> 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. > + /* > + * 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