Merge tag 'ronx-next' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux into devel-stable
generic fixmaps ARM support for CONFIG_DEBUG_RODATA
This commit is contained in:
@@ -67,7 +67,7 @@ test-kprobes-objs += kprobes-test-arm.o
|
||||
endif
|
||||
obj-$(CONFIG_OABI_COMPAT) += sys_oabi-compat.o
|
||||
obj-$(CONFIG_ARM_THUMBEE) += thumbee.o
|
||||
obj-$(CONFIG_KGDB) += kgdb.o
|
||||
obj-$(CONFIG_KGDB) += kgdb.o patch.o
|
||||
obj-$(CONFIG_ARM_UNWIND) += unwind.o
|
||||
obj-$(CONFIG_HAVE_TCM) += tcm.o
|
||||
obj-$(CONFIG_OF) += devtree.o
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include <linux/ftrace.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/stop_machine.h>
|
||||
|
||||
#include <asm/cacheflush.h>
|
||||
#include <asm/opcodes.h>
|
||||
@@ -35,6 +36,22 @@
|
||||
|
||||
#define OLD_NOP 0xe1a00000 /* mov r0, r0 */
|
||||
|
||||
static int __ftrace_modify_code(void *data)
|
||||
{
|
||||
int *command = data;
|
||||
|
||||
set_kernel_text_rw();
|
||||
ftrace_modify_all_code(*command);
|
||||
set_kernel_text_ro();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void arch_ftrace_update_code(int command)
|
||||
{
|
||||
stop_machine(__ftrace_modify_code, &command, NULL);
|
||||
}
|
||||
|
||||
static unsigned long ftrace_nop_replace(struct dyn_ftrace *rec)
|
||||
{
|
||||
return rec->arch.old_mcount ? OLD_NOP : NOP;
|
||||
@@ -73,6 +90,8 @@ int ftrace_arch_code_modify_prepare(void)
|
||||
int ftrace_arch_code_modify_post_process(void)
|
||||
{
|
||||
set_all_modules_text_ro();
|
||||
/* Make sure any TLB misses during machine stop are cleared. */
|
||||
flush_tlb_all();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ static void __arch_jump_label_transform(struct jump_entry *entry,
|
||||
insn = arm_gen_nop();
|
||||
|
||||
if (is_static)
|
||||
__patch_text(addr, insn);
|
||||
__patch_text_early(addr, insn);
|
||||
else
|
||||
patch_text(addr, insn);
|
||||
}
|
||||
|
@@ -12,8 +12,12 @@
|
||||
#include <linux/irq.h>
|
||||
#include <linux/kdebug.h>
|
||||
#include <linux/kgdb.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#include <asm/traps.h>
|
||||
|
||||
#include "patch.h"
|
||||
|
||||
struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] =
|
||||
{
|
||||
{ "r0", 4, offsetof(struct pt_regs, ARM_r0)},
|
||||
@@ -244,6 +248,31 @@ void kgdb_arch_exit(void)
|
||||
unregister_die_notifier(&kgdb_notifier);
|
||||
}
|
||||
|
||||
int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
|
||||
{
|
||||
int err;
|
||||
|
||||
/* patch_text() only supports int-sized breakpoints */
|
||||
BUILD_BUG_ON(sizeof(int) != BREAK_INSTR_SIZE);
|
||||
|
||||
err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
|
||||
BREAK_INSTR_SIZE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
patch_text((void *)bpt->bpt_addr,
|
||||
*(unsigned int *)arch_kgdb_ops.gdb_bpt_instr);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
|
||||
{
|
||||
patch_text((void *)bpt->bpt_addr, *(unsigned int *)bpt->saved_instr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Register our undef instruction hooks with ARM undef core.
|
||||
* We regsiter a hook specifically looking for the KGB break inst
|
||||
|
@@ -29,6 +29,7 @@ extern unsigned long kexec_boot_atags;
|
||||
|
||||
static atomic_t waiting_for_crash_ipi;
|
||||
|
||||
static unsigned long dt_mem;
|
||||
/*
|
||||
* Provide a dummy crash_notes definition while crash dump arrives to arm.
|
||||
* This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
|
||||
@@ -64,7 +65,7 @@ int machine_kexec_prepare(struct kimage *image)
|
||||
return err;
|
||||
|
||||
if (be32_to_cpu(header) == OF_DT_HEADER)
|
||||
kexec_boot_atags = current_segment->mem;
|
||||
dt_mem = current_segment->mem;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -163,12 +164,12 @@ void machine_kexec(struct kimage *image)
|
||||
reboot_code_buffer = page_address(image->control_code_page);
|
||||
|
||||
/* Prepare parameters for reboot_code_buffer*/
|
||||
set_kernel_text_rw();
|
||||
kexec_start_address = image->start;
|
||||
kexec_indirection_page = page_list;
|
||||
kexec_mach_type = machine_arch_type;
|
||||
if (!kexec_boot_atags)
|
||||
kexec_boot_atags = image->start - KEXEC_ARM_ZIMAGE_OFFSET + KEXEC_ARM_ATAGS_OFFSET;
|
||||
|
||||
kexec_boot_atags = dt_mem ?: image->start - KEXEC_ARM_ZIMAGE_OFFSET
|
||||
+ KEXEC_ARM_ATAGS_OFFSET;
|
||||
|
||||
/* copy our kernel relocation code to the control code page */
|
||||
reboot_entry = fncpy(reboot_code_buffer,
|
||||
|
@@ -1,8 +1,11 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/kprobes.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/stop_machine.h>
|
||||
|
||||
#include <asm/cacheflush.h>
|
||||
#include <asm/fixmap.h>
|
||||
#include <asm/smp_plat.h>
|
||||
#include <asm/opcodes.h>
|
||||
|
||||
@@ -13,21 +16,77 @@ struct patch {
|
||||
unsigned int insn;
|
||||
};
|
||||
|
||||
void __kprobes __patch_text(void *addr, unsigned int insn)
|
||||
static DEFINE_SPINLOCK(patch_lock);
|
||||
|
||||
static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags)
|
||||
__acquires(&patch_lock)
|
||||
{
|
||||
unsigned int uintaddr = (uintptr_t) addr;
|
||||
bool module = !core_kernel_text(uintaddr);
|
||||
struct page *page;
|
||||
|
||||
if (module && IS_ENABLED(CONFIG_DEBUG_SET_MODULE_RONX))
|
||||
page = vmalloc_to_page(addr);
|
||||
else if (!module && IS_ENABLED(CONFIG_DEBUG_RODATA))
|
||||
page = virt_to_page(addr);
|
||||
else
|
||||
return addr;
|
||||
|
||||
if (flags)
|
||||
spin_lock_irqsave(&patch_lock, *flags);
|
||||
else
|
||||
__acquire(&patch_lock);
|
||||
|
||||
set_fixmap(fixmap, page_to_phys(page));
|
||||
|
||||
return (void *) (__fix_to_virt(fixmap) + (uintaddr & ~PAGE_MASK));
|
||||
}
|
||||
|
||||
static void __kprobes patch_unmap(int fixmap, unsigned long *flags)
|
||||
__releases(&patch_lock)
|
||||
{
|
||||
clear_fixmap(fixmap);
|
||||
|
||||
if (flags)
|
||||
spin_unlock_irqrestore(&patch_lock, *flags);
|
||||
else
|
||||
__release(&patch_lock);
|
||||
}
|
||||
|
||||
void __kprobes __patch_text_real(void *addr, unsigned int insn, bool remap)
|
||||
{
|
||||
bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
|
||||
unsigned int uintaddr = (uintptr_t) addr;
|
||||
bool twopage = false;
|
||||
unsigned long flags;
|
||||
void *waddr = addr;
|
||||
int size;
|
||||
|
||||
if (remap)
|
||||
waddr = patch_map(addr, FIX_TEXT_POKE0, &flags);
|
||||
else
|
||||
__acquire(&patch_lock);
|
||||
|
||||
if (thumb2 && __opcode_is_thumb16(insn)) {
|
||||
*(u16 *)addr = __opcode_to_mem_thumb16(insn);
|
||||
*(u16 *)waddr = __opcode_to_mem_thumb16(insn);
|
||||
size = sizeof(u16);
|
||||
} else if (thumb2 && ((uintptr_t)addr & 2)) {
|
||||
} else if (thumb2 && (uintaddr & 2)) {
|
||||
u16 first = __opcode_thumb32_first(insn);
|
||||
u16 second = __opcode_thumb32_second(insn);
|
||||
u16 *addrh = addr;
|
||||
u16 *addrh0 = waddr;
|
||||
u16 *addrh1 = waddr + 2;
|
||||
|
||||
addrh[0] = __opcode_to_mem_thumb16(first);
|
||||
addrh[1] = __opcode_to_mem_thumb16(second);
|
||||
twopage = (uintaddr & ~PAGE_MASK) == PAGE_SIZE - 2;
|
||||
if (twopage && remap)
|
||||
addrh1 = patch_map(addr + 2, FIX_TEXT_POKE1, NULL);
|
||||
|
||||
*addrh0 = __opcode_to_mem_thumb16(first);
|
||||
*addrh1 = __opcode_to_mem_thumb16(second);
|
||||
|
||||
if (twopage && addrh1 != addr + 2) {
|
||||
flush_kernel_vmap_range(addrh1, 2);
|
||||
patch_unmap(FIX_TEXT_POKE1, NULL);
|
||||
}
|
||||
|
||||
size = sizeof(u32);
|
||||
} else {
|
||||
@@ -36,10 +95,16 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
|
||||
else
|
||||
insn = __opcode_to_mem_arm(insn);
|
||||
|
||||
*(u32 *)addr = insn;
|
||||
*(u32 *)waddr = insn;
|
||||
size = sizeof(u32);
|
||||
}
|
||||
|
||||
if (waddr != addr) {
|
||||
flush_kernel_vmap_range(waddr, twopage ? size / 2 : size);
|
||||
patch_unmap(FIX_TEXT_POKE0, &flags);
|
||||
} else
|
||||
__release(&patch_lock);
|
||||
|
||||
flush_icache_range((uintptr_t)(addr),
|
||||
(uintptr_t)(addr) + size);
|
||||
}
|
||||
@@ -60,16 +125,5 @@ void __kprobes patch_text(void *addr, unsigned int insn)
|
||||
.insn = insn,
|
||||
};
|
||||
|
||||
if (cache_ops_need_broadcast()) {
|
||||
stop_machine(patch_text_stop_machine, &patch, cpu_online_mask);
|
||||
} else {
|
||||
bool straddles_word = IS_ENABLED(CONFIG_THUMB2_KERNEL)
|
||||
&& __opcode_is_thumb32(insn)
|
||||
&& ((uintptr_t)addr & 2);
|
||||
|
||||
if (straddles_word)
|
||||
stop_machine(patch_text_stop_machine, &patch, NULL);
|
||||
else
|
||||
__patch_text(addr, insn);
|
||||
}
|
||||
stop_machine(patch_text_stop_machine, &patch, NULL);
|
||||
}
|
||||
|
@@ -2,6 +2,16 @@
|
||||
#define _ARM_KERNEL_PATCH_H
|
||||
|
||||
void patch_text(void *addr, unsigned int insn);
|
||||
void __patch_text(void *addr, unsigned int insn);
|
||||
void __patch_text_real(void *addr, unsigned int insn, bool remap);
|
||||
|
||||
static inline void __patch_text(void *addr, unsigned int insn)
|
||||
{
|
||||
__patch_text_real(addr, insn, true);
|
||||
}
|
||||
|
||||
static inline void __patch_text_early(void *addr, unsigned int insn)
|
||||
{
|
||||
__patch_text_real(addr, insn, false);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -8,6 +8,9 @@
|
||||
#include <asm/thread_info.h>
|
||||
#include <asm/memory.h>
|
||||
#include <asm/page.h>
|
||||
#ifdef CONFIG_ARM_KERNMEM_PERMS
|
||||
#include <asm/pgtable.h>
|
||||
#endif
|
||||
|
||||
#define PROC_INFO \
|
||||
. = ALIGN(4); \
|
||||
@@ -90,6 +93,11 @@ SECTIONS
|
||||
_text = .;
|
||||
HEAD_TEXT
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ARM_KERNMEM_PERMS
|
||||
. = ALIGN(1<<SECTION_SHIFT);
|
||||
#endif
|
||||
|
||||
.text : { /* Real text segment */
|
||||
_stext = .; /* Text and read-only data */
|
||||
__exception_text_start = .;
|
||||
@@ -112,6 +120,9 @@ SECTIONS
|
||||
ARM_CPU_KEEP(PROC_INFO)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_RODATA
|
||||
. = ALIGN(1<<SECTION_SHIFT);
|
||||
#endif
|
||||
RO_DATA(PAGE_SIZE)
|
||||
|
||||
. = ALIGN(4);
|
||||
@@ -145,7 +156,11 @@ SECTIONS
|
||||
_etext = .; /* End of text and rodata section */
|
||||
|
||||
#ifndef CONFIG_XIP_KERNEL
|
||||
# ifdef CONFIG_ARM_KERNMEM_PERMS
|
||||
. = ALIGN(1<<SECTION_SHIFT);
|
||||
# else
|
||||
. = ALIGN(PAGE_SIZE);
|
||||
# endif
|
||||
__init_begin = .;
|
||||
#endif
|
||||
/*
|
||||
@@ -218,8 +233,12 @@ SECTIONS
|
||||
#ifdef CONFIG_XIP_KERNEL
|
||||
__data_loc = ALIGN(4); /* location in binary */
|
||||
. = PAGE_OFFSET + TEXT_OFFSET;
|
||||
#else
|
||||
#ifdef CONFIG_ARM_KERNMEM_PERMS
|
||||
. = ALIGN(1<<SECTION_SHIFT);
|
||||
#else
|
||||
. = ALIGN(THREAD_SIZE);
|
||||
#endif
|
||||
__init_end = .;
|
||||
__data_loc = .;
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user