Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/lib: Add alt patching test of branching past the last instruction

Add a test of the relative branch patching logic in the alternate
section feature fixup code. This tests that if we branch past the last
instruction of the alternate section, the branch is not patched.
That's because the assembler will have created a branch that already
points to the first instruction after the patched section, which is
correct and needs no further patching.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

+47
+36
arch/powerpc/lib/feature-fixups-test.S
··· 171 171 or 2,2,2 172 172 or 3,3,3 173 173 174 + globl(ftr_fixup_test7) 175 + or 1,1,1 176 + BEGIN_FTR_SECTION 177 + or 2,2,2 178 + or 2,2,2 179 + or 2,2,2 180 + or 2,2,2 181 + or 2,2,2 182 + or 2,2,2 183 + or 2,2,2 184 + FTR_SECTION_ELSE 185 + 2: b 3f 186 + 3: or 5,5,5 187 + beq 3b 188 + b 1f 189 + or 6,6,6 190 + b 2b 191 + bdnz 3b 192 + 1: 193 + ALT_FTR_SECTION_END(0, 1) 194 + or 1,1,1 195 + or 1,1,1 196 + 197 + globl(end_ftr_fixup_test7) 198 + nop 199 + 200 + globl(ftr_fixup_test7_expected) 201 + or 1,1,1 202 + 2: b 3f 203 + 3: or 5,5,5 204 + beq 3b 205 + b 1f 206 + or 6,6,6 207 + b 2b 208 + bdnz 3b 209 + 1: or 1,1,1 174 210 175 211 #if 0 176 212 /* Test that if we have a larger else case the assembler spots it and
+11
arch/powerpc/lib/feature-fixups.c
··· 425 425 check(memcmp(ftr_fixup_test6, ftr_fixup_test6_expected, size) == 0); 426 426 } 427 427 428 + static void test_alternative_case_with_branch_to_end(void) 429 + { 430 + extern unsigned int ftr_fixup_test7[]; 431 + extern unsigned int end_ftr_fixup_test7[]; 432 + extern unsigned int ftr_fixup_test7_expected[]; 433 + int size = 4 * (end_ftr_fixup_test7 - ftr_fixup_test7); 434 + 435 + check(memcmp(ftr_fixup_test7, ftr_fixup_test7_expected, size) == 0); 436 + } 437 + 428 438 static void test_cpu_macros(void) 429 439 { 430 440 extern u8 ftr_fixup_test_FTR_macros[]; ··· 490 480 test_alternative_case_too_small(); 491 481 test_alternative_case_with_branch(); 492 482 test_alternative_case_with_external_branch(); 483 + test_alternative_case_with_branch_to_end(); 493 484 test_cpu_macros(); 494 485 test_fw_macros(); 495 486 test_lwsync_macros();