From patchwork Mon Nov 4 13:20: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: 13861381 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 8023A33FE for ; Mon, 4 Nov 2024 13:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726439; cv=none; b=JzfRQsll+Sru2teQxqCSOc5xcezAYE/wLFgFl1FEFpCFmO960Pgnb9V10Y2SzBvAMBa1jJYOlWKqtmb6BVSWCbVVTz1IvD4TPte6L9+5xhlhAVoEtjb7giyUiC4c++m4UCS3wzvz9ZlmBWF0zs5P4wB4Nk+RFbiVNO5+uzGPaMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726439; c=relaxed/simple; bh=xkEJ7LX4Du0vjHFbotmFTpDVY1H3dZx3uqknKCSEr3g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S7RgTxvQjT9U26bPlzby0u/sLW94A8LjZ6NMvrgTkYWsAiMBBU6GyCQ+PEXYQnjdswMn7J8OciKQuKhU66pjKJIMKQyGI1OxPzUqzLB5xHOPWfDtwPBIWg4AME8ZyKV+zp/aydhXmkvW6/c+f+Qh/9KyHo8z/gSqzonETUBlGv4= 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=FM1HbV1B; arc=none smtp.client-ip=198.175.65.10 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="FM1HbV1B" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730726438; x=1762262438; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xkEJ7LX4Du0vjHFbotmFTpDVY1H3dZx3uqknKCSEr3g=; b=FM1HbV1BFT2OSHTq76sj22sCzdkQhk5Rxf3he62mjSpje8mVk1z4nIQ6 rZ49vlEQc2ibPTosEAhX6agrCmZX0jFisVmHcaxMxssBgdAHuIUTPnhoP m5PcQuFLJ50RLomnCjNstPB4McvkJ4oywkli6PcwaRIkv1glPyjrE19p1 yzztOZRfV/i830p0dJ8ZnExk+w5K8joyI4cNL5jSMdTS3pPNfpRGAhl1u Vv/vir+ha1idXbmHKjnbmcyedMV3OpEK17DfL7YhGxcs9/7njmoi+Bbln KneU+5RaTqrsBw/uWwXxMBUsoCdGOza1+zhrsX9DEMWnYafkObJ6qw86n Q==; X-CSE-ConnectionGUID: mmIYP6hzTYW77JkY+1Y2Cg== X-CSE-MsgGUID: yTRW7ADfTeeZToork9LoqQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="47883260" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="47883260" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 05:20:37 -0800 X-CSE-ConnectionGUID: LBIDXiKSRn6eAT0gBvwFzQ== X-CSE-MsgGUID: UR61g/0kTDK9fFzJKZ6Qzw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,257,1725346800"; d="scan'208";a="84099710" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa007.jf.intel.com with ESMTP; 04 Nov 2024 05:20:36 -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, will@kernel.org Subject: [PATCH v3 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Date: Mon, 4 Nov 2024 05:20:27 -0800 Message-Id: <20241104132033.14027-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241104132033.14027-1-yi.l.liu@intel.com> References: <20241104132033.14027-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. Signed-off-by: Yi Liu Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index ea6b4a96186d..866559bbc4e4 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3454,11 +3454,13 @@ 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) From patchwork Mon Nov 4 13:20: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: 13861382 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 3900B1CD02 for ; Mon, 4 Nov 2024 13:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726440; cv=none; b=HxtU9BriVdaw+uZ0m2NGfRFRsjUTcLyogBrdJDTe2Yke3JYwTAG3XeceK5shmL2SpSTD8EyF6QS/nYRDlcrRrPJ/xRwgPWT1U3oJ4m49ngco4L2ZW0Nh7onUF7ksiKsV4lYwjy0691bZ0PhTy/NyXTUj3ixtzObWSyi6hm9heGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726440; c=relaxed/simple; bh=eEHmXayK9QK4m707aejwlJqo2aRjzbrQ+Mcejqkcg9A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rcHTnsus0H/QIHLb0tyrM8wugXZNAxXjO3nGNcBBH+xIL4Gb7aq/joRxnZyuBEMgF0BAx2BC7Z+5zfr0QWlqo2YFMm63qmlc1VGd7bBo+QcVlS9Ge5Og499SZMh8toA4hFsNljm06fJ9vTfBOuO2GfzxTaiVCimasXMzd1ND1uE= 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=mUgd4Uxg; arc=none smtp.client-ip=198.175.65.10 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="mUgd4Uxg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730726440; x=1762262440; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eEHmXayK9QK4m707aejwlJqo2aRjzbrQ+Mcejqkcg9A=; b=mUgd4UxgTDq9nkWOKGUK3LbSOAFgNGKuEJMtAWlRU4KMqcd8mo/q8tC+ TOfhJ899zDBZGNKKtfVJiL6ad6zvjeCLfc+87S8TTn65YAwjha2qew8fb fMGY2UH8cx9boFdDp0j5SIn1EChsLim+EvvSSWSQZMNhkiocvMrIqi7p9 VSOtz1R8uYNMoQBS1C1vsaKBNOaZSbqZICFMm3ezE+v2+bbCiO7ZMxdAS yURVPX5aFEH/iAOiCB4vzVoEDJ0vPYCIr0eM7fG5RhVgtnpEzoMhyN0pv t/rMlvkYdnOowzub6GejAJm/HguZlQgAYfMxtn64Xy1GHsFSFymPwckUb w==; X-CSE-ConnectionGUID: tl7GdnnXShea2TqIHujSTQ== X-CSE-MsgGUID: fqmwppc1SZ2Iqr45jbr/KQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="47883267" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="47883267" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 05:20:37 -0800 X-CSE-ConnectionGUID: dj2GGPTeROWX/0WAwiVvBA== X-CSE-MsgGUID: fhWxWlAkTR6ifLFiiqDuLA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,257,1725346800"; d="scan'208";a="84099713" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa007.jf.intel.com with ESMTP; 04 Nov 2024 05:20:37 -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, will@kernel.org Subject: [PATCH v3 2/7] iommu: Consolidate the ops->remove_dev_pasid usage into a helper Date: Mon, 4 Nov 2024 05:20:28 -0800 Message-Id: <20241104132033.14027-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241104132033.14027-1-yi.l.liu@intel.com> References: <20241104132033.14027-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. Signed-off-by: Yi Liu Reviewed-by: Jason Gunthorpe Reviewed-by: Vasant Hegde Reviewed-by: Kevin Tian --- drivers/iommu/iommu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 866559bbc4e4..21320578d801 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3400,6 +3400,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) { @@ -3418,11 +3426,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; } @@ -3432,11 +3438,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); + iommu_remove_dev_pasid(device->dev, pasid, domain); } } From patchwork Mon Nov 4 13:20:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13861383 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 6BB141F942 for ; Mon, 4 Nov 2024 13:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726442; cv=none; b=JuG8jgmjxT/NdNGxCBUXH4qyb6MckVrIs+bTGimFpMLkb4SjbRUSghqax5Wun7NduJZZaPLqzA00baxfOSemDxHD5nmUkbKpyJROyl6P5vWRh5WhgvDx5/ynz/tjAVlyfE4XagK5wsg7zwTXGFllaq3Zm4hZDgJETCH9JI4Ac5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726442; c=relaxed/simple; bh=KVVNqzJwZcqWIOZLJeNFFrvoYnsRSL5gYbyJzdsEuaE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tgiSShKvjFpwCbjkhs8k2gzjbhovTbvdsjqDWWiw1/Dwhgi484W/xOjhcqe0uE17StTFeP8aDHyE++xUvUBZu6zl83U2MWzsEfaZLIRSvGWlQJKB8Bdt8VaH/9zOVJQkShM84GihfRh1HX53Be/8riSWWIBPaZbJ1E/L0qDL60o= 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=UFCfntvL; arc=none smtp.client-ip=198.175.65.10 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="UFCfntvL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730726440; x=1762262440; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KVVNqzJwZcqWIOZLJeNFFrvoYnsRSL5gYbyJzdsEuaE=; b=UFCfntvLHZ5j23AyqZS256G80vVKB2pW3eiUv+1CPp4np/27ojTzl4FG rf20p2mgPQGuMhXQeo1AZHXuPhKJCzGRc85Gk3jAC5U0fPv8nq0GwM0Fp HUCgDENCU8uEa3t1tNGsMye37bU/vKcnKBvpjqeunS5TlQ7Pez/2oR4nF cdFMWpsEUA2KfLo5nc4zxOQPWpcj86tIZBxydMmnN81CBF9g1w2bL0Vf9 vc8Bl+e1cXno6QnXEvDiqghb86H5HjY0oEu0m8qyBIwZVgB3bcQ7zP8gh 9W9nRiy81fFlHHsDjJO7ODhN3NvkEd62x+QxXo0eW6IjOZTFWnxnV0QgV w==; X-CSE-ConnectionGUID: 1snxp3pzRvyG2TMQS7Bg6Q== X-CSE-MsgGUID: eiiJZf4GRKWsKbgQ6nz10Q== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="47883275" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="47883275" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 05:20:40 -0800 X-CSE-ConnectionGUID: njXVw/rvQpimk6Gp/H9rGQ== X-CSE-MsgGUID: rV6Z7CncTdabYbRhPfdsJA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,257,1725346800"; d="scan'208";a="84099718" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa007.jf.intel.com with ESMTP; 04 Nov 2024 05:20:38 -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, will@kernel.org Subject: [PATCH v3 3/7] iommu: Detaching pasid by attaching to the blocked_domain Date: Mon, 4 Nov 2024 05:20:29 -0800 Message-Id: <20241104132033.14027-4-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241104132033.14027-1-yi.l.liu@intel.com> References: <20241104132033.14027-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 Signed-off-by: Yi Liu Reviewed-by: Jason Gunthorpe Reviewed-by: Vasant Hegde Reviewed-by: Kevin Tian --- 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 21320578d801..e8b2850cc61f 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3404,8 +3404,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; + + if (blocked_domain && blocked_domain->ops->set_dev_pasid) { + ret = blocked_domain->ops->set_dev_pasid(blocked_domain, + dev, pasid, domain); + } else if (ops->remove_dev_pasid) { + ops->remove_dev_pasid(dev, pasid, domain); + ret = 0; + } - ops->remove_dev_pasid(dev, pasid, domain); + WARN_ON(ret); } static int __iommu_set_group_pasid(struct iommu_domain *domain, @@ -3464,7 +3474,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 Mon Nov 4 13:20:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13861384 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 C2B2C22612 for ; Mon, 4 Nov 2024 13:20:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726442; cv=none; b=NKQOfkOEMeFVh6TjGh8ab52e8Btjrz+d/mYMVUz0yE4QRV2vFUmk/jGrN0gOK0OnhiPJirxIk/WEiNYEpxSTcDOzYMTwS/BLw+jdi2gqNz0S3WvudrFxX8FiuLJwecoj3ZO2FzHMxBE5bC5nB4DsZ6kmift7OkqQK5ocJw8+HO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726442; c=relaxed/simple; bh=kf1xvgtT9lTHmXp9iJNKEmi3xTpRAeqY1wh8VAk9QV0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A+HgliMgZwr2DW8nfhRPF5likarO/lXRpq3Ki6vL9UQOtCUMUpNY6uOozWwkCQWqiD29VzqQsunntVtG2GEIbzVGvyUAOfA33A9Zk+Jv/JtWusGU1pzIOBaktCCHexFSq4bef0iWNFNfnrPSKUk0UqPk7wjvXz89znk1c+arAiw= 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=n7FEJRdE; arc=none smtp.client-ip=198.175.65.10 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="n7FEJRdE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730726441; x=1762262441; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kf1xvgtT9lTHmXp9iJNKEmi3xTpRAeqY1wh8VAk9QV0=; b=n7FEJRdEVX/NBo9se+SPdU8gjFRk26WBZRX/Ims80Kei9R5Ns3gVxwIR NkvXQMBWlqhGz8NCapzsOt0/c5Wm65qZXO7hD8CUzcWtwkpdxNLAjg2uO rYSriAaKrw/261JolF77cB4wMq+aaAHo+VLuUeBFxUQFVFczsew7uMH17 DRHLWtx+I5fPm5nhFWEKS9rfIIUJk2iMzohP05NVgT3qrUZoh7YXhjUS5 QIjQWt7EGJENmaSN7X0ANT3QySDya0HzmwzE4ilgL71rrmb6OpMmK2EQ7 8R7x/TKLOlHEIxgqUqjsK+vBcjVeeSCUmFP3jJrgpIW1m/nCCDgA8Wyw+ A==; X-CSE-ConnectionGUID: ZdAkFNaYQk23W2GRbPqkdA== X-CSE-MsgGUID: 3slKhHD0S76cNHBt9W30rw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="47883283" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="47883283" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 05:20:40 -0800 X-CSE-ConnectionGUID: VTmIaPpIT5Wr3lwfZUKQrg== X-CSE-MsgGUID: hYPFcJESR6SmGkxKWeYaDg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,257,1725346800"; d="scan'208";a="84099726" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa007.jf.intel.com with ESMTP; 04 Nov 2024 05:20:40 -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, will@kernel.org Subject: [PATCH v3 4/7] iommu/arm-smmu-v3: Make the blocked domain support PASID Date: Mon, 4 Nov 2024 05:20:30 -0800 Message-Id: <20241104132033.14027-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241104132033.14027-1-yi.l.liu@intel.com> References: <20241104132033.14027-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 2d188d12f85c..57627ba44f6d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2961,13 +2961,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); @@ -2988,6 +2987,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, @@ -3069,6 +3069,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 = { @@ -3501,7 +3502,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 Mon Nov 4 13:20:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13861385 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 34BA12D05E for ; Mon, 4 Nov 2024 13:20:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726443; cv=none; b=XCZfLNPh8hv4U3kRVMVVPXYRwHYtsehtqrk7K6QRKNLb5Chxe1NMwefQAJs4NNVkCNlgEdEDHzGzv6+DV+fkYCcOnINwhznYagGa7xTeJagCwUsGO4mlb6qH87jRQzOHwf0FxZbhsgTuClUMQHcf9Y5Q+FkJI1FEOAhjbL7Eluk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726443; c=relaxed/simple; bh=STwQNNlpnSNSJ9AYhnQKss8CVJ6vzxvWbO4ctAdc2S0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Bvsa/w+GHMQeq62tlmcDJyTbrQ26Ke/ECeCc90Yh/jk9OOgAbLbB7DHC+1FNq+SF/Q/IUH54pxfvPvmHvBEunD5ysxG/glq2Q6zuka7LQMjq0ssKifZLxkG5Q9qM2mPkApcTKszYN4J6bzoIiRmmhcgN1rF6NVEFIaWansMqRUA= 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=KfrPLCRv; arc=none smtp.client-ip=198.175.65.10 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="KfrPLCRv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730726443; x=1762262443; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=STwQNNlpnSNSJ9AYhnQKss8CVJ6vzxvWbO4ctAdc2S0=; b=KfrPLCRvSpi9QfvbxTxBi+sXjjx54X+h9I0HUUqhx4c3d3Ir76BMVLcn 4t/CJsV+PLlyUkPA5Odg5q9mTV46QgV2doGxZx6x10yAuAgcVd/Qe3tUq 7/cFHVtVTUgxsJSJ90xndWXcr9OLQlYNdIqSI+CsexOAzmHFhyD/h5L7A nl6NUP3Vk9WT5CqJjSGz5c1anBs7t4GXyLLxJtt2BvlCgrDru3Lovm4T0 Gh84kpNugkFe31dbB8ybJdgUASb++1fu8OS4OUN3WuON8FdqdLXvvo2i2 R6lBBfbRg3kj2DmgsfiH0gaXAhcuYYGUKKCyl2AhsaBaWk7Gb8grwvXS9 A==; X-CSE-ConnectionGUID: jaZso0EtTMmvPwXlp3ikbA== X-CSE-MsgGUID: bzF+mVZXT8eY6SOqOUULaA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="47883293" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="47883293" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 05:20:41 -0800 X-CSE-ConnectionGUID: l/3qv5tnT/6O+vKxeVdHgg== X-CSE-MsgGUID: 4fCyQ77KR76IAjcITe+LqQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,257,1725346800"; d="scan'208";a="84099736" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa007.jf.intel.com with ESMTP; 04 Nov 2024 05:20:41 -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, will@kernel.org Subject: [PATCH v3 5/7] iommu/vt-d: Make the blocked domain support PASID Date: Mon, 4 Nov 2024 05:20:31 -0800 Message-Id: <20241104132033.14027-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241104132033.14027-1-yi.l.liu@intel.com> References: <20241104132033.14027-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 Signed-off-by: Yi Liu Reviewed-by: Jason Gunthorpe --- 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 7f1ca3c342a3..a1341078b962 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3414,10 +3414,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, } }; @@ -4291,15 +4296,18 @@ 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); struct intel_iommu *iommu = info->iommu; intel_pasid_tear_down_entry(iommu, dev, pasid, false); intel_drain_pasid_prq(dev, pasid); - domain_remove_dev_pasid(domain, dev, pasid); + domain_remove_dev_pasid(old, dev, pasid); + + return 0; } struct dev_pasid_info * @@ -4664,7 +4672,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, #ifdef CONFIG_INTEL_IOMMU_SVM .page_response = intel_svm_page_response, From patchwork Mon Nov 4 13:20:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13861386 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 64D9E2E40B for ; Mon, 4 Nov 2024 13:20:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726443; cv=none; b=Wthy8oNfVkMYSNo7KfPvqjvZ96EvhmKKkoE8Gc6niImINfvsCcdKsZ9O8/4ECWUkaglOCG3tPnlHINDzlhfeEohUM72vYoBkyFZF3s3zGfTuLViA68ezleDF2Rn6SbkreCqnw7nAlDqRTRUU1cWvI+y188HBsnSBBG4a805t3Vg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726443; c=relaxed/simple; bh=RCfVewssPKXS9OocasbX7CMeEPDsOqBtEh7aEvDUkbQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S5M7acUM6TbzETjTt4oryxBA8ywvldedSIu4QpdCMRAJ1W/zSgqTaaoTtqzhFaIq5mHbsGYQeFql59IzMmv9t6ETPUYxA5hpImrZF1Nq7S6bEOMAqooGtU3+uBPpJxZpM2sNWm5suIy3JFDAPVi72YsPoIiRt7Al1feg/hrk50k= 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=MFZRDnsn; arc=none smtp.client-ip=198.175.65.10 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="MFZRDnsn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730726443; x=1762262443; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RCfVewssPKXS9OocasbX7CMeEPDsOqBtEh7aEvDUkbQ=; b=MFZRDnsnQRnmX5Wq0vGSLW5V4ZIgG4kbXkd4yBqLthd6JaST7wa8GPI9 o7zwEB36DhLFVSHvyerfxa/+8kVUNOqxi/c5pqfKEIUjtWrx1ya16OmuC 26cjWuOgSt/p/DbrRZVLjVCbmoIIP9trQUPXXpxRgSfXwoDAXxhGUSj6B ktLkO7KZyIx6rTZ1J+Ivj/C5VKrU7mblGUaykztBXA2P7EWDa3cV1HLjM kuCECxge6Ab1yXJJs/q07n1YNXNHRy7EjM0x1nx1pGIKzE1kXHut+Wmwz 5K+frH1hviOgCI6cBtM1khKJImN778Llc4YLYR/8wLjTaiETlGF8UqK9L A==; X-CSE-ConnectionGUID: 0fK7KUEhTZS/lHprsZT2OQ== X-CSE-MsgGUID: RCOPoDBoSdG2DXfx6eR+Qg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="47883301" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="47883301" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 05:20:42 -0800 X-CSE-ConnectionGUID: Ao/UYGv/TVWB9ZKikg9Aww== X-CSE-MsgGUID: 4mziJiPHQaKEjf5YuQJduA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,257,1725346800"; d="scan'208";a="84099746" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa007.jf.intel.com with ESMTP; 04 Nov 2024 05:20:42 -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, will@kernel.org Subject: [PATCH v3 6/7] iommu/amd: Make the blocked domain support PASID Date: Mon, 4 Nov 2024 05:20:32 -0800 Message-Id: <20241104132033.14027-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241104132033.14027-1-yi.l.liu@intel.com> References: <20241104132033.14027-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 Signed-off-by: Yi Liu Reviewed-by: Jason Gunthorpe Reviewed-by: Vasant Hegde Reviewed-by: Kevin Tian --- 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 477aaf76b7ad..e513ced1ab53 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2472,10 +2472,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, } }; @@ -2908,7 +2917,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 Mon Nov 4 13:20:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13861387 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 1D97342AA6 for ; Mon, 4 Nov 2024 13:20:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726444; cv=none; b=n2ZKG79MoQ/up7sz+TyVPBXPq9581pMxHuVORj13bIuLafH5+23Rw01ZwkFoL+YPkoROo5Fi1GZFmjokKrvUrslNeSYmscIKKLsIcbwwfQQK1NLWr79qM6NaPF1tSGllvVwYFXxHKtfzXdALdW1GW3cCwuyfVImD+Ce3I+BFYPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730726444; c=relaxed/simple; bh=DBZ4yu49lmyJHEN3ldOTte/tR4q3nt/9R5Z+0qj5pig=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UA5z1lALqpQ9D6og8W4nnheJsmXYTS+ejjxF8bZQCb5tYrnMYMUFbaJeP1uVLtsAHfXVItm2senrlQ6jcv/Oz2DBu1MA0YQH1JPKL8dQ7tAat3Ts0pAO8S1B+yaG47kgh0ZAlntwQ45UB6JnkHh7F/onw0bqXzBfMCUODSzf61o= 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=Btik7K/h; arc=none smtp.client-ip=198.175.65.10 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="Btik7K/h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730726444; x=1762262444; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DBZ4yu49lmyJHEN3ldOTte/tR4q3nt/9R5Z+0qj5pig=; b=Btik7K/hGrZaplcMlEux5zmaZxEtLp0XGk+nZSyIQhgLDHdX5zLwB4cn 1DuEl74qk9wVaZur6Rss869RlcyQbCAVGLGW5a+CKZTsag43QIlw7wUFy V38ld5ylxygzDvfRIO9fMV8Og4lZjVjkfPZrZm2AytdpuGk2HBksS4wiV 87dzpFAneeggDDq3E0qw8yPpLlX0Hsq4/lCEbIuUBXSx5LCRjaxpcXC0+ spJOj6jQItA4dQEA22jCYuUel2zjYW9NcBshA+gcTxvMSeKy6w4gedpSX NSLLQurTCW3dLN25biBrbnL/qCeSXAHYCsxyiGxu2K8F4/wvRw+IbMWuy w==; X-CSE-ConnectionGUID: yBtM3S42Qmmf7kfO04Sg+g== X-CSE-MsgGUID: brC6PHPkTNWKXJcJLaYiUw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="47883309" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="47883309" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 05:20:43 -0800 X-CSE-ConnectionGUID: Rn7m0x/hSHSs+jgA0pAw3Q== X-CSE-MsgGUID: l5B6/ourQKyZVUACJxvUHg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,257,1725346800"; d="scan'208";a="84099754" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa007.jf.intel.com with ESMTP; 04 Nov 2024 05:20:43 -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, will@kernel.org Subject: [PATCH v3 7/7] iommu: Remove the remove_dev_pasid op Date: Mon, 4 Nov 2024 05:20:33 -0800 Message-Id: <20241104132033.14027-8-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241104132033.14027-1-yi.l.liu@intel.com> References: <20241104132033.14027-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. Signed-off-by: Yi Liu Reviewed-by: Jason Gunthorpe Reviewed-by: Vasant Hegde Reviewed-by: Kevin Tian --- 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 e8b2850cc61f..53f8e60acf30 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3405,17 +3405,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 if (ops->remove_dev_pasid) { - 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, @@ -3474,9 +3466,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 2ec0c9915aa5..257b1a53879a 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;