Skip to contentSkip to conversation

pwm: lpss: module namespace fixes

PATCH Superseded Uwe Kleine-König 3 participants 11 messages Dec 3, 2024 – Jan 21, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover pwm: lpss: module namespace fixes

Hello,

while working on a patch quite similar to
https://lore.kernel.org/all/[email protected]/
I noticed that the module name space in drivers/pwm/pwm-lpss.c isn't used. When I fixed that (patch #2) the intel pinctrl driver was unhappy with

WARNING: modpost: module pinctrl-intel uses symbol devm_pwm_lpss_probe from namespace PWM_LPSS, but does not import it.

so the first patch prevents this from happening.

This conflicts with ceb8bf2ceaa77fe222fe8fe32cb7789c9099ddf1 that is currently in Linus' tree. I'll take care about that.

Best regards
Uwe

Uwe Kleine-König (2):
pwm: lpss: Move namespace import into a header
pwm: lpss: Define DEFAULT_SYMBOL_NAMESPACE earlier

 drivers/pwm/pwm-lpss-pci.c                 | 2 --
 drivers/pwm/pwm-lpss-platform.c            | 2 --
 drivers/pwm/pwm-lpss.c                     | 4 ++--
 include/linux/platform_data/x86/pwm-lpss.h | 7 +++++++
 4 files changed, 9 insertions(+), 6 deletions(-)

base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37

Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/2 pwm: lpss: Move namespace import into a header

Each user of the exported symbols related to the pwm-lpss driver needs to import the matching namespace. So this can just be done in the header together with the prototypes.

This fixes drivers/pinctrl/intel/pinctrl-intel.c which failed to import that namespace before. (However this didn't hurt because the pwm-lpss module namespace isn't used; see the next commit.)

---
 drivers/pwm/pwm-lpss-pci.c                 | 2 --
 drivers/pwm/pwm-lpss-platform.c            | 2 --
 include/linux/platform_data/x86/pwm-lpss.h | 7 +++++++
 3 files changed, 7 insertions(+), 4 deletions(-)
drivers/pwm/pwm-lpss-pci.c +0 -2
index f7ece2809e6b..8615c44c1034 100644
@@ -8,7 +8,6 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/pm_runtime.h>
 
@@ -70,4 +69,3 @@ module_pci_driver(pwm_lpss_driver_pci);
 
 MODULE_DESCRIPTION("PWM PCI driver for Intel LPSS");
 MODULE_LICENSE("GPL v2");
-MODULE_IMPORT_NS(PWM_LPSS);
drivers/pwm/pwm-lpss-platform.c +0 -2
index 5130238a4567..3de1ab2cff54 100644
@@ -9,7 +9,6 @@
 
 #include <linux/kernel.h>
 #include <linux/mod_devicetable.h>
-#include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/property.h>
@@ -78,5 +77,4 @@ module_platform_driver(pwm_lpss_driver_platform);
 
 MODULE_DESCRIPTION("PWM platform driver for Intel LPSS");
 MODULE_LICENSE("GPL v2");
-MODULE_IMPORT_NS(PWM_LPSS);
 MODULE_ALIAS("platform:pwm-lpss");
include/linux/platform_data/x86/pwm-lpss.h +7 -0
index 752c06b47cc8..0a1025f6cd58 100644
@@ -4,6 +4,7 @@
 #ifndef __PLATFORM_DATA_X86_PWM_LPSS_H
 #define __PLATFORM_DATA_X86_PWM_LPSS_H
 
+#include <linux/module.h>
 #include <linux/types.h>
 
 struct device;
@@ -30,4 +31,10 @@ struct pwm_lpss_boardinfo {
 struct pwm_chip *devm_pwm_lpss_probe(struct device *dev, void __iomem *base,
 				     const struct pwm_lpss_boardinfo *info);
 
+/*
+ * The above function and the pwm_lpss_boardinfo variables in
+ * drivers/pwm/pwm-lpss.h are defined in the PWM_LPSS namespace.
+ */
+MODULE_IMPORT_NS(PWM_LPSS);
+
 #endif	/* __PLATFORM_DATA_X86_PWM_LPSS_H */
Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH 1/2] pwm: lpss: Move namespace import into a header

Quoted 7 lines · Uwe Kleine-König

Each user of the exported symbols related to the pwm-lpss driver needs to import the matching namespace. So this can just be done in the header together with the prototypes.

This fixes drivers/pinctrl/intel/pinctrl-intel.c which failed to import that namespace before. (However this didn't hurt because the pwm-lpss module namespace isn't used; see the next commit.)

I disagree on this change, I think it had been discussed already.

The header must not provide any module importing features as it effectively diminishes the point of namespace. Any (ab)user can include just a header and be okay with that.

Besides that, you should have based this on recent changes in the NS area of the module symbols, i.e. module namespaces needs to be provided as string literals.

See last few commits in Linus' tree as of today.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Re: [PATCH 1/2] pwm: lpss: Move namespace import into a header

Hello Andy,

Quoted 10 lines · Andy Shevchenko
Quoted 7 lines · Uwe Kleine-König

Each user of the exported symbols related to the pwm-lpss driver needs to import the matching namespace. So this can just be done in the header together with the prototypes.

This fixes drivers/pinctrl/intel/pinctrl-intel.c which failed to import that namespace before. (However this didn't hurt because the pwm-lpss module namespace isn't used; see the next commit.)

I disagree on this change, I think it had been discussed already.

Who discussed this? If I was involved, I don't remember. So if you have a link, that would be great.

Quoted 3 lines

The header must not provide any module importing features as it effectively diminishes the point of namespace. Any (ab)user can include just a header and be okay with that.

Huh? Any abuser can also just do the IMPORT_NS statement? Module namespaces are not a safeguard against bad code? So I don't see why making it simple for the regular users should be the wrong choice.

Actually I think this is very elegant because this way all needs to use these symbols (i.e. prototype and namespace) are in a single place and users just do the #include and get all the preconditions.

Quoted 3 lines

Besides that, you should have based this on recent changes in the NS area of the module symbols, i.e. module namespaces needs to be provided as string literals.

I coordinated my patch set with the pwm maintainer and he is ok with it :-) That's why I wrote "This conflicts with ceb8bf2ceaa77fe222fe8fe32cb7789c9099ddf1 that is currently in Linus' tree. I'll take care about that." in the cover letter.

Best regards
Uwe

#4 lore raw

Re: [PATCH 1/2] pwm: lpss: Move namespace import into a header

Quoted 6 lines · Uwe Kleine-König
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Uwe Kleine-König

Each user of the exported symbols related to the pwm-lpss driver needs to import the matching namespace. So this can just be done in the header together with the prototypes.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

This fixes drivers/pinctrl/intel/pinctrl-intel.c which failed to import that namespace before. (However this didn't hurt because the pwm-lpss module namespace isn't used; see the next commit.)

I disagree on this change, I think it had been discussed already.

Who discussed this? If I was involved, I don't remember. So if you have a link, that would be great.

Sure, https://lore.kernel.org/linux-pwm/[email protected]/
you were a participant there.

Quoted 11 lines
Quoted 3 lines

The header must not provide any module importing features as it effectively diminishes the point of namespace. Any (ab)user can include just a header and be okay with that.

Huh? Any abuser can also just do the IMPORT_NS statement? Module namespaces are not a safeguard against bad code? So I don't see why making it simple for the regular users should be the wrong choice.

Actually I think this is very elegant because this way all needs to use these symbols (i.e. prototype and namespace) are in a single place and users just do the #include and get all the preconditions.

Recent LWN https://lwn.net/Articles/998221/ article describes in more details what I implied under abuser here.

Quoted 8 lines
Quoted 3 lines

Besides that, you should have based this on recent changes in the NS area of the module symbols, i.e. module namespaces needs to be provided as string literals.

I coordinated my patch set with the pwm maintainer and he is ok with it :-) That's why I wrote "This conflicts with ceb8bf2ceaa77fe222fe8fe32cb7789c9099ddf1 that is currently in Linus' tree. I'll take care about that." in the cover letter.

Other subsystems simply backmerged those changes. Note, at any time one may consider origin/master as an immutable (at the point of a given change). It might be better (if no urgent need) to wait for rc2 and merge it before doing other changes.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH 1/2] pwm: lpss: Move namespace import into a header

Hello Andy,

Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Uwe Kleine-König
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Uwe Kleine-König

Each user of the exported symbols related to the pwm-lpss driver needs to import the matching namespace. So this can just be done in the header together with the prototypes.

This fixes drivers/pinctrl/intel/pinctrl-intel.c which failed to import that namespace before. (However this didn't hurt because the pwm-lpss module namespace isn't used; see the next commit.)

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I disagree on this change, I think it had been discussed already.

Who discussed this? If I was involved, I don't remember. So if you have a link, that would be great.

Sure, https://lore.kernel.org/linux-pwm/[email protected]/
you were a participant there.

Ah that. When I read "it had been discussed already" I expected a discussion with an agreement in the end. Let me note that you chose the more complicated way back then (and I let you) and the result is that the pinctrl driver didn't get the (up to now not yet) needed import.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

The header must not provide any module importing features as it effectively diminishes the point of namespace. Any (ab)user can include just a header and be okay with that.

Huh? Any abuser can also just do the IMPORT_NS statement? Module namespaces are not a safeguard against bad code? So I don't see why making it simple for the regular users should be the wrong choice.

Quoted 6 lines
Quoted 3 lines

Actually I think this is very elegant because this way all needs to use these symbols (i.e. prototype and namespace) are in a single place and users just do the #include and get all the preconditions.

Recent LWN https://lwn.net/Articles/998221/ article describes in more details what I implied under abuser here.

Ok. But I don't see how this supports your case. Independent of where the import for a given namespace happens, you can see the used namespaces in modinfo and that is the only place where suspicious imports can be noted reliably. And MODULE_foo isn't relevant here as the namespace of the pwm-lpss driver combo is used in several modules.

I thought the point of namespaces is grouping of symbols and reduction of the set of globally available symbols to speed up module loading. I didn't have "duplicate IMPORT_NS statements to make it harder for bad out-of-tree code" on my radar and that shouldn't be a motivation if the price is that in-tree code faces the same constraints IMHO.

And I'm pretty sure, we won't prevent a bad actor from successfully using a symbol they should not, just because they need an include *and* an import.

Am I missing something?

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

Besides that, you should have based this on recent changes in the NS area of the module symbols, i.e. module namespaces needs to be provided as string literals.

I coordinated my patch set with the pwm maintainer and he is ok with it :-) That's why I wrote "This conflicts with ceb8bf2ceaa77fe222fe8fe32cb7789c9099ddf1 that is currently in Linus' tree. I'll take care about that." in the cover letter.

Quoted 4 lines

Other subsystems simply backmerged those changes. Note, at any time one may consider origin/master as an immutable (at the point of a given change). It might be better (if no urgent need) to wait for rc2 and merge it before doing other changes.

I'm well aware of my options. Thanks
Uwe

#6 lore raw

Re: [PATCH 1/2] pwm: lpss: Move namespace import into a header

Quoted 4 lines · Uwe Kleine-König
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Uwe Kleine-König
Quoted 1 line · Andy Shevchenko

On Tue, Dec 03, 2024 at 06:16:14PM +0100, Uwe Kleine-König wrote:

...

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines

The header must not provide any module importing features as it effectively diminishes the point of namespace. Any (ab)user can include just a header and be okay with that.

Huh? Any abuser can also just do the IMPORT_NS statement? Module namespaces are not a safeguard against bad code? So I don't see why making it simple for the regular users should be the wrong choice.

Actually I think this is very elegant because this way all needs to use these symbols (i.e. prototype and namespace) are in a single place and users just do the #include and get all the preconditions.

Quoted 8 lines
Quoted 2 lines

Recent LWN https://lwn.net/Articles/998221/ article describes in more details what I implied under abuser here.

Ok. But I don't see how this supports your case. Independent of where the import for a given namespace happens, you can see the used namespaces in modinfo and that is the only place where suspicious imports can be noted reliably. And MODULE_foo isn't relevant here as the namespace of the pwm-lpss driver combo is used in several modules.

The initial point that the (ab)users will be visible at review stage. Yes, runtime restrictions are more difficult to enforce.

Quoted 11 lines

I thought the point of namespaces is grouping of symbols and reduction of the set of globally available symbols to speed up module loading. I didn't have "duplicate IMPORT_NS statements to make it harder for bad out-of-tree code" on my radar and that shouldn't be a motivation if the price is that in-tree code faces the same constraints IMHO.

And I'm pretty sure, we won't prevent a bad actor from successfully using a symbol they should not, just because they need an include *and* an import.

Am I missing something?

They may not need the include actually, as they can just tell the compiler with extern keyword to look for a prototype somewhere else. In any case let's return to the main topic here. My proposal is to add the respective module namespace import into pin control driver.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

Re: [PATCH 1/2] pwm: lpss: Move namespace import into a header

In reply to Andy Shevchenko

Hello Linus,

Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Uwe Kleine-König

Each user of the exported symbols related to the pwm-lpss driver needs to import the matching namespace. So this can just be done in the header together with the prototypes.

This fixes drivers/pinctrl/intel/pinctrl-intel.c which failed to import that namespace before. (However this didn't hurt because the pwm-lpss module namespace isn't used; see the next commit.)

Quoted 5 lines

I disagree on this change, I think it had been discussed already.

The header must not provide any module importing features as it effectively diminishes the point of namespace. Any (ab)user can include just a header and be okay with that.

Andy and I disagree about this change. If you happen to not have the patch in your inbox, see
https://lore.kernel.org/linux-pwm/3a99048a52aeee356d01dbf7f2f06e6e0826ed78.1733245406.git.ukleinek@kernel.org/
.

Would you please volunteer as the impartial judge here as you're the upstream maintainer of drivers/pinctrl/intel/pinctrl-intel.c?

The TL;DR; is: Do you prefer a single MODULE_IMPORT_NS() in a header, or should every consumer driver explicitly have its own MODULE_IMPORT_NS() invokation? I won't repeat the arguments because I think I cannot present them without making my opinion too obvious, so please see the discussion between Andy and me in the above linked thread.

Best regards and thanks,
Uwe

#8 lore raw

Re: [PATCH 1/2] pwm: lpss: Move namespace import into a header

Quoted 6 lines · Uwe Kleine-König

Andy and I disagree about this change. If you happen to not have the patch in your inbox, see
https://lore.kernel.org/linux-pwm/3a99048a52aeee356d01dbf7f2f06e6e0826ed78.1733245406.git.ukleinek@kernel.org/

Would you please volunteer as the impartial judge here as you're the upstream maintainer of drivers/pinctrl/intel/pinctrl-intel.c?

What about those wise lines from Torvalds in
Documentation/process/management-style.rst:

The name of the game is to **avoid** having to make a decision. In particular, if somebody tells you "choose (a) or (b), we really need you to decide on this", you're in trouble as a manager. The people you manage had better know the details better than you, so if they come to you for a technical decision, you're screwed. You're clearly not competent to make that decision for them.

Quoted 3 lines

The TL;DR; is: Do you prefer a single MODULE_IMPORT_NS() in a header, or should every consumer driver explicitly have its own MODULE_IMPORT_NS() invokation?

Intuitively I personally prefer using macros like that in every instance (in every consumer driver). But it's not like I can give any good reason for it, just intuition and what I would do.

Yours,
Linus Walleij

#9 lore raw

PATCH 2/2 pwm: lpss: Define DEFAULT_SYMBOL_NAMESPACE earlier

In reply to Uwe Kleine-König

DEFAULT_SYMBOL_NAMESPACE must be already defined when <linux/export.h> is included. So move the define above the include block.

With the DEFAULT_SYMBOL_NAMESPACE being defined too late, the exported symbols end up in the default namespace. So the modules making use of the symbols defined in pwm-lpss.c can import these just fine and just import the the PWM_LPSS namespace without any gain.

Fixes a3682d2fe3c3 ("pwm: lpss: Move exported symbols to PWM_LPSS namespace")
---
 drivers/pwm/pwm-lpss.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pwm/pwm-lpss.c +2 -2
index 867e2bc8c601..9519d1b06869 100644
@@ -10,6 +10,8 @@
  * Author: Alan Cox <[email protected]>
  */
 
+#define DEFAULT_SYMBOL_NAMESPACE PWM_LPSS
+
 #include <linux/bits.h>
 #include <linux/delay.h>
 #include <linux/io.h>
@@ -19,8 +21,6 @@
 #include <linux/pm_runtime.h>
 #include <linux/time.h>
 
-#define DEFAULT_SYMBOL_NAMESPACE PWM_LPSS
-
 #include "pwm-lpss.h"
 
 #define PWM				0x00000000
Signature · 1 line
2.45.2
#10 lore raw

Re: [PATCH 2/2] pwm: lpss: Define DEFAULT_SYMBOL_NAMESPACE earlier

Quoted 7 lines · Uwe Kleine-König

DEFAULT_SYMBOL_NAMESPACE must be already defined when <linux/export.h> is included. So move the define above the include block.

With the DEFAULT_SYMBOL_NAMESPACE being defined too late, the exported symbols end up in the default namespace. So the modules making use of the symbols defined in pwm-lpss.c can import these just fine and just import the the PWM_LPSS namespace without any gain.

Documentation disagrees with you. But, you are right, a lurking bug is here as we need to undef existing define.

Quoted 1 line

-#define DEFAULT_SYMBOL_NAMESPACE PWM_LPSS

Signature · 2 lines
With Best Regards,
Andy Shevchenko