firmware: add an extensible system data helpers
Subsystems (3)
RFC 1/1 firmware: add an extensible system data helpers
From: "Luis R. Rodriguez" <[email protected]>
The firmware API has evolved over the years slowly, as it grows we extend it by adding new routines or at times we extend existing routines with more or less arguments. This doesn't scale well, when new arguments are added to existing routines it means we need to traverse the kernel with a slew of collateral evolutions to adjust old driver users. The firmware API is also now being used for things outside of the scope of what typically would be considered "firmware", an example here is the p54 driver enables users to provide a custom EEPROM through this interface. Another example is optional CPU microcode updates.
There are other subsystems which would like to make use of the APIs for similar things but have different requirements and criteria which they'd like to be met for the requested file. If different requirements are needed it would again mean adding more arguments and making a slew of collateral evolutions, or adding yet-another-new-API-call.
Instead of extending the existing firmware API even more this provides an new extensible API which can be used to supercede the old firmware API without causing a series of collateral evolutions as requirements grow. This leaves the old firmware API as-is, ignores all consideration for usermode-helpers, labels the new API to reflect its broad use outside of the scope of firmware: system data helpers, and builds on top of the original firmware core code.
The new extensible "system data" set of helpers accepts that there really are only two types of requests for accessing system data:
a) synchronous requests
b) asynchronous requests
Both of these requests may have a different set of requirements which must be met. These requirements can simply be passed as a descriptors to each type of request. The descriptor can be extended over time to support different requirements as the kernel evolves.
Using the new system data helpers is only necessary if you have requirements outside of what the existing old firmware API accepts. We encourage developers to leave the old API as-is and extend the new descriptors and system data code to provide support for new features.
A few simple features added as part of the new set of system data request APIs, other than making the new API easily extensible for the future:
- By default the kernel will free the system data file for you after your callbacks are called, you however are allowed to request to that you wish to keep the system data file on the descriptor. This is dealt with by requiring a consumer callback for the system data file.
- Allow both asynchronous and synchronous request to specify that system data files are optional. With the old APIs we had added one full API call, request_firmware_direct() just for this purpose -- although it should be noted another of its goal was to also skip the usermode helper. The system data request APIs allow for you to annotate that a system data file is optional for both synchronous or asynchronous requests through the same two basic set of APIs.
- Usermode helpers are completely ignored, always
- The system data request APIs currently match the old synchronous firmware API calls to refcounted firmware_class module, but it should be easy to add support now to enable also refcounting the caller's module should it be be needed. Likewise the system data request APIs match the old asynchronous firmware API call and refcounts the caller's module.
In order to try to help phase out user mode helpers this makes no use of the old user mode helper code *at all*, and if we wish to can easily phase this code out with time then.
---
Although the design and goals behind firmware signing are still being discussed, one thing is clear: we need an extensible firmware API. This patch set then just address the extensibility of the firmware_class and leave firmware signing to be addressed later.
In my previous firmware signing patch set I had added firmware signing *first* and later introduced this set of APIs *after* with the idea to let callers be able to override system defaults and provide custom signature requirements. For instance I had considered the possibility of having cfg80211 customize its signing requirements under its own Kconfig option outside of the scope of firmware signing in order to replace CRDA with in-kernel functionality. To support this we'd have to enable callers to customize their firmware signing requirements somehow. Recently its been discussed that perhaps we may want to let all callers from the start to provide a specific a sha256sum of a key which we could then use to vet a signature for. In order to support that we'd need to be able to let callers specify more arguments into the firmware_class API *prior* to adding firmware signing code.
Having an extensible firmware API in place first would enable the flexibility to let us decide what requirements we want to put in place for firmware signing without concern for making a slew of collateral evolutions. This also gives us the option, if we want it, to enable firmware signing to be an explicit driver opt-in feature rather than a huge automatic tree wide effect as with module signing. It does not have to be this way -- but we'd have this flexibility with the system data API going in first. For instance, one big difference here obviously is that these new exports are all EXPORT_SYMBOL_GPL() therefore proprietary drivers would not technically be able to make use of of firmware signing if we wanted it that way. I'll note that this was not my original intention, my first series added firmware signing support behind the scenes to all firmware_request*() APIs, however, if we want to be able to customize signing requests from the start, then this could mean making this a feature only for drivers that wish to opt-in to this new feature set.
As noted, firmware signing design is still being discussed, but as a hint, the way I'd envision this is that once we decide how keys would be managed and purposed we'd also enable LSM hooks to review the system data request descriptor, and these hooks would enable the LSM hooks to tell firmware_class it can skip over the internal system data signing verification if the LSM hook can meet the criteria requested in the descriptor.
Lastly, I think its time to phase out the usermode helper, and I think this would provide an outlet of how to do this.
Documentation/firmware_class/system_data.txt | 71 +++++++ drivers/base/firmware_class.c | 291 +++++++++++++++++++++++++++ include/linux/sysdata.h | 208 +++++++++++++++++++ 3 files changed, 570 insertions(+) create mode 100644 Documentation/firmware_class/system_data.txt create mode 100644 include/linux/sysdata.h
Documentation/firmware_class/system_data.txt new file +71 -0
@@ -0,0 +1,71 @@ +System data requests API +======================== + +As the kernel evolves we keep extending the firmware_class set of APIs +with more or less arguments, this creates a slew of collateral evolutions. +The set of users of firmware request APIs has also grown now to include +users which are not looking for "firmware" per se, but instead general +system data files which for one reason or another has been decided to be +kept oustide of the kernel, and/or to allow dynamic updates. The system data +request set of APIs addresses rebranding of firmware as generic system data +files, and provides a way to enable these APIs to easily be extended without +much collateral evolutions. + +System data modes of operation +============================== + +There are only two types of modes of operation for system data requests: + + * synchronous - sysdata_file_request() + * asynchronous - sysdata_file_request_async() + +Synchronous requests expect requests to be done immediately, asynchronous +requests enable requests to be scheduled for a later time. + +System data file descriptor +=========================== + +Variations of types of system data requests are specified by a system data +request descriptor. The system data request descriptor can grow as with new +fields as requirements grow. The old firmware API provides two synchronous +requests: request_firmware() and request_firmware_direct(), the later allowing +the caller to specify that the "system data file" is optional. The system data +request API allows a caller to set the optional nature of the system data file +on the system data file descriptor using the same synchronous API. Since this +requirement is part of the descriptor it also allows asynchronous requests +to specify that the system data file is optional. + +Reference counting and releasing the system data file +===================================================== + +As with the old firmware API both the device and module are bumped with +reference counts during the system data requests. This prevents removal +of the device and module making the system data request call until the +system data request callbacks have completed, either synchronously or +asynchronously. + +The old firmware APIs refcounted the firmware_class module for synchronous +requests, meanwhile asynchronous requests refcounted the caller's module. +The system data request API currently mimic this behaviour, for synchronous +requests the firmware_class module is refcounted through the use of +dfl_sync_reqs, although if in the future we may later enable use of +also refcounting the caller's module as well. Likewise in the future we +may extend asynchronous calls to refcount the firmware_class module. + +Typical use of the old synchronous firmware APIs consist of the caller +requesting for "system data", consuming it after a request and finally +freeing it. Typical asynchronous use of the old firmware APIs consist of +the caller requesting for "system data" and then finally freeing it on +asynchronous callback. + +The system data request API enables callers to provide a callback for both +synchronous and asynchronous requests and since consumption can be expected +in these callbacks it frees it for you by default after callback handlers +are issued. If you wish to keep the system data around after your callbacks +you must specify this through the system data request descriptor. + +User mode helper +================ + +The old firmware API provided support for an optional user mode helper. The +new system data request API abandons all notions of the usermode helper.
drivers/base/firmware_class.c +291 -0
315 lines not on this page · raw message
include/linux/sysdata.h new file +208 -0
208 lines not on this page · raw message
Signature · 1 line
2.3.2.209.gd67f9d5.dirty