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

powerpc: Test prefixed instructions in feature fixups

Expand the feature-fixups self-tests to includes tests for prefixed
instructions.

Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
[mpe: Use CONFIG_PPC64 not __powerpc64__, add empty inlines]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200506034050.24806-26-jniethe5@gmail.com

authored by

Jordan Niethe and committed by
Michael Ellerman
785b79d1 f77f8ff7

+144
+69
arch/powerpc/lib/feature-fixups-test.S
··· 7 7 #include <asm/ppc_asm.h> 8 8 #include <asm/synch.h> 9 9 #include <asm/asm-compat.h> 10 + #include <asm/ppc-opcode.h> 10 11 11 12 .text 12 13 ··· 792 791 1: or 1,1,1 793 792 sync 794 793 794 + globl(ftr_fixup_prefix1) 795 + or 1,1,1 796 + .long OP_PREFIX << 26 797 + .long 0x0000000 798 + or 2,2,2 799 + globl(end_ftr_fixup_prefix1) 800 + 801 + globl(ftr_fixup_prefix1_orig) 802 + or 1,1,1 803 + .long OP_PREFIX << 26 804 + .long 0x0000000 805 + or 2,2,2 806 + 807 + globl(ftr_fixup_prefix1_expected) 808 + or 1,1,1 809 + nop 810 + nop 811 + or 2,2,2 812 + 813 + globl(ftr_fixup_prefix2) 814 + or 1,1,1 815 + .long OP_PREFIX << 26 816 + .long 0x0000000 817 + or 2,2,2 818 + globl(end_ftr_fixup_prefix2) 819 + 820 + globl(ftr_fixup_prefix2_orig) 821 + or 1,1,1 822 + .long OP_PREFIX << 26 823 + .long 0x0000000 824 + or 2,2,2 825 + 826 + globl(ftr_fixup_prefix2_alt) 827 + .long OP_PREFIX << 26 828 + .long 0x0000001 829 + 830 + globl(ftr_fixup_prefix2_expected) 831 + or 1,1,1 832 + .long OP_PREFIX << 26 833 + .long 0x0000001 834 + or 2,2,2 835 + 836 + globl(ftr_fixup_prefix3) 837 + or 1,1,1 838 + .long OP_PREFIX << 26 839 + .long 0x0000000 840 + or 2,2,2 841 + or 3,3,3 842 + globl(end_ftr_fixup_prefix3) 843 + 844 + globl(ftr_fixup_prefix3_orig) 845 + or 1,1,1 846 + .long OP_PREFIX << 26 847 + .long 0x0000000 848 + or 2,2,2 849 + or 3,3,3 850 + 851 + globl(ftr_fixup_prefix3_alt) 852 + .long OP_PREFIX << 26 853 + .long 0x0000001 854 + nop 855 + 856 + globl(ftr_fixup_prefix3_expected) 857 + or 1,1,1 858 + .long OP_PREFIX << 26 859 + .long 0x0000001 860 + nop 861 + or 3,3,3
+75
arch/powerpc/lib/feature-fixups.c
··· 689 689 } 690 690 } 691 691 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 + 692 764 static int __init test_feature_fixups(void) 693 765 { 694 766 printk(KERN_DEBUG "Running feature fixup self-tests ...\n"); ··· 775 703 test_cpu_macros(); 776 704 test_fw_macros(); 777 705 test_lwsync_macros(); 706 + test_prefix_patching(); 707 + test_prefix_alt_patching(); 708 + test_prefix_word_alt_patching(); 778 709 779 710 return 0; 780 711 }