fpga: bridge improve protection against low-level control module unloading
Subsystems (2)
cover fpga: bridge improve protection against low-level control module unloading
This RFC proposes a solution to keep protecting the fpga bridge against the unloading of the low-level control modules while addressing the limitations of the current implementation. Currently, the code assumes that the low-level module registers a driver for the parent device that is later used to take the module's refcount. This proposal removes this limitation by adding a module owner field to the fpga_bridge struct that can be set while registering the bridge.
The RFC patch is based on top of ("fpga: remove redundant checks for bridge ops").
https://lore.kernel.org/linux-fpga/[email protected]/
Marco Pagani (1):
fpga: bridge: improve protection against low-level control module
unloading
Documentation/driver-api/fpga/fpga-bridge.rst | 7 ++- drivers/fpga/fpga-bridge.c | 61 +++++++++++-------- include/linux/fpga/fpga-bridge.h | 10 ++- 3 files changed, 47 insertions(+), 31 deletions(-)
Signature · 1 line
2.43.0
RFC PATCH 1/1 fpga: bridge: improve protection against low-level control module unloading
Add a module owner field to the fpga_bridge struct and use it to take the low-level control module refcount instead of assuming that the parent device has a driver and using its owner pointer. The owner is now passed as an additional argument at registration time. To this end, the function for registering a bridge has been modified to take an additional parameter. The old registration function name is used for a helper macro that automatically sets the module that registers the fpga bridge as the owner. This ensures compatibility with existing low-level control modules and reduces the chances of inadvertently registering a bridge without setting the owner.
Update the documentation to keep it consistent with the new function for registering a bridge.
Other changes: opportunistically move put_device() from __fpga_bridge_get() to fpga_bridge_get() and of_fpga_bridge_get() to improve code clarity since the device refcount is taken in these functions.
--- Documentation/driver-api/fpga/fpga-bridge.rst | 7 ++- drivers/fpga/fpga-bridge.c | 61 +++++++++++-------- include/linux/fpga/fpga-bridge.h | 10 ++- 3 files changed, 47 insertions(+), 31 deletions(-)
Documentation/driver-api/fpga/fpga-bridge.rst +5 -2
@@ -6,9 +6,12 @@ API to implement a new FPGA bridge * struct fpga_bridge - The FPGA Bridge structure * struct fpga_bridge_ops - Low level Bridge driver ops -* fpga_bridge_register() - Create and register a bridge +* __fpga_bridge_register() - Create and register a bridge * fpga_bridge_unregister() - Unregister a bridge +The helper macro ``fpga_bridge_register()`` can be used to ease the +registration of a bridge. + .. kernel-doc:: include/linux/fpga/fpga-bridge.h :functions: fpga_bridge
@@ -16,7 +19,7 @@ API to implement a new FPGA bridge :functions: fpga_bridge_ops .. kernel-doc:: drivers/fpga/fpga-bridge.c - :functions: fpga_bridge_register + :functions: __fpga_bridge_register .. kernel-doc:: drivers/fpga/fpga-bridge.c :functions: fpga_bridge_unregister
drivers/fpga/fpga-bridge.c +35 -26
138 lines not on this page · raw message
include/linux/fpga/fpga-bridge.h +7 -3
@@ -45,6 +45,7 @@ struct fpga_bridge_info {* @dev: FPGA bridge device * @mutex: enforces exclusive reference to bridge * @br_ops: pointer to struct of FPGA bridge ops +* @br_ops_owner: module containing the br_ops * @info: fpga image specific information * @node: FPGA bridge list node * @priv: low level driver private date
@@ -54,6 +55,7 @@ struct fpga_bridge {struct device dev;struct mutex mutex;/* for exclusive reference to bridge */ const struct fpga_bridge_ops *br_ops; +struct module *br_ops_owner;struct fpga_image_info *info;struct list_head node;void *priv;
@@ -79,10 +81,12 @@ int of_fpga_bridge_get_to_list(struct device_node *np,struct fpga_image_info *info, struct list_head *bridge_list); +#define fpga_bridge_register (parent, name, br_ops, priv) \ + __fpga_bridge_register(parent, name, br_ops, priv, THIS_MODULE)struct fpga_bridge * -fpga_bridge_register (struct device *parent,const char *name, -const struct fpga_bridge_ops *br_ops, -void *priv); +__fpga_bridge_register (struct device *parent,const char *name, +const struct fpga_bridge_ops *br_ops,void *priv, +struct module *owner);void fpga_bridge_unregister (struct fpga_bridge *br);#endif /* _LINUX_FPGA_BRIDGE_H */
Signature · 1 line
2.43.0