From patchwork Wed Nov 13 13:46:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13873763 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 844841F77BD for ; Wed, 13 Nov 2024 13:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505578; cv=none; b=GJlb2DwW2CdP/UTqRyyB36CDNuAynfqIRLZP7PnW93ZFkmUugw6x1rScVcZLG60aDXEhg07vhGeIU5jD5Vi7Tcz22/jM4quHdWqP+U1KIuo+LiGQ56yq259bJQ3xdW7V0w3P5HXm7SUIujcV7UxOeUB9jRO1xUyn//flw6RE3cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505578; c=relaxed/simple; bh=4b8Io+s7nkbd6XDJjuILasFFqi95yUE1DNtobrQoHh0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PJJZHDH6bakcyVxh1E8E3UWqt3+cww3/vQl0/+5G7vqQIv8HiB5IvZotyius8ieb9FHsghDhTSfJNaJtyYeQyLfdY/2Z4hJaFJEWHziRFEK0XgKfFVaqo0wuLPhEeCdBHNMgZiedANQ8PKkoZA9/oMuaWJFmmJ+oH+w5R6thjw8= 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=hctZ7xpX; arc=none smtp.client-ip=192.198.163.11 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="hctZ7xpX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731505577; x=1763041577; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4b8Io+s7nkbd6XDJjuILasFFqi95yUE1DNtobrQoHh0=; b=hctZ7xpXCxxXSQR0s2j8WTMkn+u3cUsUM2EBCh+3pDeWgcYdbHZF8KKV KFhaGs1UdIfDRbmC2mYyGHIlhRpmHWG+ZbEJXl/lLwr95jzXyBrbbuvlD jg8kQsYJTPMQ3hVrST4tM8GfOrFz0tK+NCQPqAa6Qao/f7np953KEgBAs 8A1muQSWo5wVI+uT93QvVD2m0P2+ub6gsA5c9os0DfmL9eDcfdjPmpiuf YFE9Jf7Deq0SuHFLHIFmF1kSquxEoG+dLoS3+YTvo4eU4jpxHziNqyPs8 fTkgsNFdTUUshFj8SwGy+G3bH4bAvChW+aOWasa7TzjZiMtNV8LZEpMla g==; X-CSE-ConnectionGUID: Kd9oIraERQqrEimwK2gzPQ== X-CSE-MsgGUID: Sw3Ebc4kQ6CjW7EeMVephA== X-IronPort-AV: E=McAfee;i="6700,10204,11254"; a="42025687" X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="42025687" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2024 05:46:15 -0800 X-CSE-ConnectionGUID: 9U++DY4JSdGiGizApnQzZA== X-CSE-MsgGUID: 30Lp228rQTW+HdTVERX7Fg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="87445584" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa006.fm.intel.com with ESMTP; 13 Nov 2024 05:46:14 -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 v5 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Date: Wed, 13 Nov 2024 05:46:07 -0800 Message-Id: <20241113134613.7173-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241113134613.7173-1-yi.l.liu@intel.com> References: <20241113134613.7173-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. Signed-off-by: Yi Liu --- 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 13fcd9d8f2df..b743fe612441 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3354,16 +3354,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 Nov 13 13:46:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13873764 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 776631DED47 for ; Wed, 13 Nov 2024 13:46:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505579; cv=none; b=uzy7R2NUsUjCxVwhH989aDYCuZhpiHPLtVQby/kCro4q6elmylNI6bWKUHqyryuZdAJ4I80MmQTVF0X7zJPGCytDAEROd/4sSsIpa/QliqI4ABANPUQnacUQB8eylOwV5R7UVL2440gGnpTrEhRfRxsi+bhOQ2cvQ3cvMt0oGu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505579; c=relaxed/simple; bh=jE/kU3yz9Y06hZZtEYTjoofLn3fDGlh9QxovaYHV4zM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n5n5rb09p6ibcw1wDXsDbODBWjxB6gOpDqJ7ovO56pF+M9OuC4X2SjlEUnzsZNl0XMMUBAeqKMAARnosHtpqfehxDueJb5aqg64Ydx0QGyCNDz+HeRzMc4T3e2tKbeChDudVlNmByTH6V8F5z2WpyNwTMXKdsI5yUfXPPbXawRY= 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=EMXLJKEZ; arc=none smtp.client-ip=192.198.163.11 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="EMXLJKEZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731505578; x=1763041578; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jE/kU3yz9Y06hZZtEYTjoofLn3fDGlh9QxovaYHV4zM=; b=EMXLJKEZhDBUueR3bwk5hyL8MyHzU87ZtW9/3y4ejEeQTcMCeU9mNVx0 kY0tgxtJv7LKDli4c75XVwDc2vhFTTnVYjJZtkmTscM42WFFrPqrQ+Lig O/Gcwto9fbpEUOuneeYyQm+brikwYYZjQ9UI8hSYipCJP8Pa4bGMDzAJr M8EaGu9BrlnkSMlcOb+YI//7H4mWO0Ub/OL55Vw7imOIUtjBfV+X2uVTK WOJuJaiTmvvAVZG9QGpkbfARK7115QRSVL5C89ZTi5trIvZLTiClEbHD6 5p7zMyt7GUQJE16XzJOz2wkZcLGFa4Q4gUrhx652CToJe+Z3LIUNcYaJL A==; X-CSE-ConnectionGUID: zwjnBHFkQyGipUKFkWirVw== X-CSE-MsgGUID: NBn5vh9GSIS2rzy9YuK8sA== X-IronPort-AV: E=McAfee;i="6700,10204,11254"; a="42025694" X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="42025694" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2024 05:46:16 -0800 X-CSE-ConnectionGUID: 9oSvCC2ySo6Q3v8jEqrZ6A== X-CSE-MsgGUID: IGg4UCxjSzisow3CRoqDjA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="87445589" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa006.fm.intel.com with ESMTP; 13 Nov 2024 05:46:15 -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 v5 2/7] iommu: Consolidate the ops->remove_dev_pasid usage into a helper Date: Wed, 13 Nov 2024 05:46:08 -0800 Message-Id: <20241113134613.7173-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241113134613.7173-1-yi.l.liu@intel.com> References: <20241113134613.7173-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 b743fe612441..c1ab42ff5c4b 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 Wed Nov 13 13:46:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13873766 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 BA01D1FB882 for ; Wed, 13 Nov 2024 13:46:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505580; cv=none; b=fROXasox1y627W63iJ8kk29tC6Z3G9/REBDdyfbE4hkb1lnZ1RasheLaI4o/I+ohoJp6BaavCOI8pdY9QO0NqJiAm2BARWnARQut1S9kfA14qJ/N3sPaKZBOwGUOFAUyN5OSvDSF1RQS5d5+gChUKZVqPCwTBCulkrrqHjRenpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505580; c=relaxed/simple; bh=BRPI8MlZdOA8RXy54BH0Uwx9Ljveb1udubzfe8kZZsQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eUtxTEb9CVwCHXzLgT3qrL/QsIq+DU14v5jwCljk2SvJvnYNlMhC+COeG+T2JD9tPxlL2TruKSoVSrJ4KUfytnBOnWYmMteZOmgqsYCQfBj4yiWK/iN8y9LnYKsOucZ8X2TyS5flXXlKGwQaVDk/a/LiQ+D3I231wrlLTCuwapQ= 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=fbl/x96x; arc=none smtp.client-ip=192.198.163.11 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="fbl/x96x" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731505578; x=1763041578; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BRPI8MlZdOA8RXy54BH0Uwx9Ljveb1udubzfe8kZZsQ=; b=fbl/x96xOfgXs8zyv737qDAZBGhbYleW6Fe3XFGaJtuPoK/C7fcWp58s aPZWgj3WxUgihDNIrPpNJA1+vEgph/zEKqxo2TkNfIA87Pm0rc6RPbESw mj/eCcUgDdAHZk0qNb5vBf2M246RBm7pyx59iLV8jxwDQUMZg4C93cilJ 0+NtZalY4jZOcLy0ZbFMgx01EQu1DVeh5ULzu7bPD32Pu0dE4dbf8VKOA 2x6890Y77GQ/2To2xtLtDPbWq8J7rZqrUw2NgW/SjXms+O+nTSBnE0KHl uMW9fZjwaI+rdynaLzxEI4x1X6evHNtef80SjEcZ3soczIp1Z1TMof59/ w==; X-CSE-ConnectionGUID: OlJIM1LpRKq8LD7iFga0bA== X-CSE-MsgGUID: XRH1QD5iQx67BIO/Su9xig== X-IronPort-AV: E=McAfee;i="6700,10204,11254"; a="42025703" X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="42025703" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2024 05:46:16 -0800 X-CSE-ConnectionGUID: Rrjd+kILRMqDgiTvmo/Ofw== X-CSE-MsgGUID: WL2lfrJHRyS7Sqp7QJdUOA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="87445594" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa006.fm.intel.com with ESMTP; 13 Nov 2024 05:46:15 -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 v5 3/7] iommu: Detaching pasid by attaching to the blocked_domain Date: Wed, 13 Nov 2024 05:46:09 -0800 Message-Id: <20241113134613.7173-4-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241113134613.7173-1-yi.l.liu@intel.com> References: <20241113134613.7173-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 c1ab42ff5c4b..25d170de76fe 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, @@ -3366,7 +3376,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 Nov 13 13:46:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13873765 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 4F3041FF605 for ; Wed, 13 Nov 2024 13:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505579; cv=none; b=ajEnt2A1q+3Lu+c88CB/qDIz6wVEUu3RVabqSlCxY/sedPDpH95ILHmpzkrIwomJzFxIhj4tIy6iRNAEid70L3kEeyjUhgBH+vNJjzOFb0eKlfxXVHyuch89RQUQ/TaKynslrrqYdlCPmaWyCJD8gDJArKfd0B/9dLVvhUExJEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505579; c=relaxed/simple; bh=CQNBEu2JwavCGSEpJSQqW92hh61UdmjmKwLxFCOoolw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cpwvNjABCH0T/5F1O2JHQfOiUWn5sYQnaOM159lD4rWoOQf79cGHz57eZJ3l6mORSRU8DCip24GyaEvCPcjle+YK4Nzmo+xPrqrSahl36AubKRtbMaysp6J+aDEcKEJtmoE/bwagmkwpcTfmjbXAjSVm+RcDJDFjq5zMRuBe0ks= 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=UTj7O8e1; arc=none smtp.client-ip=192.198.163.11 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="UTj7O8e1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731505578; x=1763041578; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CQNBEu2JwavCGSEpJSQqW92hh61UdmjmKwLxFCOoolw=; b=UTj7O8e1z5MwNhByKLnK8bl7Yg/OY5IiWrLzg4xJJQTNDdpGt76y7LoH lox09XbIUmh9qKYYuvi0QDGxJfgMsxgWGg1MivALBfKlxHfMFHGayVv2F Sv1ZT6UQkcbd4XCfiCQijJmOKYBcYpOglX+/+drTqQWuE0l2eac6iipVK OZCcKQnHBNIiMwva2e4l5MfQiu1y9beuM7lRkYOb/mP1fglCtjd0HE2sx zwGcbchP48BOf2mqwr0bbGL+s33mzwq2KDoIaBhQILFuOq6hKVANSGJ1+ DE/OtEyvUxcN1vkBSCNz4BLUErO0WUMypV9ygPw/xDNAzouzj7ZbBuhnK g==; X-CSE-ConnectionGUID: hWhZ1oW+SFyQam2Hw0NDDQ== X-CSE-MsgGUID: ZjdT+1KoS2ei2+l5a4An0Q== X-IronPort-AV: E=McAfee;i="6700,10204,11254"; a="42025711" X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="42025711" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2024 05:46:17 -0800 X-CSE-ConnectionGUID: X9t7aTfzTRmvl5Q51QwOqQ== X-CSE-MsgGUID: lAhf9qYGQXKB1BRsoo04FQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="87445598" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa006.fm.intel.com with ESMTP; 13 Nov 2024 05:46:16 -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 v5 4/7] iommu/arm-smmu-v3: Make the blocked domain support PASID Date: Wed, 13 Nov 2024 05:46:10 -0800 Message-Id: <20241113134613.7173-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241113134613.7173-1-yi.l.liu@intel.com> References: <20241113134613.7173-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 Wed Nov 13 13:46:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13873767 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 1CC571F8EEB for ; Wed, 13 Nov 2024 13:46:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505580; cv=none; b=benW4sm7cpRe9SmOUmAwHyStU6dY6Vjkqn5H5beyKTEVcGbjPA36NzzuKozWf+nXGBScc3DCShPY+bsgEPWGI9po9j2iObr580tPGrKmdfnYZ06AQtXBqVHhoO8j2NvQ/+gzy3sND4rrUSY0EtIDiHNcgRnNIdZ4DqR13oSZ7LE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505580; c=relaxed/simple; bh=3AqbtmLCwoM3c8F9WaTD6rvQENqm318ez1vv4b46eK8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pEXEtCK5YuaApnGLALwiyckfe5ifaoncVO3ztZKvEkHDoLH+pZWW3j3bsHt0pJJdnbvR57kWYQaDRGnmux9GYP0IRHk/Nk0QE/hvCH5hrbUNPofDrSB8ZI4zaMr325V7jbTNmAAAPwiVnyMOCztl0i2OFvIH+ql+zLrJBvMzpZo= 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=Pb8u1yy0; arc=none smtp.client-ip=192.198.163.11 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="Pb8u1yy0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731505579; x=1763041579; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3AqbtmLCwoM3c8F9WaTD6rvQENqm318ez1vv4b46eK8=; b=Pb8u1yy0Uq9l+uaJ2YEEKlVR+5CFwIy2ZCqYMmN4t7VLwxn8odSNtUv1 XnRA5HnNFMW5lUlI+FAHTMBZ6St8ZphxCRSW8l1bEp1rMuMhtAf6sLcHL Binc2HXj97eAmSG8+BzQOzImIs86vM73mVuL/YW/FwmhE+aoIwS7Qi1VB K4ecT7N3P8Lt1LV9NetFT+GVtH9MzlmDxiH/cYWPTrDCG28/Ym7pK4i1B uDo34syuM6N1w5pBFrNBlQC16hBpZ0nQOL2ouCoLkINYJy8gJGUx6+5E+ 0o3fXeM9GABj3OLG1FuNREo3hv8MxBtyhwDbtx/NcY06tk5ClVyVaHHtH Q==; X-CSE-ConnectionGUID: 2lkPTuDkRj6dvYOIsr8h7g== X-CSE-MsgGUID: 3VGRiQJmQB67jMdcbtbJ/w== X-IronPort-AV: E=McAfee;i="6700,10204,11254"; a="42025719" X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="42025719" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2024 05:46:17 -0800 X-CSE-ConnectionGUID: A0vWsUhvQyq7FMt8COVkfw== X-CSE-MsgGUID: QRgU68J5SaiMX9n2iN5TCw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="87445604" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa006.fm.intel.com with ESMTP; 13 Nov 2024 05:46:16 -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 v5 5/7] iommu/vt-d: Make the blocked domain support PASID Date: Wed, 13 Nov 2024 05:46:11 -0800 Message-Id: <20241113134613.7173-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241113134613.7173-1-yi.l.liu@intel.com> References: <20241113134613.7173-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 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 Wed Nov 13 13:46:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13873768 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 F30621FF035 for ; Wed, 13 Nov 2024 13:46:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505581; cv=none; b=MDBsrnegQxR5c4jo78T7svw/AxLfkzjId+LALxFp3wUSVIDPN63nPm0Q+RxYbeCQhos2uHjh5Eojju4Q3ewi/WoPUbolLJPBwxlpfy9yvBfxrOzmSucsk/zKb9xwyfNExpAq1TZCrThaTuQGQiRKZ+GsBWtAqvPQ/AIgrrS/ums= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505581; c=relaxed/simple; bh=Mejinn7dwxrWFJJxi0gYE+6CIjdQ4PZ7QCUJBDIlsZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=II48trqZhHf0ZTc9QD8Z5v83xqh5FXmqtA5kLmGjTtk5r5na+K5jblOtKBdBfNuSMEAC6YgsILcjpyrSP0ObrPDmMEz83bb1v1Og5TEhKGBleXkv06cSi2YrbcErqviWklS5Gmxc86+On/YXyOybRFhNUELzKU8RPqdl3Lxi08w= 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=VLsrJdtJ; arc=none smtp.client-ip=192.198.163.11 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="VLsrJdtJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731505580; x=1763041580; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Mejinn7dwxrWFJJxi0gYE+6CIjdQ4PZ7QCUJBDIlsZY=; b=VLsrJdtJegLlYwNWo/AiV79Dpan/K2Y8BzI0Cb/6qCfRKKfrdCohRjEN 3DZSQniHlbnhl6OJv4itsVXiQJcHYr++oBesLcQxS+3nL3khbVBkpua81 1n4hnqLClq1n1VM8PMXRZVhWg7HhdCZxxlNAr5X2jA76zjGsDSTMTlfbe xA4391qmDkQskls99OqsKglQiw0SwT0sUEadg7mVNIZGAHjmpmj2QRw9l dmMkx9F07V2BNwABGbkP6fouIH1C7yHVDo1Rhel0uE/rRJ96POCfExx+E LYUG+BCUhudHBMxoK7HjDzlaC8R4SsZK7aoRz2aDarDh4JmWatnyCudbe w==; X-CSE-ConnectionGUID: oZ95hqt8R2KQ8KtNh8hL5g== X-CSE-MsgGUID: Tmj+I6K4SWWBFoif2MMrag== X-IronPort-AV: E=McAfee;i="6700,10204,11254"; a="42025726" X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="42025726" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2024 05:46:17 -0800 X-CSE-ConnectionGUID: vJiFkR5CROu4rv9N5ga33w== X-CSE-MsgGUID: swwAPy1JSyePTy0ZfrT4bg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="87445608" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa006.fm.intel.com with ESMTP; 13 Nov 2024 05:46:16 -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 v5 6/7] iommu/amd: Make the blocked domain support PASID Date: Wed, 13 Nov 2024 05:46:12 -0800 Message-Id: <20241113134613.7173-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241113134613.7173-1-yi.l.liu@intel.com> References: <20241113134613.7173-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 Wed Nov 13 13:46:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13873769 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 5EBF8201036 for ; Wed, 13 Nov 2024 13:46:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505582; cv=none; b=bLkZtVpVsFKgPNL8m0CBYdgWyZJOxo1z4qFRKbXsXf/Y1NCHod9tQIy95uUVwYOOT87tzGtMDasg2vMa45ZUC+APAw0CBp8InsQdMVq0V4Sh3m6savxDjo4IqjSkDDJRtb/yL7w7BpzNr7hnffqIkmaKx1baNvMSys1IAUwL1DA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731505582; c=relaxed/simple; bh=RSZiUmG12bOfUY9cuPpOaVCOvpSre8G8I7IPBw8s4VA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L6VnEpS0T6F7b6RjZfNaLHu4p+OOBIFgbmWvak6IP63N94IYbrW0dajYEWzzTwmEXXYNsgkYr/9enLWeE5FhkRfbmPQzQQ1DaeuTcrPVKub9iXcJmVRz9F5SXZvfE2l7TzPsvaTK9RPD+PeHdvqJzJYx5LytBmY+7LMju4Qb4nw= 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=ghORtReT; arc=none smtp.client-ip=192.198.163.11 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="ghORtReT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731505580; x=1763041580; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RSZiUmG12bOfUY9cuPpOaVCOvpSre8G8I7IPBw8s4VA=; b=ghORtReTxQatqDu+oDukVvagfyOthqa2QSdvuD4WZ4Pfe3+V+xiapiRT /c7bLx7JUlxKQ/y9peyUscXXPley5ZojkF0OfCI+0tOxnL4mnZZNFjR/W yn+Ug+npQWWs88Uei/G0RPcQYv20DFrTZqJ6n44J71EQm/aH/B9yHZnav hWAs9gA1mDJNS1+uG1eqgmHDariKIEyxKZpc5kKucWNBPKm289r9Cz82P nYywP3igWdCb8hqJcAYsBC2S5A7IMSp44bIgB9Fxj8b0wl4LDRy6A4d6i Y6Uu2UjLO11zxTJ5bE7rfJh/cDnrAW5u3ynwRVaBqlpL4so00oaTTP53w Q==; X-CSE-ConnectionGUID: bO+lq2YbSxa2U6LKJKDqjw== X-CSE-MsgGUID: RajcmH0hRl+lh6P1i0GWHw== X-IronPort-AV: E=McAfee;i="6700,10204,11254"; a="42025735" X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="42025735" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2024 05:46:18 -0800 X-CSE-ConnectionGUID: sZTYEZIRQ4GTyTm6J0Hwcg== X-CSE-MsgGUID: QhaMjDBbSoGjOBH292t0cA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,151,1728975600"; d="scan'208";a="87445611" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa006.fm.intel.com with ESMTP; 13 Nov 2024 05:46:17 -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 v5 7/7] iommu: Remove the remove_dev_pasid op Date: Wed, 13 Nov 2024 05:46:13 -0800 Message-Id: <20241113134613.7173-8-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241113134613.7173-1-yi.l.liu@intel.com> References: <20241113134613.7173-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 25d170de76fe..8a3e3a753fd5 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, @@ -3376,9 +3368,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 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;