All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu: explicitly check for NULL in iommu_dma_get_resv_regions()
@ 2022-02-09 14:09 ` Aleksandr Fedorov
  0 siblings, 0 replies; 6+ messages in thread
From: Aleksandr Fedorov @ 2022-02-09 14:09 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, iommu, linux-kernel

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.

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);
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] iommu: explicitly check for NULL in iommu_dma_get_resv_regions()
@ 2022-02-09 14:09 ` Aleksandr Fedorov
  0 siblings, 0 replies; 6+ messages in thread
From: Aleksandr Fedorov @ 2022-02-09 14:09 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, iommu, linux-kernel

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.

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] iommu: explicitly check for NULL in iommu_dma_get_resv_regions()
  2022-02-09 14:09 ` Aleksandr Fedorov
@ 2022-02-10 10:43   ` Robin Murphy
  -1 siblings, 0 replies; 6+ messages in thread
From: Robin Murphy @ 2022-02-10 10:43 UTC (permalink / raw)
  To: Aleksandr Fedorov, Joerg Roedel, Will Deacon, iommu, linux-kernel

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iommu: explicitly check for NULL in iommu_dma_get_resv_regions()
@ 2022-02-10 10:43   ` Robin Murphy
  0 siblings, 0 replies; 6+ messages in thread
From: Robin Murphy @ 2022-02-10 10:43 UTC (permalink / raw)
  To: Aleksandr Fedorov, Joerg Roedel, Will Deacon, iommu, linux-kernel

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iommu: explicitly check for NULL in iommu_dma_get_resv_regions()
  2022-02-10 10:43   ` Robin Murphy
@ 2022-02-11 10:18     ` Aleksandr Fedorov
  -1 siblings, 0 replies; 6+ messages in thread
From: Aleksandr Fedorov @ 2022-02-11 10:18 UTC (permalink / raw)
  To: Robin Murphy; +Cc: Joerg Roedel, Will Deacon, iommu, linux-kernel

> 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".

Thanks for the explanations, yes, this was the misunderstanding on my
part. Maybe add a comment?

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index d85d54f2b549..ce5e7d4d054a 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -379,6 +379,9 @@ void iommu_put_dma_cookie(struct iommu_domain *domain)
  * for general non-IOMMU-specific reservations. Currently, this covers GICv3
  * ITS region reservation on ACPI based ARM platforms that may require HW MSI
  * reservation.
+ *
+ * Note that this helper is meant to be used only by drivers that are already
+ * using the fwspec mechanism for common firmware bindings.
  */
 void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
 {

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] iommu: explicitly check for NULL in iommu_dma_get_resv_regions()
@ 2022-02-11 10:18     ` Aleksandr Fedorov
  0 siblings, 0 replies; 6+ messages in thread
From: Aleksandr Fedorov @ 2022-02-11 10:18 UTC (permalink / raw)
  To: Robin Murphy; +Cc: Will Deacon, iommu, linux-kernel

> 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".

Thanks for the explanations, yes, this was the misunderstanding on my
part. Maybe add a comment?

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index d85d54f2b549..ce5e7d4d054a 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -379,6 +379,9 @@ void iommu_put_dma_cookie(struct iommu_domain *domain)
  * for general non-IOMMU-specific reservations. Currently, this covers GICv3
  * ITS region reservation on ACPI based ARM platforms that may require HW MSI
  * reservation.
+ *
+ * Note that this helper is meant to be used only by drivers that are already
+ * using the fwspec mechanism for common firmware bindings.
  */
 void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
 {
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-02-11 10:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 14:09 [PATCH] iommu: explicitly check for NULL in iommu_dma_get_resv_regions() Aleksandr Fedorov
2022-02-09 14:09 ` Aleksandr Fedorov
2022-02-10 10:43 ` Robin Murphy
2022-02-10 10:43   ` Robin Murphy
2022-02-11 10:18   ` Aleksandr Fedorov
2022-02-11 10:18     ` Aleksandr Fedorov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.