2019-04-05 03:14:08 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* fixmaps for parisc
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Sven Schnelle <svens@stackframe.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kprobes.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/fixmap.h>
|
|
|
|
|
parisc: add dynamic ftrace
This patch implements dynamic ftrace for PA-RISC. The required mcount
call sequences can get pretty long, so instead of patching the
whole call sequence out of the functions, we are using
-fpatchable-function-entry from gcc. This puts a configurable amount of
NOPS before/at the start of the function. Taking do_sys_open() as example,
which would look like this when the call is patched out:
1036b248: 08 00 02 40 nop
1036b24c: 08 00 02 40 nop
1036b250: 08 00 02 40 nop
1036b254: 08 00 02 40 nop
1036b258 <do_sys_open>:
1036b258: 08 00 02 40 nop
1036b25c: 08 03 02 41 copy r3,r1
1036b260: 6b c2 3f d9 stw rp,-14(sp)
1036b264: 08 1e 02 43 copy sp,r3
1036b268: 6f c1 01 00 stw,ma r1,80(sp)
When ftrace gets enabled for this function the kernel will patch these
NOPs to:
1036b248: 10 19 57 20 <address of ftrace>
1036b24c: 6f c1 00 80 stw,ma r1,40(sp)
1036b250: 48 21 3f d1 ldw -18(r1),r1
1036b254: e8 20 c0 02 bv,n r0(r1)
1036b258 <do_sys_open>:
1036b258: e8 3f 1f df b,l,n .-c,r1
1036b25c: 08 03 02 41 copy r3,r1
1036b260: 6b c2 3f d9 stw rp,-14(sp)
1036b264: 08 1e 02 43 copy sp,r3
1036b268: 6f c1 01 00 stw,ma r1,80(sp)
So the first NOP in do_sys_open() will be patched to jump backwards into
some minimal trampoline code which pushes a stackframe, saves r1 which
holds the return address, loads the address of the real ftrace function,
and branches to that location. For 64 Bit things are getting a bit more
complicated (and longer) because we must make sure that the address of
ftrace location is 8 byte aligned, and the offset passed to ldd for
fetching the address is 8 byte aligned as well.
Note that gcc has a bug which misplaces the function label, and needs a
patch to make dynamic ftrace work. See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90751 for details.
Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Helge Deller <deller@gmx.de>
2019-06-06 04:32:22 +08:00
|
|
|
void notrace set_fixmap(enum fixed_addresses idx, phys_addr_t phys)
|
2019-04-05 03:14:08 +08:00
|
|
|
{
|
|
|
|
unsigned long vaddr = __fix_to_virt(idx);
|
|
|
|
pgd_t *pgd = pgd_offset_k(vaddr);
|
2019-12-05 08:54:12 +08:00
|
|
|
p4d_t *p4d = p4d_offset(pgd, vaddr);
|
|
|
|
pud_t *pud = pud_offset(p4d, vaddr);
|
|
|
|
pmd_t *pmd = pmd_offset(pud, vaddr);
|
2019-04-05 03:14:08 +08:00
|
|
|
pte_t *pte;
|
|
|
|
|
2021-11-01 04:58:12 +08:00
|
|
|
pte = pte_offset_kernel(pmd, vaddr);
|
2019-04-05 03:14:08 +08:00
|
|
|
set_pte_at(&init_mm, vaddr, pte, __mk_pte(phys, PAGE_KERNEL_RWX));
|
|
|
|
flush_tlb_kernel_range(vaddr, vaddr + PAGE_SIZE);
|
|
|
|
}
|
|
|
|
|
parisc: add dynamic ftrace
This patch implements dynamic ftrace for PA-RISC. The required mcount
call sequences can get pretty long, so instead of patching the
whole call sequence out of the functions, we are using
-fpatchable-function-entry from gcc. This puts a configurable amount of
NOPS before/at the start of the function. Taking do_sys_open() as example,
which would look like this when the call is patched out:
1036b248: 08 00 02 40 nop
1036b24c: 08 00 02 40 nop
1036b250: 08 00 02 40 nop
1036b254: 08 00 02 40 nop
1036b258 <do_sys_open>:
1036b258: 08 00 02 40 nop
1036b25c: 08 03 02 41 copy r3,r1
1036b260: 6b c2 3f d9 stw rp,-14(sp)
1036b264: 08 1e 02 43 copy sp,r3
1036b268: 6f c1 01 00 stw,ma r1,80(sp)
When ftrace gets enabled for this function the kernel will patch these
NOPs to:
1036b248: 10 19 57 20 <address of ftrace>
1036b24c: 6f c1 00 80 stw,ma r1,40(sp)
1036b250: 48 21 3f d1 ldw -18(r1),r1
1036b254: e8 20 c0 02 bv,n r0(r1)
1036b258 <do_sys_open>:
1036b258: e8 3f 1f df b,l,n .-c,r1
1036b25c: 08 03 02 41 copy r3,r1
1036b260: 6b c2 3f d9 stw rp,-14(sp)
1036b264: 08 1e 02 43 copy sp,r3
1036b268: 6f c1 01 00 stw,ma r1,80(sp)
So the first NOP in do_sys_open() will be patched to jump backwards into
some minimal trampoline code which pushes a stackframe, saves r1 which
holds the return address, loads the address of the real ftrace function,
and branches to that location. For 64 Bit things are getting a bit more
complicated (and longer) because we must make sure that the address of
ftrace location is 8 byte aligned, and the offset passed to ldd for
fetching the address is 8 byte aligned as well.
Note that gcc has a bug which misplaces the function label, and needs a
patch to make dynamic ftrace work. See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90751 for details.
Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Helge Deller <deller@gmx.de>
2019-06-06 04:32:22 +08:00
|
|
|
void notrace clear_fixmap(enum fixed_addresses idx)
|
2019-04-05 03:14:08 +08:00
|
|
|
{
|
|
|
|
unsigned long vaddr = __fix_to_virt(idx);
|
2020-06-09 12:33:05 +08:00
|
|
|
pte_t *pte = virt_to_kpte(vaddr);
|
2019-04-05 03:14:08 +08:00
|
|
|
|
2019-06-06 04:32:19 +08:00
|
|
|
if (WARN_ON(pte_none(*pte)))
|
|
|
|
return;
|
|
|
|
|
2019-04-05 03:14:08 +08:00
|
|
|
pte_clear(&init_mm, vaddr, pte);
|
|
|
|
|
|
|
|
flush_tlb_kernel_range(vaddr, vaddr + PAGE_SIZE);
|
|
|
|
}
|