public inbox for kernelnewbies@kernelnewbies.org
 help / color / mirror / Atom feed
* unmap memory mapped with devm_ioremap_resource
@ 2022-12-02 17:24 Adrian Fiergolski
  2022-12-02 18:01 ` Constantine Shulyupin
  0 siblings, 1 reply; 8+ messages in thread
From: Adrian Fiergolski @ 2022-12-02 17:24 UTC (permalink / raw)
  To: kernelnewbies

Hello,

I am extending xilinx-hls driver 
(https://github.com/Xilinx/linux-xlnx/blob/master/drivers/media/platform/xilinx/xilinx-hls.c) 
to support of_overlay.

In order to reflect in the driver changes being applied by the overlay 
to the device tree, I need to unmap first the memory mapped with 
devm_ioremap_resource. How to do it properly?

I think it's uncommon, as normally kernel (devm_* functions) manages 
those resources itself with devres, so I can't find inspiration in other 
drivers.

Regards,
Adrian



_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: unmap memory mapped with devm_ioremap_resource
  2022-12-02 17:24 unmap memory mapped with devm_ioremap_resource Adrian Fiergolski
@ 2022-12-02 18:01 ` Constantine Shulyupin
  2022-12-06 21:23   ` Adrian Fiergolski
  0 siblings, 1 reply; 8+ messages in thread
From: Constantine Shulyupin @ 2022-12-02 18:01 UTC (permalink / raw)
  To: Adrian Fiergolski; +Cc: kernelnewbies

Hi,

I suppose you are looking for `devm_iounmap`.
You can find example of usage in `drivers/fpga/dfl.c`:

...
                        feature->ioaddr =
                               devm_ioremap_resource(binfo->dev,
                                                     &finfo->mmio_res);
...

static void build_info_complete(struct build_feature_devs_info *binfo)
{
       devm_iounmap(binfo->dev, binfo->ioaddr);
       devm_release_mem_region(binfo->dev, binfo->start, binfo->len);
}

Regards,
Costa


On Fri, 2 Dec 2022 at 19:25, Adrian Fiergolski
<adrian.fiergolski@fastree3d.com> wrote:
>
> Hello,
>
> I am extending xilinx-hls driver
> (https://github.com/Xilinx/linux-xlnx/blob/master/drivers/media/platform/xilinx/xilinx-hls.c)
> to support of_overlay.
>
> In order to reflect in the driver changes being applied by the overlay
> to the device tree, I need to unmap first the memory mapped with
> devm_ioremap_resource. How to do it properly?
>
> I think it's uncommon, as normally kernel (devm_* functions) manages
> those resources itself with devres, so I can't find inspiration in other
> drivers.
>
> Regards,
> Adrian
>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



-- 
Constantine Shulyupin

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: unmap memory mapped with devm_ioremap_resource
  2022-12-02 18:01 ` Constantine Shulyupin
@ 2022-12-06 21:23   ` Adrian Fiergolski
  2022-12-09 16:14     ` Adrian Fiergolski
  0 siblings, 1 reply; 8+ messages in thread
From: Adrian Fiergolski @ 2022-12-06 21:23 UTC (permalink / raw)
  To: Constantine Shulyupin; +Cc: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 2170 bytes --]

Hi Costa,

Thank you for your reply.

I saw 'devm_iounmap' , but, correct me if I am wrong, I think is not 
enough.

devm_ioremap_resource calls __devm_ioremap_resource (link 
<https://elixir.bootlin.com/linux/v5.10.157/source/lib/devres.c#L117>) 
which calls eventually __devm_request_region (link 
<https://elixir.bootlin.com/linux/v5.10.157/source/kernel/resource.c#L1520>) 
and __devm_ioremap (link 
<https://elixir.bootlin.com/linux/v5.10.157/source/lib/devres.c#L25>). 
Those two will allocate 2 devres: devm_region_release and 
devm_ioremap_release.

The proposed devm_iounmap (link 
<https://elixir.bootlin.com/linux/v5.10.157/source/lib/devres.c#L108>) 
seems to destroy only devm_ioremap_release devres.

Regards,
Adrian

On 2.12.2022 19:01, Constantine Shulyupin wrote:
> Hi,
>
> I suppose you are looking for `devm_iounmap`.
> You can find example of usage in `drivers/fpga/dfl.c`:
>
> ...
>                          feature->ioaddr =
>                                 devm_ioremap_resource(binfo->dev,
>                                                       &finfo->mmio_res);
> ...
>
> static void build_info_complete(struct build_feature_devs_info *binfo)
> {
>         devm_iounmap(binfo->dev, binfo->ioaddr);
>         devm_release_mem_region(binfo->dev, binfo->start, binfo->len);
> }
>
> Regards,
> Costa
>
>
> On Fri, 2 Dec 2022 at 19:25, Adrian Fiergolski
> <adrian.fiergolski@fastree3d.com>  wrote:
>> Hello,
>>
>> I am extending xilinx-hls driver
>> (https://github.com/Xilinx/linux-xlnx/blob/master/drivers/media/platform/xilinx/xilinx-hls.c)
>> to support of_overlay.
>>
>> In order to reflect in the driver changes being applied by the overlay
>> to the device tree, I need to unmap first the memory mapped with
>> devm_ioremap_resource. How to do it properly?
>>
>> I think it's uncommon, as normally kernel (devm_* functions) manages
>> those resources itself with devres, so I can't find inspiration in other
>> drivers.
>>
>> Regards,
>> Adrian
>>
>>
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies@kernelnewbies.org
>> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>

[-- Attachment #1.2: Type: text/html, Size: 3281 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: unmap memory mapped with devm_ioremap_resource
  2022-12-06 21:23   ` Adrian Fiergolski
@ 2022-12-09 16:14     ` Adrian Fiergolski
  2022-12-09 19:58       ` jim.cromie
  0 siblings, 1 reply; 8+ messages in thread
From: Adrian Fiergolski @ 2022-12-09 16:14 UTC (permalink / raw)
  To: Constantine Shulyupin; +Cc: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 2410 bytes --]

Hi,

Does the community have any other ideas? Or I am wrong, and devm_iounmap 
is enough?

Regards,
Adrian

On 6.12.2022 22:23, Adrian Fiergolski wrote:
>
> Hi Costa,
>
> Thank you for your reply.
>
> I saw 'devm_iounmap' , but, correct me if I am wrong, I think is not 
> enough.
>
> devm_ioremap_resource calls __devm_ioremap_resource (link 
> <https://elixir.bootlin.com/linux/v5.10.157/source/lib/devres.c#L117>) 
> which calls eventually __devm_request_region (link 
> <https://elixir.bootlin.com/linux/v5.10.157/source/kernel/resource.c#L1520>) 
> and __devm_ioremap (link 
> <https://elixir.bootlin.com/linux/v5.10.157/source/lib/devres.c#L25>). 
> Those two will allocate 2 devres: devm_region_release and 
> devm_ioremap_release.
>
> The proposed devm_iounmap (link 
> <https://elixir.bootlin.com/linux/v5.10.157/source/lib/devres.c#L108>) 
> seems to destroy only devm_ioremap_release devres.
>
> Regards,
> Adrian
>
> On 2.12.2022 19:01, Constantine Shulyupin wrote:
>> Hi,
>>
>> I suppose you are looking for `devm_iounmap`.
>> You can find example of usage in `drivers/fpga/dfl.c`:
>>
>> ...
>>                          feature->ioaddr =
>>                                 devm_ioremap_resource(binfo->dev,
>>                                                       &finfo->mmio_res);
>> ...
>>
>> static void build_info_complete(struct build_feature_devs_info *binfo)
>> {
>>         devm_iounmap(binfo->dev, binfo->ioaddr);
>>         devm_release_mem_region(binfo->dev, binfo->start, binfo->len);
>> }
>>
>> Regards,
>> Costa
>>
>>
>> On Fri, 2 Dec 2022 at 19:25, Adrian Fiergolski
>> <adrian.fiergolski@fastree3d.com>  wrote:
>>> Hello,
>>>
>>> I am extending xilinx-hls driver
>>> (https://github.com/Xilinx/linux-xlnx/blob/master/drivers/media/platform/xilinx/xilinx-hls.c)
>>> to support of_overlay.
>>>
>>> In order to reflect in the driver changes being applied by the overlay
>>> to the device tree, I need to unmap first the memory mapped with
>>> devm_ioremap_resource. How to do it properly?
>>>
>>> I think it's uncommon, as normally kernel (devm_* functions) manages
>>> those resources itself with devres, so I can't find inspiration in other
>>> drivers.
>>>
>>> Regards,
>>> Adrian
>>>
>>>
>>>
>>> _______________________________________________
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.org
>>> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[-- Attachment #1.2: Type: text/html, Size: 3855 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: unmap memory mapped with devm_ioremap_resource
  2022-12-09 16:14     ` Adrian Fiergolski
@ 2022-12-09 19:58       ` jim.cromie
  2022-12-09 20:35         ` Valdis Klētnieks
  0 siblings, 1 reply; 8+ messages in thread
From: jim.cromie @ 2022-12-09 19:58 UTC (permalink / raw)
  To: Adrian Fiergolski; +Cc: Constantine Shulyupin, kernelnewbies

On Fri, Dec 9, 2022 at 9:14 AM Adrian Fiergolski
<adrian.fiergolski@fastree3d.com> wrote:
>
> Hi,
>
> Does the community have any other ideas? Or I am wrong, and devm_iounmap is enough?
>

I dunno, but it says you asked ~4 hrs ago.
I bet you could just try it and get an answer faster.
Do feel free to report back.

> Regards,
> Adrian
>
> On 6.12.2022 22:23, Adrian Fiergolski wrote:
>
> Hi Costa,
>
> Thank you for your reply.
>
> I saw 'devm_iounmap' , but, correct me if I am wrong, I think is not enough.
>
> devm_ioremap_resource calls __devm_ioremap_resource (link) which calls eventually __devm_request_region (link) and __devm_ioremap (link). Those two will allocate 2 devres: devm_region_release and devm_ioremap_release.
>
> The proposed devm_iounmap (link) seems to destroy only devm_ioremap_release devres.
>
> Regards,
> Adrian
>
> On 2.12.2022 19:01, Constantine Shulyupin wrote:
>
> Hi,
>
> I suppose you are looking for `devm_iounmap`.
> You can find example of usage in `drivers/fpga/dfl.c`:
>
> ...
>                         feature->ioaddr =
>                                devm_ioremap_resource(binfo->dev,
>                                                      &finfo->mmio_res);
> ...
>
> static void build_info_complete(struct build_feature_devs_info *binfo)
> {
>        devm_iounmap(binfo->dev, binfo->ioaddr);
>        devm_release_mem_region(binfo->dev, binfo->start, binfo->len);
> }
>
> Regards,
> Costa
>
>
> On Fri, 2 Dec 2022 at 19:25, Adrian Fiergolski
> <adrian.fiergolski@fastree3d.com> wrote:
>
> Hello,
>
> I am extending xilinx-hls driver
> (https://github.com/Xilinx/linux-xlnx/blob/master/drivers/media/platform/xilinx/xilinx-hls.c)
> to support of_overlay.
>
> In order to reflect in the driver changes being applied by the overlay
> to the device tree, I need to unmap first the memory mapped with
> devm_ioremap_resource. How to do it properly?
>
> I think it's uncommon, as normally kernel (devm_* functions) manages
> those resources itself with devres, so I can't find inspiration in other
> drivers.
>
> Regards,
> Adrian
>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: unmap memory mapped with devm_ioremap_resource
  2022-12-09 19:58       ` jim.cromie
@ 2022-12-09 20:35         ` Valdis Klētnieks
  2022-12-09 22:52           ` Adrian Fiergolski
  0 siblings, 1 reply; 8+ messages in thread
From: Valdis Klētnieks @ 2022-12-09 20:35 UTC (permalink / raw)
  To: jim.cromie; +Cc: Constantine Shulyupin, kernelnewbies, Adrian Fiergolski


[-- Attachment #1.1: Type: text/plain, Size: 892 bytes --]

On Fri, 09 Dec 2022 12:58:20 -0700, jim.cromie@gmail.com said:
> On Fri, Dec 9, 2022 at 9:14 AM Adrian Fiergolski <adrian.fiergolski@fastree3d.com> wrote:
> > Does the community have any other ideas? Or I am wrong, and devm_iounmap is enough?

> I dunno, but it says you asked ~4 hrs ago.
> I bet you could just try it and get an answer faster.
> Do feel free to report back.

Note that it *is* possible for something to *look* like it works, but it leaves
dangling pointers or other hidden corruption that takes a while to surface.  I
once had to troubleshoot a userspace bug that worked fine on one system but
blew up on another with a different malloc() - some 6 million malloc calls
after the bug hit.

Fortunately, the vast majority of kernel functions will return an error code if
anything at all fishy happened, so just checking return codes on *everything* is
usually good enough...


[-- Attachment #1.2: Type: application/pgp-signature, Size: 494 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: unmap memory mapped with devm_ioremap_resource
  2022-12-09 20:35         ` Valdis Klētnieks
@ 2022-12-09 22:52           ` Adrian Fiergolski
  2022-12-10  6:53             ` Constantine Shulyupin
  0 siblings, 1 reply; 8+ messages in thread
From: Adrian Fiergolski @ 2022-12-09 22:52 UTC (permalink / raw)
  To: Valdis Klētnieks, jim.cromie; +Cc: Constantine Shulyupin, kernelnewbies

Hi,

I checked the kernel source code and, as I wrote, in my opinion, the 
proposed devm_iounmap doesn't seem to release all resources allocated 
with devm_ioremap_resource. Thus, I don't see a point in testing it, and 
I am still looking for the proper solution.

Jim, the original question is more than a week old.

Regards,
Adrian

On 9.12.2022 at 21:35, Valdis Klētnieks wrote:
> On Fri, 09 Dec 2022 12:58:20 -0700, jim.cromie@gmail.com said:
>> On Fri, Dec 9, 2022 at 9:14 AM Adrian Fiergolski <adrian.fiergolski@fastree3d.com> wrote:
>>> Does the community have any other ideas? Or I am wrong, and devm_iounmap is enough?
>> I dunno, but it says you asked ~4 hrs ago.
>> I bet you could just try it and get an answer faster.
>> Do feel free to report back.
> Note that it *is* possible for something to *look* like it works, but it leaves
> dangling pointers or other hidden corruption that takes a while to surface.  I
> once had to troubleshoot a userspace bug that worked fine on one system but
> blew up on another with a different malloc() - some 6 million malloc calls
> after the bug hit.
>
> Fortunately, the vast majority of kernel functions will return an error code if
> anything at all fishy happened, so just checking return codes on *everything* is
> usually good enough...
>

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: unmap memory mapped with devm_ioremap_resource
  2022-12-09 22:52           ` Adrian Fiergolski
@ 2022-12-10  6:53             ` Constantine Shulyupin
  0 siblings, 0 replies; 8+ messages in thread
From: Constantine Shulyupin @ 2022-12-10  6:53 UTC (permalink / raw)
  To: Adrian Fiergolski; +Cc: jim.cromie, Valdis Klētnieks, kernelnewbies

It looks like the proper solution is to use two functions:
devm_iounmap and devm_release_mem_region. There are a lot of examples
in the kernel.

Regards,
Costa

On Sat, 10 Dec 2022 at 00:52, Adrian Fiergolski
<adrian.fiergolski@fastree3d.com> wrote:
>
> Hi,
>
> I checked the kernel source code and, as I wrote, in my opinion, the
> proposed devm_iounmap doesn't seem to release all resources allocated
> with devm_ioremap_resource. Thus, I don't see a point in testing it, and
> I am still looking for the proper solution.
>
> Jim, the original question is more than a week old.
>
> Regards,
> Adrian
>
> On 9.12.2022 at 21:35, Valdis Klētnieks wrote:
> > On Fri, 09 Dec 2022 12:58:20 -0700, jim.cromie@gmail.com said:
> >> On Fri, Dec 9, 2022 at 9:14 AM Adrian Fiergolski <adrian.fiergolski@fastree3d.com> wrote:
> >>> Does the community have any other ideas? Or I am wrong, and devm_iounmap is enough?
> >> I dunno, but it says you asked ~4 hrs ago.
> >> I bet you could just try it and get an answer faster.
> >> Do feel free to report back.
> > Note that it *is* possible for something to *look* like it works, but it leaves
> > dangling pointers or other hidden corruption that takes a while to surface.  I
> > once had to troubleshoot a userspace bug that worked fine on one system but
> > blew up on another with a different malloc() - some 6 million malloc calls
> > after the bug hit.
> >
> > Fortunately, the vast majority of kernel functions will return an error code if
> > anything at all fishy happened, so just checking return codes on *everything* is
> > usually good enough...
> >



-- 
Constantine Shulyupin

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

end of thread, other threads:[~2022-12-10  6:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-02 17:24 unmap memory mapped with devm_ioremap_resource Adrian Fiergolski
2022-12-02 18:01 ` Constantine Shulyupin
2022-12-06 21:23   ` Adrian Fiergolski
2022-12-09 16:14     ` Adrian Fiergolski
2022-12-09 19:58       ` jim.cromie
2022-12-09 20:35         ` Valdis Klētnieks
2022-12-09 22:52           ` Adrian Fiergolski
2022-12-10  6:53             ` Constantine Shulyupin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox