From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 64C7B332916 for ; Thu, 7 May 2026 18:47:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778179634; cv=none; b=CsDIo+22V9eyJwbF6K6seQ7kNrvrszDVt2JCfcvGV2esDjy5nXfiQbpZlLHlsOPuGLyrgWO8Tlhj9+4Jiq60XnS9vWHULxyG1W8prpXl5AFnf06HRMmTGf/ps5ucw1jFbv8dSPkvUx5Ovyf9mpo6QYJUFz7wy/BYgc9EWr50pFY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778179634; c=relaxed/simple; bh=h1JkDde0JEpeHExaAaLcI/3EDWHEcgua5TaSpojYG5I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MGWykOeifmSEmpopUeZ1MUbVAXFZZgQDdJOYrrUrMJaogqUPNATeDivfEdX/wv+/EbLlkay70Vh/QQChgXuAsRlNY+4j7WkdZmWMR544zM9JGDevX3tHC9be75x/Tj9HdC1WlJ66ckIdHXxBMnsKqiUAEnibtp5kCprqPebsVgA= 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=TvN4gAr1; arc=none smtp.client-ip=209.85.214.177 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="TvN4gAr1" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2ba180a022dso17555ad.1 for ; Thu, 07 May 2026 11:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778179632; x=1778784432; 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=CukuR4C0VokxuACh8W7BiMV3ykO5i2dF/8Jc99UlNZw=; b=TvN4gAr12UOEDzR+1X/JXjdaXNGbMwc7p2aOK8dRMmVZ+EIQAD1d/H55LoTAMCSvAM av4D3P2ujK8g9MhUSqABXDbWWvDQdzltWe9fsUyCyUrYpdwpHdJ3Ztr/iVGb0ZjZlWTM T9lRhEQBkAcNIN0UbmEV2n73qI7+DAlsolqlnMfRBWJ5UAjqExugtVgCldQUV0ReGyKz QOpJM+7PVafrMBvaPmAUrvJQhOMYAHrFKoPx83uTyG44smCeeB9qwtzJjtjEspzunfV5 ZIB4uNxGHrbyYe9n+NuximOLiRGSdqQYfHIPn0mx2jnSOxsYFWtHj27eDL9waLfUOilH 4OIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778179632; x=1778784432; 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=CukuR4C0VokxuACh8W7BiMV3ykO5i2dF/8Jc99UlNZw=; b=AoTNfLKe7XC/WdICHW/zi/k7lsD8BsGJ9Zbjc2lmEaY0O7HI2YiBXPw9B/thLDwAhC DBnQxCUfIzfFELV0GbPHjmL1F5xhxzfF7+A2qaR10bPk23+TijaNmlOrubTp+lU0wqfj LVbEFPs0RJsQTDFpuizs9vz/vPI18PQvZHx4zvgd9TtT97PQa9ihtf93sXNro4OWqUHy 93SytAE+LIAR57ifRfbF8huIgU2kwZDVFHcmjzv6FxlZ4l1oWKLHsFgO//HWmGQJWOXI pLny4WiplaIR5P9p9U30enaBWbqBJ5FbabNB8/Jq9TNR3dimihuz1hUc9eoFqZKWbE3y 50tw== X-Forwarded-Encrypted: i=1; AFNElJ8rWXGzBjF0O91a4KvkEbVl2zUu8weoSFh8iaiY6kU490cwhHs3F+nbmFvSV6tY5f+my1Bupi309Nqel+8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0bTo24tXrM5JxJ+qdnjqTBlioXmLSv5oUdUJ8EYsi+vsFtvti c005rbjog/rGP7RmqbHDOdRHPE3xgIhPfLnEd6QEXbqK5GXgofMdoum92z6/RKuqjA== X-Gm-Gg: Acq92OHJlOSM/mKhk4dPmCjo4WeChNXdVJXDEhPUE9CgXgd0CL+DfWJJYUO+Ui3w/lw g2VEjMrkj4Fs+Ve8wawhdqWJFNJCkHj3dGE7S0NSEWFxD7mcbAEV0aX/m3EGEksdeEzNtjpMkbc 4pOlZRgiacrtDgGorgtUirf31yWEgHPOkRcfZi/uob0I/fWuD4uKC+GcTo1Ut5Yw86Z5ajcSDXl 1hevn2u7lPAvSMs2MBIEOsSz+pcUvf778f4sSBppUGSJL0U2xFACrOE9LjGCJkMPLn4Uh7i6qOp p1NHH/XO4HMLKqRsvagFiRo2aSqM80Ilq5cR9hi09IDFGCD0e7BNauZoJuIhFGZg+c1662CnVaq gMWw/Mv+DywUyV+IMq/LfeiLqwcFQ/7DC/EGNe/Por3Ze0QFG5kfemEni70q3fUdojLUjjIr4r7 BMTGgmnikhEwNnuANPnovL+wJICfYuRScmUw/fRkFyhVraLwTb5lgtL6iJOJgmGVwCUnecTA== X-Received: by 2002:a17:902:d50d:b0:2b2:5931:5950 with SMTP id d9443c01a7336-2bae9e68566mr558665ad.16.1778179631231; Thu, 07 May 2026 11:47:11 -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-c82640ca287sm278224a12.23.2026.05.07.11.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 11:47:10 -0700 (PDT) Date: Thu, 7 May 2026 18:47:07 +0000 From: Samiullah Khawaja To: Baolu Lu Cc: David Woodhouse , 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 , Pranjal Shrivastava , Vipin Sharma , YiFei Zhu Subject: Re: [PATCH v2 04/16] iommu: Implement device and IOMMU HW preservation Message-ID: References: <20260427175633.1978233-1-skhawaja@google.com> <20260427175633.1978233-5-skhawaja@google.com> <3874a086-98ae-4b94-8c1b-20e13f5a92fb@linux.intel.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: <3874a086-98ae-4b94-8c1b-20e13f5a92fb@linux.intel.com> On Thu, May 07, 2026 at 10:07:43AM +0800, Baolu Lu wrote: >On 4/28/26 01:56, Samiullah Khawaja wrote: >>Add IOMMU ops to preserve/unpreserve a device. These can be implemented >>by the IOMMU drivers that support preservation of devices that have >>their IOMMU domains preserved. During device preservation the state of >>the associated IOMMU is also preserved as dependency. >> >>Signed-off-by: Samiullah Khawaja >>--- >> drivers/iommu/liveupdate.c | 162 +++++++++++++++++++++++++++++++ >> include/linux/iommu-liveupdate.h | 33 +++++++ >> include/linux/iommu.h | 20 ++++ >> 3 files changed, 215 insertions(+) >> [snip] >>+ >>+int iommu_preserve_device(struct iommu_domain *domain, >>+ struct device *dev, u64 *preserved_state) >>+{ >>+ struct iommu_flb_obj *flb_obj; >>+ struct iommu_device_ser *device_ser; >>+ struct dev_iommu *iommu; >>+ struct pci_dev *pdev; >>+ int ret; >>+ >>+ if (!dev_is_pci(dev)) >>+ return -EOPNOTSUPP; >>+ >>+ if (!domain->preserved_state) >>+ return -EINVAL; >>+ >>+ if (!iommu_group_dma_owner_claimed(dev->iommu_group)) >>+ return -EINVAL; >>+ >>+ pdev = to_pci_dev(dev); >>+ iommu = dev->iommu; >>+ if (!iommu->iommu_dev->ops->preserve_device || >>+ !iommu->iommu_dev->ops->preserve) >>+ return -EOPNOTSUPP; I will check for unpreserve ops here also. >>+ >>+ ret = liveupdate_flb_get_outgoing(&iommu_flb, (void **)&flb_obj); >>+ if (ret) >>+ return ret; >>+ [snip] >>+} >>+ >>+void iommu_unpreserve_device(struct iommu_domain *domain, struct device *dev) >>+{ >>+ struct iommu_flb_obj *flb_obj; >>+ struct iommu_device_ser *iommu_device_ser; >>+ struct dev_iommu *iommu; >>+ struct pci_dev *pdev; >>+ int ret; >>+ >>+ if (!dev_is_pci(dev)) >>+ return; >>+ >>+ if (!iommu_group_dma_owner_claimed(dev->iommu_group)) >>+ return; >>+ >>+ pdev = to_pci_dev(dev); >>+ iommu = dev->iommu; >>+ if (!iommu->iommu_dev->ops->unpreserve_device || >>+ !iommu->iommu_dev->ops->unpreserve) >>+ return; > >Is it considered a driver bug if it implements the preserve hooks but >not unpreserve ones? This would at least cause a silent memory leak. How >about adding a WARN like this? I think the preservation should not be done if the unpreserve ops are not implemented by the driver. I will add these checks in the _preserve functions and return EOPNOTSUPP if it is not implemented by the driver. > > if (WARN_ON_ONCE(!iommu->iommu_dev->ops->unpreserve_device || > !iommu->iommu_dev->ops->unpreserve)) > return; We can add this warning here also. > >? > >Thanks, >baolu > Thanks, Sami