mbox series

[v4,0/4] Properly handle module_kobject creation

Message ID 20250227184930.34163-1-shyamsaini@linux.microsoft.com (mailing list archive)
Headers show
Series Properly handle module_kobject creation | expand

Message

Shyam Saini Feb. 27, 2025, 6:49 p.m. UTC
Hi Everyone,

This patch series fixes handling of module_kobject creation.
A driver expect module_kset list populated with its corresponding
module_kobject to create its /sys/module/<built-in-module>/drivers
directory.

Since,
[1] commit 96a1a2412acb ("kernel/params.c: defer most of param_sysfs_init() to late_initcall time")
Call to populate module_kset list is deferred to save init time so that
external watchdog doesn't fireup on some boards and Linux can take
responsibility of feeding watchdog before it spuriously resets the
system. However, [1] this fix caused another issue i.e, consumers
of module_kset can't get related module_kobject during driver
initialisation and hence can't create their
/sys/module/<built-in-module>/drivers directory.

Consequently, [1] breaks user-space applications for eg: DPDK, which
expects /sys/module/vfio_pci/drivers/pci:vfio-pci/new_id to be present.

The second issue was reported and the [2] revert of [1] was
proposed. However, [2] the Revert doesn't address the original issue
reported in [1].

This patch series addresses both issues reported in [1] and [2].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=96a1a2412acb
[2] https://lore.kernel.org/lkml/20250130225803.321004-1-shyamsaini@linux.microsoft.com/

Thanks,
Shyam

---
- Changes in v4;
  - Restore accidentally removed empty line in kernel_add_sysfs_param()
  - Prepare this patch series for stable tree inclusion

- Changes in v3:
  - Split refactoring and globalisation of lookup_or_create_module_kobject() into two patches
  - Fix commit message to better describe the change.
  - Use IS_ENABLED instead of #ifdef macro construct
  - Undo the moving of __modinit macro construct into module.h
  - drop __modinit from lookup_or_create_module_kobject() declaration
  - Link: https://lore.kernel.org/lkml/20250211214842.1806521-1-shyamsaini@linux.microsoft.com/

Changes in v2:
- Undo the moving of to_module* and lookup_or_create_module_kobject() into module.h
- Refactor and globalize lookup_or_create_module_kobject()
- move __modinit macro construct to module.h
- Fix commit message typos
- Link: https://lore.kernel.org/lkml/20250207054538.1110340-1-shyamsaini@linux.microsoft.com/


Changes in v1: 
- Rename locate_module_kobject() to lookup_or_create_module_kobject() to accurately
  describe its operations.
- Moves lookup_or_create_module_kobject() and to_module* macros to module.h, so
  that driver code can use these.
- Handle module_kobject creation and population of module_kset list to fix [1]
  and [2] issues.
- Link: https://lore.kernel.org/lkml/20250204052222.1611510-1-shyamsaini@linux.microsoft.com/

Changes in RFC:
         Reverts commit 96a1a2412acb ("kernel/params.c: defer most of param_sysfs_init() to late_initcall time")

Shyam Saini (4):
  kernel: param: rename locate_module_kobject
  kernel: refactor lookup_or_create_module_kobject()
  kernel: globalize lookup_or_create_module_kobject()
  drivers: base: handle module_kobject creation

 drivers/base/module.c  | 13 +++++-------
 include/linux/module.h |  2 ++
 kernel/params.c        | 47 ++++++++++++++++++++----------------------
 3 files changed, 29 insertions(+), 33 deletions(-)

Comments

Petr Pavlu March 5, 2025, 9:55 a.m. UTC | #1
On 2/27/25 19:49, Shyam Saini wrote:
> Hi Everyone,
> 
> This patch series fixes handling of module_kobject creation.
> A driver expect module_kset list populated with its corresponding
> module_kobject to create its /sys/module/<built-in-module>/drivers
> directory.
> 
> Since,
> [1] commit 96a1a2412acb ("kernel/params.c: defer most of param_sysfs_init() to late_initcall time")
> Call to populate module_kset list is deferred to save init time so that
> external watchdog doesn't fireup on some boards and Linux can take
> responsibility of feeding watchdog before it spuriously resets the
> system. However, [1] this fix caused another issue i.e, consumers
> of module_kset can't get related module_kobject during driver
> initialisation and hence can't create their
> /sys/module/<built-in-module>/drivers directory.
> 
> Consequently, [1] breaks user-space applications for eg: DPDK, which
> expects /sys/module/vfio_pci/drivers/pci:vfio-pci/new_id to be present.
> 
> The second issue was reported and the [2] revert of [1] was
> proposed. However, [2] the Revert doesn't address the original issue
> reported in [1].
> 
> This patch series addresses both issues reported in [1] and [2].
> 
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=96a1a2412acb
> [2] https://lore.kernel.org/lkml/20250130225803.321004-1-shyamsaini@linux.microsoft.com/

This looks ok to me. I only think the Fixes: tag should have remained
solely on the last patch in the series as that is the actual fix. I'll
adjust it when picking up the patches.

I'm going to wait for a few days if others still would like to comment
and then plan to queue this on modules-next.

@Greg, could I please get an Acked-by from you on the last patch in the
series as this affects the code in the driver core?
Shyam Saini March 5, 2025, 8:01 p.m. UTC | #2
Hi Petr,

On Wed, Mar 05, 2025 at 10:55:03AM +0100, Petr Pavlu wrote:
> On 2/27/25 19:49, Shyam Saini wrote:
> > Hi Everyone,
> > 
> > This patch series fixes handling of module_kobject creation.
> > A driver expect module_kset list populated with its corresponding
> > module_kobject to create its /sys/module/<built-in-module>/drivers
> > directory.
> > 
> > Since,
> > [1] commit 96a1a2412acb ("kernel/params.c: defer most of param_sysfs_init() to late_initcall time")
> > Call to populate module_kset list is deferred to save init time so that
> > external watchdog doesn't fireup on some boards and Linux can take
> > responsibility of feeding watchdog before it spuriously resets the
> > system. However, [1] this fix caused another issue i.e, consumers
> > of module_kset can't get related module_kobject during driver
> > initialisation and hence can't create their
> > /sys/module/<built-in-module>/drivers directory.
> > 
> > Consequently, [1] breaks user-space applications for eg: DPDK, which
> > expects /sys/module/vfio_pci/drivers/pci:vfio-pci/new_id to be present.
> > 
> > The second issue was reported and the [2] revert of [1] was
> > proposed. However, [2] the Revert doesn't address the original issue
> > reported in [1].
> > 
> > This patch series addresses both issues reported in [1] and [2].
> > 
> > [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=96a1a2412acb
> > [2] https://lore.kernel.org/lkml/20250130225803.321004-1-shyamsaini@linux.microsoft.com/
> 
> This looks ok to me. I only think the Fixes: tag should have remained
> solely on the last patch in the series as that is the actual fix. I'll
> adjust it when picking up the patches.
> 

Thank you for pointing that out, will take care of it next time.

I makred rest of the dependent patches for stable inclusion as per this [1] doc and, 
there was a warning from checkpatch scripts without Fixes: tag
WARNING: The commit message has 'stable@', `perhaps it also needs a 'Fixes:' tag?

Thanks,
Shyam

[1] https://docs.kernel.org/process/stable-kernel-rules.html#option-1