From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (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 B8B6B37B3E1 for ; Fri, 10 Apr 2026 23:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775863014; cv=none; b=m9JBotEOhWGBpgoVqC6kwg74RMp4i/6TMSHQ9hjVhYjHh0dSdBQ289gzjrYEfF5/KNdh9N4KEAh58E8glf+kfm6HKURXJSqMxhoHuQEzoCJQMOBa98clYgpivC2OwEYSrpAfRtPsaImq+YuTvqsNjIXHzzDnNQCPPeVlcrPRH14= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775863014; c=relaxed/simple; bh=uuKi1X0TZzBYQCH/+D+igtqxtVeYjyboC6Wv2+XouX4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=alrPBkYdxg1S2QwIozJuYxSxKv5GqakgmYMMD5nyk8XyNx1OlWiXIJu3ryrBoMJakJk6vSHFc13wTwfDqrYLJUMA/p6mXyFAuroFiSJJYSGGdmTo0tje/UzvlZOxi9Hbq3OofDpPeEPh6/abltwrarjQka/jKPix3EvKYCBKEtI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=cqPJLr8y; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="cqPJLr8y" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-8d4f78fc9f6so304012885a.3 for ; Fri, 10 Apr 2026 16:16:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1775863012; x=1776467812; 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=+cd4+5YI3Ts2enNXoZMTCszEKCVLBE3ELOgKW1U5A4o=; b=cqPJLr8yVXPROM6EfXG8H1Ts6hFdodrVBQYkn54U2TVYYIExlXx8H/5Zecmhkax4yg HEI9+2HH873oGZm6CK0PGWURXhZMYJCMLuZfYyxbPVH/hzyVAkftuv4OTte3skqf6NXL CZBYq7GYM6ysbexaiQ0aYGMm1ty5R42V90wBY9Ns7j0iXvxuo78h+EHn6aqThBgjn1MD 9fooam2LZMg+1DNE7doDEFS4CBLys3BO/2pQfGu3r+mI4RJ3udA433HzRE7bgGt38bMn pcd2X4p0D+UUXkvGsZuhN4PGQG3O1zjI/M14w6Yl7qRQp+/LOcBZtvSjnkB2/COpT48q zt+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775863012; x=1776467812; 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=+cd4+5YI3Ts2enNXoZMTCszEKCVLBE3ELOgKW1U5A4o=; b=I2AJZaA3pdYwfeh/Axt69Lj15vJZECA7VdkMteCvpsl/fcbMwHKK2W5sAERuoh521r lSgUcLPLvvvZczc8FhR+mcAstUHYke4SPB9seG89gJvz+6ku6zwNz7Ga2RCesBMfQxqj c4AqBlk1SyXGXw/YjEXYjulWQN5MrM0jsLgrbjZkSZi8UrEpw7OcD3AnBzzYI9cp7HjN aH5SgJaura8yw4AzTPZhGY83bj7L+g+fsMPzngeWpIg6UTCL0j80gbKys3zFRb3OcOTj zqyYP5B5KBNy3NAvlssb+ha1cbjNTFqyIfNOUZGeztba7khAUweJBGNVA7WHea8nwYeY jX2g== X-Forwarded-Encrypted: i=1; AJvYcCWGIk1myVvz7sKamqm7+01Qerc5A7kAZcHFTlscM5JrGvCfgqalrunXYiOMSWtnDwzIBgmLKq321AaazT8=@vger.kernel.org X-Gm-Message-State: AOJu0YydSzl2gA9AjDhObDK3rBu1Q2CyJBh3IVUpTK/G564IiYCcbsHP KejF4caA2JPB2/QnasqdUaNSSERv0vek5Cb70XrsumRfMeRqruZzchAxWdLyxjkkBa8= X-Gm-Gg: AeBDiesEl1LLl3USgN2gUBbV8L8UxyAwTSk7ahkljuJeyE3Kl0Ux4XJxKEOr+ItKG9P D/GE8I5HxsCHJc1LxprAhuO3P6eRSISrhQrtj/PEpsqQ125SRVa7MtvjgyOMqka6vqXpgFt+8EF qqujWeOEEI+ZXIAHxfjve8mHsP2+9+a9hISxOOLF7OWF78qbaVG0EfbZSpdppxWXPJXyFpd7CnH Hn8KuoENRdzhBnNFd1oz2iQjMW+EJBQdkTIRrwff66gGFkb9o3k/8G9sd3iczp9AdcVyYc/8JRd LrfzfOmYU0vmg/9cMbaWUurfrsbp0uXBL9qPbqKaLBB3p/uEgqBbJNTKHTgwhASH5CRpdhuzfhQ eok4jHE6pl69/Ys6mNQ7pxU2HsoDXubDICFVxvDYwG8DLBMZ2y+7ORUNEbjyHsb6o8k2aWF7k6J AUyXGLhZEgM7kMZEP0nT4HlLD4334cPK2sYOm7iC6r4x79fMAhnMh63UZIG9w8ulzDKRwEGA== X-Received: by 2002:a05:620a:1a24:b0:8cd:b626:cdf1 with SMTP id af79cd13be357-8ddcfcb2c39mr749957785a.46.1775863011618; Fri, 10 Apr 2026 16:16:51 -0700 (PDT) Received: from ziepe.ca (mctnnbsa70w-159-2-73-22.dhcp-dynamic.fibreop.nb.bellaliant.net. [159.2.73.22]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8ddb934dcd3sm342518785a.34.2026.04.10.16.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Apr 2026 16:16:50 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wBL5m-0000000Gks1-1hx8; Fri, 10 Apr 2026 20:16:50 -0300 Date: Fri, 10 Apr 2026 20:16:50 -0300 From: Jason Gunthorpe To: Samiullah Khawaja Cc: Pranjal Shrivastava , David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , 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 05/14] iommupt: Implement preserve/unpreserve/restore callbacks Message-ID: <20260410231650.GD3694781@ziepe.ca> References: <20260203220948.2176157-1-skhawaja@google.com> <20260203220948.2176157-6-skhawaja@google.com> <20260410141652.GV2551565@ziepe.ca> 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: On Fri, Apr 10, 2026 at 11:02:52PM +0000, Samiullah Khawaja wrote: > On Fri, Apr 10, 2026 at 11:16:52AM -0300, Jason Gunthorpe wrote: > > On Fri, Mar 20, 2026 at 09:57:08PM +0000, Pranjal Shrivastava wrote: > > > > +static int __restore_tables(struct pt_range *range, void *arg, > > > > + unsigned int level, struct pt_table_p *table) > > > > +{ > > > > + struct pt_state pts = pt_init(range, level, table); > > > > + int ret; > > > > + > > > > + for_each_pt_level_entry(&pts) { > > > > + if (pts.type == PT_ENTRY_TABLE) { > > > > + iommu_restore_page(virt_to_phys(pts.table_lower)); > > > > + ret = pt_descend(&pts, arg, __restore_tables); > > > > + if (ret) > > > > + return ret; > > > > > > If pt_descend() returns an error, we immediately return ret. However, we > > > have already successfully called iommu_restore_page() on pts.table_lower > > > and potentially many other tables earlier in the loop or higher up in > > > the tree.. > > > > It doesn't return an error, it just propogates errors from the > > callbacks which this one never errors. So this is just dead code. > > > > > > +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 = pt_all_range(common); > > > > + > > > > + iommu_restore_page(ser->top_table); > > > > + > > > > + /* Free new table */ > > > > + iommu_free_pages(range.top_table); > > > > + > > > > + /* Set the restored top table */ > > > > + pt_top_set(common, phys_to_virt(ser->top_table), ser->top_level); > > > > + > > > > + /* Restore all pages*/ > > > > + range = pt_all_range(common); > > > > + return pt_walk_range(&range, __restore_tables, NULL); > > > > This should probably be doing something with the FEAT flags and > > ias/oas too or do you imagine the calling driver has to deal with > > that? > > During boot the iommu_domain is recreated in driver and it sets up the > FEAT flags and ias/oas properly. Then this generic callback is used to > restore the page tables. > > Currently the FEAT flags of a domain are not explicitly preserved, I > will preserve them and error out here if there is a mismatch. Hrm, that expands the ABI a bit though If the only operation on the restored table is free then I suppose it can be simplified quite a bit, you just need the minimal things that the collect walker in free touches. Is that the intention, free only? If so then the restored iommu_domain should be some special free only domain too. Jason