Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions
alternative.h File Reference
#include <linux/types.h>
#include <linux/stddef.h>
#include <linux/stringify.h>
#include <asm/asm.h>
#include <asm/cpufeature.h>

Go to the source code of this file.

Data Structures

struct  alt_instr
 
struct  text_poke_param
 

Macros

#define LOCK_PREFIX_HERE   ""
 
#define LOCK_PREFIX   ""
 
#define OLDINSTR(oldinstr)   "661:\n\t" oldinstr "\n662:\n"
 
#define b_replacement(number)   "663"#number
 
#define e_replacement(number)   "664"#number
 
#define alt_slen   "662b-661b"
 
#define alt_rlen(number)   e_replacement(number)"f-"b_replacement(number)"f"
 
#define ALTINSTR_ENTRY(feature, number)
 
#define DISCARD_ENTRY(number)
 
#define ALTINSTR_REPLACEMENT(newinstr, feature, number)
 
#define ALTERNATIVE(oldinstr, newinstr, feature)
 
#define ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2)
 
#define alternative(oldinstr, newinstr, feature)   asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) : : : "memory")
 
#define alternative_input(oldinstr, newinstr, feature, input...)
 
#define alternative_io(oldinstr, newinstr, feature, output, input...)
 
#define alternative_call(oldfunc, newfunc, feature, output, input...)
 
#define alternative_call_2(oldfunc, newfunc1, feature1, newfunc2, feature2,output, input...)
 
#define ASM_OUTPUT2(a...)   a
 
#define ASM_NO_INPUT_CLOBBER(clbr...)   "i" (0) : clbr
 
#define __parainstructions   NULL
 
#define __parainstructions_end   NULL
 

Functions

void alternative_instructions (void)
 
void apply_alternatives (struct alt_instr *start, struct alt_instr *end)
 
voidtext_poke_early (void *addr, const void *opcode, size_t len)
 
voidtext_poke (void *addr, const void *opcode, size_t len)
 
voidtext_poke_smp (void *addr, const void *opcode, size_t len)
 
void text_poke_smp_batch (struct text_poke_param *params, int n)
 

Macro Definition Documentation

#define __parainstructions   NULL

Definition at line 206 of file alternative.h.

#define __parainstructions_end   NULL

Definition at line 207 of file alternative.h.

#define alt_rlen (   number)    e_replacement(number)"f-"b_replacement(number)"f"

Definition at line 84 of file alternative.h.

#define alt_slen   "662b-661b"

Definition at line 83 of file alternative.h.

#define ALTERNATIVE (   oldinstr,
  newinstr,
  feature 
)
Value:
OLDINSTR(oldinstr) \
".pushsection .altinstructions,\"a\"\n" \
ALTINSTR_ENTRY(feature, 1) \
".popsection\n" \
".pushsection .discard,\"aw\",@progbits\n" \
DISCARD_ENTRY(1) \
".popsection\n" \
".pushsection .altinstr_replacement, \"ax\"\n" \
ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
".popsection"

Definition at line 100 of file alternative.h.

#define alternative (   oldinstr,
  newinstr,
  feature 
)    asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) : : : "memory")

Definition at line 145 of file alternative.h.

#define ALTERNATIVE_2 (   oldinstr,
  newinstr1,
  feature1,
  newinstr2,
  feature2 
)
Value:
OLDINSTR(oldinstr) \
".pushsection .altinstructions,\"a\"\n" \
ALTINSTR_ENTRY(feature1, 1) \
ALTINSTR_ENTRY(feature2, 2) \
".popsection\n" \
".pushsection .discard,\"aw\",@progbits\n" \
DISCARD_ENTRY(1) \
DISCARD_ENTRY(2) \
".popsection\n" \
".pushsection .altinstr_replacement, \"ax\"\n" \
ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
".popsection"

Definition at line 112 of file alternative.h.

#define alternative_call (   oldfunc,
  newfunc,
  feature,
  output,
  input... 
)
Value:
asm volatile (ALTERNATIVE("call %P[old]", "call %P[new]", feature) \
: output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input)

Definition at line 169 of file alternative.h.

#define alternative_call_2 (   oldfunc,
  newfunc1,
  feature1,
  newfunc2,
  feature2,
  output,
  input... 
)
Value:
asm volatile (ALTERNATIVE_2("call %P[old]", "call %P[new1]", feature1,\
"call %P[new2]", feature2) \
: output : [old] "i" (oldfunc), [new1] "i" (newfunc1), \
[new2] "i" (newfunc2), ## input)

Definition at line 179 of file alternative.h.

#define alternative_input (   oldinstr,
  newinstr,
  feature,
  input... 
)
Value:
asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) \
: : "i" (0), ## input)

Definition at line 159 of file alternative.h.

#define alternative_io (   oldinstr,
  newinstr,
  feature,
  output,
  input... 
)
Value:
asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) \
: output : "i" (0), ## input)

Definition at line 164 of file alternative.h.

#define ALTINSTR_ENTRY (   feature,
  number 
)
Value:
" .long 661b - .\n" /* label */ \
" .long " b_replacement(number)"f - .\n" /* new instruction */ \
" .word " __stringify(feature) "\n" /* feature bit */ \
" .byte " alt_slen "\n" /* source len */ \
" .byte " alt_rlen(number) "\n" /* replacement len */

Definition at line 86 of file alternative.h.

#define ALTINSTR_REPLACEMENT (   newinstr,
  feature,
  number 
)
Value:
/* replacement */ \
b_replacement(number)":\n\t" newinstr "\n" e_replacement(number) ":\n\t"

Definition at line 96 of file alternative.h.

#define ASM_NO_INPUT_CLOBBER (   clbr...)    "i" (0) : clbr

Definition at line 196 of file alternative.h.

#define ASM_OUTPUT2 (   a...)    a

Definition at line 190 of file alternative.h.

#define b_replacement (   number)    "663"#number

Definition at line 80 of file alternative.h.

#define DISCARD_ENTRY (   number)
Value:
/* rlen <= slen */ \
" .byte 0xff + (" alt_rlen(number) ") - (" alt_slen ")\n"

Definition at line 93 of file alternative.h.

#define e_replacement (   number)    "664"#number

Definition at line 81 of file alternative.h.

#define LOCK_PREFIX   ""

Definition at line 42 of file alternative.h.

#define LOCK_PREFIX_HERE   ""

Definition at line 41 of file alternative.h.

#define OLDINSTR (   oldinstr)    "661:\n\t" oldinstr "\n662:\n"

Definition at line 78 of file alternative.h.

Function Documentation

void alternative_instructions ( void  )

Definition at line 486 of file alternative.c.

void apply_alternatives ( struct alt_instr start,
struct alt_instr end 
)

Definition at line 395 of file um_arch.c.

void* text_poke ( void addr,
const void opcode,
size_t  len 
)

text_poke - Update instructions on a live kernel : address to modify : source of the copy : length to copy

Only atomic text poke/set should be allowed when not doing early patching. It means the size must be writable atomically and the address must be aligned in a way that permits an atomic write. It also makes sure we fit on a single page.

Note: Must be called under text_mutex.

Definition at line 564 of file alternative.c.

void *__init_or_module text_poke_early ( void addr,
const void opcode,
size_t  len 
)

text_poke_early - Update instructions on a live kernel at boot time : address to modify : source of the copy : length to copy

When you use this code to patch more than one byte of an instruction you need to make sure that other CPUs cannot execute this code in parallel. Also no thread must be currently preempted in the middle of these instructions. And on the local CPU you need to be protected again NMI or MCE handlers seeing an inconsistent instruction while you patch.

Definition at line 538 of file alternative.c.

void* text_poke_smp ( void addr,
const void opcode,
size_t  len 
)

text_poke_smp - Update instructions on a live kernel on SMP : address to modify : source of the copy : length to copy

Modify multi-byte instruction by using stop_machine() on SMP. This allows user to poke/set multi-byte text on SMP. Only non-NMI/MCE code modifying should be allowed, since stop_machine() does not protect code against NMI and MCE.

Note: Must be called under get_online_cpus() and text_mutex.

Definition at line 657 of file alternative.c.

void text_poke_smp_batch ( struct text_poke_param params,
int  n 
)

text_poke_smp_batch - Update instructions on a live kernel on SMP : an array of text_poke parameters
: the number of elements in params.

Modify multi-byte instruction by using stop_machine() on SMP. Since the stop_machine() is heavy task, it is better to aggregate text_poke requests and do it once if possible.

Note: Must be called under get_online_cpus() and text_mutex.

Definition at line 685 of file alternative.c.