@@ -114,31 +114,16 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
114
114
*/
115
115
static int test_24bit_addr (unsigned long ip , unsigned long addr )
116
116
{
117
- long diff ;
118
117
119
- /*
120
- * Can we get to addr from ip in 24 bits?
121
- * (26 really, since we mulitply by 4 for 4 byte alignment)
122
- */
123
- diff = addr - ip ;
124
-
125
- /*
126
- * Return true if diff is less than 1 << 25
127
- * and greater than -1 << 26.
128
- */
129
- return (diff < (1 << 25 )) && (diff > (-1 << 26 ));
118
+ /* use the create_branch to verify that this offset can be branched */
119
+ return create_branch ((unsigned int * )ip , addr , 0 );
130
120
}
131
121
132
122
static int is_bl_op (unsigned int op )
133
123
{
134
124
return (op & 0xfc000003 ) == 0x48000001 ;
135
125
}
136
126
137
- static int test_offset (unsigned long offset )
138
- {
139
- return (offset + 0x2000000 > 0x3ffffff ) || ((offset & 3 ) != 0 );
140
- }
141
-
142
127
static unsigned long find_bl_target (unsigned long ip , unsigned int op )
143
128
{
144
129
static int offset ;
@@ -151,12 +136,6 @@ static unsigned long find_bl_target(unsigned long ip, unsigned int op)
151
136
return ip + (long )offset ;
152
137
}
153
138
154
- static unsigned int branch_offset (unsigned long offset )
155
- {
156
- /* return "bl ip+offset" */
157
- return 0x48000001 | (offset & 0x03fffffc );
158
- }
159
-
160
139
#ifdef CONFIG_PPC64
161
140
static int
162
141
__ftrace_make_nop (struct module * mod ,
@@ -402,7 +381,6 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
402
381
{
403
382
unsigned int op [2 ];
404
383
unsigned long ip = rec -> ip ;
405
- unsigned long offset ;
406
384
407
385
/* read where this goes */
408
386
if (probe_kernel_read (op , (void * )ip , MCOUNT_INSN_SIZE * 2 ))
@@ -424,17 +402,14 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
424
402
return - EINVAL ;
425
403
}
426
404
427
- /* now calculate a jump to the ftrace caller trampoline */
428
- offset = rec -> arch .mod -> arch .tramp - ip ;
429
-
430
- if (test_offset (offset )) {
431
- printk (KERN_ERR "REL24 %li out of range!\n" ,
432
- (long int )offset );
405
+ /* create the branch to the trampoline */
406
+ op [0 ] = create_branch ((unsigned int * )ip ,
407
+ rec -> arch .mod -> arch .tramp , BRANCH_SET_LINK );
408
+ if (!op [0 ]) {
409
+ printk (KERN_ERR "REL24 out of range!\n" );
433
410
return - EINVAL ;
434
411
}
435
412
436
- /* Set to "bl addr" */
437
- op [0 ] = branch_offset (offset );
438
413
/* ld r2,40(r1) */
439
414
op [1 ] = 0xe8410028 ;
440
415
@@ -453,7 +428,6 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
453
428
{
454
429
unsigned int op ;
455
430
unsigned long ip = rec -> ip ;
456
- unsigned long offset ;
457
431
458
432
/* read where this goes */
459
433
if (probe_kernel_read (& op , (void * )ip , MCOUNT_INSN_SIZE ))
@@ -471,18 +445,14 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
471
445
return - EINVAL ;
472
446
}
473
447
474
- /* now calculate a jump to the ftrace caller trampoline */
475
- offset = rec -> arch .mod -> arch .tramp - ip ;
476
-
477
- if (test_offset (offset )) {
478
- printk (KERN_ERR "REL24 %li out of range!\n" ,
479
- (long int )offset );
448
+ /* create the branch to the trampoline */
449
+ op = create_branch ((unsigned int * )ip ,
450
+ rec -> arch .mod -> arch .tramp , BRANCH_SET_LINK );
451
+ if (!op ) {
452
+ printk (KERN_ERR "REL24 out of range!\n" );
480
453
return - EINVAL ;
481
454
}
482
455
483
- /* Set to "bl addr" */
484
- op = branch_offset (offset );
485
-
486
456
DEBUGP ("write to %lx\n" , rec -> ip );
487
457
488
458
if (probe_kernel_write ((void * )ip , & op , MCOUNT_INSN_SIZE ))
0 commit comments