linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
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 10/28] powerpc: Introduce functions for instruction equality
Date: Fri,  1 May 2020 13:42:02 +1000	[thread overview]
Message-ID: <20200501034220.8982-11-jniethe5@gmail.com> (raw)
In-Reply-To: <20200501034220.8982-1-jniethe5@gmail.com>

In preparation for an instruction data type that can not be directly
used with the '==' operator use functions for checking equality.

Reviewed-by: Balamuruhan S <bala24@linux.ibm.com>
Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
---
v5: Remove ppc_inst_null()
v7: Fix compilation issue in expected_nop_sequence() when no
    CONFIG_MPROFILE_KERNEL
---
 arch/powerpc/include/asm/inst.h    |  5 +++++
 arch/powerpc/kernel/trace/ftrace.c | 15 ++++++++-------
 arch/powerpc/lib/code-patching.c   | 12 ++++++------
 arch/powerpc/xmon/xmon.c           |  4 ++--
 4 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/include/asm/inst.h b/arch/powerpc/include/asm/inst.h
index 23fd57a86b03..0c5dc539160a 100644
--- a/arch/powerpc/include/asm/inst.h
+++ b/arch/powerpc/include/asm/inst.h
@@ -23,4 +23,9 @@ static inline u32 ppc_inst_swab(u32 x)
 	return ppc_inst(swab32(ppc_inst_val(x)));
 }
 
+static inline bool ppc_inst_equal(u32 x, u32 y)
+{
+	return x == y;
+}
+
 #endif /* _ASM_INST_H */
diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace/ftrace.c
index 335b10008035..d83c1be417f2 100644
--- a/arch/powerpc/kernel/trace/ftrace.c
+++ b/arch/powerpc/kernel/trace/ftrace.c
@@ -72,7 +72,7 @@ ftrace_modify_code(unsigned long ip, unsigned int old, unsigned int new)
 		return -EFAULT;
 
 	/* Make sure it is what we expect it to be */
-	if (replaced != old) {
+	if (!ppc_inst_equal(replaced, old)) {
 		pr_err("%p: replaced (%#x) != old (%#x)",
 		(void *)ip, ppc_inst_val(replaced), ppc_inst_val(old));
 		return -EINVAL;
@@ -170,7 +170,8 @@ __ftrace_make_nop(struct module *mod,
 	}
 
 	/* We expect either a mflr r0, or a std r0, LRSAVE(r1) */
-	if (op != ppc_inst(PPC_INST_MFLR) && op != ppc_inst(PPC_INST_STD_LR)) {
+	if (!ppc_inst_equal(op, ppc_inst(PPC_INST_MFLR)) &&
+	    !ppc_inst_equal(op, ppc_inst(PPC_INST_STD_LR))) {
 		pr_err("Unexpected instruction %08x around bl _mcount\n", ppc_inst_val(op));
 		return -EINVAL;
 	}
@@ -200,7 +201,7 @@ __ftrace_make_nop(struct module *mod,
 		return -EFAULT;
 	}
 
-	if (op != ppc_inst(PPC_INST_LD_TOC)) {
+	if (!ppc_inst_equal(op,  ppc_inst(PPC_INST_LD_TOC))) {
 		pr_err("Expected %08x found %08x\n", PPC_INST_LD_TOC, ppc_inst_val(op));
 		return -EINVAL;
 	}
@@ -497,7 +498,7 @@ expected_nop_sequence(void *ip, unsigned int op0, unsigned int op1)
 	 * The load offset is different depending on the ABI. For simplicity
 	 * just mask it out when doing the compare.
 	 */
-	if ((op0 != ppc_inst(0x48000008)) || (ppc_inst_val(op1) & 0xffff0000) != 0xe8410000)
+	if ((!ppc_inst_equal(op0, ppc_inst(0x48000008))) || (ppc_inst_val(op1) & 0xffff0000) != 0xe8410000)
 		return 0;
 	return 1;
 }
@@ -506,7 +507,7 @@ static int
 expected_nop_sequence(void *ip, unsigned int op0, unsigned int op1)
 {
 	/* look for patched "NOP" on ppc64 with -mprofile-kernel */
-	if (op0 != ppc_inst(PPC_INST_NOP))
+	if (!ppc_inst_equal(op0, ppc_inst(PPC_INST_NOP)))
 		return 0;
 	return 1;
 }
@@ -589,7 +590,7 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
 		return -EFAULT;
 
 	/* It should be pointing to a nop */
-	if (op != ppc_inst(PPC_INST_NOP)) {
+	if (!ppc_inst_equal(op,  ppc_inst(PPC_INST_NOP))) {
 		pr_err("Expected NOP but have %x\n", op);
 		return -EINVAL;
 	}
@@ -646,7 +647,7 @@ static int __ftrace_make_call_kernel(struct dyn_ftrace *rec, unsigned long addr)
 		return -EFAULT;
 	}
 
-	if (op != ppc_inst(PPC_INST_NOP)) {
+	if (!ppc_inst_equal(op, ppc_inst(PPC_INST_NOP))) {
 		pr_err("Unexpected call sequence at %p: %x\n", ip, ppc_inst_val(op));
 		return -EINVAL;
 	}
diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index f5c6dcbac44b..d298bb16936e 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -479,7 +479,7 @@ static void __init test_branch_iform(void)
 	/* Check flags are masked correctly */
 	err = create_branch(&instr, &instr, addr, 0xFFFFFFFC);
 	check(instr_is_branch_to_addr(&instr, addr));
-	check(instr == ppc_inst(0x48000000));
+	check(ppc_inst_equal(instr, ppc_inst(0x48000000)));
 }
 
 static void __init test_create_function_call(void)
@@ -564,7 +564,7 @@ static void __init test_branch_bform(void)
 	/* Check flags are masked correctly */
 	err = create_cond_branch(&instr, iptr, addr, 0xFFFFFFFC);
 	check(instr_is_branch_to_addr(&instr, addr));
-	check(instr == ppc_inst(0x43FF0000));
+	check(ppc_inst_equal(instr, ppc_inst(0x43FF0000)));
 }
 
 static void __init test_translate_branch(void)
@@ -598,7 +598,7 @@ static void __init test_translate_branch(void)
 	patch_instruction(q, instr);
 	check(instr_is_branch_to_addr(p, addr));
 	check(instr_is_branch_to_addr(q, addr));
-	check(*q == ppc_inst(0x4a000000));
+	check(ppc_inst_equal(*q, ppc_inst(0x4a000000)));
 
 	/* Maximum positive case, move x to x - 32 MB + 4 */
 	p = buf + 0x2000000;
@@ -609,7 +609,7 @@ static void __init test_translate_branch(void)
 	patch_instruction(q, instr);
 	check(instr_is_branch_to_addr(p, addr));
 	check(instr_is_branch_to_addr(q, addr));
-	check(*q == ppc_inst(0x49fffffc));
+	check(ppc_inst_equal(*q, ppc_inst(0x49fffffc)));
 
 	/* Jump to x + 16 MB moved to x + 20 MB */
 	p = buf;
@@ -655,7 +655,7 @@ static void __init test_translate_branch(void)
 	patch_instruction(q, instr);
 	check(instr_is_branch_to_addr(p, addr));
 	check(instr_is_branch_to_addr(q, addr));
-	check(*q == ppc_inst(0x43ff8000));
+	check(ppc_inst_equal(*q, ppc_inst(0x43ff8000)));
 
 	/* Maximum positive case, move x to x - 32 KB + 4 */
 	p = buf + 0x8000;
@@ -667,7 +667,7 @@ static void __init test_translate_branch(void)
 	patch_instruction(q, instr);
 	check(instr_is_branch_to_addr(p, addr));
 	check(instr_is_branch_to_addr(q, addr));
-	check(*q == ppc_inst(0x43ff7ffc));
+	check(ppc_inst_equal(*q, ppc_inst(0x43ff7ffc)));
 
 	/* Jump to x + 12 KB moved to x + 20 KB */
 	p = buf;
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 855676785c56..5064e29a3dab 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -947,7 +947,7 @@ static void remove_bpts(void)
 		if ((bp->enabled & (BP_TRAP|BP_CIABR)) != BP_TRAP)
 			continue;
 		if (mread(bp->address, &instr, 4) == 4
-		    && instr == ppc_inst(bpinstr)
+		    && ppc_inst_equal(instr, ppc_inst(bpinstr))
 		    && patch_instruction(
 			(unsigned int *)bp->address, bp->instr[0]) != 0)
 			printf("Couldn't remove breakpoint at %lx\n",
@@ -2862,7 +2862,7 @@ generic_inst_dump(unsigned long adr, long count, int praddr,
 			break;
 		}
 		inst = ppc_inst(GETWORD(val));
-		if (adr > first_adr && inst == last_inst) {
+		if (adr > first_adr && ppc_inst_equal(inst, last_inst)) {
 			if (!dotted) {
 				printf(" ...\n");
 				dotted = 1;
-- 
2.17.1


  parent reply	other threads:[~2020-05-01  4:05 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 ` Jordan Niethe [this message]
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 ` [PATCH v7 17/28] powerpc: Introduce a function for reporting instruction length Jordan Niethe
2020-05-05  2:02   ` 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-11-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).