From patchwork Fri Nov 8 12:04:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13868096 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02F431E47CB for ; Fri, 8 Nov 2024 12:04:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067474; cv=none; b=H/Ln73D9bAwDSdajwGokV1Imk6M4Pb1HNcgKidmIC/NigiC2Q7XCz4S/2QhKwrMoNDUOrm/emi52495pV5+lIG5Cks9Or0dYCBVSsLdM7ixdGTNi/h401sg75hcHE+PXld9NFBCn2arr5iMdqT6OSEntG1npgWYZjfwSGoZQtmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067474; c=relaxed/simple; bh=hga76UsnkngRS0zS8f0+ZljIoWVttNerXYCKXD9K8aE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JeIV9rUsiqAyrjF7cwUd6ld0xPT5R9ZsWm9Vo/J41aCAFfewXeI6nH03NkOvjY869hnfvkuyRBlDZR27aDvdUT7574wqIsMHKbuoFVBqw30kemWYM8PNEABCDaho2uNru82rLD77wQg0vJFnRltkDeZ9KIiHrMgXc4PcE4m8WUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=E88p1+Tr; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="E88p1+Tr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731067473; x=1762603473; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hga76UsnkngRS0zS8f0+ZljIoWVttNerXYCKXD9K8aE=; b=E88p1+TrhnHxDJPTIXeu8P2j/E+2Duzsj2wfh4FKL3k7wKZCMLLWqTyM z+ldKPBGMyVhyAL/mOp5d5pk2ZuAXSgoXv1GBv8VQ2xV7YedxAs5XDj1N h6n1mtwnb2Wabwp46mHDNUTUUTSk4xObANfZgGrV8h22dVi9TbX3uzeZh 4y2agN2px2pr2vyQAsfS8DcSjSQndfJ4dsWMiLry67mYbM7bVUUsYMtip n1o5Vp+igCvbtl+q95lrh5b9xbvTVIMFZirmKA2Iy8QF+cCDxNhGw0Xd0 NhPObG4M9kdWaWDXwYtKGADemoqIqdynENozfOLUZUR1C4ItLUI9cycS0 A==; X-CSE-ConnectionGUID: nVsWI6ISTIeJ2j6DiEnN9Q== X-CSE-MsgGUID: OdO2hmtkQ8WHO4QIPSAXzg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="31116406" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="31116406" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2024 04:04:31 -0800 X-CSE-ConnectionGUID: EoOSmgAcR12+xNQz5v1n/A== X-CSE-MsgGUID: GzrpdAunSya6SwNaKweqFA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,137,1728975600"; d="scan'208";a="85679020" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa008.fm.intel.com with ESMTP; 08 Nov 2024 04:04:29 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, iommu@lists.linux.dev, zhenzhong.duan@intel.com, vasant.hegde@amd.com, willy@infradead.org Subject: [PATCH v4 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Date: Fri, 8 Nov 2024 04:04:21 -0800 Message-Id: <20241108120427.13562-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241108120427.13562-1-yi.l.liu@intel.com> References: <20241108120427.13562-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 driver should implement both set_dev_pasid and remove_dev_pasid op, otherwise it is a problem how to detach pasid. In reality, it is impossible that an iommu driver implements set_dev_pasid() but no remove_dev_pasid() op. However, it is better to check it. Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Signed-off-by: Yi Liu --- drivers/iommu/iommu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 13fcd9d8f2df..1c689e57928e 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3352,17 +3352,19 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, struct iommu_attach_handle *handle) { /* Caller must be a probed driver on dev */ + const struct iommu_ops *ops = dev_iommu_ops(dev); struct iommu_group *group = dev->iommu_group; struct group_device *device; int ret; - if (!domain->ops->set_dev_pasid) + if (!domain->ops->set_dev_pasid || + !ops->remove_dev_pasid) return -EOPNOTSUPP; if (!group) return -ENODEV; - if (!dev_has_iommu(dev) || dev_iommu_ops(dev) != domain->owner || + if (!dev_has_iommu(dev) || ops != domain->owner || pasid == IOMMU_NO_PASID) return -EINVAL; From patchwork Fri Nov 8 12:04:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13868097 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4D051E5019 for ; Fri, 8 Nov 2024 12:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067476; cv=none; b=ImMI79YXVjA6R02gC5fOtGhocMsjkTNw3ZdqHnC2cpKuU9gQv6j0N132pvn2j8qu3+g30Va8zUHFD6ouo43PWSD6IMCUOS1jY38sqDVj1Eo5ecU8SnHANvn2/OVPbJi44RogtjElcvJEQe//uEgEMHLjIl33B3KV1kToL+kC27I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067476; c=relaxed/simple; bh=h/iir5bbQI/sdAE4QJiveeaniAldZP8K2NkM9vUjrYI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WhfwcYyOwTBfM4+Xw9OzwvuapVYhNZMn1qQ0ynvBE5CxxEoGZhdYMBGv0/WtJZY1kf9dglxEbG2YX/sFOi6QPRARJ6gz9GTOOnse2XmA28ENRnMw2VJzFVYQuJJYjE55L49zaSagCfFKYx5K0C4llC5ADabeiXBGxavUSWHhszk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JsBgB7kw; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JsBgB7kw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731067474; x=1762603474; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h/iir5bbQI/sdAE4QJiveeaniAldZP8K2NkM9vUjrYI=; b=JsBgB7kw1UXW3QKFA/aNRRH62lOtFtUkSmZsy/fLPuvreqi2oASxZbGd /ZFUlm+FELh15kmetgRvKUf1XLi6D7kK3clivE+ZWRf6XhQfHLxrWq+NH +VFXru1hcPUjt88bstaw5ayBdqzU/Y8T6X2vnKEWwe3OuwwE1bZ+7/ze2 DYVD1xh/Jaeb/8jVnuOeGdLPGacdm8ghxYFhZ5lWoOuJfExHBpdwUOVyW U5wFrIBXDctSi2GXAKcbqNE9Xf0inxGLGsp/flSquIPmY+o9Y+0OKAkql 5kA4/Sh8UnLNnviLqim5P0HvUVqt51RmIZUBJqTJhFJXQafmhfsmlJQEH Q==; X-CSE-ConnectionGUID: 7elMSxrFT5WIMHt0IC6wQg== X-CSE-MsgGUID: nWVOnRNyTdKUkItTWvB+SQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="31116413" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="31116413" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2024 04:04:31 -0800 X-CSE-ConnectionGUID: OvajEX1eTXONS94RaD+Hrw== X-CSE-MsgGUID: FVcmXU9BSm6nsdqtjefGtQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,137,1728975600"; d="scan'208";a="85679024" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa008.fm.intel.com with ESMTP; 08 Nov 2024 04:04:30 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, iommu@lists.linux.dev, zhenzhong.duan@intel.com, vasant.hegde@amd.com, willy@infradead.org Subject: [PATCH v4 2/7] iommu: Consolidate the ops->remove_dev_pasid usage into a helper Date: Fri, 8 Nov 2024 04:04:22 -0800 Message-Id: <20241108120427.13562-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241108120427.13562-1-yi.l.liu@intel.com> References: <20241108120427.13562-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a wrapper for the ops->remove_dev_pasid, this consolidates the iommu_ops fetching and callback invoking. It is also a preparation for starting the transition from using remove_dev_pasid op to detach pasid to the way using blocked_domain to detach pasid. Reviewed-by: Vasant Hegde Reviewed-by: Kevin Tian Reviewed-by: Jason Gunthorpe Signed-off-by: Yi Liu --- drivers/iommu/iommu.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 1c689e57928e..819c6e0188d5 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3298,6 +3298,14 @@ bool iommu_group_dma_owner_claimed(struct iommu_group *group) } EXPORT_SYMBOL_GPL(iommu_group_dma_owner_claimed); +static void iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid, + struct iommu_domain *domain) +{ + const struct iommu_ops *ops = dev_iommu_ops(dev); + + ops->remove_dev_pasid(dev, pasid, domain); +} + static int __iommu_set_group_pasid(struct iommu_domain *domain, struct iommu_group *group, ioasid_t pasid) { @@ -3316,11 +3324,9 @@ static int __iommu_set_group_pasid(struct iommu_domain *domain, err_revert: last_gdev = device; for_each_group_device(group, device) { - const struct iommu_ops *ops = dev_iommu_ops(device->dev); - if (device == last_gdev) break; - ops->remove_dev_pasid(device->dev, pasid, domain); + iommu_remove_dev_pasid(device->dev, pasid, domain); } return ret; } @@ -3330,12 +3336,9 @@ static void __iommu_remove_group_pasid(struct iommu_group *group, struct iommu_domain *domain) { struct group_device *device; - const struct iommu_ops *ops; - for_each_group_device(group, device) { - ops = dev_iommu_ops(device->dev); - ops->remove_dev_pasid(device->dev, pasid, domain); - } + for_each_group_device(group, device) + iommu_remove_dev_pasid(device->dev, pasid, domain); } /* From patchwork Fri Nov 8 12:04:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13868098 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FD311E570A for ; Fri, 8 Nov 2024 12:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067477; cv=none; b=oKu3WhvXdcLRrYb2bYplyT32mPRlO3jm7L1DzLnK2tGHfONWwTP872QkrvJUN0i37cKF11Pzxx5KJZ82iHs2KU6eYdR401ctYmo5T4cISBdcDKK6RvQOaiXy/UFOA+o+edxfBe8O3zi94nl9DgUbo3626aUC1T/ljMD6G0Njsw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067477; c=relaxed/simple; bh=Ztqkn6YB5KTFuQ7dpEC8XYRiiVU3SJZ6g0Npm58rDr0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iWh+76v0dZ5dVlx6ZcsmQImrkOawC9u0Iyecrb8wzFEZ//fXxMFfFPn6Vd5b3zLTJgXKXX31xI+r5hYN829ATwNt81dOw3FzclW3vpd8+zriPIj45g4o7TeHBALww/9BRLbCocRuiGsKJcOahfQeF3851i8sVJgbCX5R/OT5nH4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FkYfO9Nn; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FkYfO9Nn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731067475; x=1762603475; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ztqkn6YB5KTFuQ7dpEC8XYRiiVU3SJZ6g0Npm58rDr0=; b=FkYfO9NnDvtsu7mNHd/RhdrH2nBOG3vr64AAsFCMsNEpIt0VzjO56d68 wckjTZmnQQ1iTuUqZWHTeDgZcJHtmC01UKdGJnhpIO3leRAquwK9nZnp0 7u4n6wdcjrUIvRavsjdmxadCTxvppXJmtv9EmeoHeGy5pd7I/x1JATnm9 xq2tNniUC4c7VOisCpKQo2u1jUEwxovh40NV0YQD7GKibo8/q1RM418m3 4HjwA0e/FqP1sYsmFBNR/vqnoyFciYcp0sTBBOQ3dwW0wcqH3oM9qvo81 bnzIEjAq+RPrTkkoZIIFDu0zTxl18gRJRXOxwB5yOYPFGXOTdHP0e4Gmn A==; X-CSE-ConnectionGUID: UCd46McQRTS2PfnlAyQMhQ== X-CSE-MsgGUID: sIsU9gtBRTm99dBtEzlFWw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="31116423" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="31116423" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2024 04:04:32 -0800 X-CSE-ConnectionGUID: BvjJf2gaSj6pwhLWq9KBvA== X-CSE-MsgGUID: CKvdFd2ySC21KJndqgmptw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,137,1728975600"; d="scan'208";a="85679028" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa008.fm.intel.com with ESMTP; 08 Nov 2024 04:04:30 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, iommu@lists.linux.dev, zhenzhong.duan@intel.com, vasant.hegde@amd.com, willy@infradead.org Subject: [PATCH v4 3/7] iommu: Detaching pasid by attaching to the blocked_domain Date: Fri, 8 Nov 2024 04:04:23 -0800 Message-Id: <20241108120427.13562-4-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241108120427.13562-1-yi.l.liu@intel.com> References: <20241108120427.13562-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The iommu drivers are on the way to detach pasid by attaching to the blocked domain. However, this cannot be done in one shot. During the transition, iommu core would select between the remove_dev_pasid op and the blocked domain. Suggested-by: Kevin Tian Suggested-by: Jason Gunthorpe Reviewed-by: Kevin Tian Reviewed-by: Vasant Hegde Reviewed-by: Jason Gunthorpe Signed-off-by: Yi Liu --- drivers/iommu/iommu.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 819c6e0188d5..6fd4b904f270 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3302,8 +3302,18 @@ static void iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid, struct iommu_domain *domain) { const struct iommu_ops *ops = dev_iommu_ops(dev); + struct iommu_domain *blocked_domain = ops->blocked_domain; + int ret = 1; - ops->remove_dev_pasid(dev, pasid, domain); + if (blocked_domain && blocked_domain->ops->set_dev_pasid) { + ret = blocked_domain->ops->set_dev_pasid(blocked_domain, + dev, pasid, domain); + } else { + ops->remove_dev_pasid(dev, pasid, domain); + ret = 0; + } + + WARN_ON(ret); } static int __iommu_set_group_pasid(struct iommu_domain *domain, @@ -3361,7 +3371,9 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, int ret; if (!domain->ops->set_dev_pasid || - !ops->remove_dev_pasid) + (!ops->remove_dev_pasid && + (!ops->blocked_domain || + !ops->blocked_domain->ops->set_dev_pasid))) return -EOPNOTSUPP; if (!group) From patchwork Fri Nov 8 12:04:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13868099 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E02F1E570A for ; Fri, 8 Nov 2024 12:04:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067481; cv=none; b=jZr70s9/BPudU51cDaZzNN3dS0K9sRTl1WyzOAYU4xbp+eq+UfA8cJErwFxbDsw9uQVEbN0eRdtbwvE4XRuONfOTp8LkT1/b9T4a3A9A7RWVimHMqttqH7UvJgF2djeaU1B8U5cQLOLxKCuvXuHuUhF99D7gZtvv7D40MaGcROQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067481; c=relaxed/simple; bh=CQNBEu2JwavCGSEpJSQqW92hh61UdmjmKwLxFCOoolw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pUwlB/DkVEGliHHrhI4YfepYfv+xLdwNbVV3+vqDTuw8H62cVyxkk8peALSozM1s31zxiI3Huf4wPpY5xKoAPYWLJrKNVnW4O9a45bCfLC1Ks9QLyfWQ+vqpb6twu1V8K9nmkuIibEWVlJED+lqmX6b4XbqswUSH4NU8nWPjBWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ahbpli8J; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ahbpli8J" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731067481; x=1762603481; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CQNBEu2JwavCGSEpJSQqW92hh61UdmjmKwLxFCOoolw=; b=ahbpli8JlV/+fO065eQOEXQZuShHdnRAWHoGkZOJyhQg8MlLuxtyh5la VIiYg35o/U/ovC2AK0HIQDXA/aMjGm7CwA86+tC8zk2chtzAxLb20t3A3 uy6qACHlOd3o8GG7dgSRLqETfARlleNlxGH4NVsAKg+8NIwNORDLBlYSg ZbQZmULHgaFebEAtbRmvcPR+waYyQRis1rXwqLksD8jOS6UMuBWqKSNns J6DqiUARTi7zqEGpIVPK8+XT6W6gWxNsCNvmUKsqGrglEjsNIXGgpknQ4 6QruL74cnQ9NCXeKigrBZ22OK4r9sgHjkLz8uKpdGRIRLuWg1U8q/wR1j w==; X-CSE-ConnectionGUID: 0vY0msXwQS2rrqG7O/SYhw== X-CSE-MsgGUID: l1H1UpBNT7STBY6oAz+6Cw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="31116431" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="31116431" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2024 04:04:32 -0800 X-CSE-ConnectionGUID: 8jPCKd2FSTyOYptJ5NZeMw== X-CSE-MsgGUID: 9aVtwdCUSbaefL4fgoEG3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,137,1728975600"; d="scan'208";a="85679033" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa008.fm.intel.com with ESMTP; 08 Nov 2024 04:04:31 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, iommu@lists.linux.dev, zhenzhong.duan@intel.com, vasant.hegde@amd.com, willy@infradead.org Subject: [PATCH v4 4/7] iommu/arm-smmu-v3: Make the blocked domain support PASID Date: Fri, 8 Nov 2024 04:04:24 -0800 Message-Id: <20241108120427.13562-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241108120427.13562-1-yi.l.liu@intel.com> References: <20241108120427.13562-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jason Gunthorpe The blocked domain is used to park RID to be blocking DMA state. This can be extended to PASID as well. By this, the remove_dev_pasid() op of ARM SMMUv3 can be dropped. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian Reviewed-by: Nicolin Chen Signed-off-by: Yi Liu --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 7ee3cbbe3744..276738d047e7 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2979,13 +2979,12 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, return ret; } -static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid, - struct iommu_domain *domain) +static int arm_smmu_blocking_set_dev_pasid(struct iommu_domain *new_domain, + struct device *dev, ioasid_t pasid, + struct iommu_domain *old_domain) { + struct arm_smmu_domain *smmu_domain = to_smmu_domain(old_domain); struct arm_smmu_master *master = dev_iommu_priv_get(dev); - struct arm_smmu_domain *smmu_domain; - - smmu_domain = to_smmu_domain(domain); mutex_lock(&arm_smmu_asid_lock); arm_smmu_clear_cd(master, pasid); @@ -3006,6 +3005,7 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid, sid_domain->type == IOMMU_DOMAIN_BLOCKED) sid_domain->ops->attach_dev(sid_domain, dev); } + return 0; } static void arm_smmu_attach_dev_ste(struct iommu_domain *domain, @@ -3087,6 +3087,7 @@ static int arm_smmu_attach_dev_blocked(struct iommu_domain *domain, static const struct iommu_domain_ops arm_smmu_blocked_ops = { .attach_dev = arm_smmu_attach_dev_blocked, + .set_dev_pasid = arm_smmu_blocking_set_dev_pasid, }; static struct iommu_domain arm_smmu_blocked_domain = { @@ -3514,7 +3515,6 @@ static struct iommu_ops arm_smmu_ops = { .device_group = arm_smmu_device_group, .of_xlate = arm_smmu_of_xlate, .get_resv_regions = arm_smmu_get_resv_regions, - .remove_dev_pasid = arm_smmu_remove_dev_pasid, .dev_enable_feat = arm_smmu_dev_enable_feature, .dev_disable_feat = arm_smmu_dev_disable_feature, .page_response = arm_smmu_page_response, From patchwork Fri Nov 8 12:04:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13868101 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BA651E7C2F for ; Fri, 8 Nov 2024 12:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067484; cv=none; b=qnNHYh0BYRCkcUljwxZ6eqgsn1a4vGlVwVWHr3JVd2AqMqTfqjbqUKU/etBWeU0BPXcKh+pK+ouvU+qP5a6F2mk9gt4qgeF1jm5FSzfVLg4cL6jRh55sZKxWvvNsP6GjaEc+ryq/rVJ9/KPZ7hOaorm2IjNNv/dT8Q9l9DY+eww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067484; c=relaxed/simple; bh=V4RugJTuvyGaHxwOKya60LQUcMi6hhRYO69X0PS1uPo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Le2gMecXsSL5TUMvhjQ9Usd11I2rYSwzl8JTJ1pqgol/4opSlSgqtTuG5H0xnBiwqhuiDmcnd8mBmoJplz0EUNvmwqRj8ne8wdZdiRiSLbD2lyFT4wgnXRQE9Nf3x96mvSzEN/iASXSVjNnC+e2KEKQWYOptjVmUcQM94uCWXOU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=g9zzKq0q; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="g9zzKq0q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731067483; x=1762603483; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V4RugJTuvyGaHxwOKya60LQUcMi6hhRYO69X0PS1uPo=; b=g9zzKq0qOLqjxcuiPjFlhDHBlYIkj2GmwxCbScUYbUbGSrN5ljgN4Xuw +jz5qf/EYx3+sbW/fxULFpCFkdctwRy+H1INKXC8pMnDQASxixYshPQnj anIWe2t5c8KrTWSjSg6/dNvg6AjRypWD7IskHuWqowh9YL5DDC1WWZWS6 boGsZjokhBJsJT42oD41/6A3MMkAZ/7K/mK5ILkpowHlBFJGejnDeQKVJ /qyaWnWWohgI/orL4e4L/0MN3zVaYcgn/Frrkv+sfs39hrjisH5Qo6Ryy pRTSAAl4qDGI0X+0y3ZqROxI2KZ3SNOBuV5RWE0jRsgjQM0332TQxvnDn A==; X-CSE-ConnectionGUID: plwahaB/QdGlOTLSQjhwJw== X-CSE-MsgGUID: CTQas5CVSoqGDWBzIrHY0w== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="31116441" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="31116441" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2024 04:04:33 -0800 X-CSE-ConnectionGUID: vl5OxtZAQguZD0FznzMI6Q== X-CSE-MsgGUID: hrEr16b5Q4+Cx7B3TlXy+g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,137,1728975600"; d="scan'208";a="85679042" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa008.fm.intel.com with ESMTP; 08 Nov 2024 04:04:32 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, iommu@lists.linux.dev, zhenzhong.duan@intel.com, vasant.hegde@amd.com, willy@infradead.org Subject: [PATCH v4 5/7] iommu/vt-d: Make the blocked domain support PASID Date: Fri, 8 Nov 2024 04:04:25 -0800 Message-Id: <20241108120427.13562-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241108120427.13562-1-yi.l.liu@intel.com> References: <20241108120427.13562-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The blocked domain can be extended to park PASID of a device to be the DMA blocking state. By this the remove_dev_pasid() op is dropped. Reviewed-by: Kevin Tian Reviewed-by: Jason Gunthorpe Signed-off-by: Yi Liu --- drivers/iommu/intel/iommu.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 527f6f89d8a1..b08981bbd5ca 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3248,10 +3248,15 @@ static int blocking_domain_attach_dev(struct iommu_domain *domain, return 0; } +static int blocking_domain_set_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid, + struct iommu_domain *old); + static struct iommu_domain blocking_domain = { .type = IOMMU_DOMAIN_BLOCKED, .ops = &(const struct iommu_domain_ops) { .attach_dev = blocking_domain_attach_dev, + .set_dev_pasid = blocking_domain_set_dev_pasid, } }; @@ -4105,13 +4110,16 @@ void domain_remove_dev_pasid(struct iommu_domain *domain, kfree(dev_pasid); } -static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid, - struct iommu_domain *domain) +static int blocking_domain_set_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid, + struct iommu_domain *old) { struct device_domain_info *info = dev_iommu_priv_get(dev); intel_pasid_tear_down_entry(info->iommu, dev, pasid, false); - domain_remove_dev_pasid(domain, dev, pasid); + domain_remove_dev_pasid(old, dev, pasid); + + return 0; } struct dev_pasid_info * @@ -4483,7 +4491,6 @@ const struct iommu_ops intel_iommu_ops = { .dev_disable_feat = intel_iommu_dev_disable_feat, .is_attach_deferred = intel_iommu_is_attach_deferred, .def_domain_type = device_def_domain_type, - .remove_dev_pasid = intel_iommu_remove_dev_pasid, .pgsize_bitmap = SZ_4K, .page_response = intel_iommu_page_response, .default_domain_ops = &(const struct iommu_domain_ops) { From patchwork Fri Nov 8 12:04:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13868100 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30FE01E7C1B for ; Fri, 8 Nov 2024 12:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067483; cv=none; b=JvJvH/+MVuOcdVex81ukafEKGPZL+wXGM5MzBmN7UiNC6ZtUUvEeBsO4g98pel2xi0Oi7c27EkxA20+cRwHCWcqqdAkxj7DKPGunHY0aDwoTnF2f2+jRh6vTl4rQY68OKolKx/w+6/cmIykPt0Z0V9bagsWL92AP4dlS5zF7cmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067483; c=relaxed/simple; bh=Mejinn7dwxrWFJJxi0gYE+6CIjdQ4PZ7QCUJBDIlsZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qjEDkp0lGyao18nH6Nk/4IqvUZC5yukxYABpo9+DGgfXJJTHgpqY5eIMGY/gUxt+2/E7T9GCzsl5qEFiynpVG7n5KTL8QBCCTD3KKdS9LbbTmYI6n5BDs70w043KAG4Yqp/l0D2olfWDu13qZCXTiVWD009WJW1CFLiNYmrzaTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hHKk23/E; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hHKk23/E" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731067483; x=1762603483; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Mejinn7dwxrWFJJxi0gYE+6CIjdQ4PZ7QCUJBDIlsZY=; b=hHKk23/EoFTKOlJwqVV9XOsql7H24N0vMTJLPp3hrTad622SvQk6yJ1P /ZaRpJRG+pY2aecbqnvYrbLhBf3TmUdwsyDOuXEeAE3v4lWTLzK2JDzKX LqXooBmc4zLqdw4fg6fL5FJZLad1q0RyFhA596YStEf+Oj5gPT+TrxXBH VSpPj4Dkv7SeF/yiBW/Ccl8vAkcp6oq0LLmqExv+6UPSbnLPU3QUJHiJm 8z2kQu2PrpliYuMzF/Jq96WLVG4TGp+PIufFIeE40gUQvS3f9thhsErn0 sETP8mX1iekwXtuTpuSXC1JV2whu+nrjPGBe3sahdg0yz4TP6YPCKae7g A==; X-CSE-ConnectionGUID: U7A82M5tRL+Z7Jwb6mSNIw== X-CSE-MsgGUID: rcKuPaK7TreDGas5Vpn8ng== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="31116448" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="31116448" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2024 04:04:34 -0800 X-CSE-ConnectionGUID: HeJOK7pPTzO1DxBE0Wu1HA== X-CSE-MsgGUID: xGl0tHZJTbawrD+vXM23Bw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,137,1728975600"; d="scan'208";a="85679050" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa008.fm.intel.com with ESMTP; 08 Nov 2024 04:04:33 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, iommu@lists.linux.dev, zhenzhong.duan@intel.com, vasant.hegde@amd.com, willy@infradead.org Subject: [PATCH v4 6/7] iommu/amd: Make the blocked domain support PASID Date: Fri, 8 Nov 2024 04:04:26 -0800 Message-Id: <20241108120427.13562-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241108120427.13562-1-yi.l.liu@intel.com> References: <20241108120427.13562-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The blocked domain can be extended to park PASID of a device to be the DMA blocking state. By this the remove_dev_pasid() op is dropped. Remove PASID from old domain and device GCR3 table. No need to attach PASID to the blocked domain as clearing PASID from GCR3 table will make sure all DMAs for that PASID are blocked. Suggested-by: Jason Gunthorpe Reviewed-by: Vasant Hegde Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Signed-off-by: Yi Liu --- drivers/iommu/amd/iommu.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 5ce8e6504ba7..d216313b6d44 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2468,10 +2468,19 @@ static int blocked_domain_attach_device(struct iommu_domain *domain, return 0; } +static int blocked_domain_set_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid, + struct iommu_domain *old) +{ + amd_iommu_remove_dev_pasid(dev, pasid, old); + return 0; +} + static struct iommu_domain blocked_domain = { .type = IOMMU_DOMAIN_BLOCKED, .ops = &(const struct iommu_domain_ops) { .attach_dev = blocked_domain_attach_device, + .set_dev_pasid = blocked_domain_set_dev_pasid, } }; @@ -2894,7 +2903,6 @@ const struct iommu_ops amd_iommu_ops = { .def_domain_type = amd_iommu_def_domain_type, .dev_enable_feat = amd_iommu_dev_enable_feature, .dev_disable_feat = amd_iommu_dev_disable_feature, - .remove_dev_pasid = amd_iommu_remove_dev_pasid, .page_response = amd_iommu_page_response, .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = amd_iommu_attach_device, From patchwork Fri Nov 8 12:04:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13868102 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C75E81E2834 for ; Fri, 8 Nov 2024 12:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067484; cv=none; b=JqAtHjuhU234DON+8H6sX0v944oWjEVAehCMr65D2TTV0jF0vUWeLaAOg59eE7p52lkAP8svSeqt3v7n4pthc/tGb/SsD+3AmIJiqjhmLxigu6F+fOX5PBcKds6nu7pwZQQuDq5nfYO9bUIUGANQJnINm3623ZzDXu4c2MdRekg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731067484; c=relaxed/simple; bh=2s1wQPEzFpmggA2jawJvQiccvDr/ayphBD/48j9DeAE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IX9gjvePcUGc7zhyCT1glCNWg3rk96v7N37nGQkHXNRqSXLhWROUxMhH4A2ON9cZTB1b8OTWrC2ThnBk0cocA8fmkNpuxgd64sBBIiUCMd7ElukQSFZYH0QPyKqtWNLwZQqD4B36RcPp9mwsMMEOaIZM66VDwJB7XVMA4jxZCik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=HWdhtepZ; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HWdhtepZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731067484; x=1762603484; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2s1wQPEzFpmggA2jawJvQiccvDr/ayphBD/48j9DeAE=; b=HWdhtepZFf9CMY/6YSUc1S/JR/FoDzme9YgbmCyQfHHNmIqFrI0Z78Bv aCjoSguv0caP0LDwqUzenb9CBLdQm+I/QiKeHBRz2/3k7Ic6h7I5c+1tk 1J7m0SWt3JDZX81OSIAvE4Gz7hZnLnQVjmYKuX5CmKzYBadJpaZ0mvFkO cImcRPo9BKghT1ykMJJP2c1OUgXsxi0AchF+2e3juIDd4djAFI1z4Euk2 QeY4MqXzdsLueVomQyeVvHt177gsfh9aCdc0w6uxmQ7MrniGzJoY5ciJT 0lhnMIVD+VC0Qh2J9xHmCJey4zTDfCnup3BPnBv2DT0rxLZ4QQ7XW26pW g==; X-CSE-ConnectionGUID: r+j/jhg5Sj2Gx+4kxTzQ8w== X-CSE-MsgGUID: +xae70bfScGhelrkccjU4Q== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="31116455" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="31116455" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2024 04:04:35 -0800 X-CSE-ConnectionGUID: x/xJPLzuR/OL30nH6Ryz0g== X-CSE-MsgGUID: LFS4smFFRXO+0Ncx01WDww== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,137,1728975600"; d="scan'208";a="85679056" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa008.fm.intel.com with ESMTP; 08 Nov 2024 04:04:34 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, iommu@lists.linux.dev, zhenzhong.duan@intel.com, vasant.hegde@amd.com, willy@infradead.org Subject: [PATCH v4 7/7] iommu: Remove the remove_dev_pasid op Date: Fri, 8 Nov 2024 04:04:27 -0800 Message-Id: <20241108120427.13562-8-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241108120427.13562-1-yi.l.liu@intel.com> References: <20241108120427.13562-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The iommu drivers that supports PASID have supported attaching pasid to the blocked_domain, hence remove the remove_dev_pasid op from the iommu_ops. Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Reviewed-by: Vasant Hegde Signed-off-by: Yi Liu --- drivers/iommu/iommu.c | 17 ++++------------- include/linux/iommu.h | 5 ----- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 6fd4b904f270..e970893168d8 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3303,17 +3303,9 @@ static void iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid, { const struct iommu_ops *ops = dev_iommu_ops(dev); struct iommu_domain *blocked_domain = ops->blocked_domain; - int ret = 1; - if (blocked_domain && blocked_domain->ops->set_dev_pasid) { - ret = blocked_domain->ops->set_dev_pasid(blocked_domain, - dev, pasid, domain); - } else { - ops->remove_dev_pasid(dev, pasid, domain); - ret = 0; - } - - WARN_ON(ret); + WARN_ON(blocked_domain->ops->set_dev_pasid(blocked_domain, + dev, pasid, domain)); } static int __iommu_set_group_pasid(struct iommu_domain *domain, @@ -3371,9 +3363,8 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, int ret; if (!domain->ops->set_dev_pasid || - (!ops->remove_dev_pasid && - (!ops->blocked_domain || - !ops->blocked_domain->ops->set_dev_pasid))) + !ops->blocked_domain || + !ops->blocked_domain->ops->set_dev_pasid) return -EOPNOTSUPP; if (!group) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 0c3bfb66dc7c..1d033121bf00 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -537,9 +537,6 @@ static inline int __iommu_copy_struct_from_user_array( * - IOMMU_DOMAIN_DMA: must use a dma domain * - 0: use the default setting * @default_domain_ops: the default ops for domains - * @remove_dev_pasid: Remove any translation configurations of a specific - * pasid, so that any DMA transactions with this pasid - * will be blocked by the hardware. * @pgsize_bitmap: bitmap of all possible supported page sizes * @owner: Driver module providing these ops * @identity_domain: An always available, always attachable identity @@ -586,8 +583,6 @@ struct iommu_ops { struct iommu_page_response *msg); int (*def_domain_type)(struct device *dev); - void (*remove_dev_pasid)(struct device *dev, ioasid_t pasid, - struct iommu_domain *domain); const struct iommu_domain_ops *default_domain_ops; unsigned long pgsize_bitmap;