@@ -25,14 +25,6 @@ static inline void apply_paravirt(struct paravirt_patch_site *start,
2525 */
2626#define POKE_MAX_OPCODE_SIZE 5
2727
28- struct text_poke_loc {
29- void * addr ;
30- int len ;
31- s32 rel32 ;
32- u8 opcode ;
33- const u8 text [POKE_MAX_OPCODE_SIZE ];
34- };
35-
3628extern void text_poke_early (void * addr , const void * opcode , size_t len );
3729
3830/*
@@ -50,21 +42,13 @@ extern void text_poke_early(void *addr, const void *opcode, size_t len);
5042 * an inconsistent instruction while you patch.
5143 */
5244extern void * text_poke (void * addr , const void * opcode , size_t len );
45+ extern void text_poke_sync (void );
5346extern void * text_poke_kgdb (void * addr , const void * opcode , size_t len );
5447extern int poke_int3_handler (struct pt_regs * regs );
5548extern void text_poke_bp (void * addr , const void * opcode , size_t len , const void * emulate );
56- extern void text_poke_bp_batch (struct text_poke_loc * tp , unsigned int nr_entries );
57- extern void text_poke_loc_init (struct text_poke_loc * tp , void * addr ,
58- const void * opcode , size_t len , const void * emulate );
59- extern int after_bootmem ;
60- extern __ro_after_init struct mm_struct * poking_mm ;
61- extern __ro_after_init unsigned long poking_addr ;
6249
63- #ifndef CONFIG_UML_X86
64- static inline void int3_emulate_jmp (struct pt_regs * regs , unsigned long ip )
65- {
66- regs -> ip = ip ;
67- }
50+ extern void text_poke_queue (void * addr , const void * opcode , size_t len , const void * emulate );
51+ extern void text_poke_finish (void );
6852
6953#define INT3_INSN_SIZE 1
7054#define INT3_INSN_OPCODE 0xCC
@@ -78,13 +62,77 @@ static inline void int3_emulate_jmp(struct pt_regs *regs, unsigned long ip)
7862#define JMP8_INSN_SIZE 2
7963#define JMP8_INSN_OPCODE 0xEB
8064
65+ #define DISP32_SIZE 4
66+
67+ static inline int text_opcode_size (u8 opcode )
68+ {
69+ int size = 0 ;
70+
71+ #define __CASE (insn ) \
72+ case insn##_INSN_OPCODE: size = insn##_INSN_SIZE; break
73+
74+ switch (opcode ) {
75+ __CASE (INT3 );
76+ __CASE (CALL );
77+ __CASE (JMP32 );
78+ __CASE (JMP8 );
79+ }
80+
81+ #undef __CASE
82+
83+ return size ;
84+ }
85+
86+ union text_poke_insn {
87+ u8 text [POKE_MAX_OPCODE_SIZE ];
88+ struct {
89+ u8 opcode ;
90+ s32 disp ;
91+ } __attribute__((packed ));
92+ };
93+
94+ static __always_inline
95+ void * text_gen_insn (u8 opcode , const void * addr , const void * dest )
96+ {
97+ static union text_poke_insn insn ; /* per instance */
98+ int size = text_opcode_size (opcode );
99+
100+ insn .opcode = opcode ;
101+
102+ if (size > 1 ) {
103+ insn .disp = (long )dest - (long )(addr + size );
104+ if (size == 2 ) {
105+ /*
106+ * Ensure that for JMP9 the displacement
107+ * actually fits the signed byte.
108+ */
109+ BUG_ON ((insn .disp >> 31 ) != (insn .disp >> 7 ));
110+ }
111+ }
112+
113+ return & insn .text ;
114+ }
115+
116+ extern int after_bootmem ;
117+ extern __ro_after_init struct mm_struct * poking_mm ;
118+ extern __ro_after_init unsigned long poking_addr ;
119+
120+ #ifndef CONFIG_UML_X86
121+ static inline void int3_emulate_jmp (struct pt_regs * regs , unsigned long ip )
122+ {
123+ regs -> ip = ip ;
124+ }
125+
81126static inline void int3_emulate_push (struct pt_regs * regs , unsigned long val )
82127{
83128 /*
84129 * The int3 handler in entry_64.S adds a gap between the
85130 * stack where the break point happened, and the saving of
86131 * pt_regs. We can extend the original stack because of
87132 * this gap. See the idtentry macro's create_gap option.
133+ *
134+ * Similarly entry_32.S will have a gap on the stack for (any) hardware
135+ * exception and pt_regs; see FIXUP_FRAME.
88136 */
89137 regs -> sp -= sizeof (unsigned long );
90138 * (unsigned long * )regs -> sp = val ;
0 commit comments