mm/kasan/tags.c
Source file repositories/reference/linux-study-clean/mm/kasan/tags.c
File Facts
- System
- Linux kernel
- Corpus path
mm/kasan/tags.c- Extension
.c- Size
- 3723 bytes
- Lines
- 149
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/atomic.hlinux/init.hlinux/kasan.hlinux/kernel.hlinux/memblock.hlinux/memory.hlinux/mm.hlinux/sched/clock.hlinux/stackdepot.hlinux/static_key.hlinux/string.hlinux/types.hkasan.h../slab.h
Detected Declarations
enum kasan_arg_stacktracefunction early_kasan_flag_stacktracefunction early_kasan_flag_stack_ring_sizefunction kasan_init_tagsfunction save_stack_infofunction kasan_save_alloc_infofunction kasan_save_free_info
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* This file contains common tag-based KASAN code.
*
* Copyright (c) 2018 Google, Inc.
* Copyright (c) 2020 Google, Inc.
*/
#include <linux/atomic.h>
#include <linux/init.h>
#include <linux/kasan.h>
#include <linux/kernel.h>
#include <linux/memblock.h>
#include <linux/memory.h>
#include <linux/mm.h>
#include <linux/sched/clock.h>
#include <linux/stackdepot.h>
#include <linux/static_key.h>
#include <linux/string.h>
#include <linux/types.h>
#include "kasan.h"
#include "../slab.h"
#define KASAN_STACK_RING_SIZE_DEFAULT (32 << 10)
enum kasan_arg_stacktrace {
KASAN_ARG_STACKTRACE_DEFAULT,
KASAN_ARG_STACKTRACE_OFF,
KASAN_ARG_STACKTRACE_ON,
};
static enum kasan_arg_stacktrace kasan_arg_stacktrace __initdata;
/* Whether to collect alloc/free stack traces. */
DEFINE_STATIC_KEY_TRUE(kasan_flag_stacktrace);
/* Non-zero, as initial pointer values are 0. */
#define STACK_RING_BUSY_PTR ((void *)1)
struct kasan_stack_ring stack_ring = {
.lock = __RW_LOCK_UNLOCKED(stack_ring.lock)
};
/* kasan.stacktrace=off/on */
static int __init early_kasan_flag_stacktrace(char *arg)
{
if (!arg)
return -EINVAL;
if (!strcmp(arg, "off"))
kasan_arg_stacktrace = KASAN_ARG_STACKTRACE_OFF;
else if (!strcmp(arg, "on"))
kasan_arg_stacktrace = KASAN_ARG_STACKTRACE_ON;
else
return -EINVAL;
return 0;
}
early_param("kasan.stacktrace", early_kasan_flag_stacktrace);
/* kasan.stack_ring_size=<number of entries> */
static int __init early_kasan_flag_stack_ring_size(char *arg)
{
if (!arg)
return -EINVAL;
return kstrtoul(arg, 0, &stack_ring.size);
}
early_param("kasan.stack_ring_size", early_kasan_flag_stack_ring_size);
void __init kasan_init_tags(void)
{
switch (kasan_arg_stacktrace) {
case KASAN_ARG_STACKTRACE_DEFAULT:
/* Default is specified by kasan_flag_stacktrace definition. */
break;
case KASAN_ARG_STACKTRACE_OFF:
static_branch_disable(&kasan_flag_stacktrace);
break;
case KASAN_ARG_STACKTRACE_ON:
static_branch_enable(&kasan_flag_stacktrace);
break;
}
if (kasan_stack_collection_enabled()) {
if (!stack_ring.size)
stack_ring.size = KASAN_STACK_RING_SIZE_DEFAULT;
stack_ring.entries = memblock_alloc(
sizeof(stack_ring.entries[0]) * stack_ring.size,
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/init.h`, `linux/kasan.h`, `linux/kernel.h`, `linux/memblock.h`, `linux/memory.h`, `linux/mm.h`, `linux/sched/clock.h`.
- Detected declarations: `enum kasan_arg_stacktrace`, `function early_kasan_flag_stacktrace`, `function early_kasan_flag_stack_ring_size`, `function kasan_init_tags`, `function save_stack_info`, `function kasan_save_alloc_info`, `function kasan_save_free_info`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: source implementation candidate.
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.