Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1451770 > unrolled thread
| Started by | Daniel Wagner <wagi@monom.org> |
|---|---|
| First post | 2016-07-28 10:00 +0200 |
| Last post | 2016-07-28 10:00 +0200 |
| Articles | 20 on this page of 47 — 8 participants |
Back to article view | Back to linux.kernel
[RFC v0 0/8] Reuse firmware loader helpers Daniel Wagner <wagi@monom.org> - 2016-07-28 10:00 +0200
[RFC v0 8/8] iwl4965: use firmware_stat instead of completion Daniel Wagner <wagi@monom.org> - 2016-07-28 10:00 +0200
[RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Daniel Wagner <wagi@monom.org> - 2016-07-28 10:00 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-07-28 20:40 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Bjorn Andersson <bjorn.andersson@linaro.org> - 2016-07-28 21:10 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Daniel Wagner <daniel.wagner@bmw-carit.de> - 2016-07-29 08:20 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Arend van Spriel <arend.vanspriel@broadcom.com> - 2016-07-30 14:50 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-07-30 19:00 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-07-31 09:30 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Daniel Wagner <daniel.wagner@bmw-carit.de> - 2016-08-01 14:40 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-08-02 00:40 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Daniel Wagner <daniel.wagner@bmw-carit.de> - 2016-08-02 08:00 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-08-02 08:40 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Daniel Wagner <daniel.wagner@bmw-carit.de> - 2016-08-02 09:00 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-08-02 10:00 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Daniel Wagner <daniel.wagner@bmw-carit.de> - 2016-08-03 09:10 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-08-03 18:20 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-08-03 20:20 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-08-03 18:50 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-08-03 20:50 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Bjorn Andersson <bjorn.andersson@linaro.org> - 2016-08-04 00:40 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-08-03 09:50 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Arend van Spriel <arend.vanspriel@broadcom.com> - 2016-08-03 13:50 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-08-03 17:20 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-08-03 17:40 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Arend van Spriel <arend.vanspriel@broadcom.com> - 2016-08-03 23:00 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-08-03 18:10 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Bjorn Andersson <bjorn.andersson@linaro.org> - 2016-08-03 19:50 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-08-03 22:40 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-08-01 22:20 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Bjorn Andersson <bjorn.andersson@linaro.org> - 2016-08-01 19:30 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-08-01 22:20 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-08-01 23:50 +0200
Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-07-31 09:20 +0200
[RFC v0 2/8] selftests: firmware: do not clutter output Daniel Wagner <wagi@monom.org> - 2016-07-28 10:00 +0200
[RFC v0 6/8] remoteproc: use firmware_stat instead of completion Daniel Wagner <wagi@monom.org> - 2016-07-28 10:00 +0200
[RFC v0 3/8] firmware: Factor out firmware load helpers Daniel Wagner <wagi@monom.org> - 2016-07-28 10:00 +0200
Re: [RFC v0 3/8] firmware: Factor out firmware load helpers Dan Williams <dcbw@redhat.com> - 2016-07-28 17:10 +0200
Re: [RFC v0 3/8] firmware: Factor out firmware load helpers Daniel Wagner <daniel.wagner@bmw-carit.de> - 2016-07-29 08:10 +0200
Re: [RFC v0 3/8] firmware: Factor out firmware load helpers Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-07-28 20:00 +0200
Re: [RFC v0 3/8] firmware: Factor out firmware load helpers Daniel Wagner <daniel.wagner@bmw-carit.de> - 2016-07-29 08:10 +0200
[RFC v0 4/8] Input: goodix: use firmware_stat instead of completion Daniel Wagner <wagi@monom.org> - 2016-07-28 10:00 +0200
Re: [RFC v0 4/8] Input: goodix: use firmware_stat instead of completion Bastien Nocera <hadess@hadess.net> - 2016-07-28 13:30 +0200
Re: [RFC v0 4/8] Input: goodix: use firmware_stat instead of completion Daniel Wagner <daniel.wagner@bmw-carit.de> - 2016-07-28 14:10 +0200
Re: [RFC v0 4/8] Input: goodix: use firmware_stat instead of completion Bastien Nocera <hadess@hadess.net> - 2016-07-28 14:30 +0200
Re: [RFC v0 4/8] Input: goodix: use firmware_stat instead of completion Daniel Wagner <daniel.wagner@bmw-carit.de> - 2016-07-28 15:20 +0200
[RFC v0 1/8] selftests: firmware: do not abort test too early Daniel Wagner <wagi@monom.org> - 2016-07-28 10:00 +0200
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
| From | Bjorn Andersson <bjorn.andersson@linaro.org> |
|---|---|
| Date | 2016-08-04 00:40 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s2cZs-dY-49@gated-at.bofh.it> |
| In reply to | #1455894 |
On Wed 03 Aug 08:55 PDT 2016, Luis R. Rodriguez wrote: > On Wed, Aug 03, 2016 at 08:57:09AM +0200, Daniel Wagner wrote: > > On 08/02/2016 09:41 AM, Luis R. Rodriguez wrote: [..] > > Not sure if I get you here correctly. Is the 'system configurable > > deterministic file' is a knob which controlled by user space? Or it > > this something you define at compile time? > > I meant at compile time on the kernel. So CONFIG_READ_READY_SENTINEL > or something like this, and it be a string, which if set then when > the kernel read APIs are used, then a new API could be introduced > that would *only* enable reading through once that sentinel has > been detected by the kernel to allowed through reads. Doing this > per mount / target filesystem is rather cumbersome given possible > overlaps in mounts and also pivot_root() being possible, so instead > targeting simply the fs/exec.c enum kernel_read_file_id would seem > more efficient and clean but we would need a decided upon set of > paths per enum kernel_read_file_id as base (or just one path per > enum kernel_read_file_id). For number of paths I mean the number > of target directories to look for the sentinel per enum kernel_read_file_id, > so for instance for READING_FIRMWARE perhaps just deciding on /lib/firmware/ > would suffice, but if this supported multiple paths another option may be > for the sentinel to also be looked for in /lib/firmware/updates/, > /lib/firmware/" UTS_RELEASE -- etc. It would *stop* after finding one > sentinel on any of these paths. > > If a system has has CONFIG_READ_READY_SENTINEL it would mean an agreed upon > system configuration has been decided so that at any point in time reads > against READING_FIRMWARE using a new kernel_read_file_from_path_sentinel() > (or something like it) would only allow the read to go through once > the sentinel has been found for READING_FIRMWARE on the agreed upon > paths. > > The benefit of the sentintel approach is it avoids complexities with > pivot_root(), and makes the deterministic aspect of the target left > only to a system-configuration enabled target path / file. > This sounds reasonable, it could be configured to wait for a certain static file or userspace could generate this file once it reaches some checkpoint. Just to provide some additional input to "will rootfs mounted be enough of a sentinel". In an Android device you have a initramfs that will read an fstab file and mount /system that holds most firmware, for some platforms additional firmware will come from a third partition (in the Qualcomm case mounted in /persist by the same mechanism). With the sentinel approach one could configure the system either point it at a file in the last file system to be mounted or have init generate a file once its done with this; or in the generic configuration just wait for /lib/firmware to show up. I like this approach. > This is just an idea. I'd like some FS folks to review. > Regards, Bjorn
[toc] | [prev] | [next] | [standalone]
| From | Dmitry Torokhov <dmitry.torokhov@gmail.com> |
|---|---|
| Date | 2016-08-03 09:50 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s1Z6a-863-9@gated-at.bofh.it> |
| In reply to | #1453647 |
On Tue, Aug 2, 2016 at 12:41 AM, Luis R. Rodriguez <mcgrof@kernel.org> wrote: > On Tue, Aug 02, 2016 at 08:53:55AM +0200, Daniel Wagner wrote: >> On 08/02/2016 08:34 AM, Luis R. Rodriguez wrote: >> >On Tue, Aug 02, 2016 at 07:49:19AM +0200, Daniel Wagner wrote: >> >>>The sysdata API's main goal rather is to provide a flexible API first, >> >>>compartamentalizing the usermode helper was secondary. But now it seems >> >>>I may just also add devm support too to help simplify code further. >> >> >> >>I missed the point that you plan to add usermode helper support to >> >>the sysdata API. >> > >> >I had no such plans, when I have asked folks so far about "hey are you >> >really in need for it, OK what for? " and "what extended uses do you >> >envision?" so I far I have not gotten any replies at all. So -- instead >> >sysdata currently ignores it. >> >> So you argue for the remoteproc use case with 100+ MB firmware that >> if there is a way to load after pivot_root() (or other additional >> firmware partition shows up) then there is no need at all for >> usermode helper? > > No, I'm saying I'd like to hear valid uses cases for the usermode helper and so > far I have only found using coccinelle grammar 2 explicit users, that's it. My > patch series (not yet merge) then annotates these as valid as I've verified > through their documentation they have some quirky requirement. In certain configurations (embedded) people do not want to use initramfs nor modules nor embed firmware into the kernel. In this case usermode helper + firmware calss timeout handling provides necessary wait for the root filesystem to be mounted. If we solve waiting for rootfs (or something else that may contain firmware) then these cases will not need to use usermode helper. Thanks. -- Dmitry
[toc] | [prev] | [next] | [standalone]
| From | Arend van Spriel <arend.vanspriel@broadcom.com> |
|---|---|
| Date | 2016-08-03 13:50 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s22Qp-20X-11@gated-at.bofh.it> |
| In reply to | #1455666 |
On 03-08-16 09:42, Dmitry Torokhov wrote: > On Tue, Aug 2, 2016 at 12:41 AM, Luis R. Rodriguez <mcgrof@kernel.org> wrote: >> On Tue, Aug 02, 2016 at 08:53:55AM +0200, Daniel Wagner wrote: >>> On 08/02/2016 08:34 AM, Luis R. Rodriguez wrote: >>>> On Tue, Aug 02, 2016 at 07:49:19AM +0200, Daniel Wagner wrote: >>>>>> The sysdata API's main goal rather is to provide a flexible API first, >>>>>> compartamentalizing the usermode helper was secondary. But now it seems >>>>>> I may just also add devm support too to help simplify code further. >>>>> >>>>> I missed the point that you plan to add usermode helper support to >>>>> the sysdata API. >>>> >>>> I had no such plans, when I have asked folks so far about "hey are you >>>> really in need for it, OK what for? " and "what extended uses do you >>>> envision?" so I far I have not gotten any replies at all. So -- instead >>>> sysdata currently ignores it. >>> >>> So you argue for the remoteproc use case with 100+ MB firmware that >>> if there is a way to load after pivot_root() (or other additional >>> firmware partition shows up) then there is no need at all for >>> usermode helper? >> >> No, I'm saying I'd like to hear valid uses cases for the usermode helper and so >> far I have only found using coccinelle grammar 2 explicit users, that's it. My >> patch series (not yet merge) then annotates these as valid as I've verified >> through their documentation they have some quirky requirement. > > In certain configurations (embedded) people do not want to use > initramfs nor modules nor embed firmware into the kernel. In this case > usermode helper + firmware calss timeout handling provides necessary > wait for the root filesystem to be mounted. And there are people who don't have a usermode helper running at all in their configuration, but I guess they should disable the helper. In my opinion the kernel should provide functionality to user-space and user-space providing functionality to the kernel should be avoided. > If we solve waiting for rootfs (or something else that may contain > firmware) then these cases will not need to use usermode helper. If firmware (or whatever) API could get notification of mount syscall it could be used to retry firmware loading instead of periodic polling. That leaves the question raised by you about when to stop trying. The initlevel stuff is probably a user-space only concept, right? So no ideas how the kernel itself could decide except for a "long" timeout. Regards, Arend
[toc] | [prev] | [next] | [standalone]
| From | "Luis R. Rodriguez" <mcgrof@kernel.org> |
|---|---|
| Date | 2016-08-03 17:20 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s267E-4aR-37@gated-at.bofh.it> |
| In reply to | #1455752 |
On Wed, Aug 03, 2016 at 01:43:31PM +0200, Arend van Spriel wrote: > On 03-08-16 09:42, Dmitry Torokhov wrote: > > On Tue, Aug 2, 2016 at 12:41 AM, Luis R. Rodriguez <mcgrof@kernel.org> wrote: > >> On Tue, Aug 02, 2016 at 08:53:55AM +0200, Daniel Wagner wrote: > >>> On 08/02/2016 08:34 AM, Luis R. Rodriguez wrote: > >>>> On Tue, Aug 02, 2016 at 07:49:19AM +0200, Daniel Wagner wrote: > >>>>>> The sysdata API's main goal rather is to provide a flexible API first, > >>>>>> compartamentalizing the usermode helper was secondary. But now it seems > >>>>>> I may just also add devm support too to help simplify code further. > >>>>> > >>>>> I missed the point that you plan to add usermode helper support to > >>>>> the sysdata API. > >>>> > >>>> I had no such plans, when I have asked folks so far about "hey are you > >>>> really in need for it, OK what for? " and "what extended uses do you > >>>> envision?" so I far I have not gotten any replies at all. So -- instead > >>>> sysdata currently ignores it. > >>> > >>> So you argue for the remoteproc use case with 100+ MB firmware that > >>> if there is a way to load after pivot_root() (or other additional > >>> firmware partition shows up) then there is no need at all for > >>> usermode helper? > >> > >> No, I'm saying I'd like to hear valid uses cases for the usermode helper and so > >> far I have only found using coccinelle grammar 2 explicit users, that's it. My > >> patch series (not yet merge) then annotates these as valid as I've verified > >> through their documentation they have some quirky requirement. > > > > In certain configurations (embedded) people do not want to use > > initramfs nor modules nor embed firmware into the kernel. In this case > > usermode helper + firmware calss timeout handling provides necessary > > wait for the root filesystem to be mounted. > > And there are people who don't have a usermode helper running at all Correction: most Linux distributions these days have CONFIG_FW_LOADER_USER_HELPER but disable CONFIG_FW_LOADER_USER_HELPER_FALLBACK. And then let me re-iterate from my patches then the implications: +When CONFIG_FW_LOADER_USER_HELPER_FALLBACK is enabled request_firmware() +*always* calls the usermode helpers. When CONFIG_FW_LOADER_USER_HELPER is +enabled, only if you specifically ask for it will the usermode helper be +called. If CONFIG_FW_LOADER_USER_HELPER_FALLBACK is disabled drivers can +still require the usermode helper by using request_firmware_nowait(). The issues with CONFIG_FW_LOADER_USER_HELPER_FALLBACK are so much so (the kmod timeout was an engineering mishap refer to my post with details about it [0]) that these days most distributions disable it and there have been huge efforts to ensure its not even called explicitly, to the point now we only have TWO explicit users for it. Keep in mind as well that in my series of patches to help clarify the situation with the usermode helper I also proposed a fix to the firmware_class to avoid the usermode helper completely when the firmware cache, this is because the firmware cache purposely *kills* any pending usermode helpers on the way to suspend anyway, so calling a new instance would be an error and just delay suspend further. [0] http://www.do-not-panic.com/2015/12/linux-asynchronous-probe.html > in > their configuration, but I guess they should disable the helper. Yes. I have gone to good lengths to ask why the hell its needed and so far I have not gotten any technical reason for it. > > If we solve waiting for rootfs (or something else that may contain > > firmware) then these cases will not need to use usermode helper. > > If firmware (or whatever) API could get notification of mount syscall it > could be used to retry firmware loading instead of periodic polling. > That leaves the question raised by you about when to stop trying. The > initlevel stuff is probably a user-space only concept, right? No init levels here refer to include/linux/init.h init calls that one wraps the kernel module inits, or subsystem inits. If it wasn't for pivot_root() existing and also the fact that systems can be complex I would have suggested simply that we make firmware_class move to late_initcall() -- this however would not solve all races given how complex systems could be set up with a partition. > So no > ideas how the kernel itself could decide except for a "long" timeout. If we wanted to learn from history -- the timeout for this would be a bad idea so this makes it a bit more complex. I proposed a technical idea here which would avoid this and I think enable making this deterministic as well for new systems that want that. Luis
[toc] | [prev] | [next] | [standalone]
| From | Dmitry Torokhov <dmitry.torokhov@gmail.com> |
|---|---|
| Date | 2016-08-03 17:40 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s26qZ-4iv-5@gated-at.bofh.it> |
| In reply to | #1455752 |
On Wed, Aug 03, 2016 at 01:43:31PM +0200, Arend van Spriel wrote: > On 03-08-16 09:42, Dmitry Torokhov wrote: > > On Tue, Aug 2, 2016 at 12:41 AM, Luis R. Rodriguez <mcgrof@kernel.org> wrote: > >> On Tue, Aug 02, 2016 at 08:53:55AM +0200, Daniel Wagner wrote: > >>> On 08/02/2016 08:34 AM, Luis R. Rodriguez wrote: > >>>> On Tue, Aug 02, 2016 at 07:49:19AM +0200, Daniel Wagner wrote: > >>>>>> The sysdata API's main goal rather is to provide a flexible API first, > >>>>>> compartamentalizing the usermode helper was secondary. But now it seems > >>>>>> I may just also add devm support too to help simplify code further. > >>>>> > >>>>> I missed the point that you plan to add usermode helper support to > >>>>> the sysdata API. > >>>> > >>>> I had no such plans, when I have asked folks so far about "hey are you > >>>> really in need for it, OK what for? " and "what extended uses do you > >>>> envision?" so I far I have not gotten any replies at all. So -- instead > >>>> sysdata currently ignores it. > >>> > >>> So you argue for the remoteproc use case with 100+ MB firmware that > >>> if there is a way to load after pivot_root() (or other additional > >>> firmware partition shows up) then there is no need at all for > >>> usermode helper? > >> > >> No, I'm saying I'd like to hear valid uses cases for the usermode helper and so > >> far I have only found using coccinelle grammar 2 explicit users, that's it. My > >> patch series (not yet merge) then annotates these as valid as I've verified > >> through their documentation they have some quirky requirement. > > > > In certain configurations (embedded) people do not want to use > > initramfs nor modules nor embed firmware into the kernel. In this case > > usermode helper + firmware calss timeout handling provides necessary > > wait for the root filesystem to be mounted. > > And there are people who don't have a usermode helper running at all in > their configuration, but I guess they should disable the helper. Right, if they don't that means their system is misconfigured. > > In my opinion the kernel should provide functionality to user-space and > user-space providing functionality to the kernel should be avoided. Why? We have bunch of stuff running in userspace for the kernel. Fuse for example. I am sure there are more. > > > If we solve waiting for rootfs (or something else that may contain > > firmware) then these cases will not need to use usermode helper. > > If firmware (or whatever) API could get notification of mount syscall it > could be used to retry firmware loading instead of periodic polling. > That leaves the question raised by you about when to stop trying. The > initlevel stuff is probably a user-space only concept, right? So no > ideas how the kernel itself could decide except for a "long" timeout. The kernel really does not know, it can only guess. The firmware may get delivered by motorized carrier pidgeons. But distribution does know how they set up, so they are in position to tell the kernel "go" or "give up". Thanks. -- Dmitry
[toc] | [prev] | [next] | [standalone]
| From | Arend van Spriel <arend.vanspriel@broadcom.com> |
|---|---|
| Date | 2016-08-03 23:00 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s2bqF-7Bn-11@gated-at.bofh.it> |
| In reply to | #1455866 |
On 03-08-16 17:35, Dmitry Torokhov wrote: >> In my opinion the kernel should provide functionality to user-space and >> > user-space providing functionality to the kernel should be avoided. > Why? We have bunch of stuff running in userspace for the kernel. Fuse > for example. I am sure there are more. To me "running in user-space" is not the same as providing functionality, but I see your point given below. >> > >>> > > If we solve waiting for rootfs (or something else that may contain >>> > > firmware) then these cases will not need to use usermode helper. >> > >> > If firmware (or whatever) API could get notification of mount syscall it >> > could be used to retry firmware loading instead of periodic polling. >> > That leaves the question raised by you about when to stop trying. The >> > initlevel stuff is probably a user-space only concept, right? So no >> > ideas how the kernel itself could decide except for a "long" timeout. > The kernel really does not know, it can only guess. The firmware may get > delivered by motorized carrier pidgeons. But distribution does know how > they set up, so they are in position to tell the kernel "go" or "give > up". What distro employs pidgeons. Like to give it a spin ;-) Maybe the latest idea from Luis is a viable option. Regards, Arend
[toc] | [prev] | [next] | [standalone]
| From | "Luis R. Rodriguez" <mcgrof@kernel.org> |
|---|---|
| Date | 2016-08-03 18:10 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s26U1-4HD-3@gated-at.bofh.it> |
| In reply to | #1455666 |
On Wed, Aug 03, 2016 at 12:42:14AM -0700, Dmitry Torokhov wrote: > On Tue, Aug 2, 2016 at 12:41 AM, Luis R. Rodriguez <mcgrof@kernel.org> wrote: > > On Tue, Aug 02, 2016 at 08:53:55AM +0200, Daniel Wagner wrote: > >> On 08/02/2016 08:34 AM, Luis R. Rodriguez wrote: > >> >On Tue, Aug 02, 2016 at 07:49:19AM +0200, Daniel Wagner wrote: > >> >>>The sysdata API's main goal rather is to provide a flexible API first, > >> >>>compartamentalizing the usermode helper was secondary. But now it seems > >> >>>I may just also add devm support too to help simplify code further. > >> >> > >> >>I missed the point that you plan to add usermode helper support to > >> >>the sysdata API. > >> > > >> >I had no such plans, when I have asked folks so far about "hey are you > >> >really in need for it, OK what for? " and "what extended uses do you > >> >envision?" so I far I have not gotten any replies at all. So -- instead > >> >sysdata currently ignores it. > >> > >> So you argue for the remoteproc use case with 100+ MB firmware that > >> if there is a way to load after pivot_root() (or other additional > >> firmware partition shows up) then there is no need at all for > >> usermode helper? > > > > No, I'm saying I'd like to hear valid uses cases for the usermode helper and so > > far I have only found using coccinelle grammar 2 explicit users, that's it. My > > patch series (not yet merge) then annotates these as valid as I've verified > > through their documentation they have some quirky requirement. > > In certain configurations (embedded) people do not want to use > initramfs nor modules nor embed firmware into the kernel. In this case > usermode helper + firmware calss timeout handling provides necessary > wait for the root filesystem to be mounted. > > If we solve waiting for rootfs (or something else that may contain > firmware) then these cases will not need to use usermode helper. Given most distributions already disable FW_LOADER_USER_HELPER_FALLBACK and grammar shows we only have 2 explicit users of the usermode helper I'd prefer if we indeed could just compartamentalize the usermode helper and not rely on it further. Furthermore I think its possible address this issue, and suggested at least one idea how for now. With a bit further review I'm in hope we can address this well, not only for the firmware API but for all other kernel_read_file*() users. Luis
[toc] | [prev] | [next] | [standalone]
| From | Bjorn Andersson <bjorn.andersson@linaro.org> |
|---|---|
| Date | 2016-08-03 19:50 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s28sN-5FV-15@gated-at.bofh.it> |
| In reply to | #1453647 |
On Tue 02 Aug 00:41 PDT 2016, Luis R. Rodriguez wrote: > On Tue, Aug 02, 2016 at 08:53:55AM +0200, Daniel Wagner wrote: > > On 08/02/2016 08:34 AM, Luis R. Rodriguez wrote: > > >On Tue, Aug 02, 2016 at 07:49:19AM +0200, Daniel Wagner wrote: > > >>>The sysdata API's main goal rather is to provide a flexible API first, > > >>>compartamentalizing the usermode helper was secondary. But now it seems > > >>>I may just also add devm support too to help simplify code further. > > >> > > >>I missed the point that you plan to add usermode helper support to > > >>the sysdata API. > > > > > >I had no such plans, when I have asked folks so far about "hey are you > > >really in need for it, OK what for? " and "what extended uses do you > > >envision?" so I far I have not gotten any replies at all. So -- instead > > >sysdata currently ignores it. > > > > So you argue for the remoteproc use case with 100+ MB firmware that > > if there is a way to load after pivot_root() (or other additional > > firmware partition shows up) then there is no need at all for > > usermode helper? > > No, I'm saying I'd like to hear valid uses cases for the usermode helper and so > far I have only found using coccinelle grammar 2 explicit users, that's it. My > patch series (not yet merge) then annotates these as valid as I've verified > through their documentation they have some quirky requirement. > I think we're on the same page, but just to make sure; I do not want the usermode helper, I only want a way to wait for the firmware files to become available. > Other than these two drivers I'd like hear to valid requirements for it. > > The existential issue is a real issue but it does not look impossible to > resolve. It may be a solution to bloat up the kernel with 100+ MB size just to > stuff built-in firmware to avoid this issue, but it does not mean a solution > is not possible. > > Remind me -- why can remoteproc not stuff the firmware in initramfs ? > RAM usage: Storing the files in initramfs would consume 100MB RAM, we would then allocate 100MB RAM for buffers during firmware loading and then we have the reserved 100MB for the peripherals. The buffers could be easily be removed with a mechanism for providing a buffer to the load operation, but we would still double the RAM consumption. Boot time: Enlarging the kernel by 100MB will give noticeable addition to boot times. Development issues: I have numerous concerns related to this, e.g. not being able to side load the firmware files without rebuilding the initramfs. But most of these are not technical issues, but rather a matter of convenience. One large issue would be how to figure out how large to make the boot partition in your Android phone, to cope with potential future growth in firmware size - which has already proven to be a mess. Legal matters: Some of these firmware files are not redistributable, making it impossible for end users to rebuild their kernel without loosing functionality. There are even cases where these files are not allowed to share partition with GPL binaries. Most of these are just a major inconveniences to the developer but some are show stoppers; especially the legal matters. So if we wave this off as something people can live without then every downstream will sit on their own solution to reimplement it. > Anyway, here's a simple suggestion: fs/exec.c gets a sentinel file monitor > support per enum kernel_read_file_id. For instance we'd have one for > READING_FIRMWARE, one for READING_KEXEC_IMAGE, perhaps READING_POLICY, and this > would in turn be used as the system configurable deterministic file for > which to wait for to be present before enabling each enum kernel_read_file_id > type read. > > Thoughts ? That does sound like a good generic solution for our problem and for the other types of files as well. Do you have any ideas (patches?) on how each sentinel would be triggered? The only concern I can think of right now is that the firmware_class.path might point to a separate partition; but based on how the signaling of the sentinels are implemented this might not be an issue. Regards, Bjorn
[toc] | [prev] | [next] | [standalone]
| From | "Luis R. Rodriguez" <mcgrof@kernel.org> |
|---|---|
| Date | 2016-08-03 22:40 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s2b7k-7uo-7@gated-at.bofh.it> |
| In reply to | #1455920 |
On Wed, Aug 03, 2016 at 10:39:55AM -0700, Bjorn Andersson wrote: > On Tue 02 Aug 00:41 PDT 2016, Luis R. Rodriguez wrote: > > > On Tue, Aug 02, 2016 at 08:53:55AM +0200, Daniel Wagner wrote: > > > On 08/02/2016 08:34 AM, Luis R. Rodriguez wrote: > > > >On Tue, Aug 02, 2016 at 07:49:19AM +0200, Daniel Wagner wrote: > > > >>>The sysdata API's main goal rather is to provide a flexible API first, > > > >>>compartamentalizing the usermode helper was secondary. But now it seems > > > >>>I may just also add devm support too to help simplify code further. > > > >> > > > >>I missed the point that you plan to add usermode helper support to > > > >>the sysdata API. > > > > > > > >I had no such plans, when I have asked folks so far about "hey are you > > > >really in need for it, OK what for? " and "what extended uses do you > > > >envision?" so I far I have not gotten any replies at all. So -- instead > > > >sysdata currently ignores it. > > > > > > So you argue for the remoteproc use case with 100+ MB firmware that > > > if there is a way to load after pivot_root() (or other additional > > > firmware partition shows up) then there is no need at all for > > > usermode helper? > > > > No, I'm saying I'd like to hear valid uses cases for the usermode helper and so > > far I have only found using coccinelle grammar 2 explicit users, that's it. My > > patch series (not yet merge) then annotates these as valid as I've verified > > through their documentation they have some quirky requirement. > > > > I think we're on the same page, but just to make sure; I do not want the > usermode helper, Yay. > I only want a way to wait for the firmware files to > become available. Sure. > > Other than these two drivers I'd like hear to valid requirements for it. > > > > The existential issue is a real issue but it does not look impossible to > > resolve. It may be a solution to bloat up the kernel with 100+ MB size just to > > stuff built-in firmware to avoid this issue, but it does not mean a solution > > is not possible. > > > > Remind me -- why can remoteproc not stuff the firmware in initramfs ? > > > > RAM usage: > Storing the files in initramfs would consume 100MB RAM, we would then > allocate 100MB RAM for buffers during firmware loading and then we have > the reserved 100MB for the peripherals. The buffers could be easily be > removed with a mechanism for providing a buffer to the load operation, > but we would still double the RAM consumption. > > Boot time: > Enlarging the kernel by 100MB will give noticeable addition to boot > times. Right I see.. Since we read the full kernel... > Development issues: > I have numerous concerns related to this, e.g. not being able to side > load the firmware files without rebuilding the initramfs. But most of > these are not technical issues, but rather a matter of convenience. > > One large issue would be how to figure out how large to make the boot > partition in your Android phone, to cope with potential future growth in > firmware size - which has already proven to be a mess. > > Legal matters: > Some of these firmware files are not redistributable, making it > impossible for end users to rebuild their kernel without loosing > functionality. There are even cases where these files are not allowed to > share partition with GPL binaries. > > > Most of these are just a major inconveniences to the developer but some > are show stoppers; especially the legal matters. So if we wave this off > as something people can live without then every downstream will sit on > their own solution to reimplement it. Thanks I'll document these into the firmware_class. > > Anyway, here's a simple suggestion: fs/exec.c gets a sentinel file monitor > > support per enum kernel_read_file_id. For instance we'd have one for > > READING_FIRMWARE, one for READING_KEXEC_IMAGE, perhaps READING_POLICY, and this > > would in turn be used as the system configurable deterministic file for > > which to wait for to be present before enabling each enum kernel_read_file_id > > type read. > > > > Thoughts ? > > That does sound like a good generic solution for our problem and for the > other types of files as well. Do you have any ideas (patches?) on how > each sentinel would be triggered? > > The only concern I can think of right now is that the > firmware_class.path might point to a separate partition; but based on > how the signaling of the sentinels are implemented this might not be an > issue. There's another simpler suggestion I'm getting too, will post in the other thread. Luis
[toc] | [prev] | [next] | [standalone]
| From | "Luis R. Rodriguez" <mcgrof@kernel.org> |
|---|---|
| Date | 2016-08-01 22:20 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s1rQS-2HG-19@gated-at.bofh.it> |
| In reply to | #1452781 |
On Sun, Jul 31, 2016 at 12:23:09AM -0700, Dmitry Torokhov wrote: > On July 30, 2016 9:58:17 AM PDT, "Luis R. Rodriguez" <mcgrof@kernel.org> wrote: > >On Sat, Jul 30, 2016 at 02:42:41PM +0200, Arend van Spriel wrote: > >> + Luis (again) ;-) > >> > >> On 29-07-16 08:13, Daniel Wagner wrote: > >> > On 07/28/2016 09:01 PM, Bjorn Andersson wrote: > >> >> On Thu 28 Jul 11:33 PDT 2016, Dmitry Torokhov wrote: > >> >> > >> >>> On Thu, Jul 28, 2016 at 09:55:11AM +0200, Daniel Wagner wrote: > >> >>>> From: Daniel Wagner <daniel.wagner@bmw-carit.de> > >> >>>> > >> >> [..] > >> >>> > >> >>> Do not quite like it... I'd rather asynchronous request give out > >a > >> >>> firmware status pointer that could be used later on. > >> > >> Excellent. Why not get rid of the callback function as well and have > >> fw_loading_wait() return result (0 = firmware available, < 0 = fail). > >> Just to confirm, you are proposing a new API function next to > >> request_firmware_nowait(), right? > > > >If proposing new firmware_class patches please bounce / Cc me, I've > >recently asked for me to be added to MAINTAINERS so I get these > >e-mails as I'm working on a new flexible API which would allow us > >to extend the firmware API without having to care about the old > >stupid usermode helper at all. > > I am not sure why we started calling usermode helper "stupid". OK Fair, how systemd implemented kmod timeout for the usermode helper was stupid and it affected tons of systems. > We only had to > implement direct kernel firmware loading because udev/stsremd folks had > "interesting" ideas how events should be handled; but having userspace to > feed us data is not stupid. It really should just be an option. The problem was the collateral due to the way it was handled in userspace. > If we want to overhaul firmware loading support we need to figure out how to > support case when a driver want to [asynchronously] request > firmware/config/blob and the rest of the system is not ready. There's a lot of issues. So let's break them down. 1) First the sysdata API came about to help avoid the required set of collateral evolutions whenever the firmware API was expanded. A new argument added meant requiring to modify all drivers with the new argument, or a new exported symbol. The sysdata API makes the API flexible, enabling extensions by just expanding on the descriptor passed. The few features I've added to sysdata (like avoiding drivers having to declare their own completions, waits) are just small enhancements, but it seems now supporting devm may be desirable as well. 2) The usermode helper cannot be removed, however we can compartamentalize it. The sysdata API aims at helping with that, it doesn't touch it. There are only 2 explicit users of the usermode helper now in the kernel. If there are further users that really want it, I'd like to hear about them. 3) The firmware API having its own kernel read thing was fine but there were other places in the kernel doing the same, this begged sharing that code and also allowing then two LSM hooks to take care of handling doing whatever with a kernel read, a pre-read hook and post-read hook. Mimi completed this work and we now have the firmware API using kernel_read_file_from_path(). 4) The asynchronous firmware loading issue you describe above is just *one* issue, but it becomes more of an generic issue if you consider 3) above... because naturally there could potentially be other users of kernel_read_file() or kernel_read_file_from_path() and whereby a race also can happen. We may decide that this is up to the subsystem/user to figure out. If that's the case lets discuss that. It however occurs to me that it could just be as simple as adding another fs/exec.c helper like kernel_read_file_from_path_wait() which passes a completion and fs/exec.c just signals back when its ready. If we have this both the old firmware_class and new sysdata API could benefit from this behind the scenes -- no new API extension would be needed, this would just be a firmware_class fix to use a more deterministic kernel read API. > Even if we want kernel to do read/load the data we need userspace to tell > kernel when firmware partition is available, until then the kernel should not > fail the request. pivot_root() is possible as well, so exactly when the *real* partition is ready is very system specific -- best I think we can do is perhaps just see when the *first* file path becomes available and signal back. Problem with this is we would still need a way to know -- *everything is ready* as a limit condition for waiting. Luis
[toc] | [prev] | [next] | [standalone]
| From | Bjorn Andersson <bjorn.andersson@linaro.org> |
|---|---|
| Date | 2016-08-01 19:30 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s1pcm-RR-39@gated-at.bofh.it> |
| In reply to | #1452728 |
On Sat 30 Jul 09:58 PDT 2016, Luis R. Rodriguez wrote: > On Sat, Jul 30, 2016 at 02:42:41PM +0200, Arend van Spriel wrote: > > + Luis (again) ;-) > > > > On 29-07-16 08:13, Daniel Wagner wrote: > > > On 07/28/2016 09:01 PM, Bjorn Andersson wrote: > > >> On Thu 28 Jul 11:33 PDT 2016, Dmitry Torokhov wrote: > > >> > > >>> On Thu, Jul 28, 2016 at 09:55:11AM +0200, Daniel Wagner wrote: > > >>>> From: Daniel Wagner <daniel.wagner@bmw-carit.de> > > >>>> > > >> [..] > > >>> > > >>> Do not quite like it... I'd rather asynchronous request give out a > > >>> firmware status pointer that could be used later on. > > > > Excellent. Why not get rid of the callback function as well and have > > fw_loading_wait() return result (0 = firmware available, < 0 = fail). > > Just to confirm, you are proposing a new API function next to > > request_firmware_nowait(), right? > > If proposing new firmware_class patches please bounce / Cc me, I've > recently asked for me to be added to MAINTAINERS so I get these > e-mails as I'm working on a new flexible API which would allow us > to extend the firmware API without having to care about the old > stupid usermode helper at all. > In the remoteproc world there are several systems where we see 100+MB of firmware being loaded. It's unfeasible to have these files in an initramfs, so we need a way to indicate to the kernel that the second/primary (or a dedicated firmware partition) is mounted. We're currently loading these files with request_firmware_nowait(), so either one can either use kernel modules or the user-helper fallback to delay the loading until the files are available. (I don't like to enforce the usage of kernel modules) I'm open to alternative ways of having firmware loading wait on secondary filesystems to be mounted, but have not yet tried to tackle this problem. I do believe something that waits and retries the firmware load as additional file systems gets mounted would be prettier than forcing user space to tell us it's time to move on. Due to the size of these firmware files we release the firmware as soon as we have copied the content into the appropriate memory segments, so we're not utilizing the caching mechanisms of the current fw loader. Regards, Bjorn
[toc] | [prev] | [next] | [standalone]
| From | "Luis R. Rodriguez" <mcgrof@kernel.org> |
|---|---|
| Date | 2016-08-01 22:20 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s1rQS-2HG-3@gated-at.bofh.it> |
| In reply to | #1453358 |
On Mon, Aug 01, 2016 at 10:19:51AM -0700, Bjorn Andersson wrote: > On Sat 30 Jul 09:58 PDT 2016, Luis R. Rodriguez wrote: > > > On Sat, Jul 30, 2016 at 02:42:41PM +0200, Arend van Spriel wrote: > > > + Luis (again) ;-) > > > > > > On 29-07-16 08:13, Daniel Wagner wrote: > > > > On 07/28/2016 09:01 PM, Bjorn Andersson wrote: > > > >> On Thu 28 Jul 11:33 PDT 2016, Dmitry Torokhov wrote: > > > >> > > > >>> On Thu, Jul 28, 2016 at 09:55:11AM +0200, Daniel Wagner wrote: > > > >>>> From: Daniel Wagner <daniel.wagner@bmw-carit.de> > > > >>>> > > > >> [..] > > > >>> > > > >>> Do not quite like it... I'd rather asynchronous request give out a > > > >>> firmware status pointer that could be used later on. > > > > > > Excellent. Why not get rid of the callback function as well and have > > > fw_loading_wait() return result (0 = firmware available, < 0 = fail). > > > Just to confirm, you are proposing a new API function next to > > > request_firmware_nowait(), right? > > > > If proposing new firmware_class patches please bounce / Cc me, I've > > recently asked for me to be added to MAINTAINERS so I get these > > e-mails as I'm working on a new flexible API which would allow us > > to extend the firmware API without having to care about the old > > stupid usermode helper at all. > > > > In the remoteproc world there are several systems where we see 100+MB of > firmware being loaded. It's unfeasible to have these files in an > initramfs, so we need a way to indicate to the kernel that the > second/primary (or a dedicated firmware partition) is mounted. > > We're currently loading these files with request_firmware_nowait(), so > either one can either use kernel modules or the user-helper fallback to > delay the loading until the files are available. (I don't like to > enforce the usage of kernel modules) Now that the firmware API is sharing the same API call to read files the existential issue of the file is not unique issue of firmware, but also to any other caller of it. > I'm open to alternative ways of having firmware loading wait on > secondary filesystems to be mounted, but have not yet tried to tackle > this problem. I do believe something that waits and retries the firmware > load as additional file systems gets mounted would be prettier than > forcing user space to tell us it's time to move on. Agreed. We simply have not addressed this problem yet. Let's discuss a possible solution on the other reply thread I provided with more details to Dmitry. > Due to the size of these firmware files we release the firmware as soon > as we have copied the content into the appropriate memory segments, so > we're not utilizing the caching mechanisms of the current fw loader. BTW my goal with the sysdata API is to automatically free this for you too :) Luis
[toc] | [prev] | [next] | [standalone]
| From | Dmitry Torokhov <dmitry.torokhov@gmail.com> |
|---|---|
| Date | 2016-08-01 23:50 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s1tfY-3At-15@gated-at.bofh.it> |
| In reply to | #1453358 |
On Mon, Aug 01, 2016 at 10:19:51AM -0700, Bjorn Andersson wrote: > On Sat 30 Jul 09:58 PDT 2016, Luis R. Rodriguez wrote: > > > On Sat, Jul 30, 2016 at 02:42:41PM +0200, Arend van Spriel wrote: > > > + Luis (again) ;-) > > > > > > On 29-07-16 08:13, Daniel Wagner wrote: > > > > On 07/28/2016 09:01 PM, Bjorn Andersson wrote: > > > >> On Thu 28 Jul 11:33 PDT 2016, Dmitry Torokhov wrote: > > > >> > > > >>> On Thu, Jul 28, 2016 at 09:55:11AM +0200, Daniel Wagner wrote: > > > >>>> From: Daniel Wagner <daniel.wagner@bmw-carit.de> > > > >>>> > > > >> [..] > > > >>> > > > >>> Do not quite like it... I'd rather asynchronous request give out a > > > >>> firmware status pointer that could be used later on. > > > > > > Excellent. Why not get rid of the callback function as well and have > > > fw_loading_wait() return result (0 = firmware available, < 0 = fail). > > > Just to confirm, you are proposing a new API function next to > > > request_firmware_nowait(), right? > > > > If proposing new firmware_class patches please bounce / Cc me, I've > > recently asked for me to be added to MAINTAINERS so I get these > > e-mails as I'm working on a new flexible API which would allow us > > to extend the firmware API without having to care about the old > > stupid usermode helper at all. > > > > In the remoteproc world there are several systems where we see 100+MB of > firmware being loaded. It's unfeasible to have these files in an > initramfs, so we need a way to indicate to the kernel that the > second/primary (or a dedicated firmware partition) is mounted. > > We're currently loading these files with request_firmware_nowait(), so > either one can either use kernel modules or the user-helper fallback to > delay the loading until the files are available. (I don't like to > enforce the usage of kernel modules) > > I'm open to alternative ways of having firmware loading wait on > secondary filesystems to be mounted, but have not yet tried to tackle > this problem. I do believe something that waits and retries the firmware > load as additional file systems gets mounted would be prettier than > forcing user space to tell us it's time to move on. Hmm, but when do you stop? How do you know that you are not going to get yet another fs mounted and that one will finally have the firmware you are looking for? The kernel does now, but distribution/product integrator does. That is why I think the most reliable way is to see if firmware is built-in, otherwise wait and let userspace do its thing. Thanks. -- Dmitry
[toc] | [prev] | [next] | [standalone]
| From | Dmitry Torokhov <dmitry.torokhov@gmail.com> |
|---|---|
| Date | 2016-07-31 09:20 +0200 |
| Subject | Re: [RFC v0 7/8] Input: ims-pcu: use firmware_stat instead of completion |
| Message-ID | <s0Tct-5qH-3@gated-at.bofh.it> |
| In reply to | #1452680 |
On July 30, 2016 5:42:41 AM PDT, Arend van Spriel <arend.vanspriel@broadcom.com> wrote: >+ Luis (again) ;-) > >On 29-07-16 08:13, Daniel Wagner wrote: >> On 07/28/2016 09:01 PM, Bjorn Andersson wrote: >>> On Thu 28 Jul 11:33 PDT 2016, Dmitry Torokhov wrote: >>> >>>> On Thu, Jul 28, 2016 at 09:55:11AM +0200, Daniel Wagner wrote: >>>>> From: Daniel Wagner <daniel.wagner@bmw-carit.de> >>>>> >>> [..] >>>> >>>> Do not quite like it... I'd rather asynchronous request give out a >>>> firmware status pointer that could be used later on. > >Excellent. Why not get rid of the callback function as well and have >fw_loading_wait() return result (0 = firmware available, < 0 = fail). >Just to confirm, you are proposing a new API function next to >request_firmware_nowait(), right? Yes, that would be a new API call. Maybe we could replace old API with the new at some point. >>>> pcu->fw_st = request_firmware_async(IMS_PCU_FIRMWARE_NAME, >>>> - pcu, >>>> - ims_pcu_process_async_firmware); > + pcu); >>>> if (IS_ERR(pcu->fw_st)) >>>> return PTR_ERR(pcu->fw_st); >>>> >>>> .... >>>> >>>> err = fw_loading_wait(pcu->fw_st); > if (err) > return err; > > fw = fwstat_get_firmware(pcu->fw_st); > >Or whatever consistent prefix it is going to be. > >>>> >>> >>> In the remoteproc case (patch 6) this would clean up the code, >rather >>> than replacing the completion API 1 to 1. I like it! >> >> IIRC most drivers do it the same way. So request_firmware_async() >indeed >> would be good thing to have. Let me try that. > >While the idea behind this series is a good one I am wondering about >the >need for these drivers to use the asynchronous API. The historic reason >might be to avoid timeout caused by user-mode helper, but that may no >longer apply and these drivers could be better off using >request_firmware_direct(). Actually systems using this driver rely on usermode helper to provide necessary delay and load the firmware from storage once root partition is mounted. Converting to request_firmware_direct() would break them. Thanks. -- Dmitry
[toc] | [prev] | [next] | [standalone]
| From | Daniel Wagner <wagi@monom.org> |
|---|---|
| Date | 2016-07-28 10:00 +0200 |
| Subject | [RFC v0 2/8] selftests: firmware: do not clutter output |
| Message-ID | <rZOoy-39Z-25@gated-at.bofh.it> |
| In reply to | #1451770 |
From: Daniel Wagner <daniel.wagner@bmw-carit.de> Some of the test are supposed to fail but we get a few ouptput lines: ./fw_filesystem.sh: line 51: printf: write error: Invalid argument ./fw_filesystem.sh: line 56: printf: write error: No such device ./fw_filesystem.sh: line 62: echo: write error: No such file or directory Let's silence them so that the selftest output is clean if all is fine. Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de> --- tools/testing/selftests/firmware/fw_filesystem.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/firmware/fw_filesystem.sh b/tools/testing/selftests/firmware/fw_filesystem.sh index 5c495ad..d8ac9ba 100755 --- a/tools/testing/selftests/firmware/fw_filesystem.sh +++ b/tools/testing/selftests/firmware/fw_filesystem.sh @@ -48,18 +48,18 @@ echo "ABCD0123" >"$FW" NAME=$(basename "$FW") -if printf '\000' >"$DIR"/trigger_request; then +if printf '\000' >"$DIR"/trigger_request 2> /dev/null; then echo "$0: empty filename should not succeed" >&2 exit 1 fi -if printf '\000' >"$DIR"/trigger_async_request; then +if printf '\000' >"$DIR"/trigger_async_request 2> /dev/null; then echo "$0: empty filename should not succeed (async)" >&2 exit 1 fi # Request a firmware that doesn't exist, it should fail. -if echo -n "nope-$NAME" >"$DIR"/trigger_request; then +if echo -n "nope-$NAME" >"$DIR"/trigger_request 2> /dev/null; then echo "$0: firmware shouldn't have loaded" >&2 exit 1 fi -- 2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Daniel Wagner <wagi@monom.org> |
|---|---|
| Date | 2016-07-28 10:00 +0200 |
| Subject | [RFC v0 6/8] remoteproc: use firmware_stat instead of completion |
| Message-ID | <rZOoy-39Z-23@gated-at.bofh.it> |
| In reply to | #1451770 |
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
Loading firmware is an operation many drivers implement in various ways
around the completion API. And most of them do it almost in the same
way. Let's reuse the firmware_stat API which is used also by the
firmware_class loader. Apart of streamlining the firmware loading states
we also document it slightly better.
Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
drivers/remoteproc/remoteproc_core.c | 10 +++++-----
drivers/soc/ti/wkup_m3_ipc.c | 2 +-
include/linux/remoteproc.h | 6 ++++--
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index db3958b..3b158f7 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -936,7 +936,7 @@ static void rproc_fw_config_virtio(const struct firmware *fw, void *context)
out:
release_firmware(fw);
/* allow rproc_del() contexts, if any, to proceed */
- complete_all(&rproc->firmware_loading_complete);
+ fw_loading_done(rproc->fw_st);
}
static int rproc_add_virtio_devices(struct rproc *rproc)
@@ -944,7 +944,7 @@ static int rproc_add_virtio_devices(struct rproc *rproc)
int ret;
/* rproc_del() calls must wait until async loader completes */
- init_completion(&rproc->firmware_loading_complete);
+ firmware_stat_init(&rproc->fw_st);
/*
* We must retrieve early virtio configuration info from
@@ -959,7 +959,7 @@ static int rproc_add_virtio_devices(struct rproc *rproc)
rproc, rproc_fw_config_virtio);
if (ret < 0) {
dev_err(&rproc->dev, "request_firmware_nowait err: %d\n", ret);
- complete_all(&rproc->firmware_loading_complete);
+ fw_loading_abort(rproc->fw_st);
}
return ret;
@@ -1089,7 +1089,7 @@ static int __rproc_boot(struct rproc *rproc, bool wait)
/* if rproc virtio is not yet configured, wait */
if (wait)
- wait_for_completion(&rproc->firmware_loading_complete);
+ fw_loading_wait(rproc->fw_st);
ret = rproc_fw_boot(rproc, firmware_p);
@@ -1447,7 +1447,7 @@ int rproc_del(struct rproc *rproc)
return -EINVAL;
/* if rproc is just being registered, wait */
- wait_for_completion(&rproc->firmware_loading_complete);
+ fw_loading_wait(rproc->fw_st);
/* clean up remote vdev entries */
list_for_each_entry_safe(rvdev, tmp, &rproc->rvdevs, node)
diff --git a/drivers/soc/ti/wkup_m3_ipc.c b/drivers/soc/ti/wkup_m3_ipc.c
index 8823cc8..14c6396 100644
--- a/drivers/soc/ti/wkup_m3_ipc.c
+++ b/drivers/soc/ti/wkup_m3_ipc.c
@@ -370,7 +370,7 @@ static void wkup_m3_rproc_boot_thread(struct wkup_m3_ipc *m3_ipc)
struct device *dev = m3_ipc->dev;
int ret;
- wait_for_completion(&m3_ipc->rproc->firmware_loading_complete);
+ fw_loading_wait(m3_ipc->rproc->fw_st);
init_completion(&m3_ipc->sync_complete);
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index 1c457a8..b8e7ff4 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -41,6 +41,7 @@
#include <linux/completion.h>
#include <linux/idr.h>
#include <linux/of.h>
+#include <linux/firmware.h>
/**
* struct resource_table - firmware resource table header
@@ -397,7 +398,7 @@ enum rproc_crash_type {
* @num_traces: number of trace buffers
* @carveouts: list of physically contiguous memory allocations
* @mappings: list of iommu mappings we initiated, needed on shutdown
- * @firmware_loading_complete: marks e/o asynchronous firmware loading
+ * @fw_sync: marks e/o asynchronous firmware loading
* @bootaddr: address of first instruction to boot rproc with (optional)
* @rvdevs: list of remote virtio devices
* @notifyids: idr for dynamically assigning rproc-wide unique notify ids
@@ -429,7 +430,7 @@ struct rproc {
int num_traces;
struct list_head carveouts;
struct list_head mappings;
- struct completion firmware_loading_complete;
+ struct firmware_stat fw_st;
u32 bootaddr;
struct list_head rvdevs;
struct idr notifyids;
@@ -479,6 +480,7 @@ struct rproc_vring {
* @vring: the vrings for this vdev
* @rsc_offset: offset of the vdev's resource entry
*/
+
struct rproc_vdev {
struct list_head node;
struct rproc *rproc;
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Daniel Wagner <wagi@monom.org> |
|---|---|
| Date | 2016-07-28 10:00 +0200 |
| Subject | [RFC v0 3/8] firmware: Factor out firmware load helpers |
| Message-ID | <rZOox-39Z-13@gated-at.bofh.it> |
| In reply to | #1451770 |
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
Factor out the firmware loading synchronization code in order to allow
drivers to reuse it. This also documents more clearly what is
happening. This is especial useful the drivers which will be converted
afterwards. Not everyone has to come with yet another way to handle it.
We use swait instead completion. complete() would only wake up one
waiter, so complete_all() is used. complete_all() wakes max MAX_UINT/2
waiters which is plenty in all cases. Though withh swait we just wait
until the exptected status shows up and wake any waiter.
Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
drivers/base/firmware_class.c | 112 +++++++++++++++++++-----------------------
include/linux/firmware.h | 71 ++++++++++++++++++++++++++
2 files changed, 122 insertions(+), 61 deletions(-)
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 773fc30..bf1ca70 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -30,6 +30,7 @@
#include <linux/syscore_ops.h>
#include <linux/reboot.h>
#include <linux/security.h>
+#include <linux/swait.h>
#include <generated/utsrelease.h>
@@ -85,11 +86,36 @@ static inline bool fw_is_builtin_firmware(const struct firmware *fw)
}
#endif
-enum {
- FW_STATUS_LOADING,
- FW_STATUS_DONE,
- FW_STATUS_ABORT,
-};
+
+#if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE))
+
+static inline bool is_fw_sync_done(unsigned long status)
+{
+ return status == FW_STATUS_LOADED || status == FW_STATUS_ABORT;
+}
+
+int __firmware_stat_wait(struct firmware_stat *fwst,
+ long timeout)
+{
+ int err;
+ err = swait_event_interruptible_timeout(fwst->wq,
+ is_fw_sync_done(READ_ONCE(fwst->status)),
+ timeout);
+ if (err == 0 && fwst->status == FW_STATUS_ABORT)
+ return -ENOENT;
+
+ return err;
+}
+EXPORT_SYMBOL(__firmware_stat_wait);
+
+void __firmware_stat_set(struct firmware_stat *fwst, unsigned long status)
+{
+ WRITE_ONCE(fwst->status, status);
+ swake_up(&fwst->wq);
+}
+EXPORT_SYMBOL(__firmware_stat_set);
+
+#endif
static int loading_timeout = 60; /* In seconds */
@@ -138,9 +164,8 @@ struct firmware_cache {
struct firmware_buf {
struct kref ref;
struct list_head list;
- struct completion completion;
+ struct firmware_stat fwst;
struct firmware_cache *fwc;
- unsigned long status;
void *data;
size_t size;
#ifdef CONFIG_FW_LOADER_USER_HELPER
@@ -194,7 +219,7 @@ static struct firmware_buf *__allocate_fw_buf(const char *fw_name,
kref_init(&buf->ref);
buf->fwc = fwc;
- init_completion(&buf->completion);
+ firmware_stat_init(&buf->fwst);
#ifdef CONFIG_FW_LOADER_USER_HELPER
INIT_LIST_HEAD(&buf->pending_list);
#endif
@@ -292,15 +317,6 @@ static const char * const fw_path[] = {
module_param_string(path, fw_path_para, sizeof(fw_path_para), 0644);
MODULE_PARM_DESC(path, "customized firmware image search path with a higher priority than default path");
-static void fw_finish_direct_load(struct device *device,
- struct firmware_buf *buf)
-{
- mutex_lock(&fw_lock);
- set_bit(FW_STATUS_DONE, &buf->status);
- complete_all(&buf->completion);
- mutex_unlock(&fw_lock);
-}
-
static int fw_get_filesystem_firmware(struct device *device,
struct firmware_buf *buf)
{
@@ -339,7 +355,7 @@ static int fw_get_filesystem_firmware(struct device *device,
}
dev_dbg(device, "direct-loading %s\n", buf->fw_id);
buf->size = size;
- fw_finish_direct_load(device, buf);
+ fw_loading_done(buf->fwst);
break;
}
__putname(path);
@@ -457,12 +473,11 @@ static void __fw_load_abort(struct firmware_buf *buf)
* There is a small window in which user can write to 'loading'
* between loading done and disappearance of 'loading'
*/
- if (test_bit(FW_STATUS_DONE, &buf->status))
+ if (is_fw_loading_done(buf->fwst))
return;
list_del_init(&buf->pending_list);
- set_bit(FW_STATUS_ABORT, &buf->status);
- complete_all(&buf->completion);
+ fw_loading_abort(buf->fwst);
}
static void fw_load_abort(struct firmware_priv *fw_priv)
@@ -475,9 +490,6 @@ static void fw_load_abort(struct firmware_priv *fw_priv)
fw_priv->buf = NULL;
}
-#define is_fw_load_aborted(buf) \
- test_bit(FW_STATUS_ABORT, &(buf)->status)
-
static LIST_HEAD(pending_fw_head);
/* reboot notifier for avoid deadlock with usermode_lock */
@@ -577,7 +589,7 @@ static ssize_t firmware_loading_show(struct device *dev,
mutex_lock(&fw_lock);
if (fw_priv->buf)
- loading = test_bit(FW_STATUS_LOADING, &fw_priv->buf->status);
+ loading = is_fw_loading(fw_priv->buf->fwst);
mutex_unlock(&fw_lock);
return sprintf(buf, "%d\n", loading);
@@ -632,23 +644,20 @@ static ssize_t firmware_loading_store(struct device *dev,
switch (loading) {
case 1:
/* discarding any previous partial load */
- if (!test_bit(FW_STATUS_DONE, &fw_buf->status)) {
+ if (!is_fw_loading_done(fw_buf->fwst)) {
for (i = 0; i < fw_buf->nr_pages; i++)
__free_page(fw_buf->pages[i]);
vfree(fw_buf->pages);
fw_buf->pages = NULL;
fw_buf->page_array_size = 0;
fw_buf->nr_pages = 0;
- set_bit(FW_STATUS_LOADING, &fw_buf->status);
+ fw_loading_start(fw_buf->fwst);
}
break;
case 0:
- if (test_bit(FW_STATUS_LOADING, &fw_buf->status)) {
+ if (is_fw_loading(fw_buf->fwst)) {
int rc;
- set_bit(FW_STATUS_DONE, &fw_buf->status);
- clear_bit(FW_STATUS_LOADING, &fw_buf->status);
-
/*
* Several loading requests may be pending on
* one same firmware buf, so let all requests
@@ -670,10 +679,11 @@ static ssize_t firmware_loading_store(struct device *dev,
*/
list_del_init(&fw_buf->pending_list);
if (rc) {
- set_bit(FW_STATUS_ABORT, &fw_buf->status);
+ fw_loading_abort(fw_buf->fwst);
written = rc;
+ } else {
+ fw_loading_done(fw_buf->fwst);
}
- complete_all(&fw_buf->completion);
break;
}
/* fallthrough */
@@ -681,7 +691,7 @@ static ssize_t firmware_loading_store(struct device *dev,
dev_err(dev, "%s: unexpected value (%d)\n", __func__, loading);
/* fallthrough */
case -1:
- fw_load_abort(fw_priv);
+ fw_loading_abort(fw_buf->fwst);
break;
}
out:
@@ -702,7 +712,7 @@ static ssize_t firmware_data_read(struct file *filp, struct kobject *kobj,
mutex_lock(&fw_lock);
buf = fw_priv->buf;
- if (!buf || test_bit(FW_STATUS_DONE, &buf->status)) {
+ if (!buf || is_fw_loading_done(buf->fwst)) {
ret_count = -ENODEV;
goto out;
}
@@ -799,7 +809,7 @@ static ssize_t firmware_data_write(struct file *filp, struct kobject *kobj,
mutex_lock(&fw_lock);
buf = fw_priv->buf;
- if (!buf || test_bit(FW_STATUS_DONE, &buf->status)) {
+ if (!buf || is_fw_loading_done(buf->fwst)) {
retval = -ENODEV;
goto out;
}
@@ -917,8 +927,7 @@ static int _request_firmware_load(struct firmware_priv *fw_priv,
timeout = MAX_JIFFY_OFFSET;
}
- retval = wait_for_completion_interruptible_timeout(&buf->completion,
- timeout);
+ retval = fw_loading_wait_timeout(buf->fwst, timeout);
if (retval == -ERESTARTSYS || !retval) {
mutex_lock(&fw_lock);
fw_load_abort(fw_priv);
@@ -927,7 +936,7 @@ static int _request_firmware_load(struct firmware_priv *fw_priv,
retval = 0;
}
- if (is_fw_load_aborted(buf))
+ if (is_fw_loading_aborted(buf->fwst))
retval = -EAGAIN;
else if (!buf->data)
retval = -ENOMEM;
@@ -986,26 +995,6 @@ static inline void kill_requests_without_uevent(void) { }
#endif /* CONFIG_FW_LOADER_USER_HELPER */
-
-/* wait until the shared firmware_buf becomes ready (or error) */
-static int sync_cached_firmware_buf(struct firmware_buf *buf)
-{
- int ret = 0;
-
- mutex_lock(&fw_lock);
- while (!test_bit(FW_STATUS_DONE, &buf->status)) {
- if (is_fw_load_aborted(buf)) {
- ret = -ENOENT;
- break;
- }
- mutex_unlock(&fw_lock);
- ret = wait_for_completion_interruptible(&buf->completion);
- mutex_lock(&fw_lock);
- }
- mutex_unlock(&fw_lock);
- return ret;
-}
-
/* prepare firmware and firmware_buf structs;
* return 0 if a firmware is already assigned, 1 if need to load one,
* or a negative error code
@@ -1039,7 +1028,8 @@ _request_firmware_prepare(struct firmware **firmware_p, const char *name,
firmware->priv = buf;
if (ret > 0) {
- ret = sync_cached_firmware_buf(buf);
+ ret = fw_loading_wait_timeout(buf->fwst,
+ firmware_loading_timeout());
if (!ret) {
fw_set_page_data(buf, firmware);
return 0; /* assigned */
@@ -1057,7 +1047,7 @@ static int assign_firmware_buf(struct firmware *fw, struct device *device,
struct firmware_buf *buf = fw->priv;
mutex_lock(&fw_lock);
- if (!buf->size || is_fw_load_aborted(buf)) {
+ if (!buf->size || is_fw_loading_aborted(buf->fwst)) {
mutex_unlock(&fw_lock);
return -ENOENT;
}
diff --git a/include/linux/firmware.h b/include/linux/firmware.h
index 5c41c5e..f584160 100644
--- a/include/linux/firmware.h
+++ b/include/linux/firmware.h
@@ -4,10 +4,17 @@
#include <linux/types.h>
#include <linux/compiler.h>
#include <linux/gfp.h>
+#include <linux/swait.h>
#define FW_ACTION_NOHOTPLUG 0
#define FW_ACTION_HOTPLUG 1
+enum {
+ FW_STATUS_LOADING,
+ FW_STATUS_LOADED,
+ FW_STATUS_ABORT,
+};
+
struct firmware {
size_t size;
const u8 *data;
@@ -17,6 +24,11 @@ struct firmware {
void *priv;
};
+struct firmware_stat {
+ unsigned long status;
+ struct swait_queue_head wq;
+};
+
struct module;
struct device;
@@ -49,6 +61,36 @@ int request_firmware_direct(const struct firmware **fw, const char *name,
struct device *device);
void release_firmware(const struct firmware *fw);
+
+static inline void firmware_stat_init(struct firmware_stat *fwst)
+{
+ init_swait_queue_head(&fwst->wq);
+}
+
+static inline unsigned long __firmware_stat_get(struct firmware_stat *fwst)
+{
+ return READ_ONCE(fwst->status);
+}
+void __firmware_stat_set(struct firmware_stat *fwst, unsigned long status);
+int __firmware_stat_wait(struct firmware_stat *fwst, long timeout);
+
+#define fw_loading_start(fwst) \
+ __firmware_stat_set(&fwst, FW_STATUS_LOADING)
+#define fw_loading_done(fwst) \
+ __firmware_stat_set(&fwst, FW_STATUS_LOADED)
+#define fw_loading_abort(fwst) \
+ __firmware_stat_set(&fwst, FW_STATUS_ABORT)
+#define fw_loading_wait(fwst) \
+ __firmware_stat_wait(&fwst, 0)
+#define fw_loading_wait_timeout(fwst, timeout) \
+ __firmware_stat_wait(&fwst, timeout)
+#define is_fw_loading(fwst) \
+ (__firmware_stat_get(&fwst) == FW_STATUS_LOADING)
+#define is_fw_loading_done(fwst) \
+ (__firmware_stat_get(&fwst) == FW_STATUS_LOADED)
+#define is_fw_loading_aborted(fwst) \
+ (__firmware_stat_get(&fwst) == FW_STATUS_ABORT)
+
#else
static inline int request_firmware(const struct firmware **fw,
const char *name,
@@ -75,5 +117,34 @@ static inline int request_firmware_direct(const struct firmware **fw,
return -EINVAL;
}
+static inline void firmware_stat_init(struct firmware_stat *fwst)
+{
+}
+
+static inline unsigned long __firmware_stat_get(struct firmware_stat *fwst)
+{
+ return -EINVAL;
+}
+
+static inline void __firmware_stat_set(struct firmware_stat *fwst,
+ unsigned long status)
+{
+}
+
+static inline int __firmware_stat_wait(struct firmware_stat *fwst,
+ long timeout)
+{
+ return -EINVAL;
+}
+
+#define fw_loading_start(fwst)
+#define fw_loading_done(fwst)
+#define fw_loading_abort(fwst)
+#define fw_loading_wait(fwst)
+#define fw_loading_wait_timeout(fwst, timeout)
+#define is_fw_loading(fwst) 0
+#define is_fw_loading_done(fwst) 0
+#define is_fw_loading_aborted(fwst) 0
+
#endif
#endif
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Dan Williams <dcbw@redhat.com> |
|---|---|
| Date | 2016-07-28 17:10 +0200 |
| Subject | Re: [RFC v0 3/8] firmware: Factor out firmware load helpers |
| Message-ID | <rZV6G-7YK-5@gated-at.bofh.it> |
| In reply to | #1451779 |
On Thu, 2016-07-28 at 09:55 +0200, Daniel Wagner wrote:
> From: Daniel Wagner <daniel.wagner@bmw-carit.de>
>
> Factor out the firmware loading synchronization code in order to
> allow
> drivers to reuse it. This also documents more clearly what is
> happening. This is especial useful the drivers which will be
> converted
> afterwards. Not everyone has to come with yet another way to handle
> it.
It's somewhat odd to me that the structure is "firmware_stat" but most
of the functions are "fw_loading_*". That seems inconsistent for a
structure that is (currently) only used by these functions.
I would personally do either:
a) "struct fw_load_status" and "fw_load_*()"
or
b) "struct firmware_load_stat" and "firmware_load_*()"
I'd also change the function names from "loading" -> "load", similar to
how userland has read(2), not reading(2).
Dan
> We use swait instead completion. complete() would only wake up one
> waiter, so complete_all() is used. complete_all() wakes max
> MAX_UINT/2
> waiters which is plenty in all cases. Though withh swait we just wait
> until the exptected status shows up and wake any waiter.
>
> Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
> ---
> drivers/base/firmware_class.c | 112 +++++++++++++++++++-------------
> ----------
> include/linux/firmware.h | 71 ++++++++++++++++++++++++++
> 2 files changed, 122 insertions(+), 61 deletions(-)
>
> diff --git a/drivers/base/firmware_class.c
> b/drivers/base/firmware_class.c
> index 773fc30..bf1ca70 100644
> --- a/drivers/base/firmware_class.c
> +++ b/drivers/base/firmware_class.c
> @@ -30,6 +30,7 @@
> #include <linux/syscore_ops.h>
> #include <linux/reboot.h>
> #include <linux/security.h>
> +#include <linux/swait.h>
>
> #include <generated/utsrelease.h>
>
> @@ -85,11 +86,36 @@ static inline bool fw_is_builtin_firmware(const
> struct firmware *fw)
> }
> #endif
>
> -enum {
> - FW_STATUS_LOADING,
> - FW_STATUS_DONE,
> - FW_STATUS_ABORT,
> -};
> +
> +#if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE)
> && defined(MODULE))
> +
> +static inline bool is_fw_sync_done(unsigned long status)
> +{
> + return status == FW_STATUS_LOADED || status ==
> FW_STATUS_ABORT;
> +}
> +
> +int __firmware_stat_wait(struct firmware_stat *fwst,
> + long timeout)
> +{
> + int err;
> + err = swait_event_interruptible_timeout(fwst->wq,
> + is_fw_sync_done(READ_ONCE(fwst-
> >status)),
> + timeout);
> + if (err == 0 && fwst->status == FW_STATUS_ABORT)
> + return -ENOENT;
> +
> + return err;
> +}
> +EXPORT_SYMBOL(__firmware_stat_wait);
> +
> +void __firmware_stat_set(struct firmware_stat *fwst, unsigned long
> status)
> +{
> + WRITE_ONCE(fwst->status, status);
> + swake_up(&fwst->wq);
> +}
> +EXPORT_SYMBOL(__firmware_stat_set);
> +
> +#endif
>
> static int loading_timeout = 60; /* In seconds */
>
> @@ -138,9 +164,8 @@ struct firmware_cache {
> struct firmware_buf {
> struct kref ref;
> struct list_head list;
> - struct completion completion;
> + struct firmware_stat fwst;
> struct firmware_cache *fwc;
> - unsigned long status;
> void *data;
> size_t size;
> #ifdef CONFIG_FW_LOADER_USER_HELPER
> @@ -194,7 +219,7 @@ static struct firmware_buf
> *__allocate_fw_buf(const char *fw_name,
>
> kref_init(&buf->ref);
> buf->fwc = fwc;
> - init_completion(&buf->completion);
> + firmware_stat_init(&buf->fwst);
> #ifdef CONFIG_FW_LOADER_USER_HELPER
> INIT_LIST_HEAD(&buf->pending_list);
> #endif
> @@ -292,15 +317,6 @@ static const char * const fw_path[] = {
> module_param_string(path, fw_path_para, sizeof(fw_path_para), 0644);
> MODULE_PARM_DESC(path, "customized firmware image search path with a
> higher priority than default path");
>
> -static void fw_finish_direct_load(struct device *device,
> - struct firmware_buf *buf)
> -{
> - mutex_lock(&fw_lock);
> - set_bit(FW_STATUS_DONE, &buf->status);
> - complete_all(&buf->completion);
> - mutex_unlock(&fw_lock);
> -}
> -
> static int fw_get_filesystem_firmware(struct device *device,
> struct firmware_buf *buf)
> {
> @@ -339,7 +355,7 @@ static int fw_get_filesystem_firmware(struct
> device *device,
> }
> dev_dbg(device, "direct-loading %s\n", buf->fw_id);
> buf->size = size;
> - fw_finish_direct_load(device, buf);
> + fw_loading_done(buf->fwst);
> break;
> }
> __putname(path);
> @@ -457,12 +473,11 @@ static void __fw_load_abort(struct firmware_buf
> *buf)
> * There is a small window in which user can write to
> 'loading'
> * between loading done and disappearance of 'loading'
> */
> - if (test_bit(FW_STATUS_DONE, &buf->status))
> + if (is_fw_loading_done(buf->fwst))
> return;
>
> list_del_init(&buf->pending_list);
> - set_bit(FW_STATUS_ABORT, &buf->status);
> - complete_all(&buf->completion);
> + fw_loading_abort(buf->fwst);
> }
>
> static void fw_load_abort(struct firmware_priv *fw_priv)
> @@ -475,9 +490,6 @@ static void fw_load_abort(struct firmware_priv
> *fw_priv)
> fw_priv->buf = NULL;
> }
>
> -#define is_fw_load_aborted(buf) \
> - test_bit(FW_STATUS_ABORT, &(buf)->status)
> -
> static LIST_HEAD(pending_fw_head);
>
> /* reboot notifier for avoid deadlock with usermode_lock */
> @@ -577,7 +589,7 @@ static ssize_t firmware_loading_show(struct
> device *dev,
>
> mutex_lock(&fw_lock);
> if (fw_priv->buf)
> - loading = test_bit(FW_STATUS_LOADING, &fw_priv->buf-
> >status);
> + loading = is_fw_loading(fw_priv->buf->fwst);
> mutex_unlock(&fw_lock);
>
> return sprintf(buf, "%d\n", loading);
> @@ -632,23 +644,20 @@ static ssize_t firmware_loading_store(struct
> device *dev,
> switch (loading) {
> case 1:
> /* discarding any previous partial load */
> - if (!test_bit(FW_STATUS_DONE, &fw_buf->status)) {
> + if (!is_fw_loading_done(fw_buf->fwst)) {
> for (i = 0; i < fw_buf->nr_pages; i++)
> __free_page(fw_buf->pages[i]);
> vfree(fw_buf->pages);
> fw_buf->pages = NULL;
> fw_buf->page_array_size = 0;
> fw_buf->nr_pages = 0;
> - set_bit(FW_STATUS_LOADING, &fw_buf->status);
> + fw_loading_start(fw_buf->fwst);
> }
> break;
> case 0:
> - if (test_bit(FW_STATUS_LOADING, &fw_buf->status)) {
> + if (is_fw_loading(fw_buf->fwst)) {
> int rc;
>
> - set_bit(FW_STATUS_DONE, &fw_buf->status);
> - clear_bit(FW_STATUS_LOADING, &fw_buf-
> >status);
> -
> /*
> * Several loading requests may be pending
> on
> * one same firmware buf, so let all
> requests
> @@ -670,10 +679,11 @@ static ssize_t firmware_loading_store(struct
> device *dev,
> */
> list_del_init(&fw_buf->pending_list);
> if (rc) {
> - set_bit(FW_STATUS_ABORT, &fw_buf-
> >status);
> + fw_loading_abort(fw_buf->fwst);
> written = rc;
> + } else {
> + fw_loading_done(fw_buf->fwst);
> }
> - complete_all(&fw_buf->completion);
> break;
> }
> /* fallthrough */
> @@ -681,7 +691,7 @@ static ssize_t firmware_loading_store(struct
> device *dev,
> dev_err(dev, "%s: unexpected value (%d)\n",
> __func__, loading);
> /* fallthrough */
> case -1:
> - fw_load_abort(fw_priv);
> + fw_loading_abort(fw_buf->fwst);
> break;
> }
> out:
> @@ -702,7 +712,7 @@ static ssize_t firmware_data_read(struct file
> *filp, struct kobject *kobj,
>
> mutex_lock(&fw_lock);
> buf = fw_priv->buf;
> - if (!buf || test_bit(FW_STATUS_DONE, &buf->status)) {
> + if (!buf || is_fw_loading_done(buf->fwst)) {
> ret_count = -ENODEV;
> goto out;
> }
> @@ -799,7 +809,7 @@ static ssize_t firmware_data_write(struct file
> *filp, struct kobject *kobj,
>
> mutex_lock(&fw_lock);
> buf = fw_priv->buf;
> - if (!buf || test_bit(FW_STATUS_DONE, &buf->status)) {
> + if (!buf || is_fw_loading_done(buf->fwst)) {
> retval = -ENODEV;
> goto out;
> }
> @@ -917,8 +927,7 @@ static int _request_firmware_load(struct
> firmware_priv *fw_priv,
> timeout = MAX_JIFFY_OFFSET;
> }
>
> - retval = wait_for_completion_interruptible_timeout(&buf-
> >completion,
> - timeout);
> + retval = fw_loading_wait_timeout(buf->fwst, timeout);
> if (retval == -ERESTARTSYS || !retval) {
> mutex_lock(&fw_lock);
> fw_load_abort(fw_priv);
> @@ -927,7 +936,7 @@ static int _request_firmware_load(struct
> firmware_priv *fw_priv,
> retval = 0;
> }
>
> - if (is_fw_load_aborted(buf))
> + if (is_fw_loading_aborted(buf->fwst))
> retval = -EAGAIN;
> else if (!buf->data)
> retval = -ENOMEM;
> @@ -986,26 +995,6 @@ static inline void
> kill_requests_without_uevent(void) { }
>
> #endif /* CONFIG_FW_LOADER_USER_HELPER */
>
> -
> -/* wait until the shared firmware_buf becomes ready (or error) */
> -static int sync_cached_firmware_buf(struct firmware_buf *buf)
> -{
> - int ret = 0;
> -
> - mutex_lock(&fw_lock);
> - while (!test_bit(FW_STATUS_DONE, &buf->status)) {
> - if (is_fw_load_aborted(buf)) {
> - ret = -ENOENT;
> - break;
> - }
> - mutex_unlock(&fw_lock);
> - ret = wait_for_completion_interruptible(&buf-
> >completion);
> - mutex_lock(&fw_lock);
> - }
> - mutex_unlock(&fw_lock);
> - return ret;
> -}
> -
> /* prepare firmware and firmware_buf structs;
> * return 0 if a firmware is already assigned, 1 if need to load
> one,
> * or a negative error code
> @@ -1039,7 +1028,8 @@ _request_firmware_prepare(struct firmware
> **firmware_p, const char *name,
> firmware->priv = buf;
>
> if (ret > 0) {
> - ret = sync_cached_firmware_buf(buf);
> + ret = fw_loading_wait_timeout(buf->fwst,
> + firmware_loading_timeo
> ut());
> if (!ret) {
> fw_set_page_data(buf, firmware);
> return 0; /* assigned */
> @@ -1057,7 +1047,7 @@ static int assign_firmware_buf(struct firmware
> *fw, struct device *device,
> struct firmware_buf *buf = fw->priv;
>
> mutex_lock(&fw_lock);
> - if (!buf->size || is_fw_load_aborted(buf)) {
> + if (!buf->size || is_fw_loading_aborted(buf->fwst)) {
> mutex_unlock(&fw_lock);
> return -ENOENT;
> }
> diff --git a/include/linux/firmware.h b/include/linux/firmware.h
> index 5c41c5e..f584160 100644
> --- a/include/linux/firmware.h
> +++ b/include/linux/firmware.h
> @@ -4,10 +4,17 @@
> #include <linux/types.h>
> #include <linux/compiler.h>
> #include <linux/gfp.h>
> +#include <linux/swait.h>
>
> #define FW_ACTION_NOHOTPLUG 0
> #define FW_ACTION_HOTPLUG 1
>
> +enum {
> + FW_STATUS_LOADING,
> + FW_STATUS_LOADED,
> + FW_STATUS_ABORT,
> +};
> +
> struct firmware {
> size_t size;
> const u8 *data;
> @@ -17,6 +24,11 @@ struct firmware {
> void *priv;
> };
>
> +struct firmware_stat {
> + unsigned long status;
> + struct swait_queue_head wq;
> +};
> +
> struct module;
> struct device;
>
> @@ -49,6 +61,36 @@ int request_firmware_direct(const struct firmware
> **fw, const char *name,
> struct device *device);
>
> void release_firmware(const struct firmware *fw);
> +
> +static inline void firmware_stat_init(struct firmware_stat *fwst)
> +{
> + init_swait_queue_head(&fwst->wq);
> +}
> +
> +static inline unsigned long __firmware_stat_get(struct firmware_stat
> *fwst)
> +{
> + return READ_ONCE(fwst->status);
> +}
> +void __firmware_stat_set(struct firmware_stat *fwst, unsigned long
> status);
> +int __firmware_stat_wait(struct firmware_stat *fwst, long timeout);
> +
> +#define fw_loading_start(fwst)
> \
> + __firmware_stat_set(&fwst, FW_STATUS_LOADING)
> +#define fw_loading_done(fwst)
> \
> + __firmware_stat_set(&fwst, FW_STATUS_LOADED)
> +#define fw_loading_abort(fwst)
> \
> + __firmware_stat_set(&fwst, FW_STATUS_ABORT)
> +#define fw_loading_wait(fwst)
> \
> + __firmware_stat_wait(&fwst, 0)
> +#define fw_loading_wait_timeout(fwst, timeout)
> \
> + __firmware_stat_wait(&fwst, timeout)
> +#define is_fw_loading(fwst) \
> + (__firmware_stat_get(&fwst) == FW_STATUS_LOADING)
> +#define is_fw_loading_done(fwst) \
> + (__firmware_stat_get(&fwst) == FW_STATUS_LOADED)
> +#define is_fw_loading_aborted(fwst) \
> + (__firmware_stat_get(&fwst) == FW_STATUS_ABORT)
> +
> #else
> static inline int request_firmware(const struct firmware **fw,
> const char *name,
> @@ -75,5 +117,34 @@ static inline int request_firmware_direct(const
> struct firmware **fw,
> return -EINVAL;
> }
>
> +static inline void firmware_stat_init(struct firmware_stat *fwst)
> +{
> +}
> +
> +static inline unsigned long __firmware_stat_get(struct firmware_stat
> *fwst)
> +{
> + return -EINVAL;
> +}
> +
> +static inline void __firmware_stat_set(struct firmware_stat *fwst,
> + unsigned long status)
> +{
> +}
> +
> +static inline int __firmware_stat_wait(struct firmware_stat *fwst,
> + long timeout)
> +{
> + return -EINVAL;
> +}
> +
> +#define fw_loading_start(fwst)
> +#define fw_loading_done(fwst)
> +#define fw_loading_abort(fwst)
> +#define fw_loading_wait(fwst)
> +#define fw_loading_wait_timeout(fwst, timeout)
> +#define is_fw_loading(fwst) 0
> +#define is_fw_loading_done(fwst) 0
> +#define is_fw_loading_aborted(fwst) 0
> +
> #endif
> #endif
[toc] | [prev] | [next] | [standalone]
| From | Daniel Wagner <daniel.wagner@bmw-carit.de> |
|---|---|
| Date | 2016-07-29 08:10 +0200 |
| Subject | Re: [RFC v0 3/8] firmware: Factor out firmware load helpers |
| Message-ID | <s099D-Os-3@gated-at.bofh.it> |
| In reply to | #1451973 |
> It's somewhat odd to me that the structure is "firmware_stat" but most > of the functions are "fw_loading_*". That seems inconsistent for a > structure that is (currently) only used by these functions. I agree, my proposal is odd. > I would personally do either: > > a) "struct fw_load_status" and "fw_load_*()" > > or > > b) "struct firmware_load_stat" and "firmware_load_*()" > > I'd also change the function names from "loading" -> "load", similar to > how userland has read(2), not reading(2). a) sounds good to me, because fw_load_ should be long enough prefix. cheers, daniel
[toc] | [prev] | [next] | [standalone]
| From | Dmitry Torokhov <dmitry.torokhov@gmail.com> |
|---|---|
| Date | 2016-07-28 20:00 +0200 |
| Subject | Re: [RFC v0 3/8] firmware: Factor out firmware load helpers |
| Message-ID | <rZXLb-12G-7@gated-at.bofh.it> |
| In reply to | #1451779 |
On Thu, Jul 28, 2016 at 09:55:07AM +0200, Daniel Wagner wrote:
> +int __firmware_stat_wait(struct firmware_stat *fwst,
> + long timeout)
> +{
> + int err;
> + err = swait_event_interruptible_timeout(fwst->wq,
> + is_fw_sync_done(READ_ONCE(fwst->status)),
> + timeout);
> + if (err == 0 && fwst->status == FW_STATUS_ABORT)
> + return -ENOENT;
> +
> + return err;
> +}
> +EXPORT_SYMBOL(__firmware_stat_wait);
> +
> +void __firmware_stat_set(struct firmware_stat *fwst, unsigned long status)
> +{
> + WRITE_ONCE(fwst->status, status);
> + swake_up(&fwst->wq);
Do we need to notify everyone for FW_STATUS_LOADING status?
The driver users do not care for sure.
Thanks.
--
Dmitry
[toc] | [prev] | [next] | [standalone]
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
Back to top | Article view | linux.kernel
csiph-web