From patchwork Wed Dec 4 12:29: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: 13893671 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 AB8571ADFFB for ; Wed, 4 Dec 2024 12:29:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315374; cv=none; b=IwZ6Uqm6OnVblhWLl52AX8roU7ow+isoPkJMZU/IzczC3cuh4LuJBd+h66tUefmjpaELvCuvY9lL5xIePybxAS2LYP+PQFwquXTV0idI3Z7P8r17LhlKuY6CHRdr0aIYDfzisWkKnrM8BHsyWSFL9+leeAOq9O3SCE2cB++pt7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315374; c=relaxed/simple; bh=6PUXI+3NsTHsfAL2o1cIt8/S23ikcs+UsrxO1KYisNQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MQEuynGlaxmB+U0xMdJIYVpDESFaQH7RM1IG0LNy5OwbdguTlBpgTA9X3scW1GpVz7Mln4QJ3JSxx9oD8xiQFlD9lr/ZjIrihhmRyFJA+t+RnsHwpIxw5cGWEsrw5ps9IbUv2L8b1gxLliRX257XJCJYGvZp+Q6OlrQuej2CEpk= 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=Z84rW8VG; arc=none smtp.client-ip=192.198.163.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="Z84rW8VG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733315373; x=1764851373; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6PUXI+3NsTHsfAL2o1cIt8/S23ikcs+UsrxO1KYisNQ=; b=Z84rW8VG4IWESRyMJ5vB3swSAaoRtuaOOx1ZmFBgs5S/3NnbMm/s+kT4 dIpM5OVnVwc5U6WxO910vFIJ0e4XR3Y+pdwQ0jvMhWpp7RG4kaMzVDTAV 9L4GoclUwcqZdNCcD/v3f+C6HQGdNBQkNkMGeqwbimWXfpPzDgugW26Px zlunQ+twm5IGp1KTS/8LiqXmobk0Gw1JE8NbHm0ONF4BLNOwrkyULd9rV 1HMf5kJKLU8XdD7YoXyoxCOpr65moE8LjC5X253Qx1d2Ae6Cj19rne8En 7WcprltBf5MO6C1QX/yrecjhZKtJadVYvnOym3bzSb1AGgcZJqv6wgCP1 w==; X-CSE-ConnectionGUID: l3uNs14nT5mo8fVQsgwLCQ== X-CSE-MsgGUID: Ahok8FWOT0SZL/lHTBoabQ== X-IronPort-AV: E=McAfee;i="6700,10204,11276"; a="32937877" X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="32937877" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2024 04:29:32 -0800 X-CSE-ConnectionGUID: DyUOY3OOQ/GzbGdPILecOA== X-CSE-MsgGUID: sM8NdmSDSQuavqRraIpWFQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="93599065" Received: from unknown (HELO 984fee00a4c6.jf.intel.com) ([10.165.58.231]) by orviesa010.jf.intel.com with ESMTP; 04 Dec 2024 04:29:31 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: 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, will@kernel.org Subject: [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Date: Wed, 4 Dec 2024 04:29:22 -0800 Message-Id: <20241204122928.11987-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241204122928.11987-1-yi.l.liu@intel.com> References: <20241204122928.11987-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. Move the group check to be the first as dev_iommu_ops() may fail when there is no valid group. Also take the chance to remove the dev_has_iommu() check as it is duplicated to the group check. Reviewed-by: Jason Gunthorpe Signed-off-by: Yi Liu Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/iommu.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 9bc0c74cca3c..38c3f67e441f 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3368,16 +3368,19 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, /* Caller must be a probed driver on dev */ struct iommu_group *group = dev->iommu_group; struct group_device *device; + const struct iommu_ops *ops; int ret; - if (!domain->ops->set_dev_pasid) - return -EOPNOTSUPP; - if (!group) return -ENODEV; - if (!dev_has_iommu(dev) || dev_iommu_ops(dev) != domain->owner || - pasid == IOMMU_NO_PASID) + ops = dev_iommu_ops(dev); + + if (!domain->ops->set_dev_pasid || + !ops->remove_dev_pasid) + return -EOPNOTSUPP; + + if (ops != domain->owner || pasid == IOMMU_NO_PASID) return -EINVAL; mutex_lock(&group->mutex); From patchwork Wed Dec 4 12:29: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: 13893672 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 2D1211B6CFF for ; Wed, 4 Dec 2024 12:29:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315374; cv=none; b=GsEHZx+goa7gT8RnIlrtW4IReU+muWIbScwXnPhT5xLYsxmWeoXgY/uabCXJ3acpQZau8uNguIz0iTpDQ+4GjwQNtCEMPBHZbAM1pfyEcJRrl1yZ4VVkVF+PDoV3JYNa9ACw3xLWC0In8eUXvYnjg+QeYNhswbOuGtzm+i2/ctE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315374; c=relaxed/simple; bh=YOo7EVh87rnwHYdcmhCtZ2+qKHDekfy1krTEhcj6ymo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VNzvuVSqQPE+Oy7SKNjRSCHuKsmJrEHUXiEKLcb961YtuvVk4jnOEpG3fr9v52iG8ADPoCS7mUVi+egLgmdXXuycwVVMFSEMW0/n2znABQiFNa7wdBKY/OOUUOwk/5ipfqSIP6e3RsIFrZ5Af/oz85NMnqXQlIp5VFrIlzl3URk= 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=LmH0x65s; arc=none smtp.client-ip=192.198.163.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="LmH0x65s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733315373; x=1764851373; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YOo7EVh87rnwHYdcmhCtZ2+qKHDekfy1krTEhcj6ymo=; b=LmH0x65sfJBNaza2sKCgvIvNtENQZlTspgPyoNEsOeCn7YkxbhDOR+kd F3El9a+FWXES0GmVKRN+BwWn4i+1G8n7+i1fq6CC65Khpc3pLnoSeSXXh beEt3n6Y7mEpycgu5e//Xfe7TpqIzCQcXmB0p/aPL30Ofmx2Qmlp1bREF ViQBeHyuy1h6Jz6v81yspZnczasJoJxrA04kY9wxCNuQZdKh00EdVtQ8m dVO1eaV/M+UfqC/iRkXuD7gfC3nfwYHi4Q0OlWuCVnwk8Hx6LZNr5V5zt CxmM/SedYSHff5/SDeClIZfC0VUYWQpvJwX2MfxArW8wlZWWHz1XEJ3gh g==; X-CSE-ConnectionGUID: eA0cYNgRQZmDTGB/2aveYA== X-CSE-MsgGUID: bFsYB8ghREqAQ5TjMYX0Dg== X-IronPort-AV: E=McAfee;i="6700,10204,11276"; a="32937886" X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="32937886" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2024 04:29:32 -0800 X-CSE-ConnectionGUID: 6rvywbw8QpKNNUz2UuyNig== X-CSE-MsgGUID: JvbBeR9USxGvupboqeabxQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="93599069" Received: from unknown (HELO 984fee00a4c6.jf.intel.com) ([10.165.58.231]) by orviesa010.jf.intel.com with ESMTP; 04 Dec 2024 04:29:32 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: 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, will@kernel.org Subject: [PATCH v6 2/7] iommu: Consolidate the ops->remove_dev_pasid usage into a helper Date: Wed, 4 Dec 2024 04:29:23 -0800 Message-Id: <20241204122928.11987-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241204122928.11987-1-yi.l.liu@intel.com> References: <20241204122928.11987-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 Reviewed-by: Lu Baolu 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 38c3f67e441f..0331dc30eb64 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3312,6 +3312,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) { @@ -3330,11 +3338,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; } @@ -3344,12 +3350,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 Wed Dec 4 12:29: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: 13893673 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 D80CB1B87E5 for ; Wed, 4 Dec 2024 12:29:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315375; cv=none; b=rZKkOPLTcqisMwcQaN3iIPwa7A/vElAaCiQjwzvtQgWcLvpWIdWJfBZoP3CctKlotNPDdhW22s6ol6ZoezU8rqniGZk+MsuZOvLHHs2DCdODgRZdriOO7IrQTvTaTc/zE/DllI/cjACi1/iMcmx/Tcjg8FvDvdaKS12PKpf0dTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315375; c=relaxed/simple; bh=MIL5kqFgIT6RtORFgAFpmdic6w+g7VOz6BAcAW7q8lE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b6nt1lMzVlpDTrdZQPVpfGab3aUP4/hjQfoRF+kqC8gYyC65Pr50AV4y42g71mqpQI2p+/6vnItDxl9dpWErQrHs6LCX2vF5a7g54ECdGxTzvK+22D9onj5NNOjHonp+6zMjv7EfH9awKZOvwQNdGxctbS8Y4FQkzkuQ2Om57vg= 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=XS3GFoZE; arc=none smtp.client-ip=192.198.163.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="XS3GFoZE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733315374; x=1764851374; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MIL5kqFgIT6RtORFgAFpmdic6w+g7VOz6BAcAW7q8lE=; b=XS3GFoZE+cb8IROa94gp67MDTj0Oxd2tV4kBFE+4BBozO0FjDtvKAtAN LXed+plyb1FAGGQkO7Tx5bZ0ws28i350G3DU0sqDlXFC5sCQy4o6Qekhu Qn+o/u2DGNOdEyRkT/9K0xL6PUAyJu9grr67RSSO27O/avPPJQi+JG3sF Fj9RBF1lDmncv32xAP27Xxy4hYHCXXXzbhz9JTFXxEfCN/9+suCHtwECv xvQXGr46WivWPRMXUZ4l5OPsWzlrls4cz5xmD6RnVLx8X6R9JkRXg/oxl a6RVfl0v/503kVk3ORuZS00L8GgMdrYOQNdSSVkQ1TcV12Mo/lMZivfJ4 g==; X-CSE-ConnectionGUID: gLnoEdi/TRWOKEhAQQfSYw== X-CSE-MsgGUID: t3HoG2VqTl2E36zR/frN4w== X-IronPort-AV: E=McAfee;i="6700,10204,11276"; a="32937893" X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="32937893" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2024 04:29:33 -0800 X-CSE-ConnectionGUID: GnC8T37dSkag/IlByv1urw== X-CSE-MsgGUID: Lx59OPTjTg67hhWYUp/sOw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="93599072" Received: from unknown (HELO 984fee00a4c6.jf.intel.com) ([10.165.58.231]) by orviesa010.jf.intel.com with ESMTP; 04 Dec 2024 04:29:33 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: 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, will@kernel.org Subject: [PATCH v6 3/7] iommu: Detaching pasid by attaching to the blocked_domain Date: Wed, 4 Dec 2024 04:29:24 -0800 Message-Id: <20241204122928.11987-4-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241204122928.11987-1-yi.l.liu@intel.com> References: <20241204122928.11987-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 Reviewed-by: Lu Baolu 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 0331dc30eb64..149ae5300cc4 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3316,8 +3316,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, @@ -3380,7 +3390,9 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, ops = dev_iommu_ops(dev); 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 (ops != domain->owner || pasid == IOMMU_NO_PASID) From patchwork Wed Dec 4 12:29: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: 13893675 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 E915E1BBBD7 for ; Wed, 4 Dec 2024 12:29:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315376; cv=none; b=YVCI3wkje5uAP2mIdf+mcWMa48LeROLzCG9TTSVBf8HOWicmXLWLEhf1KxulGzW+kQRI32JLRC0ECzhcE3CJHChSquLpI6xi0c1vtxO5pMR8YJi9bjTKFD2VwOWA6bxX7CD7bgA65vVa0ahX6CZ4ZjjJwG08AxSZMTrf3jowLNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315376; c=relaxed/simple; bh=SIs5FZktMC7aBVud1qJKzHFNR+gqN79SDzKJmiPNwp8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EpwaTlA1zpcyfAGorKXeJIgy7C+TLC6RymYqDy9iwG34pK6PXAcYUMCRjAth4rXHj2WJ/qhJYR5Mn95qjfgYavNKDQKm37Or+fQ5ARHQ199bECySviPp5dFB3lvrIgk3c2ugMjn8C36NwUZDHDSSkxJqTer4FE56u+3NEUdPnQU= 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=hXTLHZex; arc=none smtp.client-ip=192.198.163.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="hXTLHZex" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733315375; x=1764851375; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SIs5FZktMC7aBVud1qJKzHFNR+gqN79SDzKJmiPNwp8=; b=hXTLHZexswPIZlFWoAt0IqYAJo/ildAyMJi+tYOP3ga4L1AcgLuzCIYi FYcVebfaktT2Y2xPkK4lFjuyU8XgpMDgiG6CQaTZVoaTy48OeEFCCMCqW RWoCKrtUiU6E4vuPgSx7/lJAiNpByvSYF6rNOpp4ICTGq5ro9jpC4byDO fzUAve1T/ch5IfGSNrpxnNiBdrdP1coTMG6qTBHIcXHFV3MDzzEGVJRUa zK85sl/s9niuUSVS5+Ru/nmk68t4zEvxmafkuw/qJ+Fug5VIVdX77s5JF nttKoBDiqYcjAa5OTJ/i2CBbIbBOBYr5VIy/3+P5k7B5yWEN/M8wnsZjE A==; X-CSE-ConnectionGUID: knMv3MEcTcq0zGuEq6vR7Q== X-CSE-MsgGUID: 0aXgvpo2TA+LB2oJ+C8E8g== X-IronPort-AV: E=McAfee;i="6700,10204,11276"; a="32937901" X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="32937901" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2024 04:29:33 -0800 X-CSE-ConnectionGUID: PWI0gzFxReC+/Eo/zYPUMA== X-CSE-MsgGUID: O7oytZ3LQjKebXY2TnFp9w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="93599076" Received: from unknown (HELO 984fee00a4c6.jf.intel.com) ([10.165.58.231]) by orviesa010.jf.intel.com with ESMTP; 04 Dec 2024 04:29:33 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: 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, will@kernel.org Subject: [PATCH v6 4/7] iommu/arm-smmu-v3: Make the blocked domain support PASID Date: Wed, 4 Dec 2024 04:29:25 -0800 Message-Id: <20241204122928.11987-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241204122928.11987-1-yi.l.liu@intel.com> References: <20241204122928.11987-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. Reviewed-by: Kevin Tian Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe 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 e4ebd9e12ad4..ff1d9bbf6d94 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3016,13 +3016,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); @@ -3043,6 +3042,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, @@ -3124,6 +3124,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 = { @@ -3551,7 +3552,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 Wed Dec 4 12:29: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: 13893674 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 6F0491B87CE for ; Wed, 4 Dec 2024 12:29:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315376; cv=none; b=eiuI430UA70Af+RXWF5WeUxw72IZYFTPQl6VRpFGyMzUeOwKRWfTbTrRJL7lt7Qw4MlrSmCD5DQhoPRvWcHW7UvqEExZLW7fBo/MFE06MEWR5NjH6WZybifGezhgOCCllP9Nua4L8Vig9E/joJNHkWYEzYvJJ43H2t7DCyzQkWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315376; c=relaxed/simple; bh=ixl4NVgGRwnFbA2YeAKjSw/niLGNUvw+ItsuN8Jk+ac=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IvDSN+N4I1nhpqUThAdzI16JwO5uO9JPcMOdfYQqDaks/xOv0aYQ8P+AwvXWWrPprajQ4whcrqPROrwpYwlXR0EElaLrUBzwe8Z5Umi+LVjnBedu88m0S07kHQ4Vavp6eiGscfUMpwmr3GKR3wtvemndBXAnbHIqzXe4sadHO1Q= 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=lfb7NS14; arc=none smtp.client-ip=192.198.163.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="lfb7NS14" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733315375; x=1764851375; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ixl4NVgGRwnFbA2YeAKjSw/niLGNUvw+ItsuN8Jk+ac=; b=lfb7NS14KUDJjz18b0sMKKW4Vzsp8DKRsEPTKai3nM5lAjcnX90yue9d yMYAXH3TPhQWtd41xwutLIEPboKjP55XcNN2L+iWK88Op85Mfcc7dDZSs f4jT9pOpQikeA22+2zz4fLfXwR/EKZ48xT6xb/SsLPTrOySbYVM+jUreC yzHEmL7oMz56P62iDlUfanhSql2PTb0goFaL/q1CiFFxlRVKYTde6aa3+ Q5Ye4XwHPpImJrcLqtOaRsnq8q5/h6VBNRqQ1SHRl3btPHQAMNxj5Rehy b6z7xEdKppWa3HYdWRvtbTnR11nbdbfSnIphyKoTrP1eZd5Dd4r+rrKpm A==; X-CSE-ConnectionGUID: pKivAuQMQrGW+WFQmXmuKA== X-CSE-MsgGUID: cisPS1PORkasOs0q2+C3OA== X-IronPort-AV: E=McAfee;i="6700,10204,11276"; a="32937908" X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="32937908" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2024 04:29:33 -0800 X-CSE-ConnectionGUID: DS6hbnLrSm6zqQU3b1fdTQ== X-CSE-MsgGUID: 6g8d+j1uRqWT8yi1LYC1Ow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="93599079" Received: from unknown (HELO 984fee00a4c6.jf.intel.com) ([10.165.58.231]) by orviesa010.jf.intel.com with ESMTP; 04 Dec 2024 04:29:33 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: 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, will@kernel.org Subject: [PATCH v6 5/7] iommu/vt-d: Make the blocked domain support PASID Date: Wed, 4 Dec 2024 04:29:26 -0800 Message-Id: <20241204122928.11987-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241204122928.11987-1-yi.l.liu@intel.com> References: <20241204122928.11987-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 Reviewed-by: Lu Baolu 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 7d0acb74d5a5..e0c835a9831f 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, } }; @@ -4097,13 +4102,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 * @@ -4476,7 +4484,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 Wed Dec 4 12:29: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: 13893676 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 B341A1B87E3 for ; Wed, 4 Dec 2024 12:29:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315378; cv=none; b=CIvubDU1cer/FLCwg5SNehBlx9dF0u7+X4wD4DUB1n8Eyzhs8JjniP6IHELsgZMTbRVycJS/S+l3HJg9kjk4Zf1WB2NuhT8qJOtc8Y8yRCtQtmgNW/dy9i3Tv5yaSzu5nP543jEd+oWlwP7oQPkzX47WVO0Gkj3tjz+Em4Auiw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315378; c=relaxed/simple; bh=VEF5JTZJ0HODvvZPNIWVl7SRFTtTIocoY5r3pvrFnt4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BXYD1MscJCYHYPMZV27BrNPdVa3a8v5WOULkci7H9rCdxM7LChJWwn1fKBKRynuNEN/io1bhtZyae2nqsQyGBYHK9M/mAQB7TTgA4vULGkQ0EGPA8o0wcxO4qsjMW49JV7oOE7HNvzmOT5AyF7RBzjnumA/abTGIWQt80kufNZQ= 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=kWuMXF5y; arc=none smtp.client-ip=192.198.163.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="kWuMXF5y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733315376; x=1764851376; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VEF5JTZJ0HODvvZPNIWVl7SRFTtTIocoY5r3pvrFnt4=; b=kWuMXF5yjKyyUjhjH8bINAfOhJNrcHr2tweWvvu6mx+aNM0lOZrxUtEJ ZCusduQwcOvMM/Ho7i2oBaXlL86awW5LqANa8ItZIkcJa5Ac8pMk2JU/a GMoHbAfC7gtgMbeeHW65PIaXD8btkbIcMW9ysiCkWoOuS36xmladhzIid r/G0mZFQ3x1aEuuKAsxPEd9tRQTkRtKg71snN7C/boAz4KaC49EejPUB7 IXL00KL6jXkCljKdTipHflzWSyLJ89gAzxvnom1AYg9F5Y8mOZujp9mDB HK6uiUJt1xy2OAPmtoCDoTNoEh1DZuqPexLApVGkGgjBwzGaQ/ovBVUIV g==; X-CSE-ConnectionGUID: LyIKszRrT8S4tkVL8HLOsg== X-CSE-MsgGUID: jYQTOmRxS92k2u/n5u2+Uw== X-IronPort-AV: E=McAfee;i="6700,10204,11276"; a="32937915" X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="32937915" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2024 04:29:34 -0800 X-CSE-ConnectionGUID: PpKwsQmmS9GInsg+umxAKA== X-CSE-MsgGUID: JNjNj00nTdeXu0dzwCLnbA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="93599088" Received: from unknown (HELO 984fee00a4c6.jf.intel.com) ([10.165.58.231]) by orviesa010.jf.intel.com with ESMTP; 04 Dec 2024 04:29:33 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: 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, will@kernel.org Subject: [PATCH v6 6/7] iommu/amd: Make the blocked domain support PASID Date: Wed, 4 Dec 2024 04:29:27 -0800 Message-Id: <20241204122928.11987-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241204122928.11987-1-yi.l.liu@intel.com> References: <20241204122928.11987-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 3f691e1fd22c..7814ec98cf0c 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2467,10 +2467,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, } }; @@ -2893,7 +2902,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 Wed Dec 4 12:29:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13893677 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 249931BF311 for ; Wed, 4 Dec 2024 12:29:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315378; cv=none; b=ZSOLNDuncNrOLVtPodtJdnWrdsTeJoHGi6R0c70mD1RS4LtlvHHKdM2In7YN8XbaKQ1fVF95L3Gud+CucLOW5X0iVPHzkP0FeQH1bPKHmG+vaNx4e65/XVxtnz2xO/XLnbkQjmTCZlY2Bdm2KNuM2gzhY44KE95tQ5G+WDzKnhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733315378; c=relaxed/simple; bh=qaXBrpGyFt9i3LniGPVfnD7c/ISqj1AsLkUlsnwfNM0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G34ANP6KgulrT7RwJzhmjIHF6oJS9bnI6Uz0vJIF4mSzk4qiE0Oy159E3DAm4UoqNXFB5MyRl1MNwpIh60cGW5t76vyhWl6hEmPkcoxq68QEE8WvbTl1pySCynbg4Q0VSoizzPaVbTwJWFmY01HvzkTWXCMRsH33EAqy54SkDtM= 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=jOmMHWaH; arc=none smtp.client-ip=192.198.163.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="jOmMHWaH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733315376; x=1764851376; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qaXBrpGyFt9i3LniGPVfnD7c/ISqj1AsLkUlsnwfNM0=; b=jOmMHWaHzYsw8GUDX0gybrPeHiq8G1tik4wEvoxJpVHufr77DEyOxhpU wkpCuFhcD7Rj5zzvTZbOSMlSn8F5Ablz8zL3H1stfgFTzptAwzk7x+8+O BJHfeiOwfKXJ8ebH6ucGNNn73LyPTA7irtyQRPshSFghV1Pc8v6VPx+Zr 2SGXV7VQRs+FxvWJMhqqjb0FZ2ak91jnqqmCPqG8cDVUE2JVIymEfrEqJ Q8nXsOyb7j+EeaG3fm2ujDT9CEs1F+h/L4XKLKeWu1j8G/y6BEYukW+Eo qBEcHcjIcOi6sb4FZ0aWL9CEV7kWAIHVRLyug4Hw1lxE/+RCHu0ogV9Wd Q==; X-CSE-ConnectionGUID: WsEBeFgXQiqWY12I+kvyHg== X-CSE-MsgGUID: G6XgZmDPQsOR4S4xOyuBBg== X-IronPort-AV: E=McAfee;i="6700,10204,11276"; a="32937924" X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="32937924" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2024 04:29:34 -0800 X-CSE-ConnectionGUID: rgp/M8gGTnS7x4VhjIBY0g== X-CSE-MsgGUID: 114BOdpTTM2lMbRF5mEGCQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,207,1728975600"; d="scan'208";a="93599091" Received: from unknown (HELO 984fee00a4c6.jf.intel.com) ([10.165.58.231]) by orviesa010.jf.intel.com with ESMTP; 04 Dec 2024 04:29:34 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: 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, will@kernel.org Subject: [PATCH v6 7/7] iommu: Remove the remove_dev_pasid op Date: Wed, 4 Dec 2024 04:29:28 -0800 Message-Id: <20241204122928.11987-8-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241204122928.11987-1-yi.l.liu@intel.com> References: <20241204122928.11987-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 Reviewed-by: Lu Baolu 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 149ae5300cc4..d328d4753eef 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3317,17 +3317,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, @@ -3390,9 +3382,8 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, ops = dev_iommu_ops(dev); 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 (ops != domain->owner || pasid == IOMMU_NO_PASID) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 318d27841130..38c65e92ecd0 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -587,9 +587,6 @@ iommu_copy_struct_from_full_user_array(void *kdst, size_t kdst_entry_size, * - 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. * @viommu_alloc: Allocate an iommufd_viommu on a physical IOMMU instance behind * the @dev, as the set of virtualization resources shared/passed * to user space IOMMU instance. And associate it with a nesting @@ -647,8 +644,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); struct iommufd_viommu *(*viommu_alloc)( struct device *dev, struct iommu_domain *parent_domain,