kernel/notifier.c
Source file repositories/reference/linux-study-clean/kernel/notifier.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/notifier.c- Extension
.c- Size
- 18287 bytes
- Lines
- 603
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kdebug.hlinux/kprobes.hlinux/export.hlinux/notifier.hlinux/rcupdate.hlinux/vmalloc.htrace/events/notifier.h
Detected Declarations
function notifier_chain_registerfunction notifier_chain_unregisterfunction notifier_call_chainfunction notifier_call_chain_robustfunction atomic_notifier_chain_registerfunction atomic_notifier_chain_register_unique_priofunction atomic_notifier_chain_unregisterfunction atomic_notifier_call_chainfunction atomic_notifier_call_chain_is_emptyfunction __blocking_notifier_chain_registerfunction blocking_notifier_chain_registerfunction blocking_notifier_chain_register_unique_priofunction blocking_notifier_chain_unregisterfunction blocking_notifier_call_chain_robustfunction blocking_notifier_call_chainfunction raw_notifier_chain_registerfunction raw_notifier_chain_unregisterfunction raw_notifier_call_chain_robustfunction raw_notifier_call_chainfunction srcu_notifier_chain_registerfunction srcu_notifier_chain_unregisterfunction srcu_notifier_call_chainfunction srcu_cleanup_notifier_headfunction notify_diefunction register_die_notifierfunction unregister_die_notifierexport atomic_notifier_chain_registerexport atomic_notifier_chain_register_unique_prioexport atomic_notifier_chain_unregisterexport atomic_notifier_call_chainexport blocking_notifier_chain_registerexport blocking_notifier_chain_register_unique_prioexport blocking_notifier_chain_unregisterexport blocking_notifier_call_chain_robustexport blocking_notifier_call_chainexport raw_notifier_chain_registerexport raw_notifier_chain_unregisterexport raw_notifier_call_chain_robustexport raw_notifier_call_chainexport srcu_notifier_chain_registerexport srcu_notifier_chain_unregisterexport srcu_notifier_call_chainexport srcu_init_notifier_headexport register_die_notifierexport unregister_die_notifier
Annotated Snippet
if (unlikely((*nl) == n)) {
WARN(1, "notifier callback %ps already registered",
n->notifier_call);
return -EEXIST;
}
if (n->priority > (*nl)->priority)
break;
if (n->priority == (*nl)->priority && unique_priority)
return -EBUSY;
nl = &((*nl)->next);
}
n->next = *nl;
rcu_assign_pointer(*nl, n);
trace_notifier_register((void *)n->notifier_call);
return 0;
}
static int notifier_chain_unregister(struct notifier_block **nl,
struct notifier_block *n)
{
while ((*nl) != NULL) {
if ((*nl) == n) {
rcu_assign_pointer(*nl, n->next);
trace_notifier_unregister((void *)n->notifier_call);
return 0;
}
nl = &((*nl)->next);
}
return -ENOENT;
}
/**
* notifier_call_chain - Informs the registered notifiers about an event.
* @nl: Pointer to head of the blocking notifier chain
* @val: Value passed unmodified to notifier function
* @v: Pointer passed unmodified to notifier function
* @nr_to_call: Number of notifier functions to be called. Don't care
* value of this parameter is -1.
* @nr_calls: Records the number of notifications sent. Don't care
* value of this field is NULL.
* Return: notifier_call_chain returns the value returned by the
* last notifier function called.
*/
static int notifier_call_chain(struct notifier_block **nl,
unsigned long val, void *v,
int nr_to_call, int *nr_calls)
{
int ret = NOTIFY_DONE;
struct notifier_block *nb, *next_nb;
nb = rcu_dereference_raw(*nl);
while (nb && nr_to_call) {
next_nb = rcu_dereference_raw(nb->next);
#ifdef CONFIG_DEBUG_NOTIFIERS
if (unlikely(!func_ptr_is_kernel_text(nb->notifier_call))) {
WARN(1, "Invalid notifier called!");
nb = next_nb;
continue;
}
#endif
trace_notifier_run((void *)nb->notifier_call);
ret = nb->notifier_call(nb, val, v);
if (nr_calls)
(*nr_calls)++;
if (ret & NOTIFY_STOP_MASK)
break;
nb = next_nb;
nr_to_call--;
}
return ret;
}
NOKPROBE_SYMBOL(notifier_call_chain);
/**
* notifier_call_chain_robust - Inform the registered notifiers about an event
* and rollback on error.
* @nl: Pointer to head of the blocking notifier chain
* @val_up: Value passed unmodified to the notifier function
* @val_down: Value passed unmodified to the notifier function when recovering
* from an error on @val_up
* @v: Pointer passed unmodified to the notifier function
*
* NOTE: It is important the @nl chain doesn't change between the two
* invocations of notifier_call_chain() such that we visit the
* exact same notifier callbacks; this rules out any RCU usage.
*
Annotation
- Immediate include surface: `linux/kdebug.h`, `linux/kprobes.h`, `linux/export.h`, `linux/notifier.h`, `linux/rcupdate.h`, `linux/vmalloc.h`, `trace/events/notifier.h`.
- Detected declarations: `function notifier_chain_register`, `function notifier_chain_unregister`, `function notifier_call_chain`, `function notifier_call_chain_robust`, `function atomic_notifier_chain_register`, `function atomic_notifier_chain_register_unique_prio`, `function atomic_notifier_chain_unregister`, `function atomic_notifier_call_chain`, `function atomic_notifier_call_chain_is_empty`, `function __blocking_notifier_chain_register`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.