From: Mark Rutland <mark.rutland@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: catalin.marinas@arm.com, james.morse@arm.com, joey.gouly@arm.com,
mark.rutland@arm.com, peterz@infradead.org, will@kernel.org
Subject: [PATCH v2 4/9] arm64: factor insn read out of call_undef_hook()
Date: Wed, 19 Oct 2022 15:41:18 +0100 [thread overview]
Message-ID: <20221019144123.612388-5-mark.rutland@arm.com> (raw)
In-Reply-To: <20221019144123.612388-1-mark.rutland@arm.com>
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: Mark 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>
---
arch/arm64/kernel/traps.c | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index ccd7d773e5cd..4d51afd010e1 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -394,25 +394,22 @@ void unregister_undef_hook(struct undef_hook *hook)
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;
- int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
unsigned long pc = instruction_pointer(regs);
if (compat_thumb_mode(regs)) {
/* 16-bit Thumb instruction */
__le16 instr_le;
if (get_user(instr_le, (__le16 __user *)pc))
- goto exit;
+ return -EFAULT;
instr = le16_to_cpu(instr_le);
if (aarch32_insn_is_wide(instr)) {
u32 instr2;
if (get_user(instr_le, (__le16 __user *)(pc + 2)))
- goto exit;
+ return -EFAULT;
instr2 = le16_to_cpu(instr_le);
instr = (instr << 16) | instr2;
}
@@ -420,10 +417,20 @@ static int call_undef_hook(struct pt_regs *regs)
/* 32-bit ARM instruction */
__le32 instr_le;
if (get_user(instr_le, (__le32 __user *)pc))
- goto exit;
+ return -EFAULT;
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);
list_for_each_entry(hook, &undef_hook, node)
if ((instr & hook->instr_mask) == hook->instr_val &&
@@ -431,7 +438,7 @@ static int call_undef_hook(struct pt_regs *regs)
fn = hook->fn;
raw_spin_unlock_irqrestore(&undef_lock, flags);
-exit:
+
return fn ? fn(regs, instr) : 1;
}
@@ -483,13 +490,19 @@ void arm64_notify_segfault(unsigned long addr)
void do_el0_undef(struct pt_regs *regs, unsigned long esr)
{
+ u32 insn;
+
/* check for AArch32 breakpoint instructions */
if (!aarch32_break_handler(regs))
return;
- if (call_undef_hook(regs) == 0)
+ if (user_insn_read(regs, &insn))
+ goto out_err;
+
+ if (call_undef_hook(regs, insn) == 0)
return;
+out_err:
force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0);
}
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-10-19 15:03 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-19 14:41 [PATCH v2 0/9] arm64: rework UNDEFINED instruction traps Mark Rutland
2022-10-19 14:41 ` [PATCH v2 1/9] arm64: allow kprobes on EL0 handlers Mark Rutland
2022-10-19 14:41 ` [PATCH v2 2/9] arm64: split EL0/EL1 UNDEF handlers Mark Rutland
2022-10-19 14:41 ` [PATCH v2 3/9] arm64: factor out EL1 SSBS emulation hook Mark Rutland
2022-10-19 14:41 ` Mark Rutland [this message]
2022-10-19 14:41 ` [PATCH v2 5/9] arm64: rework EL0 MRS emulation Mark Rutland
2022-10-19 14:41 ` [PATCH v2 6/9] arm64: armv8_deprecated: fold ops into insn_emulation Mark Rutland
2022-10-19 14:41 ` [PATCH v2 7/9] arm64: armv8_deprecated move emulation functions Mark Rutland
2022-10-19 14:41 ` [PATCH v2 8/9] arm64: armv8_deprecated: move aarch32 helper earlier Mark Rutland
2022-10-19 14:41 ` [PATCH v2 9/9] arm64: armv8_deprecated: rework deprected instruction handling Mark Rutland
2023-02-03 10:08 ` Ruan Jinjie
2023-02-03 17:27 ` Mark Rutland
2023-02-06 2:03 ` Ruan Jinjie
2023-02-06 9:13 ` Mark Rutland
2023-02-07 7:01 ` Ruan Jinjie
2022-11-14 14:20 ` [PATCH v2 0/9] arm64: rework UNDEFINED instruction traps Will Deacon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221019144123.612388-5-mark.rutland@arm.com \
--to=mark.rutland@arm.com \
--cc=catalin.marinas@arm.com \
--cc=james.morse@arm.com \
--cc=joey.gouly@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox