Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * jump label support |
| 3 | * |
| 4 | * Copyright (C) 2009 Jason Baron <jbaron@redhat.com> |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 5 | * Copyright (C) 2011 Peter Zijlstra <pzijlstr@redhat.com> |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 6 | * |
| 7 | */ |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 8 | #include <linux/memory.h> |
| 9 | #include <linux/uaccess.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/list.h> |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 12 | #include <linux/slab.h> |
| 13 | #include <linux/sort.h> |
| 14 | #include <linux/err.h> |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 15 | #include <linux/jump_label.h> |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 16 | |
| 17 | #ifdef HAVE_JUMP_LABEL |
| 18 | |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 19 | /* mutex to protect coming/going of the the jump_label table */ |
| 20 | static DEFINE_MUTEX(jump_label_mutex); |
| 21 | |
Jason Baron | 91bad2f | 2010-10-01 17:23:48 -0400 | [diff] [blame] | 22 | void jump_label_lock(void) |
| 23 | { |
| 24 | mutex_lock(&jump_label_mutex); |
| 25 | } |
| 26 | |
| 27 | void jump_label_unlock(void) |
| 28 | { |
| 29 | mutex_unlock(&jump_label_mutex); |
| 30 | } |
| 31 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 32 | bool jump_label_enabled(struct jump_label_key *key) |
| 33 | { |
| 34 | return !!atomic_read(&key->enabled); |
| 35 | } |
| 36 | |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 37 | static int jump_label_cmp(const void *a, const void *b) |
| 38 | { |
| 39 | const struct jump_entry *jea = a; |
| 40 | const struct jump_entry *jeb = b; |
| 41 | |
| 42 | if (jea->key < jeb->key) |
| 43 | return -1; |
| 44 | |
| 45 | if (jea->key > jeb->key) |
| 46 | return 1; |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static void |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 52 | jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop) |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 53 | { |
| 54 | unsigned long size; |
| 55 | |
| 56 | size = (((unsigned long)stop - (unsigned long)start) |
| 57 | / sizeof(struct jump_entry)); |
| 58 | sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL); |
| 59 | } |
| 60 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 61 | static void jump_label_update(struct jump_label_key *key, int enable); |
| 62 | |
| 63 | void jump_label_inc(struct jump_label_key *key) |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 64 | { |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 65 | if (atomic_inc_not_zero(&key->enabled)) |
| 66 | return; |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 67 | |
Jason Baron | 91bad2f | 2010-10-01 17:23:48 -0400 | [diff] [blame] | 68 | jump_label_lock(); |
Gleb Natapov | bbbf7af | 2011-10-18 19:55:51 +0200 | [diff] [blame] | 69 | if (atomic_read(&key->enabled) == 0) |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 70 | jump_label_update(key, JUMP_LABEL_ENABLE); |
Gleb Natapov | bbbf7af | 2011-10-18 19:55:51 +0200 | [diff] [blame] | 71 | atomic_inc(&key->enabled); |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 72 | jump_label_unlock(); |
| 73 | } |
Xiao Guangrong | a65cf518 | 2011-11-28 20:39:59 +0800 | [diff] [blame] | 74 | EXPORT_SYMBOL_GPL(jump_label_inc); |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 75 | |
Gleb Natapov | b202952 | 2011-11-27 17:59:09 +0200 | [diff] [blame] | 76 | static void __jump_label_dec(struct jump_label_key *key, |
| 77 | unsigned long rate_limit, struct delayed_work *work) |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 78 | { |
Jason Baron | fadf046 | 2012-02-21 15:02:53 -0500 | [diff] [blame^] | 79 | if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex)) { |
| 80 | WARN(atomic_read(&key->enabled) < 0, |
| 81 | "jump label: negative count!\n"); |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 82 | return; |
Jason Baron | fadf046 | 2012-02-21 15:02:53 -0500 | [diff] [blame^] | 83 | } |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 84 | |
Gleb Natapov | b202952 | 2011-11-27 17:59:09 +0200 | [diff] [blame] | 85 | if (rate_limit) { |
| 86 | atomic_inc(&key->enabled); |
| 87 | schedule_delayed_work(work, rate_limit); |
| 88 | } else |
| 89 | jump_label_update(key, JUMP_LABEL_DISABLE); |
| 90 | |
Jason Baron | 91bad2f | 2010-10-01 17:23:48 -0400 | [diff] [blame] | 91 | jump_label_unlock(); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 92 | } |
Xiao Guangrong | a65cf518 | 2011-11-28 20:39:59 +0800 | [diff] [blame] | 93 | EXPORT_SYMBOL_GPL(jump_label_dec); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 94 | |
Gleb Natapov | b202952 | 2011-11-27 17:59:09 +0200 | [diff] [blame] | 95 | static void jump_label_update_timeout(struct work_struct *work) |
| 96 | { |
| 97 | struct jump_label_key_deferred *key = |
| 98 | container_of(work, struct jump_label_key_deferred, work.work); |
| 99 | __jump_label_dec(&key->key, 0, NULL); |
| 100 | } |
| 101 | |
| 102 | void jump_label_dec(struct jump_label_key *key) |
| 103 | { |
| 104 | __jump_label_dec(key, 0, NULL); |
| 105 | } |
| 106 | |
| 107 | void jump_label_dec_deferred(struct jump_label_key_deferred *key) |
| 108 | { |
| 109 | __jump_label_dec(&key->key, key->timeout, &key->work); |
| 110 | } |
| 111 | |
| 112 | |
| 113 | void jump_label_rate_limit(struct jump_label_key_deferred *key, |
| 114 | unsigned long rl) |
| 115 | { |
| 116 | key->timeout = rl; |
| 117 | INIT_DELAYED_WORK(&key->work, jump_label_update_timeout); |
| 118 | } |
| 119 | |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 120 | static int addr_conflict(struct jump_entry *entry, void *start, void *end) |
| 121 | { |
| 122 | if (entry->code <= (unsigned long)end && |
| 123 | entry->code + JUMP_LABEL_NOP_SIZE > (unsigned long)start) |
| 124 | return 1; |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 129 | static int __jump_label_text_reserved(struct jump_entry *iter_start, |
| 130 | struct jump_entry *iter_stop, void *start, void *end) |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 131 | { |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 132 | struct jump_entry *iter; |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 133 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 134 | iter = iter_start; |
| 135 | while (iter < iter_stop) { |
| 136 | if (addr_conflict(iter, start, end)) |
| 137 | return 1; |
| 138 | iter++; |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 139 | } |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 140 | |
| 141 | return 0; |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 142 | } |
| 143 | |
Jeremy Fitzhardinge | 20284aa | 2011-10-03 11:01:46 -0700 | [diff] [blame] | 144 | /* |
| 145 | * Update code which is definitely not currently executing. |
| 146 | * Architectures which need heavyweight synchronization to modify |
| 147 | * running code can override this to make the non-live update case |
| 148 | * cheaper. |
| 149 | */ |
Peter Zijlstra | 9cdbe1c | 2011-12-06 17:27:29 +0100 | [diff] [blame] | 150 | void __weak __init_or_module arch_jump_label_transform_static(struct jump_entry *entry, |
Jeremy Fitzhardinge | 20284aa | 2011-10-03 11:01:46 -0700 | [diff] [blame] | 151 | enum jump_label_type type) |
| 152 | { |
| 153 | arch_jump_label_transform(entry, type); |
| 154 | } |
| 155 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 156 | static void __jump_label_update(struct jump_label_key *key, |
Jiri Olsa | 7cbc5b8 | 2011-05-10 12:43:46 +0200 | [diff] [blame] | 157 | struct jump_entry *entry, |
| 158 | struct jump_entry *stop, int enable) |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 159 | { |
Jiri Olsa | 7cbc5b8 | 2011-05-10 12:43:46 +0200 | [diff] [blame] | 160 | for (; (entry < stop) && |
| 161 | (entry->key == (jump_label_t)(unsigned long)key); |
| 162 | entry++) { |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 163 | /* |
| 164 | * entry->code set to 0 invalidates module init text sections |
| 165 | * kernel_text_address() verifies we are not in core kernel |
| 166 | * init code, see jump_label_invalidate_module_init(). |
| 167 | */ |
| 168 | if (entry->code && kernel_text_address(entry->code)) |
| 169 | arch_jump_label_transform(entry, enable); |
| 170 | } |
| 171 | } |
| 172 | |
Jeremy Fitzhardinge | 97ce2c8 | 2011-10-12 16:17:54 -0700 | [diff] [blame] | 173 | void __init jump_label_init(void) |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 174 | { |
| 175 | struct jump_entry *iter_start = __start___jump_table; |
| 176 | struct jump_entry *iter_stop = __stop___jump_table; |
| 177 | struct jump_label_key *key = NULL; |
| 178 | struct jump_entry *iter; |
| 179 | |
| 180 | jump_label_lock(); |
| 181 | jump_label_sort_entries(iter_start, iter_stop); |
| 182 | |
| 183 | for (iter = iter_start; iter < iter_stop; iter++) { |
Jeremy Fitzhardinge | 3734880 | 2011-09-29 11:10:05 -0700 | [diff] [blame] | 184 | struct jump_label_key *iterk; |
| 185 | |
| 186 | iterk = (struct jump_label_key *)(unsigned long)iter->key; |
Jeremy Fitzhardinge | 20284aa | 2011-10-03 11:01:46 -0700 | [diff] [blame] | 187 | arch_jump_label_transform_static(iter, jump_label_enabled(iterk) ? |
| 188 | JUMP_LABEL_ENABLE : JUMP_LABEL_DISABLE); |
Jeremy Fitzhardinge | 3734880 | 2011-09-29 11:10:05 -0700 | [diff] [blame] | 189 | if (iterk == key) |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 190 | continue; |
| 191 | |
Jeremy Fitzhardinge | 3734880 | 2011-09-29 11:10:05 -0700 | [diff] [blame] | 192 | key = iterk; |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 193 | key->entries = iter; |
| 194 | #ifdef CONFIG_MODULES |
| 195 | key->next = NULL; |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 196 | #endif |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 197 | } |
| 198 | jump_label_unlock(); |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 199 | } |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 200 | |
| 201 | #ifdef CONFIG_MODULES |
| 202 | |
| 203 | struct jump_label_mod { |
| 204 | struct jump_label_mod *next; |
| 205 | struct jump_entry *entries; |
| 206 | struct module *mod; |
| 207 | }; |
| 208 | |
| 209 | static int __jump_label_mod_text_reserved(void *start, void *end) |
| 210 | { |
| 211 | struct module *mod; |
| 212 | |
| 213 | mod = __module_text_address((unsigned long)start); |
| 214 | if (!mod) |
| 215 | return 0; |
| 216 | |
| 217 | WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod); |
| 218 | |
| 219 | return __jump_label_text_reserved(mod->jump_entries, |
| 220 | mod->jump_entries + mod->num_jump_entries, |
| 221 | start, end); |
| 222 | } |
| 223 | |
| 224 | static void __jump_label_mod_update(struct jump_label_key *key, int enable) |
| 225 | { |
| 226 | struct jump_label_mod *mod = key->next; |
| 227 | |
| 228 | while (mod) { |
Jiri Olsa | 7cbc5b8 | 2011-05-10 12:43:46 +0200 | [diff] [blame] | 229 | struct module *m = mod->mod; |
| 230 | |
| 231 | __jump_label_update(key, mod->entries, |
| 232 | m->jump_entries + m->num_jump_entries, |
| 233 | enable); |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 234 | mod = mod->next; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /*** |
| 239 | * apply_jump_label_nops - patch module jump labels with arch_get_jump_label_nop() |
| 240 | * @mod: module to patch |
| 241 | * |
| 242 | * Allow for run-time selection of the optimal nops. Before the module |
| 243 | * loads patch these with arch_get_jump_label_nop(), which is specified by |
| 244 | * the arch specific jump label code. |
| 245 | */ |
| 246 | void jump_label_apply_nops(struct module *mod) |
| 247 | { |
| 248 | struct jump_entry *iter_start = mod->jump_entries; |
| 249 | struct jump_entry *iter_stop = iter_start + mod->num_jump_entries; |
| 250 | struct jump_entry *iter; |
| 251 | |
| 252 | /* if the module doesn't have jump label entries, just return */ |
| 253 | if (iter_start == iter_stop) |
| 254 | return; |
| 255 | |
Peter Zijlstra | ac99b86 | 2011-07-06 14:20:14 +0200 | [diff] [blame] | 256 | for (iter = iter_start; iter < iter_stop; iter++) { |
| 257 | struct jump_label_key *iterk; |
| 258 | |
| 259 | iterk = (struct jump_label_key *)(unsigned long)iter->key; |
| 260 | arch_jump_label_transform_static(iter, jump_label_enabled(iterk) ? |
| 261 | JUMP_LABEL_ENABLE : JUMP_LABEL_DISABLE); |
| 262 | } |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static int jump_label_add_module(struct module *mod) |
| 266 | { |
| 267 | struct jump_entry *iter_start = mod->jump_entries; |
| 268 | struct jump_entry *iter_stop = iter_start + mod->num_jump_entries; |
| 269 | struct jump_entry *iter; |
| 270 | struct jump_label_key *key = NULL; |
| 271 | struct jump_label_mod *jlm; |
| 272 | |
| 273 | /* if the module doesn't have jump label entries, just return */ |
| 274 | if (iter_start == iter_stop) |
| 275 | return 0; |
| 276 | |
| 277 | jump_label_sort_entries(iter_start, iter_stop); |
| 278 | |
| 279 | for (iter = iter_start; iter < iter_stop; iter++) { |
| 280 | if (iter->key == (jump_label_t)(unsigned long)key) |
| 281 | continue; |
| 282 | |
| 283 | key = (struct jump_label_key *)(unsigned long)iter->key; |
| 284 | |
| 285 | if (__module_address(iter->key) == mod) { |
| 286 | atomic_set(&key->enabled, 0); |
| 287 | key->entries = iter; |
| 288 | key->next = NULL; |
| 289 | continue; |
| 290 | } |
| 291 | |
| 292 | jlm = kzalloc(sizeof(struct jump_label_mod), GFP_KERNEL); |
| 293 | if (!jlm) |
| 294 | return -ENOMEM; |
| 295 | |
| 296 | jlm->mod = mod; |
| 297 | jlm->entries = iter; |
| 298 | jlm->next = key->next; |
| 299 | key->next = jlm; |
| 300 | |
| 301 | if (jump_label_enabled(key)) |
Peter Zijlstra | ac99b86 | 2011-07-06 14:20:14 +0200 | [diff] [blame] | 302 | __jump_label_update(key, iter, iter_stop, JUMP_LABEL_ENABLE); |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | static void jump_label_del_module(struct module *mod) |
| 309 | { |
| 310 | struct jump_entry *iter_start = mod->jump_entries; |
| 311 | struct jump_entry *iter_stop = iter_start + mod->num_jump_entries; |
| 312 | struct jump_entry *iter; |
| 313 | struct jump_label_key *key = NULL; |
| 314 | struct jump_label_mod *jlm, **prev; |
| 315 | |
| 316 | for (iter = iter_start; iter < iter_stop; iter++) { |
| 317 | if (iter->key == (jump_label_t)(unsigned long)key) |
| 318 | continue; |
| 319 | |
| 320 | key = (struct jump_label_key *)(unsigned long)iter->key; |
| 321 | |
| 322 | if (__module_address(iter->key) == mod) |
| 323 | continue; |
| 324 | |
| 325 | prev = &key->next; |
| 326 | jlm = key->next; |
| 327 | |
| 328 | while (jlm && jlm->mod != mod) { |
| 329 | prev = &jlm->next; |
| 330 | jlm = jlm->next; |
| 331 | } |
| 332 | |
| 333 | if (jlm) { |
| 334 | *prev = jlm->next; |
| 335 | kfree(jlm); |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | static void jump_label_invalidate_module_init(struct module *mod) |
| 341 | { |
| 342 | struct jump_entry *iter_start = mod->jump_entries; |
| 343 | struct jump_entry *iter_stop = iter_start + mod->num_jump_entries; |
| 344 | struct jump_entry *iter; |
| 345 | |
| 346 | for (iter = iter_start; iter < iter_stop; iter++) { |
| 347 | if (within_module_init(iter->code, mod)) |
| 348 | iter->code = 0; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | static int |
| 353 | jump_label_module_notify(struct notifier_block *self, unsigned long val, |
| 354 | void *data) |
| 355 | { |
| 356 | struct module *mod = data; |
| 357 | int ret = 0; |
| 358 | |
| 359 | switch (val) { |
| 360 | case MODULE_STATE_COMING: |
| 361 | jump_label_lock(); |
| 362 | ret = jump_label_add_module(mod); |
| 363 | if (ret) |
| 364 | jump_label_del_module(mod); |
| 365 | jump_label_unlock(); |
| 366 | break; |
| 367 | case MODULE_STATE_GOING: |
| 368 | jump_label_lock(); |
| 369 | jump_label_del_module(mod); |
| 370 | jump_label_unlock(); |
| 371 | break; |
| 372 | case MODULE_STATE_LIVE: |
| 373 | jump_label_lock(); |
| 374 | jump_label_invalidate_module_init(mod); |
| 375 | jump_label_unlock(); |
| 376 | break; |
| 377 | } |
| 378 | |
| 379 | return notifier_from_errno(ret); |
| 380 | } |
| 381 | |
| 382 | struct notifier_block jump_label_module_nb = { |
| 383 | .notifier_call = jump_label_module_notify, |
| 384 | .priority = 1, /* higher than tracepoints */ |
| 385 | }; |
| 386 | |
| 387 | static __init int jump_label_init_module(void) |
| 388 | { |
| 389 | return register_module_notifier(&jump_label_module_nb); |
| 390 | } |
| 391 | early_initcall(jump_label_init_module); |
| 392 | |
| 393 | #endif /* CONFIG_MODULES */ |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 394 | |
| 395 | /*** |
| 396 | * jump_label_text_reserved - check if addr range is reserved |
| 397 | * @start: start text addr |
| 398 | * @end: end text addr |
| 399 | * |
| 400 | * checks if the text addr located between @start and @end |
| 401 | * overlaps with any of the jump label patch addresses. Code |
| 402 | * that wants to modify kernel text should first verify that |
| 403 | * it does not overlap with any of the jump label addresses. |
Jason Baron | 91bad2f | 2010-10-01 17:23:48 -0400 | [diff] [blame] | 404 | * Caller must hold jump_label_mutex. |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 405 | * |
| 406 | * returns 1 if there is an overlap, 0 otherwise |
| 407 | */ |
| 408 | int jump_label_text_reserved(void *start, void *end) |
| 409 | { |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 410 | int ret = __jump_label_text_reserved(__start___jump_table, |
| 411 | __stop___jump_table, start, end); |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 412 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 413 | if (ret) |
| 414 | return ret; |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 415 | |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 416 | #ifdef CONFIG_MODULES |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 417 | ret = __jump_label_mod_text_reserved(start, end); |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 418 | #endif |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 419 | return ret; |
| 420 | } |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 421 | |
| 422 | static void jump_label_update(struct jump_label_key *key, int enable) |
| 423 | { |
Xiao Guangrong | 140fe3b | 2011-06-21 10:35:55 +0800 | [diff] [blame] | 424 | struct jump_entry *entry = key->entries, *stop = __stop___jump_table; |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 425 | |
| 426 | #ifdef CONFIG_MODULES |
Xiao Guangrong | 140fe3b | 2011-06-21 10:35:55 +0800 | [diff] [blame] | 427 | struct module *mod = __module_address((jump_label_t)key); |
| 428 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 429 | __jump_label_mod_update(key, enable); |
Xiao Guangrong | 140fe3b | 2011-06-21 10:35:55 +0800 | [diff] [blame] | 430 | |
| 431 | if (mod) |
| 432 | stop = mod->jump_entries + mod->num_jump_entries; |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 433 | #endif |
Xiao Guangrong | 140fe3b | 2011-06-21 10:35:55 +0800 | [diff] [blame] | 434 | /* if there are no users, entry can be NULL */ |
| 435 | if (entry) |
| 436 | __jump_label_update(key, entry, stop, enable); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 437 | } |
| 438 | |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 439 | #endif |