public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
To: Yi Liu <yi.l.liu@intel.com>,
	joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com
Cc: alex.williamson@redhat.com, eric.auger@redhat.com,
	nicolinc@nvidia.com, kvm@vger.kernel.org,
	chao.p.peng@linux.intel.com, iommu@lists.linux.dev,
	zhenzhong.duan@intel.com, vasant.hegde@amd.com,
	willy@infradead.org
Subject: Re: [PATCH v4 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid
Date: Sun, 10 Nov 2024 11:59:36 +0800	[thread overview]
Message-ID: <facfee81-1b25-4b3e-aecd-38930ee41f7a@linux.intel.com> (raw)
In-Reply-To: <20241108120427.13562-2-yi.l.liu@intel.com>

On 11/8/24 20:04, Yi Liu wrote:
> driver should implement both set_dev_pasid and remove_dev_pasid op, otherwise
> it is a problem how to detach pasid. In reality, it is impossible that an
> iommu driver implements set_dev_pasid() but no remove_dev_pasid() op. However,
> it is better to check it.
> 
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
> ---
>   drivers/iommu/iommu.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 13fcd9d8f2df..1c689e57928e 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -3352,17 +3352,19 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
>   			      struct iommu_attach_handle *handle)
>   {
>   	/* Caller must be a probed driver on dev */
> +	const struct iommu_ops *ops = dev_iommu_ops(dev);
>   	struct iommu_group *group = dev->iommu_group;
>   	struct group_device *device;
>   	int ret;
>   
> -	if (!domain->ops->set_dev_pasid)
> +	if (!domain->ops->set_dev_pasid ||
> +	    !ops->remove_dev_pasid)
>   		return -EOPNOTSUPP;
>   
>   	if (!group)
>   		return -ENODEV;

If group is NULL, calling dev_iommu_ops() will trigger a kernel NULL
pointer reference warning, which is unintended. If you need to check
ops->remove_dev_pasid, it should be done after the group check.

>   
> -	if (!dev_has_iommu(dev) || dev_iommu_ops(dev) != domain->owner ||
> +	if (!dev_has_iommu(dev) || ops != domain->owner ||
>   	    pasid == IOMMU_NO_PASID)
>   		return -EINVAL;
>   

--
baolu

  reply	other threads:[~2024-11-10  4:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-08 12:04 [PATCH v4 0/7] Support attaching PASID to the blocked_domain Yi Liu
2024-11-08 12:04 ` [PATCH v4 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Yi Liu
2024-11-10  3:59   ` Baolu Lu [this message]
2024-11-11  8:22     ` Yi Liu
2024-11-08 12:04 ` [PATCH v4 2/7] iommu: Consolidate the ops->remove_dev_pasid usage into a helper Yi Liu
2024-11-10  4:08   ` Baolu Lu
2024-11-08 12:04 ` [PATCH v4 3/7] iommu: Detaching pasid by attaching to the blocked_domain Yi Liu
2024-11-10  4:15   ` Baolu Lu
2024-11-10  4:21     ` Baolu Lu
2024-11-08 12:04 ` [PATCH v4 4/7] iommu/arm-smmu-v3: Make the blocked domain support PASID Yi Liu
2024-11-08 12:04 ` [PATCH v4 5/7] iommu/vt-d: " Yi Liu
2024-11-10  4:18   ` Baolu Lu
2024-11-08 12:04 ` [PATCH v4 6/7] iommu/amd: " Yi Liu
2024-11-08 12:04 ` [PATCH v4 7/7] iommu: Remove the remove_dev_pasid op Yi Liu
2024-11-10  4:19   ` Baolu Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=facfee81-1b25-4b3e-aecd-38930ee41f7a@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=eric.auger@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=vasant.hegde@amd.com \
    --cc=willy@infradead.org \
    --cc=yi.l.liu@intel.com \
    --cc=zhenzhong.duan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox