Skip to content

Commit

Permalink
powerpc: Inline setup_kup()
Browse files Browse the repository at this point in the history
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 67d53f3 ("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
44b4c44 ("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
  • Loading branch information
Michael Ellerman committed Dec 15, 2020
1 parent 44b4c44 commit 1791ebd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 6 additions & 2 deletions arch/powerpc/include/asm/kup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,6 +83,12 @@ static inline void restore_user_access(unsigned long flags) { }
#endif /* CONFIG_PPC_BOOK3S_64 */
#endif /* CONFIG_PPC_KUAP */

static __always_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);
Expand Down
6 changes: 0 additions & 6 deletions arch/powerpc/mm/init-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)); \
Expand Down

0 comments on commit 1791ebd

Please sign in to comment.