Skip to contentSkip to conversation

powerpc: Inline setup_kup()

PATCH In review Michael Ellerman 2 participants 5 messages Dec 14, 2020 – Dec 15, 2020 PowerPC

lore
Share & tools
lore

Michael Ellerman

author reviewer
#0 lore raw

PATCH 1/1 powerpc: Inline setup_kup()

setup_kup() is used by both 64-bit and 32-bit code. However on 64-bit it must not be __init, because it's used for CPU hotplug, whereas on 32-bit it should be __init because it calls setup_kuap/kuep() which are __init.

We worked around that problem in the past by marking it __ref, see commit 67d53f30e23e ("powerpc/mm: fix section mismatch for setup_kup()").

Marking it __ref basically just omits it from section mismatch checking, which can lead to bugs, and in fact it did, see commit 44b4c4450f8d ("powerpc/64s: Mark the kuap/kuep functions non __init")

We can avoid all these problems by just making it static inline. Because all it does is call other functions, making it inline actually shrinks the 32-bit vmlinux by ~76 bytes.

---
 arch/powerpc/include/asm/kup.h | 8 ++++++--
 arch/powerpc/mm/init-common.c  | 6 ------
 2 files changed, 6 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/kup.h +6 -2
index 5a9820c54da9..46b12c6dc728 100644
@@ -49,8 +49,6 @@ extern bool disable_kuap;
 
 #include <linux/pgtable.h>
 
-void setup_kup(void);
-
 #ifdef CONFIG_PPC_KUEP
 void setup_kuep(bool disabled);
 #else
@@ -85,6 +83,12 @@ static inline void restore_user_access(unsigned long flags) { }
 #endif /* CONFIG_PPC_BOOK3S_64 */
 #endif /* CONFIG_PPC_KUAP */
 
+static inline void setup_kup(void)
+{
+	setup_kuep(disable_kuep);
+	setup_kuap(disable_kuap);
+}
+
 static inline void allow_read_from_user(const void __user *from, unsigned long size)
 {
 	allow_user_access(NULL, from, size, KUAP_READ);
arch/powerpc/mm/init-common.c +0 -6
index afdebb95bcae..3a82f89827a5 100644
@@ -47,12 +47,6 @@ static int __init parse_nosmap(char *p)
 }
 early_param("nosmap", parse_nosmap);
 
-void __ref setup_kup(void)
-{
-	setup_kuep(disable_kuep);
-	setup_kuap(disable_kuap);
-}
-
 #define CTOR(shift) static void ctor_##shift(void *addr) \
 {							\
 	memset(addr, 0, sizeof(void *) << (shift));	\
Signature · 1 line
2.25.1
#1 lore raw

Le 14/12/2020 à 13:30, Michael Ellerman a écrit :

Quoted 37 lines

setup_kup() is used by both 64-bit and 32-bit code. However on 64-bit it must not be __init, because it's used for CPU hotplug, whereas on 32-bit it should be __init because it calls setup_kuap/kuep() which are __init.

We worked around that problem in the past by marking it __ref, see commit 67d53f30e23e ("powerpc/mm: fix section mismatch for setup_kup()").

Marking it __ref basically just omits it from section mismatch checking, which can lead to bugs, and in fact it did, see commit 44b4c4450f8d ("powerpc/64s: Mark the kuap/kuep functions non __init")

We can avoid all these problems by just making it static inline. Because all it does is call other functions, making it inline actually shrinks the 32-bit vmlinux by ~76 bytes.

---
  arch/powerpc/include/asm/kup.h | 8 ++++++--
  arch/powerpc/mm/init-common.c  | 6 ------
  2 files changed, 6 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/kup.h +0 -2
index 5a9820c54da9..46b12c6dc728 100644
@@ -49,8 +49,6 @@ extern bool disable_kuap;
 
  #include <linux/pgtable.h>
 
-void setup_kup(void);
-
  #ifdef CONFIG_PPC_KUEP
  void setup_kuep(bool disabled);
  #else

arch/powerpc/include/asm/kup.h static inline void restore_user_access(unsigned long flags) { } · line 86

Quoted 4 lines
arch/powerpc/include/asm/kup.h +1 -0
@@ -85,6 +83,12 @@ static inline void restore_user_access(unsigned long flags) { }
  #endif /* CONFIG_PPC_BOOK3S_64 */
  #endif /* CONFIG_PPC_KUAP */
 
+static inline void setup_kup(void)

Should it be __always_inline ?

Christophe

Quoted 26 lines
arch/powerpc/include/asm/kup.h +5 -0
+{
+	setup_kuep(disable_kuep);
+	setup_kuap(disable_kuap);
+}
+
  static inline void allow_read_from_user(const void __user *from, unsigned long size)
  {
  	allow_user_access(NULL, from, size, KUAP_READ);
arch/powerpc/mm/init-common.c +0 -6
index afdebb95bcae..3a82f89827a5 100644
@@ -47,12 +47,6 @@ static int __init parse_nosmap(char *p)
  }
  early_param("nosmap", parse_nosmap);
 
-void __ref setup_kup(void)
-{
-	setup_kuep(disable_kuep);
-	setup_kuap(disable_kuap);
-}
-
  #define CTOR(shift) static void ctor_##shift(void *addr) \
  {							\
  	memset(addr, 0, sizeof(void *) << (shift));	\
author reviewer
#2 lore raw
Quoted 41 lines · Christophe Leroy

Le 14/12/2020 à 13:30, Michael Ellerman a écrit :

Quoted 40 lines

setup_kup() is used by both 64-bit and 32-bit code. However on 64-bit it must not be __init, because it's used for CPU hotplug, whereas on 32-bit it should be __init because it calls setup_kuap/kuep() which are __init.

We worked around that problem in the past by marking it __ref, see commit 67d53f30e23e ("powerpc/mm: fix section mismatch for setup_kup()").

Marking it __ref basically just omits it from section mismatch checking, which can lead to bugs, and in fact it did, see commit 44b4c4450f8d ("powerpc/64s: Mark the kuap/kuep functions non __init")

We can avoid all these problems by just making it static inline. Because all it does is call other functions, making it inline actually shrinks the 32-bit vmlinux by ~76 bytes.

---
  arch/powerpc/include/asm/kup.h | 8 ++++++--
  arch/powerpc/mm/init-common.c  | 6 ------
  2 files changed, 6 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/kup.h +0 -2
index 5a9820c54da9..46b12c6dc728 100644
@@ -49,8 +49,6 @@ extern bool disable_kuap;
 
  #include <linux/pgtable.h>
 
-void setup_kup(void);
-
  #ifdef CONFIG_PPC_KUEP
  void setup_kuep(bool disabled);
  #else
@@ -85,6 +83,12 @@ static inline void restore_user_access(unsigned long flags) { }
  #endif /* CONFIG_PPC_BOOK3S_64 */
  #endif /* CONFIG_PPC_KUAP */
 
Quoted 3 lines

arch/powerpc/include/asm/kup.h static inline void restore_user_access(unsigned long flags) { } · line 86

Quoted 1 line
arch/powerpc/include/asm/kup.h +1 -0
+static inline void setup_kup(void)

Should it be __always_inline ?

Yes I guess so, will fix. Thanks for reviewing.

cheers

#3 lore raw

Le 15/12/2020 à 02:42, Michael Ellerman a écrit :

Quoted 42 lines
Quoted 41 lines · Christophe Leroy

Le 14/12/2020 à 13:30, Michael Ellerman a écrit :

Quoted 40 lines

setup_kup() is used by both 64-bit and 32-bit code. However on 64-bit it must not be __init, because it's used for CPU hotplug, whereas on 32-bit it should be __init because it calls setup_kuap/kuep() which are __init.

We worked around that problem in the past by marking it __ref, see commit 67d53f30e23e ("powerpc/mm: fix section mismatch for setup_kup()").

Marking it __ref basically just omits it from section mismatch checking, which can lead to bugs, and in fact it did, see commit 44b4c4450f8d ("powerpc/64s: Mark the kuap/kuep functions non __init")

We can avoid all these problems by just making it static inline. Because all it does is call other functions, making it inline actually shrinks the 32-bit vmlinux by ~76 bytes.

---
   arch/powerpc/include/asm/kup.h | 8 ++++++--
   arch/powerpc/mm/init-common.c  | 6 ------
   2 files changed, 6 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/kup.h +0 -2
index 5a9820c54da9..46b12c6dc728 100644
@@ -49,8 +49,6 @@ extern bool disable_kuap;
 
   #include <linux/pgtable.h>
 
-void setup_kup(void);
-
   #ifdef CONFIG_PPC_KUEP
   void setup_kuep(bool disabled);
   #else
@@ -85,6 +83,12 @@ static inline void restore_user_access(unsigned long flags) { }
   #endif /* CONFIG_PPC_BOOK3S_64 */
   #endif /* CONFIG_PPC_KUAP */
 
Quoted 6 lines
Quoted 3 lines

arch/powerpc/include/asm/kup.h static inline void restore_user_access(unsigned long flags) { } · line 86

Quoted 1 line
arch/powerpc/include/asm/kup.h +1 -0
+static inline void setup_kup(void)

Should it be __always_inline ?

Yes I guess so, will fix. Thanks for reviewing.

While we are talking about __always_inline, do you plan to take the following patch this cycle ?

https://patchwork.ozlabs.org/project/linuxppc-dev/patch/a1d31f84ddb0926813b17fcd5cc7f3fa7b4deac2.1602759123.git.christophe.leroy@csgroup.eu/

Christophe

author reviewer
#4 lore raw
Quoted 47 lines · Christophe Leroy

Le 15/12/2020 à 02:42, Michael Ellerman a écrit :

Quoted 46 lines
Quoted 44 lines · Christophe Leroy

Le 14/12/2020 à 13:30, Michael Ellerman a écrit :

Quoted 37 lines

setup_kup() is used by both 64-bit and 32-bit code. However on 64-bit it must not be __init, because it's used for CPU hotplug, whereas on 32-bit it should be __init because it calls setup_kuap/kuep() which are __init.

We worked around that problem in the past by marking it __ref, see commit 67d53f30e23e ("powerpc/mm: fix section mismatch for setup_kup()").

Marking it __ref basically just omits it from section mismatch checking, which can lead to bugs, and in fact it did, see commit 44b4c4450f8d ("powerpc/64s: Mark the kuap/kuep functions non __init")

We can avoid all these problems by just making it static inline. Because all it does is call other functions, making it inline actually shrinks the 32-bit vmlinux by ~76 bytes.

---
   arch/powerpc/include/asm/kup.h | 8 ++++++--
   arch/powerpc/mm/init-common.c  | 6 ------
   2 files changed, 6 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/kup.h +0 -2
index 5a9820c54da9..46b12c6dc728 100644
@@ -49,8 +49,6 @@ extern bool disable_kuap;
 
   #include <linux/pgtable.h>
 
-void setup_kup(void);
-
   #ifdef CONFIG_PPC_KUEP
   void setup_kuep(bool disabled);
   #else

arch/powerpc/include/asm/kup.h static inline void restore_user_access(unsigned long flags) { } · line 86

Quoted 4 lines
arch/powerpc/include/asm/kup.h +1 -0
@@ -85,6 +83,12 @@ static inline void restore_user_access(unsigned long flags) { }
   #endif /* CONFIG_PPC_BOOK3S_64 */
   #endif /* CONFIG_PPC_KUAP */
 
+static inline void setup_kup(void)

Should it be __always_inline ?

Quoted 6 lines
Quoted 2 lines

Yes I guess so, will fix. Thanks for reviewing.

While we are talking about __always_inline, do you plan to take the following patch this cycle ?

https://patchwork.ozlabs.org/project/linuxppc-dev/patch/a1d31f84ddb0926813b17fcd5cc7f3fa7b4deac2.1602759123.git.christophe.leroy@csgroup.eu/

I intended to, will grab it now.

cheers