Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Make it __always_inline as pointed out by Christophe.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201214123011.311024-1-mpe@ellerman.id.au

+6 -8
+6 -2
arch/powerpc/include/asm/kup.h
··· 49 49 50 50 #include <linux/pgtable.h> 51 51 52 - void setup_kup(void); 53 - 54 52 #ifdef CONFIG_PPC_KUEP 55 53 void setup_kuep(bool disabled); 56 54 #else ··· 82 84 static inline void restore_user_access(unsigned long flags) { } 83 85 #endif /* CONFIG_PPC_BOOK3S_64 */ 84 86 #endif /* CONFIG_PPC_KUAP */ 87 + 88 + static __always_inline void setup_kup(void) 89 + { 90 + setup_kuep(disable_kuep); 91 + setup_kuap(disable_kuap); 92 + } 85 93 86 94 static inline void allow_read_from_user(const void __user *from, unsigned long size) 87 95 {
-6
arch/powerpc/mm/init-common.c
··· 47 47 } 48 48 early_param("nosmap", parse_nosmap); 49 49 50 - void __ref setup_kup(void) 51 - { 52 - setup_kuep(disable_kuep); 53 - setup_kuap(disable_kuap); 54 - } 55 - 56 50 #define CTOR(shift) static void ctor_##shift(void *addr) \ 57 51 { \ 58 52 memset(addr, 0, sizeof(void *) << (shift)); \