Skip to contentSkip to conversation

lib/nodemask: inline wrappers around bitmap

PATCH In review Yury Norov 4 participants 18 messages Jul 23, 2022 – Aug 12, 2022

Subsystems (3)
lore
Share & tools
lore

Yury Norov

author maintainer
#0 lore raw

cover lib/nodemask: inline wrappers around bitmap

On top of [email protected]:/norov/linux.git bitmap-for-next.

There are just 2 functions in nodemask.c, both are thin wrappers around bitmap API. 1st patch of this series drops dependency on <asm/machdep.h for powerpc, which prevents from inlining those nodemask functions, and 2nd patch inlines them and drops nodemask.c.

Yury Norov (2):
powerpc: drop dependency on <asm/machdep.h> in archrandom.h lib/nodemask: inline next_node_in() and node_random()

 MAINTAINERS                           |  1 -
 arch/powerpc/include/asm/archrandom.h |  9 +-------
 arch/powerpc/kernel/setup-common.c    | 11 ++++++++++
 include/linux/nodemask.h              | 27 +++++++++++++++++++-----
 lib/Makefile                          |  2 +-
 lib/nodemask.c                        | 30 ---------------------------
 6 files changed, 35 insertions(+), 45 deletions(-)
 delete mode 100644 lib/nodemask.c
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/2 powerpc: drop dependency on <asm/machdep.h> in archrandom.h

archrandom.h includes <asm/machdep.h> to refer ppc_md. This causes circular header dependency, if generic nodemask.h includes random.h:

In file included from include/linux/cred.h:16,

                 from include/linux/seq_file.h:13,
                 from arch/powerpc/include/asm/machdep.h:6,
                 from arch/powerpc/include/asm/archrandom.h:5,
                 from include/linux/random.h:109,
                 from include/linux/nodemask.h:97,
                 from include/linux/list_lru.h:12,
                 from include/linux/fs.h:13,
                 from include/linux/compat.h:17,
                 from arch/powerpc/kernel/asm-offsets.c:12:
include/linux/sched.h:1203:9: error: unknown type name 'nodemask_t'
 1203 |         nodemask_t                      mems_allowed;
      |         ^~~~~~~~~~

Fix it by removing <asm/machdep.h> dependency from archrandom.h

---
 arch/powerpc/include/asm/archrandom.h |  9 +--------
 arch/powerpc/kernel/setup-common.c    | 11 +++++++++++
 2 files changed, 12 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/archrandom.h +1 -8
index 9a53e29680f4..21def59ef1a6 100644
@@ -4,7 +4,7 @@
 
 #ifdef CONFIG_ARCH_RANDOM
 
-#include <asm/machdep.h>
+bool __must_check arch_get_random_seed_long(unsigned long *v);
 
 static inline bool __must_check arch_get_random_long(unsigned long *v)
 {
@@ -16,13 +16,6 @@ static inline bool __must_check arch_get_random_int(unsigned int *v)
 	return false;
 }
 
-static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
-{
-	if (ppc_md.get_random_seed)
-		return ppc_md.get_random_seed(v);
-
-	return false;
-}
 
 static inline bool __must_check arch_get_random_seed_int(unsigned int *v)
 {
arch/powerpc/kernel/setup-common.c +11 -0
index eb0077b302e2..18c5fa5918bf 100644
@@ -171,6 +171,17 @@ EXPORT_SYMBOL_GPL(machine_power_off);
 void (*pm_power_off)(void);
 EXPORT_SYMBOL_GPL(pm_power_off);
 
+#ifdef CONFIG_ARCH_RANDOM
+bool __must_check arch_get_random_seed_long(unsigned long *v)
+{
+	if (ppc_md.get_random_seed)
+		return ppc_md.get_random_seed(v);
+
+	return false;
+}
+EXPORT_SYMBOL(arch_get_random_seed_long);
+#endif
+
 void machine_halt(void)
 {
 	machine_shutdown();
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

Quoted 19 lines · Yury Norov

archrandom.h includes <asm/machdep.h> to refer ppc_md. This causes circular header dependency, if generic nodemask.h includes random.h:

In file included from include/linux/cred.h:16,

                 from include/linux/seq_file.h:13,
                 from arch/powerpc/include/asm/machdep.h:6,
                 from arch/powerpc/include/asm/archrandom.h:5,
                 from include/linux/random.h:109,
                 from include/linux/nodemask.h:97,
                 from include/linux/list_lru.h:12,
                 from include/linux/fs.h:13,
                 from include/linux/compat.h:17,
                 from arch/powerpc/kernel/asm-offsets.c:12:
include/linux/sched.h:1203:9: error: unknown type name 'nodemask_t'
 1203 |         nodemask_t                      mems_allowed;
      |         ^~~~~~~~~~

Fix it by removing <asm/machdep.h> dependency from archrandom.h

...

Quoted 1 line

EXPORT_SYMBOL_GPL(pm_power_off);

^^^ (Note this and read below)

...

Quoted 1 line

+EXPORT_SYMBOL(arch_get_random_seed_long);

It can't be like this. Brief browsing of the callees shows that.

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

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

Quoted 25 lines · Andy Shevchenko
Quoted 19 lines · Yury Norov

archrandom.h includes <asm/machdep.h> to refer ppc_md. This causes circular header dependency, if generic nodemask.h includes random.h:

In file included from include/linux/cred.h:16,

                 from include/linux/seq_file.h:13,
                 from arch/powerpc/include/asm/machdep.h:6,
                 from arch/powerpc/include/asm/archrandom.h:5,
                 from include/linux/random.h:109,
                 from include/linux/nodemask.h:97,
                 from include/linux/list_lru.h:12,
                 from include/linux/fs.h:13,
                 from include/linux/compat.h:17,
                 from arch/powerpc/kernel/asm-offsets.c:12:
include/linux/sched.h:1203:9: error: unknown type name 'nodemask_t'
 1203 |         nodemask_t                      mems_allowed;
      |         ^~~~~~~~~~

Fix it by removing <asm/machdep.h> dependency from archrandom.h

...

Quoted 1 line

EXPORT_SYMBOL_GPL(pm_power_off);

Quoted 7 lines

^^^ (Note this and read below)

...

Quoted 1 line

+EXPORT_SYMBOL(arch_get_random_seed_long);

It can't be like this. Brief browsing of the callees shows that.

Is my understanding correct that you're suggesting to make it GPL?

ppc_md is exported with EXPORT_SYMBOL(), and the function is in header, so it's available for non-GPL code now. I don't want to change it.

#4 lore raw

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

Quoted 2 lines · Yury Norov
Quoted 1 line · Andy Shevchenko

On Sun, Jul 24, 2022 at 12:19 AM Yury Norov <[email protected]> wrote:

...

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

EXPORT_SYMBOL_GPL(pm_power_off);

^^^ (Note this and read below)

...

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+EXPORT_SYMBOL(arch_get_random_seed_long);

It can't be like this. Brief browsing of the callees shows that.

Is my understanding correct that you're suggesting to make it GPL?

ppc_md is exported with EXPORT_SYMBOL(), and the function is in header, so it's available for non-GPL code now. I don't want to change it.

The symbols your function calls are GPL. As far as I understand (not a lawyer!) it logically one may not call GPL and pretend to be non-GPL.

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

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

Quoted 16 lines · Andy Shevchenko
Quoted 2 lines · Yury Norov
Quoted 1 line · Andy Shevchenko

On Sun, Jul 24, 2022 at 12:19 AM Yury Norov <[email protected]> wrote:

...

Quoted 10 lines
Quoted 9 lines
Quoted 1 line

EXPORT_SYMBOL_GPL(pm_power_off);

^^^ (Note this and read below)

...

Quoted 1 line

+EXPORT_SYMBOL(arch_get_random_seed_long);

It can't be like this. Brief browsing of the callees shows that.

Quoted 7 lines
Quoted 4 lines

Is my understanding correct that you're suggesting to make it GPL?

ppc_md is exported with EXPORT_SYMBOL(), and the function is in header, so it's available for non-GPL code now. I don't want to change it.

The symbols your function calls are GPL. As far as I understand (not a lawyer!) it logically one may not call GPL and pretend to be non-GPL.

Can you explain what you mean in details?

The function is:

        static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
        {
               if (ppc_md.get_random_seed)
                       return ppc_md.get_random_seed(v);

               return false;
        }

ppc_md is non-GPL:
77 /* The main machine-dep calls structure
78 */
79 struct machdep_calls ppc_md;
80 EXPORT_SYMBOL(ppc_md);

And get_random_seed is initialized in in arch/powerpc/platforms/powernv/rng.c with different functions that are static and not exported at all.

I don't understand where arch_get_random_seed_long calls GPL...

#6 lore raw

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

Quoted 4 lines · Yury Norov
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Yury Norov
Quoted 1 line · Andy Shevchenko

On Sun, Jul 24, 2022 at 12:19 AM Yury Norov <[email protected]> wrote:

...

Quoted 29 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 1 line

EXPORT_SYMBOL_GPL(pm_power_off);

^^^ (Note this and read below)

...

Quoted 1 line

+EXPORT_SYMBOL(arch_get_random_seed_long);

It can't be like this. Brief browsing of the callees shows that.

Quoted 7 lines
Quoted 4 lines

Is my understanding correct that you're suggesting to make it GPL?

ppc_md is exported with EXPORT_SYMBOL(), and the function is in header, so it's available for non-GPL code now. I don't want to change it.

The symbols your function calls are GPL. As far as I understand (not a lawyer!) it logically one may not call GPL and pretend to be non-GPL.

Can you explain what you mean in details?

The function is:

        static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
        {
               if (ppc_md.get_random_seed)
                       return ppc_md.get_random_seed(v);

               return false;
        }
Quoted 5 lines

ppc_md is non-GPL:
77 /* The main machine-dep calls structure
78 */
79 struct machdep_calls ppc_md;
80 EXPORT_SYMBOL(ppc_md);

What a mess...

Quoted 4 lines

And get_random_seed is initialized in in arch/powerpc/platforms/powernv/rng.c with different functions that are static and not exported at all.

I don't understand where arch_get_random_seed_long calls GPL...

The ->get_random_seed() (aka "callees" in my previous mail) are all GPL (maybe I missed one out of five which is non-GPL, but then it's even more of a mess).

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

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

Quoted 38 lines · Andy Shevchenko
Quoted 4 lines · Yury Norov
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Yury Norov
Quoted 1 line · Andy Shevchenko

On Sun, Jul 24, 2022 at 12:19 AM Yury Norov <[email protected]> wrote:

...

Quoted 29 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 1 line

EXPORT_SYMBOL_GPL(pm_power_off);

^^^ (Note this and read below)

...

Quoted 1 line

+EXPORT_SYMBOL(arch_get_random_seed_long);

It can't be like this. Brief browsing of the callees shows that.

Quoted 7 lines
Quoted 4 lines

Is my understanding correct that you're suggesting to make it GPL?

ppc_md is exported with EXPORT_SYMBOL(), and the function is in header, so it's available for non-GPL code now. I don't want to change it.

The symbols your function calls are GPL. As far as I understand (not a lawyer!) it logically one may not call GPL and pretend to be non-GPL.

Can you explain what you mean in details?

The function is:

        static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
        {
               if (ppc_md.get_random_seed)
                       return ppc_md.get_random_seed(v);

               return false;
        }
Quoted 10 lines
Quoted 5 lines

ppc_md is non-GPL:
77 /* The main machine-dep calls structure
78 */
79 struct machdep_calls ppc_md;
80 EXPORT_SYMBOL(ppc_md);

What a mess...

Quoted 2 lines

And get_random_seed is initialized in in arch/powerpc/platforms/powernv/rng.c with different functions that are static and not exported at all.

To be clear, their license is defined in the file: "GPL-2.0-or-later". But again, not a lawyer, just using my common sense.

Quoted 5 lines
Quoted 1 line

I don't understand where arch_get_random_seed_long calls GPL...

The ->get_random_seed() (aka "callees" in my previous mail) are all GPL (maybe I missed one out of five which is non-GPL, but then it's even more of a mess).

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

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

In reply to Yury Norov
Quoted 30 lines · Yury Norov
Quoted 29 lines · Andy Shevchenko
Quoted 19 lines · Yury Norov

archrandom.h includes <asm/machdep.h> to refer ppc_md. This causes circular header dependency, if generic nodemask.h includes random.h:

In file included from include/linux/cred.h:16,

                 from include/linux/seq_file.h:13,
                 from arch/powerpc/include/asm/machdep.h:6,
                 from arch/powerpc/include/asm/archrandom.h:5,
                 from include/linux/random.h:109,
                 from include/linux/nodemask.h:97,
                 from include/linux/list_lru.h:12,
                 from include/linux/fs.h:13,
                 from include/linux/compat.h:17,
                 from arch/powerpc/kernel/asm-offsets.c:12:
include/linux/sched.h:1203:9: error: unknown type name 'nodemask_t'
 1203 |         nodemask_t                      mems_allowed;
      |         ^~~~~~~~~~

Fix it by removing <asm/machdep.h> dependency from archrandom.h

...

Quoted 1 line

EXPORT_SYMBOL_GPL(pm_power_off);

^^^ (Note this and read below)

...

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+EXPORT_SYMBOL(arch_get_random_seed_long);

It can't be like this. Brief browsing of the callees shows that.

Is my understanding correct that you're suggesting to make it GPL?

ppc_md is exported with EXPORT_SYMBOL(), and the function is in header, so it's available for non-GPL code now. I don't want to change it.

That's true, your change maintains the status quo.

But I think we actually don't need it exported to modules, I think it's a private detail of the RNG <-> architecture interface, not something that modules should be calling.

So I think it's OK to drop the EXPORT_SYMBOL, either in this patch or a subsequent one if you don't want to rebase.

cheers

author maintainer
#9 lore raw

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

Quoted 40 lines · Michael Ellerman
Quoted 30 lines · Yury Norov
Quoted 29 lines · Andy Shevchenko
Quoted 19 lines · Yury Norov

archrandom.h includes <asm/machdep.h> to refer ppc_md. This causes circular header dependency, if generic nodemask.h includes random.h:

In file included from include/linux/cred.h:16,

                 from include/linux/seq_file.h:13,
                 from arch/powerpc/include/asm/machdep.h:6,
                 from arch/powerpc/include/asm/archrandom.h:5,
                 from include/linux/random.h:109,
                 from include/linux/nodemask.h:97,
                 from include/linux/list_lru.h:12,
                 from include/linux/fs.h:13,
                 from include/linux/compat.h:17,
                 from arch/powerpc/kernel/asm-offsets.c:12:
include/linux/sched.h:1203:9: error: unknown type name 'nodemask_t'
 1203 |         nodemask_t                      mems_allowed;
      |         ^~~~~~~~~~

Fix it by removing <asm/machdep.h> dependency from archrandom.h

...

Quoted 1 line

EXPORT_SYMBOL_GPL(pm_power_off);

^^^ (Note this and read below)

...

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+EXPORT_SYMBOL(arch_get_random_seed_long);

It can't be like this. Brief browsing of the callees shows that.

Is my understanding correct that you're suggesting to make it GPL?

ppc_md is exported with EXPORT_SYMBOL(), and the function is in header, so it's available for non-GPL code now. I don't want to change it.

Quoted 8 lines

That's true, your change maintains the status quo.

But I think we actually don't need it exported to modules, I think it's a private detail of the RNG <-> architecture interface, not something that modules should be calling.

So I think it's OK to drop the EXPORT_SYMBOL, either in this patch or a subsequent one if you don't want to rebase.

OK, changed.

#10 lore raw

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

In reply to Yury Norov
Quoted 39 lines · Yury Norov

archrandom.h includes <asm/machdep.h> to refer ppc_md. This causes circular header dependency, if generic nodemask.h includes random.h:

In file included from include/linux/cred.h:16,

                 from include/linux/seq_file.h:13,
                 from arch/powerpc/include/asm/machdep.h:6,
                 from arch/powerpc/include/asm/archrandom.h:5,
                 from include/linux/random.h:109,
                 from include/linux/nodemask.h:97,
                 from include/linux/list_lru.h:12,
                 from include/linux/fs.h:13,
                 from include/linux/compat.h:17,
                 from arch/powerpc/kernel/asm-offsets.c:12:
include/linux/sched.h:1203:9: error: unknown type name 'nodemask_t'
 1203 |         nodemask_t                      mems_allowed;
      |         ^~~~~~~~~~

Fix it by removing <asm/machdep.h> dependency from archrandom.h

---
 arch/powerpc/include/asm/archrandom.h |  9 +--------
 arch/powerpc/kernel/setup-common.c    | 11 +++++++++++
 2 files changed, 12 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/archrandom.h +1 -1
index 9a53e29680f4..21def59ef1a6 100644
@@ -4,7 +4,7 @@
 
 #ifdef CONFIG_ARCH_RANDOM
 
-#include <asm/machdep.h>
+bool __must_check arch_get_random_seed_long(unsigned long *v);
 
 static inline bool __must_check arch_get_random_long(unsigned long *v)
 {

arch/powerpc/include/asm/archrandom.h static inline bool __must_check arch_get_random_int(unsigned int *v) · line 25

Quoted 10 lines
arch/powerpc/include/asm/archrandom.h +0 -7
@@ -16,13 +16,6 @@ static inline bool __must_check arch_get_random_int(unsigned int *v)
 	return false;
 }
 
-static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
-{
-	if (ppc_md.get_random_seed)
-		return ppc_md.get_random_seed(v);
-
-	return false;
-}

I'd rather we didn't have to force this out of line.

I think I see a different way to fix it, I'll just do some more build tests.

cheers

#11 lore raw

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

Quoted 53 lines · Michael Ellerman
Quoted 39 lines · Yury Norov

archrandom.h includes <asm/machdep.h> to refer ppc_md. This causes circular header dependency, if generic nodemask.h includes random.h:

In file included from include/linux/cred.h:16,

                 from include/linux/seq_file.h:13,
                 from arch/powerpc/include/asm/machdep.h:6,
                 from arch/powerpc/include/asm/archrandom.h:5,
                 from include/linux/random.h:109,
                 from include/linux/nodemask.h:97,
                 from include/linux/list_lru.h:12,
                 from include/linux/fs.h:13,
                 from include/linux/compat.h:17,
                 from arch/powerpc/kernel/asm-offsets.c:12:
include/linux/sched.h:1203:9: error: unknown type name 'nodemask_t'
 1203 |         nodemask_t                      mems_allowed;
      |         ^~~~~~~~~~

Fix it by removing <asm/machdep.h> dependency from archrandom.h

---
 arch/powerpc/include/asm/archrandom.h |  9 +--------
 arch/powerpc/kernel/setup-common.c    | 11 +++++++++++
 2 files changed, 12 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/archrandom.h +1 -1
index 9a53e29680f4..21def59ef1a6 100644
@@ -4,7 +4,7 @@
 
 #ifdef CONFIG_ARCH_RANDOM
 
-#include <asm/machdep.h>
+bool __must_check arch_get_random_seed_long(unsigned long *v);
 
 static inline bool __must_check arch_get_random_long(unsigned long *v)
 {

arch/powerpc/include/asm/archrandom.h static inline bool __must_check arch_get_random_int(unsigned int *v) · line 25

Quoted 10 lines
arch/powerpc/include/asm/archrandom.h +0 -7
@@ -16,13 +16,6 @@ static inline bool __must_check arch_get_random_int(unsigned int *v)
 	return false;
 }
 
-static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
-{
-	if (ppc_md.get_random_seed)
-		return ppc_md.get_random_seed(v);
-
-	return false;
-}

I'd rather we didn't have to force this out of line.

Quoted 2 lines

I think I see a different way to fix it, I'll just do some more build tests.

Of course my idea didn't work :}

So I'll just ack your patch for now, and maybe I can get the headers cleaned up in future to allow it to be out-of-line again.

cheers

author maintainer
#12 lore raw

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

Quoted 54 lines · Michael Ellerman
Quoted 53 lines · Michael Ellerman
Quoted 39 lines · Yury Norov

archrandom.h includes <asm/machdep.h> to refer ppc_md. This causes circular header dependency, if generic nodemask.h includes random.h:

In file included from include/linux/cred.h:16,

                 from include/linux/seq_file.h:13,
                 from arch/powerpc/include/asm/machdep.h:6,
                 from arch/powerpc/include/asm/archrandom.h:5,
                 from include/linux/random.h:109,
                 from include/linux/nodemask.h:97,
                 from include/linux/list_lru.h:12,
                 from include/linux/fs.h:13,
                 from include/linux/compat.h:17,
                 from arch/powerpc/kernel/asm-offsets.c:12:
include/linux/sched.h:1203:9: error: unknown type name 'nodemask_t'
 1203 |         nodemask_t                      mems_allowed;
      |         ^~~~~~~~~~

Fix it by removing <asm/machdep.h> dependency from archrandom.h

---
 arch/powerpc/include/asm/archrandom.h |  9 +--------
 arch/powerpc/kernel/setup-common.c    | 11 +++++++++++
 2 files changed, 12 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/archrandom.h +1 -1
index 9a53e29680f4..21def59ef1a6 100644
@@ -4,7 +4,7 @@
 
 #ifdef CONFIG_ARCH_RANDOM
 
-#include <asm/machdep.h>
+bool __must_check arch_get_random_seed_long(unsigned long *v);
 
 static inline bool __must_check arch_get_random_long(unsigned long *v)
 {

arch/powerpc/include/asm/archrandom.h static inline bool __must_check arch_get_random_int(unsigned int *v) · line 25

Quoted 10 lines
arch/powerpc/include/asm/archrandom.h +0 -7
@@ -16,13 +16,6 @@ static inline bool __must_check arch_get_random_int(unsigned int *v)
 	return false;
 }
 
-static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
-{
-	if (ppc_md.get_random_seed)
-		return ppc_md.get_random_seed(v);
-
-	return false;
-}

I'd rather we didn't have to force this out of line.

Quoted 7 lines
Quoted 2 lines

I think I see a different way to fix it, I'll just do some more build tests.

Of course my idea didn't work :}

So I'll just ack your patch for now, and maybe I can get the headers cleaned up in future to allow it to be out-of-line again.

I understand that it looks like a tradeoff - we inline a couple of small functions with the cost of uninlining an almost innocent victim.

The complete solution would be probably a splitting ppc_md declaration out of asm/machdep.h. I wanted to do that, but I'm not a PPC guy, and just don't know how to split the header correctly.

Anyways, thanks for the ack. Applied on bitmap-for-next.

Thanks,
Yury

#13 lore raw

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

Quoted 58 lines · Yury Norov
Quoted 57 lines · Michael Ellerman
Quoted 55 lines · Michael Ellerman
Quoted 39 lines · Yury Norov

archrandom.h includes <asm/machdep.h> to refer ppc_md. This causes circular header dependency, if generic nodemask.h includes random.h:

In file included from include/linux/cred.h:16,

                 from include/linux/seq_file.h:13,
                 from arch/powerpc/include/asm/machdep.h:6,
                 from arch/powerpc/include/asm/archrandom.h:5,
                 from include/linux/random.h:109,
                 from include/linux/nodemask.h:97,
                 from include/linux/list_lru.h:12,
                 from include/linux/fs.h:13,
                 from include/linux/compat.h:17,
                 from arch/powerpc/kernel/asm-offsets.c:12:
include/linux/sched.h:1203:9: error: unknown type name 'nodemask_t'
 1203 |         nodemask_t                      mems_allowed;
      |         ^~~~~~~~~~

Fix it by removing <asm/machdep.h> dependency from archrandom.h

---
 arch/powerpc/include/asm/archrandom.h |  9 +--------
 arch/powerpc/kernel/setup-common.c    | 11 +++++++++++
 2 files changed, 12 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/archrandom.h +1 -1
index 9a53e29680f4..21def59ef1a6 100644
@@ -4,7 +4,7 @@
 
 #ifdef CONFIG_ARCH_RANDOM
 
-#include <asm/machdep.h>
+bool __must_check arch_get_random_seed_long(unsigned long *v);
 
 static inline bool __must_check arch_get_random_long(unsigned long *v)
 {

arch/powerpc/include/asm/archrandom.h static inline bool __must_check arch_get_random_int(unsigned int *v) · line 25

Quoted 10 lines
arch/powerpc/include/asm/archrandom.h +0 -7
@@ -16,13 +16,6 @@ static inline bool __must_check arch_get_random_int(unsigned int *v)
 	return false;
 }
 
-static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
-{
-	if (ppc_md.get_random_seed)
-		return ppc_md.get_random_seed(v);
-
-	return false;
-}

I'd rather we didn't have to force this out of line.

I think I see a different way to fix it, I'll just do some more build tests.

Quoted 7 lines
Quoted 4 lines

Of course my idea didn't work :}

So I'll just ack your patch for now, and maybe I can get the headers cleaned up in future to allow it to be out-of-line again.

I understand that it looks like a tradeoff - we inline a couple of small functions with the cost of uninlining an almost innocent victim.

Yeah. The truth is the cost to access the RNG will far outweigh the cost of that out-of-line call, so there's no real issue. But it's also such a small function that it just cries out to be inlined :)

Quoted 3 lines

The complete solution would be probably a splitting ppc_md declaration out of asm/machdep.h. I wanted to do that, but I'm not a PPC guy, and just don't know how to split the header correctly.

I managed to drop the includes of seq_file.h and dma-mapping.h, which seemed to fix the circular include problem, but there's a bit of fall out in unrelated files. I think I can get that sorted though eventually.

Quoted 1 line

Anyways, thanks for the ack. Applied on bitmap-for-next.

No worries.

cheers

reviewer Acked-by on v1 1/2
#14 lore raw

Re: [PATCH 1/2] powerpc: drop dependency on <asm/machdep.h> in archrandom.h

In reply to Yury Norov
Quoted 17 lines · Yury Norov

archrandom.h includes <asm/machdep.h> to refer ppc_md. This causes circular header dependency, if generic nodemask.h includes random.h:

In file included from include/linux/cred.h:16,

                 from include/linux/seq_file.h:13,
                 from arch/powerpc/include/asm/machdep.h:6,
                 from arch/powerpc/include/asm/archrandom.h:5,
                 from include/linux/random.h:109,
                 from include/linux/nodemask.h:97,
                 from include/linux/list_lru.h:12,
                 from include/linux/fs.h:13,
                 from include/linux/compat.h:17,
                 from arch/powerpc/kernel/asm-offsets.c:12:
include/linux/sched.h:1203:9: error: unknown type name 'nodemask_t'
 1203 |         nodemask_t                      mems_allowed;
      |         ^~~~~~~~~~
Quoted 7 lines

Fix it by removing <asm/machdep.h> dependency from archrandom.h

---
 arch/powerpc/include/asm/archrandom.h |  9 +--------
 arch/powerpc/kernel/setup-common.c    | 11 +++++++++++
 2 files changed, 12 insertions(+), 8 deletions(-)

cheers

author maintainer
#15 lore raw

PATCH RESEND 2/2 lib/nodemask: inline next_node_in() and node_random()

In reply to Yury Norov

The functions are pretty thin wrappers around find_bit engine, and keeping them in c-file prevents compiler from small_const_nbits() optimization, which must take place for all systems with MAX_NUMNODES less than BITS_PER_LONG (default is 16 for me).

Moving them to header file doesn't blow up the kernel size:
add/remove: 1/2 grow/shrink: 9/5 up/down: 968/-88 (880)

CC Andy Shevchenko <[email protected]>
CC Rasmus Villemoes <[email protected]>
---
 MAINTAINERS              |  1 -
 include/linux/nodemask.h | 27 ++++++++++++++++++++++-----
 lib/Makefile             |  2 +-
 lib/nodemask.c           | 30 ------------------------------
 4 files changed, 23 insertions(+), 37 deletions(-)
 delete mode 100644 lib/nodemask.c
MAINTAINERS +0 -1
index 7c0b8f28aa25..19c8d0ef1177 100644
@@ -3540,7 +3540,6 @@ F:	lib/bitmap.c
 F:	lib/cpumask.c
 F:	lib/find_bit.c
 F:	lib/find_bit_benchmark.c
-F:	lib/nodemask.c
 F:	lib/test_bitmap.c
 F:	tools/include/linux/bitmap.h
 F:	tools/include/linux/find.h
include/linux/nodemask.h +22 -5
index 0f233b76c9ce..48ebe4007955 100644
@@ -94,6 +94,7 @@
 #include <linux/bitmap.h>
 #include <linux/minmax.h>
 #include <linux/numa.h>
+#include <linux/random.h>
 
 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
 extern nodemask_t _unused_nodemask_arg_;
@@ -276,7 +277,14 @@ static inline unsigned int __next_node(int n, const nodemask_t *srcp)
  * the first node in src if needed.  Returns MAX_NUMNODES if src is empty.
  */
 #define next_node_in(n, src) __next_node_in((n), &(src))
-unsigned int __next_node_in(int node, const nodemask_t *srcp);
+static inline unsigned int __next_node_in(int node, const nodemask_t *srcp)
+{
+	unsigned int ret = __next_node(node, srcp);
+
+	if (ret == MAX_NUMNODES)
+		ret = __first_node(srcp);
+	return ret;
+}
 
 static inline void init_nodemask_of_node(nodemask_t *mask, int node)
 {
@@ -493,14 +501,23 @@ static inline int num_node_state(enum node_states state)
 
 #endif
 
+/*
+ * Return the bit number of a random bit set in the nodemask.
+ * (returns NUMA_NO_NODE if nodemask is empty)
+ */
+static inline int node_random(const nodemask_t *maskp)
+{
 #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1)
-extern int node_random(const nodemask_t *maskp);
+	int w, bit = NUMA_NO_NODE;
+
+	w = nodes_weight(*maskp);
+	if (w)
+		bit = find_nth_bit(maskp->bits, MAX_NUMNODES, get_random_int() % w);
+	return bit;
 #else
-static inline int node_random(const nodemask_t *mask)
-{
 	return 0;
-}
 #endif
+}
 
 #define node_online_map 	node_states[N_ONLINE]
 #define node_possible_map 	node_states[N_POSSIBLE]
lib/Makefile +1 -1
index f99bf61f8bbc..731cea0342d1 100644
@@ -33,7 +33,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 flex_proportions.o ratelimit.o show_mem.o \
 	 is_single_threaded.o plist.o decompress.o kobject_uevent.o \
 	 earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
-	 nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o \
+	 nmi_backtrace.o win_minmax.o memcat_p.o \
 	 buildid.o
 
 lib-$(CONFIG_PRINTK) += dump_stack.o
lib/nodemask.c deleted +0 -30
deleted file mode 100644
index 7dad4ce8ff59..000000000000
@@ -1,30 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/nodemask.h>
-#include <linux/module.h>
-#include <linux/random.h>
-
-unsigned int __next_node_in(int node, const nodemask_t *srcp)
-{
-	unsigned int ret = __next_node(node, srcp);
-
-	if (ret == MAX_NUMNODES)
-		ret = __first_node(srcp);
-	return ret;
-}
-EXPORT_SYMBOL(__next_node_in);
-
-#ifdef CONFIG_NUMA
-/*
- * Return the bit number of a random bit set in the nodemask.
- * (returns NUMA_NO_NODE if nodemask is empty)
- */
-int node_random(const nodemask_t *maskp)
-{
-	int w, bit = NUMA_NO_NODE;
-
-	w = nodes_weight(*maskp);
-	if (w)
-		bit = find_nth_bit(maskp->bits, MAX_NUMNODES, get_random_int() % w);
-	return bit;
-}
-#endif
Signature · 1 line
2.34.1
#16 lore raw

Re: [RESEND PATCH 2/2] lib/nodemask: inline next_node_in() and node_random()

Quoted 138 lines · Yury Norov

The functions are pretty thin wrappers around find_bit engine, and keeping them in c-file prevents compiler from small_const_nbits() optimization, which must take place for all systems with MAX_NUMNODES less than BITS_PER_LONG (default is 16 for me).

Moving them to header file doesn't blow up the kernel size:
add/remove: 1/2 grow/shrink: 9/5 up/down: 968/-88 (880)

CC Andy Shevchenko <[email protected]>
CC Rasmus Villemoes <[email protected]>
---
 MAINTAINERS              |  1 -
 include/linux/nodemask.h | 27 ++++++++++++++++++++++-----
 lib/Makefile             |  2 +-
 lib/nodemask.c           | 30 ------------------------------
 4 files changed, 23 insertions(+), 37 deletions(-)
 delete mode 100644 lib/nodemask.c
MAINTAINERS +0 -1
index 7c0b8f28aa25..19c8d0ef1177 100644
@@ -3540,7 +3540,6 @@ F:	lib/bitmap.c
 F:	lib/cpumask.c
 F:	lib/find_bit.c
 F:	lib/find_bit_benchmark.c
-F:	lib/nodemask.c
 F:	lib/test_bitmap.c
 F:	tools/include/linux/bitmap.h
 F:	tools/include/linux/find.h
include/linux/nodemask.h +22 -5
index 0f233b76c9ce..48ebe4007955 100644
@@ -94,6 +94,7 @@
 #include <linux/bitmap.h>
 #include <linux/minmax.h>
 #include <linux/numa.h>
+#include <linux/random.h>
 
 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
 extern nodemask_t _unused_nodemask_arg_;
@@ -276,7 +277,14 @@ static inline unsigned int __next_node(int n, const nodemask_t *srcp)
  * the first node in src if needed.  Returns MAX_NUMNODES if src is empty.
  */
 #define next_node_in(n, src) __next_node_in((n), &(src))
-unsigned int __next_node_in(int node, const nodemask_t *srcp);
+static inline unsigned int __next_node_in(int node, const nodemask_t *srcp)
+{
+	unsigned int ret = __next_node(node, srcp);
+
+	if (ret == MAX_NUMNODES)
+		ret = __first_node(srcp);
+	return ret;
+}
 
 static inline void init_nodemask_of_node(nodemask_t *mask, int node)
 {
@@ -493,14 +501,23 @@ static inline int num_node_state(enum node_states state)
 
 #endif
 
+/*
+ * Return the bit number of a random bit set in the nodemask.
+ * (returns NUMA_NO_NODE if nodemask is empty)
+ */
+static inline int node_random(const nodemask_t *maskp)
+{
 #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1)
-extern int node_random(const nodemask_t *maskp);
+	int w, bit = NUMA_NO_NODE;
+
+	w = nodes_weight(*maskp);
+	if (w)
+		bit = find_nth_bit(maskp->bits, MAX_NUMNODES, get_random_int() % w);
+	return bit;
 #else
-static inline int node_random(const nodemask_t *mask)
-{
 	return 0;
-}
 #endif
+}
 
 #define node_online_map 	node_states[N_ONLINE]
 #define node_possible_map 	node_states[N_POSSIBLE]
lib/Makefile +1 -1
index f99bf61f8bbc..731cea0342d1 100644
@@ -33,7 +33,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 flex_proportions.o ratelimit.o show_mem.o \
 	 is_single_threaded.o plist.o decompress.o kobject_uevent.o \
 	 earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
-	 nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o \
+	 nmi_backtrace.o win_minmax.o memcat_p.o \
 	 buildid.o
 
 lib-$(CONFIG_PRINTK) += dump_stack.o
lib/nodemask.c deleted +0 -30
deleted file mode 100644
index 7dad4ce8ff59..000000000000
@@ -1,30 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/nodemask.h>
-#include <linux/module.h>
-#include <linux/random.h>
-
-unsigned int __next_node_in(int node, const nodemask_t *srcp)
-{
-	unsigned int ret = __next_node(node, srcp);
-
-	if (ret == MAX_NUMNODES)
-		ret = __first_node(srcp);
-	return ret;
-}
-EXPORT_SYMBOL(__next_node_in);
-
-#ifdef CONFIG_NUMA
-/*
- * Return the bit number of a random bit set in the nodemask.
- * (returns NUMA_NO_NODE if nodemask is empty)
- */
-int node_random(const nodemask_t *maskp)
-{
-	int w, bit = NUMA_NO_NODE;
-
-	w = nodes_weight(*maskp);
-	if (w)
-		bit = find_nth_bit(maskp->bits, MAX_NUMNODES, get_random_int() % w);
-	return bit;
-}
-#endif
Signature · 1 line
2.34.1

The patch that got merged (36d4b36b69590fed99356a4426c940a253a93800) still have lib/nodemask.c

author maintainer
#17 lore raw

Re: [RESEND PATCH 2/2] lib/nodemask: inline next_node_in() and node_random()

Quoted 134 lines · Aneesh Kumar K.V
Quoted 132 lines · Yury Norov

The functions are pretty thin wrappers around find_bit engine, and keeping them in c-file prevents compiler from small_const_nbits() optimization, which must take place for all systems with MAX_NUMNODES less than BITS_PER_LONG (default is 16 for me).

Moving them to header file doesn't blow up the kernel size:
add/remove: 1/2 grow/shrink: 9/5 up/down: 968/-88 (880)

CC Andy Shevchenko <[email protected]>
CC Rasmus Villemoes <[email protected]>
---
 MAINTAINERS              |  1 -
 include/linux/nodemask.h | 27 ++++++++++++++++++++++-----
 lib/Makefile             |  2 +-
 lib/nodemask.c           | 30 ------------------------------
 4 files changed, 23 insertions(+), 37 deletions(-)
 delete mode 100644 lib/nodemask.c
MAINTAINERS +0 -1
index 7c0b8f28aa25..19c8d0ef1177 100644
@@ -3540,7 +3540,6 @@ F:	lib/bitmap.c
 F:	lib/cpumask.c
 F:	lib/find_bit.c
 F:	lib/find_bit_benchmark.c
-F:	lib/nodemask.c
 F:	lib/test_bitmap.c
 F:	tools/include/linux/bitmap.h
 F:	tools/include/linux/find.h
include/linux/nodemask.h +22 -5
index 0f233b76c9ce..48ebe4007955 100644
@@ -94,6 +94,7 @@
 #include <linux/bitmap.h>
 #include <linux/minmax.h>
 #include <linux/numa.h>
+#include <linux/random.h>
 
 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
 extern nodemask_t _unused_nodemask_arg_;
@@ -276,7 +277,14 @@ static inline unsigned int __next_node(int n, const nodemask_t *srcp)
  * the first node in src if needed.  Returns MAX_NUMNODES if src is empty.
  */
 #define next_node_in(n, src) __next_node_in((n), &(src))
-unsigned int __next_node_in(int node, const nodemask_t *srcp);
+static inline unsigned int __next_node_in(int node, const nodemask_t *srcp)
+{
+	unsigned int ret = __next_node(node, srcp);
+
+	if (ret == MAX_NUMNODES)
+		ret = __first_node(srcp);
+	return ret;
+}
 
 static inline void init_nodemask_of_node(nodemask_t *mask, int node)
 {
@@ -493,14 +501,23 @@ static inline int num_node_state(enum node_states state)
 
 #endif
 
+/*
+ * Return the bit number of a random bit set in the nodemask.
+ * (returns NUMA_NO_NODE if nodemask is empty)
+ */
+static inline int node_random(const nodemask_t *maskp)
+{
 #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1)
-extern int node_random(const nodemask_t *maskp);
+	int w, bit = NUMA_NO_NODE;
+
+	w = nodes_weight(*maskp);
+	if (w)
+		bit = find_nth_bit(maskp->bits, MAX_NUMNODES, get_random_int() % w);
+	return bit;
 #else
-static inline int node_random(const nodemask_t *mask)
-{
 	return 0;
-}
 #endif
+}
 
 #define node_online_map 	node_states[N_ONLINE]
 #define node_possible_map 	node_states[N_POSSIBLE]
lib/Makefile +1 -1
index f99bf61f8bbc..731cea0342d1 100644
@@ -33,7 +33,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 flex_proportions.o ratelimit.o show_mem.o \
 	 is_single_threaded.o plist.o decompress.o kobject_uevent.o \
 	 earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
-	 nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o \
+	 nmi_backtrace.o win_minmax.o memcat_p.o \
 	 buildid.o
 
 lib-$(CONFIG_PRINTK) += dump_stack.o
lib/nodemask.c deleted +0 -26
deleted file mode 100644
index 7dad4ce8ff59..000000000000
@@ -1,30 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/nodemask.h>
-#include <linux/module.h>
-#include <linux/random.h>
-
-unsigned int __next_node_in(int node, const nodemask_t *srcp)
-{
-	unsigned int ret = __next_node(node, srcp);
-
-	if (ret == MAX_NUMNODES)
-		ret = __first_node(srcp);
-	return ret;
-}
-EXPORT_SYMBOL(__next_node_in);
-
-#ifdef CONFIG_NUMA
-/*
- * Return the bit number of a random bit set in the nodemask.
- * (returns NUMA_NO_NODE if nodemask is empty)
- */
-int node_random(const nodemask_t *maskp)
-{
-	int w, bit = NUMA_NO_NODE;
-
-	w = nodes_weight(*maskp);
-	if (w)
Quoted 8 lines
Quoted 6 lines
lib/nodemask.c deleted +0 -4
-		bit = find_nth_bit(maskp->bits, MAX_NUMNODES, get_random_int() % w);
-	return bit;
-}
-#endif
Signature · 1 line
2.34.1

The patch that got merged (36d4b36b69590fed99356a4426c940a253a93800) still have lib/nodemask.c

Thanks Aneesh. I'll send a fix shortly.