提交 dbfbd87e 编写于 作者: M Mark Rutland 提交者: Will Deacon

arm64: factor insn read out of call_undef_hook()

Subsequent patches will rework EL0 UNDEF handling, removing the need for
struct undef_hook and call_undef_hook. In preparation for those changes,
this patch factors the logic for reading user instructions out of
call_undef_hook() and into a new user_insn_read() helper, matching the
style of the existing aarch64_insn_read() helper used for reading kernel
instructions.

There should be no functional change as a result of this patch.
Signed-off-by: NMark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Joey Gouly <joey.gouly@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20221019144123.612388-5-mark.rutland@arm.comSigned-off-by: NWill Deacon <will@kernel.org>
上级 bff8f413
...@@ -394,25 +394,22 @@ void unregister_undef_hook(struct undef_hook *hook) ...@@ -394,25 +394,22 @@ void unregister_undef_hook(struct undef_hook *hook)
raw_spin_unlock_irqrestore(&undef_lock, flags); raw_spin_unlock_irqrestore(&undef_lock, flags);
} }
static int call_undef_hook(struct pt_regs *regs) static int user_insn_read(struct pt_regs *regs, u32 *insnp)
{ {
struct undef_hook *hook;
unsigned long flags;
u32 instr; u32 instr;
int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
unsigned long pc = instruction_pointer(regs); unsigned long pc = instruction_pointer(regs);
if (compat_thumb_mode(regs)) { if (compat_thumb_mode(regs)) {
/* 16-bit Thumb instruction */ /* 16-bit Thumb instruction */
__le16 instr_le; __le16 instr_le;
if (get_user(instr_le, (__le16 __user *)pc)) if (get_user(instr_le, (__le16 __user *)pc))
goto exit; return -EFAULT;
instr = le16_to_cpu(instr_le); instr = le16_to_cpu(instr_le);
if (aarch32_insn_is_wide(instr)) { if (aarch32_insn_is_wide(instr)) {
u32 instr2; u32 instr2;
if (get_user(instr_le, (__le16 __user *)(pc + 2))) if (get_user(instr_le, (__le16 __user *)(pc + 2)))
goto exit; return -EFAULT;
instr2 = le16_to_cpu(instr_le); instr2 = le16_to_cpu(instr_le);
instr = (instr << 16) | instr2; instr = (instr << 16) | instr2;
} }
...@@ -420,10 +417,20 @@ static int call_undef_hook(struct pt_regs *regs) ...@@ -420,10 +417,20 @@ static int call_undef_hook(struct pt_regs *regs)
/* 32-bit ARM instruction */ /* 32-bit ARM instruction */
__le32 instr_le; __le32 instr_le;
if (get_user(instr_le, (__le32 __user *)pc)) if (get_user(instr_le, (__le32 __user *)pc))
goto exit; return -EFAULT;
instr = le32_to_cpu(instr_le); instr = le32_to_cpu(instr_le);
} }
*insnp = instr;
return 0;
}
static int call_undef_hook(struct pt_regs *regs, u32 instr)
{
struct undef_hook *hook;
unsigned long flags;
int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
raw_spin_lock_irqsave(&undef_lock, flags); raw_spin_lock_irqsave(&undef_lock, flags);
list_for_each_entry(hook, &undef_hook, node) list_for_each_entry(hook, &undef_hook, node)
if ((instr & hook->instr_mask) == hook->instr_val && if ((instr & hook->instr_mask) == hook->instr_val &&
...@@ -431,7 +438,7 @@ static int call_undef_hook(struct pt_regs *regs) ...@@ -431,7 +438,7 @@ static int call_undef_hook(struct pt_regs *regs)
fn = hook->fn; fn = hook->fn;
raw_spin_unlock_irqrestore(&undef_lock, flags); raw_spin_unlock_irqrestore(&undef_lock, flags);
exit:
return fn ? fn(regs, instr) : 1; return fn ? fn(regs, instr) : 1;
} }
...@@ -483,13 +490,19 @@ void arm64_notify_segfault(unsigned long addr) ...@@ -483,13 +490,19 @@ void arm64_notify_segfault(unsigned long addr)
void do_el0_undef(struct pt_regs *regs, unsigned long esr) void do_el0_undef(struct pt_regs *regs, unsigned long esr)
{ {
u32 insn;
/* check for AArch32 breakpoint instructions */ /* check for AArch32 breakpoint instructions */
if (!aarch32_break_handler(regs)) if (!aarch32_break_handler(regs))
return; return;
if (call_undef_hook(regs) == 0) if (user_insn_read(regs, &insn))
goto out_err;
if (call_undef_hook(regs, insn) == 0)
return; return;
out_err:
force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0); force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册