diff mbox series

[3/3] powerpc/code-patching: don't use the stack for code patching tests

Message ID 20211126032249.1652080-3-npiggin@gmail.com (mailing list archive)
State Superseded
Headers show
Series [1/3] powerpc/code-patching: work around code patching verification in patching tests | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 24 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 7 jobs.

Commit Message

Nicholas Piggin Nov. 26, 2021, 3:22 a.m. UTC
Use the existing test function for code patching tests instead of
writing to the stack. This means the address verification does not have
to be bypassed for these tests.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/lib/code-patching.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 70247fc58b6e..babf6b22adef 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -422,9 +422,11 @@  static void __init test_branch_iform(void)
 {
 	int err;
 	struct ppc_inst instr;
-	u32 tmp[2];
-	u32 *iptr = tmp;
-	unsigned long addr = (unsigned long)tmp;
+	u32 *iptr;
+	unsigned long addr;
+
+	iptr = (u32 *)ppc_function_entry(test_trampoline);
+	addr = (unsigned long)iptr;
 
 	/* The simplest case, branch to self, no flags */
 	check(instr_is_branch_iform(ppc_inst(0x48000000)));
@@ -516,12 +518,12 @@  static void __init test_create_function_call(void)
 static void __init test_branch_bform(void)
 {
 	int err;
-	unsigned long addr;
 	struct ppc_inst instr;
-	u32 tmp[2];
-	u32 *iptr = tmp;
+	u32 *iptr;
+	unsigned long addr;
 	unsigned int flags;
 
+	iptr = (u32 *)ppc_function_entry(test_trampoline);
 	addr = (unsigned long)iptr;
 
 	/* The simplest case, branch to self, no flags */
@@ -603,6 +605,12 @@  static void __init test_translate_branch(void)
 	if (!buf)
 		return;
 
+	/*
+	 * Have to disable the address bounds check for patch_instruction
+	 * because we are patching vmalloc space here.
+	 */
+	skip_addr_verif = true;
+
 	/* Simple case, branch to self moved a little */
 	p = buf;
 	addr = (unsigned long)p;
@@ -715,6 +723,8 @@  static void __init test_translate_branch(void)
 	check(instr_is_branch_to_addr(p, addr));
 	check(instr_is_branch_to_addr(q, addr));
 
+	skip_addr_verif = false;
+
 	/* Free the buffer we were using */
 	vfree(buf);
 }
@@ -743,13 +753,11 @@  static int __init test_code_patching(void)
 {
 	printk(KERN_DEBUG "Running code patching self-tests ...\n");
 
-	skip_addr_verif = true;
 	test_branch_iform();
 	test_branch_bform();
 	test_create_function_call();
 	test_translate_branch();
 	test_prefixed_patching();
-	skip_addr_verif = false;
 
 	return 0;
 }