| Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 1 | /* | 
|  | 2 | * jump label x86 support | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2009 Jason Baron <jbaron@redhat.com> | 
|  | 5 | * | 
|  | 6 | */ | 
|  | 7 | #include <linux/jump_label.h> | 
|  | 8 | #include <linux/memory.h> | 
|  | 9 | #include <linux/uaccess.h> | 
|  | 10 | #include <linux/module.h> | 
|  | 11 | #include <linux/list.h> | 
|  | 12 | #include <linux/jhash.h> | 
|  | 13 | #include <linux/cpu.h> | 
|  | 14 | #include <asm/kprobes.h> | 
|  | 15 | #include <asm/alternative.h> | 
|  | 16 |  | 
|  | 17 | #ifdef HAVE_JUMP_LABEL | 
|  | 18 |  | 
|  | 19 | union jump_code_union { | 
|  | 20 | char code[JUMP_LABEL_NOP_SIZE]; | 
|  | 21 | struct { | 
|  | 22 | char jump; | 
|  | 23 | int offset; | 
|  | 24 | } __attribute__((packed)); | 
|  | 25 | }; | 
|  | 26 |  | 
| Jeremy Fitzhardinge | e71a5be | 2011-09-29 11:11:09 -0700 | [diff] [blame] | 27 | static void __jump_label_transform(struct jump_entry *entry, | 
|  | 28 | enum jump_label_type type, | 
|  | 29 | void *(*poker)(void *, const void *, size_t)) | 
| Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 30 | { | 
|  | 31 | union jump_code_union code; | 
|  | 32 |  | 
|  | 33 | if (type == JUMP_LABEL_ENABLE) { | 
|  | 34 | code.jump = 0xe9; | 
|  | 35 | code.offset = entry->target - | 
|  | 36 | (entry->code + JUMP_LABEL_NOP_SIZE); | 
|  | 37 | } else | 
| H. Peter Anvin | dc326fc | 2011-04-18 15:19:51 -0700 | [diff] [blame] | 38 | memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE); | 
| Jeremy Fitzhardinge | e71a5be | 2011-09-29 11:11:09 -0700 | [diff] [blame] | 39 |  | 
|  | 40 | (*poker)((void *)entry->code, &code, JUMP_LABEL_NOP_SIZE); | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | void arch_jump_label_transform(struct jump_entry *entry, | 
|  | 44 | enum jump_label_type type) | 
|  | 45 | { | 
| Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 46 | get_online_cpus(); | 
|  | 47 | mutex_lock(&text_mutex); | 
| Jeremy Fitzhardinge | e71a5be | 2011-09-29 11:11:09 -0700 | [diff] [blame] | 48 | __jump_label_transform(entry, type, text_poke_smp); | 
| Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 49 | mutex_unlock(&text_mutex); | 
|  | 50 | put_online_cpus(); | 
|  | 51 | } | 
|  | 52 |  | 
| Peter Zijlstra | 9cdbe1c | 2011-12-06 17:27:29 +0100 | [diff] [blame] | 53 | __init_or_module void arch_jump_label_transform_static(struct jump_entry *entry, | 
| Jeremy Fitzhardinge | e71a5be | 2011-09-29 11:11:09 -0700 | [diff] [blame] | 54 | enum jump_label_type type) | 
|  | 55 | { | 
|  | 56 | __jump_label_transform(entry, type, text_poke_early); | 
|  | 57 | } | 
|  | 58 |  | 
| Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 59 | #endif |