"dev->dma_range_map" contains the devices' dma_ranges information,
This patch moves dma_range_map before of_iommu_configure. The iommu
driver may need to know the dma_address requirements of its iommu
consumer devices.
CC: Rob Herring <[email protected]>
CC: Frank Rowand <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
---
drivers/of/device.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/of/device.c b/drivers/of/device.c
index aedfaaafd3e7..1d84636149df 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -170,9 +170,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
dev_dbg(dev, "device is%sdma coherent\n",
coherent ? " " : " not ");
+ dev->dma_range_map = map;
iommu = of_iommu_configure(dev, np, id);
if (PTR_ERR(iommu) == -EPROBE_DEFER) {
kfree(map);
+ dev->dma_range_map = NULL;
return -EPROBE_DEFER;
}
@@ -181,7 +183,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
- dev->dma_range_map = map;
return 0;
}
EXPORT_SYMBOL_GPL(of_dma_configure_id);
--
2.18.0
On Mon, Jan 11, 2021 at 07:18:47PM +0800, Yong Wu wrote:
> "dev->dma_range_map" contains the devices' dma_ranges information,
> This patch moves dma_range_map before of_iommu_configure. The iommu
> driver may need to know the dma_address requirements of its iommu
> consumer devices.
>
> CC: Rob Herring <[email protected]>
> CC: Frank Rowand <[email protected]>
> Signed-off-by: Yong Wu <[email protected]>
> ---
> drivers/of/device.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index aedfaaafd3e7..1d84636149df 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -170,9 +170,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> dev_dbg(dev, "device is%sdma coherent\n",
> coherent ? " " : " not ");
>
> + dev->dma_range_map = map;
> iommu = of_iommu_configure(dev, np, id);
> if (PTR_ERR(iommu) == -EPROBE_DEFER) {
> kfree(map);
> + dev->dma_range_map = NULL;
Not really going to matter, but you should probably clear dma_range_map
before what it points to is freed.
With that,
Reviewed-by: Rob Herring <[email protected]>
> return -EPROBE_DEFER;
> }
>
> @@ -181,7 +183,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
>
> arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
>
> - dev->dma_range_map = map;
> return 0;
> }
> EXPORT_SYMBOL_GPL(of_dma_configure_id);
> --
> 2.18.0
>
On Thu, 2021-01-14 at 13:27 -0600, Rob Herring wrote:
> On Mon, Jan 11, 2021 at 07:18:47PM +0800, Yong Wu wrote:
> > "dev->dma_range_map" contains the devices' dma_ranges information,
> > This patch moves dma_range_map before of_iommu_configure. The iommu
> > driver may need to know the dma_address requirements of its iommu
> > consumer devices.
> >
> > CC: Rob Herring <[email protected]>
> > CC: Frank Rowand <[email protected]>
> > Signed-off-by: Yong Wu <[email protected]>
> > ---
> > drivers/of/device.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/of/device.c b/drivers/of/device.c
> > index aedfaaafd3e7..1d84636149df 100644
> > --- a/drivers/of/device.c
> > +++ b/drivers/of/device.c
> > @@ -170,9 +170,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> > dev_dbg(dev, "device is%sdma coherent\n",
> > coherent ? " " : " not ");
> >
> > + dev->dma_range_map = map;
> > iommu = of_iommu_configure(dev, np, id);
> > if (PTR_ERR(iommu) == -EPROBE_DEFER) {
> > kfree(map);
> > + dev->dma_range_map = NULL;
>
> Not really going to matter, but you should probably clear dma_range_map
> before what it points to is freed.
>
> With that,
>
> Reviewed-by: Rob Herring <[email protected]>
Thanks for the review. I will move it before "kfree(map)" in next
version.
>
> > return -EPROBE_DEFER;
> > }
> >
> > @@ -181,7 +183,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> >
> > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
> >
> > - dev->dma_range_map = map;
> > return 0;
> > }
> > EXPORT_SYMBOL_GPL(of_dma_configure_id);
> > --
> > 2.18.0
> >
On 2021-01-15 05:30, Yong Wu wrote:
> On Thu, 2021-01-14 at 13:27 -0600, Rob Herring wrote:
>> On Mon, Jan 11, 2021 at 07:18:47PM +0800, Yong Wu wrote:
>>> "dev->dma_range_map" contains the devices' dma_ranges information,
>>> This patch moves dma_range_map before of_iommu_configure. The iommu
>>> driver may need to know the dma_address requirements of its iommu
>>> consumer devices.
>>>
>>> CC: Rob Herring <[email protected]>
>>> CC: Frank Rowand <[email protected]>
>>> Signed-off-by: Yong Wu <[email protected]>
>>> ---
>>> drivers/of/device.c | 3 ++-
>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/of/device.c b/drivers/of/device.c
>>> index aedfaaafd3e7..1d84636149df 100644
>>> --- a/drivers/of/device.c
>>> +++ b/drivers/of/device.c
>>> @@ -170,9 +170,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
>>> dev_dbg(dev, "device is%sdma coherent\n",
>>> coherent ? " " : " not ");
>>>
>>> + dev->dma_range_map = map;
>>> iommu = of_iommu_configure(dev, np, id);
>>> if (PTR_ERR(iommu) == -EPROBE_DEFER) {
>>> kfree(map);
>>> + dev->dma_range_map = NULL;
>>
>> Not really going to matter, but you should probably clear dma_range_map
>> before what it points to is freed.
>>
>> With that,
>>
>> Reviewed-by: Rob Herring <[email protected]>
>
> Thanks for the review. I will move it before "kfree(map)" in next
> version.
Paul noticed that we already have a bug in assigning to this
unconditionally[1] - I'd totally forgotten about this series when I
theorised about IOMMU drivers wanting the information earlier, but
sweeping my inbox now only goes to show I was right to think of it :)
We should really get something in as a fix independent of this series,
taking both angles into account.
Robin.
[1]
https://lore.kernel.org/linux-arm-kernel/[email protected]/
>>
>>> return -EPROBE_DEFER;
>>> }
>>>
>>> @@ -181,7 +183,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
>>>
>>> arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
>>>
>>> - dev->dma_range_map = map;
>>> return 0;
>>> }
>>> EXPORT_SYMBOL_GPL(of_dma_configure_id);
>>> --
>>> 2.18.0
>>>
>
> _______________________________________________
> iommu mailing list
> [email protected]
> https://lists.linuxfoundation.org/mailman/listinfo/iommu
>
Hi,
On Mon 18 Jan 21, 15:49, Robin Murphy wrote:
> On 2021-01-15 05:30, Yong Wu wrote:
> > On Thu, 2021-01-14 at 13:27 -0600, Rob Herring wrote:
> > > On Mon, Jan 11, 2021 at 07:18:47PM +0800, Yong Wu wrote:
> > > > "dev->dma_range_map" contains the devices' dma_ranges information,
> > > > This patch moves dma_range_map before of_iommu_configure. The iommu
> > > > driver may need to know the dma_address requirements of its iommu
> > > > consumer devices.
> > > >
> > > > CC: Rob Herring <[email protected]>
> > > > CC: Frank Rowand <[email protected]>
> > > > Signed-off-by: Yong Wu <[email protected]>
> > > > ---
> > > > drivers/of/device.c | 3 ++-
> > > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/of/device.c b/drivers/of/device.c
> > > > index aedfaaafd3e7..1d84636149df 100644
> > > > --- a/drivers/of/device.c
> > > > +++ b/drivers/of/device.c
> > > > @@ -170,9 +170,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> > > > dev_dbg(dev, "device is%sdma coherent\n",
> > > > coherent ? " " : " not ");
> > > > + dev->dma_range_map = map;
> > > > iommu = of_iommu_configure(dev, np, id);
> > > > if (PTR_ERR(iommu) == -EPROBE_DEFER) {
> > > > kfree(map);
> > > > + dev->dma_range_map = NULL;
> > >
> > > Not really going to matter, but you should probably clear dma_range_map
> > > before what it points to is freed.
> > >
> > > With that,
> > >
> > > Reviewed-by: Rob Herring <[email protected]>
> >
> > Thanks for the review. I will move it before "kfree(map)" in next
> > version.
>
> Paul noticed that we already have a bug in assigning to this
> unconditionally[1] - I'd totally forgotten about this series when I
> theorised about IOMMU drivers wanting the information earlier, but sweeping
> my inbox now only goes to show I was right to think of it :)
>
> We should really get something in as a fix independent of this series,
> taking both angles into account.
Okay, I can also fix this while fixing my case. So we'd go for setting
dev->dma_range_map = map; under the if (!ret).
Then I think the error case for of_iommu_configure should be to set
dev->dma_range_map = NULL; only if map != NULL (otherwise we'd be overwriting
and leaking the previously-set map).
I think a comment to remind that dev->dma_range_map can be set prior to this
function would be useful too.
What do you think?
Cheers,
Paul
> Robin.
>
> [1] https://lore.kernel.org/linux-arm-kernel/[email protected]/
>
> > >
> > > > return -EPROBE_DEFER;
> > > > }
> > > > @@ -181,7 +183,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> > > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
> > > > - dev->dma_range_map = map;
> > > > return 0;
> > > > }
> > > > EXPORT_SYMBOL_GPL(of_dma_configure_id);
> > > > --
> > > > 2.18.0
> > > >
> >
> > _______________________________________________
> > iommu mailing list
> > [email protected]
> > https://lists.linuxfoundation.org/mailman/listinfo/iommu
> >
--
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
On Mon, 2021-01-18 at 15:49 +0000, Robin Murphy wrote:
> On 2021-01-15 05:30, Yong Wu wrote:
> > On Thu, 2021-01-14 at 13:27 -0600, Rob Herring wrote:
> >> On Mon, Jan 11, 2021 at 07:18:47PM +0800, Yong Wu wrote:
> >>> "dev->dma_range_map" contains the devices' dma_ranges information,
> >>> This patch moves dma_range_map before of_iommu_configure. The iommu
> >>> driver may need to know the dma_address requirements of its iommu
> >>> consumer devices.
> >>>
> >>> CC: Rob Herring <[email protected]>
> >>> CC: Frank Rowand <[email protected]>
> >>> Signed-off-by: Yong Wu <[email protected]>
> >>> ---
> >>> drivers/of/device.c | 3 ++-
> >>> 1 file changed, 2 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/drivers/of/device.c b/drivers/of/device.c
> >>> index aedfaaafd3e7..1d84636149df 100644
> >>> --- a/drivers/of/device.c
> >>> +++ b/drivers/of/device.c
> >>> @@ -170,9 +170,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> >>> dev_dbg(dev, "device is%sdma coherent\n",
> >>> coherent ? " " : " not ");
> >>>
> >>> + dev->dma_range_map = map;
> >>> iommu = of_iommu_configure(dev, np, id);
> >>> if (PTR_ERR(iommu) == -EPROBE_DEFER) {
> >>> kfree(map);
> >>> + dev->dma_range_map = NULL;
> >>
> >> Not really going to matter, but you should probably clear dma_range_map
> >> before what it points to is freed.
> >>
> >> With that,
> >>
> >> Reviewed-by: Rob Herring <[email protected]>
> >
> > Thanks for the review. I will move it before "kfree(map)" in next
> > version.
>
> Paul noticed that we already have a bug in assigning to this
> unconditionally[1] - I'd totally forgotten about this series when I
> theorised about IOMMU drivers wanting the information earlier, but
> sweeping my inbox now only goes to show I was right to think of it :)
>
> We should really get something in as a fix independent of this series,
> taking both angles into account.
Thanks this info. Following your suggestion, Move this into the "if (!
ret)". Then it is like this:
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -163,8 +163,10 @@ int of_dma_configure_id(struct device *dev, struct
device_node *np,
dev->coherent_dma_mask &= mask;
*dev->dma_mask &= mask;
/* ...but only set bus limit if we found valid dma-ranges earlier */
- if (!ret)
+ if (!ret) {
dev->bus_dma_limit = end;
+ dev->dma_range_map = map;
+ }
coherent = of_dma_is_coherent(np);
dev_dbg(dev, "device is%sdma coherent\n",
@@ -172,6 +174,8 @@ int of_dma_configure_id(struct device *dev, struct
device_node *np,
iommu = of_iommu_configure(dev, np, id);
if (PTR_ERR(iommu) == -EPROBE_DEFER) {
+ if (!ret)
+ dev->dma_range_map = NULL;
kfree(map);
return -EPROBE_DEFER;
}
@@ -181,7 +185,6 @@ int of_dma_configure_id(struct device *dev, struct
device_node *np,
arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
- dev->dma_range_map = map;
return 0;
}
EXPORT_SYMBOL_GPL(of_dma_configure_id);
If this is ok, I will send this as a independent patch.
>
> Robin.
>
> [1]
> https://lore.kernel.org/linux-arm-kernel/[email protected]/
>
> >>
> >>> return -EPROBE_DEFER;
> >>> }
> >>>
> >>> @@ -181,7 +183,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> >>>
> >>> arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
> >>>
> >>> - dev->dma_range_map = map;
> >>> return 0;
> >>> }
> >>> EXPORT_SYMBOL_GPL(of_dma_configure_id);
> >>> --
> >>> 2.18.0
> >>>
> >
> > _______________________________________________
> > iommu mailing list
> > [email protected]
> > https://lists.linuxfoundation.org/mailman/listinfo/iommu
> >
Hi,
On Tue 19 Jan 21, 17:20, Yong Wu wrote:
> On Mon, 2021-01-18 at 15:49 +0000, Robin Murphy wrote:
> > On 2021-01-15 05:30, Yong Wu wrote:
> > > On Thu, 2021-01-14 at 13:27 -0600, Rob Herring wrote:
> > >> On Mon, Jan 11, 2021 at 07:18:47PM +0800, Yong Wu wrote:
> > >>> "dev->dma_range_map" contains the devices' dma_ranges information,
> > >>> This patch moves dma_range_map before of_iommu_configure. The iommu
> > >>> driver may need to know the dma_address requirements of its iommu
> > >>> consumer devices.
> > >>>
> > >>> CC: Rob Herring <[email protected]>
> > >>> CC: Frank Rowand <[email protected]>
> > >>> Signed-off-by: Yong Wu <[email protected]>
> > >>> ---
> > >>> drivers/of/device.c | 3 ++-
> > >>> 1 file changed, 2 insertions(+), 1 deletion(-)
> > >>>
> > >>> diff --git a/drivers/of/device.c b/drivers/of/device.c
> > >>> index aedfaaafd3e7..1d84636149df 100644
> > >>> --- a/drivers/of/device.c
> > >>> +++ b/drivers/of/device.c
> > >>> @@ -170,9 +170,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> > >>> dev_dbg(dev, "device is%sdma coherent\n",
> > >>> coherent ? " " : " not ");
> > >>>
> > >>> + dev->dma_range_map = map;
> > >>> iommu = of_iommu_configure(dev, np, id);
> > >>> if (PTR_ERR(iommu) == -EPROBE_DEFER) {
> > >>> kfree(map);
> > >>> + dev->dma_range_map = NULL;
> > >>
> > >> Not really going to matter, but you should probably clear dma_range_map
> > >> before what it points to is freed.
> > >>
> > >> With that,
> > >>
> > >> Reviewed-by: Rob Herring <[email protected]>
> > >
> > > Thanks for the review. I will move it before "kfree(map)" in next
> > > version.
> >
> > Paul noticed that we already have a bug in assigning to this
> > unconditionally[1] - I'd totally forgotten about this series when I
> > theorised about IOMMU drivers wanting the information earlier, but
> > sweeping my inbox now only goes to show I was right to think of it :)
> >
> > We should really get something in as a fix independent of this series,
> > taking both angles into account.
>
> Thanks this info. Following your suggestion, Move this into the "if (!
> ret)". Then it is like this:
Thanks for preparing the change :)
>
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -163,8 +163,10 @@ int of_dma_configure_id(struct device *dev, struct
> device_node *np,
> dev->coherent_dma_mask &= mask;
> *dev->dma_mask &= mask;
> /* ...but only set bus limit if we found valid dma-ranges earlier */
Maybe the comment would need some update too, like:
/* ...but only set bus limit and map if we found valid dma-ranges earlier */
> - if (!ret)
> + if (!ret) {
> dev->bus_dma_limit = end;
> + dev->dma_range_map = map;
> + }
>
> coherent = of_dma_is_coherent(np);
> dev_dbg(dev, "device is%sdma coherent\n",
> @@ -172,6 +174,8 @@ int of_dma_configure_id(struct device *dev, struct
> device_node *np,
>
> iommu = of_iommu_configure(dev, np, id);
> if (PTR_ERR(iommu) == -EPROBE_DEFER) {
And maybe one here, something like:
/* don't touch range map if it wasn't set from a valid dma-ranges */
> + if (!ret)
> + dev->dma_range_map = NULL;
> kfree(map);
> return -EPROBE_DEFER;
> }
> @@ -181,7 +185,6 @@ int of_dma_configure_id(struct device *dev, struct
> device_node *np,
>
> arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
>
> - dev->dma_range_map = map;
> return 0;
> }
> EXPORT_SYMBOL_GPL(of_dma_configure_id);
>
>
> If this is ok, I will send this as a independent patch.
With the suggested changes, this looks good to me!
Thanks,
Paul
> >
> > Robin.
> >
> > [1]
> > https://lore.kernel.org/linux-arm-kernel/[email protected]/
> >
> > >>
> > >>> return -EPROBE_DEFER;
> > >>> }
> > >>>
> > >>> @@ -181,7 +183,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> > >>>
> > >>> arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
> > >>>
> > >>> - dev->dma_range_map = map;
> > >>> return 0;
> > >>> }
> > >>> EXPORT_SYMBOL_GPL(of_dma_configure_id);
> > >>> --
> > >>> 2.18.0
> > >>>
> > >
> > > _______________________________________________
> > > iommu mailing list
> > > [email protected]
> > > https://lists.linuxfoundation.org/mailman/listinfo/iommu
> > >
>
--
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com