Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
alternative.c File Reference
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/mutex.h>
#include <linux/list.h>
#include <linux/stringify.h>
#include <linux/kprobes.h>
#include <linux/mm.h>
#include <linux/vmalloc.h>
#include <linux/memory.h>
#include <linux/stop_machine.h>
#include <linux/slab.h>
#include <asm/alternative.h>
#include <asm/sections.h>
#include <asm/pgtable.h>
#include <asm/mce.h>
#include <asm/nmi.h>
#include <asm/cacheflush.h>
#include <asm/tlbflush.h>
#include <asm/io.h>
#include <asm/fixmap.h>

Go to the source code of this file.

Data Structures

struct  text_poke_params
 

Macros

#define pr_fmt(fmt)   "SMP alternatives: " fmt
 
#define MAX_PATCH_LEN   (255-1)
 
#define DPRINTK(fmt,...)
 

Functions

 __setup ("debug-alternative", debug_alt)
 
 __setup ("noreplace-smp", setup_noreplace_smp)
 
void __init arch_init_ideal_nops (void)
 
voidtext_poke_early (void *addr, const void *opcode, size_t len)
 
void __init_or_module apply_alternatives (struct alt_instr *start, struct alt_instr *end)
 
void __init alternative_instructions (void)
 
void *__kprobes text_poke (void *addr, const void *opcode, size_t len)
 
void *__kprobes text_poke_smp (void *addr, const void *opcode, size_t len)
 
void __kprobes text_poke_smp_batch (struct text_poke_param *params, int n)
 

Variables

const unsigned char *constideal_nops = intel_nops
 
struct alt_instr __alt_instructions []
 
struct alt_instr __alt_instructions_end []
 
s32 __smp_locks []
 
s32 __smp_locks_end []
 

Macro Definition Documentation

#define DPRINTK (   fmt,
  ... 
)
Value:
do { \
if (debug_alternative) \
printk(KERN_DEBUG fmt, ##__VA_ARGS__); \
} while (0)

Definition at line 55 of file alternative.c.

#define MAX_PATCH_LEN   (255-1)

Definition at line 24 of file alternative.c.

#define pr_fmt (   fmt)    "SMP alternatives: " fmt

Definition at line 1 of file alternative.c.

Function Documentation

__setup ( "debug-alternative ,
debug_alt   
)
__setup ( "noreplace-smp ,
setup_noreplace_smp   
)
void __init alternative_instructions ( void  )

Definition at line 486 of file alternative.c.

void __init_or_module apply_alternatives ( struct alt_instr start,
struct alt_instr end 
)

Definition at line 252 of file alternative.c.

void __init arch_init_ideal_nops ( void  )

Definition at line 189 of file alternative.c.

void* __kprobes 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* 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* __kprobes 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 __kprobes 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.

Variable Documentation

struct alt_instr __alt_instructions[]
struct alt_instr __alt_instructions_end[]
s32 __smp_locks[]
s32 __smp_locks_end[]
const unsigned char* const* ideal_nops = intel_nops

Definition at line 186 of file alternative.c.