aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander van Heukelum <heukelum@mailshack.com>2008-11-24 09:38:45 -0500
committerIngo Molnar <mingo@elte.hu>2008-11-27 06:37:54 -0500
commitd211af055d0c12dc3416c2886e6fbdc6eb74a381 (patch)
tree27f6826ac10ae12cc546bfedc86959a664ce2802
parentddeb8f2149de280d54f0c8910cead42e6042b2cb (diff)
i386: get rid of the use of KPROBE_ENTRY / KPROBE_END
entry_32.S is now the only user of KPROBE_ENTRY / KPROBE_END, treewide. This patch reorders entry_64.S and explicitly generates a separate section for functions that need the protection. The generated code before and after the patch is equal. The KPROBE_ENTRY and KPROBE_END macro's are removed too. Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--arch/x86/kernel/entry_32.S438
-rw-r--r--include/linux/linkage.h8
2 files changed, 224 insertions, 222 deletions
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
index bd02ec77edc4..6e96028d1a9c 100644
--- a/arch/x86/kernel/entry_32.S
+++ b/arch/x86/kernel/entry_32.S
@@ -688,65 +688,6 @@ ENDPROC(name)
688/* The include is where all of the SMP etc. interrupts come from */ 688/* The include is where all of the SMP etc. interrupts come from */
689#include "entry_arch.h" 689#include "entry_arch.h"
690 690
691KPROBE_ENTRY(page_fault)
692 RING0_EC_FRAME
693 pushl $do_page_fault
694 CFI_ADJUST_CFA_OFFSET 4
695 ALIGN
696error_code:
697 /* the function address is in %fs's slot on the stack */
698 pushl %es
699 CFI_ADJUST_CFA_OFFSET 4
700 /*CFI_REL_OFFSET es, 0*/
701 pushl %ds
702 CFI_ADJUST_CFA_OFFSET 4
703 /*CFI_REL_OFFSET ds, 0*/
704 pushl %eax
705 CFI_ADJUST_CFA_OFFSET 4
706 CFI_REL_OFFSET eax, 0
707 pushl %ebp
708 CFI_ADJUST_CFA_OFFSET 4
709 CFI_REL_OFFSET ebp, 0
710 pushl %edi
711 CFI_ADJUST_CFA_OFFSET 4
712 CFI_REL_OFFSET edi, 0
713 pushl %esi
714 CFI_ADJUST_CFA_OFFSET 4
715 CFI_REL_OFFSET esi, 0
716 pushl %edx
717 CFI_ADJUST_CFA_OFFSET 4
718 CFI_REL_OFFSET edx, 0
719 pushl %ecx
720 CFI_ADJUST_CFA_OFFSET 4
721 CFI_REL_OFFSET ecx, 0
722 pushl %ebx
723 CFI_ADJUST_CFA_OFFSET 4
724 CFI_REL_OFFSET ebx, 0
725 cld
726 pushl %fs
727 CFI_ADJUST_CFA_OFFSET 4
728 /*CFI_REL_OFFSET fs, 0*/
729 movl $(__KERNEL_PERCPU), %ecx
730 movl %ecx, %fs
731 UNWIND_ESPFIX_STACK
732 popl %ecx
733 CFI_ADJUST_CFA_OFFSET -4
734 /*CFI_REGISTER es, ecx*/
735 movl PT_FS(%esp), %edi # get the function address
736 movl PT_ORIG_EAX(%esp), %edx # get the error code
737 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
738 mov %ecx, PT_FS(%esp)
739 /*CFI_REL_OFFSET fs, ES*/
740 movl $(__USER_DS), %ecx
741 movl %ecx, %ds
742 movl %ecx, %es
743 TRACE_IRQS_OFF
744 movl %esp,%eax # pt_regs pointer
745 call *%edi
746 jmp ret_from_exception
747 CFI_ENDPROC
748KPROBE_END(page_fault)
749
750ENTRY(coprocessor_error) 691ENTRY(coprocessor_error)
751 RING0_INT_FRAME 692 RING0_INT_FRAME
752 pushl $0 693 pushl $0
@@ -777,140 +718,6 @@ ENTRY(device_not_available)
777 CFI_ENDPROC 718 CFI_ENDPROC
778END(device_not_available) 719END(device_not_available)
779 720
780/*
781 * Debug traps and NMI can happen at the one SYSENTER instruction
782 * that sets up the real kernel stack. Check here, since we can't
783 * allow the wrong stack to be used.
784 *
785 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
786 * already pushed 3 words if it hits on the sysenter instruction:
787 * eflags, cs and eip.
788 *
789 * We just load the right stack, and push the three (known) values
790 * by hand onto the new stack - while updating the return eip past
791 * the instruction that would have done it for sysenter.
792 */
793#define FIX_STACK(offset, ok, label) \
794 cmpw $__KERNEL_CS,4(%esp); \
795 jne ok; \
796label: \
797 movl TSS_sysenter_sp0+offset(%esp),%esp; \
798 CFI_DEF_CFA esp, 0; \
799 CFI_UNDEFINED eip; \
800 pushfl; \
801 CFI_ADJUST_CFA_OFFSET 4; \
802 pushl $__KERNEL_CS; \
803 CFI_ADJUST_CFA_OFFSET 4; \
804 pushl $sysenter_past_esp; \
805 CFI_ADJUST_CFA_OFFSET 4; \
806 CFI_REL_OFFSET eip, 0
807
808KPROBE_ENTRY(debug)
809 RING0_INT_FRAME
810 cmpl $ia32_sysenter_target,(%esp)
811 jne debug_stack_correct
812 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
813debug_stack_correct:
814 pushl $-1 # mark this as an int
815 CFI_ADJUST_CFA_OFFSET 4
816 SAVE_ALL
817 TRACE_IRQS_OFF
818 xorl %edx,%edx # error code 0
819 movl %esp,%eax # pt_regs pointer
820 call do_debug
821 jmp ret_from_exception
822 CFI_ENDPROC
823KPROBE_END(debug)
824
825/*
826 * NMI is doubly nasty. It can happen _while_ we're handling
827 * a debug fault, and the debug fault hasn't yet been able to
828 * clear up the stack. So we first check whether we got an
829 * NMI on the sysenter entry path, but after that we need to
830 * check whether we got an NMI on the debug path where the debug
831 * fault happened on the sysenter path.
832 */
833KPROBE_ENTRY(nmi)
834 RING0_INT_FRAME
835 pushl %eax
836 CFI_ADJUST_CFA_OFFSET 4
837 movl %ss, %eax
838 cmpw $__ESPFIX_SS, %ax
839 popl %eax
840 CFI_ADJUST_CFA_OFFSET -4
841 je nmi_espfix_stack
842 cmpl $ia32_sysenter_target,(%esp)
843 je nmi_stack_fixup
844 pushl %eax
845 CFI_ADJUST_CFA_OFFSET 4
846 movl %esp,%eax
847 /* Do not access memory above the end of our stack page,
848 * it might not exist.
849 */
850 andl $(THREAD_SIZE-1),%eax
851 cmpl $(THREAD_SIZE-20),%eax
852 popl %eax
853 CFI_ADJUST_CFA_OFFSET -4
854 jae nmi_stack_correct
855 cmpl $ia32_sysenter_target,12(%esp)
856 je nmi_debug_stack_check
857nmi_stack_correct:
858 /* We have a RING0_INT_FRAME here */
859 pushl %eax
860 CFI_ADJUST_CFA_OFFSET 4
861 SAVE_ALL
862 TRACE_IRQS_OFF
863 xorl %edx,%edx # zero error code
864 movl %esp,%eax # pt_regs pointer
865 call do_nmi
866 jmp restore_nocheck_notrace
867 CFI_ENDPROC
868
869nmi_stack_fixup:
870 RING0_INT_FRAME
871 FIX_STACK(12,nmi_stack_correct, 1)
872 jmp nmi_stack_correct
873
874nmi_debug_stack_check:
875 /* We have a RING0_INT_FRAME here */
876 cmpw $__KERNEL_CS,16(%esp)
877 jne nmi_stack_correct
878 cmpl $debug,(%esp)
879 jb nmi_stack_correct
880 cmpl $debug_esp_fix_insn,(%esp)
881 ja nmi_stack_correct
882 FIX_STACK(24,nmi_stack_correct, 1)
883 jmp nmi_stack_correct
884
885nmi_espfix_stack:
886 /* We have a RING0_INT_FRAME here.
887 *
888 * create the pointer to lss back
889 */
890 pushl %ss
891 CFI_ADJUST_CFA_OFFSET 4
892 pushl %esp
893 CFI_ADJUST_CFA_OFFSET 4
894 addw $4, (%esp)
895 /* copy the iret frame of 12 bytes */
896 .rept 3
897 pushl 16(%esp)
898 CFI_ADJUST_CFA_OFFSET 4
899 .endr
900 pushl %eax
901 CFI_ADJUST_CFA_OFFSET 4
902 SAVE_ALL
903 TRACE_IRQS_OFF
904 FIXUP_ESPFIX_STACK # %eax == %esp
905 xorl %edx,%edx # zero error code
906 call do_nmi
907 RESTORE_REGS
908 lss 12+4(%esp), %esp # back to espfix stack
909 CFI_ADJUST_CFA_OFFSET -24
910 jmp irq_return
911 CFI_ENDPROC
912KPROBE_END(nmi)
913
914#ifdef CONFIG_PARAVIRT 721#ifdef CONFIG_PARAVIRT
915ENTRY(native_iret) 722ENTRY(native_iret)
916 iret 723 iret
@@ -926,19 +733,6 @@ ENTRY(native_irq_enable_sysexit)
926END(native_irq_enable_sysexit) 733END(native_irq_enable_sysexit)
927#endif 734#endif
928 735
929KPROBE_ENTRY(int3)
930 RING0_INT_FRAME
931 pushl $-1 # mark this as an int
932 CFI_ADJUST_CFA_OFFSET 4
933 SAVE_ALL
934 TRACE_IRQS_OFF
935 xorl %edx,%edx # zero error code
936 movl %esp,%eax # pt_regs pointer
937 call do_int3
938 jmp ret_from_exception
939 CFI_ENDPROC
940KPROBE_END(int3)
941
942ENTRY(overflow) 736ENTRY(overflow)
943 RING0_INT_FRAME 737 RING0_INT_FRAME
944 pushl $0 738 pushl $0
@@ -1003,14 +797,6 @@ ENTRY(stack_segment)
1003 CFI_ENDPROC 797 CFI_ENDPROC
1004END(stack_segment) 798END(stack_segment)
1005 799
1006KPROBE_ENTRY(general_protection)
1007 RING0_EC_FRAME
1008 pushl $do_general_protection
1009 CFI_ADJUST_CFA_OFFSET 4
1010 jmp error_code
1011 CFI_ENDPROC
1012KPROBE_END(general_protection)
1013
1014ENTRY(alignment_check) 800ENTRY(alignment_check)
1015 RING0_EC_FRAME 801 RING0_EC_FRAME
1016 pushl $do_alignment_check 802 pushl $do_alignment_check
@@ -1220,3 +1006,227 @@ END(mcount)
1220#include "syscall_table_32.S" 1006#include "syscall_table_32.S"
1221 1007
1222syscall_table_size=(.-sys_call_table) 1008syscall_table_size=(.-sys_call_table)
1009
1010/*
1011 * Some functions should be protected against kprobes
1012 */
1013 .pushsection .kprobes.text, "ax"
1014
1015ENTRY(page_fault)
1016 RING0_EC_FRAME
1017 pushl $do_page_fault
1018 CFI_ADJUST_CFA_OFFSET 4
1019 ALIGN
1020error_code:
1021 /* the function address is in %fs's slot on the stack */
1022 pushl %es
1023 CFI_ADJUST_CFA_OFFSET 4
1024 /*CFI_REL_OFFSET es, 0*/
1025 pushl %ds
1026 CFI_ADJUST_CFA_OFFSET 4
1027 /*CFI_REL_OFFSET ds, 0*/
1028 pushl %eax
1029 CFI_ADJUST_CFA_OFFSET 4
1030 CFI_REL_OFFSET eax, 0
1031 pushl %ebp
1032 CFI_ADJUST_CFA_OFFSET 4
1033 CFI_REL_OFFSET ebp, 0
1034 pushl %edi
1035 CFI_ADJUST_CFA_OFFSET 4
1036 CFI_REL_OFFSET edi, 0
1037 pushl %esi
1038 CFI_ADJUST_CFA_OFFSET 4
1039 CFI_REL_OFFSET esi, 0
1040 pushl %edx
1041 CFI_ADJUST_CFA_OFFSET 4
1042 CFI_REL_OFFSET edx, 0
1043 pushl %ecx
1044 CFI_ADJUST_CFA_OFFSET 4
1045 CFI_REL_OFFSET ecx, 0
1046 pushl %ebx
1047 CFI_ADJUST_CFA_OFFSET 4
1048 CFI_REL_OFFSET ebx, 0
1049 cld
1050 pushl %fs
1051 CFI_ADJUST_CFA_OFFSET 4
1052 /*CFI_REL_OFFSET fs, 0*/
1053 movl $(__KERNEL_PERCPU), %ecx
1054 movl %ecx, %fs
1055 UNWIND_ESPFIX_STACK
1056 popl %ecx
1057 CFI_ADJUST_CFA_OFFSET -4
1058 /*CFI_REGISTER es, ecx*/
1059 movl PT_FS(%esp), %edi # get the function address
1060 movl PT_ORIG_EAX(%esp), %edx # get the error code
1061 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
1062 mov %ecx, PT_FS(%esp)
1063 /*CFI_REL_OFFSET fs, ES*/
1064 movl $(__USER_DS), %ecx
1065 movl %ecx, %ds
1066 movl %ecx, %es
1067 TRACE_IRQS_OFF
1068 movl %esp,%eax # pt_regs pointer
1069 call *%edi
1070 jmp ret_from_exception
1071 CFI_ENDPROC
1072END(page_fault)
1073
1074/*
1075 * Debug traps and NMI can happen at the one SYSENTER instruction
1076 * that sets up the real kernel stack. Check here, since we can't
1077 * allow the wrong stack to be used.
1078 *
1079 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1080 * already pushed 3 words if it hits on the sysenter instruction:
1081 * eflags, cs and eip.
1082 *
1083 * We just load the right stack, and push the three (known) values
1084 * by hand onto the new stack - while updating the return eip past
1085 * the instruction that would have done it for sysenter.
1086 */
1087#define FIX_STACK(offset, ok, label) \
1088 cmpw $__KERNEL_CS,4(%esp); \
1089 jne ok; \
1090label: \
1091 movl TSS_sysenter_sp0+offset(%esp),%esp; \
1092 CFI_DEF_CFA esp, 0; \
1093 CFI_UNDEFINED eip; \
1094 pushfl; \
1095 CFI_ADJUST_CFA_OFFSET 4; \
1096 pushl $__KERNEL_CS; \
1097 CFI_ADJUST_CFA_OFFSET 4; \
1098 pushl $sysenter_past_esp; \
1099 CFI_ADJUST_CFA_OFFSET 4; \
1100 CFI_REL_OFFSET eip, 0
1101
1102ENTRY(debug)
1103 RING0_INT_FRAME
1104 cmpl $ia32_sysenter_target,(%esp)
1105 jne debug_stack_correct
1106 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
1107debug_stack_correct:
1108 pushl $-1 # mark this as an int
1109 CFI_ADJUST_CFA_OFFSET 4
1110 SAVE_ALL
1111 TRACE_IRQS_OFF
1112 xorl %edx,%edx # error code 0
1113 movl %esp,%eax # pt_regs pointer
1114 call do_debug
1115 jmp ret_from_exception
1116 CFI_ENDPROC
1117END(debug)
1118
1119/*
1120 * NMI is doubly nasty. It can happen _while_ we're handling
1121 * a debug fault, and the debug fault hasn't yet been able to
1122 * clear up the stack. So we first check whether we got an
1123 * NMI on the sysenter entry path, but after that we need to
1124 * check whether we got an NMI on the debug path where the debug
1125 * fault happened on the sysenter path.
1126 */
1127ENTRY(nmi)
1128 RING0_INT_FRAME
1129 pushl %eax
1130 CFI_ADJUST_CFA_OFFSET 4
1131 movl %ss, %eax
1132 cmpw $__ESPFIX_SS, %ax
1133 popl %eax
1134 CFI_ADJUST_CFA_OFFSET -4
1135 je nmi_espfix_stack
1136 cmpl $ia32_sysenter_target,(%esp)
1137 je nmi_stack_fixup
1138 pushl %eax
1139 CFI_ADJUST_CFA_OFFSET 4
1140 movl %esp,%eax
1141 /* Do not access memory above the end of our stack page,
1142 * it might not exist.
1143 */
1144 andl $(THREAD_SIZE-1),%eax
1145 cmpl $(THREAD_SIZE-20),%eax
1146 popl %eax
1147 CFI_ADJUST_CFA_OFFSET -4
1148 jae nmi_stack_correct
1149 cmpl $ia32_sysenter_target,12(%esp)
1150 je nmi_debug_stack_check
1151nmi_stack_correct:
1152 /* We have a RING0_INT_FRAME here */
1153 pushl %eax
1154 CFI_ADJUST_CFA_OFFSET 4
1155 SAVE_ALL
1156 TRACE_IRQS_OFF
1157 xorl %edx,%edx # zero error code
1158 movl %esp,%eax # pt_regs pointer
1159 call do_nmi
1160 jmp restore_nocheck_notrace
1161 CFI_ENDPROC
1162
1163nmi_stack_fixup:
1164 RING0_INT_FRAME
1165 FIX_STACK(12,nmi_stack_correct, 1)
1166 jmp nmi_stack_correct
1167
1168nmi_debug_stack_check:
1169 /* We have a RING0_INT_FRAME here */
1170 cmpw $__KERNEL_CS,16(%esp)
1171 jne nmi_stack_correct
1172 cmpl $debug,(%esp)
1173 jb nmi_stack_correct
1174 cmpl $debug_esp_fix_insn,(%esp)
1175 ja nmi_stack_correct
1176 FIX_STACK(24,nmi_stack_correct, 1)
1177 jmp nmi_stack_correct
1178
1179nmi_espfix_stack:
1180 /* We have a RING0_INT_FRAME here.
1181 *
1182 * create the pointer to lss back
1183 */
1184 pushl %ss
1185 CFI_ADJUST_CFA_OFFSET 4
1186 pushl %esp
1187 CFI_ADJUST_CFA_OFFSET 4
1188 addw $4, (%esp)
1189 /* copy the iret frame of 12 bytes */
1190 .rept 3
1191 pushl 16(%esp)
1192 CFI_ADJUST_CFA_OFFSET 4
1193 .endr
1194 pushl %eax
1195 CFI_ADJUST_CFA_OFFSET 4
1196 SAVE_ALL
1197 TRACE_IRQS_OFF
1198 FIXUP_ESPFIX_STACK # %eax == %esp
1199 xorl %edx,%edx # zero error code
1200 call do_nmi
1201 RESTORE_REGS
1202 lss 12+4(%esp), %esp # back to espfix stack
1203 CFI_ADJUST_CFA_OFFSET -24
1204 jmp irq_return
1205 CFI_ENDPROC
1206END(nmi)
1207
1208ENTRY(int3)
1209 RING0_INT_FRAME
1210 pushl $-1 # mark this as an int
1211 CFI_ADJUST_CFA_OFFSET 4
1212 SAVE_ALL
1213 TRACE_IRQS_OFF
1214 xorl %edx,%edx # zero error code
1215 movl %esp,%eax # pt_regs pointer
1216 call do_int3
1217 jmp ret_from_exception
1218 CFI_ENDPROC
1219END(int3)
1220
1221ENTRY(general_protection)
1222 RING0_EC_FRAME
1223 pushl $do_general_protection
1224 CFI_ADJUST_CFA_OFFSET 4
1225 jmp error_code
1226 CFI_ENDPROC
1227END(general_protection)
1228
1229/*
1230 * End of kprobes section
1231 */
1232 .popsection
diff --git a/include/linux/linkage.h b/include/linux/linkage.h
index 9fd1f859021b..fee9e59649c1 100644
--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -64,14 +64,6 @@
64 name: 64 name:
65#endif 65#endif
66 66
67#define KPROBE_ENTRY(name) \
68 .pushsection .kprobes.text, "ax"; \
69 ENTRY(name)
70
71#define KPROBE_END(name) \
72 END(name); \
73 .popsection
74
75#ifndef END 67#ifndef END
76#define END(name) \ 68#define END(name) \
77 .size name, .-name 69 .size name, .-name