From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 DA0D8372B3D for ; Wed, 25 Mar 2026 20:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774471314; cv=none; b=K//o1tKgfLiR7/vwCohNJgbHiY5lpycYShoeKqHUaITayd9v/diSghwdsBIAQpuLlBNuau1HFofc1QOy02j7jp7O78sumVrricrDKhjIVU4hYhRHp+f664kOXipdNAfkkrytU9Vl9h2B5SCSmMI50OzYntiHL7nKQTxGP/eRPoI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774471314; c=relaxed/simple; bh=G1E89mLoruFGE9oPJq27RLkXxKfVa/lw4yDksVV+di0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CXm9fdQCVMksKLwJpo5aoZwvMpG1AppL4ixJSvRZlybPBG3DisXD1GK+sA/kTkm8Ad82uURG6wTVzFQKFOYczENCGkIK0ayHGqCbiVrdSNwOTGO80EvTwTFX4EvdWnvKNoigtG8ibxJFTrKmnYGYRyl+Sf51BwO+IlfoBzb5HyU= 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=gXOLxL3M; arc=none smtp.client-ip=209.85.214.182 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="gXOLxL3M" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2aeab6ff148so9305ad.1 for ; Wed, 25 Mar 2026 13:41:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774471311; x=1775076111; darn=lists.linux.dev; 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=PXwLIE/SIo2+NqmxnJ4XMLPsqC2QhJnG7KTzcOS0bpI=; b=gXOLxL3MW4LPeJfX7/tKIotAsJgIxW+6jS8TdzbWoYl9qKqXxHFOTUFknfELwW+HdZ TCCzjbvmd2IBOIzOHgrzezXT7hGgejiJkr+f5HYO4dGARC7oSbU+irj4G3/TTIffG9jq ycaXUx5VSPHysBPi3+6WumaFnsx6GoTgvnfPqVfE6r4Kt5A2yYTvDY7K7Z2lO4PrJrUu u7V2vpxyXy/ABFfKvCP933WsEaFmVCsLnGHH9UCEK9oUK3EvLww5TefQRnSS7+2agB8y v2WT/gqdHbxnX8mWQ8Cvr8cDxEm9gyEOaS3p463dYHBvWpxSavygRFY6yctKMmMOxAAO WgTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774471311; x=1775076111; 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=PXwLIE/SIo2+NqmxnJ4XMLPsqC2QhJnG7KTzcOS0bpI=; b=KjwG/yMOkFHjFWspdE/yXMntHTriD14/nAZviPdQwRQsnExP69zU/Y6ohkv76Vl3lw YtRSUzHRKZb+mhbiRiUCrWtwnnnDtJrUUZPDtosKD+rbytsQxmWE9j/KDhsX2JV8gdhm Y2ZyC1bi7toQcTsLHheD86dd/OXgmFP9LL71m1hEh68llSpiDc5log0EbsqRBMsRVaxG lDvmzWejyYLxt5BR/95Enj23KrK5rhfF8NpmsIeAHo6LIviwnpqvoZ8Nv9UMslX239s5 zkcA8e7rjY73/a3ZudcLQVV6UGPGjt7tWh8IZ2xh5+odyL+zBlsgCIG5A+/jMOS+IP+7 OeYA== X-Forwarded-Encrypted: i=1; AJvYcCXFDJGxTtSVD+XEgKucFYALk98JryZWXYG74JBrJ0H9Dpe/bwzh6iYqRd7k35p9HzpCYcIQKA==@lists.linux.dev X-Gm-Message-State: AOJu0YxPPDv0UPAUbURIJNp6LUO3jBFTrpWlzjzCmDuxdqdwgzLc1FDL PPBVqjMHtr3t7Xwi+15dwJenN0mTbgLUHpiW7yscz9VA+uc35lDD6pXRbxNu/ZxtlQ== X-Gm-Gg: ATEYQzzl2uHpD6d7Wb1Bu3AM5QY+ID3pKBwUNlhe6luWzWL7vlLJIJlgjbdRW/AGXxK a4s9WdYo0KM/juZ4jeNx3l/Irh0zsiPJ70ICOsKFhEajh42prG1Da6Bxo3SaSVOJxgsbvqFwpuf VvcI/XZlvfO22gNvRmwPyaZy5NvNnHv0vgJ8XFmSy+6H0xWhz/6ZvS7HMXo/Ly2Tiic6Pn0xe8s Yu8VBebH9nVYDgglR8fWMFR7D2acgOBuymjAO3vqVmeQdjD5/CG91JG9xSnsXoTpJ0sMZ3IVJsf vmu1+z/IqH++mSA8lMsSd4Lh0lsOUyAQO2Bd7B1GG4kaYySVBcMVAFlJV0N+1mJmObHjsVPuwao HHG+HHeAwIRZppcGRHO+axPIk58eWJUsVCdCDxluZXPEtWTK1N2pV+wWef94IGYTCiEKTkydAT7 IC838dD9gu0XGNGch9TD6cfM1VkbtOYWdQPRn//htWyJC/sHZK1pCRGQQHkpZ13g== X-Received: by 2002:a17:903:1a08:b0:2ad:6f9b:7817 with SMTP id d9443c01a7336-2b0bf9a38c0mr489605ad.22.1774471310796; Wed, 25 Mar 2026 13:41:50 -0700 (PDT) Received: from google.com (168.136.83.34.bc.googleusercontent.com. [34.83.136.168]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82c7d1e1960sm554979b3a.3.2026.03.25.13.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 13:41:50 -0700 (PDT) Date: Wed, 25 Mar 2026 20:41:46 +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 12/14] iommufd: Add APIs to preserve/unpreserve a vfio cdev Message-ID: References: <20260203220948.2176157-1-skhawaja@google.com> <20260203220948.2176157-13-skhawaja@google.com> Precedence: bulk X-Mailing-List: iommu@lists.linux.dev 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 Wed, Mar 25, 2026 at 08:24:24PM +0000, Pranjal Shrivastava wrote: >On Tue, Feb 03, 2026 at 10:09:46PM +0000, Samiullah Khawaja wrote: >> Add APIs that can be used to preserve and unpreserve a vfio cdev. Use >> the APIs exported by the IOMMU core to preserve/unpreserve device. Pass >> the LUO preservation token of the attached iommufd into IOMMU preserve >> device API. This establishes the ownership of the device with the >> preserved iommufd. >> >> Signed-off-by: Samiullah Khawaja >> --- >> drivers/iommu/iommufd/device.c | 69 ++++++++++++++++++++++++++++++++++ >> include/linux/iommufd.h | 23 ++++++++++++ >> 2 files changed, 92 insertions(+) >> >> diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c >> index 4c842368289f..30cb5218093b 100644 >> --- a/drivers/iommu/iommufd/device.c >> +++ b/drivers/iommu/iommufd/device.c >> @@ -2,6 +2,7 @@ >> /* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES >> */ >> #include >> +#include >> #include >> #include >> #include >> @@ -1661,3 +1662,71 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd) >> iommufd_put_object(ucmd->ictx, &idev->obj); >> return rc; >> } >> + >> +#ifdef CONFIG_IOMMU_LIVEUPDATE >> +int iommufd_device_preserve(struct liveupdate_session *s, >> + struct iommufd_device *idev, >> + u64 *tokenp) >> +{ >> + struct iommufd_group *igroup = idev->igroup; >> + struct iommufd_hwpt_paging *hwpt_paging; >> + struct iommufd_hw_pagetable *hwpt; >> + struct iommufd_attach *attach; >> + int ret; >> + >> + mutex_lock(&igroup->lock); >> + attach = xa_load(&igroup->pasid_attach, IOMMU_NO_PASID); > >By explicitly looking up IOMMU_NO_PASID, we skip any PASID attachments >the device might have. Since PASID live update is NOT supported in this >series, should we check if the pasid_attach xarray contains anything >other than IOMMU_NO_PASID and return -EOPNOTSUPP? > >Otherwise, we silently fail to preserve those domains without informing >the VMM? VMM should be able to preserve the NO_PASID domains even if it has PASID attachments. This is the intended behaviour, I will document it in the uAPI docs. > >> + if (!attach) { >> + ret = -ENOENT; >> + goto out; >> + } >> + >> + hwpt = attach->hwpt; >> + hwpt_paging = find_hwpt_paging(hwpt); >> + if (!hwpt_paging || !hwpt_paging->lu_preserve) { >> + ret = -EINVAL; >> + goto out; >> + } >> + >> + ret = liveupdate_get_token_outgoing(s, idev->ictx->file, tokenp); >> + if (ret) >> + goto out; >> + >> + ret = iommu_preserve_device(hwpt_paging->common.domain, >> + idev->dev, >> + *tokenp); >> +out: >> + mutex_unlock(&igroup->lock); >> + return ret; >> +} >> +EXPORT_SYMBOL_NS_GPL(iommufd_device_preserve, "IOMMUFD"); >> + >> +void iommufd_device_unpreserve(struct liveupdate_session *s, >> + struct iommufd_device *idev, >> + u64 token) >> +{ >> + struct iommufd_group *igroup = idev->igroup; >> + struct iommufd_hwpt_paging *hwpt_paging; >> + struct iommufd_hw_pagetable *hwpt; >> + struct iommufd_attach *attach; >> + >> + mutex_lock(&igroup->lock); >> + attach = xa_load(&igroup->pasid_attach, IOMMU_NO_PASID); >> + if (!attach) { >> + WARN_ON(-ENOENT); > >WARN_ON takes a condition.. if we want this to be printed always, why >not WARN_ON(1, "...") ? What's the significance of having -ENOENT as a >condition? Will update this. > >> + goto out; >> + } >> + >> + hwpt = attach->hwpt; >> + hwpt_paging = find_hwpt_paging(hwpt); >> + if (!hwpt_paging || !hwpt_paging->lu_preserve) { >> + WARN_ON(-EINVAL); > >Same here for -EINVAL? Same here. > >> + goto out; >> + } >> + >> + iommu_unpreserve_device(hwpt_paging->common.domain, idev->dev); >> +out: >> + mutex_unlock(&igroup->lock); >> +} >> +EXPORT_SYMBOL_NS_GPL(iommufd_device_unpreserve, "IOMMUFD"); >> +#endif > >[ ----- >8 ----- ] > >Thanks, >Praan Thanks, Sami