Skip to content

Commit 785b79d

Browse files
iamjpnmpe
authored andcommitted
powerpc: Test prefixed instructions in feature fixups
Expand the feature-fixups self-tests to includes tests for prefixed instructions. Signed-off-by: Jordan Niethe <[email protected]> [mpe: Use CONFIG_PPC64 not __powerpc64__, add empty inlines] Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f77f8ff commit 785b79d

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed

arch/powerpc/lib/feature-fixups-test.S

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <asm/ppc_asm.h>
88
#include <asm/synch.h>
99
#include <asm/asm-compat.h>
10+
#include <asm/ppc-opcode.h>
1011

1112
.text
1213

@@ -791,3 +792,71 @@ globl(lwsync_fixup_test_expected_SYNC)
791792
1: or 1,1,1
792793
sync
793794

795+
globl(ftr_fixup_prefix1)
796+
or 1,1,1
797+
.long OP_PREFIX << 26
798+
.long 0x0000000
799+
or 2,2,2
800+
globl(end_ftr_fixup_prefix1)
801+
802+
globl(ftr_fixup_prefix1_orig)
803+
or 1,1,1
804+
.long OP_PREFIX << 26
805+
.long 0x0000000
806+
or 2,2,2
807+
808+
globl(ftr_fixup_prefix1_expected)
809+
or 1,1,1
810+
nop
811+
nop
812+
or 2,2,2
813+
814+
globl(ftr_fixup_prefix2)
815+
or 1,1,1
816+
.long OP_PREFIX << 26
817+
.long 0x0000000
818+
or 2,2,2
819+
globl(end_ftr_fixup_prefix2)
820+
821+
globl(ftr_fixup_prefix2_orig)
822+
or 1,1,1
823+
.long OP_PREFIX << 26
824+
.long 0x0000000
825+
or 2,2,2
826+
827+
globl(ftr_fixup_prefix2_alt)
828+
.long OP_PREFIX << 26
829+
.long 0x0000001
830+
831+
globl(ftr_fixup_prefix2_expected)
832+
or 1,1,1
833+
.long OP_PREFIX << 26
834+
.long 0x0000001
835+
or 2,2,2
836+
837+
globl(ftr_fixup_prefix3)
838+
or 1,1,1
839+
.long OP_PREFIX << 26
840+
.long 0x0000000
841+
or 2,2,2
842+
or 3,3,3
843+
globl(end_ftr_fixup_prefix3)
844+
845+
globl(ftr_fixup_prefix3_orig)
846+
or 1,1,1
847+
.long OP_PREFIX << 26
848+
.long 0x0000000
849+
or 2,2,2
850+
or 3,3,3
851+
852+
globl(ftr_fixup_prefix3_alt)
853+
.long OP_PREFIX << 26
854+
.long 0x0000001
855+
nop
856+
857+
globl(ftr_fixup_prefix3_expected)
858+
or 1,1,1
859+
.long OP_PREFIX << 26
860+
.long 0x0000001
861+
nop
862+
or 3,3,3

arch/powerpc/lib/feature-fixups.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,78 @@ static void test_lwsync_macros(void)
689689
}
690690
}
691691

692+
#ifdef CONFIG_PPC64
693+
static void __init test_prefix_patching(void)
694+
{
695+
extern unsigned int ftr_fixup_prefix1[];
696+
extern unsigned int end_ftr_fixup_prefix1[];
697+
extern unsigned int ftr_fixup_prefix1_orig[];
698+
extern unsigned int ftr_fixup_prefix1_expected[];
699+
int size = sizeof(unsigned int) * (end_ftr_fixup_prefix1 - ftr_fixup_prefix1);
700+
701+
fixup.value = fixup.mask = 8;
702+
fixup.start_off = calc_offset(&fixup, ftr_fixup_prefix1 + 1);
703+
fixup.end_off = calc_offset(&fixup, ftr_fixup_prefix1 + 3);
704+
fixup.alt_start_off = fixup.alt_end_off = 0;
705+
706+
/* Sanity check */
707+
check(memcmp(ftr_fixup_prefix1, ftr_fixup_prefix1_orig, size) == 0);
708+
709+
patch_feature_section(0, &fixup);
710+
check(memcmp(ftr_fixup_prefix1, ftr_fixup_prefix1_expected, size) == 0);
711+
check(memcmp(ftr_fixup_prefix1, ftr_fixup_prefix1_orig, size) != 0);
712+
}
713+
714+
static void __init test_prefix_alt_patching(void)
715+
{
716+
extern unsigned int ftr_fixup_prefix2[];
717+
extern unsigned int end_ftr_fixup_prefix2[];
718+
extern unsigned int ftr_fixup_prefix2_orig[];
719+
extern unsigned int ftr_fixup_prefix2_expected[];
720+
extern unsigned int ftr_fixup_prefix2_alt[];
721+
int size = sizeof(unsigned int) * (end_ftr_fixup_prefix2 - ftr_fixup_prefix2);
722+
723+
fixup.value = fixup.mask = 8;
724+
fixup.start_off = calc_offset(&fixup, ftr_fixup_prefix2 + 1);
725+
fixup.end_off = calc_offset(&fixup, ftr_fixup_prefix2 + 3);
726+
fixup.alt_start_off = calc_offset(&fixup, ftr_fixup_prefix2_alt);
727+
fixup.alt_end_off = calc_offset(&fixup, ftr_fixup_prefix2_alt + 2);
728+
/* Sanity check */
729+
check(memcmp(ftr_fixup_prefix2, ftr_fixup_prefix2_orig, size) == 0);
730+
731+
patch_feature_section(0, &fixup);
732+
check(memcmp(ftr_fixup_prefix2, ftr_fixup_prefix2_expected, size) == 0);
733+
check(memcmp(ftr_fixup_prefix2, ftr_fixup_prefix2_orig, size) != 0);
734+
}
735+
736+
static void __init test_prefix_word_alt_patching(void)
737+
{
738+
extern unsigned int ftr_fixup_prefix3[];
739+
extern unsigned int end_ftr_fixup_prefix3[];
740+
extern unsigned int ftr_fixup_prefix3_orig[];
741+
extern unsigned int ftr_fixup_prefix3_expected[];
742+
extern unsigned int ftr_fixup_prefix3_alt[];
743+
int size = sizeof(unsigned int) * (end_ftr_fixup_prefix3 - ftr_fixup_prefix3);
744+
745+
fixup.value = fixup.mask = 8;
746+
fixup.start_off = calc_offset(&fixup, ftr_fixup_prefix3 + 1);
747+
fixup.end_off = calc_offset(&fixup, ftr_fixup_prefix3 + 4);
748+
fixup.alt_start_off = calc_offset(&fixup, ftr_fixup_prefix3_alt);
749+
fixup.alt_end_off = calc_offset(&fixup, ftr_fixup_prefix3_alt + 3);
750+
/* Sanity check */
751+
check(memcmp(ftr_fixup_prefix3, ftr_fixup_prefix3_orig, size) == 0);
752+
753+
patch_feature_section(0, &fixup);
754+
check(memcmp(ftr_fixup_prefix3, ftr_fixup_prefix3_expected, size) == 0);
755+
patch_feature_section(0, &fixup);
756+
check(memcmp(ftr_fixup_prefix3, ftr_fixup_prefix3_orig, size) != 0);
757+
}
758+
#else
759+
static inline void test_prefix_patching(void) {}
760+
static inline void test_prefix_alt_patching(void) {}
761+
static inline void test_prefix_word_alt_patching(void) {}
762+
#endif /* CONFIG_PPC64 */
763+
692764
static int __init test_feature_fixups(void)
693765
{
694766
printk(KERN_DEBUG "Running feature fixup self-tests ...\n");
@@ -703,6 +775,9 @@ static int __init test_feature_fixups(void)
703775
test_cpu_macros();
704776
test_fw_macros();
705777
test_lwsync_macros();
778+
test_prefix_patching();
779+
test_prefix_alt_patching();
780+
test_prefix_word_alt_patching();
706781

707782
return 0;
708783
}

0 commit comments

Comments
 (0)