diff mbox series

[v3] module: create weak dependecies

Message ID 20240510085726.327831-1-jtornosm@redhat.com (mailing list archive)
State Handled Elsewhere
Headers show
Series [v3] module: create weak dependecies | expand

Commit Message

Jose Ignacio Tornos Martinez May 10, 2024, 8:57 a.m. UTC
It has been seen that for some network mac drivers (i.e. lan78xx) the
related module for the phy is loaded dynamically depending on the current
hardware. In this case, the associated phy is read using mdio bus and then
the associated phy module is loaded during runtime (kernel function
phy_request_driver_module). However, no software dependency is defined, so
the user tools will no be able to get this dependency. For example, if
dracut is used and the hardware is present, lan78xx will be included but no
phy module will be added, and in the next restart the device will not work
from boot because no related phy will be found during initramfs stage.

In order to solve this, we could define a normal 'pre' software dependency
in lan78xx module with all the possible phy modules (there may be some),
but proceeding in that way, all the possible phy modules would be loaded
while only one is necessary.

The idea is to create a new type of dependency, that we are going to call
'weak' to be used only by the user tools that need to detect this situation.
In that way, for example, dracut could check the 'weak' dependency of the
modules involved in order to install these dependencies in initramfs too.
That is, for the commented lan78xx module, defining the 'weak' dependency
with the possible phy modules list, only the necessary phy would be loaded
on demand keeping the same behavior, but all the possible phy modules would
be available from initramfs.

The 'weak' dependency support has been included in kmod:
https://github.com/kmod-project/kmod/commit/05828b4a6e9327a63ef94df544a042b5e9ce4fe7
But, take into account that this can only be used if depmod is new enough.
If it isn't, depmod will have the same behavior as always (keeping backward
compatibility) and the information for the 'weak' dependency will not be
provided.

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
---
V2 -> V3:
- Include note about backward compatibility.
- Balance the /* and */.
V1 -> V2:
- Include reference to 'weak' dependency support in kmod.

 include/linux/module.h | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Lucas De Marchi May 14, 2024, 2:25 p.m. UTC | #1
On Fri, May 10, 2024 at 10:57:22AM GMT, Jose Ignacio Tornos Martinez wrote:
>It has been seen that for some network mac drivers (i.e. lan78xx) the
>related module for the phy is loaded dynamically depending on the current
>hardware. In this case, the associated phy is read using mdio bus and then
>the associated phy module is loaded during runtime (kernel function
>phy_request_driver_module). However, no software dependency is defined, so
>the user tools will no be able to get this dependency. For example, if
>dracut is used and the hardware is present, lan78xx will be included but no
>phy module will be added, and in the next restart the device will not work
>from boot because no related phy will be found during initramfs stage.
>
>In order to solve this, we could define a normal 'pre' software dependency
>in lan78xx module with all the possible phy modules (there may be some),
>but proceeding in that way, all the possible phy modules would be loaded
>while only one is necessary.
>
>The idea is to create a new type of dependency, that we are going to call
>'weak' to be used only by the user tools that need to detect this situation.
>In that way, for example, dracut could check the 'weak' dependency of the
>modules involved in order to install these dependencies in initramfs too.
>That is, for the commented lan78xx module, defining the 'weak' dependency
>with the possible phy modules list, only the necessary phy would be loaded
>on demand keeping the same behavior, but all the possible phy modules would
>be available from initramfs.
>
>The 'weak' dependency support has been included in kmod:
>https://github.com/kmod-project/kmod/commit/05828b4a6e9327a63ef94df544a042b5e9ce4fe7
>But, take into account that this can only be used if depmod is new enough.
>If it isn't, depmod will have the same behavior as always (keeping backward
>compatibility) and the information for the 'weak' dependency will not be
>provided.
>
>Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>


Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>

thanks
Lucas De Marchi

>---
>V2 -> V3:
>- Include note about backward compatibility.
>- Balance the /* and */.
>V1 -> V2:
>- Include reference to 'weak' dependency support in kmod.
>
> include/linux/module.h | 6 ++++++
> 1 file changed, 6 insertions(+)
>
>diff --git a/include/linux/module.h b/include/linux/module.h
>index 1153b0d99a80..2a056017df5b 100644
>--- a/include/linux/module.h
>+++ b/include/linux/module.h
>@@ -173,6 +173,12 @@ extern void cleanup_module(void);
>  */
> #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep)
>
>+/*
>+ * Weak module dependencies. See man modprobe.d for details.
>+ * Example: MODULE_WEAKDEP("module-foo")
>+ */
>+#define MODULE_WEAKDEP(_weakdep) MODULE_INFO(weakdep, _weakdep)
>+
> /*
>  * MODULE_FILE is used for generating modules.builtin
>  * So, make it no-op when this is being built as a module
>-- 
>2.44.0
>
Luis Chamberlain June 18, 2024, 7:53 p.m. UTC | #2
On Tue, May 14, 2024 at 09:25:55AM -0500, Lucas De Marchi wrote:
> On Fri, May 10, 2024 at 10:57:22AM GMT, Jose Ignacio Tornos Martinez wrote:
> > It has been seen that for some network mac drivers (i.e. lan78xx) the
> > related module for the phy is loaded dynamically depending on the current
> > hardware. In this case, the associated phy is read using mdio bus and then
> > the associated phy module is loaded during runtime (kernel function
> > phy_request_driver_module). However, no software dependency is defined, so
> > the user tools will no be able to get this dependency. For example, if
> > dracut is used and the hardware is present, lan78xx will be included but no
> > phy module will be added, and in the next restart the device will not work
> > from boot because no related phy will be found during initramfs stage.
> > 
> > In order to solve this, we could define a normal 'pre' software dependency
> > in lan78xx module with all the possible phy modules (there may be some),
> > but proceeding in that way, all the possible phy modules would be loaded
> > while only one is necessary.
> > 
> > The idea is to create a new type of dependency, that we are going to call
> > 'weak' to be used only by the user tools that need to detect this situation.
> > In that way, for example, dracut could check the 'weak' dependency of the
> > modules involved in order to install these dependencies in initramfs too.
> > That is, for the commented lan78xx module, defining the 'weak' dependency
> > with the possible phy modules list, only the necessary phy would be loaded
> > on demand keeping the same behavior, but all the possible phy modules would
> > be available from initramfs.
> > 
> > The 'weak' dependency support has been included in kmod:
> > https://github.com/kmod-project/kmod/commit/05828b4a6e9327a63ef94df544a042b5e9ce4fe7
> > But, take into account that this can only be used if depmod is new enough.
> > If it isn't, depmod will have the same behavior as always (keeping backward
> > compatibility) and the information for the 'weak' dependency will not be
> > provided.
> > 
> > Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
> 
> 
> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>

Thanks! Applied and pushed to modules-next.

  Luis
diff mbox series

Patch

diff --git a/include/linux/module.h b/include/linux/module.h
index 1153b0d99a80..2a056017df5b 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -173,6 +173,12 @@  extern void cleanup_module(void);
  */
 #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep)
 
+/*
+ * Weak module dependencies. See man modprobe.d for details.
+ * Example: MODULE_WEAKDEP("module-foo")
+ */
+#define MODULE_WEAKDEP(_weakdep) MODULE_INFO(weakdep, _weakdep)
+
 /*
  * MODULE_FILE is used for generating modules.builtin
  * So, make it no-op when this is being built as a module