Linux IOMMU Development
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Aleksandr Fedorov <sanekf@nxt.ru>, Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iommu: explicitly check for NULL in iommu_dma_get_resv_regions()
Date: Thu, 10 Feb 2022 10:43:17 +0000	[thread overview]
Message-ID: <b090141f-0822-609f-429d-ea790d7fc828@arm.com> (raw)
In-Reply-To: <5481021644415780@myt5-a5512e99e394.qloud-c.yandex.net>

On 2022-02-09 14:09, Aleksandr Fedorov wrote:
> iommu_dma_get_resv_regions() assumes that iommu_fwspec field for
> corresponding device is set which is not always true.  Since
> iommu_dma_get_resv_regions() seems to be a future-proof generic API
> that can be used by any iommu driver, add an explicit check for NULL.

Except it's not a "generic" interface for drivers to call at random, 
it's a helper for retrieving common firmware-based information 
specifically for drivers already using the fwspec mechanism for common 
firmware bindings. If any driver calls this with a device *without* a 
valid fwnode, it deserves to crash because it's done something 
fundamentally wrong.

I concur that it's not exactly obvious that "non-IOMMU-specific" means 
"based on common firmware bindings, thus implying fwspec".

Robin.

> Currently it can work by accident since compiler can eliminate
> the 'iommu_fwspec' check altogether when CONFIG_ACPI_IORT=n, but
> code elimination from optimizations is not reliable.
> 
> Signed-off-by: Aleksandr Fedorov <halcien@gmail.com>
> ---
> A compilation failure has been observed on a gcc-compatible compiler based on EDG.
> 
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index d85d54f2b549..474b1b7211d7 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -382,10 +382,10 @@ void iommu_put_dma_cookie(struct iommu_domain *domain)
>    */
>   void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
>   {
> +	struct iommu_fwspec *iommu_fwspec = dev_iommu_fwspec_get(dev);
>   
> -	if (!is_of_node(dev_iommu_fwspec_get(dev)->iommu_fwnode))
> +	if (iommu_fwspec && !is_of_node(iommu_fwspec->iommu_fwnode))
>   		iort_iommu_msi_get_resv_regions(dev, list);
> -
>   }
>   EXPORT_SYMBOL(iommu_dma_get_resv_regions);
>   
> _______________________________________________
> iommu mailing list
> iommu@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2022-02-10 10:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09 14:09 [PATCH] iommu: explicitly check for NULL in iommu_dma_get_resv_regions() Aleksandr Fedorov
2022-02-10 10:43 ` Robin Murphy [this message]
2022-02-11 10:18   ` Aleksandr Fedorov

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=b090141f-0822-609f-429d-ea790d7fc828@arm.com \
    --to=robin.murphy@arm.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sanekf@nxt.ru \
    --cc=will@kernel.org \
    /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