From: Jordan Niethe <jniethe5@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: alistair@popple.id.au, npiggin@gmail.com, bala24@linux.ibm.com,
naveen.n.rao@linux.vnet.ibm.com,
Jordan Niethe <jniethe5@gmail.com>,
dja@axtens.net
Subject: [PATCH v7 17/28] powerpc: Introduce a function for reporting instruction length
Date: Fri, 1 May 2020 13:42:09 +1000 [thread overview]
Message-ID: <20200501034220.8982-18-jniethe5@gmail.com> (raw)
In-Reply-To: <20200501034220.8982-1-jniethe5@gmail.com>
Currently all instructions have the same length, but in preparation for
prefixed instructions introduce a function for returning instruction
length.
Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
---
v6: - feature-fixups.c: do_final_fixups(): use here
- ppc_inst_len(): change return type from bool to int
- uprobes: Use ppc_inst_read() before calling ppc_inst_len()
---
arch/powerpc/include/asm/inst.h | 5 +++++
arch/powerpc/kernel/kprobes.c | 6 ++++--
arch/powerpc/kernel/uprobes.c | 2 +-
arch/powerpc/lib/feature-fixups.c | 14 +++++++-------
4 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/include/asm/inst.h b/arch/powerpc/include/asm/inst.h
index 0d581b332c20..2f3c9d5bcf7c 100644
--- a/arch/powerpc/include/asm/inst.h
+++ b/arch/powerpc/include/asm/inst.h
@@ -17,6 +17,11 @@ static inline u32 ppc_inst_val(struct ppc_inst x)
return x.val;
}
+static inline int ppc_inst_len(struct ppc_inst x)
+{
+ return sizeof(struct ppc_inst);
+}
+
static inline int ppc_inst_primary_opcode(struct ppc_inst x)
{
return ppc_inst_val(x) >> 26;
diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index a72c8e1a42ad..33d54b091c70 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -462,14 +462,16 @@ NOKPROBE_SYMBOL(trampoline_probe_handler);
*/
int kprobe_post_handler(struct pt_regs *regs)
{
+ int len;
struct kprobe *cur = kprobe_running();
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
if (!cur || user_mode(regs))
return 0;
+ len = ppc_inst_len(ppc_inst_read((struct ppc_inst *)cur->ainsn.insn));
/* make sure we got here for instruction we have a kprobe on */
- if (((unsigned long)cur->ainsn.insn + 4) != regs->nip)
+ if (((unsigned long)cur->ainsn.insn + len) != regs->nip)
return 0;
if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
@@ -478,7 +480,7 @@ int kprobe_post_handler(struct pt_regs *regs)
}
/* Adjust nip to after the single-stepped instruction */
- regs->nip = (unsigned long)cur->addr + 4;
+ regs->nip = (unsigned long)cur->addr + len;
regs->msr |= kcb->kprobe_saved_msr;
/*Restore back the original saved kprobes variables and continue. */
diff --git a/arch/powerpc/kernel/uprobes.c b/arch/powerpc/kernel/uprobes.c
index 6893d40a48c5..83e883e1a42d 100644
--- a/arch/powerpc/kernel/uprobes.c
+++ b/arch/powerpc/kernel/uprobes.c
@@ -112,7 +112,7 @@ int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
* support doesn't exist and have to fix-up the next instruction
* to be executed.
*/
- regs->nip = utask->vaddr + MAX_UINSN_BYTES;
+ regs->nip = utask->vaddr + ppc_inst_len(ppc_inst_read(&auprobe->insn));
user_disable_single_step(current);
return 0;
diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c
index 13ec3264a565..f4845e740338 100644
--- a/arch/powerpc/lib/feature-fixups.c
+++ b/arch/powerpc/lib/feature-fixups.c
@@ -390,20 +390,20 @@ void do_lwsync_fixups(unsigned long value, void *fixup_start, void *fixup_end)
static void do_final_fixups(void)
{
#if defined(CONFIG_PPC64) && defined(CONFIG_RELOCATABLE)
- struct ppc_inst *src, *dest;
- unsigned long length;
+ struct ppc_inst inst, *src, *dest, *end;
if (PHYSICAL_START == 0)
return;
src = (struct ppc_inst *)(KERNELBASE + PHYSICAL_START);
dest = (struct ppc_inst *)KERNELBASE;
- length = (__end_interrupts - _stext) / sizeof(struct ppc_inst);
+ end = (void *)src + (__end_interrupts - _stext);
- while (length--) {
- raw_patch_instruction(dest, ppc_inst_read(src));
- src++;
- dest++;
+ while (src < end) {
+ inst = ppc_inst_read(src);
+ raw_patch_instruction(dest, inst);
+ src = (void *)src + ppc_inst_len(inst);
+ dest = (void *)dest + ppc_inst_len(inst);
}
#endif
}
--
2.17.1
next prev parent reply other threads:[~2020-05-01 4:20 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-01 3:41 [PATCH v7 00/28] Initial Prefixed Instruction support Jordan Niethe
2020-05-01 3:41 ` [PATCH v7 01/28] powerpc/xmon: Remove store_inst() for patch_instruction() Jordan Niethe
2020-05-01 3:41 ` [PATCH v7 02/28] powerpc/xmon: Move breakpoint instructions to own array Jordan Niethe
2020-05-04 5:41 ` Alistair Popple
2020-05-04 5:52 ` Jordan Niethe
2020-05-01 3:41 ` [PATCH v7 03/28] powerpc/xmon: Move breakpoints to text section Jordan Niethe
2020-05-01 3:41 ` [PATCH v7 04/28] powerpc/xmon: Use bitwise calculations in_breakpoint_table() Jordan Niethe
2020-05-04 5:41 ` Alistair Popple
2020-05-05 7:08 ` Michael Ellerman
2020-05-05 7:31 ` Jordan Niethe
2020-05-01 3:41 ` [PATCH v7 05/28] powerpc: Change calling convention for create_branch() et. al Jordan Niethe
2020-05-04 2:55 ` Alistair Popple
2020-05-01 3:41 ` [PATCH v7 06/28] powerpc: Use a macro for creating instructions from u32s Jordan Niethe
2020-05-04 5:54 ` Alistair Popple
2020-05-01 3:41 ` [PATCH v7 07/28] powerpc: Use an accessor for instructions Jordan Niethe
2020-05-01 3:42 ` [PATCH v7 08/28] powerpc: Use a function for getting the instruction op code Jordan Niethe
2020-05-04 8:01 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 09/28] powerpc: Use a function for byte swapping instructions Jordan Niethe
2020-05-01 3:42 ` [PATCH v7 10/28] powerpc: Introduce functions for instruction equality Jordan Niethe
2020-05-01 3:42 ` [PATCH v7 11/28] powerpc: Use a datatype for instructions Jordan Niethe
2020-05-02 14:29 ` kbuild test robot
2020-05-01 3:42 ` [PATCH v7 12/28] powerpc: Use a function for reading instructions Jordan Niethe
2020-05-04 8:26 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 13/28] powerpc: Add a probe_user_read_inst() function Jordan Niethe
2020-05-04 8:30 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 14/28] powerpc: Add a probe_kernel_read_inst() function Jordan Niethe
2020-05-04 9:24 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 15/28] powerpc/kprobes: Use patch_instruction() Jordan Niethe
2020-05-05 1:41 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 16/28] powerpc: Define and use __get_user_instr{, inatomic}() Jordan Niethe
2020-05-05 1:46 ` Alistair Popple
2020-05-01 3:42 ` Jordan Niethe [this message]
2020-05-05 2:02 ` [PATCH v7 17/28] powerpc: Introduce a function for reporting instruction length Alistair Popple
2020-05-01 3:42 ` [PATCH v7 18/28] powerpc/xmon: Use a function for reading instructions Jordan Niethe
2020-05-05 2:07 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 19/28] powerpc/xmon: Move insertion of breakpoint for xol'ing Jordan Niethe
2020-05-05 2:19 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 20/28] powerpc: Make test_translate_branch() independent of instruction length Jordan Niethe
2020-05-05 2:40 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 21/28] powerpc: Enable Prefixed Instructions Jordan Niethe
2020-05-01 3:42 ` [PATCH v7 22/28] powerpc: Define new SRR1 bits for a future ISA version Jordan Niethe
2020-05-05 2:49 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 23/28] powerpc: Add prefixed instructions to instruction data type Jordan Niethe
2020-05-05 6:04 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 24/28] powerpc: Test prefixed code patching Jordan Niethe
2020-05-05 6:08 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 25/28] powerpc: Test prefixed instructions in feature fixups Jordan Niethe
2020-05-05 7:15 ` Alistair Popple
2020-05-05 7:34 ` Jordan Niethe
2020-05-01 3:42 ` [PATCH v7 26/28] powerpc: Support prefixed instructions in alignment handler Jordan Niethe
2020-05-05 7:17 ` Alistair Popple
2020-05-01 3:42 ` [PATCH v7 27/28] powerpc sstep: Add support for prefixed load/stores Jordan Niethe
2020-05-01 3:42 ` [PATCH v7 28/28] powerpc sstep: Add support for prefixed fixed-point arithmetic Jordan Niethe
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=20200501034220.8982-18-jniethe5@gmail.com \
--to=jniethe5@gmail.com \
--cc=alistair@popple.id.au \
--cc=bala24@linux.ibm.com \
--cc=dja@axtens.net \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=naveen.n.rao@linux.vnet.ibm.com \
--cc=npiggin@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).