Skip to content

Commit f77f8ff

Browse files
iamjpnmpe
authored andcommitted
powerpc: Test prefixed code patching
Expand the code-patching self-tests to includes tests for patching prefixed instructions. Signed-off-by: Jordan Niethe <[email protected]> [mpe: Use CONFIG_PPC64 not __powerpc64__] Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 650b55b commit f77f8ff

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

arch/powerpc/lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ CFLAGS_code-patching.o += -DDISABLE_BRANCH_PROFILING
1616
CFLAGS_feature-fixups.o += -DDISABLE_BRANCH_PROFILING
1717
endif
1818

19-
obj-y += alloc.o code-patching.o feature-fixups.o pmem.o inst.o
19+
obj-y += alloc.o code-patching.o feature-fixups.o pmem.o inst.o test_code-patching.o
2020

2121
ifndef CONFIG_KASAN
2222
obj-y += string.o memcmp_$(BITS).o

arch/powerpc/lib/code-patching.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,26 @@ static void __init test_translate_branch(void)
708708
vfree(buf);
709709
}
710710

711+
#ifdef CONFIG_PPC64
712+
static void __init test_prefixed_patching(void)
713+
{
714+
extern unsigned int code_patching_test1[];
715+
extern unsigned int code_patching_test1_expected[];
716+
extern unsigned int end_code_patching_test1[];
717+
718+
__patch_instruction((struct ppc_inst *)code_patching_test1,
719+
ppc_inst_prefix(OP_PREFIX << 26, 0x00000000),
720+
(struct ppc_inst *)code_patching_test1);
721+
722+
check(!memcmp(code_patching_test1,
723+
code_patching_test1_expected,
724+
sizeof(unsigned int) *
725+
(end_code_patching_test1 - code_patching_test1)));
726+
}
727+
#else
728+
static inline void test_prefixed_patching(void) {}
729+
#endif
730+
711731
static int __init test_code_patching(void)
712732
{
713733
printk(KERN_DEBUG "Running code patching self-tests ...\n");
@@ -716,6 +736,7 @@ static int __init test_code_patching(void)
716736
test_branch_bform();
717737
test_create_function_call();
718738
test_translate_branch();
739+
test_prefixed_patching();
719740

720741
return 0;
721742
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (C) 2020 IBM Corporation
4+
*/
5+
#include <asm/ppc-opcode.h>
6+
7+
.text
8+
9+
#define globl(x) \
10+
.globl x; \
11+
x:
12+
13+
globl(code_patching_test1)
14+
nop
15+
nop
16+
globl(end_code_patching_test1)
17+
18+
globl(code_patching_test1_expected)
19+
.long OP_PREFIX << 26
20+
.long 0x0000000

0 commit comments

Comments
 (0)